@@ -293,11 +293,11 @@ func (w *filesParser) getProcessedFiles(loader *fileLoader) processedFiles {
293293 libFilesMap := make (map [tspath.Path ]* LibFile , libFileCount )
294294
295295 var redirectTargetsMap map [tspath.Path ][]string
296- var deduplicatedPaths collections. Set [tspath.Path ]
297- var packageIdToCanonicalPath map [module.PackageId ]tspath. Path
296+ var redirectFilesByPath map [tspath.Path ]* redirectsFile
297+ var packageIdToSourceFile map [module.PackageId ]* ast. SourceFile
298298 if ! loader .opts .Config .CompilerOptions ().DeduplicatePackages .IsFalse () {
299299 redirectTargetsMap = make (map [tspath.Path ][]string )
300- packageIdToCanonicalPath = make (map [module.PackageId ]tspath. Path )
300+ packageIdToSourceFile = make (map [module.PackageId ]* ast. SourceFile )
301301 }
302302
303303 var collectFiles func (tasks []* parseTask , seen map [* parseTaskData ]string )
@@ -349,22 +349,31 @@ func (w *filesParser) getProcessedFiles(loader *fileLoader) processedFiles {
349349 loader .opts .Host .Trace (trace .Message , trace .Args ... )
350350 }
351351
352- var existingCanonicalPath tspath.Path
353- if packageIdToCanonicalPath != nil && data .packageId .Name != "" {
354- if canonical , exists := packageIdToCanonicalPath [data .packageId ]; exists {
355- redirectTargetsMap [canonical ] = append (redirectTargetsMap [canonical ], task .normalizedFilePath )
356- existingCanonicalPath = canonical
357- deduplicatedPaths .Add (task .path )
358- deduplicatedPaths .Add (canonical )
359- } else {
360- packageIdToCanonicalPath [data .packageId ] = task .path
352+ file := task .file
353+ if packageIdToSourceFile != nil && data .packageId .Name != "" {
354+ if packageIdFile , exists := packageIdToSourceFile [data .packageId ]; exists {
355+ redirectTargetsMap [packageIdFile .Path ()] = append (redirectTargetsMap [packageIdFile .Path ()], task .normalizedFilePath )
356+ if redirectFilesByPath == nil {
357+ redirectFilesByPath = make (map [tspath.Path ]* redirectsFile , totalFileCount )
358+ }
359+ redirectFilesByPath [task .path ] = & redirectsFile {
360+ index : len (files ) + len (redirectFilesByPath ),
361+ fileName : task .normalizedFilePath ,
362+ path : task .path ,
363+ target : packageIdFile .Path (),
364+ }
365+ filesByPath [task .path ] = packageIdFile
366+ if data .lowestDepth > 0 {
367+ sourceFilesFoundSearchingNodeModules .Add (task .path )
368+ }
369+ continue
370+ } else if file != nil {
371+ packageIdToSourceFile [data .packageId ] = file
361372 }
362373 }
363374
364- if existingCanonicalPath == "" {
365- if subTasks := task .subTasks ; len (subTasks ) > 0 {
366- collectFiles (subTasks , seen )
367- }
375+ if subTasks := task .subTasks ; len (subTasks ) > 0 {
376+ collectFiles (subTasks , seen )
368377 }
369378
370379 // Exclude automatic type directive tasks from include reason processing,
@@ -381,10 +390,6 @@ func (w *filesParser) getProcessedFiles(loader *fileLoader) processedFiles {
381390 typeResolutionsInFile [task .path ] = task .typeResolutionsInFile
382391 continue
383392 }
384- file := task .file
385- if existingCanonicalPath != "" {
386- file = filesByPath [existingCanonicalPath ]
387- }
388393
389394 path := task .path
390395
@@ -401,7 +406,7 @@ func (w *filesParser) getProcessedFiles(loader *fileLoader) processedFiles {
401406 if task .libFile != nil {
402407 libFiles = append (libFiles , file )
403408 libFilesMap [path ] = task .libFile
404- } else if existingCanonicalPath == "" {
409+ } else {
405410 files = append (files , file )
406411 }
407412 filesByPath [path ] = file
@@ -431,6 +436,9 @@ func (w *filesParser) getProcessedFiles(loader *fileLoader) processedFiles {
431436 loader .sortLibs (libFiles )
432437
433438 allFiles := append (libFiles , files ... )
439+ for _ , redirectFile := range redirectFilesByPath {
440+ redirectFile .index += len (libFiles )
441+ }
434442
435443 keys := slices .Collect (loader .pathForLibFileResolutions .Keys ())
436444 slices .Sort (keys )
@@ -461,7 +469,7 @@ func (w *filesParser) getProcessedFiles(loader *fileLoader) processedFiles {
461469 includeProcessor : includeProcessor ,
462470 outputFileToProjectReferenceSource : outputFileToProjectReferenceSource ,
463471 redirectTargetsMap : redirectTargetsMap ,
464- deduplicatedPaths : deduplicatedPaths ,
472+ redirectFilesByPath : redirectFilesByPath ,
465473 }
466474}
467475
0 commit comments