@@ -5,10 +5,6 @@ import * as ts from 'typescript';
5
5
6
6
const NEW_LINE = '\n' ;
7
7
8
- // When making a project with only a subset of the files in the original tsconfig,
9
- // 6307 errors will appear when importing other files, but they're only a problem because the tsconfig has been edited
10
- const CODE_FILE_NOT_INCLUDED = 6307 ;
11
-
12
8
type TypeScriptReadConfigResult = {
13
9
config : {
14
10
compilerOptions : ts . CompilerOptions ;
@@ -81,6 +77,11 @@ export function typescript(configFilePath: string, extraCompilerOptions: ts.Comp
81
77
} ) ;
82
78
}
83
79
80
+ // TypeScript throws a 6307 error when it need to access type information from a file
81
+ // that wasn't included by the tsconfig. This happens whenever we run the compiler on
82
+ // a subset of files, so we need to filter out those errors!
83
+ const CODE_FILE_NOT_INCLUDED = 6307 ;
84
+
84
85
/** @internal Definitely not stable! Please don't use! */
85
86
export function typescriptΔ ( configFilePath : string , extraCompilerOptions : ts . CompilerOptions = { } ) : BettererFileTest {
86
87
if ( ! configFilePath ) {
@@ -106,8 +107,11 @@ export function typescriptΔ(configFilePath: string, extraCompilerOptions: ts.Co
106
107
...extraCompilerOptions
107
108
} ;
108
109
config . compilerOptions = fullCompilerOptions ;
109
- config . files = filePaths ;
110
- delete config . include ;
110
+
111
+ if ( ! config . compilerOptions . incremental ) {
112
+ config . files = filePaths ;
113
+ delete config . include ;
114
+ }
111
115
112
116
const compilerHost = ts . createCompilerHost ( fullCompilerOptions ) ;
113
117
const configHost : ts . ParseConfigHost = {
@@ -139,8 +143,13 @@ export function typescriptΔ(configFilePath: string, extraCompilerOptions: ts.Co
139
143
] ) ;
140
144
141
145
allDiagnostics
142
- . filter ( ( d ) : d is ts . DiagnosticWithLocation => d . file !== undefined && d . start != null && d . length != null )
143
- . filter ( ( { file, code } ) => filePaths . includes ( file . fileName ) && code !== CODE_FILE_NOT_INCLUDED )
146
+ . filter ( ( diagnostic ) : diagnostic is ts . DiagnosticWithLocation => {
147
+ const { file, start, length } = diagnostic ;
148
+ return file != null && start != null && length != null ;
149
+ } )
150
+ . filter ( ( { file, code } ) => {
151
+ return filePaths . includes ( file . fileName ) && code !== CODE_FILE_NOT_INCLUDED ;
152
+ } )
144
153
. forEach ( ( { start, length, file : source , messageText } ) => {
145
154
const file = fileTestResult . addFile ( source . fileName , source . getFullText ( ) ) ;
146
155
const message = ts . flattenDiagnosticMessageText ( messageText , NEW_LINE ) ;
0 commit comments