webpack 5.77.0 → 5.79.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.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (82) hide show
  1. package/bin/webpack.js +0 -0
  2. package/lib/APIPlugin.js +25 -18
  3. package/lib/CompatibilityPlugin.js +80 -62
  4. package/lib/Compiler.js +7 -4
  5. package/lib/ConstPlugin.js +22 -15
  6. package/lib/ContextModule.js +3 -2
  7. package/lib/DefinePlugin.js +62 -42
  8. package/lib/DelegatedModule.js +2 -1
  9. package/lib/DllModule.js +2 -1
  10. package/lib/ErrorHelpers.js +61 -22
  11. package/lib/ExportsInfoApiPlugin.js +16 -9
  12. package/lib/ExternalModule.js +2 -1
  13. package/lib/FlagAllModulesAsUsedPlugin.js +22 -27
  14. package/lib/FlagDependencyExportsPlugin.js +336 -348
  15. package/lib/FlagDependencyUsagePlugin.js +6 -8
  16. package/lib/FlagEntryExportAsUsedPlugin.js +22 -23
  17. package/lib/HotModuleReplacementPlugin.js +50 -45
  18. package/lib/JavascriptMetaInfoPlugin.js +16 -9
  19. package/lib/LibManifestPlugin.js +2 -1
  20. package/lib/ModuleTypeConstants.js +50 -0
  21. package/lib/NodeStuffPlugin.js +35 -31
  22. package/lib/NormalModule.js +2 -1
  23. package/lib/NormalModuleFactory.js +7 -1
  24. package/lib/NormalModuleReplacementPlugin.js +1 -1
  25. package/lib/ProvidePlugin.js +17 -10
  26. package/lib/RawModule.js +2 -1
  27. package/lib/RequireJsStuffPlugin.js +15 -15
  28. package/lib/UseStrictPlugin.js +15 -8
  29. package/lib/WebpackIsIncludedPlugin.js +16 -9
  30. package/lib/config/defaults.js +16 -8
  31. package/lib/config/normalization.js +4 -0
  32. package/lib/container/ContainerEntryModule.js +2 -1
  33. package/lib/css/CssLoadingRuntimeModule.js +1 -1
  34. package/lib/css/CssParser.js +28 -8
  35. package/lib/css/walkCssTokens.js +6 -1
  36. package/lib/debug/ProfilingPlugin.js +20 -12
  37. package/lib/dependencies/AMDPlugin.js +26 -20
  38. package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -4
  39. package/lib/dependencies/CommonJsPlugin.js +29 -25
  40. package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -1
  41. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +4 -0
  42. package/lib/dependencies/HarmonyImportSpecifierDependency.js +28 -3
  43. package/lib/dependencies/HarmonyModulesPlugin.js +11 -5
  44. package/lib/dependencies/ImportMetaContextPlugin.js +11 -5
  45. package/lib/dependencies/ImportMetaPlugin.js +26 -20
  46. package/lib/dependencies/ImportPlugin.js +14 -7
  47. package/lib/dependencies/RequireContextPlugin.js +12 -6
  48. package/lib/dependencies/RequireEnsurePlugin.js +13 -7
  49. package/lib/dependencies/RequireIncludePlugin.js +11 -5
  50. package/lib/dependencies/SystemPlugin.js +21 -15
  51. package/lib/dependencies/URLPlugin.js +15 -9
  52. package/lib/dependencies/WorkerPlugin.js +14 -8
  53. package/lib/index.js +5 -0
  54. package/lib/javascript/JavascriptModulesPlugin.js +157 -164
  55. package/lib/javascript/JavascriptParser.js +88 -0
  56. package/lib/json/JsonModulesPlugin.js +13 -5
  57. package/lib/library/AmdLibraryPlugin.js +22 -6
  58. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -1
  59. package/lib/node/ReadFileCompileWasmPlugin.js +2 -1
  60. package/lib/optimize/ConcatenatedModule.js +2 -1
  61. package/lib/optimize/InnerGraphPlugin.js +47 -46
  62. package/lib/optimize/SideEffectsFlagPlugin.js +43 -43
  63. package/lib/sharing/ConsumeSharedPlugin.js +4 -0
  64. package/lib/stats/DefaultStatsPrinterPlugin.js +14 -0
  65. package/lib/util/hash/md4.js +2 -2
  66. package/lib/util/hash/xxhash64.js +1 -1
  67. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +9 -6
  68. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +42 -43
  69. package/lib/web/FetchCompileAsyncWasmPlugin.js +2 -1
  70. package/lib/web/FetchCompileWasmPlugin.js +40 -40
  71. package/lib/webpack.js +1 -1
  72. package/package.json +41 -36
  73. package/schemas/WebpackOptions.check.js +1 -1
  74. package/schemas/WebpackOptions.json +18 -0
  75. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  76. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  77. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  78. package/schemas/plugins/container/ContainerPlugin.json +8 -0
  79. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  80. package/schemas/plugins/container/ModuleFederationPlugin.json +8 -0
  81. package/schemas/plugins/sharing/SharePlugin.check.js +1 -1
  82. package/types.d.ts +152 -122
