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

feat(bundler): Add --sourcemap=linked for //# sourceMappingURL comments #11983

Merged
merged 5 commits into from
Jun 20, 2024

Conversation

paperclover
Copy link
Member

@paperclover paperclover commented Jun 19, 2024

What does this PR do?

This implements --sourcemap=linked exactly as esbuild does so. This also changes the default behavior of --sourcemap to linked nvm, it was inline and will stay inline. When using external sourcemaps, it is almost always a better idea to use linked sourcemaps, as that is what browsers and most tooling supports. Having unlinked external sourcemaps (--sourcemap=external) can be useful for proprietary codebases where the source map and the bundled code are meant to be isolated.

For more context, see https://esbuild.github.io/api/#sourcemap

also fixes this disabled test because some of these chars are hex lowercase which is silly.
image

Fixes #3325
Fixes #9314

@paperclover
Copy link
Member Author

wuh image

Copy link
Contributor

github-actions bot commented Jun 20, 2024

@paperdave, your commit has failing tests :(

💪 1 failing tests Darwin AARCH64

  • test/js/bun/io/bun-write.test.js 1 failing

🐧🖥 1 failing tests Linux x64

  • test/js/web/workers/worker.test.ts 1 failing

🪟💻 4 failing tests Windows x64 baseline

  • test/cli/install/registry/bun-install-registry.test.ts 1 failing
  • test/integration/next-pages/test/dev-server.test.ts 1 failing
  • test/integration/next-pages/test/next-build.test.ts 1 failing
  • test/js/bun/http/serve-body-leak.test.ts 1 failing

🪟💻 1 failing tests Windows x64

  • test/integration/next-pages/test/dev-server.test.ts 1 failing

View logs

@@ -9336,12 +9336,27 @@ const LinkerContext = struct {
);

switch (c.options.source_maps) {
.external => {
inline .external, .linked => |tag| {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this need the inline?

Suggested change
inline .external, .linked => |tag| {
.external, .linked => |tag| {

Copy link
Member Author

Choose a reason for hiding this comment

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

this makes tag comptime, which is what it is being used in the if. i guess that isn't strictly needed for this use-case. i can remove.

@@ -9520,13 +9535,26 @@ const LinkerContext = struct {
);

switch (c.options.source_maps) {
.external => {
inline .external, .linked => |tag| {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this need the inline?

Suggested change
inline .external, .linked => |tag| {
.external, .linked => |tag| {

@Jarred-Sumner
Copy link
Collaborator

What about public_path?

@Jarred-Sumner
Copy link
Collaborator

Jarred-Sumner commented Jun 20, 2024

We're probably also going to want to allow a different base url as an option for sourcemaps, like --sourcemap-url=${path}. I remember at Stripe they put the sourcemaps on a corporate-only subdomain so that any employee connected to the VPN could access them easily, but it remained internal otherwise

@Jarred-Sumner
Copy link
Collaborator

IMO, the behavior should be:

  • If --outdir is specified, --sourcemap means linked
  • If --outdir is not specified, --sourcemap means inline

@paperclover
Copy link
Member Author

What about public_path?

ah, yeah that should be handled. i overlooked that.

I remember at Stripe they ...

that makes sense, but i would recommend for cases like this to use --sourcemap=external, which would not put the URL in at all outside of debug builds. This seems to be what stripe.com does (sourceMappingURL does not appear in their JS bundles)

IMO, the behavior should be: [behavior]

Ok. It will be a bit extra to document but we can do that. I was hesitant to change defaults much. I think this will "just work" for most people, but it does feel a bit odd to have it vary in this way (i like what esbuild does, but that would be a breaking api change for us).

@paperclover paperclover self-assigned this Jun 20, 2024
@paperclover
Copy link
Member Author

We're probably also going to want to allow a different base url as an option for sourcemaps, like --sourcemap-url

I don't think that is necessary, since esbuild doesn't have this. We maybe want to add --source-root, but anything else we should just wait for users to feature-request.

@Jarred-Sumner Jarred-Sumner merged commit e58cf69 into main Jun 20, 2024
48 of 53 checks passed
@Jarred-Sumner Jarred-Sumner deleted the dave/source-map-url branch June 20, 2024 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bun build linked sourcemap option Sourcemaps should contain sourceMappingURL
2 participants