@@ -17,7 +17,9 @@ import {
17
17
ServiceHostWhichMayBeCacheable ,
18
18
SolutionBuilderWithWatchHost ,
19
19
SolutionDiagnostics ,
20
+ TSCommon ,
20
21
TSInstance ,
22
+ TSInternal ,
21
23
WatchCallbacks ,
22
24
WatchFactory ,
23
25
WatchHost ,
@@ -175,9 +177,10 @@ export function makeServicesHost(
175
177
return file . version . toString ( ) ;
176
178
}
177
179
178
- const outputFileAndKey = instance . solutionBuilderHost ?. getOutputFileAndKeyFromReferencedProject (
179
- fileName
180
- ) ;
180
+ const outputFileAndKey =
181
+ instance . solutionBuilderHost ?. getOutputFileAndKeyFromReferencedProject (
182
+ fileName
183
+ ) ;
181
184
if ( outputFileAndKey !== undefined ) {
182
185
instance . solutionBuilderHost ! . outputAffectingInstanceVersion . set (
183
186
outputFileAndKey . key ,
@@ -198,9 +201,10 @@ export function makeServicesHost(
198
201
199
202
if ( file === undefined ) {
200
203
if ( instance . solutionBuilderHost ) {
201
- const outputFileAndKey = instance . solutionBuilderHost . getOutputFileTextAndKeyFromReferencedProject (
202
- fileName
203
- ) ;
204
+ const outputFileAndKey =
205
+ instance . solutionBuilderHost . getOutputFileTextAndKeyFromReferencedProject (
206
+ fileName
207
+ ) ;
204
208
if ( outputFileAndKey !== undefined ) {
205
209
instance . solutionBuilderHost ! . outputAffectingInstanceVersion . set (
206
210
outputFileAndKey . key ,
@@ -288,16 +292,20 @@ function makeResolvers<T extends typescript.ModuleResolutionHost>(
288
292
) ;
289
293
290
294
const resolveTypeReferenceDirectives = (
291
- typeDirectiveNames : string [ ] ,
295
+ typeDirectiveNames : string [ ] | readonly typescript . FileReference [ ] ,
292
296
containingFile : string ,
293
- redirectedReference ?: typescript . ResolvedProjectReference
297
+ redirectedReference : typescript . ResolvedProjectReference | undefined ,
298
+ options : typescript . CompilerOptions ,
299
+ containingFileMode ?: typescript . SourceFile [ 'impliedNodeFormat' ] | undefined // new impliedNodeFormat is accepted by compilerHost
294
300
) : ( typescript . ResolvedTypeReferenceDirective | undefined ) [ ] =>
295
301
typeDirectiveNames . map (
296
302
directive =>
297
303
resolveTypeReferenceDirective (
298
304
directive ,
299
305
containingFile ,
300
- redirectedReference
306
+ options ,
307
+ redirectedReference ,
308
+ containingFileMode
301
309
) . resolvedTypeReferenceDirective
302
310
) ;
303
311
@@ -312,9 +320,12 @@ function createWatchFactory(
312
320
filePathKeyMapper : ( fileName : string ) => FilePathKey ,
313
321
compiler : typeof typescript
314
322
) : WatchFactory {
315
- const watchedFiles : WatchCallbacks < typescript . FileWatcherCallback > = new Map ( ) ;
316
- const watchedDirectories : WatchCallbacks < typescript . DirectoryWatcherCallback > = new Map ( ) ;
317
- const watchedDirectoriesRecursive : WatchCallbacks < typescript . DirectoryWatcherCallback > = new Map ( ) ;
323
+ const watchedFiles : WatchCallbacks < typescript . FileWatcherCallback > =
324
+ new Map ( ) ;
325
+ const watchedDirectories : WatchCallbacks < typescript . DirectoryWatcherCallback > =
326
+ new Map ( ) ;
327
+ const watchedDirectoriesRecursive : WatchCallbacks < typescript . DirectoryWatcherCallback > =
328
+ new Map ( ) ;
318
329
319
330
return {
320
331
watchedFiles,
@@ -473,13 +484,8 @@ export function makeWatchHost(
473
484
instance : TSInstance ,
474
485
projectReferences ?: ReadonlyArray < typescript . ProjectReference >
475
486
) {
476
- const {
477
- compiler,
478
- compilerOptions,
479
- files,
480
- otherFiles,
481
- filePathKeyMapper,
482
- } = instance ;
487
+ const { compiler, compilerOptions, files, otherFiles, filePathKeyMapper } =
488
+ instance ;
483
489
484
490
const { watchFile, watchDirectory, invokeFileWatcher } = createWatchFactory (
485
491
filePathKeyMapper ,
@@ -507,9 +513,10 @@ export function makeWatchHost(
507
513
readFile : readFileWithCachingText ,
508
514
509
515
watchFile : ( fileName , callback , pollingInterval , options ) => {
510
- const outputFileKey = instance . solutionBuilderHost ?. getOutputFileKeyFromReferencedProject (
511
- fileName
512
- ) ;
516
+ const outputFileKey =
517
+ instance . solutionBuilderHost ?. getOutputFileKeyFromReferencedProject (
518
+ fileName
519
+ ) ;
513
520
if ( ! outputFileKey || outputFileKey === filePathKeyMapper ( fileName ) ) {
514
521
return watchFile ( fileName , callback , pollingInterval , options ) ;
515
522
}
@@ -1155,9 +1162,11 @@ export function getSolutionErrors(instance: TSInstance, context: string) {
1155
1162
}
1156
1163
1157
1164
type ResolveTypeReferenceDirective = (
1158
- directive : string ,
1165
+ directive : string | typescript . FileReference ,
1159
1166
containingFile : string ,
1160
- redirectedReference ?: typescript . ResolvedProjectReference
1167
+ options : typescript . CompilerOptions ,
1168
+ redirectedReference ?: typescript . ResolvedProjectReference ,
1169
+ containingFileMode ?: typescript . SourceFile [ 'impliedNodeFormat' ] | undefined // new impliedNodeFormat is accepted by compilerHost
1161
1170
) => typescript . ResolvedTypeReferenceDirectiveWithFailedLookupLocations ;
1162
1171
1163
1172
function makeResolveTypeReferenceDirective (
@@ -1172,31 +1181,50 @@ function makeResolveTypeReferenceDirective(
1172
1181
if ( customResolveTypeReferenceDirective === undefined ) {
1173
1182
// Until the api is published
1174
1183
if (
1175
- ( compiler as any ) . createTypeReferenceDirectiveResolutionCache &&
1184
+ compiler . createTypeReferenceDirectiveResolutionCache !== undefined &&
1176
1185
! instance . typeReferenceResolutionCache
1177
1186
) {
1178
- instance . typeReferenceResolutionCache = ( compiler as any ) . createTypeReferenceDirectiveResolutionCache (
1179
- moduleResolutionHost . getCurrentDirectory ! ( ) ,
1180
- createGetCanonicalFileName ( instance ) ,
1181
- instance . compilerOptions ,
1182
- instance . moduleResolutionCache ?. getPackageJsonInfoCache ?.( )
1183
- ) ;
1187
+ instance . typeReferenceResolutionCache =
1188
+ compiler . createTypeReferenceDirectiveResolutionCache (
1189
+ moduleResolutionHost . getCurrentDirectory ! ( ) ,
1190
+ createGetCanonicalFileName ( instance ) ,
1191
+ instance . compilerOptions ,
1192
+ instance . moduleResolutionCache ?. getPackageJsonInfoCache ?.( )
1193
+ ) ;
1184
1194
}
1185
- return ( directive , containingFile , redirectedReference ) =>
1186
- // Until the api is published
1187
- ( compiler . resolveTypeReferenceDirective as any ) (
1188
- directive ,
1195
+ return (
1196
+ typeDirectiveName ,
1197
+ containingFile ,
1198
+ options ,
1199
+ redirectedReference ,
1200
+ containingFileMode
1201
+ ) => {
1202
+ // Copy-pasted from https://github.com/TypeStrong/ts-node/blob/9f789d0d91c6eba30ac7f7aad45194a23b44f159/src/resolver-functions.ts#L139
1203
+ const nameIsString = typeof typeDirectiveName === 'string' ;
1204
+ const mode = nameIsString
1205
+ ? undefined
1206
+ : ( compiler as any as TSInternal ) . getModeForFileReference ! (
1207
+ typeDirectiveName ,
1208
+ containingFileMode
1209
+ ) ;
1210
+ const strName = nameIsString
1211
+ ? typeDirectiveName
1212
+ : typeDirectiveName . fileName . toLowerCase ( ) ;
1213
+ return ( compiler as any as TSCommon ) . resolveTypeReferenceDirective (
1214
+ strName ,
1189
1215
containingFile ,
1190
- compilerOptions ,
1216
+ options ,
1191
1217
moduleResolutionHost ,
1192
1218
redirectedReference ,
1193
- instance . typeReferenceResolutionCache
1219
+ undefined ,
1220
+ mode
1194
1221
) ;
1222
+ } ;
1195
1223
}
1196
1224
1197
1225
return ( directive , containingFile ) =>
1198
1226
customResolveTypeReferenceDirective (
1199
- directive ,
1227
+ directive as string , // unsure whether we should evolve this further
1200
1228
containingFile ,
1201
1229
compilerOptions ,
1202
1230
moduleResolutionHost ,
0 commit comments