diff --git a/docs/rules.md b/docs/rules.md index 98ca5708..d90c8b56 100644 --- a/docs/rules.md +++ b/docs/rules.md @@ -37,9 +37,9 @@ extended configuration file as well, to pass them both to the TypeScript compile ## ts_project_rule
-ts_project_rule(name, allow_js, args, assets, assets_outs, buildinfo_out, composite, data,
-                declaration, declaration_dir, declaration_map, deps, emit_declaration_only, extends,
-                incremental, is_typescript_5_or_greater, js_outs, map_outs, out_dir, preserve_jsx,
+ts_project_rule(name, allow_js, args, assets, buildinfo_out, composite, data, declaration,
+                declaration_dir, declaration_map, deps, emit_declaration_only, extends, incremental,
+                is_typescript_5_or_greater, js_outs, map_outs, out_dir, preserve_jsx,
                 resolve_json_module, root_dir, source_map, srcs, supports_workers, transpile,
                 ts_build_info_file, tsc, tsc_worker, tsconfig, typing_maps_outs, typings_outs,
                 validate, validator)
@@ -61,7 +61,6 @@ Implementation rule behind the ts_project macro.
 | allow_js |  https://www.typescriptlang.org/tsconfig#allowJs   | Boolean | optional | False |
 | args |  https://www.typescriptlang.org/docs/handbook/compiler-options.html   | List of strings | optional | [] |
 | assets |  Files which are needed by a downstream build step such as a bundler.

See more details on the assets parameter of the ts_project macro. | List of labels | optional | [] | -| assets_outs | Locations in bazel-out where ts_project will output asset files | List of labels | optional | | | buildinfo_out | Location in bazel-out where tsc will write a .tsbuildinfo file | Label | optional | | | composite | https://www.typescriptlang.org/tsconfig#composite | Boolean | optional | False | | data | Runtime dependencies to include in binaries/tests that depend on this target.

The transitive npm dependencies, transitive sources, default outputs and runfiles of targets in the data attribute are added to the runfiles of this target. They should appear in the '*.runfiles' area of any executable which has a runtime dependency on this target.

If this list contains linked npm packages, npm package store targets or other targets that provide JsInfo, NpmPackageStoreInfo providers are gathered from JsInfo. This is done directly from the npm_package_store_deps field of these. For linked npm package targets, the underlying npm_package_store target(s) that back the links is used. Gathered NpmPackageStoreInfo providers are propagated to the direct dependencies of downstream linked npm_package targets.

NB: Linked npm package targets that are "dev" dependencies do not forward their underlying npm_package_store target(s) through npm_package_store_deps and will therefore not be propagated to the direct dependencies of downstream linked npm_package targets. npm packages that come in from npm_translate_lock are considered "dev" dependencies if they are have dev: true set in the pnpm lock file. This should be all packages that are only listed as "devDependencies" in all package.json files within the pnpm workspace. This behavior is intentional to mimic how devDependencies work in published npm packages. | List of labels | optional | [] | diff --git a/examples/assets/BUILD.bazel b/examples/assets/BUILD.bazel index dbbf3fa0..3bc54c70 100644 --- a/examples/assets/BUILD.bazel +++ b/examples/assets/BUILD.bazel @@ -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") @@ -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 = [ @@ -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", ], ) diff --git a/ts/defs.bzl b/ts/defs.bzl index 356e1a60..5e35d080 100644 --- a/ts/defs.bzl +++ b/ts/defs.bzl @@ -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) @@ -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, diff --git a/ts/private/ts_lib.bzl b/ts/private/ts_lib.bzl index 8cfcabea..6fe60385 100644 --- a/ts/private/ts_lib.bzl +++ b/ts/private/ts_lib.bzl @@ -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): @@ -220,14 +217,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): @@ -331,5 +320,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, )