Skip to content

Commit

Permalink
fix: remove predeclared asset outputs (#586)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedard authored and gregmagolan committed May 21, 2024
1 parent 21b41be commit 71118ab
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 28 deletions.
9 changes: 4 additions & 5 deletions docs/rules.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 84 additions & 8 deletions examples/assets/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("@aspect_bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory")
load("@aspect_bazel_lib//lib:testing.bzl", "assert_outputs")
load("@aspect_rules_ts//ts:defs.bzl", "ts_config", "ts_project")
load("@bazel_skylib//rules:build_test.bzl", "build_test")

Expand Down Expand Up @@ -42,6 +44,84 @@ ts_project(
tsconfig = {"compilerOptions": {"outDir": "out"}},
)

filegroup(
name = "assets-filegroup",
srcs = [
"src/generated.json",
"src/styles.css",
],
)

ts_project(
name = "ts-out-target",
srcs = [
"src/index.ts",
],
assets = [":assets-filegroup"],
out_dir = "out-target",
tsconfig = ":config",
)

assert_outputs(
name = "ts-out-target_outputs_test",
actual = ":ts-out-target",
expected = [
"examples/assets/out-target/src/generated.json",
"examples/assets/out-target/src/index.js",
"examples/assets/out-target/src/styles.css",
],
)

copy_to_directory(
name = "assets-directory",
srcs = [
"src/generated.json",
"src/styles.css",
],
)

ts_project(
name = "ts-out-copy-target",
srcs = [
"src/index.ts",
],
assets = [":assets-filegroup"],
out_dir = "out-copy-target",
tsconfig = ":config",
)

assert_outputs(
name = "ts-out-copy-target_outputs_test",
actual = ":ts-out-copy-target",
expected = [
"examples/assets/out-copy-target/src/generated.json",
"examples/assets/out-copy-target/src/index.js",
"examples/assets/out-copy-target/src/styles.css",
],
)

ts_project(
name = "ts-out-copy-target-abs",
srcs = [
"src/index.ts",
],
assets = [
"//%s:assets-filegroup" % package_name(),
],
out_dir = "out-copy-target-abs",
tsconfig = ":config",
)

assert_outputs(
name = "ts-out-copy-target-abs_outputs_test",
actual = ":ts-out-copy-target-abs",
expected = [
"examples/assets/out-copy-target-abs/src/generated.json",
"examples/assets/out-copy-target-abs/src/index.js",
"examples/assets/out-copy-target-abs/src/styles.css",
],
)

ts_project(
name = "ts-root",
srcs = [
Expand Down Expand Up @@ -75,22 +155,18 @@ build_test(
# Defaults of no root/out_dir
":ts",
":src/index.js",
":src/styles.css",
":src/generated.json",
# out_dir
":ts-out",
":out/src/index.js",
":out/src/styles.css",
":out/src/generated.json",
# root_dir
":ts-root",
":index.js",
":styles.css",
":generated.json",
# root_dir + out_dir
":ts-root-out",
":root-out/index.js",
":root-out/styles.css",
":root-out/generated.json",
# asset targets instead of files
":ts-out-target",
":ts-out-copy-target",
":ts-out-copy-target-abs",
],
)
3 changes: 0 additions & 3 deletions ts/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,6 @@ def ts_project(
typings_out_dir = declaration_dir if declaration_dir else out_dir
tsbuildinfo_path = ts_build_info_file if ts_build_info_file else name + ".tsbuildinfo"

assets_outs = _lib.calculate_assets_outs(assets, out_dir, root_dir)

tsc_typings_outs = _lib.calculate_typings_outs(srcs, typings_out_dir, root_dir, declaration, composite, allow_js)
tsc_typing_maps_outs = _lib.calculate_typing_maps_outs(srcs, typings_out_dir, root_dir, declaration_map, allow_js)

Expand Down Expand Up @@ -416,7 +414,6 @@ def ts_project(
map_outs = tsc_map_outs,
typings_outs = tsc_typings_outs,
typing_maps_outs = tsc_typing_maps_outs,
assets_outs = assets_outs,
buildinfo_out = tsbuildinfo_path if composite or incremental else None,
emit_declaration_only = emit_declaration_only,
tsc = tsc,
Expand Down
12 changes: 0 additions & 12 deletions ts/private/ts_lib.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,6 @@ OUTPUT_ATTRS = {
"typings_outs": attr.output_list(
doc = "Locations in bazel-out where tsc will write `.d.ts` files",
),
"assets_outs": attr.output_list(
doc = "Locations in bazel-out where ts_project will output asset files",
),
}

def _join(*elements):
Expand Down Expand Up @@ -221,14 +218,6 @@ def _to_js_out_paths(srcs, out_dir, root_dir, allow_js, resolve_json_module, ext
outs.append(out)
return outs

def _calculate_assets_outs(assets, out_dir = ".", root_dir = "."):
outs = []
for a in assets:
out = _to_out_path(a, out_dir, root_dir)
if out != a:
outs.append(out)
return outs

# Quick check to validate path options
# One usecase: https://github.com/aspect-build/rules_ts/issues/551
def _validate_tsconfig_dirs(root_dir, out_dir, typings_out_dir):
Expand Down Expand Up @@ -332,5 +321,4 @@ lib = struct(
calculate_typings_outs = _calculate_typings_outs,
calculate_typing_maps_outs = _calculate_typing_maps_outs,
calculate_root_dir = _calculate_root_dir,
calculate_assets_outs = _calculate_assets_outs,
)

0 comments on commit 71118ab

Please sign in to comment.