webpack 5.55.0 → 5.55.1

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.

@@ -78,7 +78,7 @@ const {
78
78
  createFakeHook
79
79
  } = require("./util/deprecation");
80
80
  const processAsyncTree = require("./util/processAsyncTree");
81
- const { getRuntimeKey, RuntimeSpecMap } = require("./util/runtime");
81
+ const { getRuntimeKey } = require("./util/runtime");
82
82
  const { isSourceEqual } = require("./util/source");
83
83
 
84
84
  /** @template T @typedef {import("tapable").AsArray<T>} AsArray<T> */
@@ -2178,7 +2178,39 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2178
2178
  let statNew = 0;
2179
2179
  let statChanged = 0;
2180
2180
  let statUnchanged = 0;
2181
+ let statReferencesChanged = 0;
2181
2182
  let statWithoutHash = 0;
2183
+
2184
+ const computeReferences = module => {
2185
+ /** @type {WeakMap<Dependency, Module>} */
2186
+ let references = undefined;
2187
+ for (const connection of moduleGraph.getOutgoingConnections(module)) {
2188
+ const d = connection.dependency;
2189
+ const m = connection.module;
2190
+ if (!d || !m || unsafeCacheDependencies.has(d)) continue;
2191
+ if (references === undefined) references = new WeakMap();
2192
+ references.set(d, m);
2193
+ }
2194
+ return references;
2195
+ };
2196
+
2197
+ /**
2198
+ * @param {Module} module the module
2199
+ * @param {WeakMap<Dependency, Module>} references references
2200
+ * @returns {boolean} true, when the references differ
2201
+ */
2202
+ const compareReferences = (module, references) => {
2203
+ if (references === undefined) return true;
2204
+ for (const connection of moduleGraph.getOutgoingConnections(module)) {
2205
+ const d = connection.dependency;
2206
+ if (!d) continue;
2207
+ const entry = references.get(d);
2208
+ if (entry === undefined) continue;
2209
+ if (entry !== connection.module) return false;
2210
+ }
2211
+ return true;
2212
+ };
2213
+
2182
2214
  for (const module of modules) {
2183
2215
  const hash = module.buildInfo && module.buildInfo.hash;
2184
2216
  if (typeof hash === "string") {
@@ -2188,27 +2220,33 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2188
2220
  const memCache = new WeakTupleMap();
2189
2221
  moduleMemCacheCache.set(module, {
2190
2222
  hash: hash,
2223
+ references: computeReferences(module),
2191
2224
  memCache
2192
2225
  });
2193
2226
  moduleMemCaches.set(module, memCache);
2194
2227
  affectedModules.add(module);
2195
2228
  statNew++;
2196
- } else if (cachedMemCache.hash === hash) {
2197
- // keep the old mem cache
2198
- moduleMemCaches.set(module, cachedMemCache.memCache);
2199
- statUnchanged++;
2200
- } else {
2229
+ } else if (cachedMemCache.hash !== hash) {
2201
2230
  // use a new one
2202
2231
  const memCache = new WeakTupleMap();
2203
- moduleMemCacheCache.set(module, {
2204
- hash: hash,
2205
- memCache
2206
- });
2207
2232
  moduleMemCaches.set(module, memCache);
2208
2233
  affectedModules.add(module);
2209
2234
  cachedMemCache.hash = hash;
2235
+ cachedMemCache.references = computeReferences(module);
2210
2236
  cachedMemCache.memCache = memCache;
2211
2237
  statChanged++;
2238
+ } else if (!compareReferences(module, cachedMemCache.references)) {
2239
+ // use a new one
2240
+ const memCache = new WeakTupleMap();
2241
+ moduleMemCaches.set(module, memCache);
2242
+ affectedModules.add(module);
2243
+ cachedMemCache.references = computeReferences(module);
2244
+ cachedMemCache.memCache = memCache;
2245
+ statReferencesChanged++;
2246
+ } else {
2247
+ // keep the old mem cache
2248
+ moduleMemCaches.set(module, cachedMemCache.memCache);
2249
+ statUnchanged++;
2212
2250
  }
2213
2251
  } else {
2214
2252
  infectedModules.add(module);
@@ -2261,7 +2299,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2261
2299
  affectedModules.add(referencingModule);
2262
2300
  }
2263
2301
  const memCache = new WeakTupleMap();
2264
- const cache = moduleMemCacheCache.get(module);
2302
+ const cache = moduleMemCacheCache.get(referencingModule);
2265
2303
  cache.memCache = memCache;
2266
2304
  moduleMemCaches.set(referencingModule, memCache);
2267
2305
  }
@@ -2275,7 +2313,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2275
2313
  infectedModules.size
2276
2314
  } infected of ${
2277
2315
  this.modules.size
2278
- }) modules flagged as affected (${statNew} new modules, ${statChanged} changed, ${statUnchanged} unchanged, ${statWithoutHash} without hash)`
2316
+ }) modules flagged as affected (${statNew} new modules, ${statChanged} changed, ${statReferencesChanged} references changed, ${statUnchanged} unchanged, ${statWithoutHash} without hash)`
2279
2317
  );
2280
2318
  }
2281
2319
 
@@ -3095,16 +3133,11 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3095
3133
  // modules with async blocks depend on the chunk graph and can't be cached that way
3096
3134
  module.blocks.length === 0 &&
3097
3135
  moduleMemCaches.get(module);
