Skip to content

Commit 8d8da4c

Browse files
committed
Merge branch 'master' into bump_prettier
2 parents f1092ad + 0f70fcb commit 8d8da4c

Some content is hidden

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

44 files changed

+482
-129
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ yarn add webpack --dev
5252

5353
<h2 align="center">Introduction</h2>
5454

55-
> This README reflects Webpack v2.x and v3.x. The Webpack v1.x documentation has been deprecated and deleted.
55+
> This README reflects webpack v2.x and v3.x. The webpack v1.x documentation has been deprecated and deleted.
5656
5757
webpack is a bundler for modules. The main purpose is to bundle JavaScript
5858
files for usage in a browser, yet it is also capable of transforming, bundling,

bin/webpack.js

100644100755
Lines changed: 69 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,80 @@
11
#!/usr/bin/env node
2+
function runCommand(command, options) {
3+
const cp = require("child_process");
4+
return new Promise((resolve, reject) => {
5+
const executedCommand = cp.spawn(command, options, {
6+
stdio: "inherit"
7+
});
8+
9+
executedCommand.on("error", error => {
10+
reject(error);
11+
});
12+
13+
executedCommand.on("exit", code => {
14+
if (code === 0) {
15+
resolve(true);
16+
} else {
17+
reject();
18+
}
19+
});
20+
});
21+
}
222

323
let webpackCliInstalled = false;
424
try {
525
require.resolve("webpack-cli");
626
webpackCliInstalled = true;
7-
} catch (e) {
27+
} catch (err) {
828
webpackCliInstalled = false;
929
}
1030

