From 652e569c09f9bb0299a3bc2dbf35c1202d3128c9 Mon Sep 17 00:00:00 2001 From: Jacob Gardner Date: Mon, 25 Mar 2024 09:20:24 -0500 Subject: [PATCH] feat: support --noEmit for type-checking as a validation action --- docs/rules.md | 12 +++-- e2e/test/common.bats | 21 ++++++++ e2e/test/validation.bats | 38 +++++++++++++++ examples/no_emit/BUILD.bazel | 16 +++++++ examples/no_emit/tsconfig.json | 7 +++ examples/transpiler/BUILD.bazel | 13 +++++ ts/defs.bzl | 15 ++++-- ts/private/ts_lib.bzl | 19 ++++---- ts/private/ts_project.bzl | 56 +++++++++++++++++----- ts/private/ts_project_options_validator.js | 22 ++------- ts/private/ts_project_worker.js | 9 ++++ ts/private/ts_validate_options.bzl | 5 +- ts/test/mock_transpiler.bzl | 4 +- 13 files changed, 182 insertions(+), 55 deletions(-) create mode 100644 e2e/test/validation.bats create mode 100644 examples/no_emit/BUILD.bazel create mode 100644 examples/no_emit/tsconfig.json diff --git a/docs/rules.md b/docs/rules.md index aa5f71f4..4856f702 100644 --- a/docs/rules.md +++ b/docs/rules.md @@ -37,10 +37,10 @@ extended configuration file as well, to pass them both to the TypeScript compile
 ts_project_rule(name, deps, srcs, data, allow_js, args, assets, buildinfo_out, composite,
                 declaration, declaration_dir, declaration_map, emit_declaration_only, extends,
-                incremental, is_typescript_5_or_greater, js_outs, map_outs, out_dir, preserve_jsx,
-                resolve_json_module, resource_set, root_dir, source_map, supports_workers, transpile,
-                ts_build_info_file, tsc, tsc_worker, tsconfig, typing_maps_outs, typings_outs,
-                validate, validator)
+                incremental, is_typescript_5_or_greater, js_outs, map_outs, no_emit, out_dir,
+                preserve_jsx, resolve_json_module, resource_set, root_dir, source_map,
+                supports_workers, transpile, ts_build_info_file, tsc, tsc_worker, tsconfig,
+                typing_maps_outs, typings_outs, validate, validator)
 
Implementation rule behind the ts_project macro. @@ -72,6 +72,7 @@ for srcs and tsconfig, and pre-declaring output files. | is_typescript_5_or_greater | Whether TypeScript version is >= 5.0.0 | Boolean | optional | `False` | | js_outs | Locations in bazel-out where tsc will write `.js` files | List of labels | optional | `[]` | | map_outs | Locations in bazel-out where tsc will write `.js.map` files | List of labels | optional | `[]` | +| no_emit | https://www.typescriptlang.org/tsconfig#noEmit | Boolean | optional | `False` | | out_dir | https://www.typescriptlang.org/tsconfig#outDir | String | optional | `""` | | preserve_jsx | https://www.typescriptlang.org/tsconfig#jsx | Boolean | optional | `False` | | resolve_json_module | https://www.typescriptlang.org/tsconfig#resolveJsonModule | Boolean | optional | `False` | @@ -117,7 +118,7 @@ along with any transitively referenced tsconfig.json files chained by the
 ts_project(name, tsconfig, srcs, args, data, deps, assets, extends, allow_js, declaration,
            source_map, declaration_map, resolve_json_module, preserve_jsx, composite, incremental,
-           emit_declaration_only, transpiler, ts_build_info_file, tsc, tsc_worker, validate,
+           no_emit, emit_declaration_only, transpiler, ts_build_info_file, tsc, tsc_worker, validate,
            validator, declaration_dir, out_dir, root_dir, supports_workers, kwargs)
 
