@@ -25,6 +25,16 @@ export class ProjectHost implements ts.CompilerHost {
2525 private processedFiles = new Map < string , ProcessedFileInfo > ( ) ;
2626 private sourceFileCache = new Map < string , ts . SourceFile | undefined > ( ) ;
2727 private fileContent = new Map < string , string > ( ) ;
28+ private tsconfigCache = new Map < string , ts . ExtendedConfigCacheEntry > ( ) ;
29+ private commandLineCache = new Map < string , ts . ParsedCommandLine > ( ) ;
30+
31+ private parseConfigHost : ts . ParseConfigHost = {
32+ useCaseSensitiveFileNames : this . useCaseSensitiveFileNames ( ) ,
33+ readDirectory :
34+ ( rootDir , extensions , excludes , includes , depth ) => this . readDirectory ( rootDir , extensions , excludes , includes , depth ) ,
35+ fileExists : ( f ) => this . fileExists ( f ) ,
36+ readFile : ( f ) => this . readFile ( f ) ,
37+ } ;
2838
2939 public getCanonicalFileName = ts . sys . useCaseSensitiveFileNames ? ( f : string ) => f : ( f : string ) => f . toLowerCase ( ) ;
3040 private moduleResolutionCache = ts . createModuleResolutionCache ( this . cwd , this . getCanonicalFileName ) ;
@@ -208,6 +218,8 @@ export class ProjectHost implements ts.CompilerHost {
208218 ( entry ) => entry . kind === FileKind . Directory ? path . join ( dir , entry . name ) : undefined ,
209219 ) ;
210220 }
221+ public getSourceFile ( fileName : string , languageVersion : ts . ScriptTarget . JSON ) : ts . JsonSourceFile | undefined ;
222+ public getSourceFile ( fileName : string , languageVersion : ts . ScriptTarget ) : ts . SourceFile | undefined ;
211223 public getSourceFile ( fileName : string , languageVersion : ts . ScriptTarget ) {
212224 return resolveCachedResult (
213225 this . sourceFileCache ,
@@ -225,6 +237,7 @@ export class ProjectHost implements ts.CompilerHost {
225237 oldProgram : ts . Program | undefined ,
226238 projectReferences : ReadonlyArray < ts . ProjectReference > | undefined ,
227239 ) {
240+ options = { ...options , suppressOutputPathCheck : true } ;
228241 this . compilerOptions = options ;
229242 this . moduleResolutionCache = ts . createModuleResolutionCache ( this . cwd , this . getCanonicalFileName , options ) ;
230243 return ts . createProgram ( { rootNames, options, oldProgram, projectReferences, host : this } ) ;
@@ -255,6 +268,29 @@ export class ProjectHost implements ts.CompilerHost {
255268 this . processedFiles . delete ( fileName ) ;
256269 }
257270
271+ public getParsedCommandLine ( fileName : string ) {
272+ return resolveCachedResult ( this . commandLineCache , fileName , this . parseConfigFile ) ;
273+ }
274+
275+ @bind
276+ private parseConfigFile ( fileName : string ) {
277+ // Note to future self: it's highly unlikely that a tsconfig of a project reference is used as base config for another tsconfig.
278+ // Therefore it doesn't make such sense to read or write the tsconfigCache here.
279+ const sourceFile = this . getSourceFile ( fileName , ts . ScriptTarget . JSON ) ;
280+ if ( sourceFile === undefined )
281+ return ;
282+ return ts . parseJsonSourceFileConfigFileContent (
283+ sourceFile ,
284+ this . parseConfigHost ,
285+ path . dirname ( fileName ) ,
286+ undefined ,
287+ fileName ,
288+ undefined ,
289+ undefined ,
290+ < ts . Map < ts . ExtendedConfigCacheEntry > > this . tsconfigCache ,
291+ ) ;
292+ }
293+
258294 public resolveModuleNames ( names : string [ ] , file : string , _ ?: unknown , reference ?: ts . ResolvedProjectReference ) {
259295 const seen = new Map < string , ts . ResolvedModuleFull | undefined > ( ) ;
260296 const resolve = ( name : string ) =>
0 commit comments