Skip to content

fix: resolve sources inside the sourceRoot directory on filesystem paths - #560

Open
LukaszKokot wants to merge 1 commit into
2wce:mainfrom
LukaszKokot:fix/source-root-directory
Open

LukaszKokot wants to merge 1 commit into
2wce:mainfrom
LukaszKokot:fix/source-root-directory

Conversation

@LukaszKokot

@LukaszKokot LukaszKokot commented Oct 27, 2026 •

Copy link
Copy Markdown

Problem

resolveUrl() resolves each segment with path.resolve(path.dirname(resolved), next). path.resolve strips the trailing slash that resolveSources() appends to sourceRoot, so the following path.dirname drops the root directory again.

For a map at <pkg>/data.mjs.map with "sourceRoot": "src" and "sources": ["data.ts"], the source resolves to <pkg>/data.ts instead of <pkg>/src/data.ts. The read fails and, because sourcesContent is only kept when every source resolves, the whole map loses its sourcesContent.

apache-arrow@21.2.0 ships maps like this, so bundles that include it silently lose the embedded sources for all of its modules.
URL bases are not affected because new URL() keeps the trailing slash.

Fix

Keep a trailing slash on the resolved base so the next segment resolves inside that directory, mirroring URL resolution.

Checked against maps without sourceRoot, ../ and absolute sources, URL sourceRoot values (http:, webpack:///, file://), empty segments and Windows drive paths: unchanged. sourceRoot values src, src/, ./, ../src and absolute roots now resolve inside the root.

Test

resolves sources inside the sourceRoot directory fails on main with dist/index.ts instead of dist/src/index.ts and passes with the fix.

Notes

This was done using Opus 5.5 🤖
We first applied the same patch -using pnpm- in one of our private iTwin repository

@changeset-bot

changeset-bot Bot commented Oct 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3fc9e2f

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

This PR includes changesets to release 1 package
Name Type
rollup-plugin-sourcemaps2 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

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.

1 participant