@@ -26,23 +26,6 @@ namespace ts {
2626 isInvalidated ?: boolean ;
2727 }
2828
29- interface ResolverWithGlobalCache {
30- ( primaryResult : ResolvedModuleWithFailedLookupLocations , moduleName : string , compilerOptions : CompilerOptions , host : ModuleResolutionHost ) : ResolvedModuleWithFailedLookupLocations | undefined ;
31- }
32-
33- export function resolveWithGlobalCache ( primaryResult : ResolvedModuleWithFailedLookupLocations , moduleName : string , compilerOptions : CompilerOptions , host : ModuleResolutionHost , globalCache : string | undefined , projectName : string ) : ResolvedModuleWithFailedLookupLocations | undefined {
34- if ( ! isExternalModuleNameRelative ( moduleName ) && ! ( primaryResult . resolvedModule && extensionIsTypeScript ( primaryResult . resolvedModule . extension ) ) && globalCache !== undefined ) {
35- // otherwise try to load typings from @types
36-
37- // create different collection of failed lookup locations for second pass
38- // if it will fail and we've already found something during the first pass - we don't want to pollute its results
39- const { resolvedModule, failedLookupLocations } = loadModuleFromGlobalCache ( moduleName , projectName , compilerOptions , host , globalCache ) ;
40- if ( resolvedModule ) {
41- return { resolvedModule, failedLookupLocations : primaryResult . failedLookupLocations . concat ( failedLookupLocations ) } ;
42- }
43- }
44- }
45-
4629 interface FailedLookupLocationsWatcher {
4730 fileWatcher : FileWatcher ;
4831 refCount : number ;
@@ -53,7 +36,8 @@ namespace ts {
5336 getCompilerOptions : ( ) => CompilerOptions ,
5437 watchForFailedLookupLocation : ( failedLookupLocation : string , failedLookupLocationPath : Path , containingFile : string , name : string ) => FileWatcher ,
5538 log : ( s : string ) => void ,
56- resolveWithGlobalCache ?: ResolverWithGlobalCache ) : ResolutionCache {
39+ projectName ?: string ,
40+ getGlobalCache ?: ( ) => string | undefined ) : ResolutionCache {
5741
5842 let host : ModuleResolutionHost ;
5943 let filesWithChangedSetOfUnresolvedImports : Path [ ] ;
@@ -107,9 +91,24 @@ namespace ts {
10791
10892 function resolveModuleName ( moduleName : string , containingFile : string , compilerOptions : CompilerOptions , host : ModuleResolutionHost ) : ResolvedModuleWithFailedLookupLocations {
10993 const primaryResult = ts . resolveModuleName ( moduleName , containingFile , compilerOptions , host ) ;
110- // return result immediately only if it is .ts, .tsx or .d.ts
94+ // return result immediately only if global cache support is not enabled or if it is .ts, .tsx or .d.ts
95+ if ( ! getGlobalCache ) {
96+ return primaryResult ;
97+ }
98+
11199 // otherwise try to load typings from @types
112- return ( resolveWithGlobalCache && resolveWithGlobalCache ( primaryResult , moduleName , compilerOptions , host ) ) || primaryResult ;
100+ const globalCache = getGlobalCache ( ) ;
101+ if ( globalCache !== undefined && ! isExternalModuleNameRelative ( moduleName ) && ! ( primaryResult . resolvedModule && extensionIsTypeScript ( primaryResult . resolvedModule . extension ) ) ) {
102+ // create different collection of failed lookup locations for second pass
103+ // if it will fail and we've already found something during the first pass - we don't want to pollute its results
104+ const { resolvedModule, failedLookupLocations } = loadModuleFromGlobalCache ( moduleName , projectName , compilerOptions , host , globalCache ) ;
105+ if ( resolvedModule ) {
106+ return { resolvedModule, failedLookupLocations : primaryResult . failedLookupLocations . concat ( failedLookupLocations ) } ;
107+ }
108+ }
109+
110+ // Default return the result from the first pass
111+ return primaryResult ;
113112 }
114113
115114 function resolveNamesWithLocalCache < T extends NameResolutionWithFailedLookupLocations , R > (
0 commit comments