mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
webpack: add missing MultiStats methods (#45929)
ref: https://github.com/webpack/webpack/blob/v4.43.0/lib/MultiStats.js
This commit is contained in:
parent
120445b449
commit
39d287cc10
8
types/webpack/index.d.ts
vendored
8
types/webpack/index.d.ts
vendored
@ -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 {
|
||||
|
||||
@ -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();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user