Skip to content

Commit

Permalink
chore(performance): cleanup logic errors, reformat test expects with …
Browse files Browse the repository at this point in the history
…new colomn [big] format if empty
  • Loading branch information
TheLarkInn committed Dec 2, 2016
1 parent f360e1e commit 6e47f34
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 45 deletions.
8 changes: 5 additions & 3 deletions lib/Stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,9 @@ Stats.jsonToString = function jsonToString(obj, useColors) {
for(row = 0; row < rows; row++) {
for(col = 0; col < cols; col++) {
value = getText(array, row, col) + "";
if(value.length === 0) {
colSizes[col] = 0;
}
if(value.length > colSizes[col]) {
colSizes[col] = value.length;
}
Expand All @@ -434,7 +437,7 @@ Stats.jsonToString = function jsonToString(obj, useColors) {
colors.normal(" ");
if(align[col] === "r")
format(value);
if(col + 1 < cols)
if(col + 1 < cols && colSizes[col] != 0)
colors.normal(splitter || " ");
}
newline();
Expand All @@ -446,7 +449,6 @@ Stats.jsonToString = function jsonToString(obj, useColors) {
return colors.yellow;
}


return defaultColor;
}

Expand Down Expand Up @@ -489,7 +491,7 @@ Stats.jsonToString = function jsonToString(obj, useColors) {
{value: formatSize(asset.size), color: getAssetColor(asset, colors.normal)},
{value: asset.chunks.join(", "), color: colors.bold},
{value: asset.emitted ? "[emitted]" : "", color: colors.green},
{value: asset.isOverSizeLimit ? "[big]" : "", color: colors.yellow},
{value: asset.isOverSizeLimit ? "[big]" : "", color: getAssetColor(asset, colors.normal)},
{value: asset.chunkNames.join(", "), color: colors.normal}
]);
});
Expand Down
13 changes: 5 additions & 8 deletions lib/WebpackOptionsApply.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var FlagIncludedChunksPlugin = require("./optimize/FlagIncludedChunksPlugin");
var OccurrenceOrderPlugin = require("./optimize/OccurrenceOrderPlugin");
var FlagDependencyUsagePlugin = require("./FlagDependencyUsagePlugin");
var FlagDependencyExportsPlugin = require("./FlagDependencyExportsPlugin");
var EmittedAssetSizeLimitPlugin = require("./performance/EmittedAssetSizeLimitPlugin");

var ResolverFactory = require("enhanced-resolve").ResolverFactory;

Expand All @@ -64,28 +65,21 @@ WebpackOptionsApply.prototype.process = function(options, compiler) {
compiler.name = options.name;
compiler.dependencies = options.dependencies;
if(typeof options.target === "string") {
var EmittedAssetSizeLimitPlugin;
var JsonpTemplatePlugin;
var NodeSourcePlugin;
var NodeTargetPlugin;
var NodeTemplatePlugin;

switch(options.target) {
case "web":
JsonpTemplatePlugin = require("./JsonpTemplatePlugin");
NodeSourcePlugin = require("./node/NodeSourcePlugin");

compiler.apply(
new JsonpTemplatePlugin(options.output),
new FunctionModulePlugin(options.output),
new NodeSourcePlugin(options.node),
new LoaderTargetPlugin("web")
);

if (options.performance.hints) {
EmittedAssetSizeLimitPlugin = require("./performance/EmittedAssetSizeLimitPlugin");
compiler.apply(new EmittedAssetSizeLimitPlugin(options.performance));
}

break;
case "webworker":
var WebWorkerTemplatePlugin = require("./webworker/WebWorkerTemplatePlugin");
Expand Down Expand Up @@ -193,6 +187,7 @@ WebpackOptionsApply.prototype.process = function(options, compiler) {
} else {
throw new Error("Unsupported target '" + options.target + "'.");
}

if(options.output.library || options.output.libraryTarget !== "var") {
var LibraryTemplatePlugin = require("./LibraryTemplatePlugin");
compiler.apply(new LibraryTemplatePlugin(options.output.library, options.output.libraryTarget, options.output.umdNamedDefine, options.output.auxiliaryComment || ""));
Expand Down Expand Up @@ -270,6 +265,8 @@ WebpackOptionsApply.prototype.process = function(options, compiler) {
new FlagDependencyUsagePlugin()
);

compiler.apply(new EmittedAssetSizeLimitPlugin(options.performance));

compiler.apply(new TemplatedPathPlugin());

compiler.apply(new RecordIdsPlugin());
Expand Down
16 changes: 10 additions & 6 deletions lib/WebpackOptionsDefaulter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ function WebpackOptionsDefaulter() {
this.set("context", process.cwd());
this.set("target", "web");

this.set("performance.maxAssetSize", 250000);
this.set("performance.maxInitialChunkSize", 250000);
this.set("performance.hints", true);
this.set("performance.errorOnHint", false);

this.set("module.unknownContextRequest", ".");
this.set("module.unknownContextRegExp", false);
this.set("module.unknownContextRecursive", true);
Expand Down Expand Up @@ -74,6 +69,16 @@ function WebpackOptionsDefaulter() {
this.set("node.__filename", "mock");
this.set("node.__dirname", "mock");

this.set("performance.maxAssetSize", 250000);
this.set("performance.maxInitialChunkSize", 250000);
this.set("performance.errorOnHint", false);
this.set("performance.hints", "make", function(options) {
if(options.target === "web")
return true;
else
return false;
});

this.set("resolve", {});
this.set("resolve.unsafeCache", true);
this.set("resolve.modules", ["node_modules"]);
Expand All @@ -90,7 +95,6 @@ function WebpackOptionsDefaulter() {
else
return ["module", "main"];
});

this.set("resolveLoader", {});
this.set("resolveLoader.unsafeCache", true);
this.set("resolveLoader.mainFields", ["loader", "main"]);
Expand Down
2 changes: 1 addition & 1 deletion lib/performance/AssetsOverSizeLimitWarning.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function AssetsOverSizeLimitWarning(assetsOverSizeLimit, assetLimit) {
this.assets = assetsOverSizeLimit;

var assetLists = this.assets.map(function(asset) {
return "\n " + asset.name + " (" + SizeFormatHelpers.formatSize(asset.size) +")";
return "\n " + asset.name + " (" + SizeFormatHelpers.formatSize(asset.size) + ")";
}).join("");

this.message = "asset size limit: The following asset(s) exceed the recommended size limit (" + SizeFormatHelpers.formatSize(assetLimit) + "). \n" +
Expand Down
6 changes: 4 additions & 2 deletions lib/performance/EmittedAssetSizeLimitPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ EmittedAssetSizeLimitPlugin.prototype.apply = function(compiler) {
}).length > 0;

var entrypointsOverLimit = Object.keys(compilation.entrypoints)
.map(function(key) { return compilation.entrypoints[key] })
.map(function(key) {
return compilation.entrypoints[key]
})
.filter(function(entry) {
return doesExceedLimit(entrypointSizeLimit, entry.getSize(compilation))
});
Expand Down Expand Up @@ -83,7 +85,7 @@ EmittedAssetSizeLimitPlugin.prototype.apply = function(compiler) {
warnings.push(new NoAsyncChunksWarning());
}
} else {
if(entrypointsOverLimit.legnth > 0) {
if(entrypointsOverLimit.length > 0) {
warnings.push(
new EntrypointsOverSizeLimitWarning(
entrypointsOverLimit,
Expand Down
3 changes: 0 additions & 3 deletions lib/performance/EntrypointsOverSizeLimitWarning.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ function EntrypointsOverSizeLimitWarning(entrypoints, compilation, entrypointLim
this.name = "EntrypointsOverSizeLimitWarning";
this.entrypoints = entrypoints;


var entrypointCompilation = compilation;
var entrypointList = this.entrypoints.map(function(entrypoint) {
return "\n " + entrypoint.name + " (" + SizeFormatHelpers.formatSize(entrypoint.getSize(entrypointCompilation)) + ")\n" +
Expand All @@ -19,8 +18,6 @@ function EntrypointsOverSizeLimitWarning(entrypoints, compilation, entrypointLim
}).join("");
}).join("");

debugger;

this.message = "entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (" + SizeFormatHelpers.formatSize(entrypointLimit) + "). " +
"This can impact web performance.\n" +
"Entrypoints:" + entrypointList;
Expand Down
2 changes: 1 addition & 1 deletion test/statsCases/color-enabled-custom/expected.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Hash: <CLR=BOLD>6c781fe6bf412ba6435b</CLR>
Time: <CLR=BOLD>X</CLR>ms
<CLR=BOLD>Asset</CLR> <CLR=BOLD>Size</CLR> <CLR=BOLD>Chunks</CLR> <CLR=39,BOLD><CLR=22> <CLR=BOLD>Chunk Names</CLR>
<CLR=BOLD>Asset</CLR> <CLR=BOLD>Size</CLR> <CLR=BOLD>Chunks</CLR> <CLR=39,BOLD><CLR=22> <CLR=39,BOLD><CLR=22><CLR=BOLD>Chunk Names</CLR>
<CLR=32>main.js</CLR> 2.43 kB <CLR=BOLD>0</CLR> <CLR=32>[emitted]</CLR> main
chunk {<CLR=33>0</CLR>} <CLR=32>main.js</CLR> (main) 0 bytes<CLR=33> [entry]</CLR><CLR=32> [rendered]</CLR>
[0] <CLR=BOLD>(webpack)/test/statsCases/color-enabled-custom/index.js</CLR> 0 bytes {<CLR=33>0</CLR>}<CLR=32> [built]</CLR>
2 changes: 1 addition & 1 deletion test/statsCases/color-enabled/expected.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Hash: <CLR=BOLD>6c781fe6bf412ba6435b</CLR>
Time: <CLR=BOLD>X</CLR>ms
<CLR=BOLD>Asset</CLR> <CLR=BOLD>Size</CLR> <CLR=BOLD>Chunks</CLR> <CLR=39,BOLD><CLR=22> <CLR=BOLD>Chunk Names</CLR>
<CLR=BOLD>Asset</CLR> <CLR=BOLD>Size</CLR> <CLR=BOLD>Chunks</CLR> <CLR=39,BOLD><CLR=22> <CLR=39,BOLD><CLR=22><CLR=BOLD>Chunk Names</CLR>
<CLR=32,BOLD>main.js</CLR> 2.43 kB <CLR=BOLD>0</CLR> <CLR=32,BOLD>[emitted]</CLR> main
chunk {<CLR=33,BOLD>0</CLR>} <CLR=32,BOLD>main.js</CLR> (main) 0 bytes<CLR=33,BOLD> [entry]</CLR><CLR=32,BOLD> [rendered]</CLR>
[0] <CLR=BOLD>(webpack)/test/statsCases/color-enabled/index.js</CLR> 0 bytes {<CLR=33,BOLD>0</CLR>}<CLR=32,BOLD> [built]</CLR>
19 changes: 9 additions & 10 deletions test/statsCases/performance-error/expected.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Time: <CLR=BOLD>X</CLR>ms
<CLR=BOLD>Asset</CLR> <CLR=BOLD>Size</CLR> <CLR=BOLD>Chunks</CLR> <CLR=39,BOLD><CLR=22> <CLR=BOLD>Chunk Names</CLR>
<CLR=32,BOLD>0.js</CLR> 227 bytes <CLR=BOLD>0</CLR> <CLR=32,BOLD>[emitted]</CLR>
<CLR=32,BOLD>1.js</CLR> 106 bytes <CLR=BOLD>1</CLR> <CLR=32,BOLD>[emitted]</CLR>
<CLR=32,BOLD>2.js</CLR> 200 bytes <CLR=BOLD>2</CLR> <CLR=32,BOLD>[emitted]</CLR>
<CLR=33,BOLD>main.js</CLR> <CLR=33,BOLD>306 kB</CLR> <CLR=BOLD>3</CLR> <CLR=32,BOLD>[emitted]</CLR> main
<CLR=BOLD>Asset</CLR> <CLR=BOLD>Size</CLR> <CLR=BOLD>Chunks</CLR> <CLR=39,BOLD><CLR=22> <CLR=39,BOLD><CLR=22> <CLR=BOLD>Chunk Names</CLR>
<CLR=32,BOLD>0.js</CLR> 227 bytes <CLR=BOLD>0</CLR> <CLR=32,BOLD>[emitted]</CLR>
<CLR=32,BOLD>1.js</CLR> 106 bytes <CLR=BOLD>1</CLR> <CLR=32,BOLD>[emitted]</CLR>
<CLR=32,BOLD>2.js</CLR> 200 bytes <CLR=BOLD>2</CLR> <CLR=32,BOLD>[emitted]</CLR>
<CLR=33,BOLD>main.js</CLR> <CLR=33,BOLD>306 kB</CLR> <CLR=BOLD>3</CLR> <CLR=32,BOLD>[emitted]</CLR> <CLR=33,BOLD>[big]</CLR> main
chunk {<CLR=33,BOLD>0</CLR>} <CLR=32,BOLD>0.js</CLR> 54 bytes {<CLR=33,BOLD>3</CLR>}<CLR=32,BOLD> [rendered]</CLR>
[2] <CLR=BOLD>(webpack)/test/statsCases/performance-error/c.js</CLR> 54 bytes {<CLR=33,BOLD>0</CLR>}<CLR=32,BOLD> [built]</CLR>
chunk {<CLR=33,BOLD>1</CLR>} <CLR=32,BOLD>1.js</CLR> 22 bytes {<CLR=33,BOLD>3</CLR>}<CLR=32,BOLD> [rendered]</CLR>
Expand All @@ -15,14 +15,13 @@ chunk {<CLR=33,BOLD>3</CLR>} <CLR=32,BOLD>main.js</CLR> (main) 300 kB<CLR=33,
[0] <CLR=BOLD>(webpack)/test/statsCases/performance-error/a.js</CLR> 300 kB {<CLR=33,BOLD>3</CLR>}<CLR=32,BOLD> [built]</CLR>
[5] <CLR=BOLD>(webpack)/test/statsCases/performance-error/index.js</CLR> 52 bytes {<CLR=33,BOLD>3</CLR>}<CLR=32,BOLD> [built]</CLR>

<CLR=31,BOLD>ERROR in asset size limit: The following assets exceed the recommended size limit (250 kB).
<CLR=31,BOLD>ERROR in asset size limit: The following asset(s) exceed the recommended size limit (250 kB).
This can impact web performance.
Assets:
main.js</CLR>
main.js (306 kB)</CLR>

<CLR=31,BOLD>ERROR in entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (250 kB). This can impact web performance.
Entrypoints:

main: 306 kB
Entrypoints:
main (306 kB)
main.js
</CLR>
19 changes: 9 additions & 10 deletions test/statsCases/preset-normal-performance/expected.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Time: <CLR=BOLD>X</CLR>ms
<CLR=BOLD>Asset</CLR> <CLR=BOLD>Size</CLR> <CLR=BOLD>Chunks</CLR> <CLR=39,BOLD><CLR=22> <CLR=BOLD>Chunk Names</CLR>
<CLR=32,BOLD>0.js</CLR> 227 bytes <CLR=BOLD>0</CLR> <CLR=32,BOLD>[emitted]</CLR>
<CLR=32,BOLD>1.js</CLR> 106 bytes <CLR=BOLD>1</CLR> <CLR=32,BOLD>[emitted]</CLR>
<CLR=32,BOLD>2.js</CLR> 200 bytes <CLR=BOLD>2</CLR> <CLR=32,BOLD>[emitted]</CLR>
<CLR=33,BOLD>main.js</CLR> <CLR=33,BOLD>306 kB</CLR> <CLR=BOLD>3</CLR> <CLR=32,BOLD>[emitted]</CLR> main
<CLR=BOLD>Asset</CLR> <CLR=BOLD>Size</CLR> <CLR=BOLD>Chunks</CLR> <CLR=39,BOLD><CLR=22> <CLR=39,BOLD><CLR=22> <CLR=BOLD>Chunk Names</CLR>
<CLR=32,BOLD>0.js</CLR> 227 bytes <CLR=BOLD>0</CLR> <CLR=32,BOLD>[emitted]</CLR>
<CLR=32,BOLD>1.js</CLR> 106 bytes <CLR=BOLD>1</CLR> <CLR=32,BOLD>[emitted]</CLR>
<CLR=32,BOLD>2.js</CLR> 200 bytes <CLR=BOLD>2</CLR> <CLR=32,BOLD>[emitted]</CLR>
<CLR=33,BOLD>main.js</CLR> <CLR=33,BOLD>306 kB</CLR> <CLR=BOLD>3</CLR> <CLR=32,BOLD>[emitted]</CLR> <CLR=33,BOLD>[big]</CLR> main
chunk {<CLR=33,BOLD>0</CLR>} <CLR=32,BOLD>0.js</CLR> 54 bytes {<CLR=33,BOLD>3</CLR>}<CLR=32,BOLD> [rendered]</CLR>
[2] <CLR=BOLD>(webpack)/test/statsCases/preset-normal-performance/c.js</CLR> 54 bytes {<CLR=33,BOLD>0</CLR>}<CLR=32,BOLD> [built]</CLR>
chunk {<CLR=33,BOLD>1</CLR>} <CLR=32,BOLD>1.js</CLR> 22 bytes {<CLR=33,BOLD>3</CLR>}<CLR=32,BOLD> [rendered]</CLR>
Expand All @@ -15,14 +15,13 @@ chunk {<CLR=33,BOLD>3</CLR>} <CLR=32,BOLD>main.js</CLR> (main) 300 kB<CLR=33,
[0] <CLR=BOLD>(webpack)/test/statsCases/preset-normal-performance/a.js</CLR> 300 kB {<CLR=33,BOLD>3</CLR>}<CLR=32,BOLD> [built]</CLR>
[5] <CLR=BOLD>(webpack)/test/statsCases/preset-normal-performance/index.js</CLR> 52 bytes {<CLR=33,BOLD>3</CLR>}<CLR=32,BOLD> [built]</CLR>

<CLR=33,BOLD>WARNING in asset size limit: The following assets exceed the recommended size limit (250 kB).
<CLR=33,BOLD>WARNING in asset size limit: The following asset(s) exceed the recommended size limit (250 kB).
This can impact web performance.
Assets:
main.js</CLR>
main.js (306 kB)</CLR>

<CLR=33,BOLD>WARNING in entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (250 kB). This can impact web performance.
Entrypoints:

main: 306 kB
Entrypoints:
main (306 kB)
main.js
</CLR>

0 comments on commit 6e47f34

Please sign in to comment.