@@ -107,6 +107,7 @@ import {
107
107
removeTrailingDirectorySeparator ,
108
108
replaceFirstStar ,
109
109
ResolutionMode ,
110
+ ResolvedModuleSpecifierInfo ,
110
111
resolveModuleName ,
111
112
resolvePath ,
112
113
ScriptKind ,
@@ -287,14 +288,15 @@ export function tryGetModuleSpecifiersFromCache(
287
288
host :ModuleSpecifierResolutionHost ,
288
289
userPreferences :UserPreferences ,
289
290
options :ModuleSpecifierOptions = { } ,
290
- ) :readonly string [ ] | undefined {
291
- return tryGetModuleSpecifiersFromCacheWorker (
291
+ ) :ModuleSpecifierResult | undefined {
292
+ const result = tryGetModuleSpecifiersFromCacheWorker (
292
293
moduleSymbol ,
293
294
importingSourceFile ,
294
295
host ,
295
296
userPreferences ,
296
297
options ,
297
- ) [ 0 ] ;
298
+ ) ;
299
+ return result [ 1 ] && { kind :result [ 0 ] , moduleSpecifiers :result [ 1 ] , computedWithoutCache :false } ;
298
300
}
299
301
300
302
function tryGetModuleSpecifiersFromCacheWorker (
@@ -303,15 +305,15 @@ function tryGetModuleSpecifiersFromCacheWorker(
303
305
host :ModuleSpecifierResolutionHost ,
304
306
userPreferences :UserPreferences ,
305
307
options :ModuleSpecifierOptions = { } ,
306
- ) :readonly [ specifiers ?:readonly string [ ] , moduleFile ?:SourceFile , modulePaths ?:readonly ModulePath [ ] , cache ?:ModuleSpecifierCache ] {
308
+ ) :readonly [ kind ?: ModuleSpecifierResult [ "kind" ] , specifiers ?:readonly string [ ] , moduleFile ?:SourceFile , modulePaths ?:readonly ModulePath [ ] , cache ?:ModuleSpecifierCache ] {
307
309
const moduleSourceFile = getSourceFileOfModule ( moduleSymbol ) ;
308
310
if ( ! moduleSourceFile ) {
309
311
return emptyArray as [ ] ;
310
312
}
311
313
312
314
const cache = host . getModuleSpecifierCache ?.( ) ;
313
315
const cached = cache ?. get ( importingSourceFile . path , moduleSourceFile . path , userPreferences , options ) ;
314
- return [ cached ?. moduleSpecifiers , moduleSourceFile , cached ?. modulePaths , cache ] ;
316
+ return [ cached ?. kind , cached ?. moduleSpecifiers , moduleSourceFile , cached ?. modulePaths , cache ] ;
315
317
}
316
318
317
319
/**
@@ -340,6 +342,13 @@ export function getModuleSpecifiers(
340
342
) . moduleSpecifiers ;
341
343
}
342
344
345
+ /**@internal */
346
+ export interface ModuleSpecifierResult {
347
+ kind :ResolvedModuleSpecifierInfo [ "kind" ] ;
348
+ moduleSpecifiers :readonly string [ ] ;
349
+ computedWithoutCache :boolean ;
350
+ }
351
+
343
352
/**@internal */
344
353
export function getModuleSpecifiersWithCacheInfo (
345
354
moduleSymbol :Symbol ,
@@ -350,21 +359,21 @@ export function getModuleSpecifiersWithCacheInfo(
350
359
userPreferences :UserPreferences ,
351
360
options :ModuleSpecifierOptions = { } ,
352
361
forAutoImport :boolean ,
353
- ) :{ moduleSpecifiers : readonly string [ ] ; computedWithoutCache : boolean ; } {
362
+ ) :ModuleSpecifierResult {
354
363
let computedWithoutCache = false ;
355
364
const ambient = tryGetModuleNameFromAmbientModule ( moduleSymbol , checker ) ;
356
- if ( ambient ) return { moduleSpecifiers :[ ambient ] , computedWithoutCache} ;
365
+ if ( ambient ) return { kind : "ambient" , moduleSpecifiers :[ ambient ] , computedWithoutCache} ;
357
366
358
367
// eslint-disable-next-line prefer-const
359
- let [ specifiers , moduleSourceFile , modulePaths , cache ] = tryGetModuleSpecifiersFromCacheWorker (
368
+ let [ kind , specifiers , moduleSourceFile , modulePaths , cache ] = tryGetModuleSpecifiersFromCacheWorker (
360
369
moduleSymbol ,
361
370
importingSourceFile ,
362
371
host ,
363
372
userPreferences ,
364
373
options ,
365
374
) ;
366
- if ( specifiers ) return { moduleSpecifiers :specifiers , computedWithoutCache} ;
367
- if ( ! moduleSourceFile ) return { moduleSpecifiers :emptyArray , computedWithoutCache} ;
375
+ if ( specifiers ) return { kind , moduleSpecifiers :specifiers , computedWithoutCache} ;
376
+ if ( ! moduleSourceFile ) return { kind : undefined , moduleSpecifiers :emptyArray , computedWithoutCache} ;
368
377
369
378
computedWithoutCache = true ;
370
379
modulePaths ||= getAllModulePathsWorker ( getInfo ( importingSourceFile . fileName , host ) , moduleSourceFile . originalFileName , host , compilerOptions , options ) ;
@@ -377,8 +386,8 @@ export function getModuleSpecifiersWithCacheInfo(
377
386
options ,
378
387
forAutoImport ,
379
388
) ;
380
- cache ?. set ( importingSourceFile . path , moduleSourceFile . path , userPreferences , options , modulePaths , result ) ;
381
- return { moduleSpecifiers : result , computedWithoutCache } ;
389
+ cache ?. set ( importingSourceFile . path , moduleSourceFile . path , userPreferences , options , result . kind , modulePaths , result . moduleSpecifiers ) ;
390
+ return result ;
382
391
}
383
392
384
393
/**@internal */
@@ -409,7 +418,7 @@ function computeModuleSpecifiers(
409
418
userPreferences :UserPreferences ,
410
419
options :ModuleSpecifierOptions = { } ,
411
420
forAutoImport :boolean ,
412
- ) :readonly string [ ] {
421
+ ) :ModuleSpecifierResult {
413
422
const info = getInfo ( importingSourceFile . fileName , host ) ;
414
423
const preferences = getModuleSpecifierPreferences ( userPreferences , host , compilerOptions , importingSourceFile ) ;
415
424
const existingSpecifier = isFullSourceFile ( importingSourceFile ) && forEach ( modulePaths , modulePath =>
@@ -432,8 +441,7 @@ function computeModuleSpecifiers(
432
441
} ,
433
442
) ) ;
434
443
if ( existingSpecifier ) {
435
- const moduleSpecifiers = [ existingSpecifier ] ;
436
- return moduleSpecifiers ;
444
+ return { kind :undefined , moduleSpecifiers :[ existingSpecifier ] , computedWithoutCache :true } ;
437
445
}
438
446
439
447
const importedFileIsInNodeModules = some ( modulePaths , p => p . isInNodeModules ) ;
@@ -455,7 +463,7 @@ function computeModuleSpecifiers(
455
463
if ( specifier && modulePath . isRedirect ) {
456
464
// If we got a specifier for a redirect, it was a bare package specifier (e.g. "@foo/bar",
457
465
// not "@foo/bar/path/to/file"). No other specifier will be this good, so stop looking.
458
- return nodeModulesSpecifiers ! ;
466
+ return { kind : "node_modules" , moduleSpecifiers : nodeModulesSpecifiers ! , computedWithoutCache : true } ;
459
467
}
460
468
461
469
if ( ! specifier ) {
@@ -501,10 +509,10 @@ function computeModuleSpecifiers(
501
509
}
502
510
}
503
511
504
- return pathsSpecifiers ?. length ?pathsSpecifiers :
505
- redirectPathsSpecifiers ?. length ?redirectPathsSpecifiers :
506
- nodeModulesSpecifiers ?. length ?nodeModulesSpecifiers :
507
- Debug . checkDefined ( relativeSpecifiers ) ;
512
+ return pathsSpecifiers ?. length ?{ kind : "paths" , moduleSpecifiers : pathsSpecifiers , computedWithoutCache : true } :
513
+ redirectPathsSpecifiers ?. length ?{ kind : "redirect" , moduleSpecifiers : redirectPathsSpecifiers , computedWithoutCache : true } :
514
+ nodeModulesSpecifiers ?. length ?{ kind : "node_modules" , moduleSpecifiers : nodeModulesSpecifiers , computedWithoutCache : true } :
515
+ { kind : "relative" , moduleSpecifiers : Debug . checkDefined ( relativeSpecifiers ) , computedWithoutCache : true } ;
508
516
}
509
517
510
518
interface Info {