Skip to content

Commit 5f5d80f

Browse files
committed
Always use a MultiCompiler
1 parent e06b485 commit 5f5d80f

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

lib/MultiStats.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ class MultiStats {
3434
}
3535

3636
toJson(options, forToString) {
37+
if (this.stats.length === 1) {
38+
return this.stats[0].toJson(options, forToString);
39+
}
40+
3741
if (typeof options === "boolean" || typeof options === "string") {
3842
options = Stats.presetToOptions(options);
3943
} else if (!options) {
@@ -81,6 +85,10 @@ class MultiStats {
8185
}
8286

8387
toString(options) {
88+
if (this.stats.length === 1) {
89+
return this.stats[0].toString(options);
90+
}
91+
8492
if (typeof options === "boolean" || typeof options === "string") {
8593
options = Stats.presetToOptions(options);
8694
} else if (!options) {

lib/webpack.js

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -70,38 +70,25 @@ const createCompiler = options => {
7070

7171
/**
7272
* @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
7575
*/
7676
const webpack = (options, callback) => {
7777
const validationErrors = validateSchema(webpackOptionsSchema, options);
7878
if (validationErrors.length) {
7979
throw new WebpackOptionsValidationError(validationErrors);
8080
}
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);
9483
if (callback) {
84+
const watch = compilerOptions.some(options => options.watch);
9585
if (watch) {
86+
const watchOptions = compilerOptions.map(
87+
options => options.watchOptions || {}
88+
);
9689
compiler.watch(watchOptions, callback);
9790
} 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);
10592
}
10693
}
10794
return compiler;

0 commit comments

Comments
 (0)