webpack 5.51.2 → 5.54.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 (62) hide show
  1. package/lib/AsyncDependenciesBlock.js +9 -2
  2. package/lib/CacheFacade.js +10 -3
  3. package/lib/ChunkGraph.js +19 -8
  4. package/lib/CodeGenerationResults.js +7 -2
  5. package/lib/Compilation.js +207 -16
  6. package/lib/Compiler.js +9 -1
  7. package/lib/DependencyTemplates.js +8 -2
  8. package/lib/EvalDevToolModulePlugin.js +2 -1
  9. package/lib/EvalSourceMapDevToolPlugin.js +2 -1
  10. package/lib/ExternalModule.js +36 -18
  11. package/lib/FileSystemInfo.js +101 -170
  12. package/lib/FlagDependencyExportsPlugin.js +43 -16
  13. package/lib/InitFragment.js +23 -0
  14. package/lib/JavascriptMetaInfoPlugin.js +6 -1
  15. package/lib/MemCache.js +45 -0
  16. package/lib/ModuleFilenameHelpers.js +21 -7
  17. package/lib/NodeStuffInWebError.js +34 -0
  18. package/lib/NodeStuffPlugin.js +59 -16
  19. package/lib/NormalModuleFactory.js +7 -4
  20. package/lib/SourceMapDevToolPlugin.js +7 -3
  21. package/lib/WebpackOptionsApply.js +20 -4
  22. package/lib/cache/PackFileCacheStrategy.js +183 -53
  23. package/lib/cache/getLazyHashedEtag.js +35 -8
  24. package/lib/config/defaults.js +32 -13
  25. package/lib/dependencies/CachedConstDependency.js +4 -3
  26. package/lib/dependencies/ConstDependency.js +12 -4
  27. package/lib/dependencies/JsonExportsDependency.js +7 -1
  28. package/lib/dependencies/LoaderPlugin.js +94 -98
  29. package/lib/dependencies/ModuleDecoratorDependency.js +5 -2
  30. package/lib/dependencies/ProvidedDependency.js +6 -2
  31. package/lib/dependencies/PureExpressionDependency.js +5 -1
  32. package/lib/dependencies/RuntimeRequirementsDependency.js +5 -1
  33. package/lib/ids/IdHelpers.js +21 -8
  34. package/lib/ids/NamedChunkIdsPlugin.js +3 -0
  35. package/lib/ids/NamedModuleIdsPlugin.js +3 -1
  36. package/lib/index.js +6 -0
  37. package/lib/javascript/BasicEvaluatedExpression.js +3 -0
  38. package/lib/javascript/JavascriptParser.js +22 -4
  39. package/lib/javascript/JavascriptParserHelpers.js +0 -2
  40. package/lib/node/NodeTargetPlugin.js +1 -0
  41. package/lib/optimize/ConcatenatedModule.js +25 -4
  42. package/lib/optimize/InnerGraph.js +22 -2
  43. package/lib/optimize/MangleExportsPlugin.js +21 -4
  44. package/lib/optimize/ModuleConcatenationPlugin.js +2 -1
  45. package/lib/runtime/RelativeUrlRuntimeModule.js +1 -1
  46. package/lib/schemes/HttpUriPlugin.js +1 -2
  47. package/lib/serialization/BinaryMiddleware.js +11 -2
  48. package/lib/serialization/FileMiddleware.js +24 -7
  49. package/lib/serialization/ObjectMiddleware.js +23 -12
  50. package/lib/util/createHash.js +10 -0
  51. package/lib/util/hash/BatchedHash.js +65 -0
  52. package/lib/util/hash/xxhash64.js +154 -0
  53. package/lib/util/internalSerializables.js +2 -0
  54. package/lib/util/serialization.js +10 -6
  55. package/package.json +13 -9
  56. package/schemas/WebpackOptions.check.js +1 -1
  57. package/schemas/WebpackOptions.json +17 -5
  58. package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
  59. package/schemas/plugins/HashedModuleIdsPlugin.json +20 -2
  60. package/schemas/plugins/IgnorePlugin.check.js +1 -1
  61. package/schemas/plugins/IgnorePlugin.json +4 -2
  62. package/types.d.ts +166 -17
