@@ -100,7 +100,7 @@ class JsdocCommand {
100100 }
101101}
102102
103- const exec = util . promisify ( cp . exec ) ;
103+ util . promisify ( cp . exec ) ;
104104
105105class Explain extends JsdocCommand {
106106 async getOutput ( ) {
@@ -120,18 +120,39 @@ class Explain extends JsdocCommand {
120120 }
121121
122122 async _runJsdoc ( ) {
123- const cmd = this . options . source . length
124- ? `node ${ this . jsdocPath } ${ toSpawnArgs ( this . jsdocOptions ) . join ( ' ' ) } -X ${ this . tempFileSet . files . join ( ' ' ) } `
125- : `node ${ this . jsdocPath } ${ toSpawnArgs ( this . jsdocOptions ) . join ( ' ' ) } -X ${ this . inputFileSet . files . join ( ' ' ) } ` ;
126-
123+ const jsdocArgs = [
124+ this . jsdocPath ,
125+ ...toSpawnArgs ( this . jsdocOptions ) ,
126+ '-X' ,
127+ ...( this . options . source . length ? this . tempFileSet . files : this . inputFileSet . files )
128+ ] ;
127129 let jsdocOutput = { stdout : '' , stderr : '' } ;
130+
131+ const code = await new Promise ( ( resolve , reject ) => {
132+ const handle = cp . spawn ( 'node' , jsdocArgs ) ;
133+ handle . stdout . setEncoding ( 'utf8' ) ;
134+ handle . stderr . setEncoding ( 'utf8' ) ;
135+ handle . stdout . on ( 'data' , chunk => {
136+ jsdocOutput . stdout += chunk ;
137+ } ) ;
138+ handle . stderr . on ( 'data' , chunk => {
139+ jsdocOutput . stderr += chunk ;
140+ } ) ;
141+ handle . on ( 'exit' , ( code ) => {
142+ resolve ( code ) ;
143+ } ) ;
144+ handle . on ( 'error' , reject ) ;
145+ } ) ;
128146 try {
129- jsdocOutput = await exec ( cmd , { maxBuffer : 1024 * 1024 * 100 } ) ; /* 100MB */
130- const explainOutput = JSON . parse ( jsdocOutput . stdout ) ;
131- if ( this . options . cache ) {
132- await this . cache . write ( this . cacheKey , explainOutput ) ;
147+ if ( code > 0 ) {
148+ throw new Error ( 'jsdoc exited with non-zero code: ' + code )
149+ } else {
150+ const explainOutput = JSON . parse ( jsdocOutput . stdout ) ;
151+ if ( this . options . cache ) {
152+ await this . cache . write ( this . cacheKey , explainOutput ) ;
153+ }
154+ return explainOutput
133155 }
134- return explainOutput
135156 } catch ( err ) {
136157 const firstLineOfStdout = jsdocOutput . stdout . split ( / \r ? \n / ) [ 0 ] ;
137158 const jsdocErr = new Error ( jsdocOutput . stderr . trim ( ) || firstLineOfStdout || 'Jsdoc failed.' ) ;
0 commit comments