fix(webpack): correct Stats class details (#43971)

* fix(webpack): correct Stats class details

- remove abstract keyword for Stats class
- add constructor with options
- add class and instance methods
- update tests

71eb5931db/lib/Stats.js

/cc @ernestostifano

Thanks!

Fixes #43952

* Update types/webpack/test/index.ts

Thx to @ofhouse for review of this part!

Co-Authored-By: Felix Haus <ofhouse@users.noreply.github.com>

* Update types/webpack/index.d.ts

Thx to @ofhouse for reviewing and suggestion!

Co-Authored-By: Felix Haus <ofhouse@users.noreply.github.com>

* Correct `filterWarnings` after method params redefinition

Missed when accepting the suggestion as part of PR review

Thanks!

Co-authored-by: Felix Haus <ofhouse@users.noreply.github.com>
This commit is contained in:
Piotr Błażejewicz (Peter Blazejewicz) 2020-04-18 19:47:32 +02:00 committed by GitHub
parent b1cfdc9ab7
commit 069f404e66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View File

@ -22,6 +22,7 @@
// Daniel Chin <https://github.com/danielthank>
// Daiki Ihara <https://github.com/sasurau4>
// Dion Shi <https://github.com/dionshihk>
// Piotr Błażejewicz <https://github.com/peterblazejewicz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
@ -1409,20 +1410,33 @@ declare namespace webpack {
apply(resolver: any /* EnhancedResolve.Resolver */): void;
}
abstract class Stats {
class Stats {
compilation: compilation.Compilation;
hash?: string;
startTime?: number;
endTime?: number;
static filterWarnings(
warnings: string[],
warningsFilter?: Array<string | RegExp | ((warning: string) => boolean)>
): string[];
/**
* Returns the default json options from the stats preset.
* @param preset The preset to be transformed into json options.
*/
static presetToOptions(preset?: Stats.Preset): Stats.ToJsonOptionsObject;
constructor(compilation: compilation.Compilation);
formatFilePath(filePath: string): string;
/** Returns true if there were errors while compiling. */
hasErrors(): boolean;
/** Returns true if there were warnings while compiling. */
hasWarnings(): boolean;
/** Remove a prefixed "!" that can be specified to reverse sort order */
normalizeFieldKey(field: string): string;
/** if a field is prefixed by a "!" reverse sort order */
sortOrderRegular(field: string): boolean;
/** Returns compilation information as a JSON object. */
toJson(options?: Stats.ToJsonOptions, forToString?: boolean): Stats.ToJsonOutput;
/** Returns a formatted string of the compilation information (similar to CLI output). */

View File

@ -1166,3 +1166,14 @@ class LoggingPlugin extends webpack.Plugin {
});
}
}
// Stats Microsoft/DefinitelyTyped#43952
const { Stats } = webpack;
compiler.hooks.compilation.tap('SomePlugin', compilation => {
const stats = new Stats(compilation); // $ExpectType Stats
Stats.filterWarnings([], [(warning: string) => true]); // $ExpectType string[]
stats.formatFilePath('app/src/'); // $ExpectType string
stats.normalizeFieldKey('field'); // $ExpectType string
stats.sortOrderRegular('!field'); // $ExpectType boolean
});