@@ -8,6 +8,7 @@ import { Plugin } from "./plugins";
88import { getTransformers } from "./transformers" ;
99import { EmitHost , ProcessedFile } from "./utils" ;
1010import * as performance from "../measure-performance" ;
11+ import { parseConfigFileWithSystem } from "../cli/tsconfig" ;
1112
1213export interface TranspileOptions {
1314 program : ts . Program ;
@@ -30,13 +31,38 @@ export function getProgramTranspileResult(
3031
3132 const options = program . getCompilerOptions ( ) as CompilerOptions ;
3233
33- if ( options . tstlVerbose ) {
34- console . log ( "Parsing project settings" ) ;
35- }
34+ if ( options . tstlVerbose ) console . log ( "Parsing project settings" ) ;
3635
3736 const diagnostics = validateOptions ( options ) ;
37+
3838 let transpiledFiles : ProcessedFile [ ] = [ ] ;
3939
40+ if ( options . build ) {
41+ for ( const projectReferences of options . projectReferences ?? [ ] )
42+ {
43+ if ( options . tstlVerbose ) console . log ( `Build mode: Checking reference ${ projectReferences . path } ` ) ;
44+
45+ const tsConfigPath = path . join ( projectReferences . path , "tsconfig.json" ) ;
46+ // Parse reference path but stay in build mode
47+ const parseResult = parseConfigFileWithSystem ( tsConfigPath , { build : true } ) ;
48+ diagnostics . push ( ...parseResult . errors ) ;
49+
50+ if ( parseResult . errors . length === 0 ) {
51+ const referenceProgram = ts . createProgram ( parseResult . fileNames , parseResult . options ) ;
52+ const referencePreEmitDiagnostics = ts . getPreEmitDiagnostics ( referenceProgram ) ;
53+ const { diagnostics : referenceDiagnostics , transpiledFiles : referenceFiles } = getProgramTranspileResult ( emitHost , writeFileResult , { program : referenceProgram } ) ;
54+ diagnostics . push ( ...referencePreEmitDiagnostics , ...referenceDiagnostics ) ;
55+
56+ if ( projectReferences . prepend )
57+ {
58+ transpiledFiles . push ( ...referenceFiles ) ;
59+ }
60+ }
61+ }
62+ }
63+
64+ diagnostics . push ( ...ts . getPreEmitDiagnostics ( program ) ) ;
65+
4066 if ( options . noEmitOnError ) {
4167 const preEmitDiagnostics = [
4268 ...diagnostics ,
0 commit comments