@@ -84,6 +84,7 @@ export function compile(
8484 . pipe ( gulpReplace ( key , value ) ) ;
8585 }
8686
87+ // 使用 longReporter 确保错误信息完整输出
8788 const tsResult = sourcesStream
8889 . pipe (
8990 gulpIF (
@@ -103,7 +104,7 @@ export function compile(
103104 const diagnostics = ( tsResult as any ) . diagnostics || [ ] ;
104105 if ( diagnostics . length > 0 ) {
105106 // eslint-disable-next-line no-console
106- console . error ( '\n=== TypeScript Compilation Errors ===' ) ;
107+ console . error ( '\n=== TypeScript Compilation Errors (from error event) ===' ) ;
107108 // eslint-disable-next-line no-console
108109 console . error ( ts . formatDiagnostics ( diagnostics , ts . createCompilerHost ( ts . getDefaultCompilerOptions ( ) ) ) ) ;
109110 }
@@ -129,6 +130,23 @@ export function compile(
129130 }
130131 } ) ;
131132
133+ // 在编译过程中定期检查诊断信息(通过监听数据流)
134+ let hasReportedDiagnostics = false ;
135+ const checkDiagnostics = ( ) => {
136+ const diagnostics = ( tsResult as any ) . diagnostics || [ ] ;
137+ if ( diagnostics . length > 0 && ! hasReportedDiagnostics ) {
138+ hasReportedDiagnostics = true ;
139+ // eslint-disable-next-line no-console
140+ console . error ( '\n=== TypeScript Compilation Errors (detected during compilation) ===' ) ;
141+ // eslint-disable-next-line no-console
142+ console . error ( ts . formatDiagnostics ( diagnostics , ts . createCompilerHost ( ts . getDefaultCompilerOptions ( ) ) ) ) ;
143+ }
144+ } ;
145+
146+ // 监听数据流事件,在编译过程中检查诊断信息
147+ tsResult . js . on ( 'data' , checkDiagnostics ) ;
148+ tsResult . dts . on ( 'data' , checkDiagnostics ) ;
149+
132150 merge ( [
133151 tsResult . js
134152 . pipe (
@@ -182,15 +200,20 @@ export function compile(
182200 . on ( 'finish' , ( ) => {
183201 // 检查是否有编译错误(在 finish 时检查,因为有些错误可能不会触发 error 事件)
184202 const diagnostics = ( tsResult as any ) . diagnostics || [ ] ;
185- if ( diagnostics . length > 0 && noEmitOnError ) {
186- // eslint-disable-next-line no-console
187- console . error ( '\n=== TypeScript Compilation Errors (detected on finish) ===' ) ;
188- // eslint-disable-next-line no-console
189- console . error ( ts . formatDiagnostics ( diagnostics , ts . createCompilerHost ( ts . getDefaultCompilerOptions ( ) ) ) ) ;
190- const error = new Error ( 'TypeScript compilation failed with errors' ) ;
191- reject ( error ) ;
192- process . exit ( 1 ) ;
193- } else {
203+ if ( diagnostics . length > 0 ) {
204+ if ( ! hasReportedDiagnostics ) {
205+ // eslint-disable-next-line no-console
206+ console . error ( '\n=== TypeScript Compilation Errors (detected on finish) ===' ) ;
207+ // eslint-disable-next-line no-console
208+ console . error ( ts . formatDiagnostics ( diagnostics , ts . createCompilerHost ( ts . getDefaultCompilerOptions ( ) ) ) ) ;
209+ }
210+ if ( noEmitOnError ) {
211+ const error = new Error ( `TypeScript compilation failed with ${ diagnostics . length } error(s)` ) ;
212+ reject ( error ) ;
213+ process . exit ( 1 ) ;
214+ }
215+ }
216+ if ( diagnostics . length === 0 || ! noEmitOnError ) {
194217 resolve ( undefined ) ;
195218 }
196219 } )
0 commit comments