@@ -68,7 +68,7 @@ function successLoader(
68
68
)
69
69
: rawFilePath ;
70
70
71
- const fileVersion = updateFileInCache ( filePath , contents , instance ) ;
71
+ const fileVersion = updateFileInCache ( options , filePath , contents , instance ) ;
72
72
const referencedProject = getAndCacheProjectReference ( filePath , instance ) ;
73
73
if ( referencedProject !== undefined ) {
74
74
const [ relativeProjectConfigPath , relativeFilePath ] = [
@@ -332,6 +332,7 @@ function makeLoaderOptions(instanceName: string, loaderOptions: LoaderOptions) {
332
332
* Also add the file to the modified files
333
333
*/
334
334
function updateFileInCache (
335
+ options : LoaderOptions ,
335
336
filePath : string ,
336
337
contents : string ,
337
338
instance : TSInstance
@@ -358,6 +359,20 @@ function updateFileInCache(
358
359
fileWatcherEventKind = instance . compiler . FileWatcherEventKind . Deleted ;
359
360
}
360
361
362
+ // filePath is a root file as it was passed to the loader. But it
363
+ // could have been found earlier as a dependency of another file. If
364
+ // that is the case, compiling this file changes the structure of
365
+ // the program and we need to increase the instance version.
366
+ //
367
+ // See https://github.com/TypeStrong/ts-loader/issues/943
368
+ if (
369
+ ! instance . rootFileNames . has ( filePath ) &&
370
+ ( options . allowTsInNodeModules || filePath . indexOf ( 'node_modules' ) !== - 1 )
371
+ ) {
372
+ instance . version ! ++ ;
373
+ instance . rootFileNames . add ( filePath ) ;
374
+ }
375
+
361
376
if ( file . text !== contents ) {
362
377
file . version ++ ;
363
378
file . text = contents ;
@@ -381,6 +396,7 @@ function updateFileInCache(
381
396
instance . modifiedFiles = new Map < string , TSFile > ( ) ;
382
397
}
383
398
instance . modifiedFiles . set ( filePath , file ) ;
399
+
384
400
return file . version ;
385
401
}
386
402
0 commit comments