webpack 4.10.1 → 4.12.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.
Files changed (118) hide show
  1. package/lib/AmdMainTemplatePlugin.js +3 -1
  2. package/lib/AsyncDependencyToInitialChunkError.js +4 -4
  3. package/lib/BannerPlugin.js +3 -1
  4. package/lib/BasicEvaluatedExpression.js +14 -11
  5. package/lib/CachePlugin.js +12 -5
  6. package/lib/CaseSensitiveModulesWarning.js +41 -45
  7. package/lib/Chunk.js +56 -19
  8. package/lib/ChunkGroup.js +14 -6
  9. package/lib/CommentCompilationWarning.js +22 -0
  10. package/lib/Compilation.js +72 -29
  11. package/lib/Compiler.js +22 -10
  12. package/lib/ConstPlugin.js +25 -9
  13. package/lib/ContextModule.js +88 -36
  14. package/lib/ContextModuleFactory.js +18 -7
  15. package/lib/ContextReplacementPlugin.js +14 -7
  16. package/lib/DefinePlugin.js +15 -6
  17. package/lib/DependenciesBlock.js +3 -1
  18. package/lib/DependenciesBlockVariable.js +2 -1
  19. package/lib/DllPlugin.js +4 -2
  20. package/lib/DynamicEntryPlugin.js +4 -2
  21. package/lib/EntryModuleNotFoundError.js +21 -22
  22. package/lib/ErrorHelpers.js +5 -2
  23. package/lib/EvalSourceMapDevToolPlugin.js +2 -1
  24. package/lib/FlagDependencyUsagePlugin.js +11 -5
  25. package/lib/FunctionModuleTemplatePlugin.js +8 -6
  26. package/lib/HarmonyLinkingError.js +1 -2
  27. package/lib/HotModuleReplacement.runtime.js +13 -4
  28. package/lib/HotModuleReplacementPlugin.js +13 -6
  29. package/lib/JavascriptGenerator.js +2 -1
  30. package/lib/JavascriptModulesPlugin.js +4 -9
  31. package/lib/JsonParser.js +2 -1
  32. package/lib/LibraryTemplatePlugin.js +2 -1
  33. package/lib/LoaderOptionsPlugin.js +2 -1
  34. package/lib/MainTemplate.js +2 -1
  35. package/lib/Module.js +13 -5
  36. package/lib/ModuleBuildError.js +22 -12
  37. package/lib/ModuleDependencyError.js +4 -4
  38. package/lib/ModuleDependencyWarning.js +4 -4
  39. package/lib/ModuleError.js +13 -5
  40. package/lib/ModuleFilenameHelpers.js +20 -8
  41. package/lib/ModuleNotFoundError.js +23 -26
  42. package/lib/ModuleParseError.js +27 -14
  43. package/lib/ModuleWarning.js +13 -7
  44. package/lib/MultiCompiler.js +19 -7
  45. package/lib/MultiModule.js +5 -2
  46. package/lib/NodeStuffPlugin.js +2 -1
  47. package/lib/NormalModule.js +80 -16
  48. package/lib/NormalModuleFactory.js +67 -24
  49. package/lib/OptionsDefaulter.js +7 -3
  50. package/lib/Parser.js +182 -75
  51. package/lib/ParserHelpers.js +6 -3
  52. package/lib/ProgressPlugin.js +17 -2
  53. package/lib/RawModule.js +4 -2
  54. package/lib/RecordIdsPlugin.js +77 -9
  55. package/lib/RemovedPluginError.js +1 -3
  56. package/lib/RequestShortener.js +15 -6
  57. package/lib/RuleSet.js +51 -18
  58. package/lib/RuntimeTemplate.js +21 -10
  59. package/lib/SourceMapDevToolPlugin.js +4 -3
  60. package/lib/Stats.js +74 -31
  61. package/lib/Template.js +7 -4
  62. package/lib/TemplatedPathPlugin.js +6 -3
  63. package/lib/UmdMainTemplatePlugin.js +8 -3
  64. package/lib/UnsupportedFeatureWarning.js +22 -21
  65. package/lib/WarnCaseSensitiveModulesPlugin.js +2 -1
  66. package/lib/Watching.js +3 -2
  67. package/lib/WebpackOptionsApply.js +51 -23
  68. package/lib/WebpackOptionsDefaulter.js +15 -9
  69. package/lib/WebpackOptionsValidationError.js +63 -34
  70. package/lib/debug/ProfilingPlugin.js +11 -2
  71. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +17 -8
  72. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +8 -4
  73. package/lib/dependencies/HarmonyDetectionParserPlugin.js +4 -2
  74. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +7 -3
  75. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +6 -3
  76. package/lib/dependencies/ImportParserPlugin.js +42 -11
  77. package/lib/dependencies/LoaderPlugin.js +12 -7
  78. package/lib/dependencies/LocalModulesHelpers.js +13 -6
  79. package/lib/dependencies/RequireContextPlugin.js +4 -2
  80. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +8 -4
  81. package/lib/dependencies/SystemPlugin.js +6 -6
  82. package/lib/dependencies/WebAssemblyExportImportedDependency.js +29 -0
  83. package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
  84. package/lib/formatLocation.js +15 -7
  85. package/lib/node/NodeMainTemplateAsync.runtime.js +1 -1
  86. package/lib/node/NodeMainTemplatePlugin.js +6 -3
  87. package/lib/node/NodeSourcePlugin.js +9 -5
  88. package/lib/node/NodeWatchFileSystem.js +29 -12
  89. package/lib/node/ReadFileCompileWasmTemplatePlugin.js +11 -2
  90. package/lib/optimize/AggressiveSplittingPlugin.js +12 -6
  91. package/lib/optimize/ConcatenatedModule.js +19 -8
  92. package/lib/optimize/MergeDuplicateChunksPlugin.js +6 -3
  93. package/lib/optimize/ModuleConcatenationPlugin.js +23 -10
  94. package/lib/optimize/OccurrenceOrderPlugin.js +11 -4
  95. package/lib/optimize/RemoveParentModulesPlugin.js +17 -7
  96. package/lib/optimize/SideEffectsFlagPlugin.js +14 -3
  97. package/lib/optimize/SplitChunksPlugin.js +33 -20
  98. package/lib/performance/AssetsOverSizeLimitWarning.js +7 -7
  99. package/lib/performance/EntrypointsOverSizeLimitWarning.js +6 -7
  100. package/lib/performance/NoAsyncChunksWarning.js +5 -5
  101. package/lib/util/SortableSet.js +5 -2
  102. package/lib/util/StackedSetMap.js +12 -5
  103. package/lib/wasm/UnsupportedWebAssemblyFeatureError.js +1 -2
  104. package/lib/wasm/WasmFinalizeExportsPlugin.js +66 -0
  105. package/lib/wasm/WasmMainTemplatePlugin.js +87 -43
  106. package/lib/wasm/WebAssemblyGenerator.js +117 -74
  107. package/lib/wasm/WebAssemblyJavascriptGenerator.js +92 -49
  108. package/lib/wasm/WebAssemblyModulesPlugin.js +11 -1
  109. package/lib/wasm/WebAssemblyParser.js +96 -24
  110. package/lib/wasm/WebAssemblyUtils.js +17 -6
  111. package/lib/web/FetchCompileWasmTemplatePlugin.js +13 -1
  112. package/lib/web/JsonpChunkTemplatePlugin.js +7 -0
  113. package/lib/web/JsonpMainTemplate.runtime.js +2 -1
  114. package/lib/web/JsonpMainTemplatePlugin.js +68 -63
  115. package/lib/webpack.js +2 -1
  116. package/lib/webworker/WebWorkerMainTemplate.runtime.js +2 -1
  117. package/package.json +12 -11
  118. package/schemas/WebpackOptions.json +8 -0
