diff --git a/examples/app/BUILD.bazel b/examples/app/BUILD.bazel index db73be5dd3..cec78a0612 100644 --- a/examples/app/BUILD.bazel +++ b/examples/app/BUILD.bazel @@ -66,7 +66,7 @@ ts_project( name = "tsconfig-test", testonly = 1, srcs = ["app.e2e-spec.ts"], - extends = ["tsconfig.json"], + extends = "tsconfig.json", deps = [ "@npm//@types/jasmine", "@npm//@types/node", diff --git a/packages/typescript/internal/ts_project.bzl b/packages/typescript/internal/ts_project.bzl index b4e72dbfa0..1ca2e566ef 100644 --- a/packages/typescript/internal/ts_project.bzl +++ b/packages/typescript/internal/ts_project.bzl @@ -24,7 +24,7 @@ _ATTRS = { ], aspects = [module_mappings_aspect], ), - "extends": attr.label_list(allow_files = [".json"]), + "extends": attr.label(allow_files = [".json"]), "link_workspace_root": attr.bool(), "out_dir": attr.string(), "root_dir": attr.string(), @@ -120,15 +120,17 @@ 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: - inputs.extend(ctx.attr.tsconfig[TsConfigInfo].deps) + tsconfig_inputs.extend(ctx.attr.tsconfig[TsConfigInfo].deps) else: - inputs.append(ctx.file.tsconfig) - for extend in ctx.attr.extends: - if TsConfigInfo in extend: - inputs.extend(extend[TsConfigInfo].deps) + 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: - inputs.extend(extend.files.to_list()) + tsconfig_inputs.extend(ctx.attr.extends.files.to_list()) + 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. # (The exception is when out_dir is used, then the .json output is a different path than the input.) @@ -186,7 +188,7 @@ def _ts_project_impl(ctx): sources = depset(runtime_outputs), deps = ctx.attr.deps, ), - TsConfigInfo(deps = depset([ctx.file.tsconfig] + ctx.files.extends, transitive = [ + TsConfigInfo(deps = depset(tsconfig_inputs, transitive = [ dep[TsConfigInfo].deps for dep in ctx.attr.deps if TsConfigInfo in dep @@ -246,7 +248,7 @@ validate_options = rule( "declaration": attr.bool(), "declaration_map": attr.bool(), "emit_declaration_only": attr.bool(), - "extends": attr.label_list(allow_files = [".json"]), + "extends": attr.label(allow_files = [".json"]), "incremental": attr.bool(), "source_map": attr.bool(), "target": attr.string(), @@ -433,11 +435,6 @@ def ts_project_macro( To support "chaining" of more than one extended config, this label could be a target that provdes `TsConfigInfo` such as `ts_config`. - _DEPRECATED, to be removed in 3.0_: - For backwards compatibility, this accepts a list of Labels of the "chained" - tsconfig files. You should instead use a single Label of a `ts_config` target. - Follow this deprecation: https://github.com/bazelbuild/rules_nodejs/issues/2140 - args: List of strings of additional command-line arguments to pass to tsc. tsc: Label of the TypeScript compiler binary to run. @@ -488,11 +485,11 @@ def ts_project_macro( srcs = native.glob(["**/*.ts", "**/*.tsx"]) extra_deps = [] - if type(tsconfig) == type(dict()): - # Opt-in to #2140 breaking change at the same time you opt-in to experimental tsconfig dict - if type(extends) == type([]): - fail("when tsconfig is a dict, extends should have a single value") + if type(extends) == type([]): + fail("As of rules_nodejs 3.0, extends should have a single value, not a list.\n" + + "Use a ts_config rule to group together a chain of extended tsconfigs.") + if type(tsconfig) == type(dict()): # Copy attributes <-> tsconfig properties # TODO: fail if compilerOptions includes a conflict with an attribute? compiler_options = tsconfig.setdefault("compilerOptions", {}) @@ -546,10 +543,6 @@ def ts_project_macro( typings_out_dir = declaration_dir if declaration_dir else out_dir tsbuildinfo_path = ts_build_info_file if ts_build_info_file else name + ".tsbuildinfo" - # Backcompat for extends as a list, to cleanup in #2140 - if (type(extends) == type("")): - extends = [extends] - ts_project( name = name, srcs = srcs, diff --git a/packages/typescript/test/ts_project/a/BUILD.bazel b/packages/typescript/test/ts_project/a/BUILD.bazel index 847c10d6f5..4dc2aba668 100644 --- a/packages/typescript/test/ts_project/a/BUILD.bazel +++ b/packages/typescript/test/ts_project/a/BUILD.bazel @@ -1,11 +1,17 @@ -load("//packages/typescript:index.bzl", "ts_project") +load("//packages/typescript:index.bzl", "ts_config", "ts_project") + +ts_config( + name = "config", + src = "tsconfig.json", + deps = [ + "tsconfig-extended.json", + "//packages/typescript/test/ts_project:tsconfig", + ], +) ts_project( composite = True, - extends = [ - ":tsconfig-extended.json", - "//packages/typescript/test/ts_project:tsconfig-base.json", - ], + tsconfig = "config", # Intentionally not syncing this option from tsconfig, to test validator suppression # source_map = True, validate = False, diff --git a/packages/typescript/test/ts_project/b/BUILD.bazel b/packages/typescript/test/ts_project/b/BUILD.bazel index e8f2163d82..8cf57e5d49 100644 --- a/packages/typescript/test/ts_project/b/BUILD.bazel +++ b/packages/typescript/test/ts_project/b/BUILD.bazel @@ -9,7 +9,7 @@ ts_project( # just a test for the pass-through args attribute args = ["--emitBOM"], composite = True, - extends = ["//packages/typescript/test/ts_project:tsconfig-base.json"], + extends = "//packages/typescript/test/ts_project:tsconfig-base.json", deps = ["//packages/typescript/test/ts_project/a:tsconfig"], ) @@ -18,7 +18,7 @@ ts_project( testonly = True, srcs = [":b.spec.ts"], composite = True, - extends = ["//packages/typescript/test/ts_project:tsconfig-base.json"], + extends = "//packages/typescript/test/ts_project:tsconfig-base.json", deps = [ ":tsconfig", "@npm//@types/jasmine", diff --git a/packages/typescript/test/ts_project/c/BUILD.bazel b/packages/typescript/test/ts_project/c/BUILD.bazel index f5cb867061..8814049c03 100644 --- a/packages/typescript/test/ts_project/c/BUILD.bazel +++ b/packages/typescript/test/ts_project/c/BUILD.bazel @@ -4,7 +4,7 @@ ts_project( name = "compile", srcs = [":c.ts"], composite = True, - extends = ["//packages/typescript/test/ts_project:tsconfig-base.json"], + extends = "//packages/typescript/test/ts_project:tsconfig-base.json", tsconfig = "tsconfig.json", deps = ["//packages/typescript/test/ts_project/b:tsconfig"], )