@@ -30,6 +30,7 @@ class ConstDependency extends NullDependency {
30
30
  this.runtimeRequirements = runtimeRequirements
31
31
  ? new Set(runtimeRequirements)
32
32
  : null;
33
+ this._hashUpdate = undefined;
33
34
  }
34
35
 
35
36
  /**
@@ -39,10 +40,17 @@ class ConstDependency extends NullDependency {
39
40
  * @returns {void}
40
41
  */
41
42
  updateHash(hash, context) {
42
- hash.update(this.range + "");
43
- hash.update(this.expression + "");
44
- if (this.runtimeRequirements)
45
- hash.update(Array.from(this.runtimeRequirements).join() + "");
43
+ if (this._hashUpdate === undefined) {
44
+ let hashUpdate = "" + this.range + "|" + this.expression;
45
+ if (this.runtimeRequirements) {
46
+ for (const item of this.runtimeRequirements) {
47
+ hashUpdate += "|";
48
+ hashUpdate += item;
49
+ }
50
+ }
51
+ this._hashUpdate = hashUpdate;
52
+ }
53
+ hash.update(this._hashUpdate);
46
54
  }
47
55
 
48
56
  /**
@@ -47,6 +47,7 @@ class JsonExportsDependency extends NullDependency {
47
47
  constructor(exports) {
48
48
  super();
49
49
  this.exports = exports;
50
+ this._hashUpdate = undefined;
50
51
  }
51
52
 
52
53
  get type() {
@@ -72,7 +73,12 @@ class JsonExportsDependency extends NullDependency {
72
73
  * @returns {void}
73
74
  */
74
75
  updateHash(hash, context) {
75
- hash.update(this.exports ? JSON.stringify(this.exports) : "undefined");
76
+ if (this._hashUpdate === undefined) {
77
+ this._hashUpdate = this.exports
78
+ ? JSON.stringify(this.exports)
79
+ : "undefined";
80
+ }
81
+ hash.update(this._hashUpdate);
76
82
  }
77
83
 