@@ -164,6 +165,7 @@ If you have problems getting your `ts_project` to work correctly, read the dedic | preserve_jsx | Whether the `jsx` value is set to "preserve" in the tsconfig. Instructs Bazel to expect a `.jsx` or `.jsx.map` output for each `.tsx` source. | `False` | | composite | Whether the `composite` bit is set in the tsconfig. Instructs Bazel to expect a `.tsbuildinfo` output and a `.d.ts` output for each `.ts` source. | `False` | | incremental | Whether the `incremental` bit is set in the tsconfig. Instructs Bazel to expect a `.tsbuildinfo` output. | `False` | +| no_emit | Whether the `noEmit` bit is set in the tsconfig. Instructs Bazel *not* to expect any outputs. Only a validation action is used. | `False` | | emit_declaration_only | Whether the `emitDeclarationOnly` bit is set in the tsconfig. Instructs Bazel *not* to expect `.js` or `.js.map` outputs for `.ts` sources. | `False` | | transpiler | A custom transpiler tool to run that produces the JavaScript outputs instead of `tsc`.

Under `--@aspect_rules_ts//ts:default_to_tsc_transpiler`, the default is to use `tsc` to produce `.js` outputs in the same action that does the type-checking to produce `.d.ts` outputs. This is the simplest configuration, however `tsc` is slower than alternatives. It also means developers must wait for the type-checking in the developer loop.

Without `--@aspect_rules_ts//ts:default_to_tsc_transpiler`, an explicit value must be set. This may be the string `"tsc"` to explicitly choose `tsc`, just like the default above.

It may also be any rule or macro with this signature: `(name, srcs, **kwargs)`

