rules_swc
rules_swc copied to clipboard
[Bug]: When using a wrapped `swc` transpiler in a `ts_project`, source maps are wrong.
What happened?
I'm using something simple like this in order to produce source_maps:
This file is in a BUILD.bazel
in a folder hello
ts_project(
name = "lib",
srcs = glob([
"src/**/*.ts",
]),
declaration = True,
declaration_map = True,
source_map = True,
transpiler = partial.make(
swc,
source_maps = True,
swcrc = ":.swcrc",
),
tsconfig = "tsconfig",
validate = True,
visibility = ["//visibility:public"],
deps = [
":node_modules",
],
)
It produce:
{
"version":3,
"sources":[
"index.ts"
],
...
}
Where it should be:
{
"version":3,
"sources":[
"src/index.ts"
],
"sourceRoot": "hello"
...
}
Version
Development (host) and target OS/architectures:
Output of bazel --version
:
6.4.0
Version of the Aspect rules, or other relevant rules from your
WORKSPACE
or MODULE.bazel
file:
http_archive(
name = "rules_nodejs",
sha256 = "162f4adfd719ba42b8a6f16030a20f434dc110c65dc608660ef7b3411c9873f9",
strip_prefix = "rules_nodejs-6.0.2",
url = "https://github.com/bazelbuild/rules_nodejs/releases/download/v6.0.2/rules_nodejs-v6.0.2.tar.gz",
)
http_archive(
name = "aspect_rules_swc",
sha256 = "8eb9e42ed166f20cacedfdb22d8d5b31156352eac190fc3347db55603745a2d8",
strip_prefix = "rules_swc-1.1.0",
url = "https://github.com/aspect-build/rules_swc/releases/download/v1.1.0/rules_swc-v1.1.0.tar.gz",
)
http_archive(
name = "aspect_rules_ts",
sha256 = "bd3e7b17e677d2b8ba1bac3862f0f238ab16edb3e43fb0f0b9308649ea58a2ad",
strip_prefix = "rules_ts-2.1.0",
url = "https://github.com/aspect-build/rules_ts/releases/download/v2.1.0/rules_ts-v2.1.0.tar.gz",
)
http_archive(
name = "aspect_rules_js",
sha256 = "76a04ef2120ee00231d85d1ff012ede23963733339ad8db81f590791a031f643",
strip_prefix = "rules_js-1.34.1",
url = "https://github.com/aspect-build/rules_js/releases/download/v1.34.1/rules_js-v1.34.1.tar.gz",
)
Language(s) and/or frameworks involved:
How to reproduce
No response
Any other information?
No response
You can set sourceRoot with:
swc( ... source_root = package_name() # or native.package_name() in macros )
However I haven't solved the missing path in the sources array
Actually, this commit made it work for me: https://github.com/aspect-build/rules_swc/compare/main...pat-trunk-io:rules_swc:pat/FixSourcesArraySourceMap
@pat-trunk-io that fix looks correct, would you like to open a PR in rules_swc? A test showing it's fixed would also be great if you can add one? Or if your fix breaks an existing test maybe the existing one just needs an update. See the tests that have a *.map.golden
file and try using one of those to demo the fix 👍
Sounds good. Little busy this week, should be able to get around next week.