Skip to content

Commit 45f8a28

Browse files
committed
Merge branch 'master' into next
# Conflicts: # lib/JsonpMainTemplatePlugin.js # lib/NoEmitOnErrorsPlugin.js
2 parents 7336ab9 + b059e07 commit 45f8a28

File tree

28 files changed

+134
-32
lines changed

28 files changed

+134
-32
lines changed

lib/NoEmitOnErrorsPlugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
class NoEmitOnErrorsPlugin {
88
apply(compiler) {
99
compiler.hooks.shouldEmit.tap("NoEmitOnErrorsPlugin", (compilation) => {
10-
if(compilation.errors.length > 0)
10+
if(compilation.getStats().hasErrors())
1111
return false;
1212
});
1313
compiler.hooks.compilation.tap("NoEmitOnErrorsPlugin", (compilation) => {
1414
compilation.hooks.shouldRecord.tap("NoEmitOnErrorsPlugin", () => {
15-
if(compilation.errors.length > 0)
15+
if(compilation.getStats().hasErrors())
1616
return false;
1717
});
1818
});

lib/Stats.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,13 @@ class Stats {
5050
}
5151

5252
hasWarnings() {
53-
return this.compilation.warnings.length > 0;
53+
return this.compilation.warnings.length > 0 ||
54+
this.compilation.children.some(child => child.getStats().hasWarnings());
5455
}
5556

5657
hasErrors() {
57-
return this.compilation.errors.length > 0;
58+
return this.compilation.errors.length > 0 ||
59+
this.compilation.children.some(child => child.getStats().hasErrors());
5860
}
5961

6062
// remove a prefixed "!" that can be specified to reverse sort order

lib/WebpackOptionsDefaulter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
120120
this.set("output.hotUpdateChunkFilename", "[id].[hash].hot-update.js");
121121
this.set("output.hotUpdateMainFilename", "[hash].hot-update.json");
122122
this.set("output.crossOriginLoading", false);
123+
this.set("output.jsonpScriptType", false);
123124
this.set("output.chunkLoadTimeout", 120000);
124125
this.set("output.hashFunction", "md5");
125126
this.set("output.hashDigest", "hex");

lib/web/JsonpMainTemplatePlugin.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class JsonpMainTemplatePlugin {
4242
const chunkMaps = chunk.getChunkMaps();
4343
const crossOriginLoading = mainTemplate.outputOptions.crossOriginLoading;
4444
const chunkLoadTimeout = mainTemplate.outputOptions.chunkLoadTimeout;
45+
const jsonpScriptType = mainTemplate.outputOptions.jsonpScriptType;
4546
const scriptSrcPath = mainTemplate.getAssetPath(JSON.stringify(chunkFilename), {
4647
hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`,
4748
hashWithLength: length => `" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "`,
@@ -61,6 +62,7 @@ class JsonpMainTemplatePlugin {
6162
});
6263
return Template.asString([
6364
"var script = document.createElement('script');",
65+
jsonpScriptType ? `script.type = ${JSON.stringify(jsonpScriptType)};` : "",
6466
"script.charset = 'utf-8';",
6567
`script.timeout = ${chunkLoadTimeout};`,
6668
crossOriginLoading ? `script.crossOrigin = ${JSON.stringify(crossOriginLoading)};` : "",

schemas/WebpackOptions.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,14 @@
352352
"use-credentials"
353353
]
354354
},
355+
"jsonpScriptType": {
356+
"description": "This option enables loading async chunks via a custom script type, such as script type=\"module\"",
357+
"enum": [
358+
false,
359+
"text/javascript",
360+
"module"
361+
]
362+
},
355363
"chunkLoadTimeout": {
356364
"description": "Number of milliseconds before chunk request expires",
357365
"type": "number"

test/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ If you are trying to solve a bug which is reproducible when x and y properties a
3535

3636
In addition to an `index.js`, these configCases require a `webpack.config.js` is located inside of your test suite. This will run this specific config through `webpack` just as you were building individually. They will use the same loading/bundling technique of your `it()` tests, however you now have a more specific config use cases that you can write even before you start coding.
3737

38-
#### statsCases (`Stats.test.js`)
38+
#### statsCases (`StatsTestCases.test.js`)
3939
Stats cases are similar to configCases except specifically focusing on the `expected` output of your stats. Instead of writing to the console, however the output of stats will be written to disk.
4040

4141
By default, the "expected" outcome is a pain to write by hand so instead when statsCases are run the following happens:

test/Stats.unittest.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ describe("Stats", () => {
1010
describe("does have", () => {
1111
it("hasErrors", () => {
1212
const mockStats = new Stats({
13+
children: [],
1314
errors: ["firstError"],
1415
hash: "1234",
1516
compiler: {
@@ -20,6 +21,7 @@ describe("Stats", () => {
2021
});
2122
it("hasWarnings", () => {
2223
const mockStats = new Stats({
24+
children: [],
2325
warnings: ["firstError"],
2426
hash: "1234",
2527
compiler: {
@@ -32,6 +34,7 @@ describe("Stats", () => {
3234
describe("does not have", () => {
3335
it("hasErrors", () => {
3436
const mockStats = new Stats({
37+
children: [],
3538
errors: [],
3639
hash: "1234",
3740
compiler: {
@@ -42,6 +45,7 @@ describe("Stats", () => {
4245
});
4346
it("hasWarnings", () => {
4447
const mockStats = new Stats({
48+
children: [],
4549
warnings: [],
4650
hash: "1234",
4751
compiler: {
@@ -51,6 +55,34 @@ describe("Stats", () => {
5155
mockStats.hasWarnings().should.not.be.ok();
5256
});
5357
});
58+
describe("children have", () => {
59+
it("hasErrors", () => {
60+
const mockStats = new Stats({
61+
children: [{
62+
getStats: () => new Stats({
63+
errors: ["firstError"],
64+
hash: "5678"
65+
}),
66+
}],
67+
errors: [],
68+
hash: "1234"
69+
});
70+
mockStats.hasErrors().should.be.ok();
71+
});
72+
it("hasWarnings", () => {
73+
const mockStats = new Stats({
74+
children: [{
75+
getStats: () => new Stats({
76+
warnings: ["firstError"],
77+
hash: "5678"
78+
}),
79+
}],
80+
warnings: [],
81+
hash: "1234"
82+
});
83+
mockStats.hasWarnings().should.be.ok();
84+
});
85+
});
5486
it("formatError handles string errors", () => {
5587
const mockStats = new Stats({
5688
errors: ["firstError"],

test/StatsTestCases.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe("StatsTestCases", () => {
6363
if(/error$/.test(testName)) {
6464
stats.hasErrors().should.be.equal(true);
6565
} else if(stats.hasErrors()) {
66-
done(new Error(stats.toJson().errors.join("\n\n")));
66+
return done(new Error(stats.toJson().errors.join("\n\n")));
6767
}
6868

6969
let toStringOptions = {

test/statsCases/aggressive-splitting-on-demand/expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ eed136bb9b1f0de139a9.js 1.94 KiB 1 [emitted]
88
e013686b7b1ce4bd99ba.js 1.94 KiB 4 [emitted]
99
5ac554478945d88843c9.js 1 KiB 5 [emitted]
1010
2eb796a695b728235608.js 1.01 KiB 6 [emitted]
11-
8d11ec270922149a5452.js 8.36 KiB 7 [emitted] main
11+
8d11ec270922149a5452.js 8.37 KiB 7 [emitted] main
1212
Entrypoint main = 8d11ec270922149a5452.js
1313
chunk {0} 8111929f6761a49abd03.js 1.76 KiB {7} [recorded]
1414
> aggressive-splitted duplicate [11] ./index.js 4:0-51

test/statsCases/chunks-development/expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Time: Xms
44
0.bundle.js 530 bytes 0 [emitted]
55
1.bundle.js 394 bytes 1 [emitted]
66
2.bundle.js 782 bytes 2 [emitted]
7-
bundle.js 7.55 KiB main [emitted] main
7+
bundle.js 7.56 KiB main [emitted] main
88
chunk {main} bundle.js (main) 73 bytes [entry] [rendered]
99
> main [./index.js] ./index.js
1010
[./a.js] 22 bytes {main} [built]

test/statsCases/commons-chunk-min-size-0/expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Hash: 96561e55e52ce5dd05d9
22
Time: Xms
33
Asset Size Chunks Chunk Names
44
entry-1.js 81 bytes 0 [emitted] entry-1
5-
vendor-1.js 8 KiB 1 [emitted] vendor-1
5+
vendor-1.js 8.01 KiB 1 [emitted] vendor-1
66
[0] ./modules/a.js 22 bytes {1} [built]
77
[1] ./modules/b.js 22 bytes {1} [built]
88
[2] ./modules/c.js 22 bytes {1} [built]

test/statsCases/commons-chunk-plugin-children/expected.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Child children:
5151
3.bundle.js 1.19 KiB 3 [emitted] x4
5252
4.bundle.js 749 bytes 4 [emitted] x5
5353
5.bundle.js 1.04 KiB 5 [emitted] xx5
54-
bundle.js 7.17 KiB 6 [emitted] main
54+
bundle.js 7.18 KiB 6 [emitted] main
5555
chunk {0} 0.bundle.js (x1) 14 bytes {6} [rendered]
5656
> x1 [11] ./index.js 1:0-42
5757
[6] ./x1.js 14 bytes {0} [built]
@@ -90,7 +90,7 @@ Child async:
9090
4.bundle.js 1.19 KiB 4 [emitted] x4
9191
5.bundle.js 749 bytes 5 [emitted] x5
9292
6.bundle.js 1.04 KiB 6 [emitted] xx5
93-
bundle.js 7.25 KiB 7 [emitted] main
93+
bundle.js 7.26 KiB 7 [emitted] main
9494
chunk {0} 0.bundle.js 0 bytes {7} [rendered]
9595
> async commons x1 [11] ./index.js 1:0-42
9696
> async commons x2 [11] ./index.js 2:0-42
@@ -134,7 +134,7 @@ Child deep-children:
134134
3.bundle.js 1.13 KiB 3 [emitted] x4
135135
4.bundle.js 749 bytes 4 [emitted] x5
136136
5.bundle.js 1020 bytes 5 [emitted] xx5
137-
bundle.js 7.29 KiB 6 [emitted] main
137+
bundle.js 7.3 KiB 6 [emitted] main
138138
chunk {0} 0.bundle.js (x1) 14 bytes {6} [rendered]
139139
> x1 [11] ./index.js 1:0-42
140140
[6] ./x1.js 14 bytes {0} [built]
@@ -171,7 +171,7 @@ Child deep-async:
171171
4.bundle.js 1.13 KiB 4 [emitted] x4
172172
5.bundle.js 789 bytes 5 [emitted] x5
173173
6.bundle.js 1020 bytes 6 [emitted] xx5
174-
bundle.js 7.25 KiB 7 [emitted] main
174+
bundle.js 7.26 KiB 7 [emitted] main
175175
chunk {0} 0.bundle.js 0 bytes {7} [rendered]
176176
> async commons x1 [11] ./index.js 1:0-42
177177
> async commons x2 [11] ./index.js 2:0-42

test/statsCases/commons-plugin-issue-4980/expected.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Child
55
Asset Size Chunks Chunk Names
66
app.js 656 bytes 0 [emitted] app
77
vendor.1c0346d33a16fbee0579.js 619 bytes 1 [emitted] vendor
8-
runtime.js 7.03 KiB 2 [emitted] runtime
8+
runtime.js 7.04 KiB 2 [emitted] runtime
99
[./constants.js] 87 bytes {1} [built]
1010
[./entry-1.js] ./entry-1.js + 2 modules 190 bytes {0} [built]
1111
| ./entry-1.js 67 bytes [built]
@@ -17,7 +17,7 @@ Child
1717
Asset Size Chunks Chunk Names
1818
app.js 673 bytes 0 [emitted] app
1919
vendor.1c0346d33a16fbee0579.js 619 bytes 1 [emitted] vendor
20-
runtime.js 7.03 KiB 2 [emitted] runtime
20+
runtime.js 7.04 KiB 2 [emitted] runtime
2121
[./constants.js] 87 bytes {1} [built]
2222
[./entry-2.js] ./entry-2.js + 2 modules 197 bytes {0} [built]
2323
| ./entry-2.js 67 bytes [built]

test/statsCases/import-context-filter/expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Time: Xms
44
0.js 305 bytes 0 [emitted]
55
1.js 314 bytes 1 [emitted]
66
2.js 308 bytes 2 [emitted]
7-
entry.js 7.75 KiB 3 [emitted] entry
7+
entry.js 7.76 KiB 3 [emitted] entry
88
[0] ./templates/bar.js 38 bytes {0} [optional] [built]
99
[1] ./templates/baz.js 38 bytes {1} [optional] [built]
1010
[2] ./templates/foo.js 38 bytes {2} [optional] [built]

test/statsCases/import-weak/expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Hash: 28bb31ac457d1e720fe0
22
Time: Xms
33
Asset Size Chunks Chunk Names
44
0.js 149 bytes 0 [emitted]
5-
entry.js 7.58 KiB 1 [emitted] entry
5+
entry.js 7.59 KiB 1 [emitted] entry
66
[0] ./modules/b.js 22 bytes {0} [built]
77
[1] ./entry.js 120 bytes {1} [built]
88
[2] ./modules/a.js 37 bytes [built]

test/statsCases/limit-chunk-count-plugin/expected.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Child
1616
Time: Xms
1717
Asset Size Chunks Chunk Names
1818
0.bundle.js 928 bytes 0 [emitted]
19-
bundle.js 7.12 KiB 1 [emitted] main
19+
bundle.js 7.13 KiB 1 [emitted] main
2020
chunk {0} 0.bundle.js 118 bytes {1} [rendered]
2121
[0] ./d.js 22 bytes {0} [built]
2222
[1] ./e.js 22 bytes {0} [built]
@@ -31,7 +31,7 @@ Child
3131
Asset Size Chunks Chunk Names
3232
0.bundle.js 790 bytes 0 [emitted]
3333
1.bundle.js 245 bytes 1 [emitted]
34-
bundle.js 7.12 KiB 2 [emitted] main
34+
bundle.js 7.13 KiB 2 [emitted] main
3535
chunk {0} 0.bundle.js 74 bytes {2} [rendered]
3636
[0] ./d.js 22 bytes {0} [built]
3737
[2] ./a.js 22 bytes {0} [built]
@@ -48,7 +48,7 @@ Child
4848
0.bundle.js 236 bytes 0 [emitted]
4949
1.bundle.js 245 bytes 1 [emitted]
5050
2.bundle.js 619 bytes 2 [emitted]
51-
bundle.js 7.11 KiB 3 [emitted] main
51+
bundle.js 7.12 KiB 3 [emitted] main
5252
chunk {0} 0.bundle.js 44 bytes {2} {3} [rendered]
5353
[0] ./d.js 22 bytes {0} [built]
5454
[2] ./a.js 22 bytes {0} [built]

test/statsCases/module-deduplication-named/expected.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ Asset Size Chunks Chunk Names
22
0.js 818 bytes 0 [emitted] async3
33
1.js 818 bytes 1 [emitted] async1
44
2.js 818 bytes 2 [emitted] async2
5-
e1.js 7.94 KiB 3 [emitted] e1
6-
e2.js 7.96 KiB 4 [emitted] e2
7-
e3.js 7.98 KiB 5 [emitted] e3
5+
e1.js 7.95 KiB 3 [emitted] e1
6+
e2.js 7.97 KiB 4 [emitted] e2
7+
e3.js 7.99 KiB 5 [emitted] e3
88
chunk {0} 0.js (async3) 89 bytes {2} {5} [rendered]
99
[4] ./h.js 9 bytes {0} {5} [built]
1010
[7] ./async3.js 80 bytes {0} [built]

test/statsCases/module-deduplication/expected.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ Asset Size Chunks Chunk Names
55
3.js 661 bytes 3 [emitted]
66
4.js 661 bytes 4 [emitted]
77
5.js 661 bytes 5 [emitted]
8-
e1.js 8.11 KiB 6 [emitted] e1
9-
e2.js 8.13 KiB 7 [emitted] e2
10-
e3.js 8.15 KiB 8 [emitted] e3
8+
e1.js 8.12 KiB 6 [emitted] e1
9+
e2.js 8.14 KiB 7 [emitted] e2
10+
e3.js 8.16 KiB 8 [emitted] e3
1111
chunk {0} 0.js 37 bytes {7} {8} [rendered]
1212
[2] ./d.js 9 bytes {0} {6} [built]
1313
[5] ./async1.js 28 bytes {0} {5} [built]

test/statsCases/named-chunks-plugin-async/expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Time: Xms
33
Asset Size Chunks Chunk Names
44
chunk-containing-__a_js.js 465 bytes chunk-containing-__a_js [emitted]
55
chunk-containing-__b_js.js 173 bytes chunk-containing-__b_js [emitted]
6-
entry.js 7.13 KiB entry [emitted] entry
6+
entry.js 7.14 KiB entry [emitted] entry
77
[0] ./modules/b.js 22 bytes {chunk-containing-__b_js} [built]
88
[1] ./modules/a.js 37 bytes {chunk-containing-__a_js} [built]
99
[2] ./entry.js 47 bytes {entry} [built]

test/statsCases/named-chunks-plugin/expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Hash: f4f2142b60f3f055cbd9
22
Time: Xms
33
Asset Size Chunks Chunk Names
44
entry.js 425 bytes entry [emitted] entry
5-
manifest.js 7.04 KiB manifest [emitted] manifest
5+
manifest.js 7.05 KiB manifest [emitted] manifest
66
vendor.js 469 bytes vendor [emitted] vendor
77
[0] multi ./modules/a ./modules/b 40 bytes {vendor} [built]
88
[./entry.js] 72 bytes {entry} [built]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"use strict";
2+
3+
var SingleEntryPlugin = require("../../../lib/SingleEntryPlugin");
4+
5+
/**
6+
* Runs a child compilation which produces an error in order to test that NoEmitErrorsPlugin
7+
* recognizes errors within child compilations.
8+
*/
9+
module.exports = class TestChildCompilationFailurePlugin {
10+
11+
constructor(output) {
12+
this.output = output;
13+
}
14+
15+
apply(compiler) {
16+
compiler.plugin("make", (compilation, cb) => {
17+
const child = compilation.createChildCompiler("child", this.output);
18+
child.plugin("compilation", childCompilation => {
19+
childCompilation.errors.push(new Error("forced error"));
20+
});
21+
child.apply(new SingleEntryPlugin(compiler.options.context, compiler.options.entry, "child"));
22+
child.runAsChild(cb);
23+
});
24+
}
25+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Hash: 2e82f0bf277419f24e02
2+
Time: Xms
3+
Asset Size Chunks Chunk Names
4+
child.js 2.6 KiB
5+
bundle.js 2.6 KiB 0 main
6+
[0] ./index.js 0 bytes {0} [built]
7+
8+
WARNING in configuration
9+
The 'mode' option has not been set. Set 'mode' option to 'development' or 'production' to enable defaults for this enviroment.
10+
Child child:
11+
Asset Size Chunks Chunk Names
12+
child.js 2.6 KiB 0 child
13+
[0] ./index.js 0 bytes {0} [built]
14+
15+
ERROR in forced error

test/statsCases/no-emit-on-errors-plugin-with-child-error/index.js

Whitespace-only changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"use strict";
2+
3+
var NoEmitOnErrorsPlugin = require("../../../lib/NoEmitOnErrorsPlugin");
4+
var TestChildCompilationFailurePlugin = require("./TestChildCompilationFailurePlugin");
5+
6+
module.exports = {
7+
entry: "./index",
8+
output: {
9+
filename: "bundle.js"
10+
},
11+
plugins: [
12+
new NoEmitOnErrorsPlugin(),
13+
new TestChildCompilationFailurePlugin({
14+
filename: "child.js"
15+
})
16+
]
17+
};

test/statsCases/optimize-chunks/expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Time: Xms
88
4.js 190 bytes 4, 6 [emitted] chunk
99
5.js 371 bytes 5, 3 [emitted] cir2 from cir1
1010
6.js 130 bytes 6 [emitted] ac in ab
11-
main.js 7.68 KiB 7 [emitted] main
11+
main.js 7.69 KiB 7 [emitted] main
1212
chunk {0} 0.js (cir1) 81 bytes {3} {7} [rendered]
1313
> duplicate cir1 from cir2 [3] ./circular2.js 1:0-79
1414
> duplicate cir1 [8] ./index.js 13:0-54

0 commit comments

Comments
 (0)