@@ -86,15 +86,24 @@ namespace ts {
86
86
return { fileName : resolved . path , packageId : resolved . packageId } ;
87
87
}
88
88
89
- function createResolvedModuleWithFailedLookupLocations ( resolved : Resolved | undefined , isExternalLibraryImport : boolean | undefined , failedLookupLocations : string [ ] , diagnostics : Diagnostic [ ] , resultFromCache : ResolvedModuleWithFailedLookupLocations | undefined ) : ResolvedModuleWithFailedLookupLocations {
89
+ function createResolvedModuleWithFailedLookupLocations (
90
+ resolved : Resolved | undefined ,
91
+ isExternalLibraryImport : boolean | undefined ,
92
+ failedLookupLocations : string [ ] ,
93
+ affectingLocations : string [ ] ,
94
+ diagnostics : Diagnostic [ ] ,
95
+ resultFromCache : ResolvedModuleWithFailedLookupLocations | undefined
96
+ ) : ResolvedModuleWithFailedLookupLocations {
90
97
if ( resultFromCache ) {
91
98
resultFromCache . failedLookupLocations . push ( ...failedLookupLocations ) ;
99
+ resultFromCache . affectingLocations . push ( ...affectingLocations ) ;
92
100
return resultFromCache ;
93
101
}
94
102
return {
95
103
resolvedModule : resolved && { resolvedFileName : resolved . path , originalPath : resolved . originalPath === true ? undefined : resolved . originalPath , extension : resolved . extension , isExternalLibraryImport, packageId : resolved . packageId } ,
96
104
failedLookupLocations,
97
- resolutionDiagnostics : diagnostics
105
+ affectingLocations,
106
+ resolutionDiagnostics : diagnostics ,
98
107
} ;
99
108
}
100
109
@@ -104,6 +113,7 @@ namespace ts {
104
113
compilerOptions : CompilerOptions ;
105
114
traceEnabled : boolean ;
106
115
failedLookupLocations : Push < string > ;
116
+ affectingLocations : Push < string > ;
107
117
resultFromCache ?: ResolvedModuleWithFailedLookupLocations ;
108
118
packageJsonInfoCache : PackageJsonInfoCache | undefined ;
109
119
features : NodeResolutionFeatures ;
@@ -345,6 +355,7 @@ namespace ts {
345
355
}
346
356
347
357
const failedLookupLocations : string [ ] = [ ] ;
358
+ const affectingLocations : string [ ] = [ ] ;
348
359
let features = getDefaultNodeResolutionFeatures ( options ) ;
349
360
// Unlike `import` statements, whose mode-calculating APIs are all guaranteed to return `undefined` if we're in an un-mode-ed module resolution
350
361
// setting, type references will return their target mode regardless of options because of how the parser works, so we guard against the mode being
@@ -363,6 +374,7 @@ namespace ts {
363
374
host,
364
375
traceEnabled,
365
376
failedLookupLocations,
377
+ affectingLocations,
366
378
packageJsonInfoCache : cache ,
367
379
features,
368
380
conditions,
@@ -388,7 +400,7 @@ namespace ts {
388
400
isExternalLibraryImport : pathContainsNodeModules ( fileName ) ,
389
401
} ;
390
402
}
391
- result = { resolvedTypeReferenceDirective, failedLookupLocations, resolutionDiagnostics : diagnostics } ;
403
+ result = { resolvedTypeReferenceDirective, failedLookupLocations, affectingLocations , resolutionDiagnostics : diagnostics } ;
392
404
perFolderCache ?. set ( typeReferenceDirectiveName , /*mode*/ resolutionMode , result ) ;
393
405
if ( traceEnabled ) traceResult ( result ) ;
394
406
return result ;
@@ -479,6 +491,7 @@ namespace ts {
479
491
host,
480
492
traceEnabled : isTraceEnabled ( options , host ) ,
481
493
failedLookupLocations : [ ] ,
494
+ affectingLocations : [ ] ,
482
495
packageJsonInfoCache : cache ?. getPackageJsonInfoCache ( ) ,
483
496
conditions : emptyArray ,
484
497
features : NodeResolutionFeatures . None ,
@@ -1330,6 +1343,7 @@ namespace ts {
1330
1343
const traceEnabled = isTraceEnabled ( compilerOptions , host ) ;
1331
1344
1332
1345
const failedLookupLocations : string [ ] = [ ] ;
1346
+ const affectingLocations : string [ ] = [ ] ;
1333
1347
// conditions are only used by the node16/nodenext resolver - there's no priority order in the list,
1334
1348
//it's essentially a set (priority is determined by object insertion order in the object we look at).
1335
1349
const conditions = features & NodeResolutionFeatures . EsmMode ? [ "node" , "import" , "types" ] : [ "node" , "require" , "types" ] ;
@@ -1343,6 +1357,7 @@ namespace ts {
1343
1357
host,
1344
1358
traceEnabled,
1345
1359
failedLookupLocations,
1360
+ affectingLocations,
1346
1361
packageJsonInfoCache : cache ,
1347
1362
features,
1348
1363
conditions,
@@ -1351,7 +1366,14 @@ namespace ts {
1351
1366
} ;
1352
1367
1353
1368
const result = forEach ( extensions , ext => tryResolve ( ext ) ) ;
1354
- return createResolvedModuleWithFailedLookupLocations ( result ?. value ?. resolved , result ?. value ?. isExternalLibraryImport , failedLookupLocations , diagnostics , state . resultFromCache ) ;
1369
+ return createResolvedModuleWithFailedLookupLocations (
1370
+ result ?. value ?. resolved ,
1371
+ result ?. value ?. isExternalLibraryImport ,
1372
+ failedLookupLocations ,
1373
+ affectingLocations ,
1374
+ diagnostics ,
1375
+ state . resultFromCache
1376
+ ) ;
1355
1377
1356
1378
function tryResolve ( extensions : Extensions ) : SearchResult < { resolved : Resolved , isExternalLibraryImport : boolean } > {
1357
1379
const loader : ResolutionKindSpecificLoader = ( extensions , candidate , onlyRecordFailures , state ) => nodeLoadModuleByRelativeName ( extensions , candidate , onlyRecordFailures , state , /*considerPackageJson*/ true ) ;
@@ -1675,6 +1697,7 @@ namespace ts {
1675
1697
host,
1676
1698
traceEnabled : isTraceEnabled ( options , host ) ,
1677
1699
failedLookupLocations : [ ] ,
1700
+ affectingLocations : [ ] ,
1678
1701
packageJsonInfoCache : cache ?. getPackageJsonInfoCache ( ) ,
1679
1702
conditions : [ "node" , "require" , "types" ] ,
1680
1703
features,
@@ -1785,6 +1808,7 @@ namespace ts {
1785
1808
compilerOptions : CompilerOptions ;
1786
1809
traceEnabled : boolean ;
1787
1810
failedLookupLocations : Push < string > ;
1811
+ affectingLocations : Push < string > ;
1788
1812
resultFromCache ?: ResolvedModuleWithFailedLookupLocations ;
1789
1813
packageJsonInfoCache : PackageJsonInfoCache | undefined ;
1790
1814
features : number ;
@@ -1796,6 +1820,7 @@ namespace ts {
1796
1820
compilerOptions : options ,
1797
1821
traceEnabled : isTraceEnabled ( options , host ) ,
1798
1822
failedLookupLocations : [ ] ,
1823
+ affectingLocations : [ ] ,
1799
1824
packageJsonInfoCache,
1800
1825
features : 0 ,
1801
1826
conditions : [ ] ,
@@ -1827,6 +1852,7 @@ namespace ts {
1827
1852
if ( existing !== undefined ) {
1828
1853
if ( typeof existing !== "boolean" ) {
1829
1854
if ( traceEnabled ) trace ( host , Diagnostics . File_0_exists_according_to_earlier_cached_lookups , packageJsonPath ) ;
1855
+ state . affectingLocations . push ( packageJsonPath ) ;
1830
1856
return existing ;
1831
1857
}
1832
1858
else {
@@ -1844,6 +1870,7 @@ namespace ts {
1844
1870
const versionPaths = readPackageJsonTypesVersionPaths ( packageJsonContent , state ) ;
1845
1871
const result = { packageDirectory, packageJsonContent, versionPaths, resolvedEntrypoints : undefined } ;
1846
1872
state . packageJsonInfoCache ?. setPackageJsonInfo ( packageJsonPath , result ) ;
1873
+ state . affectingLocations . push ( packageJsonPath ) ;
1847
1874
return result ;
1848
1875
}
1849
1876
else {
@@ -2550,13 +2577,31 @@ namespace ts {
2550
2577
export function classicNameResolver ( moduleName : string , containingFile : string , compilerOptions : CompilerOptions , host : ModuleResolutionHost , cache ?: NonRelativeModuleNameResolutionCache , redirectedReference ?: ResolvedProjectReference ) : ResolvedModuleWithFailedLookupLocations {
2551
2578
const traceEnabled = isTraceEnabled ( compilerOptions , host ) ;
2552
2579
const failedLookupLocations : string [ ] = [ ] ;
2580
+ const affectingLocations : string [ ] = [ ] ;
2553
2581
const containingDirectory = getDirectoryPath ( containingFile ) ;
2554
2582
const diagnostics : Diagnostic [ ] = [ ] ;
2555
- const state : ModuleResolutionState = { compilerOptions, host, traceEnabled, failedLookupLocations, packageJsonInfoCache : cache , features : NodeResolutionFeatures . None , conditions : [ ] , requestContainingDirectory : containingDirectory , reportDiagnostic : diag => void diagnostics . push ( diag ) } ;
2583
+ const state : ModuleResolutionState = {
2584
+ compilerOptions,
2585
+ host,
2586
+ traceEnabled,
2587
+ failedLookupLocations,
2588
+ affectingLocations, packageJsonInfoCache : cache ,
2589
+ features : NodeResolutionFeatures . None ,
2590
+ conditions : [ ] ,
2591
+ requestContainingDirectory : containingDirectory ,
2592
+ reportDiagnostic : diag => void diagnostics . push ( diag ) ,
2593
+ } ;
2556
2594
2557
2595
const resolved = tryResolve ( Extensions . TypeScript ) || tryResolve ( Extensions . JavaScript ) ;
2558
2596
// No originalPath because classic resolution doesn't resolve realPath
2559
- return createResolvedModuleWithFailedLookupLocations ( resolved && resolved . value , /*isExternalLibraryImport*/ false , failedLookupLocations , diagnostics , state . resultFromCache ) ;
2597
+ return createResolvedModuleWithFailedLookupLocations (
2598
+ resolved && resolved . value ,
2599
+ /*isExternalLibraryImport*/ false ,
2600
+ failedLookupLocations ,
2601
+ affectingLocations ,
2602
+ diagnostics ,
2603
+ state . resultFromCache
2604
+ ) ;
2560
2605
2561
2606
function tryResolve ( extensions : Extensions ) : SearchResult < Resolved > {
2562
2607
const resolvedUsingSettings = tryLoadModuleUsingOptionalResolutionSettings ( extensions , moduleName , containingDirectory , loadModuleFromFileNoPackageId , state ) ;
@@ -2601,10 +2646,29 @@ namespace ts {
2601
2646
trace ( host , Diagnostics . Auto_discovery_for_typings_is_enabled_in_project_0_Running_extra_resolution_pass_for_module_1_using_cache_location_2 , projectName , moduleName , globalCache ) ;
2602
2647
}
2603
2648
const failedLookupLocations : string [ ] = [ ] ;
2649
+ const affectingLocations : string [ ] = [ ] ;
2604
2650
const diagnostics : Diagnostic [ ] = [ ] ;
2605
- const state : ModuleResolutionState = { compilerOptions, host, traceEnabled, failedLookupLocations, packageJsonInfoCache, features : NodeResolutionFeatures . None , conditions : [ ] , requestContainingDirectory : undefined , reportDiagnostic : diag => void diagnostics . push ( diag ) } ;
2651
+ const state : ModuleResolutionState = {
2652
+ compilerOptions,
2653
+ host,
2654
+ traceEnabled,
2655
+ failedLookupLocations,
2656
+ affectingLocations,
2657
+ packageJsonInfoCache,
2658
+ features : NodeResolutionFeatures . None ,
2659
+ conditions : [ ] ,
2660
+ requestContainingDirectory : undefined ,
2661
+ reportDiagnostic : diag => void diagnostics . push ( diag ) ,
2662
+ } ;
2606
2663
const resolved = loadModuleFromImmediateNodeModulesDirectory ( Extensions . DtsOnly , moduleName , globalCache , state , /*typesScopeOnly*/ false , /*cache*/ undefined , /*redirectedReference*/ undefined ) ;
2607
- return createResolvedModuleWithFailedLookupLocations ( resolved , /*isExternalLibraryImport*/ true , failedLookupLocations , diagnostics , state . resultFromCache ) ;
2664
+ return createResolvedModuleWithFailedLookupLocations (
2665
+ resolved ,
2666
+ /*isExternalLibraryImport*/ true ,
2667
+ failedLookupLocations ,
2668
+ affectingLocations ,
2669
+ diagnostics ,
2670
+ state . resultFromCache
2671
+ ) ;
2608
2672
}
2609
2673
2610
2674
/**
0 commit comments