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

fix: set sourcemap root to the workspace relative root_dir #176

Merged
merged 1 commit into from
Mar 6, 2023

Conversation

jbedard
Copy link
Member

@jbedard jbedard commented Mar 1, 2023

This makes the sourcemap sources and sourceRoot align with tsc (when invoked from ts_project EDIT: and not in a worker, and properly sandboxed, and probably other conditions for it to be the "normal" case). This is comparing a ts_project in silo, tsc vs swc

The sourcesContent is relative to the swc(root_dir), the sourceRoot is relative to the workspace root and includes the root_dir.

The map file sources is relative to the map, so when there is 1 .map per .js it is just the filename.
The sourceRoot is basically just a prefix and we just set it to what the user specifies (#177)

Copy link
Member

@thesayyn thesayyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be great to have a test where source_map_support is used.

swc/private/swc.bzl Outdated Show resolved Hide resolved
swc/private/swc.bzl Outdated Show resolved Hide resolved
Copy link
Member

@thesayyn thesayyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

examples/root_dir/BUILD.bazel Outdated Show resolved Hide resolved
examples/rc/src/expected.js.map Outdated Show resolved Hide resolved
@jbedard jbedard marked this pull request as draft March 2, 2023 17:49
@realtimetodie
Copy link
Contributor

I think this is a great solution and I added a small extra in #177. Let me know what you think.

@jbedard jbedard force-pushed the swc-sourcemap-paths branch 2 times, most recently from 10de226 to fac5edd Compare March 2, 2023 22:07
@jbedard jbedard requested a review from thesayyn March 2, 2023 22:08
@jbedard jbedard force-pushed the swc-sourcemap-paths branch 7 times, most recently from deb9794 to c52fdc0 Compare March 3, 2023 21:19
@alexeagle
Copy link
Member

Is this still draft, or is it ready to go?
Every time someone hits a TS worker bug I am dying to get rules_swc 1.0 out :)

@jbedard
Copy link
Member Author

jbedard commented Mar 4, 2023

I put it into draft state because @thesayyn wasn't sure about the paths, see the ugly second commit which I'd like him to review.

Essentially we have to navigate from the .map file, out of the out_dir, and back to the original source (potentially in a root_dir). If the map was referencing the original .js files this would be essential, but the map files we're generating have the source embedded so technically it's isn't required for nice stack traces... I think? 😬

Copy link
Member

@thesayyn thesayyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks awesome

@thesayyn thesayyn marked this pull request as ready for review March 6, 2023 13:29
@thesayyn thesayyn merged commit 0db4ce9 into main Mar 6, 2023
@thesayyn thesayyn deleted the swc-sourcemap-paths branch March 6, 2023 13:29
Copy link
Member

@alexeagle alexeagle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this broke Windows:

C:\tools\msys64\usr\bin\bash.exe -c external/aspect_rules_swc~override~swc~swc_win32-x64-msvc/swc-win32-x64-msvc.exe $@ < /dev/null  compile --source-maps false --source-file-name foo.ts --source-root  --config-file .swcrc --out-file bazel-out/x64_windows-fastbuild/bin/foo.js foo.ts
--
  | # Configuration: d00ace43f601efe48e0f1336609380be0dfba06ec5d3ce9d24364e336cd3c540
  | # Execution platform: @local_config_platform//:host
  | error: The argument '--source-root <SOURCE_ROOT>' requires a value but none was supplied

https://buildkite.com/bazel/bcr-presubmit/builds/1090#0186b799-ced5-4b38-8404-30c2129b62bb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

4 participants