@@ -60,12 +60,15 @@ class ContextReplacementPlugin {
60
60
  cmf.hooks.beforeResolve.tap("ContextReplacementPlugin", result => {
61
61
  if (!result) return;
62
62
  if (resourceRegExp.test(result.request)) {
63
- if (typeof newContentResource !== "undefined")
63
+ if (typeof newContentResource !== "undefined") {
64
64
  result.request = newContentResource;
65
- if (typeof newContentRecursive !== "undefined")
65
+ }
66
+ if (typeof newContentRecursive !== "undefined") {
66
67
  result.recursive = newContentRecursive;
67
- if (typeof newContentRegExp !== "undefined")
68
+ }
69
+ if (typeof newContentRegExp !== "undefined") {
68
70
  result.regExp = newContentRegExp;
71
+ }
69
72
  if (typeof newContentCallback === "function") {
70
73
  newContentCallback(result);
71
74
  } else {
@@ -79,16 +82,20 @@ class ContextReplacementPlugin {
79
82
  cmf.hooks.afterResolve.tap("ContextReplacementPlugin", result => {
80
83
  if (!result) return;
81
84
  if (resourceRegExp.test(result.resource)) {
82
- if (typeof newContentResource !== "undefined")
85
+ if (typeof newContentResource !== "undefined") {
83
86
  result.resource = path.resolve(result.resource, newContentResource);
84
- if (typeof newContentRecursive !== "undefined")
87
+ }
88
+ if (typeof newContentRecursive !== "undefined") {
85
89
  result.recursive = newContentRecursive;
86
- if (typeof newContentRegExp !== "undefined")
90
+ }
91
+ if (typeof newContentRegExp !== "undefined") {
87
92
  result.regExp = newContentRegExp;
88
- if (typeof newContentCreateContextMap === "function")
93
+ }
94
+ if (typeof newContentCreateContextMap === "function") {
89
95
  result.resolveDependencies = createResolveDependenciesFromContextMap(
90
96
  newContentCreateContextMap
91
97
  );
98
+ }
92
99
  if (typeof newContentCallback === "function") {
93
100
  const origResource = result.resource;
94
101
  newContentCallback(result);
@@ -23,13 +23,22 @@ const stringifyObj = obj => {
23
23
  };
24
24
 
25
25
  const toCode = code => {
26
- if (code === null) return "null";
27
- else if (code === undefined) return "undefined";
28
- else if (code instanceof RegExp && code.toString) return code.toString();
29
- else if (typeof code === "function" && code.toString)
26
+ if (code === null) {
27
+ return "null";
28
+ }
29
+ if (code === undefined) {
30
+ return "undefined";
31
+ }
32
+ if (code instanceof RegExp && code.toString) {
33
+ return code.toString();
34
+ }
35
+ if (typeof code === "function" && code.toString) {
30
36
  return "(" + code.toString() + ")";
31
- else if (typeof code === "object") return stringifyObj(code);
32
- else return code + "";
37
+ }
38
+ if (typeof code === "object") {
39
+ return stringifyObj(code);
40
+ }
41
+ return code + "";
33
42
  };
34
43
 
35
44
  class DefinePlugin {
@@ -40,7 +40,9 @@ class DependenciesBlock {
40
40
 
41
41
  removeDependency(dependency) {
42
42
  const idx = this.dependencies.indexOf(dependency);
43
- if (idx >= 0) this.dependencies.splice(idx, 1);
43
+ if (idx >= 0) {
44
+ this.dependencies.splice(idx, 1);
45
+ }
44
46
  }
45
47
 
46
48
  updateHash(hash) {
@@ -25,8 +25,9 @@ class DependenciesBlockVariable {
25
25
  const source = new ReplaceSource(new RawSource(this.expression));
26
26
  for (const dep of this.dependencies) {
27
27
  const template = dependencyTemplates.get(dep.constructor);
28
- if (!template)
28
+ if (!template) {
29
29
  throw new Error(`No template for dependency: ${dep.constructor.name}`);
30
+ }
30
31
  template.apply(dep, source, runtimeTemplate, dependencyTemplates);
31
32
  }
32
33
  return source;
package/lib/DllPlugin.js CHANGED
@@ -20,8 +20,10 @@ class DllPlugin {
20
20
  apply(compiler) {
21
21
  compiler.hooks.entryOption.tap("DllPlugin", (context, entry) => {
22
22
  const itemToPlugin = (item, name) => {
23
- if (Array.isArray(item)) return new DllEntryPlugin(context, item, name);
24
- else throw new Error("DllPlugin: supply an Array as entry");
23
+ if (Array.isArray(item)) {
24
+ return new DllEntryPlugin(context, item, name);
25
+ }
26
+ throw new Error("DllPlugin: supply an Array as entry");
25
27
  };
26
28
  if (typeof entry === "object" && !Array.isArray(entry)) {
27
29
  Object.keys(entry).forEach(name => {
@@ -65,7 +65,9 @@ class DynamicEntryPlugin {
65
65
  module.exports = DynamicEntryPlugin;
66
66
 
67
67
  DynamicEntryPlugin.createDependency = (entry, name) => {
68
- if (Array.isArray(entry))
68
+ if (Array.isArray(entry)) {
69
69
  return MultiEntryPlugin.createDependency(entry, name);
70
- else return SingleEntryPlugin.createDependency(entry, name);
70
+ } else {
71
+ return SingleEntryPlugin.createDependency(entry, name);
72
+ }
71
73
  };
@@ -1,22 +1,21 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
-
7
- const WebpackError = require("./WebpackError");
8
-
9
- class EntryModuleNotFoundError extends WebpackError {
10
- constructor(err) {
11
- super();
12
-
13
- this.name = "EntryModuleNotFoundError";
14
- this.message = "Entry module not found: " + err;
15
- this.details = err.details;
16
- this.error = err;
17
-
18
- Error.captureStackTrace(this, this.constructor);
19
- }
20
- }
21
-
22
- module.exports = EntryModuleNotFoundError;
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+
7
+ const WebpackError = require("./WebpackError");
8
+
9
+ class EntryModuleNotFoundError extends WebpackError {
10
+ constructor(err) {
11
+ super("Entry module not found: " + err);
12
+
13
+ this.name = "EntryModuleNotFoundError";
14
+ this.details = err.details;
15
+ this.error = err;
16
+
17
+ Error.captureStackTrace(this, this.constructor);
18
+ }
19
+ }
20
+
21
+ module.exports = EntryModuleNotFoundError;
@@ -10,8 +10,11 @@ const webpackOptionsFlag = "WEBPACK_OPTIONS";
10
10
 
11
11
  exports.cutOffByFlag = (stack, flag) => {
12
12
  stack = stack.split("\n");
13
- for (let i = 0; i < stack.length; i++)
14
- if (stack[i].includes(flag)) stack.length = i;
13
+ for (let i = 0; i < stack.length; i++) {
14
+ if (stack[i].includes(flag)) {
15
+ stack.length = i;
16
+ }
17
+ }
15
18
  return stack.join("\n");
16
19
  };
17
20
 
@@ -9,10 +9,11 @@ const SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOpt
9
9
 
10
10
  class EvalSourceMapDevToolPlugin {
11
11
  constructor(options) {
12
- if (arguments.length > 1)
12
+ if (arguments.length > 1) {
13
13
  throw new Error(
14
14
  "EvalSourceMapDevToolPlugin only takes one argument (pass an options object)"
15
15
  );
16
+ }
16
17
  if (typeof options === "string") {
17
18
  options = {
18
19
  append: options
@@ -26,16 +26,22 @@ class FlagDependencyUsagePlugin {
26
26
  const processModule = (module, usedExports) => {
27
27
  module.used = true;
28
28
  if (module.usedExports === true) return;
29
- else if (usedExports === true) module.usedExports = true;
30
- else if (Array.isArray(usedExports)) {
29
+ if (usedExports === true) {
30
+ module.usedExports = true;
31
+ } else if (Array.isArray(usedExports)) {
31
32
  const old = module.usedExports ? module.usedExports.length : -1;
32
33
  module.usedExports = addToSet(
33
34
  module.usedExports || [],
34
35
  usedExports
35
36
  );
36
- if (module.usedExports.length === old) return;
37
- } else if (Array.isArray(module.usedExports)) return;
38
- else module.usedExports = false;
37
+ if (module.usedExports.length === old) {
38
+ return;
39
+ }
40
+ } else if (Array.isArray(module.usedExports)) {
41
+ return;
42
+ } else {
43
+ module.usedExports = false;
44
+ }
39
45
 
40
46
  // for a module without side effects we stop tracking usage here when no export is used
41
47
  // This module won't be evaluated in this case
@@ -47,30 +47,32 @@ class FunctionModuleTemplatePlugin {
47
47
  if (
48
48
  Array.isArray(module.buildMeta.providedExports) &&
49
49
  module.buildMeta.providedExports.length === 0
50
- )
50
+ ) {
51
51
  source.add(Template.toComment("no exports provided") + "\n");
52
- else if (Array.isArray(module.buildMeta.providedExports))
52
+ } else if (Array.isArray(module.buildMeta.providedExports)) {
53
53
  source.add(
54
54
  Template.toComment(
55
55
  "exports provided: " +
56
56
  module.buildMeta.providedExports.join(", ")
57
57
  ) + "\n"
58
58
  );
59
- else if (module.buildMeta.providedExports)
59
+ } else if (module.buildMeta.providedExports) {
60
60
  source.add(Template.toComment("no static exports found") + "\n");
61
+ }
61
62
  if (
62
63
  Array.isArray(module.usedExports) &&
63
64
  module.usedExports.length === 0
64
- )
65
+ ) {
65
66
  source.add(Template.toComment("no exports used") + "\n");
66
- else if (Array.isArray(module.usedExports))
67
+ } else if (Array.isArray(module.usedExports)) {
67
68
  source.add(
68
69
  Template.toComment(
69
70
  "exports used: " + module.usedExports.join(", ")
70
71
  ) + "\n"
71
72
  );
72
- else if (module.usedExports)
73
+ } else if (module.usedExports) {
73
74
  source.add(Template.toComment("all exports used") + "\n");
75
+ }
74
76
  if (module.optimizationBailout) {
75
77
  for (const text of module.optimizationBailout) {
76
78
  let code;
@@ -8,9 +8,8 @@ const WebpackError = require("./WebpackError");
8
8
  module.exports = class HarmonyLinkingError extends WebpackError {
9
9
  /** @param {string} message Error message */
10
10
  constructor(message) {
11
- super();
11
+ super(message);
12
12
  this.name = "HarmonyLinkingError";
13
- this.message = message;
14
13
  this.hideStack = true;
15
14
 
16
15
  Error.captureStackTrace(this, this.constructor);
@@ -19,13 +19,16 @@ module.exports = function() {
19
19
  var fn = function(request) {
20
20
  if (me.hot.active) {
21
21
  if (installedModules[request]) {
22
- if (installedModules[request].parents.indexOf(moduleId) === -1)
22
+ if (installedModules[request].parents.indexOf(moduleId) === -1) {
23
23
  installedModules[request].parents.push(moduleId);
24
+ }
24
25
  } else {
25
26
  hotCurrentParents = [moduleId];
26
27
  hotCurrentChildModule = request;
27
28
  }
28
- if (me.children.indexOf(request) === -1) me.children.push(request);
29
+ if (me.children.indexOf(request) === -1) {
30
+ me.children.push(request);
31
+ }
29
32
  } else {
30
33
  console.warn(
31
34
  "[HMR] unexpected require(" +
@@ -52,7 +55,8 @@ module.exports = function() {
52
55
  for (var name in $require$) {
53
56
  if (
54
57
  Object.prototype.hasOwnProperty.call($require$, name) &&
55
- name !== "e"
58
+ name !== "e" &&
59
+ name !== "t"
56
60
  ) {
57
61
  Object.defineProperty(fn, name, ObjectFactory(name));
58
62
  }
@@ -77,6 +81,10 @@ module.exports = function() {
77
81
  }
78
82
  }
79
83
  };
84
+ fn.t = function(value, mode) {
85
+ if (mode & 1) value = fn(value);
86
+ return $require$.t(value, mode & ~1);
87
+ };
80
88
  return fn;
81
89
  }
82
90
 
@@ -167,8 +175,9 @@ module.exports = function() {
167
175
  }
168
176
 
169
177
  function hotCheck(apply) {
170
- if (hotStatus !== "idle")
178
+ if (hotStatus !== "idle") {
171
179
  throw new Error("check() is only allowed in idle status");
180
+ }
172
181
  hotApplyOnUpdate = apply;
173
182
  hotSetStatus("check");
174
183
  return hotDownloadManifest(hotRequestTimeout).then(function(update) {
@@ -255,8 +255,11 @@ module.exports = class HotModuleReplacementPlugin {
255
255
  mainTemplate.hooks.currentHash.tap(
256
256
  "HotModuleReplacementPlugin",
257
257
  (_, length) => {
258
- if (isFinite(length)) return `hotCurrentHash.substr(0, ${length})`;
259
- else return "hotCurrentHash";
258
+ if (isFinite(length)) {
259
+ return `hotCurrentHash.substr(0, ${length})`;
260
+ } else {
261
+ return "hotCurrentHash";
262
+ }
260
263
  }
261
264
  );
262
265
 
@@ -301,21 +304,24 @@ module.exports = class HotModuleReplacementPlugin {
301
304
  }
302
305
  );
303
306
  // TODO webpack 5: refactor this, no custom hooks
304
- if (!parser.hooks.hotAcceptCallback)
307
+ if (!parser.hooks.hotAcceptCallback) {
305
308
  parser.hooks.hotAcceptCallback = new SyncBailHook([
306
309
  "expression",
307
310
  "requests"
308
311
  ]);
309
- if (!parser.hooks.hotAcceptWithoutCallback)
312
+ }
313
+ if (!parser.hooks.hotAcceptWithoutCallback) {
310
314
  parser.hooks.hotAcceptWithoutCallback = new SyncBailHook([
311
315
  "expression",
312
316
  "requests"
313
317
  ]);
318
+ }
314
319
  parser.hooks.call
315
320
  .for("module.hot.accept")
316
321
  .tap("HotModuleReplacementPlugin", expr => {
317
- if (!parser.state.compilation.hotUpdateChunkTemplate)
322
+ if (!parser.state.compilation.hotUpdateChunkTemplate) {
318
323
  return false;
324
+ }
319
325
  if (expr.arguments.length >= 1) {
320
326
  const arg = parser.evaluateExpression(expr.arguments[0]);
321
327
  let params = [];
@@ -355,8 +361,9 @@ module.exports = class HotModuleReplacementPlugin {
355
361
  parser.hooks.call
356
362
  .for("module.hot.decline")
357
363
  .tap("HotModuleReplacementPlugin", expr => {
358
- if (!parser.state.compilation.hotUpdateChunkTemplate)
364
+ if (!parser.state.compilation.hotUpdateChunkTemplate) {
359
365
  return false;
366
+ }
360
367
  if (expr.arguments.length === 1) {
361
368
  const arg = parser.evaluateExpression(expr.arguments[0]);
362
369
  let params = [];
@@ -143,10 +143,11 @@ class JavascriptGenerator {
143
143
 
144
144
  sourceDependency(dependency, dependencyTemplates, source, runtimeTemplate) {
145
145
  const template = dependencyTemplates.get(dependency.constructor);
146
- if (!template)
146
+ if (!template) {
147
147
  throw new Error(
148
148
  "No template for dependency: " + dependency.constructor.name
149
149
  );
150
+ }
150
151
  template.apply(dependency, source, runtimeTemplate, dependencyTemplates);
151
152
  }
152
153
 
@@ -55,10 +55,8 @@ class JavascriptModulesPlugin {
55
55
  const moduleTemplates = options.moduleTemplates;
56
56
  const dependencyTemplates = options.dependencyTemplates;
57
57
 
58
- let filenameTemplate;
59
- if (chunk.filenameTemplate)
60
- filenameTemplate = chunk.filenameTemplate;
61
- else filenameTemplate = outputOptions.filename;
58
+ const filenameTemplate =
59
+ chunk.filenameTemplate || outputOptions.filename;
62
60
 
63
61
  const useChunkHash = compilation.mainTemplate.useChunkHash(chunk);
64
62
 
@@ -101,11 +99,8 @@ class JavascriptModulesPlugin {
101
99
  const outputOptions = options.outputOptions;
102
100
  const moduleTemplates = options.moduleTemplates;
103
101
  const dependencyTemplates = options.dependencyTemplates;
104
-
105
- let filenameTemplate;
106
- if (chunk.filenameTemplate)
107
- filenameTemplate = chunk.filenameTemplate;
108
- else filenameTemplate = outputOptions.chunkFilename;
102
+ const filenameTemplate =
103
+ chunk.filenameTemplate || outputOptions.chunkFilename;
109
104
 
110
105
  result.push({
111
106
  render: () =>
package/lib/JsonParser.js CHANGED
@@ -16,8 +16,9 @@ class JsonParser {
16
16
  const data = parseJson(source[0] === "\ufeff" ? source.slice(1) : source);
17
17
  state.module.buildInfo.jsonData = data;
18
18
  state.module.buildMeta.exportsType = "named";
19
- if (typeof data === "object" && data)
19
+ if (typeof data === "object" && data) {
20
20
  state.module.addDependency(new JsonExportsDependency(Object.keys(data)));
21
+ }
21
22
  state.module.addDependency(new JsonExportsDependency(["default"]));
22
23
  return state;
23
24
  }
@@ -30,8 +30,9 @@ const accessorAccess = (base, accessor, joinWith = "; ") => {
30
30
  ? base + accessorToObjectAccess(accessors.slice(0, idx + 1))
31
31
  : accessors[0] + accessorToObjectAccess(accessors.slice(1, idx + 1));
32
32
  if (idx === accessors.length - 1) return a;
33
- if (idx === 0 && typeof base === "undefined")
33
+ if (idx === 0 && typeof base === "undefined") {
34
34
  return `${a} = typeof ${a} === "object" ? ${a} : {}`;
35
+ }
35
36
  return `${a} = ${a} || {}`;
36
37
  })
37
38
  .join(joinWith);
@@ -14,10 +14,11 @@ class LoaderOptionsPlugin {
14
14
  validateOptions(schema, options || {}, "Loader Options Plugin");
15
15
 
16
16
  if (typeof options !== "object") options = {};
17
- if (!options.test)
17
+ if (!options.test) {
18
18
  options.test = {
19
19
  test: () => true
20
20
  };
21
+ }
21
22
  this.options = options;
22
23
  }
23
24
 
@@ -401,10 +401,11 @@ module.exports = class MainTemplate extends Tapable {
401
401
  if (chunk.hasEntryModule()) {
402
402
  source = this.hooks.renderWithEntry.call(source, chunk, hash);
403
403
  }
404
- if (!source)
404
+ if (!source) {
405
405
  throw new Error(
406
406
  "Compiler error: MainTemplate plugin 'render' should return something"
407
407
  );
408
+ }
408
409
  chunk.rendered = true;
409
410
  return new ConcatSource(source, ";");
410
411
  }
package/lib/Module.js CHANGED
@@ -225,8 +225,9 @@ class Module extends DependenciesBlock {
225
225
 
226
226
  hasReasonForChunk(chunk) {
227
227
  if (this._rewriteChunkInReasons) {
228
- for (const operation of this._rewriteChunkInReasons)
228
+ for (const operation of this._rewriteChunkInReasons) {
229
229
  this._doRewriteChunkInReasons(operation.oldChunk, operation.newChunks);
230
+ }
230
231
  this._rewriteChunkInReasons = undefined;
231
232
  }
232
233
  for (let i = 0; i < this.reasons.length; i++) {
@@ -241,8 +242,9 @@ class Module extends DependenciesBlock {
241
242
 
242
243
  rewriteChunkInReasons(oldChunk, newChunks) {
243
244
  // This is expensive. Delay operation until we really need the data
244
- if (this._rewriteChunkInReasons === undefined)
245
+ if (this._rewriteChunkInReasons === undefined) {
245
246
  this._rewriteChunkInReasons = [];
247
+ }
246
248
  this._rewriteChunkInReasons.push({
247
249
  oldChunk,
248
250
  newChunks
@@ -266,13 +268,15 @@ class Module extends DependenciesBlock {
266
268
 
267
269
  // Mangle export name if possible
268
270
  if (this.isProvided(exportName)) {
269
- if (this.buildMeta.exportsType === "namespace")
271
+ if (this.buildMeta.exportsType === "namespace") {
270
272
  return Template.numberToIdentifer(idx);
271
- else if (
273
+ }
274
+ if (
272
275
  this.buildMeta.exportsType === "named" &&
273
276
  !this.usedExports.includes("default")
274
- )
277
+ ) {
275
278
  return Template.numberToIdentifer(idx);
279
+ }
276
280
  }
277
281
  return exportName;
278
282
  }
@@ -366,8 +370,12 @@ Object.defineProperty(Module.prototype, "meta", {
366
370
  }, "Module.meta was renamed to Module.buildMeta")
367
371
  });
368
372
 
373
+ /** @type {function(): string} */
369
374
  Module.prototype.identifier = null;
375
+
376
+ /** @type {function(RequestShortener): string} */
370
377
  Module.prototype.readableIdentifier = null;
378
+
371
379
  Module.prototype.build = null;
372
380
  Module.prototype.source = null;
373
381
  Module.prototype.size = null;
@@ -8,30 +8,40 @@ const WebpackError = require("./WebpackError");
8
8
  const { cutOffLoaderExecution } = require("./ErrorHelpers");
9
9
 
10
10
  class ModuleBuildError extends WebpackError {
11
- constructor(module, err) {
12
- super();
13
-
14
- this.name = "ModuleBuildError";
15
- this.message = "Module build failed: ";
11
+ constructor(module, err, { from = null } = {}) {
12
+ let message = "Module build failed";
13
+ let details = undefined;
14
+ if (from) {
15
+ message += ` (from ${from}):\n`;
16
+ } else {
17
+ message += ": ";
18
+ }
16
19
  if (err !== null && typeof err === "object") {
17
20
  if (typeof err.stack === "string" && err.stack) {
18
- var stack = cutOffLoaderExecution(err.stack);
21
+ const stack = cutOffLoaderExecution(err.stack);
19
22
  if (!err.hideStack) {
20
- this.message += stack;
23
+ message += stack;
21
24
  } else {
22
- this.details = stack;
25
+ details = stack;
23
26
  if (typeof err.message === "string" && err.message) {
24
- this.message += err.message;
27
+ message += err.message;
25
28
  } else {
26
- this.message += err;
29
+ message += err;
27
30
  }
28
31
  }
29
32
  } else if (typeof err.message === "string" && err.message) {
30
- this.message += err.message;
33
+ message += err.message;
31
34
  } else {
32
- this.message += err;
35
+ message += err;
33
36
  }
37
+ } else {
38
+ message = err;
34
39
  }
40
+
41
+ super(message);
42
+
43
+ this.name = "ModuleBuildError";
44
+ this.details = details;
35
45
  this.module = module;
36
46
  this.error = err;
37
47
 
@@ -5,7 +5,6 @@
5
5
  "use strict";
6
6
 
7
7
  const WebpackError = require("./WebpackError");
8
- const formatLocation = require("./formatLocation");
9
8
 
10
9
  /** @typedef {import("./Module")} Module */
11
10
 
@@ -17,16 +16,17 @@ class ModuleDependencyError extends WebpackError {
17
16
  * @param {TODO} loc location of dependency
18
17
  */
19
18
  constructor(module, err, loc) {
20
- super();
19
+ super(err.message);
21
20
 
22
21
  this.name = "ModuleDependencyError";
23
- this.message = `${formatLocation(loc)} ${err.message}`;
24
22
  this.details = err.stack
25
23
  .split("\n")
26
24
  .slice(1)
27
25
  .join("\n");
28
- this.origin = this.module = module;
26
+ this.module = module;
27
+ this.loc = loc;
29
28
  this.error = err;
29
+ this.origin = module.issuer;
30
30
 
31
31
  Error.captureStackTrace(this, this.constructor);
32
32
  }
@@ -5,20 +5,20 @@
5
5
  "use strict";
6
6
 
7
7
  const WebpackError = require("./WebpackError");
8
- const formatLocation = require("./formatLocation");
9
8
 
10
9
  module.exports = class ModuleDependencyWarning extends WebpackError {
11
10
  constructor(module, err, loc) {
12
- super();
11
+ super(err.message);
13
12
 
14
13
  this.name = "ModuleDependencyWarning";
15
- this.message = `${formatLocation(loc)} ${err.message}`;
16
14
  this.details = err.stack
17
15
  .split("\n")
18
16
  .slice(1)
19
17
  .join("\n");
20
- this.origin = this.module = module;
18
+ this.module = module;
19
+ this.loc = loc;
21
20
  this.error = err;
21
+ this.origin = module.issuer;
22
22
 
23
23
  Error.captureStackTrace(this, this.constructor);
24
24
  }
@@ -8,13 +8,21 @@ const WebpackError = require("./WebpackError");
8
8
  const { cleanUp } = require("./ErrorHelpers");
9
9
 
10
10
  class ModuleError extends WebpackError {
11
- constructor(module, err) {
12
- super();
13
-
11
+ constructor(module, err, { from = null } = {}) {
12
+ let message = "Module Error";
13
+ if (from) {
14
+ message += ` (from ${from}):\n`;
15
+ } else {
16
+ message += ": ";
17
+ }
18
+ if (err && typeof err === "object" && err.message) {
19
+ message += err.message;
20
+ } else if (err) {
21
+ message += err;
22
+ }
23
+ super(message);
14
24
  this.name = "ModuleError";
15
25
  this.module = module;
16
- this.message =
17
- err && typeof err === "object" && err.message ? err.message : err;
18
26
  this.error = err;
19
27
  this.details =
20
28
  err && typeof err === "object" && err.stack