Skip to content

Commit 61445a5

Browse files
committed
Merge tag 'v4.29.3' into next
4.29.3
2 parents e96b929 + b934e26 commit 61445a5

File tree

9 files changed

+103
-55
lines changed

9 files changed

+103
-55
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ matrix:
3838
- os: linux
3939
node_js: "10"
4040
env:
41-
- NODEJS_VERSION=v12.0.0-nightly20181024bb79e768e5
41+
- NODEJS_VERSION=v12.0.0-nightly20190206686043e76e
4242
- YARN_EXTRA_ARGS="--ignore-engines"
4343
- NO_WATCH_TESTS=1
4444
- JEST="--maxWorkers=2 --cacheDirectory .jest-cache"

lib/ContextModule.js

Lines changed: 67 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -489,13 +489,12 @@ function webpackContext(req) {
489489
${returnModuleObject}
490490
}
491491
function webpackContextResolve(req) {
492-
var id = map[req];
493-
if(!(id + 1)) { // check for number or string
492+
if(!Object.prototype.hasOwnProperty.call(map, req)) {
494493
var e = new Error("Cannot find module '" + req + "'");
495494
e.code = 'MODULE_NOT_FOUND';
496495
throw e;
497496
}
498-
return id;
497+
return map[req];
499498
}
500499
webpackContext.keys = function webpackContextKeys() {
501500
return Object.keys(map);
@@ -529,13 +528,12 @@ function webpackContext(req) {
529528
${returnModuleObject}
530529
}
531530
function webpackContextResolve(req) {
532-
var id = map[req];
533-
if(!(id + 1)) { // check for number or string
531+
if(!Object.prototype.hasOwnProperty.call(map, req)) {
534532
var e = new Error("Cannot find module '" + req + "'");
535533
e.code = 'MODULE_NOT_FOUND';
536534
throw e;
537535
}
538-
return id;
536+
return map[req];
539537
}
540538
webpackContext.keys = function webpackContextKeys() {
541539
return Object.keys(map);
@@ -573,13 +571,12 @@ function webpackAsyncContextResolve(req) {
573571
// Here Promise.resolve().then() is used instead of new Promise() to prevent
574572
// uncaught exception popping up in devtools
575573
return Promise.resolve().then(function() {
576-
var id = map[req];
577-
if(!(id + 1)) { // check for number or string
574+
if(!Object.prototype.hasOwnProperty.call(map, req)) {
578575
var e = new Error("Cannot find module '" + req + "'");
579576
e.code = 'MODULE_NOT_FOUND';
580577
throw e;
581578
}
582-
return id;
579+
return map[req];
583580
});
584581
}
585582
webpackAsyncContext.keys = function webpackAsyncContextKeys() {
@@ -615,13 +612,12 @@ function webpackAsyncContextResolve(req) {
615612
// Here Promise.resolve().then() is used instead of new Promise() to prevent
616613
// uncaught exception popping up in devtools
617614
return Promise.resolve().then(function() {
618-
var id = map[req];
619-
if(!(id + 1)) { // check for number or string
615+
if(!Object.prototype.hasOwnProperty.call(map, req)) {
620616
var e = new Error("Cannot find module '" + req + "'");
621617
e.code = 'MODULE_NOT_FOUND';
622618
throw e;
623619
}
624-
return id;
620+
return map[req];
625621
});
626622
}
627623
webpackAsyncContext.keys = function webpackAsyncContextKeys() {
@@ -665,13 +661,12 @@ function webpackAsyncContext(req) {
665661
}
666662
function webpackAsyncContextResolve(req) {
667663
return ${promise}.then(function() {
668-
var id = map[req];
669-
if(!(id + 1)) { // check for number or string
664+
if(!Object.prototype.hasOwnProperty.call(map, req)) {
670665
var e = new Error("Cannot find module '" + req + "'");
671666
e.code = 'MODULE_NOT_FOUND';
672667
throw e;
673668
}
674-
return id;
669+
return map[req];
675670
});
676671
}
677672
webpackAsyncContext.keys = function webpackAsyncContextKeys() {
@@ -691,70 +686,102 @@ module.exports = webpackAsyncContext;`;
691686
getLazySource(blocks, id, chunkGraph) {
692687
const moduleGraph = chunkGraph.moduleGraph;
693688
let hasMultipleOrNoChunks = false;
689+
let hasNoChunk = true;
694690
const fakeMap = this.getFakeMap(
695691
blocks.map(b => b.dependencies[0]),
696692
chunkGraph
697693
);
698-
const map = blocks
694+
const hasFakeMap = typeof fakeMap === "object";
695+
const items = blocks
699696
.map(block => {
700697
const dependency = block.dependencies[0];
701698
return {
702699
dependency: dependency,
703700
module: moduleGraph.getModule(dependency),
704701
block: block,
705-
userRequest: dependency.userRequest
702+
userRequest: dependency.userRequest,
703+
chunks: undefined
706704
};
707705
})
708-
.filter(item => item.module)
706+
.filter(item => item.module);
707+
for (const item of items) {
708+
const chunkGroup = chunkGraph.getBlockChunkGroup(item.block);
709+
const chunks = (chunkGroup && chunkGroup.chunks) || [];
710+
item.chunks = chunks;
711+
if (chunks.length > 0) {
712+
hasNoChunk = false;
713+
}
714+
if (chunks.length !== 1) {
715+
hasMultipleOrNoChunks = true;
716+
}
717+
}
718+
const shortMode = hasNoChunk && !hasFakeMap;
719+
const map = items
709720
.sort((a, b) => {
710721
if (a.userRequest === b.userRequest) return 0;
711722
return a.userRequest < b.userRequest ? -1 : 1;
712723
})
713724
.reduce((map, item) => {
714-
const chunkGroup = chunkGraph.getBlockChunkGroup(item.block);
715-
const chunks = (chunkGroup && chunkGroup.chunks) || [];
716-
if (chunks.length !== 1) {
717-
hasMultipleOrNoChunks = true;
718-
}
719-
const module = moduleGraph.getModule(item.dependency);
720-
const moduleId = chunkGraph.getModuleId(module);
721-
const arrayStart = [moduleId];
722-
if (typeof fakeMap === "object") {
723-
arrayStart.push(fakeMap[moduleId]);
725+
const moduleId = chunkGraph.getModuleId(item.module);
726+
if (shortMode) {
727+
map[item.userRequest] = moduleId;
728+
} else {
729+
const arrayStart = [moduleId];
730+
if (hasFakeMap) {
731+
arrayStart.push(fakeMap[moduleId]);
732+
}
733+
map[item.userRequest] = arrayStart.concat(
734+
item.chunks.map(chunk => chunk.id)
735+
);
724736
}
725-
map[item.userRequest] = arrayStart.concat(
726-
chunks.map(chunk => chunk.id)
727-
);
728-
729737
return map;
730738
}, Object.create(null));
731739

732-
const chunksStartPosition = typeof fakeMap === "object" ? 2 : 1;
733-
const requestPrefix = hasMultipleOrNoChunks
740+
const chunksStartPosition = hasFakeMap ? 2 : 1;
741+
const requestPrefix = hasNoChunk
742+
? "Promise.resolve()"
743+
: hasMultipleOrNoChunks
734744
? `Promise.all(ids.slice(${chunksStartPosition}).map(${
735745
RuntimeGlobals.ensureChunk
736746
}))`
737747
: `${RuntimeGlobals.ensureChunk}(ids[${chunksStartPosition}])`;
738748
const returnModuleObject = this.getReturnModuleObjectSource(
739749
fakeMap,
740-
"ids[1]"
750+
shortMode ? "invalid" : "ids[1]"
741751
);
742752

743-
return `var map = ${JSON.stringify(map, null, "\t")};
753+
const webpackAsyncContext =
754+
requestPrefix === "Promise.resolve()"
755+
? `${shortMode ? "" : ""}
744756
function webpackAsyncContext(req) {
745-
var ids = map[req];
746-
if(!ids) {
757+
return Promise.resolve().then(function() {
758+
if(!Object.prototype.hasOwnProperty.call(map, req)) {
759+
var e = new Error("Cannot find module '" + req + "'");
760+
e.code = 'MODULE_NOT_FOUND';
761+
throw e;
762+
}
763+
764+
${shortMode ? "var id = map[req];" : "var ids = map[req], id = ids[0];"}
765+
${returnModuleObject}
766+
});
767+
}`
768+
: `function webpackAsyncContext(req) {
769+
if(!Object.prototype.hasOwnProperty.call(map, req)) {
747770
return Promise.resolve().then(function() {
748771
var e = new Error("Cannot find module '" + req + "'");
749772
e.code = 'MODULE_NOT_FOUND';
750773
throw e;
751774
});
752775
}
776+
777+
var ids = map[req], id = ids[0];
753778
return ${requestPrefix}.then(function() {
754-
var id = ids[0];
755779
${returnModuleObject}
756780
});
757-
}
781+
}`;
782+
783+
return `var map = ${JSON.stringify(map, null, "\t")};
784+
${webpackAsyncContext}
758785
webpackAsyncContext.keys = function webpackAsyncContextKeys() {
759786
return Object.keys(map);
760787
};

lib/WebpackError.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
"use strict";
77

8+
const inspect = require("util").inspect.custom;
89
const makeSerializable = require("./util/makeSerializable");
910

1011
/** @typedef {import("./Chunk")} Chunk */
@@ -33,7 +34,7 @@ class WebpackError extends Error {
3334
Error.captureStackTrace(this, this.constructor);
3435
}
3536

36-
inspect() {
37+
[inspect]() {
3738
return this.stack + (this.details ? `\n${this.details}` : "");
3839
}
3940

test/__snapshots__/StatsTestCases.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,7 @@ Built at: Thu Jan 01 1970 00:00:00 GMT
10941094
374.js 320 bytes {374} [emitted]
10951095
457.js 320 bytes {457} [emitted]
10961096
920.js 320 bytes {920} [emitted]
1097-
entry.js 8.6 KiB {707} [emitted] entry
1097+
entry.js 8.64 KiB {707} [emitted] entry
10981098
Entrypoint entry = entry.js
10991099
[259] ./templates lazy ^\\\\.\\\\/.*$ include: \\\\.js$ exclude: \\\\.noimport\\\\.js$ namespace object 160 bytes {707} [optional] [built]
11001100
[374] ./templates/baz.js 38 bytes {374} [optional] [built]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default "initialModuleDefault";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exports.default = "other";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default "initialModuleDefault";
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
it("should resolve when import existed chunk (#8626)", function(done) {
2+
require.context("./dir-initial/");
3+
const fileName = "initialModule";
4+
import(`./dir-initial/${fileName}`).then(({default:m}) => {
5+
expect(m).toBe("initialModuleDefault");
6+
done();
7+
}).catch(done);
8+
});
9+
10+
it("should resolve when import existed chunk with fake maps", function(done) {
11+
require.context("./dir-initial-with-fake-map/");
12+
const fileName = "initialModule";
13+
import(`./dir-initial-with-fake-map/${fileName}`).then(({default:m}) => {
14+
expect(m).toBe("initialModuleDefault");
15+
done();
16+
}).catch(done);
17+
});

yarn.lock

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4506,24 +4506,24 @@ rc@^1.2.7:
45064506
strip-json-comments "~2.0.1"
45074507

45084508
react-dom@^16.8.0:
4509-
version "16.8.0"
4510-
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.8.0.tgz#18f28d4be3571ed206672a267c66dd083145a9c4"
4511-
integrity sha512-dBzoAGYZpW9Yggp+CzBPC7q1HmWSeRc93DWrwbskmG1eHJWznZB/p0l/Sm+69leIGUS91AXPB/qB3WcPnKx8Sw==
4509+
version "16.8.1"
4510+
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.8.1.tgz#ec860f98853d09d39bafd3a6f1e12389d283dbb4"
4511+
integrity sha512-N74IZUrPt6UiDjXaO7UbDDFXeUXnVhZzeRLy/6iqqN1ipfjrhR60Bp5NuBK+rv3GMdqdIuwIl22u1SYwf330bg==
45124512
dependencies:
45134513
loose-envify "^1.1.0"
45144514
object-assign "^4.1.1"
45154515
prop-types "^15.6.2"
4516-
scheduler "^0.13.0"
4516+
scheduler "^0.13.1"
45174517

45184518
react@^16.8.0:
4519-
version "16.8.0"
4520-
resolved "https://registry.yarnpkg.com/react/-/react-16.8.0.tgz#8533f0e4af818f448a276eae71681d09e8dd970a"
4521-
integrity sha512-g+nikW2D48kqgWSPwNo0NH9tIGG3DsQFlrtrQ1kj6W77z5ahyIHG0w8kPpz4Sdj6gyLnz0lEd/xsjOoGge2MYQ==
4519+
version "16.8.1"
4520+
resolved "https://registry.yarnpkg.com/react/-/react-16.8.1.tgz#ae11831f6cb2a05d58603a976afc8a558e852c4a"
4521+
integrity sha512-wLw5CFGPdo7p/AgteFz7GblI2JPOos0+biSoxf1FPsGxWQZdN/pj6oToJs1crn61DL3Ln7mN86uZ4j74p31ELQ==
45224522
dependencies:
45234523
loose-envify "^1.1.0"
45244524
object-assign "^4.1.1"
45254525
prop-types "^15.6.2"
4526-
scheduler "^0.13.0"
4526+
scheduler "^0.13.1"
45274527

45284528
read-pkg-up@^4.0.0:
45294529
version "4.0.0"
@@ -4827,10 +4827,10 @@ sax@^1.2.4:
48274827
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
48284828
integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==
48294829

4830-
scheduler@^0.13.0:
4831-
version "0.13.0"
4832-
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.13.0.tgz#e701f62e1b3e78d2bbb264046d4e7260f12184dd"
4833-
integrity sha512-w7aJnV30jc7OsiZQNPVmBc+HooZuvQZIZIShKutC3tnMFMkcwVN9CZRRSSNw03OnSCKmEkK8usmwcw6dqBaLzw==
4830+
scheduler@^0.13.1:
4831+
version "0.13.1"
4832+
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.13.1.tgz#1a217df1bfaabaf4f1b92a9127d5d732d85a9591"
4833+
integrity sha512-VJKOkiKIN2/6NOoexuypwSrybx13MY7NSy9RNt8wPvZDMRT1CW6qlpF5jXRToXNHz3uWzbm2elNpZfXfGPqP9A==
48344834
dependencies:
48354835
loose-envify "^1.1.0"
48364836
object-assign "^4.1.1"

0 commit comments

Comments
 (0)