Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Bun: fix issue with sourcemap shim#346

Merged
jhaynie merged 1 commit intomainfrom
fix-bun-sourcemap
May 24, 2025
Merged

Bun: fix issue with sourcemap shim#346
jhaynie merged 1 commit intomainfrom
fix-bun-sourcemap

Conversation

@jhaynie
Copy link
Copy Markdown
Member

@jhaynie jhaynie commented May 24, 2025

in production, the bundle isn't included correctly

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of source map support for projects using the "bunjs" runtime, ensuring more reliable debugging.
  • Refactor
    • Streamlined the bundling process for JavaScript, resulting in more maintainable and efficient internal plugin logic.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 24, 2025

Walkthrough

The changes update the JavaScript bundling workflow to handle source map shimming internally within a plugin. The createPlugin function now takes additional parameters for the directory and a shim flag, and registers an extra handler when shimming is needed. The explicit post-build shim string logic has been removed from the build options.

Changes

File(s) Change Summary
internal/bundler/bundler.go Refactored to use a shimSourceMap flag and pass directory and flag to createPlugin; removed post-build shim string logic.
internal/bundler/patch.go Updated createPlugin to accept directory and shim flag; registers extra OnLoad handler for source map shimming when needed.

Poem

In the warren where code is spun,
The bundler's dance is nearly done.
No more shims tacked on with glue—
Now plugins know just what to do!
With flags and paths, they hop along,
Making source maps neat and strong.
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e18a483 and 1ad8596.

📒 Files selected for processing (2)
  • internal/bundler/bundler.go (2 hunks)
  • internal/bundler/patch.go (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
internal/bundler/bundler.go (1)
internal/project/project.go (1)
  • Bundler (456-465)
🔇 Additional comments (7)
internal/bundler/patch.go (3)

6-6: LGTM: Import added for path operations.

The path import is appropriately added to support the path.Join operation used in the new shimming logic.


72-72:

Details

✅ Verification successful

Verify function signature change is consistent across codebase.

The function signature has been updated to accept additional parameters. This is a breaking change that requires all call sites to be updated.

I can see from the bundler.go file that the call site has been updated, but let me verify there are no other usages:


🏁 Script executed:

#!/bin/bash
# Description: Verify all calls to createPlugin have been updated to match the new signature
# Expected: Only the updated call in bundler.go should be found

rg -A 3 "createPlugin\(" --type go

Length of output: 599


✅ createPlugin signature update verified

A repo-wide search for createPlugin( reveals only one usage in internal/bundler/bundler.go, which has already been updated to:

createPlugin(ctx.Logger, dir, shimSourceMap)

No other call sites exist—no further changes are required.


76-90:

Details

✅ Verification successful

Verify sourceMapShim variable is defined and accessible.

The new shimming logic looks well-structured, but it references sourceMapShim which is not defined in this file. Please ensure this variable is accessible in the current scope.


🏁 Script executed:

#!/bin/bash
# Description: Find the definition of sourceMapShim variable
# Expected: Should find where sourceMapShim is defined

rg "sourceMapShim" --type go -B 2 -A 2

Length of output: 644


sourceMapShim is already defined and accessible

The sourceMapShim variable is declared in internal/bundler/shim.go as:

// NOTE: this shim is only used in bun since node has built-in source map support
var sourceMapShim = `…
(function () {
  const { SourceMapConsumer… } = require('source-map-js');

})();
`

Since both shim.go and patch.go reside in the same internal/bundler package, sourceMapShim is in scope and no further action is needed.

internal/bundler/bundler.go (4)

156-156: LGTM: Clean variable initialization.

The shimSourceMap boolean variable is properly initialized to false, providing a clear default state.


162-162: LGTM: Conditional shimming for Bun runtime.

Setting shimSourceMap = true specifically for the "bunjs" runtime after ensuring source-map-js is installed is a logical approach that aligns with Bun's specific requirements for source map handling.


235-235: LGTM: Function call updated to match new signature.

The createPlugin call correctly passes the new parameters (dir and shimSourceMap) that match the updated function signature in patch.go.


239-239:

Details

✅ Verification successful

Verify that removing postShim doesn't break existing functionality.

The Banner field has been simplified to exclude postShim, which suggests the source map shimming logic has been moved from a post-build banner approach to the plugin-based approach. This architectural change looks sound, but please verify that no existing functionality is broken.


🏁 Script executed:

#!/bin/bash
# Description: Search for any remaining references to postShim to ensure it's been properly removed
# Expected: Should find minimal or no references if the migration is complete

rg "postShim" --type go -B 2 -A 2

Length of output: 33


🏁 Script executed:

#!/bin/bash
# Search for any remaining references to postShim across the entire repository
rg -n "postShim"

Length of output: 16


postShim removal verified

A repository-wide search shows no remaining references to postShim, confirming it has been fully removed in favor of the plugin-based approach. Everything looks in order—please ensure the existing test suite (and any end-to-end tests) passes to catch any integration regressions.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@jhaynie jhaynie merged commit 1633cea into main May 24, 2025
14 checks passed
@jhaynie jhaynie deleted the fix-bun-sourcemap branch May 24, 2025 03:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant