Skip to content

Commit bfd74e5

Browse files
authored
fix: tsconfig validator fails on chained tsconfig references (#2512)
1 parent 09be982 commit bfd74e5

File tree

7 files changed

+49
-15
lines changed

7 files changed

+49
-15
lines changed

packages/typescript/internal/ts_project.bzl

+16-15
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,7 @@ def _ts_project_impl(ctx):
161161
inputs.extend(depset(transitive = deps_depsets).to_list())
162162

163163
# Gather TsConfig info from both the direct (tsconfig) and indirect (extends) attribute
164-
tsconfig_inputs = []
165-
if TsConfigInfo in ctx.attr.tsconfig:
166-
tsconfig_inputs.extend(ctx.attr.tsconfig[TsConfigInfo].deps)
167-
else:
168-
tsconfig_inputs.append(ctx.file.tsconfig)
169-
if hasattr(ctx.attr, "extends") and ctx.attr.extends:
170-
if TsConfigInfo in ctx.attr.extends:
171-
tsconfig_inputs.extend(ctx.attr.extends[TsConfigInfo].deps)
172-
else:
173-
tsconfig_inputs.extend(ctx.attr.extends.files.to_list())
164+
tsconfig_inputs = _tsconfig_inputs(ctx)
174165
inputs.extend(tsconfig_inputs)
175166

176167
# We do not try to predeclare json_outs, because their output locations generally conflict with their path in the source tree.
@@ -249,6 +240,20 @@ def _ts_project_impl(ctx):
249240

250241
return providers
251242

243+
def _tsconfig_inputs(ctx):
244+
"""Returns all transitively referenced tsconfig files from "tsconfig" and "extends" attributes."""
245+
inputs = []
246+
if TsConfigInfo in ctx.attr.tsconfig:
247+
inputs.extend(ctx.attr.tsconfig[TsConfigInfo].deps)
248+
else:
249+
inputs.append(ctx.file.tsconfig)
250+
if hasattr(ctx.attr, "extends") and ctx.attr.extends:
251+
if TsConfigInfo in ctx.attr.extends:
252+
inputs.extend(ctx.attr.extends[TsConfigInfo].deps)
253+
else:
254+
inputs.extend(ctx.attr.extends.files.to_list())
255+
return inputs
256+
252257
ts_project = rule(
253258
implementation = _ts_project_impl,
254259
attrs = dict(_ATTRS, **_OUTPUTS),
@@ -271,11 +276,7 @@ def _validate_options_impl(ctx):
271276
ts_build_info_file = ctx.attr.ts_build_info_file,
272277
).to_json()])
273278

274-
inputs = ctx.files.extends[:]
275-
if TsConfigInfo in ctx.attr.tsconfig:
276-
inputs.extend(ctx.attr.tsconfig[TsConfigInfo].deps)
277-
else:
278-
inputs.append(ctx.file.tsconfig)
279+
inputs = _tsconfig_inputs(ctx)
279280

280281
run_node(
281282
ctx,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
load("//packages/typescript:index.bzl", "ts_config")
2+
3+
ts_config(
4+
name = "tsconfig_node",
5+
src = "tsconfig.node.json",
6+
visibility = [":__subpackages__"],
7+
deps = ["tsconfig.base.json"],
8+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
load("//packages/typescript:index.bzl", "ts_project")
2+
3+
ts_project(
4+
name = "main",
5+
srcs = ["main.ts"],
6+
extends = "//packages/typescript/test/ts_project/extends_chain:tsconfig_node",
7+
tsconfig = ":tsconfig.json",
8+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('Hello world!');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "../tsconfig.node.json"
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"compilerOptions": {
3+
"noImplicitAny": true,
4+
"types": []
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig.base.json",
3+
"compilerOptions": {
4+
"moduleResolution": "Node",
5+
"module": "commonjs"
6+
}
7+
}

0 commit comments

Comments
 (0)