From b1d987e4dc2f5cd02a1dd95c14b33f961855ae09 Mon Sep 17 00:00:00 2001 From: Jason Bedard Date: Fri, 18 Oct 2024 15:16:12 -0700 Subject: [PATCH] fix: do not declare _typecheck[_test] target when using tsc as transpiler Fix #719 --- examples/transpiler/BUILD.bazel | 34 ++++++++++++++++++++++++++++++--- examples/transpiler/tsc.bzl | 4 ++-- ts/defs.bzl | 2 +- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/examples/transpiler/BUILD.bazel b/examples/transpiler/BUILD.bazel index 540f1b20..6cb0cebe 100644 --- a/examples/transpiler/BUILD.bazel +++ b/examples/transpiler/BUILD.bazel @@ -84,7 +84,7 @@ build_test( targets = [ # babel ts_project ":babel", - ":babel_typecheck", + ":babel_types", # babel outputted js "big.js", # NOTE: does not implement out_dir in this test # tsc outputted dts @@ -122,6 +122,36 @@ build_test( ], ) +# custom js & dts transpilers, tsc will not run for typechecking when only requesting transpiled files. +# Tagging as manual should prevent the typecheck from running even when requesting +# transpiler output files. +ts_project( + name = "typecheck_fail-custom_transpilers", + srcs = ["typecheck_fail.ts"], + declaration = True, + declaration_transpiler = partial.make( + tsc_dts, + args = ["--noCheck"], + out_dir = "build-typecheck_fail-custom_transpilers", + ), + out_dir = "build-typecheck_fail-custom_transpilers", + source_map = True, + tags = ["manual"], + transpiler = partial.make( + tsc_js, + args = ["--noCheck"], + out_dir = "build-typecheck_fail-custom_transpilers", + ), +) + +build_test( + name = "typecheck_fail-custom_transpilers_test", + targets = [ + ":typecheck_fail-custom_transpilers", + ":typecheck_fail-custom_transpilers_types", + ], +) + # custom js & dts transpilers, tsc still run for typechecking ts_project( name = "custom_transpilers", @@ -214,7 +244,6 @@ build_test( targets = [ ":custom_dts_transpiler", ":custom_dts_transpiler_types", - ":custom_dts_transpiler_typecheck", "build-custom_dts_transpiler/a.js", "build-custom_dts_transpiler/a.d.ts", ], @@ -243,7 +272,6 @@ build_test( name = "custom_dts_transpiler-no_declarations-test", targets = [ ":custom_dts_transpiler-no_declarations", - ":custom_dts_transpiler-no_declarations_typecheck", "build-custom_dts_transpiler-no_declarations/a.js", ], ) diff --git a/examples/transpiler/tsc.bzl b/examples/transpiler/tsc.bzl index 5f8c6d4c..b2bd759e 100644 --- a/examples/transpiler/tsc.bzl +++ b/examples/transpiler/tsc.bzl @@ -8,7 +8,7 @@ def tsc_dts(name, srcs, out_dir, **kwargs): name = name, srcs = srcs + ["tsconfig.json"], outs = ["%s/%s" % (out_dir, src.replace(".ts", ".d.ts")) for src in srcs], - args = [ + args = kwargs.pop("args", []) + [ "-p %s/tsconfig.json" % native.package_name(), "--emitDeclarationOnly", "--outDir %s/%s" % (native.package_name(), out_dir), @@ -22,7 +22,7 @@ def tsc_js(name, srcs, out_dir, **kwargs): name = name, srcs = srcs + ["tsconfig.json"], outs = ["%s/%s" % (out_dir, src.replace(".ts", ".js")) for src in srcs], - args = [ + args = kwargs.pop("args", []) + [ "-p %s/tsconfig.json" % native.package_name(), "--declaration", "false", diff --git a/ts/defs.bzl b/ts/defs.bzl index 0ad506f7..5459eb65 100644 --- a/ts/defs.bzl +++ b/ts/defs.bzl @@ -385,7 +385,7 @@ def ts_project( ) # If the primary target does not output dts files then type-checking has a separate target. - if not emit_tsc_js or not emit_tsc_dts: + if not emit_tsc_js and not emit_tsc_dts: typecheck_target_name = "%s_typecheck" % name test_target_name = "%s_typecheck_test" % name