diff --git a/examples/assets/BUILD.bazel b/examples/assets/BUILD.bazel index 3bc54c70..c1996867 100644 --- a/examples/assets/BUILD.bazel +++ b/examples/assets/BUILD.bazel @@ -1,5 +1,6 @@ load("@aspect_bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory") load("@aspect_bazel_lib//lib:testing.bzl", "assert_outputs") +load("@aspect_rules_js//js:defs.bzl", "js_test") load("@aspect_rules_ts//ts:defs.bzl", "ts_config", "ts_project") load("@bazel_skylib//rules:build_test.bzl", "build_test") @@ -44,6 +45,34 @@ ts_project( tsconfig = {"compilerOptions": {"outDir": "out"}}, ) +ts_project( + name = "ts-runtime-assets", + srcs = ["src/index-runtime.ts"], + assets = ["src/generated.json"], + tsconfig = ":config", +) + +js_test( + name = "ts-runtime-assets_test", + data = [":ts-runtime-assets"], + entry_point = "src/index-runtime.js", +) + +ts_project( + name = "ts-runtime-outdir-assets", + srcs = ["src/index-runtime.ts"], + assets = ["src/generated.json"], + extends = ":config", + out_dir = "out", + tsconfig = {"compilerOptions": {"outDir": "out"}}, +) + +js_test( + name = "ts-runtime-outdir-assets_test", + data = [":ts-runtime-outdir-assets"], + entry_point = "out/src/index-runtime.js", +) + filegroup( name = "assets-filegroup", srcs = [ diff --git a/examples/assets/src/index-runtime.ts b/examples/assets/src/index-runtime.ts new file mode 100644 index 00000000..60d7069b --- /dev/null +++ b/examples/assets/src/index-runtime.ts @@ -0,0 +1,11 @@ +/** + * This testcase exists to verify assets get propagated correctly. It + * intentionally does not use `import` or `require` for the generated asset to + * more closely mimic what a downstream rule (eg. a bundler) would do. + */ +import * as fs from 'fs' +import * as path from 'path' + +const data = fs.readFileSync(path.join(__dirname, 'generated.json')) + +console.log(__dirname, data) diff --git a/ts/private/ts_project.bzl b/ts/private/ts_project.bzl index 367bba07..8b632798 100644 --- a/ts/private/ts_project.bzl +++ b/ts/private/ts_project.bzl @@ -167,6 +167,8 @@ See https://github.com/aspect-build/rules_ts/issues/361 for more details. asset = ctx.actions.declare_file(a_out) copy_file_action(ctx, a, asset) assets_outs.append(asset) + else: + assets_outs.append(a) outputs = js_outs + map_outs + typings_outs + typing_maps_outs if ctx.outputs.buildinfo_out: