diff --git a/examples/simple/BUILD.bazel b/examples/simple/BUILD.bazel index cc96ab34..ef89b555 100644 --- a/examples/simple/BUILD.bazel +++ b/examples/simple/BUILD.bazel @@ -13,6 +13,7 @@ ts_project( # "." is the same as default # explicitly given as a regression test for https://github.com/aspect-build/rules_ts/issues/195 out_dir = ".", + visibility = ["//examples:__subpackages__"], # Note, the tsconfig attribute defaults to the tsconfig.json file in this directory. # tsconfig = "", deps = [ diff --git a/examples/srcs/BUILD.bazel b/examples/srcs/BUILD.bazel index a902f228..4e67fd3d 100644 --- a/examples/srcs/BUILD.bazel +++ b/examples/srcs/BUILD.bazel @@ -26,6 +26,39 @@ ts_project( out_dir = "filegroup", ) +ts_project( + name = "srcs-filegroup-gentsconfig", + srcs = [":srcs"], + tsconfig = { + "compilerOptions": { + "outDir": "filegroup-gentsconfig", + }, + }, +) + +ts_project( + name = "srcs-filegroup-sibling", + srcs = [ + ":srcs", + "//examples/simple:ts", + ], + out_dir = "filegroup-sibling", +) + +ts_project( + name = "srcs-filegroup-sibling-gentsconfig", + srcs = [ + ":srcs", + "//examples/simple:ts", + ], + tsconfig = { + "compilerOptions": { + "allowJs": True, + "outDir": "filegroup-sibling-gentsconfig", + }, + }, +) + # Tools can also generate .ts source files, so the sources are actually in the bazel-out tree. # This example just writes one directly but this could instead be some tool. write_file( @@ -47,6 +80,20 @@ ts_project( out_dir = "generated", ) +ts_project( + name = "srcs-generated-gentsconfig", + # Demonstrates that you can mix sources with generated files + srcs = [ + "a.ts", + "generated.ts", + ], + tsconfig = { + "compilerOptions": { + "outDir": "generated-gentsconfig", + }, + }, +) + # Testing what outputs are actually produced [ params_file( @@ -58,7 +105,11 @@ ts_project( for case in [ "auto", "filegroup", + "filegroup-gentsconfig", + "filegroup-sibling", + "filegroup-sibling-gentsconfig", "generated", + "generated-gentsconfig", ] ] @@ -71,7 +122,11 @@ ts_project( for case in [ "auto", "filegroup", + "filegroup-gentsconfig", + "filegroup-sibling", + "filegroup-sibling-gentsconfig", "generated", + "generated-gentsconfig", ] ] diff --git a/ts/private/ts_project.bzl b/ts/private/ts_project.bzl index 367bba07..cd50d879 100644 --- a/ts/private/ts_project.bzl +++ b/ts/private/ts_project.bzl @@ -79,6 +79,11 @@ def _ts_project_impl(ctx): validation_outs = [] if ctx.attr.validate: + package_slash = ctx.label.package + "/" + for src in srcs_inputs: + if not src.path.startswith(package_slash): + fail("ts_project(%s) src (%s) must be in the same package" % (ctx.label, src.path)) + validation_outs.extend(_validate_lib.validation_action(ctx, tsconfig_inputs)) _lib.validate_tsconfig_dirs(ctx.attr.root_dir, ctx.attr.out_dir, typings_out_dir)