Skip to content

fix: sourcemap tool get modules contents#1400

Merged
yifancong merged 2 commits intomainfrom
fix/sourcemap-sources-cases
Nov 11, 2025
Merged

fix: sourcemap tool get modules contents#1400
yifancong merged 2 commits intomainfrom
fix/sourcemap-sources-cases

Conversation

@yifancong
Copy link
Contributor

@yifancong yifancong commented Nov 11, 2025

Summary

fix: sourcemap tool get modules contents

  1. In asset.source.sourceAndMap(), the map's source(s) may carry loader identifiers — we need to support/handle this kind of source.
    Example:
    javascript/auto|User/demo/packages/A/dist/build-utils/build/loader/probeLoader.js??ruleSet[1].rules[4].oneOf[0].use[0]!builtin:swc-loader??ruleSet[1].rules[4].oneOf[0].use[1]!/Users/demo/packages/core/dist/build-utils/build/loader/probeLoader.js??/Users/demo/node_modules/.pnpm/@aaaa+ccc@2.4.19_@babel+runtime@7.28.4_@CCC+ddd@0.112.3_@by_jwmsj3bjj7ci3pv4sanrci5qyy/node_modules/@AAAA/ccc/dist/components/Loading/button.tsx|react:background

  2. The module graph can contain multiple entries with the same file path, but their identifiers differ due to entry-related reasons, so moduleGraph.getModuleByFile was optimized to handle this.

——————————————————————————————————————————————————————————————

  1. asset.source.sourceAndMap() 中的 map.source 会携带 loaders 的 identifier 情况,需要兼容这种 source
    例如:javascript/auto|User/demo/packages/A/dist/build-utils/build/loader/probeLoader.js??ruleSet[1].rules[4].oneOf[0].use[0]!builtin:swc-loader??ruleSet[1].rules[4].oneOf[0].use[1]!/Users/demo/packages/core/dist/build-utils/build/loader/probeLoader.js??/Users/demo/node_modules/.pnpm/@aaaa+ccc@2.4.19_@babel+runtime@7.28.4_@CCC+ddd@0.112.3_@by_jwmsj3bjj7ci3pv4sanrci5qyy/node_modules/@AAAA/ccc/dist/components/Loading/button.tsx|react:background

  2. module graph 中会存在多个相同的 file path,但因为 entry 问题 identifier 不同,所以优化了 moduleGraph.getModuleByFile。

Related Links

Copilot AI review requested due to automatic review settings November 11, 2025 07:34
@netlify
Copy link

netlify bot commented Nov 11, 2025

Deploy Preview for rsdoctor ready!

Name Link
🔨 Latest commit cfd3034
🔍 Latest deploy log https://app.netlify.com/projects/rsdoctor/deploys/6912ec1644b8dd0008621deb
😎 Deploy Preview https://deploy-preview-1400--rsdoctor.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

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 fixes an issue with sourcemap tool module content retrieval by changing getModuleByFile to return an array of modules instead of a single module. This allows handling cases where multiple modules may share the same file path.

Key changes:

  • Updated getModuleByFile method signature to return ModuleInstance[] instead of ModuleInstance | undefined
  • Enhanced sourcemap parsing logic to handle complex loader chains, builtin modules, and query parameters
  • Modified consumers to iterate over multiple modules when setting size and source data

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/types/src/sdk/module.ts Updated getModuleByFile return type from single module to array
packages/graph/src/graph/module-graph/graph.ts Changed implementation to filter and return array of matching modules
packages/graph/src/transform/chunks/assetsModules.ts Updated to iterate over returned module array when setting parsed data
packages/core/src/build-utils/build/module-graph/webpack/transform.ts Updated to access first element of returned array with null check
packages/core/src/inner-plugins/plugins/sourcemapTool.ts Enhanced source path parsing to handle loader chains, builtins, and query parameters
pnpm-lock.yaml Added compiled package placeholders for various dependencies
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

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

@yifancong yifancong force-pushed the fix/sourcemap-sources-cases branch from 77be97e to cfd3034 Compare November 11, 2025 07:56
@yifancong yifancong merged commit e068194 into main Nov 11, 2025
8 checks passed
@yifancong yifancong deleted the fix/sourcemap-sources-cases branch November 11, 2025 08:26
@yifancong yifancong mentioned this pull request Nov 13, 2025
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.

3 participants