Skip to content

Commit

Permalink
fix aspect-build#250: add runtime inputs (js, json) to output sources
Browse files Browse the repository at this point in the history
  • Loading branch information
gzm0 authored and alexeagle committed Apr 28, 2023
1 parent 12012a4 commit ec5b0e1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions examples/resolve_json_module/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
)
16 changes: 16 additions & 0 deletions ts/private/ts_project.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit ec5b0e1

Please sign in to comment.