78
84
  serialize(context) {
@@ -37,11 +37,9 @@ const LoaderImportDependency = require("./LoaderImportDependency");
37
37
  class LoaderPlugin {
38
38
  /**
39
39
  * @param {Object} options options
40
- * @param {boolean=} options.enableExecuteModule execute module enabled
41
40
  */
42
- constructor(options = {}) {
43
- this._enableExecuteModule = !!options.enableExecuteModule;
44
- }
41
+ constructor(options = {}) {}
42
+
45
43
  /**
46
44
  * Apply the plugin
47
45
  * @param {Compiler} compiler the compiler instance
@@ -155,106 +153,104 @@ class LoaderPlugin {
155
153
  );
156
154
  };
157
155
 
158
- if (this._enableExecuteModule) {
159
- /**
160
- * @param {string} request the request string to load the module from
161
- * @param {ImportModuleOptions=} options options
162
- * @param {ImportModuleCallback=} callback callback returning the exports
163
- * @returns {void}
164
- */
165
- const importModule = (request, options, callback) => {
166
- const dep = new LoaderImportDependency(request);
167
- dep.loc = {
168
- name: request
169
- };
170
- const factory = compilation.dependencyFactories.get(
171
- /** @type {DepConstructor} */ (dep.constructor)
156
+ /**
157
+ * @param {string} request the request string to load the module from
158
+ * @param {ImportModuleOptions=} options options
159
+ * @param {ImportModuleCallback=} callback callback returning the exports
160
+ * @returns {void}
161
+ */
162
+ const importModule = (request, options, callback) => {
163
+ const dep = new LoaderImportDependency(request);
164
+ dep.loc = {
165
+ name: request
166
+ };
167
+ const factory = compilation.dependencyFactories.get(
168
+ /** @type {DepConstructor} */ (dep.constructor)
169
+ );
170
+ if (factory === undefined) {
171
+ return callback(
172
+ new Error(
173
+ `No module factory available for dependency type: ${dep.constructor.name}`
174
+ )
172
175
  );
173
- if (factory === undefined) {
174
- return callback(
175
- new Error(
176
- `No module factory available for dependency type: ${dep.constructor.name}`
177
- )
178
- );
179
- }
180
- compilation.buildQueue.increaseParallelism();
181
- compilation.handleModuleCreation(
182
- {
183
- factory,
184
- dependencies: [dep],
185
- originModule: loaderContext._module,
186
- contextInfo: {
187
- issuerLayer: options.layer
188
- },
189
- context: loaderContext.context,
190
- connectOrigin: false
176
+ }
177
+ compilation.buildQueue.increaseParallelism();
178
+ compilation.handleModuleCreation(
179
+ {
180
+ factory,
181
+ dependencies: [dep],
182
+ originModule: loaderContext._module,
183
+ contextInfo: {
184
+ issuerLayer: options.layer
191
185
  },
192
- err => {
193
- compilation.buildQueue.decreaseParallelism();
194
- if (err) {
195
- return callback(err);
196
- }
197
- const referencedModule = moduleGraph.getModule(dep);
198
- if (!referencedModule) {
199
- return callback(new Error("Cannot load the module"));
200
- }
201
- compilation.executeModule(
202
- referencedModule,
203
- {
204
- entryOptions: {
205
- publicPath: options.publicPath
206
- }
207
- },
208
- (err, result) => {
209
- if (err) return callback(err);
210
- for (const d of result.fileDependencies) {
211
- loaderContext.addDependency(d);
212
- }
213
- for (const d of result.contextDependencies) {
214
- loaderContext.addContextDependency(d);
215
- }
216
- for (const d of result.missingDependencies) {
217
- loaderContext.addMissingDependency(d);
218
- }
219
- for (const d of result.buildDependencies) {
220
- loaderContext.addBuildDependency(d);
221
- }
222
- if (result.cacheable === false)
223
- loaderContext.cacheable(false);
224
- for (const [name, { source, info }] of result.assets) {
225
- const { buildInfo } = loaderContext._module;
226
- if (!buildInfo.assets) {
227
- buildInfo.assets = Object.create(null);
228
- buildInfo.assetsInfo = new Map();
229
- }
230
- buildInfo.assets[name] = source;
231
- buildInfo.assetsInfo.set(name, info);
186
+ context: loaderContext.context,
187
+ connectOrigin: false
188
+ },
189
+ err => {
190
+ compilation.buildQueue.decreaseParallelism();
191
+ if (err) {
192
+ return callback(err);
193
+ }
194
+ const referencedModule = moduleGraph.getModule(dep);
195
+ if (!referencedModule) {
196
+ return callback(new Error("Cannot load the module"));
197
+ }
198
+ compilation.executeModule(
199
+ referencedModule,
200
+ {
201
+ entryOptions: {
202
+ publicPath: options.publicPath
203
+ }
204
+ },
205
+ (err, result) => {
206
+ if (err) return callback(err);
207
+ for (const d of result.fileDependencies) {
208
+ loaderContext.addDependency(d);
209
+ }
210
+ for (const d of result.contextDependencies) {
211
+ loaderContext.addContextDependency(d);
212
+ }
213
+ for (const d of result.missingDependencies) {
214
+ loaderContext.addMissingDependency(d);
215
+ }
216
+ for (const d of result.buildDependencies) {
217
+ loaderContext.addBuildDependency(d);
218
+ }
219
+ if (result.cacheable === false)
220
+ loaderContext.cacheable(false);
221
+ for (const [name, { source, info }] of result.assets) {
222
+ const { buildInfo } = loaderContext._module;
223
+ if (!buildInfo.assets) {
224
+ buildInfo.assets = Object.create(null);
225
+ buildInfo.assetsInfo = new Map();
232
226
  }
233
- callback(null, result.exports);
227
+ buildInfo.assets[name] = source;
228
+ buildInfo.assetsInfo.set(name, info);
234
229
  }
235
- );
236
- }
237
- );
238
- };
230
+ callback(null, result.exports);
231
+ }
232
+ );
233
+ }
234
+ );
235
+ };
239
236
 
240
- /**
241
- * @param {string} request the request string to load the module from
242
- * @param {ImportModuleOptions} options options
243
- * @param {ImportModuleCallback=} callback callback returning the exports
244
- * @returns {Promise<any> | void} exports
245
- */
246
- loaderContext.importModule = (request, options, callback) => {
247
- if (!callback) {
248
- return new Promise((resolve, reject) => {
249
- importModule(request, options || {}, (err, result) => {
250
- if (err) reject(err);
251
- else resolve(result);
252
- });
237
+ /**
238
+ * @param {string} request the request string to load the module from
239
+ * @param {ImportModuleOptions} options options
240
+ * @param {ImportModuleCallback=} callback callback returning the exports
241
+ * @returns {Promise<any> | void} exports
242
+ */
243
+ loaderContext.importModule = (request, options, callback) => {
244
+ if (!callback) {
245
+ return new Promise((resolve, reject) => {
246
+ importModule(request, options || {}, (err, result) => {
247
+ if (err) reject(err);
248
+ else resolve(result);
253
249
  });
254
- }
255
- return importModule(request, options || {}, callback);
256
- };
257
- }
250
+ });
251
+ }
252
+ return importModule(request, options || {}, callback);
253
+ };
258
254
  }
259
255
  );
260
256
  });
@@ -30,6 +30,7 @@ class ModuleDecoratorDependency extends NullDependency {
30
30
  super();
31
31
  this.decorator = decorator;
32
32
  this.allowExportsAccess = allowExportsAccess;
33
+ this._hashUpdate = undefined;
33
34
  }
34
35
 
35
36
  /**
@@ -69,8 +70,10 @@ class ModuleDecoratorDependency extends NullDependency {
69
70
  * @returns {void}
70
71
  */
71
72
  updateHash(hash, context) {
72
- hash.update(this.decorator);
73
- hash.update(`${this.allowExportsAccess}`);
73
+ if (this._hashUpdate === undefined) {
74
+ this._hashUpdate = `${this.decorator}${this.allowExportsAccess}`;
75
+ }
76
+ hash.update(this._hashUpdate);
74
77
  }
75
78
 
76
79
  serialize(context) {
@@ -34,6 +34,7 @@ class ProvidedDependency extends ModuleDependency {
34
34
  this.identifier = identifier;
35
35
  this.path = path;
36
36
  this.range = range;
37
+ this._hashUpdate = undefined;
37
38
  }
38
39
 
39
40
  get type() {
@@ -51,8 +52,11 @@ class ProvidedDependency extends ModuleDependency {
51
52
  * @returns {void}
52
53
  */
53
54
  updateHash(hash, context) {
54
- hash.update(this.identifier);
55
- hash.update(this.path ? this.path.join(",") : "null");
55
+ if (this._hashUpdate === undefined) {
56
+ this._hashUpdate =
57
+ this.identifier + (this.path ? this.path.join(",") : "null");
58
+ }
59
+ hash.update(this._hashUpdate);
56
60
  }
57
61
 
58
62
  serialize(context) {
@@ -28,6 +28,7 @@ class PureExpressionDependency extends NullDependency {
28
28
  this.range = range;
29
29
  /** @type {Set<string> | false} */
30
30
  this.usedByExports = false;
31
+ this._hashUpdate = undefined;
31
32
  }
32
33
 
33
34
  /**
@@ -37,7 +38,10 @@ class PureExpressionDependency extends NullDependency {
37
38
  * @returns {void}
38
39
  */
39
40
  updateHash(hash, context) {
40
- hash.update(this.range + "");
41
+ if (this._hashUpdate === undefined) {
42
+ this._hashUpdate = this.range + "";
43
+ }
44
+ hash.update(this._hashUpdate);
41
45
  }
42
46
 
43
47
  /**
@@ -23,6 +23,7 @@ class RuntimeRequirementsDependency extends NullDependency {
23
23
  constructor(runtimeRequirements) {
24
24
  super();
25
25
  this.runtimeRequirements = new Set(runtimeRequirements);
26
+ this._hashUpdate = undefined;
26
27
  }
27
28
 
28
29
  /**
@@ -32,7 +33,10 @@ class RuntimeRequirementsDependency extends NullDependency {
32
33
  * @returns {void}
33
34
  */
34
35
  updateHash(hash, context) {
35
- hash.update(Array.from(this.runtimeRequirements).join() + "");
36
+ if (this._hashUpdate === undefined) {
37
+ this._hashUpdate = Array.from(this.runtimeRequirements).join() + "";
38
+ }
39
+ hash.update(this._hashUpdate);
36
40
  }
37
41
 
38
42
  serialize(context) {
@@ -13,14 +13,16 @@ const numberHash = require("../util/numberHash");
13
13
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
14
14
  /** @typedef {import("../Compilation")} Compilation */
15
15
  /** @typedef {import("../Module")} Module */
16
+ /** @typedef {typeof import("../util/Hash")} Hash */
16
17
 
17
18
  /**
18
19
  * @param {string} str string to hash
19
20
  * @param {number} len max length of the hash
21
+ * @param {string | Hash} hashFunction hash function to use
20
22
  * @returns {string} hash
21
23
  */
22
- const getHash = (str, len) => {
23
- const hash = createHash("md4");
24
+ const getHash = (str, len, hashFunction) => {
25
+ const hash = createHash(hashFunction);
24
26
  hash.update(str);
25
27
  const digest = /** @type {string} */ (hash.digest("hex"));
26
28
  return digest.substr(0, len);
@@ -61,12 +63,15 @@ exports.requestToId = requestToId;
61
63
  /**
62
64
  * @param {string} string the string
63
65
  * @param {string} delimiter separator for string and hash
66
+ * @param {string | Hash} hashFunction hash function to use
64
67
  * @returns {string} string with limited max length to 100 chars
65
68
  */
66
- const shortenLongString = (string, delimiter) => {
69
+ const shortenLongString = (string, delimiter, hashFunction) => {
67
70
  if (string.length < 100) return string;
68
71
  return (
69
- string.slice(0, 100 - 6 - delimiter.length) + delimiter + getHash(string, 6)
72
+ string.slice(0, 100 - 6 - delimiter.length) +
73
+ delimiter +
74
+ getHash(string, 6, hashFunction)
70
75
  );
71
76
  };
72
77
 
@@ -92,6 +97,7 @@ exports.getShortModuleName = getShortModuleName;
92
97
  * @param {string} shortName the short name
93
98
  * @param {Module} module the module
94
99
  * @param {string} context context directory
100
+ * @param {string | Hash} hashFunction hash function to use
95
101
  * @param {Object=} associatedObjectForCache an object to which the cache will be attached
96
102
  * @returns {string} long module name
97
103
  */
@@ -99,10 +105,11 @@ const getLongModuleName = (
99
105
  shortName,
100
106
  module,
101
107
  context,
108
+ hashFunction,
102
109
  associatedObjectForCache
103
110
  ) => {
104
111
  const fullName = getFullModuleName(module, context, associatedObjectForCache);
105
- return `${shortName}?${getHash(fullName, 4)}`;
112
+ return `${shortName}?${getHash(fullName, 4, hashFunction)}`;
106
113
  };
107
114
  exports.getLongModuleName = getLongModuleName;
108
115
 
@@ -126,6 +133,7 @@ exports.getFullModuleName = getFullModuleName;
126
133
  * @param {ChunkGraph} chunkGraph the chunk graph
127
134
  * @param {string} context context directory
128
135
  * @param {string} delimiter delimiter for names
136
+ * @param {string | Hash} hashFunction hash function to use
129
137
  * @param {Object=} associatedObjectForCache an object to which the cache will be attached
130
138
  * @returns {string} short chunk name
131
139
  */
@@ -134,6 +142,7 @@ const getShortChunkName = (
134
142
  chunkGraph,
135
143
  context,
136
144
  delimiter,
145
+ hashFunction,
137
146
  associatedObjectForCache
138
147
  ) => {
139
148
  const modules = chunkGraph.getChunkRootModules(chunk);
@@ -145,7 +154,7 @@ const getShortChunkName = (
145
154
  .concat(shortModuleNames)
146
155
  .filter(Boolean)
147
156
  .join(delimiter);
148
- return shortenLongString(chunkName, delimiter);
157
+ return shortenLongString(chunkName, delimiter, hashFunction);
149
158
  };
150
159
  exports.getShortChunkName = getShortChunkName;
151
160
 
@@ -154,6 +163,7 @@ exports.getShortChunkName = getShortChunkName;
154
163
  * @param {ChunkGraph} chunkGraph the chunk graph
155
164
  * @param {string} context context directory
156
165
  * @param {string} delimiter delimiter for names
166
+ * @param {string | Hash} hashFunction hash function to use
157
167
  * @param {Object=} associatedObjectForCache an object to which the cache will be attached
158
168
  * @returns {string} short chunk name
159
169
  */
@@ -162,6 +172,7 @@ const getLongChunkName = (
162
172
  chunkGraph,
163
173
  context,
164
174
  delimiter,
175
+ hashFunction,
165
176
  associatedObjectForCache
166
177
  ) => {
167
178
  const modules = chunkGraph.getChunkRootModules(chunk);
@@ -169,14 +180,16 @@ const getLongChunkName = (
169
180
  requestToId(getShortModuleName(m, context, associatedObjectForCache))
170
181
  );
171
182
  const longModuleNames = modules.map(m =>
172
- requestToId(getLongModuleName("", m, context, associatedObjectForCache))
183
+ requestToId(
184
+ getLongModuleName("", m, context, hashFunction, associatedObjectForCache)
185
+ )
173
186
  );
174
187
  chunk.idNameHints.sort();
175
188
  const chunkName = Array.from(chunk.idNameHints)
176
189
  .concat(shortModuleNames, longModuleNames)
177
190
  .filter(Boolean)
178
191
  .join(delimiter);
179
- return shortenLongString(chunkName, delimiter);
192
+ return shortenLongString(chunkName, delimiter, hashFunction);
180
193
  };
181
194
  exports.getLongChunkName = getLongChunkName;
182
195
 
@@ -31,6 +31,7 @@ class NamedChunkIdsPlugin {
31
31
  */
32
32
  apply(compiler) {
33
33
  compiler.hooks.compilation.tap("NamedChunkIdsPlugin", compilation => {
34
+ const { hashFunction } = compilation.outputOptions;
34
35
  compilation.hooks.chunkIds.tap("NamedChunkIdsPlugin", chunks => {
35
36
  const chunkGraph = compilation.chunkGraph;
36
37
  const context = this.context ? this.context : compiler.context;
@@ -50,6 +51,7 @@ class NamedChunkIdsPlugin {
50
51
  chunkGraph,
51
52
  context,
52
53
  delimiter,
54
+ hashFunction,
53
55
  compiler.root
54
56
  ),
55
57
  chunk =>
@@ -58,6 +60,7 @@ class NamedChunkIdsPlugin {
58
60
  chunkGraph,
59
61
  context,
60
62
  delimiter,
63
+ hashFunction,
61
64
  compiler.root
62
65
  ),
63
66
  compareChunksNatural(chunkGraph),
@@ -30,6 +30,7 @@ class NamedModuleIdsPlugin {
30
30
  apply(compiler) {
31
31
  const { root } = compiler;
32
32
  compiler.hooks.compilation.tap("NamedModuleIdsPlugin", compilation => {
33
+ const { hashFunction } = compilation.outputOptions;
33
34
  compilation.hooks.moduleIds.tap("NamedModuleIdsPlugin", modules => {
34
35
  const chunkGraph = compilation.chunkGraph;
35
36
  const context = this.options.context
@@ -43,7 +44,8 @@ class NamedModuleIdsPlugin {
43
44
  return chunkGraph.getModuleId(module) === null;
44
45
  }),
45
46
  m => getShortModuleName(m, context, root),
46
- (m, shortName) => getLongModuleName(shortName, m, context, root),
47
+ (m, shortName) =>
48
+ getLongModuleName(shortName, m, context, hashFunction, root),
47
49
  compareModulesByIdentifier,
48
50
  getUsedModuleIds(compilation),
49
51
  (m, name) => chunkGraph.setModuleId(m, name)
package/lib/index.js CHANGED
@@ -394,6 +394,9 @@ module.exports = mergeExports(fn, {
394
394
  "DEP_WEBPACK_AGGRESSIVE_SPLITTING_PLUGIN"
395
395
  )();
396
396
  },
397
+ get InnerGraph() {
398
+ return require("./optimize/InnerGraph");
399
+ },
397
400
  get LimitChunkCountPlugin() {
398
401
  return require("./optimize/LimitChunkCountPlugin");
399
402
  },
@@ -535,6 +538,9 @@ module.exports = mergeExports(fn, {
535
538
  get comparators() {
536
539
  return require("./util/comparators");
537
540
  },
541
+ get runtime() {
542
+ return require("./util/runtime");
543
+ },
538
544
  get serialization() {
539
545
  return require("./util/serialization");
540
546
  },
@@ -417,6 +417,9 @@ class BasicEvaluatedExpression {
417
417
 
418
418
  setNullish(value) {
419
419
  this.nullish = value;
420
+
421
+ if (value) return this.setFalsy();
422
+
420
423
  return this;
421
424
  }
422
425
 
@@ -417,23 +417,41 @@ class JavascriptParser extends Parser {
417
417
 
418
418
  const left = this.evaluateExpression(expr.left);
419
419
  if (!left) return;
420
+ let returnRight = false;
421
+ /** @type {boolean|undefined} */
422
+ let allowedRight;
420
423
  if (expr.operator === "&&") {
421
424
  const leftAsBool = left.asBool();
422
425
  if (leftAsBool === false) return left.setRange(expr.range);
423
- if (leftAsBool !== true) return;
426
+ returnRight = leftAsBool === true;
427
+ allowedRight = false;
424
428
  } else if (expr.operator === "||") {
425
429
  const leftAsBool = left.asBool();
426
430
  if (leftAsBool === true) return left.setRange(expr.range);
427
- if (leftAsBool !== false) return;
431
+ returnRight = leftAsBool === false;
432
+ allowedRight = true;
428
433
  } else if (expr.operator === "??") {
429
434
  const leftAsNullish = left.asNullish();
430
435
  if (leftAsNullish === false) return left.setRange(expr.range);
431
436
  if (leftAsNullish !== true) return;
437
+ returnRight = true;
432
438
  } else return;
433
439
  const right = this.evaluateExpression(expr.right);
434
440
  if (!right) return;
435
- if (left.couldHaveSideEffects()) right.setSideEffects();
436
- return right.setRange(expr.range);
441
+ if (returnRight) {
442
+ if (left.couldHaveSideEffects()) right.setSideEffects();
443
+ return right.setRange(expr.range);
444
+ }
445
+
446
+ const asBool = right.asBool();
447
+
448
+ if (allowedRight === true && asBool === true) {
449
+ return new BasicEvaluatedExpression()
450
+ .setRange(expr.range)
451
+ .setTruthy();
452
+ } else if (allowedRight === false && asBool === false) {
453
+ return new BasicEvaluatedExpression().setRange(expr.range).setFalsy();
454
+ }
437
455
  });
438
456
 
439
457
  const valueAsExpression = (value, expr, sideEffects) => {
@@ -76,10 +76,8 @@ exports.evaluateToIdentifier = (identifier, rootInfo, getMembers, truthy) => {
76
76
  switch (truthy) {
77
77
  case true:
78
78
  evaluatedExpression.setTruthy();
79
- evaluatedExpression.setNullish(false);
80
79
  break;
81
80
  case null:
82
- evaluatedExpression.setFalsy();
83
81
  evaluatedExpression.setNullish(true);
84
82
  break;
85
83
  case false:
@@ -41,6 +41,7 @@ const builtins = [
41
41
  "repl",
42
42
  "stream",
43
43
  "stream/promises",
44
+ "stream/web",
44
45
  "string_decoder",
45
46
  "sys",
46
47
  "timers",
@@ -58,6 +58,7 @@ const {
58
58
  /** @typedef {import("../WebpackError")} WebpackError */
59
59
  /** @typedef {import("../javascript/JavascriptModulesPlugin").ChunkRenderContext} ChunkRenderContext */
60
60
  /** @typedef {import("../util/Hash")} Hash */
61
+ /** @typedef {typeof import("../util/Hash")} HashConstructor */
61
62
  /** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
62
63
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
63
64
 
@@ -647,13 +648,21 @@ class ConcatenatedModule extends Module {
647
648
  * @param {Set<Module>} modules all modules in the concatenation (including the root module)
648
649
  * @param {RuntimeSpec} runtime the runtime
649
650
  * @param {Object=} associatedObjectForCache object for caching
651
+ * @param {string | HashConstructor=} hashFunction hash function to use
650
652
  * @returns {ConcatenatedModule} the module
651
653
  */
652
- static create(rootModule, modules, runtime, associatedObjectForCache) {
654
+ static create(
655
+ rootModule,
656
+ modules,
657
+ runtime,
658
+ associatedObjectForCache,
659
+ hashFunction = "md4"
660
+ ) {
653
661
  const identifier = ConcatenatedModule._createIdentifier(
654
662
  rootModule,
655
663
  modules,
656
- associatedObjectForCache
664
+ associatedObjectForCache,
665
+ hashFunction
657
666
  );
658
667
  return new ConcatenatedModule({
659
668
  identifier,
@@ -1010,7 +1019,19 @@ class ConcatenatedModule extends Module {
1010
1019
  return list;
1011
1020
  }
1012
1021
 
1013
- static _createIdentifier(rootModule, modules, associatedObjectForCache) {
1022
+ /**
1023
+ * @param {Module} rootModule the root module of the concatenation
1024
+ * @param {Set<Module>} modules all modules in the concatenation (including the root module)
1025
+ * @param {Object=} associatedObjectForCache object for caching
1026
+ * @param {string | HashConstructor=} hashFunction hash function to use
1027
+ * @returns {string} the identifier
1028
+ */
1029
+ static _createIdentifier(
1030
+ rootModule,
1031
+ modules,
1032
+ associatedObjectForCache,
1033
+ hashFunction = "md4"
1034
+ ) {
1014
1035
  const cachedMakePathsRelative = makePathsRelative.bindContextCache(
1015
1036
  rootModule.context,
1016
1037
  associatedObjectForCache
@@ -1020,7 +1041,7 @@ class ConcatenatedModule extends Module {
1020
1041
  identifiers.push(cachedMakePathsRelative(module.identifier()));
1021
1042
  }
1022
1043
  identifiers.sort();
1023
- const hash = createHash("md4");
1044
+ const hash = createHash(hashFunction);
1024
1045
  hash.update(identifiers.join(" "));
1025
1046
  return rootModule.identifier() + "|" + hash.digest("hex");
1026
1047
  }