@@ -7,8 +7,7 @@ namespace ts {
7
7
host . trace ( formatMessage . apply ( undefined , arguments ) ) ;
8
8
}
9
9
10
- /* @internal */
11
- export function isTraceEnabled ( compilerOptions : CompilerOptions , host : ModuleResolutionHost ) : boolean {
10
+ function isTraceEnabled ( compilerOptions : CompilerOptions , host : ModuleResolutionHost ) : boolean {
12
11
return compilerOptions . traceResolution && host . trace !== undefined ;
13
12
}
14
13
@@ -79,37 +78,6 @@ namespace ts {
79
78
traceEnabled : boolean ;
80
79
}
81
80
82
- /** LsHost uses a global cache of automatically-installed typings to help it resolve modules. */
83
- /* @internal */
84
- export function resolveModuleNameForLsHost ( moduleName : string , containingFile : string , compilerOptions : CompilerOptions , host : ModuleResolutionHost , globalCache : string | undefined , projectName : string ) : ResolvedModuleWithFailedLookupLocations {
85
- const primaryResult = resolveModuleName ( moduleName , containingFile , compilerOptions , host ) ;
86
- if ( primaryResult . resolvedModule && primaryResult . resolvedModule . resolvedTsFileName ) {
87
- // return result immediately only if it is .ts, .tsx or .d.ts
88
- // otherwise try to load typings from @types
89
- return primaryResult ;
90
- }
91
-
92
- // create different collection of failed lookup locations for second pass
93
- // if it will fail and we've already found something during the first pass - we don't want to pollute its results
94
- const secondaryLookupFailedLookupLocations : string [ ] = [ ] ;
95
- if ( globalCache !== undefined ) {
96
- const traceEnabled = isTraceEnabled ( compilerOptions , host ) ;
97
- if ( traceEnabled ) {
98
- 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 ) ;
99
- }
100
- const state : ModuleResolutionState = { compilerOptions, host, traceEnabled } ;
101
- const resolved = loadModuleFromNodeModules ( Extensions . All , moduleName , globalCache , secondaryLookupFailedLookupLocations , state , /*checkOneLevel*/ true ) ;
102
- if ( resolved ) {
103
- return createResolvedModuleWithFailedLookupLocations ( resolved , /*isExternalLibraryImport*/ true , primaryResult . failedLookupLocations . concat ( secondaryLookupFailedLookupLocations ) ) ;
104
- }
105
- }
106
-
107
- if ( ! primaryResult . resolvedModule && secondaryLookupFailedLookupLocations . length ) {
108
- primaryResult . failedLookupLocations = primaryResult . failedLookupLocations . concat ( secondaryLookupFailedLookupLocations ) ;
109
- }
110
- return primaryResult ;
111
- }
112
-
113
81
function tryReadTypesSection ( packageJsonPath : string , baseDirectory : string , state : ModuleResolutionState ) : string {
114
82
const jsonContent = readJson ( packageJsonPath , state . host ) ;
115
83
@@ -850,4 +818,20 @@ namespace ts {
850
818
containingDirectory = parentPath ;
851
819
}
852
820
}
821
+
822
+ /**
823
+ * LSHost may load a module from a global cache of typings.
824
+ * This is the minumum code needed to expose that functionality; the rest is in LSHost.
825
+ */
826
+ /* @internal */
827
+ export function loadModuleFromGlobalCache ( moduleName : string , projectName : string , compilerOptions : CompilerOptions , host : ModuleResolutionHost , globalCache : string ) : ResolvedModuleWithFailedLookupLocations {
828
+ const traceEnabled = isTraceEnabled ( compilerOptions , host ) ;
829
+ if ( traceEnabled ) {
830
+ 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 ) ;
831
+ }
832
+ const state : ModuleResolutionState = { compilerOptions, host, traceEnabled } ;
833
+ const failedLookupLocations : string [ ] = [ ] ;
834
+ const resolved = loadModuleFromNodeModules ( Extensions . All , moduleName , globalCache , failedLookupLocations , state , /*checkOneLevel*/ true ) ;
835
+ return createResolvedModuleWithFailedLookupLocations ( resolved , /*isExternalLibraryImport*/ true , failedLookupLocations ) ;
836
+ }
853
837
}
0 commit comments