webpack 5.45.1 → 5.46.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.

package/bin/webpack.js CHANGED
File without changes
@@ -350,18 +350,20 @@ class NormalModule extends Module {
350
350
  this.resource = m.resource;
351
351
  this.matchResource = m.matchResource;
352
352
  this.loaders = m.loaders;
353
- this._sourceTypes = m._sourceTypes;
354
- this._sourceSizes = m._sourceSizes;
355
353
  }
356
354
 
357
355
  /**
358
356
  * Assuming this module is in the cache. Remove internal references to allow freeing some memory.
359
357
  */
360
358
  cleanupForCache() {
361
- // Make sure to cache types and sizes before cleanup
362
- if (this._sourceTypes === undefined) this.getSourceTypes();
363
- for (const type of this._sourceTypes) {
364
- this.size(type);
359
+ // Make sure to cache types and sizes before cleanup when this module has been built
360
+ // They are accessed by the stats and we don't want them to crash after cleanup
361
+ // TODO reconsider this for webpack 6
362
+ if (this.buildInfo) {
363
+ if (this._sourceTypes === undefined) this.getSourceTypes();
364
+ for (const type of this._sourceTypes) {
365
+ this.size(type);
366
+ }
365
367
  }
366
368
  super.cleanupForCache();
367
369
  this.parser = undefined;
@@ -172,24 +172,29 @@ class AssetModulesPlugin {
172
172
  );
173
173
  if (modules) {
174
174
  for (const module of modules) {
175
- const codeGenResult = codeGenerationResults.get(
176
- module,
177
- chunk.runtime
178
- );
179
- result.push({
180
- render: () => codeGenResult.sources.get(type),
181
- filename:
182
- module.buildInfo.filename ||
183
- codeGenResult.data.get("filename"),
184
- info:
185
- module.buildInfo.assetInfo ||
186
- codeGenResult.data.get("assetInfo"),
187
- auxiliary: true,
188
- identifier: `assetModule${chunkGraph.getModuleId(module)}`,
189
- hash:
190
- module.buildInfo.fullContentHash ||
191
- codeGenResult.data.get("fullContentHash")
192
- });
175
+ try {
176
+ const codeGenResult = codeGenerationResults.get(
177
+ module,
178
+ chunk.runtime
179
+ );
180
+ result.push({
181
+ render: () => codeGenResult.sources.get(type),
182
+ filename:
183
+ module.buildInfo.filename ||
184
+ codeGenResult.data.get("filename"),
185
+ info:
186
+ module.buildInfo.assetInfo ||
187
+ codeGenResult.data.get("assetInfo"),
188
+ auxiliary: true,
189
+ identifier: `assetModule${chunkGraph.getModuleId(module)}`,
190
+ hash:
191
+ module.buildInfo.fullContentHash ||
192
+ codeGenResult.data.get("fullContentHash")
193
+ });
194
+ } catch (e) {
195
+ e.message += `\nduring rendering of asset ${module.identifier()}`;
196
+ throw e;
197
+ }
193
198
  }
194
199
  }
195
200
 
@@ -9,6 +9,7 @@ var $interceptModuleExecution$ = undefined;
9
9
  var $moduleCache$ = undefined;
10
10
  // eslint-disable-next-line no-unused-vars
11
11
  var $hmrModuleData$ = undefined;
12
+ /** @type {() => Promise} */
12
13
  var $hmrDownloadManifest$ = undefined;
13
14
  var $hmrDownloadUpdateHandlers$ = undefined;
14
15
  var $hmrInvalidateModuleHandlers$ = undefined;
@@ -209,8 +210,12 @@ module.exports = function () {
209
210
 
210
211
  function setStatus(newStatus) {
211
212
  currentStatus = newStatus;
213
+ var results = [];
214
+
212
215
  for (var i = 0; i < registeredStatusHandlers.length; i++)
213
- registeredStatusHandlers[i].call(null, newStatus);
216
+ results[i] = registeredStatusHandlers[i].call(null, newStatus);
217
+
218
+ return Promise.all(results);
214
219
  }
215
220
 
216
221
  function trackBlockingPromise(promise) {
@@ -219,7 +224,7 @@ module.exports = function () {
219
224
  setStatus("prepare");
220
225
  blockingPromises.push(promise);
221
226
  waitForBlockingPromises(function () {
222
- setStatus("ready");
227
+ return setStatus("ready");
223
228
  });
224
229
  return promise;
225
230
  case "prepare":
@@ -243,47 +248,47 @@ module.exports = function () {
243
248
  if (currentStatus !== "idle") {
244
249
  throw new Error("check() is only allowed in idle status");
245
250
  }
246
- setStatus("check");
247
- return $hmrDownloadManifest$().then(function (update) {
248
- if (!update) {
249
- setStatus(applyInvalidatedModules() ? "ready" : "idle");
250
- return null;
251
- }
252
-
253
- setStatus("prepare");
254
-
255
- var updatedModules = [];
256
- blockingPromises = [];
257
- currentUpdateApplyHandlers = [];
258
-
259
- return Promise.all(
260
- Object.keys($hmrDownloadUpdateHandlers$).reduce(function (
261
- promises,
262
- key
263
- ) {
264
- $hmrDownloadUpdateHandlers$[key](
265
- update.c,
266
- update.r,
267
- update.m,
268
- promises,
269
- currentUpdateApplyHandlers,
270
- updatedModules
271
- );
272
- return promises;
273
- },
274
- [])
275
- ).then(function () {
276
- return waitForBlockingPromises(function () {
277
- if (applyOnUpdate) {
278
- return internalApply(applyOnUpdate);
279
- } else {
280
- setStatus("ready");
251
+ return setStatus("check")
252
+ .then($hmrDownloadManifest$)
253
+ .then(function (update) {
254
+ if (!update) {
255
+ return setStatus(applyInvalidatedModules() ? "ready" : "idle");
256
+ }
281
257
 
282
- return updatedModules;
283
- }
258
+ return setStatus("prepare").then(function () {
259
+ var updatedModules = [];
260
+ blockingPromises = [];
261
+ currentUpdateApplyHandlers = [];
262
+
263
+ return Promise.all(
264
+ Object.keys($hmrDownloadUpdateHandlers$).reduce(function (
265
+ promises,
266
+ key
267
+ ) {
268
+ $hmrDownloadUpdateHandlers$[key](
269
+ update.c,
270
+ update.r,
271
+ update.m,
272
+ promises,
273
+ currentUpdateApplyHandlers,
274
+ updatedModules
275
+ );
276
+ return promises;
277
+ },
278
+ [])
279
+ ).then(function () {
280
+ return waitForBlockingPromises(function () {
281
+ if (applyOnUpdate) {
282
+ return internalApply(applyOnUpdate);
283
+ } else {
284
+ return setStatus("ready").then(function () {
285
+ return updatedModules;
286
+ });
287
+ }
288
+ });
289
+ });
284
290
  });
285
291
  });
286
- });
287
292
  }
288
293
 
289
294
  function hotApply(options) {
@@ -312,21 +317,20 @@ module.exports = function () {
312
317
  .filter(Boolean);
313
318
 
314
319
  if (errors.length > 0) {
315
- setStatus("abort");
316
- return Promise.resolve().then(function () {
320
+ return setStatus("abort").then(function () {
317
321
  throw errors[0];
318
322
  });
319
323
  }
320
324
 
321
325
  // Now in "dispose" phase
322
- setStatus("dispose");
326
+ var disposePromise = setStatus("dispose");
323
327
 
324
328
  results.forEach(function (result) {
325
329
  if (result.dispose) result.dispose();
326
330
  });
327
331
 
328
332
  // Now in "apply" phase
329
- setStatus("apply");
333
+ var applyPromise = setStatus("apply");
330
334
 
331
335
  var error;
332
336
  var reportError = function (err) {
@@ -345,25 +349,27 @@ module.exports = function () {
345
349
  }
346
350
  });
347
351
 
348
- // handle errors in accept handlers and self accepted module load
349
- if (error) {
350
- setStatus("fail");
351
- return Promise.resolve().then(function () {
352
- throw error;
353
- });
354
- }
352
+ return Promise.all([disposePromise, applyPromise]).then(function () {
353
+ // handle errors in accept handlers and self accepted module load
354
+ if (error) {
355
+ return setStatus("fail").then(function () {
356
+ throw error;
357
+ });
358
+ }
355
359
 
356
- if (queuedInvalidatedModules) {
357
- return internalApply(options).then(function (list) {
358
- outdatedModules.forEach(function (moduleId) {
359
- if (list.indexOf(moduleId) < 0) list.push(moduleId);
360
+ if (queuedInvalidatedModules) {
361
+ return internalApply(options).then(function (list) {
362
+ outdatedModules.forEach(function (moduleId) {
363
+ if (list.indexOf(moduleId) < 0) list.push(moduleId);
364
+ });
365
+ return list;
360
366
  });
361
- return list;
362
- });
363
- }
367
+ }
364
368
 
365
- setStatus("idle");
366
- return Promise.resolve(outdatedModules);
369
+ return setStatus("idle").then(function () {
370
+ return outdatedModules;
371
+ });
372
+ });
367
373
  }
368
374
 
369
375
  function applyInvalidatedModules() {
@@ -1182,11 +1182,14 @@ const SIMPLE_EXTRACTORS = {
1182
1182
  type,
1183
1183
  compilation: { moduleGraph }
1184
1184
  } = context;
1185
- object.reasons = factory.create(
1185
+ const groupsReasons = factory.create(
1186
1186
  `${type.slice(0, -8)}.reasons`,
1187
1187
  Array.from(moduleGraph.getIncomingConnections(module)),
1188
1188
  context
1189
1189
  );
1190
+ const limited = spaceLimited(groupsReasons, options.reasonsSpace);
1191
+ object.reasons = limited.children;
1192
+ object.filteredReasons = limited.filteredChildren;
1190
1193
  },
1191
1194
  usedExports: (
1192
1195
  object,
@@ -1764,6 +1767,16 @@ const moduleGroup = (children, modules) => {
1764
1767
  };
1765
1768
  };
1766
1769
 
1770
+ const reasonGroup = (children, reasons) => {
1771
+ let active = false;
1772
+ for (const reason of children) {
1773
+ active = active || reason.active;
1774
+ }
1775
+ return {
1776
+ active
1777
+ };
1778
+ };
1779
+
1767
1780
  /** @type {Record<string, (groupConfigs: GroupConfig[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>} */
1768
1781
  const ASSETS_GROUPERS = {
1769
1782
  _: (groupConfigs, context, options) => {
@@ -2074,7 +2087,24 @@ const RESULT_GROUPERS = {
2074
2087
  "compilation.modules": MODULES_GROUPERS("module"),
2075
2088
  "chunk.modules": MODULES_GROUPERS("chunk"),
2076
2089
  "chunk.rootModules": MODULES_GROUPERS("root-of-chunk"),
2077
- "module.modules": MODULES_GROUPERS("nested")
2090
+ "module.modules": MODULES_GROUPERS("nested"),
2091
+ "module.reasons": {
2092
+ groupReasonsByOrigin: groupConfigs => {
2093
+ groupConfigs.push({
2094
+ getKeys: reason => {
2095
+ return [reason.module];
2096
+ },
2097
+ createGroup: (key, children, reasons) => {
2098
+ return {
2099
+ type: "from origin",
2100
+ module: key,
2101
+ children,
2102
+ ...reasonGroup(children, reasons)
2103
+ };
2104
+ }
2105
+ });
2106
+ }
2107
+ }
2078
2108
  };
2079
2109
 
2080
2110
  // remove a prefixed "!" that can be specified to reverse sort order
@@ -50,6 +50,7 @@ const NAMED_PRESETS = {
50
50
  modulesSpace: Infinity,
51
51
  chunkModulesSpace: Infinity,
52
52
  assetsSpace: Infinity,
53
+ reasonsSpace: Infinity,
53
54
  children: true
54
55
  },
55
56
  detailed: {
@@ -72,8 +73,9 @@ const NAMED_PRESETS = {
72
73
  logging: true,
73
74
  runtimeModules: true,
74
75
  exclude: false,
75
- modulesSpace: Infinity,
76
- assetsSpace: Infinity
76
+ modulesSpace: 1000,
77
+ assetsSpace: 1000,
78
+ reasonsSpace: 1000
77
79
  },
78
80
  minimal: {
79
81
  all: false,
@@ -194,6 +196,8 @@ const DEFAULTS = {
194
196
  depth: OFF_FOR_TO_STRING,
195
197
  cachedAssets: OFF_FOR_TO_STRING,
196
198
  reasons: OFF_FOR_TO_STRING,
199
+ reasonsSpace: (o, { forToString }) => (forToString ? 15 : Infinity),
200
+ groupReasonsByOrigin: ON_FOR_TO_STRING,
197
201
  usedExports: OFF_FOR_TO_STRING,
198
202
  providedExports: OFF_FOR_TO_STRING,
199
203
  optimizationBailout: OFF_FOR_TO_STRING,
@@ -374,6 +374,10 @@ const SIMPLE_PRINTERS = {
374
374
  "modules"
375
375
  )}`
376
376
  : undefined,
377
+ "module.filteredReasons": filteredReasons =>
378
+ filteredReasons > 0
379
+ ? `${filteredReasons} ${plural(filteredReasons, "reason", "reasons")}`
380
+ : undefined,
377
381
  "module.filteredChildren": filteredChildren =>
378
382
  filteredChildren > 0
379
383
  ? `${filteredChildren} ${plural(filteredChildren, "module", "modules")}`
@@ -393,6 +397,10 @@ const SIMPLE_PRINTERS = {
393
397
  "moduleReason.active": (active, { formatFlag }) =>
394
398
  active ? undefined : formatFlag("inactive"),
395
399
  "moduleReason.resolvedModule": (module, { magenta }) => magenta(module),
400
+ "moduleReason.filteredChildren": filteredChildren =>
401
+ filteredChildren > 0
402
+ ? `${filteredChildren} ${plural(filteredChildren, "reason", "reasons")}`
403
+ : undefined,
396
404
 
397
405
  "module.profile.total": (value, { formatTime }) => formatTime(value),
398
406
  "module.profile.resolving": (value, { formatTime }) =>
@@ -590,6 +598,7 @@ const ITEM_NAMES = {
590
598
  "module.modules[]": "module",
591
599
  "module.children[]": "module",
592
600
  "module.reasons[]": "moduleReason",
601
+ "moduleReason.children[]": "moduleReason",
593
602
  "module.issuerPath[]": "moduleIssuer",
594
603
  "chunk.origins[]": "chunkOrigin",
595
604
  "chunk.modules[]": "module",
@@ -721,6 +730,7 @@ const PREFERRED_ORDERS = {
721
730
  "usedExports",
722
731
  "optimizationBailout",
723
732
  "reasons",
733
+ "filteredReasons",
724
734
  "issuerPath",
725
735
  "profile",
726
736
  "modules",
@@ -734,7 +744,9 @@ const PREFERRED_ORDERS = {
734
744
  "module",
735
745
  "resolvedModule",
736
746
  "loc",
737
- "explanation"
747
+ "explanation",
748
+ "children",
749
+ "filteredChildren"
738
750
  ],
739
751
  "module.profile": [
740
752
  "total",
@@ -1019,10 +1031,32 @@ const SIMPLE_ELEMENT_JOINERS = {
1019
1031
  chunkGroupAsset: joinOneLine,
1020
1032
  chunkGroupChildGroup: joinOneLine,
1021
1033
  chunkGroupChild: joinOneLine,
1034
+ // moduleReason: (items, { moduleReason }) => {
1035
+ // let hasName = false;
1036
+ // return joinOneLine(
1037
+ // items.filter(item => {
1038
+ // switch (item.element) {
1039
+ // case "moduleId":
1040
+ // if (moduleReason.moduleId === moduleReason.module && item.content)
1041
+ // hasName = true;
1042
+ // break;
1043
+ // case "module":
1044
+ // if (hasName) return false;
1045
+ // break;
1046
+ // case "resolvedModule":
1047
+ // return (
1048
+ // moduleReason.module !== moduleReason.resolvedModule &&
1049
+ // item.content
1050
+ // );
1051
+ // }
1052
+ // return true;
1053
+ // })
1054
+ // );
1055
+ // },
1022
1056
  moduleReason: (items, { moduleReason }) => {
1023
1057
  let hasName = false;
1024
- return joinOneLine(
1025
- items.filter(item => {
1058
+ return joinExplicitNewLine(
1059
+ items.map(item => {
1026
1060
  switch (item.element) {
1027
1061
  case "moduleId":
1028
1062
  if (moduleReason.moduleId === moduleReason.module && item.content)
@@ -1032,13 +1066,21 @@ const SIMPLE_ELEMENT_JOINERS = {
1032
1066
  if (hasName) return false;
1033
1067
  break;
1034
1068
  case "resolvedModule":
1035
- return (
1036
- moduleReason.module !== moduleReason.resolvedModule &&
1037
- item.content
1038
- );
1069
+ if (moduleReason.module === moduleReason.resolvedModule)
1070
+ return false;
1071
+ break;
1072
+ case "children":
1073
+ if (item.content) {
1074
+ return {
1075
+ ...item,
1076
+ content: `\n${item.content}\n`
1077
+ };
1078
+ }
1079
+ break;
1039
1080
  }
1040
- return true;
1041
- })
1081
+ return item;
1082
+ }),
1083
+ " "
1042
1084
  );
1043
1085
  },
1044
1086
  "module.profile": joinInBrackets,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "5.45.1",
3
+ "version": "5.46.0",
4
4
  "author": "Tobias Koppers @sokra",
5
5
  "description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
6
6
  "license": "MIT",
@@ -27,7 +27,7 @@
27
27
  "tapable": "^2.1.1",
28
28
  "terser-webpack-plugin": "^5.1.3",
29
29
  "watchpack": "^2.2.0",
30
- "webpack-sources": "^2.3.0"
30
+ "webpack-sources": "^2.3.1"
31
31
  },
32
32
  "peerDependenciesMeta": {
33
33
  "webpack-cli": {