See [docs/transpiler.md](/docs/transpiler.md) for more details. | `None` | | ts_build_info_file | The user-specified value of `tsBuildInfoFile` from the tsconfig. Helps Bazel to predict the path where the .tsbuildinfo output is written. | `None` | diff --git a/e2e/test/common.bats b/e2e/test/common.bats index dc17f085..2be8a73d 100644 --- a/e2e/test/common.bats +++ b/e2e/test/common.bats @@ -82,6 +82,7 @@ function tsconfig() { local target="ES2020" local module_resolution="node" local composite="false" + local no_emit="false" local trace_resolution="false" local extended_diagnostics="false" while (($# > 0)); do @@ -111,6 +112,10 @@ function tsconfig() { composite="true" shift ;; + --no-emit) + shift + no_emit="true" + ;; --target) shift target="$1" @@ -139,6 +144,7 @@ function tsconfig() { "isolatedModules": $isolated_modules, "sourceMap": $source_map, "declaration": $declaration, + "noEmit": $no_emit, "target": "$target", "moduleResolution": "$module_resolution", "traceResolution": $trace_resolution, @@ -161,6 +167,9 @@ function ts_project() { local source_map="" local declaration="" local composite="" + local transpiler="" + local mock_transpiler_disabled="#" + local no_emit="" while (($# > 0)); do case "$1" in --path) @@ -215,6 +224,15 @@ function ts_project() { shift composite="composite = True," ;; + --transpiler-mock) + shift; + transpiler="transpiler = mock," + mock_transpiler_disabled="" + ;; + --no-emit) + shift + no_emit="no_emit = True," + ;; --) shift break @@ -238,6 +256,7 @@ function ts_project() { load("@aspect_rules_ts//ts:defs.bzl", "ts_project") ${npm_link_all_packages}load("@npm//:defs.bzl", "npm_link_all_packages") ${npm_link_all_packages}npm_link_all_packages(name = "node_modules") +${mock_transpiler_disabled}load("@aspect_rules_ts//ts/test:mock_transpiler.bzl", "mock") ts_project( name = "${name}", @@ -250,6 +269,8 @@ ts_project( $source_map $declaration $composite + $transpiler + $no_emit ) EOF } diff --git a/e2e/test/validation.bats b/e2e/test/validation.bats new file mode 100644 index 00000000..50231467 --- /dev/null +++ b/e2e/test/validation.bats @@ -0,0 +1,38 @@ +load "common.bats" + +setup() { + cd $BATS_FILE_TMPDIR +} + +teardown() { + bazel shutdown + rm -rf $BATS_FILE_TMPDIR/* +} + + +@test 'When tsc is only used for type-checking with a type-error, should pass when validations are disabled' { + workspace + + echo "export const a: string = 1;" > ./source.ts + tsconfig --declaration + ts_project --transpiler-mock --declaration --src "source.ts" + + run bazel build :foo --norun_validations + assert_success + run cat bazel-bin/source.js + assert_success + # Mock transpiler just copies source input to output + assert_output -p 'export const a: string = 1;' +} + +@test 'When tsc is only used for type-checking with a type-error, should fail when validations are enabled' { + workspace + + echo "export const a: string = 1;" > ./source.ts + tsconfig --no-emit + ts_project --no-emit --src "source.ts" + + run bazel build :foo --run_validations + assert_failure + assert_output -p "error TS2322: Type 'number' is not assignable to type 'string'" +} diff --git a/examples/no_emit/BUILD.bazel b/examples/no_emit/BUILD.bazel new file mode 100644 index 00000000..50f42975 --- /dev/null +++ b/examples/no_emit/BUILD.bazel @@ -0,0 +1,16 @@ +load("@aspect_rules_ts//ts:defs.bzl", "ts_project") +load("@bazel_skylib//rules:write_file.bzl", "write_file") + +write_file( + name = "gen_ts", + out = "a.ts", + content = [ + "export const a: number = 42", + ], +) + +ts_project( + name = "no-emit", + srcs = ["a.ts"], + no_emit = True, +) diff --git a/examples/no_emit/tsconfig.json b/examples/no_emit/tsconfig.json new file mode 100644 index 00000000..759c5c6b --- /dev/null +++ b/examples/no_emit/tsconfig.json @@ -0,0 +1,7 @@ +{ + // Workaround https://github.com/microsoft/TypeScript/issues/59036 + "exclude": [], + "compilerOptions": { + "noEmit": true + } +} diff --git a/examples/transpiler/BUILD.bazel b/examples/transpiler/BUILD.bazel index 0d76fc77..557be627 100644 --- a/examples/transpiler/BUILD.bazel +++ b/examples/transpiler/BUILD.bazel @@ -29,3 +29,16 @@ ts_project( source_map = True, transpiler = babel, ) + +# Transpiler with no dts being omitted +ts_project( + name = "no-emit", + srcs = ["big.ts"], + no_emit = True, + transpiler = babel, + tsconfig = { + "compilerOptions": { + "noEmit": True, + }, + }, +) diff --git a/ts/defs.bzl b/ts/defs.bzl index aa53f75c..da3070f1 100644 --- a/ts/defs.bzl +++ b/ts/defs.bzl @@ -47,6 +47,7 @@ def ts_project( preserve_jsx = False, composite = False, incremental = False, + no_emit = False, emit_declaration_only = False, transpiler = None, ts_build_info_file = None, @@ -215,6 +216,8 @@ def ts_project( Instructs Bazel to expect a `.tsbuildinfo` output and a `.d.ts` output for each `.ts` source. incremental: Whether the `incremental` bit is set in the tsconfig. Instructs Bazel to expect a `.tsbuildinfo` output. + no_emit: Whether the `noEmit` bit is set in the tsconfig. + Instructs Bazel *not* to expect any outputs. Only a validation action is used. emit_declaration_only: Whether the `emitDeclarationOnly` bit is set in the tsconfig. Instructs Bazel *not* to expect `.js` or `.js.map` outputs for `.ts` sources. ts_build_info_file: The user-specified value of `tsBuildInfoFile` from the tsconfig. @@ -276,6 +279,7 @@ def ts_project( source_map = compiler_options.setdefault("sourceMap", source_map) declaration = compiler_options.setdefault("declaration", declaration) declaration_map = compiler_options.setdefault("declarationMap", declaration_map) + no_emit = compiler_options.setdefault("noEmit", no_emit) emit_declaration_only = compiler_options.setdefault("emitDeclarationOnly", emit_declaration_only) allow_js = compiler_options.setdefault("allowJs", allow_js) if resolve_json_module != None: @@ -309,14 +313,14 @@ def ts_project( 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" - tsc_typings_outs = _lib.calculate_typings_outs(srcs, typings_out_dir, root_dir, declaration, composite, allow_js) - tsc_typing_maps_outs = _lib.calculate_typing_maps_outs(srcs, typings_out_dir, root_dir, declaration_map, allow_js) + tsc_typings_outs = _lib.calculate_typings_outs(srcs, typings_out_dir, root_dir, declaration, composite, allow_js, no_emit) + tsc_typing_maps_outs = _lib.calculate_typing_maps_outs(srcs, typings_out_dir, root_dir, declaration_map, allow_js, no_emit) tsc_js_outs = [] tsc_map_outs = [] - if not transpiler or transpiler == "tsc": - tsc_js_outs = _lib.calculate_js_outs(srcs, out_dir, root_dir, allow_js, resolve_json_module, preserve_jsx, emit_declaration_only) - tsc_map_outs = _lib.calculate_map_outs(srcs, out_dir, root_dir, source_map, preserve_jsx, emit_declaration_only) + if no_emit or not transpiler or transpiler == "tsc": + tsc_js_outs = _lib.calculate_js_outs(srcs, out_dir, root_dir, allow_js, resolve_json_module, preserve_jsx, no_emit, emit_declaration_only) + tsc_map_outs = _lib.calculate_map_outs(srcs, out_dir, root_dir, source_map, preserve_jsx, no_emit, emit_declaration_only) tsc_target_name = name else: # To stitch together a tree of ts_project where transpiler is a separate rule, @@ -401,6 +405,7 @@ def ts_project( typings_outs = tsc_typings_outs, typing_maps_outs = tsc_typing_maps_outs, buildinfo_out = tsbuildinfo_path if composite or incremental else None, + no_emit = no_emit, emit_declaration_only = emit_declaration_only, tsc = tsc, tsc_worker = tsc_worker, diff --git a/ts/private/ts_lib.bzl b/ts/private/ts_lib.bzl index de720e58..a42c5b45 100644 --- a/ts/private/ts_lib.bzl +++ b/ts/private/ts_lib.bzl @@ -114,6 +114,9 @@ COMPILER_OPTION_ATTRS = { "declaration_map": attr.bool( doc = "https://www.typescriptlang.org/tsconfig#declarationMap", ), + "no_emit": attr.bool( + doc = "https://www.typescriptlang.org/tsconfig#noEmit", + ), "emit_declaration_only": attr.bool( doc = "https://www.typescriptlang.org/tsconfig#emitDeclarationOnly", ), @@ -234,8 +237,8 @@ def _validate_tsconfig_dirs(root_dir, out_dir, typings_out_dir): if typings_out_dir and typings_out_dir.find("../") != -1: fail("typings_out_dir cannot output to parent directory") -def _calculate_js_outs(srcs, out_dir, root_dir, allow_js, resolve_json_module, preserve_jsx, emit_declaration_only): - if emit_declaration_only: +def _calculate_js_outs(srcs, out_dir, root_dir, allow_js, resolve_json_module, preserve_jsx, no_emit, emit_declaration_only): + if no_emit or emit_declaration_only: return [] exts = { @@ -253,8 +256,8 @@ def _calculate_js_outs(srcs, out_dir, root_dir, allow_js, resolve_json_module, p return _to_js_out_paths(srcs, out_dir, root_dir, allow_js, resolve_json_module, exts) -def _calculate_map_outs(srcs, out_dir, root_dir, source_map, preserve_jsx, emit_declaration_only): - if not source_map or emit_declaration_only: +def _calculate_map_outs(srcs, out_dir, root_dir, source_map, preserve_jsx, no_emit, emit_declaration_only): + if no_emit or not source_map or emit_declaration_only: return [] exts = { @@ -269,8 +272,8 @@ def _calculate_map_outs(srcs, out_dir, root_dir, source_map, preserve_jsx, emit_ return _to_js_out_paths(srcs, out_dir, root_dir, False, False, exts) -def _calculate_typings_outs(srcs, typings_out_dir, root_dir, declaration, composite, allow_js): - if not (declaration or composite): +def _calculate_typings_outs(srcs, typings_out_dir, root_dir, declaration, composite, allow_js, no_emit): + if no_emit or not (declaration or composite): return [] exts = { @@ -283,8 +286,8 @@ def _calculate_typings_outs(srcs, typings_out_dir, root_dir, declaration, compos return _to_js_out_paths(srcs, typings_out_dir, root_dir, allow_js, False, exts) -def _calculate_typing_maps_outs(srcs, typings_out_dir, root_dir, declaration_map, allow_js): - if not declaration_map: +def _calculate_typing_maps_outs(srcs, typings_out_dir, root_dir, declaration_map, allow_js, no_emit): + if no_emit or not declaration_map: return [] exts = { diff --git a/ts/private/ts_project.bzl b/ts/private/ts_project.bzl index 7437c4ef..43aba0c5 100644 --- a/ts/private/ts_project.bzl +++ b/ts/private/ts_project.bzl @@ -62,10 +62,10 @@ def _ts_project_impl(ctx): # However, it is not possible to evaluate files in outputs of other rules such as filegroup, therefore the outs are # recalculated here. typings_out_dir = ctx.attr.declaration_dir or ctx.attr.out_dir - js_outs = _lib.declare_outputs(ctx, [] if ctx.attr.transpile == 0 else _lib.calculate_js_outs(srcs, ctx.attr.out_dir, ctx.attr.root_dir, ctx.attr.allow_js, ctx.attr.resolve_json_module, ctx.attr.preserve_jsx, ctx.attr.emit_declaration_only)) - map_outs = _lib.declare_outputs(ctx, [] if ctx.attr.transpile == 0 else _lib.calculate_map_outs(srcs, ctx.attr.out_dir, ctx.attr.root_dir, ctx.attr.source_map, ctx.attr.preserve_jsx, ctx.attr.emit_declaration_only)) - typings_outs = _lib.declare_outputs(ctx, _lib.calculate_typings_outs(srcs, typings_out_dir, ctx.attr.root_dir, ctx.attr.declaration, ctx.attr.composite, ctx.attr.allow_js)) - typing_maps_outs = _lib.declare_outputs(ctx, _lib.calculate_typing_maps_outs(srcs, typings_out_dir, ctx.attr.root_dir, ctx.attr.declaration_map, ctx.attr.allow_js)) + js_outs = _lib.declare_outputs(ctx, [] if ctx.attr.transpile == 0 else _lib.calculate_js_outs(srcs, ctx.attr.out_dir, ctx.attr.root_dir, ctx.attr.allow_js, ctx.attr.resolve_json_module, ctx.attr.preserve_jsx, ctx.attr.no_emit, ctx.attr.emit_declaration_only)) + map_outs = _lib.declare_outputs(ctx, [] if ctx.attr.transpile == 0 else _lib.calculate_map_outs(srcs, ctx.attr.out_dir, ctx.attr.root_dir, ctx.attr.source_map, ctx.attr.preserve_jsx, ctx.attr.no_emit, ctx.attr.emit_declaration_only)) + typings_outs = _lib.declare_outputs(ctx, _lib.calculate_typings_outs(srcs, typings_out_dir, ctx.attr.root_dir, ctx.attr.declaration, ctx.attr.composite, ctx.attr.allow_js, ctx.attr.no_emit)) + typing_maps_outs = _lib.declare_outputs(ctx, _lib.calculate_typing_maps_outs(srcs, typings_out_dir, ctx.attr.root_dir, ctx.attr.declaration_map, ctx.attr.allow_js, ctx.attr.no_emit)) validation_outs = [] if ctx.attr.validate: @@ -181,7 +181,7 @@ See https://github.com/aspect-build/rules_ts/issues/361 for more details. typings_srcs = [s for s in srcs_inputs if _lib.is_typings_src(s.path)] - if len(js_outs) + len(typings_outs) < 1: + if len(js_outs) + len(typings_outs) < 1 and not ctx.attr.no_emit: label = "//{}:{}".format(ctx.label.package, ctx.label.name) if len(typings_srcs) > 0: no_outs_msg = """ts_project target {target} only has typings in srcs. @@ -225,7 +225,8 @@ This is an error because Bazel does not run actions unless their outputs are nee else: # We must avoid tsc writing any JS files in this case, as tsc was only run for typings, and some other # action will try to write the JS files. We must avoid collisions where two actions write the same file. - arguments.add("--emitDeclarationOnly") + if not ctx.attr.no_emit: + arguments.add("--emitDeclarationOnly") # We don't produce any DefaultInfo outputs in this case, because we avoid running the tsc action # unless the output_types are requested. @@ -233,15 +234,44 @@ This is an error because Bazel does not run actions unless their outputs are nee srcs_tsconfig_deps = ctx.attr.srcs + [ctx.attr.tsconfig] + ctx.attr.deps - inputs_depset = depset() - if len(outputs) > 0: - transitive_inputs.append(_gather_types_from_js_infos(srcs_tsconfig_deps)) + transitive_inputs.append(_gather_types_from_js_infos(srcs_tsconfig_deps)) - inputs_depset = depset( - copy_files_to_bin_actions(ctx, inputs), - transitive = transitive_inputs, - ) + inputs_depset = depset( + copy_files_to_bin_actions(ctx, inputs), + transitive = transitive_inputs, + ) + + if ctx.attr.no_emit: + verb = "Type-checking" + + # Validation actions still need to produce some output, so we output a .validation file + # that ends up in the _validation output group. + validation_output = ctx.actions.declare_file(ctx.attr.name + ".validation") + validation_outs.append(validation_output) + + if supports_workers: + arguments.add_all(["--bazelValidationFile", validation_output.short_path]) + ctx.actions.run_shell( + command = "{} $@".format(executable.path), + tools = [executable], + inputs = inputs_depset, + arguments = [arguments, "--noEmit"], + outputs = outputs + [validation_output], + mnemonic = "TsProject", + execution_requirements = execution_requirements, + resource_set = resource_set(ctx.attr), + progress_message = "%s TypeScript project %s [tsc -p %s]" % ( + verb, + ctx.label, + tsconfig_path, + ), + env = { + "BAZEL_BINDIR": ctx.bin_dir.path, + "JS_BINARY__STDOUT_OUTPUT_FILE": validation_output.path, + }, + ) + elif len(outputs) > 0: if ctx.attr.transpile != 0 and not ctx.attr.emit_declaration_only: # Make sure the user has acknowledged that transpiling is slow if ctx.attr.transpile == -1 and not options.default_to_tsc_transpiler: diff --git a/ts/private/ts_project_options_validator.js b/ts/private/ts_project_options_validator.js index 336e0047..9a67c69a 100755 --- a/ts/private/ts_project_options_validator.js +++ b/ts/private/ts_project_options_validator.js @@ -131,25 +131,6 @@ function main(_a) { ) } } - if (options.noEmit) { - console.error( - 'ERROR: ts_project rule ' + - target + - " cannot be built because the 'noEmit' option is specified in the tsconfig." - ) - console.error( - 'This is not compatible with ts_project, which always produces outputs.' - ) - console.error( - '- If you mean to only typecheck the code, use the tsc_test rule instead.' + - ' (see https://github.com/aspect-build/rules_ts/tree/main/examples/typecheck_only)' - ) - console.error(' (See the Alternatives section in the documentation.)') - console.error( - '- Otherwise, remove the noEmit option from tsconfig and try again.' - ) - return 1 - } if (options.preserveSymlinks) { console.error( 'ERROR: ts_project rule ' + @@ -163,6 +144,7 @@ function main(_a) { } check('allowJs', 'allow_js') check('declarationMap', 'declaration_map') + check('noEmit', 'no_emit') check('emitDeclarationOnly', 'emit_declaration_only') check('resolveJsonModule', 'resolve_json_module') check('sourceMap', 'source_map') @@ -211,6 +193,8 @@ function main(_a) { attrs.incremental + '\n// source_map: ' + attrs.source_map + + '\n// no_emit: ' + + attrs.no_emit + '\n// emit_declaration_only: ' + attrs.emit_declaration_only + '\n// ts_build_info_file: ' + diff --git a/ts/private/ts_project_worker.js b/ts/private/ts_project_worker.js index 71432ab4..4fa24de3 100644 --- a/ts/private/ts_project_worker.js +++ b/ts/private/ts_project_worker.js @@ -880,6 +880,9 @@ async function emit(request) { debug(`# Beginning new work`); debug(`arguments: ${request.arguments.join(' ')}`) + const validationPath = request.arguments[request.arguments.indexOf('--bazelValidationFile') + 1] + fs.writeFileSync(path.resolve(process.cwd(), validationPath), ''); + const inputs = Object.fromEntries( request.inputs.map(input => [ input.path, @@ -992,6 +995,12 @@ if (require.main === module && worker_protocol.isPersistentWorker(process.argv)) p = path.resolve('..', '..', '..', p.slice(1)); } const args = fs.readFileSync(p).toString().trim().split('\n'); + + if (args.includes('--bazelValidationFile')) { + const [, validationPath] = args.splice(args.indexOf('--bazelValidationFile'), 2); + fs.writeFileSync(path.resolve(process.cwd(), validationPath), ''); + } + ts.sys.args = process.argv = [process.argv0, process.argv[1], ...args]; execute(ts.sys, ts.noop, args); } diff --git a/ts/private/ts_validate_options.bzl b/ts/private/ts_validate_options.bzl index 09183601..793ea490 100644 --- a/ts/private/ts_validate_options.bzl +++ b/ts/private/ts_validate_options.bzl @@ -20,9 +20,7 @@ def _tsconfig_inputs(ctx): def _validate_action(ctx, tsconfig_inputs): # Bazel validation actions must still produce an output file. - # Choose to make it a .d.ts file so it's possible to plumb it to the deps of the ts_project compile, - # even though validation action outputs don't need to be used anywhere. - marker = ctx.actions.declare_file("%s.optionsvalid.d.ts" % ctx.label.name) + marker = ctx.actions.declare_file("%s_params.validation" % ctx.label.name) tsconfig = copy_file_to_bin_action(ctx, ctx.file.tsconfig) arguments = ctx.actions.args() @@ -32,6 +30,7 @@ def _validate_action(ctx, tsconfig_inputs): declaration_map = ctx.attr.declaration_map, preserve_jsx = ctx.attr.preserve_jsx, composite = ctx.attr.composite, + no_emit = ctx.attr.no_emit, emit_declaration_only = ctx.attr.emit_declaration_only, resolve_json_module = ctx.attr.resolve_json_module, source_map = ctx.attr.source_map, diff --git a/ts/test/mock_transpiler.bzl b/ts/test/mock_transpiler.bzl index 5f141558..37d041f2 100644 --- a/ts/test/mock_transpiler.bzl +++ b/ts/test/mock_transpiler.bzl @@ -53,7 +53,7 @@ def mock(name, srcs, source_map = False, **kwargs): srcs = srcs, # Calculate pre-declared outputs so they can be referenced as targets. # This is an optional transpiler feature aligning with the default tsc transpiler. - js_outs = lib.calculate_js_outs(srcs, ".", ".", False, False, False, False), - map_outs = lib.calculate_map_outs(srcs, ".", ".", True, False, False) if source_map else [], + js_outs = lib.calculate_js_outs(srcs, ".", ".", False, False, False, False, False), + map_outs = lib.calculate_map_outs(srcs, ".", ".", True, False, False, False) if source_map else [], **kwargs )