@@ -5,10 +5,16 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const {
9
+ JAVASCRIPT_MODULE_TYPE_AUTO,
10
+ JAVASCRIPT_MODULE_TYPE_ESM,
11
+ JAVASCRIPT_MODULE_TYPE_DYNAMIC
12
+ } = require("./ModuleTypeConstants");
8
13
  const RuntimeGlobals = require("./RuntimeGlobals");
9
14
  const WebpackError = require("./WebpackError");
10
15
  const ConstDependency = require("./dependencies/ConstDependency");
11
16
  const BasicEvaluatedExpression = require("./javascript/BasicEvaluatedExpression");
17
+
12
18
  const {
13
19
  evaluateToString,
14
20
  toConstantDependency
@@ -112,6 +118,7 @@ class RuntimeValue {
112
118
  * @param {string} key the defined key
113
119
  * @param {RuntimeTemplate} runtimeTemplate the runtime template
114
120
  * @param {boolean|undefined|null=} asiSafe asi safe (undefined: unknown, null: unneeded)
121
+ * @param {Set<string>|undefined=} objKeys used keys
115
122
  * @returns {string} code converted to string that evaluates
116
123
  */
117
124
  const stringifyObj = (
@@ -120,7 +127,8 @@ const stringifyObj = (
120
127
  valueCacheVersions,
121
128
  key,
122
129
  runtimeTemplate,
123
- asiSafe
130
+ asiSafe,
131
+ objKeys
124
132
  ) => {
125
133
  let code;
126
134
  let arr = Array.isArray(obj);
@@ -131,7 +139,12 @@ const stringifyObj = (
131
139
  )
132
140
  .join(",")}]`;
133
141
  } else {
134
- code = `{${Object.keys(obj)
142
+ let keys = Object.keys(obj);
143
+ if (objKeys) {
144
+ if (objKeys.size === 0) keys = [];
145
+ else keys = keys.filter(k => objKeys.has(k));
146
+ }
147
+ code = `{${keys
135
148
  .map(key => {
136
149
  const code = obj[key];
137
150
  return (
@@ -163,6 +176,7 @@ const stringifyObj = (
163
176
  * @param {string} key the defined key
164
177
  * @param {RuntimeTemplate} runtimeTemplate the runtime template
165
178
  * @param {boolean|undefined|null=} asiSafe asi safe (undefined: unknown, null: unneeded)
179
+ * @param {Set<string>|undefined=} objKeys used keys
166
180
  * @returns {string} code converted to string that evaluates
167
181
  */
168
182
  const toCode = (
@@ -171,7 +185,8 @@ const toCode = (
171
185
  valueCacheVersions,
172
186
  key,
173
187
  runtimeTemplate,
174
- asiSafe
188
+ asiSafe,
189
+ objKeys
175
190
  ) => {
176
191
  if (code === null) {
177
192
  return "null";
@@ -205,7 +220,8 @@ const toCode = (
205
220
  valueCacheVersions,
206
221
  key,
207
222
  runtimeTemplate,
208
- asiSafe
223
+ asiSafe,
224
+ objKeys
209
225
  );
210
226
  }
211
227
  if (typeof code === "bigint") {
@@ -249,8 +265,12 @@ const toCacheVersion = code => {
249
265
  return code + "";
250
266
  };
251
267
 
252
- const VALUE_DEP_PREFIX = "webpack/DefinePlugin ";
253
- const VALUE_DEP_MAIN = "webpack/DefinePlugin_hash";
268
+ const PLUGIN_NAME = "DefinePlugin";
269
+ const VALUE_DEP_PREFIX = `webpack/${PLUGIN_NAME} `;
270
+ const VALUE_DEP_MAIN = `webpack/${PLUGIN_NAME}_hash`;
271
+ const TYPEOF_OPERATOR_REGEXP = /^typeof\s+/;
272
+ const WEBPACK_REQUIRE_FUNCTION_REGEXP = /__webpack_require__\s*(!?\.)/;
273
+ const WEBPACK_REQUIRE_IDENTIFIER_REGEXP = /__webpack_require__/;
254
274
 
255
275
  class DefinePlugin {
256
276
  /**
@@ -278,7 +298,7 @@ class DefinePlugin {
278
298
  apply(compiler) {
279
299
  const definitions = this.definitions;
280
300
  compiler.hooks.compilation.tap(
281
- "DefinePlugin",
301
+ PLUGIN_NAME,
282
302
  (compilation, { normalModuleFactory }) => {
283
303
  compilation.dependencyTemplates.set(
284
304
  ConstDependency,
@@ -300,7 +320,7 @@ class DefinePlugin {
300
320
  */
301
321
  const handler = parser => {
302
322
  const mainValue = compilation.valueCacheVersions.get(VALUE_DEP_MAIN);
303
- parser.hooks.program.tap("DefinePlugin", () => {
323
+ parser.hooks.program.tap(PLUGIN_NAME, () => {
304
324
  const { buildInfo } = parser.state.module;
305
325
  if (!buildInfo.valueDependencies)
306
326
  buildInfo.valueDependencies = new Map();
@@ -356,7 +376,7 @@ class DefinePlugin {
356
376
  const splittedKey = key.split(".");
357
377
  splittedKey.slice(1).forEach((_, i) => {
358
378
  const fullKey = prefix + splittedKey.slice(0, i + 1).join(".");
359
- parser.hooks.canRename.for(fullKey).tap("DefinePlugin", () => {
379
+ parser.hooks.canRename.for(fullKey).tap(PLUGIN_NAME, () => {
360
380
  addValueDependency(key);
361
381
  return true;
362
382
  });
@@ -371,18 +391,18 @@ class DefinePlugin {
371
391
  */
372
392
  const applyDefine = (key, code) => {
373
393
  const originalKey = key;
374
- const isTypeof = /^typeof\s+/.test(key);
375
- if (isTypeof) key = key.replace(/^typeof\s+/, "");
394
+ const isTypeof = TYPEOF_OPERATOR_REGEXP.test(key);
395
+ if (isTypeof) key = key.replace(TYPEOF_OPERATOR_REGEXP, "");
376
396
  let recurse = false;
377
397
  let recurseTypeof = false;
378
398
  if (!isTypeof) {
379
- parser.hooks.canRename.for(key).tap("DefinePlugin", () => {
399
+ parser.hooks.canRename.for(key).tap(PLUGIN_NAME, () => {
380
400
  addValueDependency(originalKey);
381
401
  return true;
382
402
  });
383
403
  parser.hooks.evaluateIdentifier
384
404
  .for(key)
385
- .tap("DefinePlugin", expr => {
405
+ .tap(PLUGIN_NAME, expr => {
386
406
  /**
387
407
  * this is needed in case there is a recursion in the DefinePlugin
388
408
  * to prevent an endless recursion
@@ -408,7 +428,7 @@ class DefinePlugin {
408
428
  res.setRange(expr.range);
409
429
  return res;
410
430
  });
411
- parser.hooks.expression.for(key).tap("DefinePlugin", expr => {
431
+ parser.hooks.expression.for(key).tap(PLUGIN_NAME, expr => {
412
432
  addValueDependency(originalKey);
413
433
  const strCode = toCode(
414
434
  code,
@@ -416,13 +436,14 @@ class DefinePlugin {
416
436
  compilation.valueCacheVersions,
417
437
  originalKey,
418
438
  runtimeTemplate,
419
- !parser.isAsiPosition(expr.range[0])
439
+ !parser.isAsiPosition(expr.range[0]),
440
+ parser.destructuringAssignmentPropertiesFor(expr)
420
441
  );
421
- if (/__webpack_require__\s*(!?\.)/.test(strCode)) {
442
+ if (WEBPACK_REQUIRE_FUNCTION_REGEXP.test(strCode)) {
422
443
  return toConstantDependency(parser, strCode, [
423
444
  RuntimeGlobals.require
424
445
  ])(expr);
425
- } else if (/__webpack_require__/.test(strCode)) {
446
+ } else if (WEBPACK_REQUIRE_IDENTIFIER_REGEXP.test(strCode)) {
426
447
  return toConstantDependency(parser, strCode, [
427
448
  RuntimeGlobals.requireScope
428
449
  ])(expr);
@@ -431,7 +452,7 @@ class DefinePlugin {
431
452
  }
432
453
  });
433
454
  }
434
- parser.hooks.evaluateTypeof.for(key).tap("DefinePlugin", expr => {
455
+ parser.hooks.evaluateTypeof.for(key).tap(PLUGIN_NAME, expr => {
435
456
  /**
436
457
  * this is needed in case there is a recursion in the DefinePlugin
437
458
  * to prevent an endless recursion
@@ -459,7 +480,7 @@ class DefinePlugin {
459
480
  res.setRange(expr.range);
460
481
  return res;
461
482
  });
462
- parser.hooks.typeof.for(key).tap("DefinePlugin", expr => {
483
+ parser.hooks.typeof.for(key).tap(PLUGIN_NAME, expr => {
463
484
  addValueDependency(originalKey);
464
485
  const codeCode = toCode(
465
486
  code,
@@ -488,26 +509,24 @@ class DefinePlugin {
488
509
  * @returns {void}
489
510
  */
490
511
  const applyObjectDefine = (key, obj) => {
491
- parser.hooks.canRename.for(key).tap("DefinePlugin", () => {
512
+ parser.hooks.canRename.for(key).tap(PLUGIN_NAME, () => {
492
513
  addValueDependency(key);
493
514
  return true;
494
515
  });
495
- parser.hooks.evaluateIdentifier
496
- .for(key)
497
- .tap("DefinePlugin", expr => {
498
- addValueDependency(key);
499
- return new BasicEvaluatedExpression()
500
- .setTruthy()
501
- .setSideEffects(false)
502
- .setRange(expr.range);
503
- });
516
+ parser.hooks.evaluateIdentifier.for(key).tap(PLUGIN_NAME, expr => {
517
+ addValueDependency(key);
518
+ return new BasicEvaluatedExpression()
519
+ .setTruthy()
520
+ .setSideEffects(false)
521
+ .setRange(expr.range);
522
+ });
504
523
  parser.hooks.evaluateTypeof
505
524
  .for(key)
506
525
  .tap(
507
- "DefinePlugin",
526
+ PLUGIN_NAME,
508
527
  withValueDependency(key, evaluateToString("object"))
509
528
  );
510
- parser.hooks.expression.for(key).tap("DefinePlugin", expr => {
529
+ parser.hooks.expression.for(key).tap(PLUGIN_NAME, expr => {
511
530
  addValueDependency(key);
512
531
  const strCode = stringifyObj(
513
532
  obj,
@@ -515,14 +534,15 @@ class DefinePlugin {
515
534
  compilation.valueCacheVersions,
516
535
  key,
517
536
  runtimeTemplate,
518
- !parser.isAsiPosition(expr.range[0])
537
+ !parser.isAsiPosition(expr.range[0]),
538
+ parser.destructuringAssignmentPropertiesFor(expr)
519
539
  );
520
540
 
521
- if (/__webpack_require__\s*(!?\.)/.test(strCode)) {
541
+ if (WEBPACK_REQUIRE_FUNCTION_REGEXP.test(strCode)) {
522
542
  return toConstantDependency(parser, strCode, [
523
543
  RuntimeGlobals.require
524
544
  ])(expr);
525
- } else if (/__webpack_require__/.test(strCode)) {
545
+ } else if (WEBPACK_REQUIRE_IDENTIFIER_REGEXP.test(strCode)) {
526
546
  return toConstantDependency(parser, strCode, [
527
547
  RuntimeGlobals.requireScope
528
548
  ])(expr);
@@ -533,7 +553,7 @@ class DefinePlugin {
533
553
  parser.hooks.typeof
534
554
  .for(key)
535
555
  .tap(
536
- "DefinePlugin",
556
+ PLUGIN_NAME,
537
557
  withValueDependency(
538
558
  key,
539
559
  toConstantDependency(parser, JSON.stringify("object"))
@@ -545,14 +565,14 @@ class DefinePlugin {
545
565
  };
546
566
 
547
567
  normalModuleFactory.hooks.parser
548
- .for("javascript/auto")
549
- .tap("DefinePlugin", handler);
568
+ .for(JAVASCRIPT_MODULE_TYPE_AUTO)
569
+ .tap(PLUGIN_NAME, handler);
550
570
  normalModuleFactory.hooks.parser
551
- .for("javascript/dynamic")
552
- .tap("DefinePlugin", handler);
571
+ .for(JAVASCRIPT_MODULE_TYPE_DYNAMIC)
572
+ .tap(PLUGIN_NAME, handler);
553
573
  normalModuleFactory.hooks.parser
554
- .for("javascript/esm")
555
- .tap("DefinePlugin", handler);
574
+ .for(JAVASCRIPT_MODULE_TYPE_ESM)
575
+ .tap(PLUGIN_NAME, handler);
556
576
 
557
577
  /**
558
578
  * Walk definitions
@@ -571,7 +591,7 @@ class DefinePlugin {
571
591
  compilation.valueCacheVersions.set(name, version);
572
592
  } else if (oldVersion !== version) {
573
593
  const warning = new WebpackError(
574
- `DefinePlugin\nConflicting values for '${prefix + key}'`
594
+ `${PLUGIN_NAME}\nConflicting values for '${prefix + key}'`
575
595
  );
576
596
  warning.details = `'${oldVersion}' !== '${version}'`;
577
597
  warning.hideStack = true;
@@ -7,6 +7,7 @@
7
7
 
8
8
  const { OriginalSource, RawSource } = require("webpack-sources");
9
9
  const Module = require("./Module");
10
+ const { JAVASCRIPT_MODULE_TYPE_DYNAMIC } = require("./ModuleTypeConstants");
10
11
  const RuntimeGlobals = require("./RuntimeGlobals");
11
12
  const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
12
13
  const StaticExportsDependency = require("./dependencies/StaticExportsDependency");
@@ -40,7 +41,7 @@ const RUNTIME_REQUIREMENTS = new Set([
40
41
 
41
42
  class DelegatedModule extends Module {
42
43
  constructor(sourceRequest, data, type, userRequest, originalRequest) {
43
- super("javascript/dynamic", null);
44
+ super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, null);
44
45
 
45
46
  // Info from Factory
46
47
  this.sourceRequest = sourceRequest;
package/lib/DllModule.js CHANGED
@@ -7,6 +7,7 @@
7
7
 
8
8
  const { RawSource } = require("webpack-sources");
9
9
  const Module = require("./Module");
10
+ const { JAVASCRIPT_MODULE_TYPE_DYNAMIC } = require("./ModuleTypeConstants");
10
11
  const RuntimeGlobals = require("./RuntimeGlobals");
11
12
  const makeSerializable = require("./util/makeSerializable");
12
13
 
@@ -35,7 +36,7 @@ const RUNTIME_REQUIREMENTS = new Set([
35
36
 
36
37
  class DllModule extends Module {
37
38
  constructor(context, dependencies, name) {
38
- super("javascript/dynamic", context);
39
+ super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, context);
39
40
 
40
41
  // Info from Factory
41
42
  this.dependencies = dependencies;
@@ -9,36 +9,57 @@ const loaderFlag = "LOADER_EXECUTION";
9
9
 
10
10
  const webpackOptionsFlag = "WEBPACK_OPTIONS";
11
11
 
12
- exports.cutOffByFlag = (stack, flag) => {
13
- stack = stack.split("\n");
14
- for (let i = 0; i < stack.length; i++) {
15
- if (stack[i].includes(flag)) {
16
- stack.length = i;
12
+ /**
13
+ * @param {string} stack stack trace
14
+ * @param {string} flag flag to cut off
15
+ * @returns {string} stack trace without the specified flag included
16
+ */
17
+ const cutOffByFlag = (stack, flag) => {
18
+ const errorStack = stack.split("\n");
19
+ for (let i = 0; i < errorStack.length; i++) {
20
+ if (errorStack[i].includes(flag)) {
21
+ errorStack.length = i;
17
22
  }
18
23
  }
19
- return stack.join("\n");
24
+ return errorStack.join("\n");
20
25
  };
21
26
 
22
- exports.cutOffLoaderExecution = stack =>
23
- exports.cutOffByFlag(stack, loaderFlag);
27
+ /**
28
+ * @param {string} stack stack trace
29
+ * @returns {string} stack trace without the loader execution flag included
30
+ */
31
+ const cutOffLoaderExecution = stack => cutOffByFlag(stack, loaderFlag);
24
32
 
25
- exports.cutOffWebpackOptions = stack =>
26
- exports.cutOffByFlag(stack, webpackOptionsFlag);
33
+ /**
34
+ * @param {string} stack stack trace
35
+ * @returns {string} stack trace without the webpack options flag included
36
+ */
37
+ const cutOffWebpackOptions = stack => cutOffByFlag(stack, webpackOptionsFlag);
27
38
 
28
- exports.cutOffMultilineMessage = (stack, message) => {
29
- stack = stack.split("\n");
30
- message = message.split("\n");
39
+ /**
40
+ * @param {string} stack stack trace
41
+ * @param {string} message error message
42
+ * @returns {string} stack trace without the message included
43
+ */
44
+ const cutOffMultilineMessage = (stack, message) => {
45
+ const stackSplitByLines = stack.split("\n");
46
+ const messageSplitByLines = message.split("\n");
31
47
 
32
48
  const result = [];
33
49
 
34
- stack.forEach((line, idx) => {
35
- if (!line.includes(message[idx])) result.push(line);
50
+ stackSplitByLines.forEach((line, idx) => {
51
+ if (!line.includes(messageSplitByLines[idx])) result.push(line);
36
52
  });
37
53
 
38
54
  return result.join("\n");
39
55
  };
40
56
 
41
- exports.cutOffMessage = (stack, message) => {
57
+ /**
58
+ * @param {string} stack stack trace
59
+ * @param {string} message error message
60
+ * @returns {string} stack trace without the message included
61
+ */
62
+ const cutOffMessage = (stack, message) => {
42
63
  const nextLine = stack.indexOf("\n");
43
64
  if (nextLine === -1) {
44
65
  return stack === message ? "" : stack;
@@ -48,14 +69,32 @@ exports.cutOffMessage = (stack, message) => {
48
69
  }
49
70
  };
50
71
 
51
- exports.cleanUp = (stack, message) => {
52
- stack = exports.cutOffLoaderExecution(stack);
53
- stack = exports.cutOffMessage(stack, message);
72
+ /**
73
+ * @param {string} stack stack trace
74
+ * @param {string} message error message
75
+ * @returns {string} stack trace without the loader execution flag and message included
76
+ */
77
+ const cleanUp = (stack, message) => {
78
+ stack = cutOffLoaderExecution(stack);
79
+ stack = cutOffMessage(stack, message);
54
80
  return stack;
55
81
  };
56
82
 
57
- exports.cleanUpWebpackOptions = (stack, message) => {
58
- stack = exports.cutOffWebpackOptions(stack);
59
- stack = exports.cutOffMultilineMessage(stack, message);
83
+ /**
84
+ * @param {string} stack stack trace
85
+ * @param {string} message error message
86
+ * @returns {string} stack trace without the webpack options flag and message included
87
+ */
88
+ const cleanUpWebpackOptions = (stack, message) => {
89
+ stack = cutOffWebpackOptions(stack);
90
+ stack = cutOffMultilineMessage(stack, message);
60
91
  return stack;
61
92
  };
93
+
94
+ exports.cutOffByFlag = cutOffByFlag;
95
+ exports.cutOffLoaderExecution = cutOffLoaderExecution;
96
+ exports.cutOffWebpackOptions = cutOffWebpackOptions;
97
+ exports.cutOffMultilineMessage = cutOffMultilineMessage;
98
+ exports.cutOffMessage = cutOffMessage;
99
+ exports.cleanUp = cleanUp;
100
+ exports.cleanUpWebpackOptions = cleanUpWebpackOptions;
@@ -5,12 +5,19 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const {
9
+ JAVASCRIPT_MODULE_TYPE_AUTO,
10
+ JAVASCRIPT_MODULE_TYPE_DYNAMIC,
11
+ JAVASCRIPT_MODULE_TYPE_ESM
12
+ } = require("./ModuleTypeConstants");
8
13
  const ConstDependency = require("./dependencies/ConstDependency");
9
14
  const ExportsInfoDependency = require("./dependencies/ExportsInfoDependency");
10
15
 
11
16
  /** @typedef {import("./Compiler")} Compiler */
12
17
  /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
13
18
 
19
+ const PLUGIN_NAME = "ExportsInfoApiPlugin";
20
+
14
21
  class ExportsInfoApiPlugin {
15
22
  /**
16
23
  * Apply the plugin
@@ -19,7 +26,7 @@ class ExportsInfoApiPlugin {
19
26
  */
20
27
  apply(compiler) {
21
28
  compiler.hooks.compilation.tap(
22
- "ExportsInfoApiPlugin",
29
+ PLUGIN_NAME,
23
30
  (compilation, { normalModuleFactory }) => {
24
31
  compilation.dependencyTemplates.set(
25
32
  ExportsInfoDependency,
@@ -32,7 +39,7 @@ class ExportsInfoApiPlugin {
32
39
  const handler = parser => {
33
40
  parser.hooks.expressionMemberChain
34
41
  .for("__webpack_exports_info__")
35
- .tap("ExportsInfoApiPlugin", (expr, members) => {
42
+ .tap(PLUGIN_NAME, (expr, members) => {
36
43
  const dep =
37
44
  members.length >= 2
38
45
  ? new ExportsInfoDependency(
@@ -47,7 +54,7 @@ class ExportsInfoApiPlugin {
47
54
  });
48
55
  parser.hooks.expression
49
56
  .for("__webpack_exports_info__")
50
- .tap("ExportsInfoApiPlugin", expr => {
57
+ .tap(PLUGIN_NAME, expr => {
51
58
  const dep = new ConstDependency("true", expr.range);
52
59
  dep.loc = expr.loc;
53
60
  parser.state.module.addPresentationalDependency(dep);
@@ -55,14 +62,14 @@ class ExportsInfoApiPlugin {
55
62
  });
56
63
  };
57
64
  normalModuleFactory.hooks.parser
58
- .for("javascript/auto")
59
- .tap("ExportsInfoApiPlugin", handler);
65
+ .for(JAVASCRIPT_MODULE_TYPE_AUTO)
66
+ .tap(PLUGIN_NAME, handler);
60
67
  normalModuleFactory.hooks.parser
61
- .for("javascript/dynamic")
62
- .tap("ExportsInfoApiPlugin", handler);
68
+ .for(JAVASCRIPT_MODULE_TYPE_DYNAMIC)
69
+ .tap(PLUGIN_NAME, handler);
63
70
  normalModuleFactory.hooks.parser
64
- .for("javascript/esm")
65
- .tap("ExportsInfoApiPlugin", handler);
71
+ .for(JAVASCRIPT_MODULE_TYPE_ESM)
72
+ .tap(PLUGIN_NAME, handler);
66
73
  }
67
74
  );
68
75
  }
@@ -10,6 +10,7 @@ const ConcatenationScope = require("./ConcatenationScope");
10
10
  const { UsageState } = require("./ExportsInfo");
11
11
  const InitFragment = require("./InitFragment");
12
12
  const Module = require("./Module");
13
+ const { JAVASCRIPT_MODULE_TYPE_DYNAMIC } = require("./ModuleTypeConstants");
13
14
  const RuntimeGlobals = require("./RuntimeGlobals");
14
15
  const Template = require("./Template");
15
16
  const StaticExportsDependency = require("./dependencies/StaticExportsDependency");
@@ -378,7 +379,7 @@ const getSourceForDefaultCase = (optional, request, runtimeTemplate) => {
378
379
 
379
380
  class ExternalModule extends Module {
380
381
  constructor(request, type, userRequest) {
381
- super("javascript/dynamic", null);
382
+ super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, null);
382
383
 
383
384
  // Info from Factory
384
385
  /** @type {string | string[] | Record<string, string | string[]>} */
@@ -10,6 +10,7 @@ const { getEntryRuntime, mergeRuntimeOwned } = require("./util/runtime");
10
10
  /** @typedef {import("./Compiler")} Compiler */
11
11
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
12
12
 
13
+ const PLUGIN_NAME = "FlagAllModulesAsUsedPlugin";
13
14
  class FlagAllModulesAsUsedPlugin {
14
15
  constructor(explanation) {
15
16
  this.explanation = explanation;
@@ -21,34 +22,28 @@ class FlagAllModulesAsUsedPlugin {
21
22
  * @returns {void}
22
23
  */
23
24
  apply(compiler) {
24
- compiler.hooks.compilation.tap(
25
- "FlagAllModulesAsUsedPlugin",
26
- compilation => {
27
- const moduleGraph = compilation.moduleGraph;
28
- compilation.hooks.optimizeDependencies.tap(
29
- "FlagAllModulesAsUsedPlugin",
30
- modules => {
31
- /** @type {RuntimeSpec} */
32
- let runtime = undefined;
33
- for (const [name, { options }] of compilation.entries) {
34
- runtime = mergeRuntimeOwned(
35
- runtime,
36
- getEntryRuntime(compilation, name, options)
37
- );
38
- }
39
- for (const module of modules) {
40
- const exportsInfo = moduleGraph.getExportsInfo(module);
41
- exportsInfo.setUsedInUnknownWay(runtime);
42
- moduleGraph.addExtraReason(module, this.explanation);
43
- if (module.factoryMeta === undefined) {
44
- module.factoryMeta = {};
45
- }
46
- module.factoryMeta.sideEffectFree = false;
47
- }
25
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
26
+ const moduleGraph = compilation.moduleGraph;
27
+ compilation.hooks.optimizeDependencies.tap(PLUGIN_NAME, modules => {
28
+ /** @type {RuntimeSpec} */
29
+ let runtime = undefined;
30
+ for (const [name, { options }] of compilation.entries) {
31
+ runtime = mergeRuntimeOwned(
32
+ runtime,
33
+ getEntryRuntime(compilation, name, options)
34
+ );
35
+ }
36
+ for (const module of modules) {
37
+ const exportsInfo = moduleGraph.getExportsInfo(module);
38
+ exportsInfo.setUsedInUnknownWay(runtime);
39
+ moduleGraph.addExtraReason(module, this.explanation);
40
+ if (module.factoryMeta === undefined) {
41
+ module.factoryMeta = {};
48
42
  }
49
- );
50
- }
51
- );
43
+ module.factoryMeta.sideEffectFree = false;
44
+ }
45
+ });
46
+ });
52
47
  }
53
48
  }
54
49