@@ -13,6 +13,7 @@ import {
13
13
ModuleKind , ModuleResolutionHost , ModuleResolutionKind , noop , noopPush , normalizePath , normalizeSlashes ,
14
14
optionsHaveModuleResolutionChanges , PackageId , packageIdToString , ParsedCommandLine , Path , pathIsRelative , Pattern ,
15
15
patternText , perfLogger , Push , readJson , removeExtension , removeFileExtension , removePrefix ,
16
+ ResolutionMode ,
16
17
ResolvedModuleWithFailedLookupLocations , ResolvedProjectReference , ResolvedTypeReferenceDirective ,
17
18
ResolvedTypeReferenceDirectiveWithFailedLookupLocations , some , sort , SourceFile , startsWith , stringContains ,
18
19
StringLiteralLike , supportedTSExtensionsFlat , toFileNameLowerCase , toPath , tryExtractTSExtension , tryGetExtensionFromPath ,
@@ -333,7 +334,7 @@ function arePathsEqual(path1: string, path2: string, host: ModuleResolutionHost)
333
334
* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups
334
335
* is assumed to be the same as root directory of the project.
335
336
*/
336
- export function resolveTypeReferenceDirective ( typeReferenceDirectiveName : string , containingFile : string | undefined , options : CompilerOptions , host : ModuleResolutionHost , redirectedReference ?: ResolvedProjectReference , cache ?: TypeReferenceDirectiveResolutionCache , resolutionMode ?: SourceFile [ "impliedNodeFormat" ] ) : ResolvedTypeReferenceDirectiveWithFailedLookupLocations {
337
+ export function resolveTypeReferenceDirective ( typeReferenceDirectiveName : string , containingFile : string | undefined , options : CompilerOptions , host : ModuleResolutionHost , redirectedReference ?: ResolvedProjectReference , cache ?: TypeReferenceDirectiveResolutionCache , resolutionMode ?: ResolutionMode ) : ResolvedTypeReferenceDirectiveWithFailedLookupLocations {
337
338
Debug . assert ( typeof typeReferenceDirectiveName === "string" , "Non-string value passed to `ts.resolveTypeReferenceDirective`, likely by a wrapping package working with an outdated `resolveTypeReferenceDirectives` signature. This is probably not a problem in TS itself." ) ;
338
339
const traceEnabled = isTraceEnabled ( options , host ) ;
339
340
if ( redirectedReference ) {
@@ -571,11 +572,11 @@ export interface TypeReferenceDirectiveResolutionCache extends PerDirectoryResol
571
572
}
572
573
573
574
export interface ModeAwareCache < T > {
574
- get ( key : string , mode : ModuleKind . CommonJS | ModuleKind . ESNext | undefined ) : T | undefined ;
575
- set ( key : string , mode : ModuleKind . CommonJS | ModuleKind . ESNext | undefined , value : T ) : this;
576
- delete ( key : string , mode : ModuleKind . CommonJS | ModuleKind . ESNext | undefined ) : this;
577
- has ( key : string , mode : ModuleKind . CommonJS | ModuleKind . ESNext | undefined ) : boolean ;
578
- forEach ( cb : ( elem : T , key : string , mode : ModuleKind . CommonJS | ModuleKind . ESNext | undefined ) => void ) : void ;
575
+ get ( key : string , mode : ResolutionMode ) : T | undefined ;
576
+ set ( key : string , mode : ResolutionMode , value : T ) : this;
577
+ delete ( key : string , mode : ResolutionMode ) : this;
578
+ has ( key : string , mode : ResolutionMode ) : boolean ;
579
+ forEach ( cb : ( elem : T , key : string , mode : ResolutionMode ) => void ) : void ;
579
580
size ( ) : number ;
580
581
}
581
582
@@ -603,7 +604,7 @@ export interface ModuleResolutionCache extends PerDirectoryResolutionCache<Resol
603
604
* We support only non-relative module names because resolution of relative module names is usually more deterministic and thus less expensive.
604
605
*/
605
606
export interface NonRelativeModuleNameResolutionCache extends PackageJsonInfoCache {
606
- getOrCreateCacheForModuleName ( nonRelativeModuleName : string , mode : ModuleKind . CommonJS | ModuleKind . ESNext | undefined , redirectedReference ?: ResolvedProjectReference ) : PerModuleNameCache ;
607
+ getOrCreateCacheForModuleName ( nonRelativeModuleName : string , mode : ResolutionMode , redirectedReference ?: ResolvedProjectReference ) : PerModuleNameCache ;
607
608
}
608
609
609
610
export interface PackageJsonInfoCache {
@@ -758,7 +759,7 @@ function createPerDirectoryResolutionCache<T>(currentDirectory: string, getCanon
758
759
export function createModeAwareCache < T > ( ) : ModeAwareCache < T > {
759
760
const underlying = new Map < ModeAwareCacheKey , T > ( ) ;
760
761
type ModeAwareCacheKey = string & { __modeAwareCacheKey : any ; } ;
761
- const memoizedReverseKeys = new Map < ModeAwareCacheKey , [ specifier : string , mode : ModuleKind . CommonJS | ModuleKind . ESNext | undefined ] > ( ) ;
762
+ const memoizedReverseKeys = new Map < ModeAwareCacheKey , [ specifier : string , mode : ResolutionMode ] > ( ) ;
762
763
763
764
const cache : ModeAwareCache < T > = {
764
765
get ( specifier , mode ) {
@@ -787,7 +788,7 @@ export function createModeAwareCache<T>(): ModeAwareCache<T> {
787
788
} ;
788
789
return cache ;
789
790
790
- function getUnderlyingCacheKey ( specifier : string , mode : ModuleKind . CommonJS | ModuleKind . ESNext | undefined ) {
791
+ function getUnderlyingCacheKey ( specifier : string , mode : ResolutionMode ) {
791
792
const result = ( mode === undefined ? specifier : `${ mode } |${ specifier } ` ) as ModeAwareCacheKey ;
792
793
memoizedReverseKeys . set ( result , [ specifier , mode ] ) ;
793
794
return result ;
@@ -864,7 +865,7 @@ export function createModuleResolutionCache(
864
865
updateRedirectsMap ( options , directoryToModuleNameMap ! , moduleNameToDirectoryMap ) ;
865
866
}
866
867
867
- function getOrCreateCacheForModuleName ( nonRelativeModuleName : string , mode : ModuleKind . CommonJS | ModuleKind . ESNext | undefined , redirectedReference ?: ResolvedProjectReference ) : PerModuleNameCache {
868
+ function getOrCreateCacheForModuleName ( nonRelativeModuleName : string , mode : ResolutionMode , redirectedReference ?: ResolvedProjectReference ) : PerModuleNameCache {
868
869
Debug . assert ( ! isExternalModuleNameRelative ( nonRelativeModuleName ) ) ;
869
870
return getOrCreateCache ( moduleNameToDirectoryMap ! , redirectedReference , mode === undefined ? nonRelativeModuleName : `${ mode } |${ nonRelativeModuleName } ` , createPerModuleNameCache ) ;
870
871
}
@@ -983,14 +984,14 @@ export function createTypeReferenceDirectiveResolutionCache(
983
984
}
984
985
}
985
986
986
- export function resolveModuleNameFromCache ( moduleName : string , containingFile : string , cache : ModuleResolutionCache , mode ?: ModuleKind . CommonJS | ModuleKind . ESNext ) : ResolvedModuleWithFailedLookupLocations | undefined {
987
+ export function resolveModuleNameFromCache ( moduleName : string , containingFile : string , cache : ModuleResolutionCache , mode ?: ResolutionMode ) : ResolvedModuleWithFailedLookupLocations | undefined {
987
988
const containingDirectory = getDirectoryPath ( containingFile ) ;
988
989
const perFolderCache = cache && cache . getOrCreateCacheForDirectory ( containingDirectory ) ;
989
990
if ( ! perFolderCache ) return undefined ;
990
991
return perFolderCache . get ( moduleName , mode ) ;
991
992
}
992
993
993
- export function resolveModuleName ( moduleName : string , containingFile : string , compilerOptions : CompilerOptions , host : ModuleResolutionHost , cache ?: ModuleResolutionCache , redirectedReference ?: ResolvedProjectReference , resolutionMode ?: ModuleKind . CommonJS | ModuleKind . ESNext ) : ResolvedModuleWithFailedLookupLocations {
994
+ export function resolveModuleName ( moduleName : string , containingFile : string , compilerOptions : CompilerOptions , host : ModuleResolutionHost , cache ?: ModuleResolutionCache , redirectedReference ?: ResolvedProjectReference , resolutionMode ?: ResolutionMode ) : ResolvedModuleWithFailedLookupLocations {
994
995
const traceEnabled = isTraceEnabled ( compilerOptions , host ) ;
995
996
if ( redirectedReference ) {
996
997
compilerOptions = redirectedReference . commandLine . options ;
@@ -1312,7 +1313,7 @@ export enum NodeResolutionFeatures {
1312
1313
1313
1314
function node16ModuleNameResolver ( moduleName : string , containingFile : string , compilerOptions : CompilerOptions ,
1314
1315
host : ModuleResolutionHost , cache ?: ModuleResolutionCache , redirectedReference ?: ResolvedProjectReference ,
1315
- resolutionMode ?: ModuleKind . CommonJS | ModuleKind . ESNext ) : ResolvedModuleWithFailedLookupLocations {
1316
+ resolutionMode ?: ResolutionMode ) : ResolvedModuleWithFailedLookupLocations {
1316
1317
return nodeNextModuleNameResolverWorker (
1317
1318
NodeResolutionFeatures . Node16Default ,
1318
1319
moduleName ,
@@ -1327,7 +1328,7 @@ function node16ModuleNameResolver(moduleName: string, containingFile: string, co
1327
1328
1328
1329
function nodeNextModuleNameResolver ( moduleName : string , containingFile : string , compilerOptions : CompilerOptions ,
1329
1330
host : ModuleResolutionHost , cache ?: ModuleResolutionCache , redirectedReference ?: ResolvedProjectReference ,
1330
- resolutionMode ?: ModuleKind . CommonJS | ModuleKind . ESNext ) : ResolvedModuleWithFailedLookupLocations {
1331
+ resolutionMode ?: ResolutionMode ) : ResolvedModuleWithFailedLookupLocations {
1331
1332
return nodeNextModuleNameResolverWorker (
1332
1333
NodeResolutionFeatures . NodeNextDefault ,
1333
1334
moduleName ,
@@ -1344,7 +1345,7 @@ const jsOnlyExtensions = [Extensions.JavaScript];
1344
1345
const tsExtensions = [ Extensions . TypeScript , Extensions . JavaScript ] ;
1345
1346
const tsPlusJsonExtensions = [ ...tsExtensions , Extensions . Json ] ;
1346
1347
const tsconfigExtensions = [ Extensions . TSConfig ] ;
1347
- function nodeNextModuleNameResolverWorker ( features : NodeResolutionFeatures , moduleName : string , containingFile : string , compilerOptions : CompilerOptions , host : ModuleResolutionHost , cache ?: ModuleResolutionCache , redirectedReference ?: ResolvedProjectReference , resolutionMode ?: ModuleKind . CommonJS | ModuleKind . ESNext ) : ResolvedModuleWithFailedLookupLocations {
1348
+ function nodeNextModuleNameResolverWorker ( features : NodeResolutionFeatures , moduleName : string , containingFile : string , compilerOptions : CompilerOptions , host : ModuleResolutionHost , cache ?: ModuleResolutionCache , redirectedReference ?: ResolvedProjectReference , resolutionMode ?: ResolutionMode ) : ResolvedModuleWithFailedLookupLocations {
1348
1349
const containingDirectory = getDirectoryPath ( containingFile ) ;
1349
1350
1350
1351
// es module file or cjs-like input file, use a variant of the legacy cjs resolver that supports the selected modern features
0 commit comments