11import path from "path"
2+ import { execSync } from "child_process"
23
34import fs from "fs-extra"
45import tmpPromise from "tmp-promise"
56import firstExistingPath from "first-existing-path"
6- import getExecFile from "get-exec-file"
77import readPkgUp from "read-pkg-up"
88import { isObject } from "lodash"
9+ import commandJoin from "command-join"
910
1011const debug = require ( "debug" ) ( "jsdoc-tsd-webpack-plugin" )
1112
1213const webpackId = "JsdocTsdWebpackPlugin"
1314
14- const getHtmlConfigPath = async ( compilation , configBase , template , options , configDir ) => {
15+ const getHtmlConfigPath = ( compilation , configBase , template , options , configDir ) => {
1516 const config = {
1617 ...configBase ,
1718 opts : {
@@ -26,7 +27,7 @@ const getHtmlConfigPath = async (compilation, configBase, template, options, con
2627 return configPath
2728}
2829
29- const getTsdConfigPath = async ( compilation , configBase , template , options , configDir ) => {
30+ const getTsdConfigPath = ( compilation , configBase , template , options , configDir ) => {
3031 const config = {
3132 ...configBase ,
3233 opts : {
@@ -169,32 +170,33 @@ export default class {
169170 debug ( `tsd output file should be named ${ this . options . autoTsdOutputFile } ` )
170171 }
171172
172- const [ htmlConfigPath , tsdConfigPath ] = await Promise . all ( [
173- getHtmlConfigPath ( compilation , configBase , htmlModulePath , this . options , tempDir ) ,
174- getTsdConfigPath ( compilation , configBase , tsdModulePath , this . options , tempDir ) ,
175- ] )
176-
177- debug ( `JSDoc HTML command: "${ process . execPath } " "${ jsdocPath } " --configure "${ htmlConfigPath } "` )
178- debug ( `JSDoc TSD command: "${ process . execPath } " "${ jsdocPath } " --configure "${ tsdConfigPath } "` )
179-
180- const jsdocJobs = [ htmlConfigPath , tsdConfigPath ] . map ( configPath => getExecFile ( process . execPath , [ jsdocPath , "--configure" , configPath ] , {
181- timeout : 1000 * 120 ,
182- } ) )
183- const jsdocResults = await Promise . all ( jsdocJobs )
184-
185- for ( const jsdocResult of jsdocResults ) {
186- if ( jsdocResult . error ) {
187- throw new Error ( `JSDoc failed with Error: ${ error . message } ` )
188- }
189- if ( jsdocResult . stderr ) {
190- throw new Error ( `JSDoc failed with error output: ${ jsdocResult . stderr } ` )
191- }
173+ const setups = [
174+ {
175+ name : "TSD" ,
176+ modulePath : tsdModulePath ,
177+ configFactory : getTsdConfigPath ,
178+ } ,
179+ {
180+ name : "HTML" ,
181+ configFactory : getHtmlConfigPath ,
182+ modulePath : htmlModulePath ,
183+ } ,
184+ ]
185+
186+ for ( const { name, modulePath, configFactory} of setups ) {
187+ const configPath = configFactory ( compilation , configBase , modulePath , this . options , tempDir )
188+ const command = commandJoin ( [ process . execPath , jsdocPath , "--configure" , configPath ] )
189+ debug ( `JSDoc ${ name } command: ${ command } ` )
190+ const out = execSync ( command , {
191+ timeout : 1000 * 120 ,
192+ cwd : compiler . context ,
193+ encoding : "utf8" ,
194+ } )
195+ debug ( `JSDoc ${ name } output: ${ out } ` )
192196 }
193197
194- debug ( `JSDoc HTML stdout: ${ jsdocResults [ 0 ] . stdout } ` )
195- debug ( `JSDoc TSD stdout: ${ jsdocResults [ 1 ] . stdout } ` )
196-
197198 if ( this . options . autoTsdOutputFile ) {
199+ debug ( `Copying ${ this . options . autoTsdOutputFile } to ${ path . join ( compiler . options . output . path , this . options . autoTsdOutputFile | > path . basename ) } ` )
198200 const tsdContent = fs . readFileSync ( this . options . autoTsdOutputFile )
199201 compilation . assets [ path . basename ( this . options . autoTsdOutputFile ) ] = {
200202 source : ( ) => tsdContent ,
0 commit comments