diff --git a/examples/srcs_targets/BUILD.bazel b/examples/srcs_targets/BUILD.bazel new file mode 100644 index 00000000..31991bc1 --- /dev/null +++ b/examples/srcs_targets/BUILD.bazel @@ -0,0 +1,51 @@ +"""Shows different ways to pass source files into ts_project""" + +load("@aspect_rules_ts//ts:defs.bzl", "ts_project") +load("@bazel_skylib//rules:build_test.bzl", "build_test") +load("@bazel_skylib//rules:write_file.bzl", "write_file") + +[ + write_file( + name = "gen-%s-ts" % n, + out = "%s.ts" % n, + content = [ + "export const %s = 42" % n, + ], + ) + for n in [ + "a", + "b", + "c", + "d", + "e", + ] +] + +# Various ways of declaring sources +ts_project( + name = "out-refs", + srcs = [ + # Labels of various syntaxes to files + "a.ts", + ":b.ts", + "//%s:c.ts" % package_name(), + "@//%s:d.ts" % package_name(), + "@aspect_rules_ts//%s:e.ts" % package_name(), + + # Label to some rules + ":gen-a-ts", + ], + out_dir = "out", +) + +build_test( + name = "test", + targets = [ + "out-refs", + "out/a.js", + "out/b.js", + "out/c.js", + "out/d.js", + "out/e.js", + ], +) diff --git a/examples/srcs_targets/tsconfig.json b/examples/srcs_targets/tsconfig.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/examples/srcs_targets/tsconfig.json @@ -0,0 +1 @@ +{} diff --git a/ts/private/ts_lib.bzl b/ts/private/ts_lib.bzl index 8cfcabea..326666b3 100644 --- a/ts/private/ts_lib.bzl +++ b/ts/private/ts_lib.bzl @@ -201,6 +201,7 @@ def _replace_ext(f, ext_map): return None def _to_out_path(f, out_dir, root_dir): + f = f[f.find(":") + 1:] if root_dir: f = f.removeprefix(root_dir + "/") if out_dir: