From 7caeca4bfbd5ca9f306c14def3dd6b416869c615 Mon Sep 17 00:00:00 2001 From: Dion Shi Date: Sun, 29 Mar 2020 21:03:30 +0800 Subject: [PATCH] Update webpack ProgressPlugin definition, to support both object/function options (#43375) * Update webpack ProgressPlugin definition, to support both options of object and function. * Re-order webpack.ProgressPlugin parameter ordering to trigger CI. * Tune webpack ProgressPlugin definition for current v4 version, and also add comments. * Fix webpack ProgressPlugin default value comment for current v4 version, and also update handler function interface according to official document. --- types/webpack/index.d.ts | 41 ++++++++++++++++++++++++++++++++++++- types/webpack/test/index.ts | 2 ++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/types/webpack/index.d.ts b/types/webpack/index.d.ts index 5905351572..e92137e1fc 100644 --- a/types/webpack/index.d.ts +++ b/types/webpack/index.d.ts @@ -21,6 +21,7 @@ // Felix Haus // Daniel Chin // Daiki Ihara +// Dion Shi // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 @@ -1832,7 +1833,45 @@ declare namespace webpack { } class ProgressPlugin extends Plugin { - constructor(options?: (percentage: number, msg: string, moduleProgress?: string, activeModules?: string, moduleName?: string) => void); + constructor(options?: ProgressPlugin.Options | ProgressPlugin.Handler); + } + + namespace ProgressPlugin { + /** + * A handler function which will be called when webpack hooks report progress + */ + type Handler = (percentage: number, msg: string, ...args: string[]) => void; + interface Options { + /** + * Show active modules count and one active module in progress message + * Default: true + */ + activeModules?: boolean; + /** + * Show entries count in progress message + * Default: false + */ + entries?: boolean; + /** + * Function that executes for every progress step + */ + handler?: Handler; + /** + * Show modules count in progress message + * Default: true + */ + modules?: boolean; + /** + * Minimum modules count to start with, only for mode = modules + * Default: 500 + */ + modulesCount?: number; + /** + * Collect profile data for progress steps + * Default: false + */ + profile?: boolean | null; + } } class EnvironmentPlugin extends Plugin { diff --git a/types/webpack/test/index.ts b/types/webpack/test/index.ts index 4a089ae972..5aeb37f249 100644 --- a/types/webpack/test/index.ts +++ b/types/webpack/test/index.ts @@ -508,6 +508,8 @@ plugin = new webpack.EnvironmentPlugin(['a', 'b']); plugin = new webpack.EnvironmentPlugin({ a: true, b: 'c' }); plugin = new webpack.ProgressPlugin((percent: number, message: string) => { }); plugin = new webpack.ProgressPlugin((percent: number, message: string, moduleProgress?: string, activeModules?: string, moduleName?: string) => { }); +plugin = new webpack.ProgressPlugin({ profile: true }); +plugin = new webpack.ProgressPlugin({ activeModules: true, entries: false }); plugin = new webpack.HashedModuleIdsPlugin(); plugin = new webpack.HashedModuleIdsPlugin({ hashFunction: 'sha256',