@@ -70,38 +70,25 @@ const createCompiler = options => {
70
70
71
71
/**
72
72
* @param {WebpackOptions | WebpackOptions[] } options options object
73
- * @param {Callback<Stats> | Callback< MultiStats>= } callback callback
74
- * @returns {Compiler | MultiCompiler } the compiler object
73
+ * @param {Callback<MultiStats>= } callback callback
74
+ * @returns {MultiCompiler } the compiler object
75
75
*/
76
76
const webpack = ( options , callback ) => {
77
77
const validationErrors = validateSchema ( webpackOptionsSchema , options ) ;
78
78
if ( validationErrors . length ) {
79
79
throw new WebpackOptionsValidationError ( validationErrors ) ;
80
80
}
81
- /** @type {TODO } */
82
- let compiler ;
83
- let watch = false ;
84
- let watchOptions ;
85
- if ( Array . isArray ( options ) ) {
86
- compiler = createMultiCompiler ( options ) ;
87
- watch = options . some ( options => options . watch ) ;
88
- watchOptions = options . map ( options => options . watchOptions || { } ) ;
89
- } else {
90
- compiler = createCompiler ( options ) ;
91
- watch = options . watch ;
92
- watchOptions = options . watchOptions || { } ;
93
- }
81
+ const compilerOptions = Array . isArray ( options ) ? options : [ options ] ;
82
+ const compiler = createMultiCompiler ( compilerOptions ) ;
94
83
if ( callback ) {
84
+ const watch = compilerOptions . some ( options => options . watch ) ;
95
85
if ( watch ) {
86
+ const watchOptions = compilerOptions . map (
87
+ options => options . watchOptions || { }
88
+ ) ;
96
89
compiler . watch ( watchOptions , callback ) ;
97
90
} else {
98
- compiler . run ( ( err , stats ) => {
99
- compiler . close ( err2 => {
100
- // @ts -ignore
101
- // TODO fix the typings
102
- callback ( err || err2 , stats ) ;
103
- } ) ;
104
- } ) ;
91
+ compiler . run ( callback ) ;
105
92
}
106
93
}
107
94
return compiler ;
0 commit comments