Skip to content

fix: bundle sourcemap output#95

Merged
leegeunhyeok merged 1 commit into
rollipop-dev:mainfrom
jingjing2222:codex/fix-sourcemap-output
Jun 1, 2026
Merged

fix: bundle sourcemap output#95
leegeunhyeok merged 1 commit into
rollipop-dev:mainfrom
jingjing2222:codex/fix-sourcemap-output

Conversation

@jingjing2222

@jingjing2222 jingjing2222 commented May 31, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Enable sourcemap generation when the bundle CLI receives --sourcemap-output
  • Add coverage for the bundle command action so the CLI forwards sourcemap: true only when a sourcemap output path is provided
  • Add a patch changeset for rollipop

Root Cause

React Native Gradle already passes a sourcemap output path to the JavaScript bundler. The missing piece was inside Rollipop: the parsed --sourcemap-output value was forwarded as sourcemapOutfile, but it was not also treated as a request to generate sourcemaps.

End-to-end flow

  1. React Native Gradle registers a bundle task for non-debuggable variants.

    TaskConfiguration.kt registers createBundle${targetName}JsAndAssets as a BundleHermesCTask.

    For a normal Android release variant, that becomes:

    :app:createBundleReleaseJsAndAssets
    
  2. BundleHermesCTask.run() computes the JavaScript bundle output and packager sourcemap output.

    In Hermes builds, the first sourcemap expected from the JS bundler is the packager sourcemap:

    android/app/build/intermediates/sourcemaps/react/release/index.android.bundle.packager.map
    
  3. BundleHermesCTask.getBundleCommand() builds the React Native CLI command and includes --sourcemap-output.

    The relevant arguments are assembled like this:

    node
    <react-native>/cli.js
    bundle
    --platform android
    --dev false
    --reset-cache
    --entry-file <app>/index.js
    --bundle-output <app>/android/app/build/generated/assets/react/release/index.android.bundle
    --assets-dest <app>/android/app/build/generated/res/react/release
    --sourcemap-output <app>/android/app/build/intermediates/sourcemaps/react/release/index.android.bundle.packager.map
    --minify false
    --verbose
    
  4. Gradle executes that exact command with execOperations.exec { exec.commandLine(command) }.

    So by the time the JS CLI starts, the sourcemap output path is already present in argv. This is not a Gradle configuration issue.

  5. Apps can replace React Native CLI commands via react-native.config.js.

    A Rollipop app typically exposes:

    module.exports = {
      commands: require('rollipop/commands'),
    };

    That means React Native CLI dispatches the bundle command to Rollipop's React Native CLI command wrapper.

  6. Rollipop defines and parses --sourcemap-output <string> as options.sourcemapOutput.

    Before this change, the Rollipop bundle action passed that value only as:

    sourcemapOutfile: options.sourcemapOutput,

    It did not pass:

    sourcemap: true,
  7. Bundler.build() later decides the final Rolldown sourcemap option from resolvedBuildOptions.sourcemap.

    Existing code normalizes it to a boolean:

    const sourcemap = resolvedBuildOptions.sourcemap ? true : false;

    With --sourcemap-output alone, resolvedBuildOptions.sourcemap is undefined, so Rollipop sends output.sourcemap = false to Rolldown.

  8. Because Rolldown receives sourcemap: false, it does not emit a .map file and the output chunk has no sourcemapFileName.

    Rollipop has later code that can move the generated map to sourcemapOutfile, but that branch requires chunk.sourcemapFileName. Since no map was generated, there is nothing to move.

  9. In Hermes builds, React Native Gradle then tries to compose the packager sourcemap with the Hermes compiler sourcemap.

    The expected packager file is missing:

    android/app/build/intermediates/sourcemaps/react/release/index.android.bundle.packager.map
    

    Therefore the final composed sourcemap cannot be produced correctly:

    android/app/build/generated/sourcemaps/react/release/index.android.bundle.map
    

Fix

When options.sourcemapOutput is present, the bundle action now forwards sourcemap: true to runBuild:

...(options.sourcemapOutput ? { sourcemap: true } : {}),

This keeps the existing behavior when --sourcemap-output is omitted, while matching React Native CLI semantics: providing a sourcemap output path means the bundler should generate a sourcemap at that path.

Validation

  • yarn workspace rollipop vp test --run src/node/commands/bundle/__tests__/action.spec.ts
  • yarn workspace rollipop typecheck
  • yarn fmt

@changeset-bot

changeset-bot Bot commented May 31, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 759fe3c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
rollipop Patch
@rollipop/jest-preset Patch
@rollipop/plugin-analyze Patch
@rollipop/plugin-module-federation Patch
@rollipop/plugin-rozenite Patch
@rollipop/plugin-svg Patch
@rollipop/init Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@jingjing2222 jingjing2222 changed the title [codex] fix bundle sourcemap output fix: bundle sourcemap output May 31, 2026
@jingjing2222 jingjing2222 marked this pull request as ready for review May 31, 2026 15:43

@leegeunhyeok leegeunhyeok left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM 👍

@leegeunhyeok leegeunhyeok merged commit 6c97ee3 into rollipop-dev:main Jun 1, 2026
1 check passed
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.

2 participants