Skip to content

Commit 82f42e2

Browse files
committed
Merge branch 'master' into next
2 parents 73bb005 + 1dc5618 commit 82f42e2

19 files changed

Lines changed: 180 additions & 20 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
MIT License http://www.opensource.org/licenses/mit-license.php
3+
Author Sean Larkin @thelarkinn
4+
*/
5+
"use strict";
6+
7+
const WebpackError = require("./WebpackError");
8+
9+
module.exports = class AsyncDependencyToInitialChunkWarning extends WebpackError {
10+
constructor(chunkName, module, loc) {
11+
super();
12+
13+
this.name = "AsyncDependencyToInitialChunkWarning";
14+
this.message = `It's not allowed to load an initial chunk on demand. The chunk name "${chunkName}" is already used by an entrypoint.`;
15+
this.module = module;
16+
this.origin = module;
17+
this.originLoc = loc;
18+
19+
Error.captureStackTrace(this, this.constructor);
20+
}
21+
};

lib/Compilation.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const HotUpdateChunkTemplate = require("./HotUpdateChunkTemplate");
2020
const ModuleTemplate = require("./ModuleTemplate");
2121
const Dependency = require("./Dependency");
2222
const ChunkRenderError = require("./ChunkRenderError");
23+
const AsyncDependencyToInitialChunkWarning = require("./AsyncDependencyToInitialChunkWarning");
2324
const CachedSource = require("webpack-sources").CachedSource;
2425
const Stats = require("./Stats");
2526
const Semaphore = require("./util/Semaphore");
@@ -891,12 +892,19 @@ class Compilation extends Tapable {
891892
// but only once (blockChunks map)
892893
let c = blockChunks.get(b);
893894
if(c === undefined) {
894-
c = this.addChunk(b.chunkName, b.module, b.loc);
895-
blockChunks.set(b, c);
896-
allCreatedChunks.add(c);
897-
// We initialize the chunks property
898-
// this is later filled with the chunk when needed
899-
b.chunks = [];
895+
c = this.namedChunks[b.chunkName];
896+
if(c && c.isInitial()) {
897+
// TODO webpack 4: convert this to an error
898+
this.warnings.push(new AsyncDependencyToInitialChunkWarning(b.chunkName, b.module, b.loc));
899+
c = chunk;
900+
} else {
901+
c = this.addChunk(b.chunkName, b.module, b.loc);
902+
blockChunks.set(b, c);
903+
allCreatedChunks.add(c);
904+
// We initialize the chunks property
905+
// this is later filled with the chunk when needed
906+
b.chunks = [];
907+
}
900908
}
901909

902910
// 2. We store the Block+Chunk mapping as dependency for the chunk

lib/ModuleParseError.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ModuleParseError extends WebpackError {
1111
super();
1212

1313
this.name = "ModuleParseError";
14-
this.message = "Module parse failed: " + module.request + " " + err.message;
14+
this.message = "Module parse failed: " + err.message;
1515
this.message += "\nYou may need an appropriate loader to handle this file type.";
1616
if(err.loc && typeof err.loc === "object" && typeof err.loc.line === "number") {
1717
var lineNumber = err.loc.line;

lib/Stats.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,22 @@ class Stats {
199199
text += e.message;
200200
if(showErrorDetails && e.details) text += `\n${e.details}`;
201201
if(showErrorDetails && e.missing) text += e.missing.map(item => `\n[${item}]`).join("");
202-
if(showModuleTrace && e.dependencies && e.origin) {
202+
if(showModuleTrace && e.origin) {
203203
text += `\n @ ${e.origin.readableIdentifier(requestShortener)}`;
204-
e.dependencies.forEach(dep => {
205-
if(!dep.loc) return;
206-
if(typeof dep.loc === "string") return;
207-
const locInfo = formatLocation(dep.loc);
208-
if(!locInfo) return;
209-
text += ` ${locInfo}`;
210-
});
204+
if(typeof e.originLoc === "object") {
205+
const locInfo = formatLocation(e.originLoc);
206+
if(locInfo)
207+
text += ` ${locInfo}`;
208+
}
209+
if(e.dependencies) {
210+
e.dependencies.forEach(dep => {
211+
if(!dep.loc) return;
212+
if(typeof dep.loc === "string") return;
213+
const locInfo = formatLocation(dep.loc);
214+
if(!locInfo) return;
215+
text += ` ${locInfo}`;
216+
});
217+
}
211218
let current = e.origin;
212219
while(current.issuer) {
213220
current = current.issuer;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webpack",
3-
"version": "3.7.1",
3+
"version": "3.8.0",
44
"author": "Tobias Koppers @sokra",
55
"description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
66
"dependencies": {

schemas/webpackOptionsSchema.json

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,7 @@
967967
"anyOf": [
968968
{
969969
"type": "object",
970+
"additionalProperties": false,
970971
"properties": {
971972
"context": {
972973
"type": "string",
@@ -989,6 +990,46 @@
989990
"type": "boolean",
990991
"description": "add assets information"
991992
},
993+
"env": {
994+
"type": "boolean",
995+
"description": "add --env information"
996+
},
997+
"colors": {
998+
"oneOf": [
999+
{
1000+
"type": "boolean",
1001+
"description": "`webpack --colors` equivalent"
1002+
},
1003+
{
1004+
"type": "object",
1005+
"additionalProperties": false,
1006+
"properties": {
1007+
"bold": {
1008+
"type": "string"
1009+
},
1010+
"red": {
1011+
"type": "string"
1012+
},
1013+
"green": {
1014+
"type": "string"
1015+
},
1016+
"cyan": {
1017+
"type": "string"
1018+
},
1019+
"magenta": {
1020+
"type": "string"
1021+
},
1022+
"yellow": {
1023+
"type": "string"
1024+
}
1025+
}
1026+
}
1027+
]
1028+
},
1029+
"maxModules": {
1030+
"type": "number",
1031+
"description": "Set the maximum number of modules to be shown"
1032+
},
9921033
"chunks": {
9931034
"type": "boolean",
9941035
"description": "add chunk information"
@@ -1009,6 +1050,10 @@
10091050
"type": "boolean",
10101051
"description": "add also information about cached (not built) modules"
10111052
},
1053+
"cachedAssets": {
1054+
"type": "boolean",
1055+
"description": "Show cached assets (setting this to `false` only shows emitted files)"
1056+
},
10121057
"reasons": {
10131058
"type": "boolean",
10141059
"description": "add information about the reasons why modules are included"
@@ -1033,6 +1078,10 @@
10331078
"description": "Please use excludeModules instead.",
10341079
"$ref": "#/definitions/filter-types"
10351080
},
1081+
"entrypoints": {
1082+
"type": "boolean",
1083+
"description": "Display the entry points with the corresponding bundles"
1084+
},
10361085
"errorDetails": {
10371086
"type": "boolean",
10381087
"description": "add details to errors (like resolving log)"
@@ -1057,6 +1106,10 @@
10571106
"type": "string",
10581107
"description": "sort the assets by that field"
10591108
},
1109+
"publicPath": {
1110+
"type": "boolean",
1111+
"description": "Add public path information"
1112+
},
10601113
"providedExports": {
10611114
"type": "boolean",
10621115
"description": "show exports provided by modules"

test/Validation.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,20 @@ describe("Validation", () => {
199199
message: [
200200
" - configuration.context: The provided value \"baz\" is not an absolute path!",
201201
]
202+
}, {
203+
name: "missing stats option",
204+
config: {
205+
entry: "foo.js",
206+
stats: {
207+
foobar: true
208+
}
209+
},
210+
test(e) {
211+
e.message.should.startWith("Invalid configuration object.");
212+
e.message.split("\n").slice(1)[0].should.be.eql(
213+
" - configuration.stats should be one of these:"
214+
);
215+
}
202216
}];
203217
testCases.forEach((testCase) => {
204218
it("should fail validation for " + testCase.name, () => {
@@ -207,6 +221,12 @@ describe("Validation", () => {
207221
} catch(e) {
208222
if(!(e instanceof WebpackOptionsValidationError))
209223
throw e;
224+
225+
if(testCase.test) {
226+
testCase.test(e);
227+
return;
228+
}
229+
210230
e.message.should.startWith("Invalid configuration object.");
211231
e.message.split("\n").slice(1).should.be.eql(testCase.message);
212232
return;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
it("should handle reference to entry chunk correctly", function(done) {
2+
import(/* webpackChunkName: "main" */"./module-a").then(function(result) {
3+
result.default.should.be.eql("ok");
4+
done();
5+
}).catch(function(e) {
6+
done(e);
7+
});
8+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default "ok";
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = [
2+
[/It's not allowed to load an initial chunk on demand\. The chunk name "main" is already used by an entrypoint\./],
3+
];

0 commit comments

Comments
 (0)