Skip to content

Commit 3e66954

Browse files
authored
Merge branch 'master' into feature/module-build-error-with-loader-name
2 parents 8060ec6 + d5eeda7 commit 3e66954

485 files changed

Lines changed: 6414 additions & 4716 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.eslintrc.js‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
root: true,
3-
plugins: ["prettier", "node"],
3+
plugins: ["prettier", "node", "jest"],
44
extends: ["eslint:recommended", "plugin:node/recommended", "plugin:prettier/recommended"],
55
env: {
66
node: true,
@@ -13,7 +13,6 @@ module.exports = {
1313
"prettier/prettier": "error",
1414
"no-undef": "error",
1515
"no-extra-semi": "error",
16-
"semi": "error",
1716
"no-template-curly-in-string": "error",
1817
"no-caller": "error",
1918
"no-control-regex": "off",
@@ -56,7 +55,7 @@ module.exports = {
5655
{
5756
files: ["test/**/*.js"],
5857
env: {
59-
mocha: true,
58+
"jest/globals": true
6059
}
6160
}
6261
]

‎.travis.yml‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,23 @@ cache:
1313
matrix:
1414
include:
1515
- os: linux
16-
node_js: "8"
16+
node_js: "10"
1717
env: NO_WATCH_TESTS=1 JOB_PART=lint
1818
- os: linux
19-
node_js: "8"
20-
env: NO_WATCH_TESTS=1 JOB_PART=integration
19+
node_js: "10"
20+
env: NO_WATCH_TESTS=1 JEST=--maxWorkers=2 JOB_PART=integration
2121
- os: linux
2222
node_js: "8"
23+
env: NO_WATCH_TESTS=1 JEST=--maxWorkers=2 JOB_PART=integration
24+
- os: linux
25+
node_js: "10"
2326
env: NO_WATCH_TESTS=1 JOB_PART=unit
2427
- os: linux
2528
node_js: "6"
26-
env: NO_WATCH_TESTS=1 JOB_PART=integration
29+
env: NO_WATCH_TESTS=1 JEST=--runInBand JOB_PART=integration
2730
- os: osx
28-
node_js: "8"
29-
env: NO_WATCH_TESTS=1 JOB_PART=integration
31+
node_js: "10"
32+
env: NO_WATCH_TESTS=1 JEST=--maxWorkers=2 JOB_PART=integration
3033
allow_failures:
3134
- os: osx
3235
fast_finish: true
@@ -40,7 +43,7 @@ script: npm run travis:$JOB_PART
4043

4144
after_success:
4245
- cat ./coverage/lcov.info | node_modules/.bin/coveralls --verbose
43-
- bash <(curl -s https://codecov.io/bash) -F $JOB_PART
46+
- bash <(curl -s https://codecov.io/bash) -F $JOB_PART --disable=gcov
4447
- rm -rf ./coverage
4548

4649
notifications:

‎appveyor.yml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ environment:
1616
job_part: unit
1717
- nodejs_version: 8
1818
job_part: integration
19+
jest: --maxWorkers=2
1920
- nodejs_version: 6
2021
job_part: integration
22+
jest: --runInBand
2123

2224
install:
2325
- ps: Install-Product node $env:nodejs_version x64
@@ -35,5 +37,6 @@ test_script:
3537
- node --version
3638
- npm --version
3739
- yarn --version
40+
- cmd: set JEST=%jest%
3841
- cmd: npm run appveyor:%job_part%
39-
- cmd: npm install -g codecov && codecov -F %job_part%
42+
- cmd: npm install -g codecov && codecov -F %job_part% --disable=gcov

‎lib/Chunk.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class Chunk {
5050
this.ids = null;
5151
this.debugId = debugId++;
5252
this.name = name;
53+
this.preventIntegration = false;
5354
this.entryModule = undefined;
5455
this._modules = new SortableSet(undefined, sortByIdentifier);
5556
this._groups = new SortableSet(undefined, sortById);
@@ -265,6 +266,9 @@ class Chunk {
265266
}
266267
return true;
267268
};
269+
270+
if (this.preventIntegration || otherChunk.preventIntegration) return false;
271+
268272
if (this.hasRuntime() !== otherChunk.hasRuntime()) {
269273
if (this.hasRuntime()) {
270274
return isAvailable(this, otherChunk);

‎lib/Compilation.js‎

Lines changed: 75 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,61 @@ class Compilation extends Tapable {
11681168
const chunkDependencies = new Map(); // Map<Chunk, Array<{Module, Chunk}>>
11691169
const allCreatedChunkGroups = new Set();
11701170

1171+
// PREPARE
1172+
const blockInfoMap = new Map();
1173+
1174+
const iteratorDependency = d => {
1175+
// We skip Dependencies without Reference
1176+
const ref = d.getReference();
1177+
if (!ref) {
1178+
return;
1179+
}
1180+
// We skip Dependencies without Module pointer
1181+
const refModule = ref.module;
1182+
if (!refModule) {
1183+
return;
1184+
}
1185+
// We skip weak Dependencies
1186+
if (ref.weak) {
1187+
return;
1188+
}
1189+
1190+
blockInfoModules.add(refModule);
1191+
};
1192+
1193+
const iteratorBlockPrepare = b => {
1194+
blockInfoBlocks.push(b);
1195+
blockQueue.push(b);
1196+
};
1197+
1198+
let block, blockQueue, blockInfoModules, blockInfoBlocks;
1199+
for (const module of this.modules) {
1200+
blockQueue = [module];
1201+
while (blockQueue.length > 0) {
1202+
block = blockQueue.pop();
1203+
blockInfoModules = new Set();
1204+
blockInfoBlocks = [];
1205+
1206+
if (block.variables) {
1207+
iterationBlockVariable(block.variables, iteratorDependency);
1208+
}
1209+
1210+
if (block.dependencies) {
1211+
iterationOfArrayCallback(block.dependencies, iteratorDependency);
1212+
}
1213+
1214+
if (block.blocks) {
1215+
iterationOfArrayCallback(block.blocks, iteratorBlockPrepare);
1216+
}
1217+
1218+
const blockInfo = {
1219+
modules: blockInfoModules,
1220+
blocks: blockInfoBlocks
1221+
};
1222+
blockInfoMap.set(block, blockInfo);
1223+
}
1224+
}
1225+
11711226
// PART ONE
11721227

11731228
const blockChunkGroups = new Map();
@@ -1180,7 +1235,7 @@ class Compilation extends Tapable {
11801235
chunkGroup
11811236
}));
11821237

1183-
let module, block, chunk, chunkGroup;
1238+
let module, chunk, chunkGroup;
11841239

11851240
// For each async Block in graph
11861241
const iteratorBlock = b => {
@@ -1227,36 +1282,6 @@ class Compilation extends Tapable {
12271282
});
12281283
};
12291284

1230-
// For each Dependency in the graph
1231-
const iteratorDependency = d => {
1232-
// We skip Dependencies without Reference
1233-
const ref = d.getReference();
1234-
if (!ref) {
1235-
return;
1236-
}
1237-
// We skip Dependencies without Module pointer
1238-
const refModule = ref.module;
1239-
if (!refModule) {
1240-
return;
1241-
}
1242-
// We skip weak Dependencies
1243-
if (ref.weak) {
1244-
return;
1245-
}
1246-
// We connect Module and Chunk when not already done
1247-
if (chunk.addModule(refModule)) {
1248-
refModule.addChunk(chunk);
1249-
1250-
// And enqueue the Module for traversal
1251-
queue.push({
1252-
block: refModule,
1253-
module: refModule,
1254-
chunk,
1255-
chunkGroup
1256-
});
1257-
}
1258-
};
1259-
12601285
// Iterative traversal of the Module graph
12611286
// Recursive would be simpler to write but could result in Stack Overflows
12621287
while (queue.length) {
@@ -1266,18 +1291,27 @@ class Compilation extends Tapable {
12661291
chunk = queueItem.chunk;
12671292
chunkGroup = queueItem.chunkGroup;
12681293

1269-
// Traverse all variables, Dependencies and Blocks
1270-
if (block.variables) {
1271-
iterationBlockVariable(block.variables, iteratorDependency);
1272-
}
1273-
1274-
if (block.dependencies) {
1275-
iterationOfArrayCallback(block.dependencies, iteratorDependency);
1294+
// get prepared block info
1295+
const blockInfo = blockInfoMap.get(block);
1296+
1297+
// Traverse all referenced modules
1298+
for (const refModule of blockInfo.modules) {
1299+
// We connect Module and Chunk when not already done
1300+
if (chunk.addModule(refModule)) {
1301+
refModule.addChunk(chunk);
1302+
1303+
// And enqueue the Module for traversal
1304+
queue.push({
1305+
block: refModule,
1306+
module: refModule,
1307+
chunk,
1308+
chunkGroup
1309+
});
1310+
}
12761311
}
12771312

1278-
if (block.blocks) {
1279-
iterationOfArrayCallback(block.blocks, iteratorBlock);
1280-
}
1313+
// Traverse all Blocks
1314+
iterationOfArrayCallback(blockInfo.blocks, iteratorBlock);
12811315
}
12821316

12831317
// PART TWO

‎lib/HotModuleReplacementPlugin.js‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const ModuleHotDeclineDependency = require("./dependencies/ModuleHotDeclineDepen
1212
const ConstDependency = require("./dependencies/ConstDependency");
1313
const NullFactory = require("./NullFactory");
1414
const ParserHelpers = require("./ParserHelpers");
15-
const createHash = require("./util/createHash");
1615

1716
module.exports = class HotModuleReplacementPlugin {
1817
constructor(options) {
@@ -74,9 +73,7 @@ module.exports = class HotModuleReplacementPlugin {
7473
records.moduleHashs = {};
7574
for (const module of compilation.modules) {
7675
const identifier = module.identifier();
77-
const hash = createHash(compilation.outputOptions.hashFunction);
78-
module.updateHash(hash);
79-
records.moduleHashs[identifier] = hash.digest("hex");
76+
records.moduleHashs[identifier] = module.hash;
8077
}
8178
records.chunkHashs = {};
8279
for (const chunk of compilation.chunks) {
@@ -136,9 +133,7 @@ module.exports = class HotModuleReplacementPlugin {
136133
return;
137134
for (const module of compilation.modules) {
138135
const identifier = module.identifier();
139-
let hash = createHash(compilation.outputOptions.hashFunction);
140-
module.updateHash(hash);
141-
hash = hash.digest("hex");
136+
let hash = module.hash;
142137
module.hotUpdate = records.moduleHashs[identifier] !== hash;
143138
}
144139
const hotUpdateMainContent = {

‎lib/NamedModulesPlugin.js‎

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
*/
55
"use strict";
66

7+
const createHash = require("./util/createHash");
8+
const RequestShortener = require("./RequestShortener");
9+
10+
const getHash = str => {
11+
const hash = createHash("md4");
12+
hash.update(str);
13+
return hash.digest("hex").substr(0, 4);
14+
};
15+
716
class NamedModulesPlugin {
817
constructor(options) {
918
this.options = options || {};
@@ -12,11 +21,32 @@ class NamedModulesPlugin {
1221
apply(compiler) {
1322
compiler.hooks.compilation.tap("NamedModulesPlugin", compilation => {
1423
compilation.hooks.beforeModuleIds.tap("NamedModulesPlugin", modules => {
24+
const namedModules = new Map();
25+
const context = this.options.context || compiler.options.context;
26+
1527
for (const module of modules) {
1628
if (module.id === null && module.libIdent) {
17-
module.id = module.libIdent({
18-
context: this.options.context || compiler.options.context
19-
});
29+
module.id = module.libIdent({ context });
30+
}
31+
32+
if (module.id !== null) {
33+
const namedModule = namedModules.get(module.id);
34+
if (namedModule !== undefined) {
35+
namedModule.push(module);
36+
} else {
37+
namedModules.set(module.id, [module]);
38+
}
39+
}
40+
}
41+
42+
for (const namedModule of namedModules.values()) {
43+
if (namedModule.length > 1) {
44+
for (const module of namedModule) {
45+
const requestShortener = new RequestShortener(context);
46+
module.id = `${module.id}?${getHash(
47+
requestShortener.shorten(module.identifier())
48+
)}`;
49+
}
2050
}
2151
}
2252
});

‎lib/WebpackOptionsDefaulter.js‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,17 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
215215
);
216216
this.set("optimization.splitChunks", {});
217217
this.set("optimization.splitChunks.chunks", "async");
218-
this.set("optimization.splitChunks.minSize", 30000);
218+
this.set("optimization.splitChunks.minSize", "make", options => {
219+
return isProductionLikeMode(options) ? 30000 : 10000;
220+
});
219221
this.set("optimization.splitChunks.minChunks", 1);
220-
this.set("optimization.splitChunks.maxAsyncRequests", 5);
222+
this.set("optimization.splitChunks.maxAsyncRequests", "make", options => {
223+
return isProductionLikeMode(options) ? 5 : Infinity;
224+
});
221225
this.set("optimization.splitChunks.automaticNameDelimiter", "~");
222-
this.set("optimization.splitChunks.maxInitialRequests", 3);
226+
this.set("optimization.splitChunks.maxInitialRequests", "make", options => {
227+
return isProductionLikeMode(options) ? 3 : Infinity;
228+
});
223229
this.set("optimization.splitChunks.name", true);
224230
this.set("optimization.splitChunks.cacheGroups", {});
225231
this.set("optimization.splitChunks.cacheGroups.default", {

‎lib/optimize/ConcatenatedModule.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,9 +576,12 @@ class ConcatenatedModule extends Module {
576576
moduleToInfoMap
577577
)
578578
);
579+
580+
// Must use full identifier in our cache here to ensure that the source
581+
// is updated should our dependencies list change.
579582
innerDependencyTemplates.set(
580583
"hash",
581-
innerDependencyTemplates.get("hash") + this.rootModule.identifier()
584+
innerDependencyTemplates.get("hash") + this.identifier()
582585
);
583586

584587
// Generate source code and analyse scopes

0 commit comments

Comments
 (0)