webpack: add missing MultiStats methods (#45929)

ref: https://github.com/webpack/webpack/blob/v4.43.0/lib/MultiStats.js
This commit is contained in:
Avi Vahl 2020-07-07 20:33:26 +03:00 committed by GitHub
parent 120445b449
commit 39d287cc10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 4 deletions

View File

@ -1305,6 +1305,14 @@ declare namespace webpack {
interface MultiStats {
stats: Stats[];
hash: string;
/** Returns true if there were errors while compiling. */
hasErrors(): boolean;
/** Returns true if there were warnings while compiling. */
hasWarnings(): boolean;
/** Returns compilation information as a JSON object. */
toJson(options?: Stats.ToJsonOptions): Stats.ToJsonOutput;
/** Returns a formatted string of the compilation information (similar to CLI output). */
toString(options?: Stats.ToStringOptions): string;
}
interface MultiCompilerHooks {

View File

@ -1102,14 +1102,19 @@ compiler.hooks.done.tap('foo', stats => {
const multiCompiler = webpack([{}, {}]);
multiCompiler.hooks.done.tap('foo', ({ stats: multiStats, hash }) => {
const stats = multiStats[0];
multiCompiler.hooks.done.tap('foo', (multiStats) => {
const [firstStat] = multiStats.stats;
if (stats.startTime === undefined || stats.endTime === undefined) {
if (multiStats.hasWarnings() || multiStats.hasErrors()) {
throw new Error(multiStats.toString('errors-warnings'));
}
multiStats.toJson(); // $ExpectType ToJsonOutput
if (firstStat.startTime === undefined || firstStat.endTime === undefined) {
throw new Error('Well, this is odd');
}
console.log(`Compiled in ${stats.endTime - stats.startTime}ms`, hash);
console.log(`Compiled in ${firstStat.endTime - firstStat.startTime}ms`, multiStats.hash);
});
webpack.Template.getFunctionContent(() => undefined).trimLeft();