@@ -13,14 +13,8 @@ export function createResolverFunctions(kwargs: {
13
13
config : _ts . ParsedCommandLine ;
14
14
configFilePath : string | undefined ;
15
15
} ) {
16
- const {
17
- host,
18
- ts,
19
- config,
20
- cwd,
21
- getCanonicalFileName,
22
- configFilePath,
23
- } = kwargs ;
16
+ const { host, ts, config, cwd, getCanonicalFileName, configFilePath } =
17
+ kwargs ;
24
18
const moduleResolutionCache = ts . createModuleResolutionCache (
25
19
cwd ,
26
20
getCanonicalFileName ,
@@ -105,69 +99,71 @@ export function createResolverFunctions(kwargs: {
105
99
} ;
106
100
107
101
// language service never calls this, but TS docs recommend that we implement it
108
- const getResolvedModuleWithFailedLookupLocationsFromCache : _ts . LanguageServiceHost [ 'getResolvedModuleWithFailedLookupLocationsFromCache' ] = (
109
- moduleName ,
110
- containingFile
111
- ) : _ts . ResolvedModuleWithFailedLookupLocations | undefined => {
112
- const ret = ts . resolveModuleNameFromCache (
102
+ const getResolvedModuleWithFailedLookupLocationsFromCache : _ts . LanguageServiceHost [ 'getResolvedModuleWithFailedLookupLocationsFromCache' ] =
103
+ (
113
104
moduleName ,
114
- containingFile ,
115
- moduleResolutionCache
116
- ) ;
117
- if ( ret && ret . resolvedModule ) {
118
- fixupResolvedModule ( ret . resolvedModule ) ;
119
- }
120
- return ret ;
121
- } ;
122
-
123
- const resolveTypeReferenceDirectives : _ts . LanguageServiceHost [ 'resolveTypeReferenceDirectives' ] = (
124
- typeDirectiveNames : string [ ] ,
125
- containingFile : string ,
126
- redirectedReference : _ts . ResolvedProjectReference | undefined ,
127
- options : _ts . CompilerOptions
128
- ) : ( _ts . ResolvedTypeReferenceDirective | undefined ) [ ] => {
129
- // Note: seems to be called with empty typeDirectiveNames array for all files.
130
- return typeDirectiveNames . map ( ( typeDirectiveName ) => {
131
- let { resolvedTypeReferenceDirective } = ts . resolveTypeReferenceDirective (
132
- typeDirectiveName ,
105
+ containingFile
106
+ ) : _ts . ResolvedModuleWithFailedLookupLocations | undefined => {
107
+ const ret = ts . resolveModuleNameFromCache (
108
+ moduleName ,
133
109
containingFile ,
134
- config . options ,
135
- host ,
136
- redirectedReference
110
+ moduleResolutionCache
137
111
) ;
138
- if ( typeDirectiveName === 'node' && ! resolvedTypeReferenceDirective ) {
139
- // Resolve @types /node relative to project first, then __dirname (copy logic from elsewhere / refactor into reusable function)
140
- let typesNodePackageJsonPath : string | undefined ;
141
- try {
142
- typesNodePackageJsonPath = require . resolve (
143
- '@types/node/package.json' ,
144
- {
145
- paths : [ configFilePath ?? cwd , __dirname ] ,
146
- }
147
- ) ;
148
- } catch { } // gracefully do nothing when @types /node is not installed for any reason
149
- if ( typesNodePackageJsonPath ) {
150
- const typeRoots = [ resolve ( typesNodePackageJsonPath , '../..' ) ] ;
151
- ( {
152
- resolvedTypeReferenceDirective,
153
- } = ts . resolveTypeReferenceDirective (
112
+ if ( ret && ret . resolvedModule ) {
113
+ fixupResolvedModule ( ret . resolvedModule ) ;
114
+ }
115
+ return ret ;
116
+ } ;
117
+
118
+ const resolveTypeReferenceDirectives : _ts . LanguageServiceHost [ 'resolveTypeReferenceDirectives' ] =
119
+ (
120
+ typeDirectiveNames : string [ ] ,
121
+ containingFile : string ,
122
+ redirectedReference : _ts . ResolvedProjectReference | undefined ,
123
+ options : _ts . CompilerOptions
124
+ ) : ( _ts . ResolvedTypeReferenceDirective | undefined ) [ ] => {
125
+ // Note: seems to be called with empty typeDirectiveNames array for all files.
126
+ return typeDirectiveNames . map ( ( typeDirectiveName ) => {
127
+ let { resolvedTypeReferenceDirective } =
128
+ ts . resolveTypeReferenceDirective (
154
129
typeDirectiveName ,
155
130
containingFile ,
156
- {
157
- ...config . options ,
158
- typeRoots,
159
- } ,
131
+ config . options ,
160
132
host ,
161
133
redirectedReference
162
- ) ) ;
134
+ ) ;
135
+ if ( typeDirectiveName === 'node' && ! resolvedTypeReferenceDirective ) {
136
+ // Resolve @types /node relative to project first, then __dirname (copy logic from elsewhere / refactor into reusable function)
137
+ let typesNodePackageJsonPath : string | undefined ;
138
+ try {
139
+ typesNodePackageJsonPath = require . resolve (
140
+ '@types/node/package.json' ,
141
+ {
142
+ paths : [ configFilePath ?? cwd , __dirname ] ,
143
+ }
144
+ ) ;
145
+ } catch { } // gracefully do nothing when @types /node is not installed for any reason
146
+ if ( typesNodePackageJsonPath ) {
147
+ const typeRoots = [ resolve ( typesNodePackageJsonPath , '../..' ) ] ;
148
+ ( { resolvedTypeReferenceDirective } =
149
+ ts . resolveTypeReferenceDirective (
150
+ typeDirectiveName ,
151
+ containingFile ,
152
+ {
153
+ ...config . options ,
154
+ typeRoots,
155
+ } ,
156
+ host ,
157
+ redirectedReference
158
+ ) ) ;
159
+ }
163
160
}
164
- }
165
- if ( resolvedTypeReferenceDirective ) {
166
- fixupResolvedModule ( resolvedTypeReferenceDirective ) ;
167
- }
168
- return resolvedTypeReferenceDirective ;
169
- } ) ;
170
- } ;
161
+ if ( resolvedTypeReferenceDirective ) {
162
+ fixupResolvedModule ( resolvedTypeReferenceDirective ) ;
163
+ }
164
+ return resolvedTypeReferenceDirective ;
165
+ } ) ;
166
+ } ;
171
167
172
168
return {
173
169
resolveModuleNames,
0 commit comments