Skip to content

Commit f83c913

Browse files
authored
Merge branch 'master' into refactor/cleanups
2 parents e5f4eb1 + fb8afe7 commit f83c913

31 files changed

Lines changed: 232 additions & 97 deletions

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ yarn add webpack --dev
4949

5050
<h2 align="center">Introduction</h2>
5151

52-
> The README reflects webpack v2.x, webpack v1.x [documentation can be found here](https://webpack.github.io/docs/?utm_source=github&utm_medium=readme&utm_campaign=top).
52+
> This README reflects Webpack v2.x and v3.x. The Webpack v1.x [documentation can be found here](https://webpack.github.io/docs/?utm_source=github&utm_medium=readme&utm_campaign=top).
5353
5454
webpack is a bundler for modules. The main purpose is to bundle JavaScript
5555
files for usage in a browser, yet it is also capable of transforming, bundling,
@@ -534,7 +534,7 @@ src="https://static.monei.net/monei-logo.svg" height="30" alt="MONEI"></a>
534534
<h2 align="center">Thanks to</h2>
535535
<p align="center">(In chronological order)</p>
536536

537-
* @google for [Google Web Toolkit (GWT)](https://code.google.com/archive/p/google-web-toolkit), which aims to compile Java to JavaScript. It features a similar [Code Splitting](http://www.gwtproject.org/doc/latest/DevGuideCodeSplitting.html) as webpack.
537+
* @google for [Google Web Toolkit (GWT)](http://www.gwtproject.org/), which aims to compile Java to JavaScript. It features a similar [Code Splitting](http://www.gwtproject.org/doc/latest/DevGuideCodeSplitting.html) as webpack.
538538
* @medikoo for [modules-webmake](https://github.com/medikoo/modules-webmake), which is a similar project. webpack was born because I wanted Code Splitting for modules-webmake. Interestingly the [Code Splitting issue is still open](https://github.com/medikoo/modules-webmake/issues/7) (thanks also to @Phoscur for the discussion).
539539
* @substack for [browserify](http://browserify.org/), which is a similar project and source for many ideas.
540540
* @jrburke for [require.js](http://requirejs.org/), which is a similar project and source for many ideas.

‎bin/config-yargs.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ module.exports = function(yargs) {
172172
requiresArg: true
173173
},
174174
"watch-poll": {
175-
type: "boolean",
175+
type: "string",
176176
describe: "The polling interval for watching (also enable polling)",
177177
group: ADVANCED_GROUP
178178
},

‎bin/convert-argv.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,12 @@ module.exports = function(yargs, argv, convertOptions) {
166166
options.watchOptions.aggregateTimeout = +argv["watch-aggregate-timeout"];
167167
}
168168

169-
if(argv["watch-poll"]) {
169+
if(typeof argv["watch-poll"] !== undefined) {
170170
options.watchOptions = options.watchOptions || {};
171-
if(typeof argv["watch-poll"] !== "boolean")
172-
options.watchOptions.poll = +argv["watch-poll"];
173-
else
171+
if(argv["watch-poll"] === "true" || argv["watch-poll"] === "")
174172
options.watchOptions.poll = true;
173+
else if(!isNaN(argv["watch-poll"]))
174+
options.watchOptions.poll = +argv["watch-poll"];
175175
}
176176

177177
if(argv["watch-stdin"]) {

‎examples/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373

7474
[harmony-unused](harmony-unused)
7575

76-
## HTT2 Aggressive Splitting
76+
## HTTP2 Aggressive Splitting
7777
[http2-aggressive-splitting](http2-aggressive-splitting)
7878

7979
## Hybrid Routing

‎lib/HotModuleReplacement.runtime.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,8 @@ module.exports = function() {
561561
type: "self-accept-error-handler-errored",
562562
moduleId: moduleId,
563563
error: err2,
564-
orginalError: err
564+
orginalError: err, // TODO remove in webpack 4
565+
originalError: err
565566
});
566567
}
567568
if(!options.ignoreErrored) {

‎lib/Module.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class Module extends DependenciesBlock {
5858
this.providedExports = null;
5959
this._chunks.clear();
6060
this._chunksDebugIdent = undefined;
61+
this.optimizationBailout.length = 0;
6162
super.disconnect();
6263
}
6364

@@ -73,6 +74,7 @@ class Module extends DependenciesBlock {
7374

7475
setChunks(chunks) {
7576
this._chunks = new SortableSet(chunks, sortById);
77+
this._chunksDebugIdent = undefined;
7678
}
7779

7880
addChunk(chunk) {

‎lib/NormalModule.js‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@ function asString(buf) {
3434

3535
function contextify(context, request) {
3636
return request.split("!").map(function(r) {
37-
let rp = path.relative(context, r);
37+
const splitPath = r.split("?");
38+
splitPath[0] = path.relative(context, splitPath[0]);
3839
if(path.sep === "\\")
39-
rp = rp.replace(/\\/g, "/");
40-
if(rp.indexOf("../") !== 0)
41-
rp = "./" + rp;
42-
return rp;
40+
splitPath[0] = splitPath[0].replace(/\\/g, "/");
41+
if(splitPath[0].indexOf("../") !== 0)
42+
splitPath[0] = "./" + splitPath[0];
43+
return splitPath.join("?");
4344
}).join("!");
4445
}
4546

‎lib/SourceMapDevToolPlugin.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ class SourceMapDevToolPlugin {
9696
return module || source;
9797
});
9898

99-
for(const module of modules) {
99+
for(let idx = 0; idx < modules.length; idx++) {
100+
const module = modules[idx];
100101
if(!moduleToSourceNameMapping.get(module)) {
101102
moduleToSourceNameMapping.set(module, ModuleFilenameHelpers.createFilename(module, moduleFilenameTemplate, requestShortener));
102103
}
@@ -121,7 +122,8 @@ class SourceMapDevToolPlugin {
121122
});
122123

123124
// find modules with conflicting source names
124-
for(const module of allModules) {
125+
for(let idx = 0; idx < allModules.length; idx++) {
126+
const module = allModules[idx];
125127
let sourceName = moduleToSourceNameMapping.get(module);
126128
let hasName = conflictDetectionSet.has(sourceName);
127129
if(!hasName) {

‎lib/Template.js‎

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ const ConcatSource = require("webpack-sources").ConcatSource;
1010
const START_LOWERCASE_ALPHABET_CODE = "a".charCodeAt(0);
1111
const START_UPPERCASE_ALPHABET_CODE = "A".charCodeAt(0);
1212
const DELTA_A_TO_Z = "z".charCodeAt(0) - START_LOWERCASE_ALPHABET_CODE + 1;
13+
const FUNCTION_CONTENT_REGEX = /^function\s?\(\)\s?\{\r?\n?|\r?\n?\}$/g;
14+
const INDENT_MULTILINE_REGEX = /^\t/mg;
15+
const LINE_SEPARATOR_REGEX = /\r?\n/g;
16+
const IDENTIFIER_NAME_REPLACE_REGEX = /^([^a-zA-Z$_])/;
17+
const IDENTIFIER_ALPHA_NUMERIC_NAME_REPLACE_REGEX = /[^a-zA-Z0-9$]+/g;
18+
const COMMENT_END_REGEX = /\*\//g;
19+
const PATH_NAME_NORMALIZE_REPLACE_REGEX = /[^a-zA-Z0-9_!§$()=\-^°]+/g;
20+
const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
1321

1422
module.exports = class Template extends Tapable {
1523
constructor(outputOptions) {
@@ -18,27 +26,27 @@ module.exports = class Template extends Tapable {
1826
}
1927

2028
static getFunctionContent(fn) {
21-
return fn.toString().replace(/^function\s?\(\)\s?\{\r?\n?|\r?\n?\}$/g, "").replace(/^\t/mg, "").replace(/\r?\n/g, "\n");
29+
return fn.toString().replace(FUNCTION_CONTENT_REGEX, "").replace(INDENT_MULTILINE_REGEX, "").replace(LINE_SEPARATOR_REGEX, "\n");
2230
}
2331

2432
static toIdentifier(str) {
2533
if(typeof str !== "string") return "";
26-
return str.replace(/^([^a-zA-Z$_])/, "_$1").replace(/[^a-zA-Z0-9$]+/g, "_");
34+
return str.replace(IDENTIFIER_NAME_REPLACE_REGEX, "_$1").replace(IDENTIFIER_ALPHA_NUMERIC_NAME_REPLACE_REGEX, "_");
2735
}
2836

2937
static toComment(str) {
3038
if(!str) return "";
31-
return `/*! ${str.replace(/\*\//g, "* /")} */`;
39+
return `/*! ${str.replace(COMMENT_END_REGEX, "* /")} */`;
3240
}
3341

3442
static toNormalComment(str) {
3543
if(!str) return "";
36-
return `/* ${str.replace(/\*\//g, "* /")} */`;
44+
return `/* ${str.replace(COMMENT_END_REGEX, "* /")} */`;
3745
}
3846

3947
static toPath(str) {
4048
if(typeof str !== "string") return "";
41-
return str.replace(/[^a-zA-Z0-9_!§$()=\-^°]+/g, "-").replace(/^-|-$/, "");
49+
return str.replace(PATH_NAME_NORMALIZE_REPLACE_REGEX, "-").replace(MATCH_PADDED_HYPHENS_REPLACE_REGEX, "");
4250
}
4351

4452
// map number to a single character a-z, A-Z or <_ + number> if number is too big
@@ -154,23 +162,27 @@ module.exports = class Template extends Tapable {
154162
} else {
155163
// Render an object
156164
source.add("{\n");
157-
allModules.sort(function(a, b) {
158-
var aId = a.id + "";
159-
var bId = b.id + "";
160-
if(aId < bId) return -1;
161-
if(aId > bId) return 1;
162-
return 0;
163-
}).forEach(function(module, idx) {
164-
if(idx !== 0) source.add(",\n");
165-
source.add("\n/***/ " + JSON.stringify(module.id) + ":\n");
166-
source.add(module.source);
167-
});
165+
allModules
166+
.sort(stringifyIdSortPredicate)
167+
.forEach(function(module, idx) {
168+
if(idx !== 0) source.add(",\n");
169+
source.add(`\n/***/ ${JSON.stringify(module.id)}:\n`);
170+
source.add(module.source);
171+
});
168172
source.add("\n\n" + prefix + "}");
169173
}
170174
return source;
171175
}
172176
};
173177

178+
function stringifyIdSortPredicate(a, b) {
179+
var aId = a.id + "";
180+
var bId = b.id + "";
181+
if(aId < bId) return -1;
182+
if(aId > bId) return 1;
183+
return 0;
184+
}
185+
174186
function moduleIdIsNumber(module) {
175187
return typeof module.id === "number";
176188
}

‎lib/dependencies/HarmonyExportImportedSpecifierDependency.js‎

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ class HarmonyExportImportedSpecifierDependency extends NullDependency {
2626
const active = HarmonyModulesHelpers.isActive(this.originModule, this);
2727
const importedModule = this.importDependency.module;
2828

29-
if(!importedModule || !used || !active) return null;
30-
if(!this.originModule.usedExports) return null;
29+
if(!importedModule || !used || !active || !this.originModule.usedExports) return null;
30+
31+
const hasUsedExports = Array.isArray(this.originModule.usedExports);
3132

3233
if(name) {
33-
const nameIsNotInUsedExports = Array.isArray(this.originModule.usedExports) && this.originModule.usedExports.indexOf(name) < 0;
34+
const nameIsNotInUsedExports = hasUsedExports && this.originModule.usedExports.indexOf(name) < 0;
3435
if(nameIsNotInUsedExports) return null;
3536

3637
// export { name as name }
@@ -48,33 +49,31 @@ class HarmonyExportImportedSpecifierDependency extends NullDependency {
4849
};
4950
}
5051

52+
const hasProvidedExports = Array.isArray(importedModule.providedExports);
53+
5154
// export *
52-
if(Array.isArray(this.originModule.usedExports)) {
55+
if(hasUsedExports) {
5356
// reexport * with known used exports
54-
var activeExports = HarmonyModulesHelpers.getActiveExports(this.originModule, this);
55-
if(Array.isArray(importedModule.providedExports)) {
56-
return {
57-
module: importedModule,
58-
importedNames: this.originModule.usedExports.filter((id) => {
59-
const notInActiveExports = activeExports.indexOf(id) < 0;
60-
const notDefault = id !== "default";
61-
const inProvidedExports = importedModule.providedExports.indexOf(id) >= 0;
62-
return notInActiveExports && notDefault && inProvidedExports;
63-
}),
64-
};
65-
}
57+
const activeExports = HarmonyModulesHelpers.getActiveExports(this.originModule, this);
58+
const importedNames = this.originModule.usedExports.filter(id => {
59+
const notInActiveExports = activeExports.indexOf(id) < 0;
60+
const notDefault = id !== "default";
61+
62+
if(hasProvidedExports) {
63+
const inProvidedExports = importedModule.providedExports.indexOf(id) >= 0;
64+
return notInActiveExports && notDefault && inProvidedExports;
65+
} else {
66+
return notInActiveExports && notDefault;
67+
}
68+
});
6669

6770
return {
6871
module: importedModule,
69-
importedNames: this.originModule.usedExports.filter(id => {
70-
const notInActiveExports = activeExports.indexOf(id) < 0;
71-
const notDefault = id !== "default";
72-
return notInActiveExports && notDefault;
73-
}),
72+
importedNames
7473
};
7574
}
7675

77-
if(Array.isArray(importedModule.providedExports)) {
76+
if(hasProvidedExports) {
7877
return {
7978
module: importedModule,
8079
importedNames: importedModule.providedExports.filter(id => id !== "default"),

0 commit comments

Comments
 (0)