rules_ts
rules_ts copied to clipboard
[Bug]: Transpiled TS conflicts with js_binary
What happened?
Moving from rules_ts-1.0.0-rc4 to a newer release fails if there's transpiled TS used as the entry_point
for a js_binary
:
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
load("@aspect_rules_swc//swc:defs.bzl", "swc_transpiler")
load("@bazel_skylib//lib:partial.bzl", "partial")
load("@aspect_rules_js//js:defs.bzl", "js_binary")
ts_project(
name = "src",
srcs = [
"src.ts",
],
declaration = True,
transpiler = partial.make(
swc_transpiler,
),
tsconfig = "//:tsconfig",
deps = [
"//:node_modules/@types/node",
],
)
js_binary(
name = "src-bin",
entry_point = ":src.js",
)
It looks like there's some kind of conflict with the anticipated output files:
ERROR: file 'src/src.js' is generated by these conflicting actions:
Label: //src:src_transpile, //src:src-bin
RuleClass: swc_transpiler rule, js_binary rule
Configuration: 8c7c8a83495a6b29f5e61b94373e857884c6b6f4ed04fcd868a9a81a5d062e34
Mnemonic: SWCTranspile, CopyFile
Action key: de389923a7de025ef490f7e6b9a234d395f1f6ecb01641df70f2ff4f0cba0cc9, 198c8d00c9d14a3e2ca1aa96583f202cabc88d60e6bf360e2eedd6182abb11df
Progress message: Transpiling with swc //src:src_transpile [swc bazel-out/darwin_arm64-fastbuild/bin/src/src.ts], Copying file src/src.js
PrimaryInput: File:[[<execution_root>]bazel-out/darwin_arm64-fastbuild/bin]src/src.ts, File:[/[path]/repro/ts-build-bug-repro[source]]src/src.js
PrimaryOutput: File:[[<execution_root>]bazel-out/darwin_arm64-fastbuild/bin]src/src.js
ERROR: com.google.devtools.build.lib.skyframe.ArtifactConflictFinder$ConflictException: com.google.devtools.build.lib.actions.MutableActionGraph$ActionConflictException: for src/src.js, previous action: action 'Copying file src/src.js', attempted action: action 'Transpiling with swc //src:src_transpile [swc bazel-out/darwin_arm64-fastbuild/bin/src/src.ts]'
Version
Development (host) and target OS/architectures:
Output of bazel --version
: Bazel 5.3.2
Version of the Aspect rules, or other relevant rules from your
WORKSPACE
or MODULE.bazel
file: rules_ts-1.0.X
Language(s) and/or frameworks involved: SWC, JS, TS.
How to reproduce
I made a repro over at https://github.com/paullewis/ts-build-bug-repro.
Any other information?
No response
Fund our work
- [ ] Sponsor our open source work by donating a bug bounty
Hmm, it doesn't happen unless SWC is set as the transpiler, interestingly enough 🤔
There's been a breaking change in the way the transpiler attribute worked. @jbedard might have the answer
I think you just need to use the swc macro rather than the underlying swc_transpiler function.
@alexeagle is right. You need to use the swc
macro now in rules_ts so that you get a pre-declared output label for ":src.js"
. When using swc_transpiler
there is no pre-delcared src.js
output label so Bazel thinks that :src.js
is a source file. Sadly, instead of saying the source file doesn't exist, which would be a nice error message, bazel fails because js_binary
creates a copy_to_bin
action on the non-existant src.js
to get it into the output tree and the output of that actions conflicts with the output of ts_project
creating src.js
in the output tree.
If you change your load statement to
load("@aspect_rules_swc//swc:defs.bzl", "swc")
and use that as the transpiler
then it should work
Oh I seeeeee - thank you! I'll close this one then 👍🏻
Reopening just to see if there's something we can do to improve the error messaging, or maybe avoid that accidental copy_to_bin that makes the symptom (a collision) so unrelated to the cause (a thing that wasn't declared).