@@ -23,23 +23,31 @@ class Output {
2323 this . streamDts = streamDts ;
2424 }
2525 writeJs ( base , fileName , content , sourceMapContent , cwd , original ) {
26- const file = new VinylFile ( {
27- path : fileName ,
28- contents : Buffer . from ( content ) ,
29- cwd,
30- base
31- } ) ;
32- this . pendingIO ++ ;
33- this . applySourceMap ( sourceMapContent , original , file ) . then ( appliedSourceMap => {
34- if ( appliedSourceMap )
35- file . sourceMap = JSON . parse ( appliedSourceMap ) ;
36- this . streamFull . push ( file ) ;
37- this . streamJs . push ( file ) ;
38- this . pendingIO -- ;
39- this . mightFinish ( ) ;
26+ this . pipeRejection ( this . writeJsAsync ( base , fileName , content , sourceMapContent , cwd , original ) , this . streamJs ) ;
27+ }
28+ writeJsAsync ( base , fileName , content , sourceMapContent , cwd , original ) {
29+ return __awaiter ( this , void 0 , void 0 , function * ( ) {
30+ const file = new VinylFile ( {
31+ path : fileName ,
32+ contents : Buffer . from ( content ) ,
33+ cwd,
34+ base
35+ } ) ;
36+ this . pendingIO ++ ;
37+ yield this . applySourceMap ( sourceMapContent , original , file ) . then ( appliedSourceMap => {
38+ if ( appliedSourceMap )
39+ file . sourceMap = JSON . parse ( appliedSourceMap ) ;
40+ this . streamFull . push ( file ) ;
41+ this . streamJs . push ( file ) ;
42+ this . pendingIO -- ;
43+ this . mightFinish ( ) ;
44+ } ) ;
4045 } ) ;
4146 }
4247 writeDts ( base , fileName , content , declarationMapContent , cwd , original ) {
48+ this . pipeRejection ( this . writeDtsAsync ( base , fileName , content , declarationMapContent , cwd , original ) , this . streamDts ) ;
49+ }
50+ writeDtsAsync ( base , fileName , content , declarationMapContent , cwd , original ) {
4351 return __awaiter ( this , void 0 , void 0 , function * ( ) {
4452 const file = new VinylFile ( {
4553 path : fileName ,
@@ -48,7 +56,7 @@ class Output {
4856 base
4957 } ) ;
5058 this . pendingIO ++ ;
51- this . applySourceMap ( declarationMapContent , original , file ) . then ( appliedSourceMap => {
59+ yield this . applySourceMap ( declarationMapContent , original , file ) . then ( appliedSourceMap => {
5260 if ( appliedSourceMap )
5361 file . sourceMap = JSON . parse ( appliedSourceMap ) ;
5462 this . streamFull . push ( file ) ;
@@ -102,6 +110,13 @@ class Output {
102110 }
103111 } ) ;
104112 }
113+ // Avoids UnhandledPromiseRejectionWarning in NodeJS
114+ pipeRejection ( promise , alternateStream ) {
115+ promise . catch ( err => {
116+ this . streamFull . emit ( "error" , err ) ;
117+ alternateStream . emit ( "error" , err ) ;
118+ } ) ;
119+ }
105120 finish ( result ) {
106121 this . result = result ;
107122 this . mightFinish ( ) ;
0 commit comments