mirror of https://github.com/webpack/webpack.git
add percentBy options to ProgressPlugin
This commit is contained in:
parent
8445f06fa9
commit
bb4a0e83bc
|
|
@ -43,6 +43,10 @@ export interface ProgressPluginOptions {
|
|||
* Minimum modules count to start with. For better progress calculation. Default: 5000
|
||||
*/
|
||||
modulesCount?: number;
|
||||
/**
|
||||
* Collect percent algorithm. By default it calculates by a median from modules, entries and dependencies percent
|
||||
*/
|
||||
percentBy?: "entries" | "modules" | "dependencies" | null;
|
||||
/**
|
||||
* Collect profile data for progress steps. Default: false
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -129,6 +129,7 @@ class ProgressPlugin {
|
|||
this.showModules = options.modules;
|
||||
this.showDependencies = options.dependencies;
|
||||
this.showActiveModules = options.activeModules;
|
||||
this.percentBy = options.percentBy;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -204,10 +205,27 @@ class ProgressPlugin {
|
|||
doneEntries / Math.max(lastEntriesCount, entriesCount);
|
||||
const percentByDependencies =
|
||||
doneDependencies / Math.max(lastDependenciesCount, dependenciesCount);
|
||||
const percentage =
|
||||
0.1 +
|
||||
median3(percentByModules, percentByEntries, percentByDependencies) *
|
||||
0.6;
|
||||
let percentageFactor;
|
||||
|
||||
switch (this.percentBy) {
|
||||
case "entries":
|
||||
percentageFactor = percentByEntries;
|
||||
break;
|
||||
case "dependencies":
|
||||
percentageFactor = percentByDependencies;
|
||||
break;
|
||||
case "modules":
|
||||
percentageFactor = percentByModules;
|
||||
break;
|
||||
default:
|
||||
percentageFactor = median3(
|
||||
percentByModules,
|
||||
percentByEntries,
|
||||
percentByDependencies
|
||||
);
|
||||
}
|
||||
|
||||
const percentage = 0.1 + percentageFactor * 0.6;
|
||||
|
||||
if (showEntries) {
|
||||
items.push(`${doneEntries}/${entriesCount} entries`);
|
||||
|
|
|
|||
|
|
@ -41,6 +41,10 @@
|
|||
"description": "Minimum modules count to start with. For better progress calculation. Default: 5000",
|
||||
"type": "number"
|
||||
},
|
||||
"percentBy": {
|
||||
"description": "Collect percent algorithm. By default it calculates by a median from modules, entries and dependencies percent",
|
||||
"enum": ["entries", "modules", "dependencies", null]
|
||||
},
|
||||
"profile": {
|
||||
"description": "Collect profile data for progress steps. Default: false",
|
||||
"enum": [true, false, null]
|
||||
|
|
|
|||
|
|
@ -60,6 +60,24 @@ describe("ProgressPlugin", function() {
|
|||
expect(_.maxBy(logs, "length").length).toBeGreaterThan(50);
|
||||
});
|
||||
});
|
||||
|
||||
it("should display all type of percentage when it is applied to SingleCompiler", () => {
|
||||
const compiler = createSimpleCompiler({
|
||||
entries: true,
|
||||
modules: true,
|
||||
dependencies: true,
|
||||
activeModules: true
|
||||
});
|
||||
|
||||
return RunCompilerAsync(compiler).then(() => {
|
||||
const logs = stderr.toString();
|
||||
|
||||
expect(logs).toEqual(expect.stringMatching(/\d+\/\d+ entries/));
|
||||
expect(logs).toEqual(expect.stringMatching(/\d+\/\d+ dependencies/));
|
||||
expect(logs).toEqual(expect.stringMatching(/\d+\/\d+ modules/));
|
||||
expect(logs).toEqual(expect.stringMatching(/\d+ active/));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const createMultiCompiler = () => {
|
||||
|
|
@ -80,7 +98,7 @@ const createMultiCompiler = () => {
|
|||
return compiler;
|
||||
};
|
||||
|
||||
const createSimpleCompiler = () => {
|
||||
const createSimpleCompiler = progressOptions => {
|
||||
const compiler = webpack({
|
||||
context: path.join(__dirname, "fixtures"),
|
||||
entry: "./a.js"
|
||||
|
|
@ -89,7 +107,8 @@ const createSimpleCompiler = () => {
|
|||
compiler.outputFileSystem = new MemoryFs();
|
||||
|
||||
new webpack.ProgressPlugin({
|
||||
activeModules: true
|
||||
activeModules: true,
|
||||
...progressOptions
|
||||
}).apply(compiler);
|
||||
|
||||
return compiler;
|
||||
|
|
|
|||
Loading…
Reference in New Issue