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]

0 commit comments

Comments
 (0)