Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ts_project: ensure assets get propagated #742

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions examples/assets/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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")

Expand Down Expand Up @@ -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 = [
Expand Down
11 changes: 11 additions & 0 deletions examples/assets/src/index-runtime.ts
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions ts/private/ts_project.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading