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: load sourcemaps at runtime when using a bun build --target=bun bundle #10998

Merged
merged 24 commits into from May 21, 2024

Conversation

paperdave
Copy link
Collaborator

@paperdave paperdave commented May 11, 2024

This makes it so when using sourcemaps with bun build --target=bun, those maps actually get loaded and used for errors:
image

The main api change to our sourcemap functions is you can now specify an intent for resolving mappings, one that includes source code information, and one that does not.

 if (this.source_mappings.resolveMapping(
     source_url.slice(),
     @max(frame.position.line, 0),
     @max(frame.position.column_start, 0),
+    .no_source_contents,
 )) |lookup| {

This was not needed before because we assumed the source is always the untranspiled code. But with --target=bun and it's // @bun annotation, the untranspiled code IS the transpiled code, and the source is stored in the sourcemap.

We are not ready yet:

  • Why is filename still not remapped.
  • Verify error.stack works
  • Support loading external sourcemaps by checking for a .map file
  • Resolve TODO in ZigSourceProvider__getSourceSlice
  • Resolve TODO getSourceCode() returns null
  • Resolve TODO in getSourceCode, this is when you load a sourcemap without file contents but then later need them.
  • Resolve TODOs in toParsedSourceMap.

@paperdave paperdave changed the title Dave/runtime sourcemap feat: load sourcemaps at runtime when using a bun build --target=bun bundle May 11, 2024
src/sourcemap/sourcemap.zig Outdated Show resolved Hide resolved
@@ -3825,4 +3890,12 @@ pub fn NewHotReloader(comptime Ctx: type, comptime EventLoopType: type, comptime
};
}

export fn Bun__addSourceProviderSourceMap(bun_vm: *anyopaque, opaque_source_provider: *anyopaque, specifier: *bun.String) void {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

*anyopaque -> VirtualMachine

@Jarred-Sumner
Copy link
Collaborator

Needs a test that does hot reloading with source maps enabled and makes sure it doesn't crash due to ref/unref of SourceProvider

@Jarred-Sumner
Copy link
Collaborator

Also needs a test for Bun.inspect on // @bun'd file

@paperdave paperdave marked this pull request as ready for review May 14, 2024 01:44
Copy link

github-actions bot commented May 15, 2024

@paperdave, your commit has failing tests :(

💪 3 failing tests Darwin AARCH64

💻 2 failing tests Darwin x64 baseline

💻 3 failing tests Darwin x64

🐧🖥 2 failing tests Linux x64

🪟💻 13 failing tests Windows x64 baseline

🪟💻 11 failing tests Windows x64

View logs

src/string.zig Outdated Show resolved Hide resolved
@paperdave
Copy link
Collaborator Author

paperdave commented May 15, 2024

Followup TODO:

  • Prevent source contents from staying in memory forever

@Jarred-Sumner
Copy link
Collaborator

@paperdave the windows tests are timing out?

@paperdave paperdave merged commit e98c235 into main May 21, 2024
23 checks passed
@paperdave paperdave deleted the dave/runtime-sourcemap branch May 21, 2024 21:41
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.

None yet

2 participants