webpack 4.41.6 → 4.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -709,6 +709,10 @@ export interface ResolveOptions {
709
709
  resolver?: {
710
710
  [k: string]: any;
711
711
  };
712
+ /**
713
+ * A list of directories in which requests that are server-relative URLs (starting with '/') are resolved. On non-windows system these requests are tried to resolve as absolute path first.
714
+ */
715
+ roots?: string[];
712
716
  /**
713
717
  * Enable resolving symlinks to the original location
714
718
  */
@@ -927,6 +931,10 @@ export interface OptimizationSplitChunksOptions {
927
931
  * Ignore minimum size, minimum chunks and maximum requests and always create chunks for this cache group
928
932
  */
929
933
  enforce?: boolean;
934
+ /**
935
+ * Size threshold at which splitting is enforced and other restrictions (maxAsyncRequests, maxInitialRequests) are ignored.
936
+ */
937
+ enforceSizeThreshold?: number;
930
938
  /**
931
939
  * Sets the template for the filename for created chunks (Only works for initial chunks)
932
940
  */
@@ -973,6 +981,10 @@ export interface OptimizationSplitChunksOptions {
973
981
  * Select chunks for determining shared modules (defaults to "async", "initial" and "all" requires adding these chunks to the HTML)
974
982
  */
975
983
  chunks?: ("initial" | "async" | "all") | Function;
984
+ /**
985
+ * Size threshold at which splitting is enforced and other restrictions (maxAsyncRequests, maxInitialRequests) are ignored.
986
+ */
987
+ enforceSizeThreshold?: number;
976
988
  /**
977
989
  * Options for modules not selected by any other cache group
978
990
  */
@@ -1118,7 +1130,7 @@ export interface OutputOptions {
1118
1130
  /**
1119
1131
  * The filename of the Hot Update Chunks. They are inside the output.path directory.
1120
1132
  */
1121
- hotUpdateChunkFilename?: string | Function;
1133
+ hotUpdateChunkFilename?: string;
1122
1134
  /**
1123
1135
  * The JSONP function used by webpack for async loading of hot update chunks.
1124
1136
  */
@@ -119,6 +119,7 @@ class ConstPlugin {
119
119
 
120
120
  const handler = parser => {
121
121
  parser.hooks.statementIf.tap("ConstPlugin", statement => {
122
+ if (parser.scope.isAsmJs) return;
122
123
  const param = parser.evaluateExpression(statement.test);
123
124
  const bool = param.asBool();
124
125
  if (typeof bool === "boolean") {
@@ -189,6 +190,7 @@ class ConstPlugin {
189
190
  parser.hooks.expressionConditionalOperator.tap(
190
191
  "ConstPlugin",
191
192
  expression => {
193
+ if (parser.scope.isAsmJs) return;
192
194
  const param = parser.evaluateExpression(expression.test);
193
195
  const bool = param.asBool();
194
196
  if (typeof bool === "boolean") {
@@ -224,6 +226,7 @@ class ConstPlugin {
224
226
  parser.hooks.expressionLogicalOperator.tap(
225
227
  "ConstPlugin",
226
228
  expression => {
229
+ if (parser.scope.isAsmJs) return;
227
230
  if (
228
231
  expression.operator === "&&" ||
229
232
  expression.operator === "||"
@@ -309,6 +312,7 @@ class ConstPlugin {
309
312
  parser.hooks.evaluateIdentifier
310
313
  .for("__resourceQuery")
311
314
  .tap("ConstPlugin", expr => {
315
+ if (parser.scope.isAsmJs) return;
312
316
  if (!parser.state.module) return;
313
317
  return ParserHelpers.evaluateToString(
314
318
  getQuery(parser.state.module.resource)
@@ -317,6 +321,7 @@ class ConstPlugin {
317
321
  parser.hooks.expression
318
322
  .for("__resourceQuery")
319
323
  .tap("ConstPlugin", () => {
324
+ if (parser.scope.isAsmJs) return;
320
325
  if (!parser.state.module) return;
321
326
  parser.state.current.addVariable(
322
327
  "__resourceQuery",
package/lib/DllPlugin.js CHANGED
@@ -5,8 +5,8 @@
5
5
  "use strict";
6
6
 
7
7
  const DllEntryPlugin = require("./DllEntryPlugin");
8
+ const FlagAllModulesAsUsedPlugin = require("./FlagAllModulesAsUsedPlugin");
8
9
  const LibManifestPlugin = require("./LibManifestPlugin");
9
- const FlagInitialModulesAsUsedPlugin = require("./FlagInitialModulesAsUsedPlugin");
10
10
 
11
11
  const validateOptions = require("schema-utils");
12
12
  const schema = require("../schemas/plugins/DllPlugin.json");
@@ -41,7 +41,7 @@ class DllPlugin {
41
41
  });
42
42
  new LibManifestPlugin(this.options).apply(compiler);
43
43
  if (!this.options.entryOnly) {
44
- new FlagInitialModulesAsUsedPlugin("DllPlugin").apply(compiler);
44
+ new FlagAllModulesAsUsedPlugin("DllPlugin").apply(compiler);
45
45
  }
46
46
  }
47
47
  }
@@ -0,0 +1,38 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+
6
+ "use strict";
7
+
8
+ /** @typedef {import("./Compiler")} Compiler */
9
+
10
+ class FlagAllModulesAsUsedPlugin {
11
+ constructor(explanation) {
12
+ this.explanation = explanation;
13
+ }
14
+
15
+ /**
16
+ * @param {Compiler} compiler webpack compiler
17
+ * @returns {void}
18
+ */
19
+ apply(compiler) {
20
+ compiler.hooks.compilation.tap(
21
+ "FlagAllModulesAsUsedPlugin",
22
+ compilation => {
23
+ compilation.hooks.optimizeDependencies.tap(
24
+ "FlagAllModulesAsUsedPlugin",
25
+ modules => {
26
+ for (const module of modules) {
27
+ module.used = true;
28
+ module.usedExports = true;
29
+ module.addReason(null, null, this.explanation);
30
+ }
31
+ }
32
+ );
33
+ }
34
+ );
35
+ }
36
+ }
37
+
38
+ module.exports = FlagAllModulesAsUsedPlugin;
@@ -93,7 +93,7 @@ class FlagDependencyUsagePlugin {
93
93
  };
94
94
 
95
95
  for (const module of modules) {
96
- module.used = false;
96
+ if (!module.used) module.used = false;
97
97
  }
98
98
 
99
99
  /** @type {[Module, DependenciesBlock, UsedExports][]} */
@@ -109,6 +109,7 @@ module.exports = function() {
109
109
  _declinedDependencies: {},
110
110
  _selfAccepted: false,
111
111
  _selfDeclined: false,
112
+ _selfInvalidated: false,
112
113
  _disposeHandlers: [],
113
114
  _main: hotCurrentChildModule !== moduleId,
114
115
 
@@ -139,6 +140,29 @@ module.exports = function() {
139
140
  var idx = hot._disposeHandlers.indexOf(callback);
140
141
  if (idx >= 0) hot._disposeHandlers.splice(idx, 1);
141
142
  },
143
+ invalidate: function() {
144
+ this._selfInvalidated = true;
145
+ switch (hotStatus) {
146
+ case "idle":
147
+ hotUpdate = {};
148
+ hotUpdate[moduleId] = modules[moduleId];
149
+ hotSetStatus("ready");
150
+ break;
151
+ case "ready":
152
+ hotApplyInvalidatedModule(moduleId);
153
+ break;
154
+ case "prepare":
155
+ case "check":
156
+ case "dispose":
157
+ case "apply":
158
+ (hotQueuedInvalidatedModules =
159
+ hotQueuedInvalidatedModules || []).push(moduleId);
160
+ break;
161
+ default:
162
+ // ignore requests in error states
163
+ break;
164
+ }
165
+ },
142
166
 
143
167
  // Management API
144
168
  check: hotCheck,
@@ -180,7 +204,7 @@ module.exports = function() {
180
204
  var hotDeferred;
181
205
 
182
206
  // The update info
183
- var hotUpdate, hotUpdateNewHash;
207
+ var hotUpdate, hotUpdateNewHash, hotQueuedInvalidatedModules;
184
208
 
185
209
  function toModuleId(id) {
186
210
  var isNumber = +id + "" === id;
@@ -195,7 +219,7 @@ module.exports = function() {
195
219
  hotSetStatus("check");
196
220
  return hotDownloadManifest(hotRequestTimeout).then(function(update) {
197
221
  if (!update) {
198
- hotSetStatus("idle");
222
+ hotSetStatus(hotApplyInvalidatedModules() ? "ready" : "idle");
199
223
  return null;
200
224
  }
201
225
  hotRequestedFilesMap = {};
@@ -288,6 +312,11 @@ module.exports = function() {
288
312
  if (hotStatus !== "ready")
289
313
  throw new Error("apply() is only allowed in ready status");
290
314
  options = options || {};
315
+ return hotApplyInternal(options);
316
+ }
317
+
318
+ function hotApplyInternal(options) {
319
+ hotApplyInvalidatedModules();
291
320
 
292
321
  var cb;
293
322
  var i;
@@ -310,7 +339,11 @@ module.exports = function() {
310
339
  var moduleId = queueItem.id;
311
340
  var chain = queueItem.chain;
312
341
  module = installedModules[moduleId];
313
- if (!module || module.hot._selfAccepted) continue;
342
+ if (
343
+ !module ||
344
+ (module.hot._selfAccepted && !module.hot._selfInvalidated)
345
+ )
346
+ continue;
314
347
  if (module.hot._selfDeclined) {
315
348
  return {
316
349
  type: "self-declined",
@@ -478,10 +511,13 @@ module.exports = function() {
478
511
  installedModules[moduleId] &&
479
512
  installedModules[moduleId].hot._selfAccepted &&
480
513
  // removed self-accepted modules should not be required
481
- appliedUpdate[moduleId] !== warnUnexpectedRequire
514
+ appliedUpdate[moduleId] !== warnUnexpectedRequire &&
515
+ // when called invalidate self-accepting is not possible
516
+ !installedModules[moduleId].hot._selfInvalidated
482
517
  ) {
483
518
  outdatedSelfAcceptedModules.push({
484
519
  module: moduleId,
520
+ parents: installedModules[moduleId].parents.slice(),
485
521
  errorHandler: installedModules[moduleId].hot._selfAccepted
486
522
  });
487
523
  }
@@ -554,7 +590,11 @@ module.exports = function() {
554
590
  // Now in "apply" phase
555
591
  hotSetStatus("apply");
556
592
 
557
- hotCurrentHash = hotUpdateNewHash;
593
+ if (hotUpdateNewHash !== undefined) {
594
+ hotCurrentHash = hotUpdateNewHash;
595
+ hotUpdateNewHash = undefined;
596
+ }
597
+ hotUpdate = undefined;
558
598
 
559
599
  // insert new code
560
600
  for (moduleId in appliedUpdate) {
@@ -607,7 +647,8 @@ module.exports = function() {
607
647
  for (i = 0; i < outdatedSelfAcceptedModules.length; i++) {
608
648
  var item = outdatedSelfAcceptedModules[i];
609
649
  moduleId = item.module;
610
- hotCurrentParents = [moduleId];
650
+ hotCurrentParents = item.parents;
651
+ hotCurrentChildModule = moduleId;
611
652
  try {
612
653
  $require$(moduleId);
613
654
  } catch (err) {
@@ -649,9 +690,32 @@ module.exports = function() {
649
690
  return Promise.reject(error);
650
691
  }
651
692
 
693
+ if (hotQueuedInvalidatedModules) {
694
+ return hotApplyInternal(options).then(function(list) {
695
+ outdatedModules.forEach(function(moduleId) {
696
+ if (list.indexOf(moduleId) < 0) list.push(moduleId);
697
+ });
698
+ return list;
699
+ });
700
+ }
701
+
652
702
  hotSetStatus("idle");
653
703
  return new Promise(function(resolve) {
654
704
  resolve(outdatedModules);
655
705
  });
656
706
  }
707
+
708
+ function hotApplyInvalidatedModules() {
709
+ if (hotQueuedInvalidatedModules) {
710
+ if (!hotUpdate) hotUpdate = {};
711
+ hotQueuedInvalidatedModules.forEach(hotApplyInvalidatedModule);
712
+ hotQueuedInvalidatedModules = undefined;
713
+ return true;
714
+ }
715
+ }
716
+
717
+ function hotApplyInvalidatedModule(moduleId) {
718
+ if (!Object.prototype.hasOwnProperty.call(hotUpdate, moduleId))
719
+ hotUpdate[moduleId] = modules[moduleId];
720
+ }
657
721
  };
package/lib/Parser.js CHANGED
@@ -1229,7 +1229,7 @@ class Parser extends Tapable {
1229
1229
  this.walkPattern(param);
1230
1230
  }
1231
1231
  if (statement.body.type === "BlockStatement") {
1232
- this.detectStrictMode(statement.body.body);
1232
+ this.detectMode(statement.body.body);
1233
1233
  this.prewalkStatement(statement.body);
1234
1234
  this.walkStatement(statement.body);
1235
1235
  } else {
@@ -1697,7 +1697,7 @@ class Parser extends Tapable {
1697
1697
  this.walkPattern(param);
1698
1698
  }
1699
1699
  if (expression.body.type === "BlockStatement") {
1700
- this.detectStrictMode(expression.body.body);
1700
+ this.detectMode(expression.body.body);
1701
1701
  this.prewalkStatement(expression.body);
1702
1702
  this.walkStatement(expression.body);
1703
1703
  } else {
@@ -1713,7 +1713,7 @@ class Parser extends Tapable {
1713
1713
  this.walkPattern(param);
1714
1714
  }
1715
1715
  if (expression.body.type === "BlockStatement") {
1716
- this.detectStrictMode(expression.body.body);
1716
+ this.detectMode(expression.body.body);
1717
1717
  this.prewalkStatement(expression.body);
1718
1718
  this.walkStatement(expression.body);
1719
1719
  } else {
@@ -1894,6 +1894,7 @@ class Parser extends Tapable {
1894
1894
  this.scope.renames.set(params[i].name, param);
1895
1895
  }
1896
1896
  if (functionExpression.body.type === "BlockStatement") {
1897
+ this.detectMode(functionExpression.body.body);
1897
1898
  this.prewalkStatement(functionExpression.body);
1898
1899
  this.walkStatement(functionExpression.body);
1899
1900
  } else {
@@ -2001,6 +2002,7 @@ class Parser extends Tapable {
2001
2002
  inTry: false,
2002
2003
  inShorthand: false,
2003
2004
  isStrict: oldScope.isStrict,
2005
+ isAsmJs: oldScope.isAsmJs,
2004
2006
  definitions: oldScope.definitions.createChild(),
2005
2007
  renames: oldScope.renames.createChild()
2006
2008
  };
@@ -2024,6 +2026,7 @@ class Parser extends Tapable {
2024
2026
  inTry: false,
2025
2027
  inShorthand: false,
2026
2028
  isStrict: oldScope.isStrict,
2029
+ isAsmJs: oldScope.isAsmJs,
2027
2030
  definitions: oldScope.definitions.createChild(),
2028
2031
  renames: oldScope.renames.createChild()
2029
2032
  };
@@ -2049,6 +2052,7 @@ class Parser extends Tapable {
2049
2052
  inTry: oldScope.inTry,
2050
2053
  inShorthand: false,
2051
2054
  isStrict: oldScope.isStrict,
2055
+ isAsmJs: oldScope.isAsmJs,
2052
2056
  definitions: oldScope.definitions.createChild(),
2053
2057
  renames: oldScope.renames.createChild()
2054
2058
  };
@@ -2058,15 +2062,23 @@ class Parser extends Tapable {
2058
2062
  this.scope = oldScope;
2059
2063
  }
2060
2064
 
2065
+ // TODO webpack 5: remove this methods
2066
+ // only for backward-compat
2061
2067
  detectStrictMode(statements) {
2062
- const isStrict =
2068
+ this.detectMode(statements);
2069
+ }
2070
+
2071
+ detectMode(statements) {
2072
+ const isLiteral =
2063
2073
  statements.length >= 1 &&
2064
2074
  statements[0].type === "ExpressionStatement" &&
2065
- statements[0].expression.type === "Literal" &&
2066
- statements[0].expression.value === "use strict";
2067
- if (isStrict) {
2075
+ statements[0].expression.type === "Literal";
2076
+ if (isLiteral && statements[0].expression.value === "use strict") {
2068
2077
  this.scope.isStrict = true;
2069
2078
  }
2079
+ if (isLiteral && statements[0].expression.value === "use asm") {
2080
+ this.scope.isAsmJs = true;
2081
+ }
2070
2082
  }
2071
2083
 
2072
2084
  enterPatterns(patterns, onIdent) {
@@ -2272,13 +2284,14 @@ class Parser extends Tapable {
2272
2284
  inTry: false,
2273
2285
  inShorthand: false,
2274
2286
  isStrict: false,
2287
+ isAsmJs: false,
2275
2288
  definitions: new StackedSetMap(),
2276
2289
  renames: new StackedSetMap()
2277
2290
  };
2278
2291
  const state = (this.state = initialState || {});
2279
2292
  this.comments = comments;
2280
2293
  if (this.hooks.program.call(ast, comments) === undefined) {
2281
- this.detectStrictMode(ast.body);
2294
+ this.detectMode(ast.body);
2282
2295
  this.prewalkStatements(ast.body);
2283
2296
  this.blockPrewalkStatements(ast.body);
2284
2297
  this.walkStatements(ast.body);
@@ -129,28 +129,34 @@ class RecordIdsPlugin {
129
129
  const sources = [];
130
130
  for (const chunkGroup of chunk.groupsIterable) {
131
131
  const index = chunkGroup.chunks.indexOf(chunk);
132
- for (const origin of chunkGroup.origins) {
133
- if (origin.module) {
134
- if (origin.request) {
135
- sources.push(
136
- `${index} ${getModuleIdentifier(origin.module)} ${
137
- origin.request
138
- }`
139
- );
140
- } else if (typeof origin.loc === "string") {
141
- sources.push(
142
- `${index} ${getModuleIdentifier(origin.module)} ${origin.loc}`
143
- );
144
- } else if (
145
- origin.loc &&
146
- typeof origin.loc === "object" &&
147
- origin.loc.start
148
- ) {
149
- sources.push(
150
- `${index} ${getModuleIdentifier(
151
- origin.module
152
- )} ${JSON.stringify(origin.loc.start)}`
153
- );
132
+ if (chunkGroup.name) {
133
+ sources.push(`${index} ${chunkGroup.name}`);
134
+ } else {
135
+ for (const origin of chunkGroup.origins) {
136
+ if (origin.module) {
137
+ if (origin.request) {
138
+ sources.push(
139
+ `${index} ${getModuleIdentifier(origin.module)} ${
140
+ origin.request
141
+ }`
142
+ );
143
+ } else if (typeof origin.loc === "string") {
144
+ sources.push(
145
+ `${index} ${getModuleIdentifier(origin.module)} ${
146
+ origin.loc
147
+ }`
148
+ );
149
+ } else if (
150
+ origin.loc &&
151
+ typeof origin.loc === "object" &&
152
+ origin.loc.start
153
+ ) {
154
+ sources.push(
155
+ `${index} ${getModuleIdentifier(
156
+ origin.module
157
+ )} ${JSON.stringify(origin.loc.start)}`
158
+ );
159
+ }
154
160
  }
155
161
  }
156
162
  }
@@ -362,6 +362,7 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
362
362
  this.set("resolveLoader.mainFields", ["loader", "main"]);
363
363
  this.set("resolveLoader.extensions", [".js", ".json"]);
364
364
  this.set("resolveLoader.mainFiles", ["index"]);
365
+ this.set("resolveLoader.roots", "make", options => [options.context]);
365
366
  this.set("resolveLoader.cacheWithContext", "make", options => {
366
367
  return (
367
368
  Array.isArray(options.resolveLoader.plugins) &&
@@ -27,6 +27,8 @@ class ExportMode {
27
27
  this.name = null;
28
28
  /** @type {Map<string, string>} */
29
29
  this.map = EMPTY_MAP;
30
+ /** @type {Set<string>|null} */
31
+ this.ignored = null;
30
32
  /** @type {Module|null} */
31
33
  this.module = null;
32
34
  /** @type {string|null} */
@@ -212,6 +214,10 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
212
214
 
213
215
  const mode = new ExportMode("dynamic-reexport");
214
216
  mode.module = importedModule;
217
+ mode.ignored = new Set([
218
+ ...this.activeExports,
219
+ ...activeFromOtherStarExports
220
+ ]);
215
221
  return mode;
216
222
  }
217
223
 
@@ -580,10 +586,7 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
580
586
  .join("");
581
587
 
582
588
  case "dynamic-reexport": {
583
- const activeExports = new Set([
584
- ...dep.activeExports,
585
- ...dep._discoverActiveExportsFromOtherStartExports()
586
- ]);
589
+ const activeExports = mode.ignored;
587
590
  let content =
588
591
  "/* harmony reexport (unknown) */ for(var __WEBPACK_IMPORT_KEY__ in " +
589
592
  importVar +