diff --git a/examples/resolve_json_module/BUILD.bazel b/examples/resolve_json_module/BUILD.bazel index 9a2b20d7..1b8c9eab 100644 --- a/examples/resolve_json_module/BUILD.bazel +++ b/examples/resolve_json_module/BUILD.bazel @@ -2,6 +2,7 @@ load("@aspect_bazel_lib//lib:testing.bzl", "assert_contains") load("@aspect_rules_ts//ts:defs.bzl", "ts_project") +load("@aspect_rules_js//js:defs.bzl", "js_test") ts_project( name = "ts", @@ -17,3 +18,10 @@ assert_contains( actual = "index.js", expected = """JSON.stringify(data_json_1["default"])""", ) + +js_test( + # Test that the json is available at runtime. + name = "ts-with-json", + data = [":ts"], + entry_point = "index.js", +) diff --git a/ts/private/ts_project.bzl b/ts/private/ts_project.bzl index a51a216f..7f567c02 100644 --- a/ts/private/ts_project.bzl +++ b/ts/private/ts_project.bzl @@ -152,7 +152,23 @@ See https://github.com/aspect-build/rules_ts/issues/361 for more details. to_output_relative_path(ctx.outputs.buildinfo_out), ]) outputs.append(ctx.outputs.buildinfo_out) + output_sources = js_outs + map_outs + copy_files_to_bin_actions(ctx, ctx.files.assets) + + # Add JS inputs that collide with outputs (see #250). + # + # Unfortunately this duplicates logic in ts_lib._out_paths: + # files collide iff the following conditions are met: + # - They are JS files (ext in [js, json]) + # - out_dir == root_dir + # + # The duplication is hard to avoid, since out_paths works on path strings + # (so it also works in the macro), but we need Files here. + if ctx.attr.out_dir == ctx.attr.root_dir: + for s in srcs_inputs: + if _lib.is_js_src(s.path, ctx.attr.allow_js, ctx.attr.resolve_json_module): + output_sources.append(s) + typings_srcs = [s for s in srcs_inputs if _lib.is_typings_src(s.path)] if len(js_outs) + len(typings_outs) < 1: