File tree Expand file tree Collapse file tree
build-utils/build/module-graph/webpack Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -91,7 +91,7 @@ function appendDependency(
9191 const request = rawRequest ?? resolveRequest ;
9292
9393 if ( ! module . getDependencyByRequest ( request ) ) {
94- const depModule = graph . getModuleByFile ( resolveRequest ) ;
94+ const depModule = graph . getModuleByFile ( resolveRequest ) [ 0 ] ;
9595
9696 if ( depModule ) {
9797 const dep = module . addDependency (
Original file line number Diff line number Diff line change @@ -117,7 +117,37 @@ export async function collectSourceMaps(
117117 if ( ! m . source ) continue ;
118118
119119 // The source in map.sources returned by sourceAndMap may be modified by Rsdoctor's loader
120- let realSource = m . source . split ( '!' ) . pop ( ) ;
120+ // Handle loader chain paths (e.g., "loader1!loader2!/path/to/file.js")
121+ // Extract the actual source file path by splitting on '!' and taking the last part
122+ let realSource = m . source ;
123+
124+ if ( realSource . includes ( '!' ) ) {
125+ const parts = realSource . split ( '!' ) ;
126+ for ( let j = parts . length - 1 ; j >= 0 ; j -- ) {
127+ const part = parts [ j ] ;
128+ if ( ! part ) continue ;
129+
130+ const cleanPart = part . split ( '??' ) [ 0 ] ;
131+
132+ if ( cleanPart . startsWith ( 'builtin:' ) ) {
133+ continue ;
134+ }
135+
136+ // Check if it looks like a file path (absolute path starting with '/' or relative path)
137+ if ( cleanPart . startsWith ( '/' ) || cleanPart . includes ( '\\' ) ) {
138+ realSource = cleanPart ;
139+ break ;
140+ }
141+ }
142+
143+ if ( realSource === m . source ) {
144+ const lastPart = parts [ parts . length - 1 ] ;
145+ realSource = lastPart ? lastPart . split ( '??' ) [ 0 ] : lastPart ;
146+ }
147+ } else if ( realSource . includes ( '??' ) ) {
148+ realSource = realSource . split ( '??' ) [ 0 ] ;
149+ }
150+
121151 if (
122152 ( realSource ?. startsWith ( 'webpack://' ) ||
123153 realSource ?. startsWith ( 'file://' ) ) &&
Original file line number Diff line number Diff line change @@ -325,7 +325,10 @@ export class ModuleGraph implements SDK.ModuleGraphInstance {
325325 }
326326
327327 getModuleByFile ( file : string ) {
328- return this . getModules ( ) . find ( ( item ) => item . path === file ) ;
328+ const similarModules = this . getModules ( ) . filter (
329+ ( item ) => item . path === file ,
330+ ) ;
331+ return similarModules || [ ] ;
329332 }
330333
331334 addModule ( ...modules : SDK . ModuleInstance [ ] ) {
Original file line number Diff line number Diff line change @@ -79,20 +79,21 @@ export async function getAssetsModulesData(
7979 } else {
8080 time ( `Start Parse bundle by sourcemap.` ) ;
8181 for ( const [ modulePath , codes ] of sourceMapSets . entries ( ) ) {
82- const module = moduleGraph . getModuleByFile ( modulePath ) ;
83- if ( ! module ) continue ;
82+ const modules = moduleGraph . getModuleByFile ( modulePath ) ;
8483 let gzipSize = undefined ;
8584 try {
8685 if ( codes && typeof codes === 'string' && codes . length > 0 ) {
8786 const { gzipSync } = await import ( 'node:zlib' ) ;
8887 gzipSize = gzipSync ( codes , { level : 9 } ) . length ;
8988 }
9089 } catch { }
91- module ?. setSize ( {
92- parsedSize : codes . length ,
93- gzipSize,
94- } ) ;
95- module ?. setSource ( { parsedSource : codes } ) ;
90+ for ( const module of modules ) {
91+ module ?. setSize ( {
92+ parsedSize : codes . length ,
93+ gzipSize,
94+ } ) ;
95+ module ?. setSource ( { parsedSource : codes } ) ;
96+ }
9697 }
9798 timeEnd ( `Start Parse bundle by sourcemap.` ) ;
9899 }
Original file line number Diff line number Diff line change @@ -311,7 +311,7 @@ export interface ModuleGraphInstance {
311311 getModuleByWebpackId ( webpackId : string ) : ModuleInstance | undefined ;
312312
313313 /** Get module by path */
314- getModuleByFile ( file : string ) : ModuleInstance | undefined ;
314+ getModuleByFile ( file : string ) : ModuleInstance [ ] | [ ] ;
315315
316316 /** Add Module */
317317 addModule ( module : ModuleInstance ) : void ;
You can’t perform that action at this time.
0 commit comments