Skip to content

fix: use relative paths in source maps#6450

Merged
chenjiahan merged 5 commits intomainfrom
source_map_paths_1027
Oct 28, 2025
Merged

fix: use relative paths in source maps#6450
chenjiahan merged 5 commits intomainfrom
source_map_paths_1027

Conversation

@chenjiahan
Copy link
Member

@chenjiahan chenjiahan commented Oct 27, 2025

Summary

Update source map paths to use relative POSIX paths instead of absolute or webpack-specific paths.

  • Prevents leaking absolute system paths
  • Keeps maps portable across environments
  • Matches source map spec and debugger expectations
  • Aligns with esbuild/Rollup/Vite.

Related Links

If the sources are not absolute URLs after prepending of the “sourceRoot”, the sources are resolved relative to the SourceMap (like resolving script src in a html document).

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings October 27, 2025 14:55
@netlify
Copy link

netlify bot commented Oct 27, 2025

Deploy Preview for rsbuild ready!

Name Link
🔨 Latest commit 4974d86
🔍 Latest deploy log https://app.netlify.com/projects/rsbuild/deploys/690037b0de24b40008320155
😎 Deploy Preview https://deploy-preview-6450--rsbuild.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 64 (🟢 up 2 from production)
Accessibility: 97 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: 60 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@chenjiahan chenjiahan changed the title fix(source-maps): use relative paths in source maps for portability fix(source-maps): use relative paths in source maps Oct 27, 2025
@chenjiahan chenjiahan changed the title fix(source-maps): use relative paths in source maps fix: use relative paths in source maps Oct 27, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates source map path handling to use relative POSIX paths instead of absolute or webpack-specific paths, improving portability and preventing system path leakage.

  • Updates devtoolModuleFilenameTemplate to generate relative paths from the dist directory
  • Removes development-only condition, applying the relative path logic to all builds
  • Updates test expectations to match the new relative path format (e.g., ../src/index.ts instead of webpack:///src/index.ts)

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/core/src/plugins/basic.ts Implements relative path generation for source maps using path.relative() and removes dev-only condition
e2e/cases/plugin-api/plugin-transform-merge-source-map/index.test.ts Updates test expectations to use relative paths instead of webpack protocol paths
e2e/cases/output/source-map/index.test.ts Simplifies test logic and updates expected source paths to relative format

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chenjiahan chenjiahan marked this pull request as draft October 27, 2025 14:58
@chenjiahan chenjiahan marked this pull request as ready for review October 28, 2025 03:29
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +73 to +76
const { distPath } = api.context;

for (const [filename, asset] of Object.entries(assets)) {
if (!filename.endsWith('.map')) {

Choose a reason for hiding this comment

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

P1 Badge Compute relative source-map paths per environment output

The new source-map plugin derives mapDir from api.context.distPath, which is the common parent directory for all environments. When building multiple environments whose output.distPath values are nested (e.g. dist/web and dist/server), asset filenames are relative to each environment’s own output path, so combining them with the common root drops the environment subfolder. The subsequent path.relative(mapDir, source) therefore emits paths like ../../../src/foo.ts that resolve to <dist>/src/foo.ts instead of the real project source, breaking source map resolution for any environment that does not emit directly into the shared root. Use the environment-specific path (e.g. compilation.outputOptions.path or the environment.distPath passed to the hook) when computing mapDir to keep the relative paths correct.

Useful? React with 👍 / 👎.

Copy link
Member Author

Choose a reason for hiding this comment

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

I will verify this issue and create another PR to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: @rsbuild/core backend nodejs source maps not work [source-map-support/register]

1 participant