diff --git a/packages/typescript/internal/ts_project.bzl b/packages/typescript/internal/ts_project.bzl index 28d76c0317..a216aa6d95 100644 --- a/packages/typescript/internal/ts_project.bzl +++ b/packages/typescript/internal/ts_project.bzl @@ -161,16 +161,7 @@ def _ts_project_impl(ctx): inputs.extend(depset(transitive = deps_depsets).to_list()) # Gather TsConfig info from both the direct (tsconfig) and indirect (extends) attribute - tsconfig_inputs = [] - if TsConfigInfo in ctx.attr.tsconfig: - tsconfig_inputs.extend(ctx.attr.tsconfig[TsConfigInfo].deps) - else: - tsconfig_inputs.append(ctx.file.tsconfig) - if hasattr(ctx.attr, "extends") and ctx.attr.extends: - if TsConfigInfo in ctx.attr.extends: - tsconfig_inputs.extend(ctx.attr.extends[TsConfigInfo].deps) - else: - tsconfig_inputs.extend(ctx.attr.extends.files.to_list()) + tsconfig_inputs = _tsconfig_inputs(ctx) inputs.extend(tsconfig_inputs) # 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): return providers +def _tsconfig_inputs(ctx): + """Returns all transitively referenced tsconfig files from "tsconfig" and "extends" attributes.""" + inputs = [] + if TsConfigInfo in ctx.attr.tsconfig: + inputs.extend(ctx.attr.tsconfig[TsConfigInfo].deps) + else: + inputs.append(ctx.file.tsconfig) + if hasattr(ctx.attr, "extends") and ctx.attr.extends: + if TsConfigInfo in ctx.attr.extends: + inputs.extend(ctx.attr.extends[TsConfigInfo].deps) + else: + inputs.extend(ctx.attr.extends.files.to_list()) + return inputs + ts_project = rule( implementation = _ts_project_impl, attrs = dict(_ATTRS, **_OUTPUTS), @@ -271,11 +276,7 @@ def _validate_options_impl(ctx): ts_build_info_file = ctx.attr.ts_build_info_file, ).to_json()]) - inputs = ctx.files.extends[:] - if TsConfigInfo in ctx.attr.tsconfig: - inputs.extend(ctx.attr.tsconfig[TsConfigInfo].deps) - else: - inputs.append(ctx.file.tsconfig) + inputs = _tsconfig_inputs(ctx) run_node( ctx, diff --git a/packages/typescript/test/ts_project/extends_chain/BUILD.bazel b/packages/typescript/test/ts_project/extends_chain/BUILD.bazel new file mode 100644 index 0000000000..ead12d3b7e --- /dev/null +++ b/packages/typescript/test/ts_project/extends_chain/BUILD.bazel @@ -0,0 +1,8 @@ +load("//packages/typescript:index.bzl", "ts_config") + +ts_config( + name = "tsconfig_node", + src = "tsconfig.node.json", + visibility = [":__subpackages__"], + deps = ["tsconfig.base.json"], +) diff --git a/packages/typescript/test/ts_project/extends_chain/main/BUILD.bazel b/packages/typescript/test/ts_project/extends_chain/main/BUILD.bazel new file mode 100644 index 0000000000..5a16b5d0a9 --- /dev/null +++ b/packages/typescript/test/ts_project/extends_chain/main/BUILD.bazel @@ -0,0 +1,8 @@ +load("//packages/typescript:index.bzl", "ts_project") + +ts_project( + name = "main", + srcs = ["main.ts"], + extends = "//packages/typescript/test/ts_project/extends_chain:tsconfig_node", + tsconfig = ":tsconfig.json", +) diff --git a/packages/typescript/test/ts_project/extends_chain/main/main.ts b/packages/typescript/test/ts_project/extends_chain/main/main.ts new file mode 100644 index 0000000000..b9d3e23cbf --- /dev/null +++ b/packages/typescript/test/ts_project/extends_chain/main/main.ts @@ -0,0 +1 @@ +console.log('Hello world!'); diff --git a/packages/typescript/test/ts_project/extends_chain/main/tsconfig.json b/packages/typescript/test/ts_project/extends_chain/main/tsconfig.json new file mode 100644 index 0000000000..5aae8b926c --- /dev/null +++ b/packages/typescript/test/ts_project/extends_chain/main/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "../tsconfig.node.json" +} diff --git a/packages/typescript/test/ts_project/extends_chain/tsconfig.base.json b/packages/typescript/test/ts_project/extends_chain/tsconfig.base.json new file mode 100644 index 0000000000..da332ac9d2 --- /dev/null +++ b/packages/typescript/test/ts_project/extends_chain/tsconfig.base.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "noImplicitAny": true, + "types": [] + } +} diff --git a/packages/typescript/test/ts_project/extends_chain/tsconfig.node.json b/packages/typescript/test/ts_project/extends_chain/tsconfig.node.json new file mode 100644 index 0000000000..b27ad182ad --- /dev/null +++ b/packages/typescript/test/ts_project/extends_chain/tsconfig.node.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.base.json", + "compilerOptions": { + "moduleResolution": "Node", + "module": "commonjs" + } +}