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

[Bug]: When using a wrapped swc transpiler in a ts_project, source maps are wrong. #222

Open
supercairos opened this issue Dec 11, 2023 · 4 comments
Labels
bug Something isn't working untriaged Requires traige

Comments

@supercairos
Copy link

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

@supercairos supercairos added the bug Something isn't working label Dec 11, 2023
@github-actions github-actions bot added the untriaged Requires traige label Dec 11, 2023
@pat-trunk-io
Copy link

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

@pat-trunk-io
Copy link

Actually, this commit made it work for me:
main...pat-trunk-io:rules_swc:pat/FixSourcesArraySourceMap

@jbedard
Copy link
Member

jbedard commented Feb 27, 2024

@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 👍

@pat-trunk-io
Copy link

Sounds good.
Little busy this week, should be able to get around next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working untriaged Requires traige
Projects
Status: No status
Development

No branches or pull requests

3 participants