From 39d287cc1049c827af269f9dc3ae02419bc6d921 Mon Sep 17 00:00:00 2001 From: Avi Vahl Date: Tue, 7 Jul 2020 20:33:26 +0300 Subject: [PATCH] webpack: add missing MultiStats methods (#45929) ref: https://github.com/webpack/webpack/blob/v4.43.0/lib/MultiStats.js --- types/webpack/index.d.ts | 8 ++++++++ types/webpack/test/index.ts | 13 +++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/types/webpack/index.d.ts b/types/webpack/index.d.ts index 52a1e7b2b5..36e35b1a3e 100644 --- a/types/webpack/index.d.ts +++ b/types/webpack/index.d.ts @@ -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 { diff --git a/types/webpack/test/index.ts b/types/webpack/test/index.ts index fb75977b24..1a25d6c537 100644 --- a/types/webpack/test/index.ts +++ b/types/webpack/test/index.ts @@ -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();