3098
- /** @type {RuntimeSpecMap<Set<string>>} */
3099
- const moduleRuntimeRequirementsMemCache =
3100
- memCache &&
3101
- memCache.provide(
3102
- "moduleRuntimeRequirements",
3103
- () => new RuntimeSpecMap()
3104
- );
3105
3136
  for (const runtime of chunkGraph.getModuleRuntimes(module)) {
3106
- if (moduleRuntimeRequirementsMemCache) {
3107
- const cached = moduleRuntimeRequirementsMemCache.get(runtime);
3137
+ if (memCache) {
3138
+ const cached = memCache.get(
3139
+ `moduleRuntimeRequirements-${getRuntimeKey(runtime)}`
3140
+ );
3108
3141
  if (cached !== undefined) {
3109
3142
  if (cached !== null) {
3110
3143
  chunkGraph.addModuleRuntimeRequirements(
@@ -3125,8 +3158,11 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3125
3158
  } else if (additionalModuleRuntimeRequirements.isUsed()) {
3126
3159
  set = new Set();
3127
3160
  } else {
3128
- if (moduleRuntimeRequirementsMemCache) {
3129
- moduleRuntimeRequirementsMemCache.set(runtime, null);
3161
+ if (memCache) {
3162
+ memCache.set(
3163
+ `moduleRuntimeRequirements-${getRuntimeKey(runtime)}`,
3164
+ null
3165
+ );
3130
3166
  }
3131
3167
  continue;
3132
3168
  }
@@ -3137,12 +3173,18 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3137
3173
  if (hook !== undefined) hook.call(module, set, context);
3138
3174
  }
3139
3175
  if (set.size === 0) {
3140
- if (moduleRuntimeRequirementsMemCache) {
3141
- moduleRuntimeRequirementsMemCache.set(runtime, null);
3176
+ if (memCache) {
3177
+ memCache.set(
3178
+ `moduleRuntimeRequirements-${getRuntimeKey(runtime)}`,
3179
+ null
3180
+ );
3142
3181
  }
3143
3182
  } else {
3144
- if (moduleRuntimeRequirementsMemCache) {
3145
- moduleRuntimeRequirementsMemCache.set(runtime, set);
3183
+ if (memCache) {
3184
+ memCache.set(
3185
+ `moduleRuntimeRequirements-${getRuntimeKey(runtime)}`,
3186
+ set
3187
+ );
3146
3188
  chunkGraph.addModuleRuntimeRequirements(
3147
3189
  module,
3148
3190
  runtime,
@@ -3555,13 +3597,9 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3555
3597
  // modules with async blocks depend on the chunk graph and can't be cached that way
3556
3598
  module.blocks.length === 0 &&
3557
3599
  moduleMemCaches.get(module);
3558
- /** @type {RuntimeSpecMap<string>} */
3559
- const moduleHashesMemCache =
3560
- memCache &&
3561
- memCache.provide("moduleHashes", () => new RuntimeSpecMap());
3562
3600
  for (const runtime of chunkGraph.getModuleRuntimes(module)) {
3563
- if (moduleHashesMemCache) {
3564
- const digest = moduleHashesMemCache.get(runtime);
3601
+ if (memCache) {
3602
+ const digest = memCache.get(`moduleHash-${getRuntimeKey(runtime)}`);
3565
3603
  if (digest !== undefined) {
3566
3604
  chunkGraph.setModuleHashes(
3567
3605
  module,
@@ -3583,8 +3621,8 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3583
3621
  hashDigest,
3584
3622
  hashDigestLength
3585
3623
  );
3586
- if (moduleHashesMemCache) {
3587
- moduleHashesMemCache.set(runtime, digest);
3624
+ if (memCache) {
3625
+ memCache.set(`moduleHash-${getRuntimeKey(runtime)}`, digest);
3588
3626
  }
3589
3627
  }
3590
3628
  }
package/lib/Compiler.js CHANGED
@@ -40,6 +40,7 @@ const { isSourceEqual } = require("./util/source");
40
40
  /** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
41
41
  /** @typedef {import("../declarations/WebpackOptions").WebpackPluginInstance} WebpackPluginInstance */
42
42
  /** @typedef {import("./Chunk")} Chunk */
43
+ /** @typedef {import("./Dependency")} Dependency */
43
44
  /** @typedef {import("./FileSystemInfo").FileSystemInfoEntry} FileSystemInfoEntry */
44
45
  /** @typedef {import("./Module")} Module */
45
46
  /** @typedef {import("./util/WeakTupleMap")} WeakTupleMap */
@@ -248,7 +249,7 @@ class Compiler {
248
249
 
249
250
  this.cache = new Cache();
250
251
 
251
- /** @type {WeakMap<Module, { hash: string, memCache: WeakTupleMap }> | undefined} */
252
+ /** @type {WeakMap<Module, { hash: string, references: WeakMap<Dependency, Module>, memCache: WeakTupleMap }> | undefined} */
252
253
  this.moduleMemCaches = undefined;
253
254
 
254
255
  this.compilerPath = "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "5.55.0",
3
+ "version": "5.55.1",
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",
package/types.d.ts CHANGED
@@ -1909,7 +1909,11 @@ declare class Compiler {
1909
1909
  cache: Cache;
1910
1910
  moduleMemCaches?: WeakMap<
1911
1911
  Module,
1912
- { hash: string; memCache: WeakTupleMap<any, any> }
1912
+ {
1913
+ hash: string;
1914
+ references: WeakMap<Dependency, Module>;
1915
+ memCache: WeakTupleMap<any, any>;
1916
+ }
1913
1917
  >;
1914
1918
  compilerPath: string;
1915
1919
  running: boolean;