11-
if (webpackCliInstalled) {
12-
require("webpack-cli"); // eslint-disable-line node/no-missing-require, node/no-extraneous-require, node/no-unpublished-require
31+
if (!webpackCliInstalled) {
32+
const path = require("path");
33+
const fs = require("fs");
34+
const readLine = require("readline");
35+
const isYarn = fs.existsSync(path.resolve(process.cwd(), "yarn.lock"));
36+
37+
const packageManager = isYarn ? "yarn" : "npm";
38+
const options = ["install", "-D", "webpack-cli"];
39+
40+
if (isYarn) {
41+
options[0] = "add";
42+
}
43+
44+
const commandToBeRun = `${packageManager} ${options.join(" ")}`;
45+
46+
const question = `Would you like to install webpack-cli? (That will run ${commandToBeRun}) `;
47+
48+
console.error("The CLI moved into a separate package: webpack-cli");
49+
const questionInterface = readLine.createInterface({
50+
input: process.stdin,
51+
output: process.stdout
52+
});
53+
questionInterface.question(question, answer => {
54+
questionInterface.close();
55+
switch (answer.toLowerCase()) {
56+
case "y":
57+
case "yes":
58+
case "1": {
59+
runCommand(packageManager, options)
60+
.then(result => {
61+
return require("webpack-cli"); //eslint-disable-line
62+
})
63+
.catch(error => {
64+
console.error(error);
65+
process.exitCode = 1;
66+
});
67+
break;
68+
}
69+
default: {
70+
console.error(
71+
"It needs to be installed alongside webpack to use the CLI"
72+
);
73+
process.exitCode = 1;
74+
break;
75+
}
76+
}
77+
});
1378
} else {
14-
console.error("The CLI moved into a separate package: webpack-cli.");
15-
console.error(
16-
"Please install 'webpack-cli' in addition to webpack itself to use the CLI."
17-
);
18-
console.error("-> When using npm: npm install webpack-cli -D");
19-
console.error("-> When using yarn: yarn add webpack-cli -D");
20-
process.exitCode = 1;
79+
require("webpack-cli"); // eslint-disable-line
2180
}

lib/Compilation.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,6 @@ class Compilation extends Tapable {
158158
beforeChunkAssets: new SyncHook([]),
159159
additionalChunkAssets: new SyncHook(["chunks"]),
160160

161-
records: new SyncHook(["compilation", "records"]),
162-
163161
additionalAssets: new AsyncSeriesHook([]),
164162
optimizeChunkAssets: new AsyncSeriesHook(["chunks"]),
165163
afterOptimizeChunkAssets: new SyncHook(["chunks"]),
@@ -253,6 +251,9 @@ class Compilation extends Tapable {
253251
this.childrenCounters = {};
254252
this.usedChunkIds = null;
255253
this.usedModuleIds = null;
254+
this.fileTimestamps = undefined;
255+
this.contextTimestamps = undefined;
256+
this.compilationDependencies = undefined;
256257

257258
this._buildingModules = new Map();
258259
this._rebuildingModules = new Map();
@@ -277,6 +278,9 @@ class Compilation extends Tapable {
277278
if (this.cache && this.cache[cacheName]) {
278279
const cacheModule = this.cache[cacheName];
279280

281+
if (typeof cacheModule.updateCacheModule === "function")
282+
cacheModule.updateCacheModule(module);
283+
280284
let rebuild = true;
281285
if (this.fileTimestamps && this.contextTimestamps) {
282286
rebuild = cacheModule.needRebuild(

lib/Compiler.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,36 +94,36 @@ class Compiler extends Tapable {
9494
this.resolverFactory.plugin("resolver normal", resolver => {
9595
resolver.plugin(hook, fn);
9696
});
97-
}, "webpack: Using compiler.resolvers.normal is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver normal", resolver => {\n resolver.plugin(/* ... */);\n}); instead.'),
97+
}, "webpack: Using compiler.resolvers.normal is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver normal", resolver => {\n resolver.plugin(/* */);\n}); instead.'),
9898
apply: util.deprecate((...args) => {
9999
this.resolverFactory.plugin("resolver normal", resolver => {
100100
resolver.apply(...args);
101101
});
102-
}, "webpack: Using compiler.resolvers.normal is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver normal", resolver => {\n resolver.apply(/* ... */);\n}); instead.')
102+
}, "webpack: Using compiler.resolvers.normal is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver normal", resolver => {\n resolver.apply(/* */);\n}); instead.')
103103
},
104104
loader: {
105105
plugins: util.deprecate((hook, fn) => {
106106
this.resolverFactory.plugin("resolver loader", resolver => {
107107
resolver.plugin(hook, fn);
108108
});
109-
}, "webpack: Using compiler.resolvers.loader is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver loader", resolver => {\n resolver.plugin(/* ... */);\n}); instead.'),
109+
}, "webpack: Using compiler.resolvers.loader is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver loader", resolver => {\n resolver.plugin(/* */);\n}); instead.'),
110110
apply: util.deprecate((...args) => {
111111
this.resolverFactory.plugin("resolver loader", resolver => {
112112
resolver.apply(...args);
113113
});
114-
}, "webpack: Using compiler.resolvers.loader is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver loader", resolver => {\n resolver.apply(/* ... */);\n}); instead.')
114+
}, "webpack: Using compiler.resolvers.loader is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver loader", resolver => {\n resolver.apply(/* */);\n}); instead.')
115115
},
116116
context: {
117117
plugins: util.deprecate((hook, fn) => {
118118
this.resolverFactory.plugin("resolver context", resolver => {
119119
resolver.plugin(hook, fn);
120120
});
121-
}, "webpack: Using compiler.resolvers.context is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver context", resolver => {\n resolver.plugin(/* ... */);\n}); instead.'),
121+
}, "webpack: Using compiler.resolvers.context is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver context", resolver => {\n resolver.plugin(/* */);\n}); instead.'),
122122
apply: util.deprecate((...args) => {
123123
this.resolverFactory.plugin("resolver context", resolver => {
124124
resolver.apply(...args);
125125
});
126-
}, "webpack: Using compiler.resolvers.context is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver context", resolver => {\n resolver.apply(/* ... */);\n}); instead.')
126+
}, "webpack: Using compiler.resolvers.context is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver context", resolver => {\n resolver.apply(/* */);\n}); instead.')
127127
}
128128
};
129129

@@ -448,10 +448,7 @@ class Compiler extends Tapable {
448448
}
449449

450450
createContextModuleFactory() {
451-
const contextModuleFactory = new ContextModuleFactory(
452-
this.resolverFactory,
453-
this.inputFileSystem
454-
);
451+
const contextModuleFactory = new ContextModuleFactory(this.resolverFactory);
455452
this.hooks.contextModuleFactory.call(contextModuleFactory);
456453
return contextModuleFactory;
457454
}

lib/ContextModule.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ class ContextModule extends Module {
4343

4444
if (typeof options.mode !== "string")
4545
throw new Error("options.mode is a required option");
46+
47+
this._identifier = this._createIdentifier();
48+
}
49+
50+
updateCacheModule(module) {
51+
this.resolveDependencies = module.resolveDependencies;
52+
this.options = module.options;
53+
this.resolveOptions = module.resolveOptions;
4654
}
4755

