@@ -477,13 +477,13 @@ export function create (rawOptions: CreateOptions = {}): Register {
477477 // Use full language services when the fast option is disabled.
478478 if ( ! transpileOnly ) {
479479 const fileContents = new Map < string , string > ( )
480- const rootFileNames = config . fileNames . slice ( )
480+ const rootFileNames = new Set ( config . fileNames )
481481 const cachedReadFile = cachedLookup ( debugFn ( 'readFile' , readFile ) )
482482
483483 // Use language services by default (TODO: invert next major version).
484484 if ( ! options . compilerHost ) {
485485 let projectVersion = 1
486- const fileVersions = new Map ( rootFileNames . map ( fileName => [ fileName , 0 ] ) )
486+ const fileVersions = new Map ( Array . from ( rootFileNames ) . map ( fileName => [ fileName , 0 ] ) )
487487
488488 const getCustomTransformers = ( ) => {
489489 if ( typeof transformers === 'function' ) {
@@ -497,7 +497,7 @@ export function create (rawOptions: CreateOptions = {}): Register {
497497 // Create the compiler host for type checking.
498498 const serviceHost : _ts . LanguageServiceHost = {
499499 getProjectVersion : ( ) => String ( projectVersion ) ,
500- getScriptFileNames : ( ) => Array . from ( fileVersions . keys ( ) ) ,
500+ getScriptFileNames : ( ) => Array . from ( rootFileNames ) ,
501501 getScriptVersion : ( fileName : string ) => {
502502 const version = fileVersions . get ( fileName )
503503 return version ? version . toString ( ) : ''
@@ -533,9 +533,12 @@ export function create (rawOptions: CreateOptions = {}): Register {
533533 const service = ts . createLanguageService ( serviceHost , registry )
534534
535535 const updateMemoryCache = ( contents : string , fileName : string ) => {
536- // Add to `rootFiles` when discovered for the first time.
537- if ( ! fileVersions . has ( fileName ) ) {
538- rootFileNames . push ( fileName )
536+ // Add to `rootFiles` if not already there
537+ // This is necessary to force TS to emit output
538+ if ( ! rootFileNames . has ( fileName ) ) {
539+ rootFileNames . add ( fileName )
540+ // Increment project version for every change to rootFileNames.
541+ projectVersion ++
539542 }
540543
541544 const previousVersion = fileVersions . get ( fileName ) || 0
@@ -637,14 +640,14 @@ export function create (rawOptions: CreateOptions = {}): Register {
637640 // Fallback for older TypeScript releases without incremental API.
638641 let builderProgram = ts . createIncrementalProgram
639642 ? ts . createIncrementalProgram ( {
640- rootNames : rootFileNames . slice ( ) ,
643+ rootNames : Array . from ( rootFileNames ) ,
641644 options : config . options ,
642645 host : host ,
643646 configFileParsingDiagnostics : config . errors ,
644647 projectReferences : config . projectReferences
645648 } )
646649 : ts . createEmitAndSemanticDiagnosticsBuilderProgram (
647- rootFileNames . slice ( ) ,
650+ Array . from ( rootFileNames ) ,
648651 config . options ,
649652 host ,
650653 undefined ,
@@ -665,13 +668,13 @@ export function create (rawOptions: CreateOptions = {}): Register {
665668
666669 // Add to `rootFiles` when discovered by compiler for the first time.
667670 if ( sourceFile === undefined ) {
668- rootFileNames . push ( fileName )
671+ rootFileNames . add ( fileName )
669672 }
670673
671674 // Update program when file changes.
672675 if ( sourceFile === undefined || sourceFile . text !== contents ) {
673676 builderProgram = ts . createEmitAndSemanticDiagnosticsBuilderProgram (
674- rootFileNames . slice ( ) ,
677+ Array . from ( rootFileNames ) ,
675678 config . options ,
676679 host ,
677680 builderProgram ,
0 commit comments