4856
prettyRegExp(regexString) {
@@ -63,7 +71,7 @@ class ContextModule extends Module {
6371
.join("!");
6472
}
6573

66-
identifier() {
74+
_createIdentifier() {
6775
let identifier = this.context;
6876
if (this.options.resourceQuery)
6977
identifier += ` ${this.options.resourceQuery}`;
@@ -80,6 +88,10 @@ class ContextModule extends Module {
8088
return identifier;
8189
}
8290

91+
identifier() {
92+
return this._identifier;
93+
}
94+
8395
readableIdentifier(requestShortener) {
8496
let identifier = requestShortener.shorten(this.context);
8597
if (this.options.resourceQuery)

lib/Dependency.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class Dependency {
1010
this.module = null;
1111
this.weak = false;
1212
this.optional = false;
13+
this.loc = undefined;
1314
}
1415

1516
getResourceIdentifier() {

lib/HotUpdateChunkTemplate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module.exports = class HotUpdateChunkTemplate extends Tapable {
4747
hotUpdateChunk.removedModules = removedModules;
4848
const modulesSource = Template.renderChunkModules(
4949
hotUpdateChunk,
50-
() => true,
50+
m => typeof m.source === "function",
5151
moduleTemplate,
5252
dependencyTemplates
5353
);

lib/JavascriptGenerator.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ class JavascriptGenerator {
8383
* we can not inject "foo" twice, therefore we just make two IIFEs like so:
8484
* (function(foo, bar, baz){
8585
* (function(foo, some, more){
86-
* ...
87-
* }(...));
88-
* }(...));
86+
*
87+
* }());
88+
* }());
8989
*
9090
* "splitVariablesInUniqueNamedChunks" splits the variables shown above up to this:
9191
* [[foo, bar, baz], [foo, some, more]]
@@ -177,8 +177,8 @@ class JavascriptGenerator {
177177

178178
/*
179179
* creates the start part of a IIFE around the module to inject a variable name
180-
* (function(...){ <- this part
181-
* }.call(...))
180+
* (function(){ <- this part
181+
* }.call())
182182
*/
183183
variableInjectionFunctionWrapperStartCode(varNames) {
184184
const args = varNames.join(", ");
@@ -194,8 +194,8 @@ class JavascriptGenerator {
194194

195195
/*
196196
* creates the end part of a IIFE around the module to inject a variable name
197-
* (function(...){
198-
* }.call(...)) <- this part
197+
* (function(){
198+
* }.call()) <- this part
199199
*/
200200
variableInjectionFunctionWrapperEndCode(module, varExpressions, block) {
201201
const firstParam = this.contextArgument(module, block);

lib/JavascriptModulesPlugin.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ class JavascriptModulesPlugin {
3232
});
3333
normalModuleFactory.hooks.createGenerator
3434
.for("javascript/auto")
35-
.tap("JavascriptModulesPlugin", options => {
36-
return new JavascriptGenerator(options);
35+
.tap("JavascriptModulesPlugin", () => {
36+
return new JavascriptGenerator();
3737
});
3838
normalModuleFactory.hooks.createGenerator
3939
.for("javascript/dynamic")
40-
.tap("JavascriptModulesPlugin", options => {
41-
return new JavascriptGenerator(options);
40+
.tap("JavascriptModulesPlugin", () => {
41+
return new JavascriptGenerator();
4242
});
4343
normalModuleFactory.hooks.createGenerator
4444
.for("javascript/esm")
45-
.tap("JavascriptModulesPlugin", options => {
46-
return new JavascriptGenerator(options);
45+
.tap("JavascriptModulesPlugin", () => {
46+
return new JavascriptGenerator();
4747
});
4848
compilation.mainTemplate.hooks.renderManifest.tap(
4949
"JavascriptModulesPlugin",

lib/Module.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ class Module extends DependenciesBlock {
6767

6868
// delayed operations
6969
this._rewriteChunkInReasons = undefined;
70+
71+
this.useSourceMap = false;
7072
}
7173

7274
get exportsArgument() {
@@ -336,5 +338,6 @@ Module.prototype.build = null;
336338
Module.prototype.source = null;
337339
Module.prototype.size = null;
338340
Module.prototype.nameForCondition = null;
341+
Module.prototype.updateCacheModule = null;
339342

340343
module.exports = Module;

0 commit comments

Comments
 (0)