webpack 5.54.0 → 5.56.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.

@@ -15,6 +15,7 @@ const { countIterable } = require("../util/IterableHelpers");
15
15
  const { first, combine } = require("../util/SetHelpers");
16
16
  const makeSerializable = require("../util/makeSerializable");
17
17
  const propertyAccess = require("../util/propertyAccess");
18
+ const { getRuntimeKey, keyToRuntime } = require("../util/runtime");
18
19
  const HarmonyExportInitFragment = require("./HarmonyExportInitFragment");
19
20
  const HarmonyImportDependency = require("./HarmonyImportDependency");
20
21
  const processExportInfo = require("./processExportInfo");
@@ -23,6 +24,7 @@ const processExportInfo = require("./processExportInfo");
23
24
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
24
25
  /** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
25
26
  /** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
27
+ /** @typedef {import("../Dependency").TRANSITIVE} TRANSITIVE */
26
28
  /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
27
29
  /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
28
30
  /** @typedef {import("../ExportsInfo")} ExportsInfo */
@@ -149,6 +151,172 @@ const findDependencyForName = (
149
151
  return undefined;
150
152
  };
151
153
 
154
+ /**
155
+ * @param {ModuleGraph} moduleGraph the module graph
156
+ * @param {HarmonyExportImportedSpecifierDependency} dep the dependency
157
+ * @param {string} runtimeKey the runtime key
158
+ * @returns {ExportMode} the export mode
159
+ */
160
+ const getMode = (moduleGraph, dep, runtimeKey) => {
161
+ const importedModule = moduleGraph.getModule(dep);
162
+
163
+ if (!importedModule) {
164
+ const mode = new ExportMode("missing");
165
+
166
+ mode.userRequest = dep.userRequest;
167
+
168
+ return mode;
169
+ }
170
+
171
+ const name = dep.name;
172
+ const runtime = keyToRuntime(runtimeKey);
173
+ const parentModule = moduleGraph.getParentModule(dep);
174
+ const exportsInfo = moduleGraph.getExportsInfo(parentModule);
175
+
176
+ if (
177
+ name
178
+ ? exportsInfo.getUsed(name, runtime) === UsageState.Unused
179
+ : exportsInfo.isUsed(runtime) === false
180
+ ) {
181
+ const mode = new ExportMode("unused");
182
+
183
+ mode.name = name || "*";
184
+
185
+ return mode;
186
+ }
187
+
188
+ const importedExportsType = importedModule.getExportsType(
189
+ moduleGraph,
190
+ parentModule.buildMeta.strictHarmonyModule
191
+ );
192
+
193
+ const ids = dep.getIds(moduleGraph);
194
+
195
+ // Special handling for reexporting the default export
196
+ // from non-namespace modules
197
+ if (name && ids.length > 0 && ids[0] === "default") {
198
+ switch (importedExportsType) {
199
+ case "dynamic": {
200
+ const mode = new ExportMode("reexport-dynamic-default");
201
+
202
+ mode.name = name;
203
+
204
+ return mode;
205
+ }
206
+ case "default-only":
207
+ case "default-with-named": {
208
+ const exportInfo = exportsInfo.getReadOnlyExportInfo(name);
209
+ const mode = new ExportMode("reexport-named-default");
210
+
211
+ mode.name = name;
212
+ mode.partialNamespaceExportInfo = exportInfo;
213
+
214
+ return mode;
215
+ }
216
+ }
217
+ }
218
+
219
+ // reexporting with a fixed name
220
+ if (name) {
221
+ let mode;
222
+ const exportInfo = exportsInfo.getReadOnlyExportInfo(name);
223
+
224
+ if (ids.length > 0) {
225
+ // export { name as name }
226
+ switch (importedExportsType) {
227
+ case "default-only":
228
+ mode = new ExportMode("reexport-undefined");
229
+ mode.name = name;
230
+ break;
231
+ default:
232
+ mode = new ExportMode("normal-reexport");
233
+ mode.items = [
234
+ new NormalReexportItem(name, ids, exportInfo, false, false)
235
+ ];
236
+ break;
237
+ }
238
+ } else {
239
+ // export * as name
240
+ switch (importedExportsType) {
241
+ case "default-only":
242
+ mode = new ExportMode("reexport-fake-namespace-object");
243
+ mode.name = name;
244
+ mode.partialNamespaceExportInfo = exportInfo;
245
+ mode.fakeType = 0;
246
+ break;
247
+ case "default-with-named":
248
+ mode = new ExportMode("reexport-fake-namespace-object");
249
+ mode.name = name;
250
+ mode.partialNamespaceExportInfo = exportInfo;
251
+ mode.fakeType = 2;
252
+ break;
253
+ case "dynamic":
254
+ default:
255
+ mode = new ExportMode("reexport-namespace-object");
256
+ mode.name = name;
257
+ mode.partialNamespaceExportInfo = exportInfo;
258
+ }
259
+ }
260
+
261
+ return mode;
262
+ }
263
+
264
+ // Star reexporting
265
+
266
+ const { ignoredExports, exports, checked, hidden } = dep.getStarReexports(
267
+ moduleGraph,
268
+ runtime,
269
+ exportsInfo,
270
+ importedModule
271
+ );
272
+ if (!exports) {
273
+ // We have too few info about the modules
274
+ // Delegate the logic to the runtime code
275
+
276
+ const mode = new ExportMode("dynamic-reexport");
277
+ mode.ignored = ignoredExports;
278
+ mode.hidden = hidden;
279
+
280
+ return mode;
281
+ }
282
+
283
+ if (exports.size === 0) {
284
+ const mode = new ExportMode("empty-star");
285
+ mode.hidden = hidden;
286
+
287
+ return mode;
288
+ }
289
+
290
+ const mode = new ExportMode("normal-reexport");
291
+
292
+ mode.items = Array.from(
293
+ exports,
294
+ exportName =>
295
+ new NormalReexportItem(
296
+ exportName,
297
+ [exportName],
298
+ exportsInfo.getReadOnlyExportInfo(exportName),
299
+ checked.has(exportName),
300
+ false
301
+ )
302
+ );
303
+ if (hidden !== undefined) {
304
+ for (const exportName of hidden) {
305
+ mode.items.push(
306
+ new NormalReexportItem(
307
+ exportName,
308
+ [exportName],
309
+ exportsInfo.getReadOnlyExportInfo(exportName),
310
+ false,
311
+ true
312
+ )
313
+ );
314
+ }
315
+ }
316
+
317
+ return mode;
318
+ };
319
+
152
320
  class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
153
321
  /**
154
322
  * @param {string} request the request string
@@ -180,7 +348,13 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
180
348
  this.otherStarExports = otherStarExports;
181
349
  this.strictExportPresence = strictExportPresence;
182
350
  this.allStarExports = allStarExports;
183
- this._getMode = this._getMode.bind(this);
351
+ }
352
+
353
+ /**
354
+ * @returns {boolean | TRANSITIVE} true, when changes to the referenced module could affect the referencing module; TRANSITIVE, when changes to the referenced module could affect referencing modules of the referencing module
355
+ */
356
+ couldAffectReferencingModule() {
357
+ return Dependency.TRANSITIVE;
184
358
  }
185
359
 
186
360
  // TODO webpack 6 remove
@@ -225,169 +399,11 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
225
399
  * @returns {ExportMode} the export mode
226
400
  */
227
401
  getMode(moduleGraph, runtime) {
228
- return moduleGraph.cached(this._getMode, runtime);
229
- }
230
-
231
- /**
232
- * @param {ModuleGraph} moduleGraph the module graph
233
- * @param {RuntimeSpec} runtime the runtime
234
- * @returns {ExportMode} the export mode
235
- */
236
- _getMode(moduleGraph, runtime) {
237
- const name = this.name;
238
- const ids = this.getIds(moduleGraph);
239
- const parentModule = moduleGraph.getParentModule(this);
240
- const importedModule = moduleGraph.getModule(this);
241
- const exportsInfo = moduleGraph.getExportsInfo(parentModule);
242
-
243
- if (!importedModule) {
244
- const mode = new ExportMode("missing");
245
-
246
- mode.userRequest = this.userRequest;
247
-
248
- return mode;
249
- }
250
-
251
- if (
252
- name
253
- ? exportsInfo.getUsed(name, runtime) === UsageState.Unused
254
- : exportsInfo.isUsed(runtime) === false
255
- ) {
256
- const mode = new ExportMode("unused");
257
-
258
- mode.name = name || "*";
259
-
260
- return mode;
261
- }
262
-
263
- const importedExportsType = importedModule.getExportsType(
264
- moduleGraph,
265
- parentModule.buildMeta.strictHarmonyModule
266
- );
267
-
268
- // Special handling for reexporting the default export
269
- // from non-namespace modules
270
- if (name && ids.length > 0 && ids[0] === "default") {
271
- switch (importedExportsType) {
272
- case "dynamic": {
273
- const mode = new ExportMode("reexport-dynamic-default");
274
-
275
- mode.name = name;
276
-
277
- return mode;
278
- }
279
- case "default-only":
280
- case "default-with-named": {
281
- const exportInfo = exportsInfo.getReadOnlyExportInfo(name);
282
- const mode = new ExportMode("reexport-named-default");
283
-
284
- mode.name = name;
285
- mode.partialNamespaceExportInfo = exportInfo;
286
-
287
- return mode;
288
- }
289
- }
290
- }
291
-
292
- // reexporting with a fixed name
293
- if (name) {
294
- let mode;
295
- const exportInfo = exportsInfo.getReadOnlyExportInfo(name);
296
-
297
- if (ids.length > 0) {
298
- // export { name as name }
299
- switch (importedExportsType) {
300
- case "default-only":
301
- mode = new ExportMode("reexport-undefined");
302
- mode.name = name;
303
- break;
304
- default:
305
- mode = new ExportMode("normal-reexport");
306
- mode.items = [
307
- new NormalReexportItem(name, ids, exportInfo, false, false)
308
- ];
309
- break;
310
- }
311
- } else {
312
- // export * as name
313
- switch (importedExportsType) {
314
- case "default-only":
315
- mode = new ExportMode("reexport-fake-namespace-object");
316
- mode.name = name;
317
- mode.partialNamespaceExportInfo = exportInfo;
318
- mode.fakeType = 0;
319
- break;
320
- case "default-with-named":
321
- mode = new ExportMode("reexport-fake-namespace-object");
322
- mode.name = name;
323
- mode.partialNamespaceExportInfo = exportInfo;
324
- mode.fakeType = 2;
325
- break;
326
- case "dynamic":
327
- default:
328
- mode = new ExportMode("reexport-namespace-object");
329
- mode.name = name;
330
- mode.partialNamespaceExportInfo = exportInfo;
331
- }
332
- }
333
-
334
- return mode;
335
- }
336
-
337
- // Star reexporting
338
-
339
- const { ignoredExports, exports, checked, hidden } = this.getStarReexports(
340
- moduleGraph,
341
- runtime,
342
- exportsInfo,
343
- importedModule
344
- );
345
- if (!exports) {
346
- // We have too few info about the modules
347
- // Delegate the logic to the runtime code
348
-
349
- const mode = new ExportMode("dynamic-reexport");
350
- mode.ignored = ignoredExports;
351
- mode.hidden = hidden;
352
-
353
- return mode;
354
- }
355
-
356
- if (exports.size === 0) {
357
- const mode = new ExportMode("empty-star");
358
- mode.hidden = hidden;
359
-
360
- return mode;
361
- }
362
-
363
- const mode = new ExportMode("normal-reexport");
364
-
365
- mode.items = Array.from(
366
- exports,
367
- exportName =>
368
- new NormalReexportItem(
369
- exportName,
370
- [exportName],
371
- exportsInfo.getReadOnlyExportInfo(exportName),
372
- checked.has(exportName),
373
- false
374
- )
402
+ return moduleGraph.dependencyCacheProvide(
403
+ this,
404
+ getRuntimeKey(runtime),
405
+ getMode
375
406
  );
376
- if (hidden !== undefined) {
377
- for (const exportName of hidden) {
378
- mode.items.push(
379
- new NormalReexportItem(
380
- exportName,
381
- [exportName],
382
- exportsInfo.getReadOnlyExportInfo(exportName),
383
- false,
384
- true
385
- )
386
- );
387
- }
388
- }
389
-
390
- return mode;
391
407
  }
392
408
 
393
409
  /**
@@ -282,7 +282,10 @@ HarmonyImportDependency.Template = class HarmonyImportDependencyTemplate extends
282
282
  }
283
283
 
284
284
  const importStatement = dep.getImportStatement(false, templateContext);
285
- if (templateContext.moduleGraph.isAsync(referencedModule)) {
285
+ if (
286
+ referencedModule &&
287
+ templateContext.moduleGraph.isAsync(referencedModule)
288
+ ) {
286
289
  templateContext.initFragments.push(
287
290
  new ConditionalInitFragment(
288
291
  importStatement[0],
@@ -9,6 +9,7 @@ const Dependency = require("../Dependency");
9
9
  const DependencyTemplate = require("../DependencyTemplate");
10
10
  const memoize = require("../util/memoize");
11
11
 
12
+ /** @typedef {import("../Dependency").TRANSITIVE} TRANSITIVE */
12
13
  /** @typedef {import("../Module")} Module */
13
14
 
14
15
  const getRawModule = memoize(() => require("../RawModule"));
@@ -38,6 +39,13 @@ class ModuleDependency extends Dependency {
38
39
  return str;
39
40
  }
40
41
 
42
+ /**
43
+ * @returns {boolean | TRANSITIVE} true, when changes to the referenced module could affect the referencing module; TRANSITIVE, when changes to the referenced module could affect referencing modules of the referencing module
44
+ */
45
+ couldAffectReferencingModule() {
46
+ return true;
47
+ }
48
+
41
49
  /**
42
50
  * @param {string} context context directory
43
51
  * @returns {Module} a module
@@ -9,16 +9,20 @@ const Dependency = require("../Dependency");
9
9
  const DependencyTemplate = require("../DependencyTemplate");
10
10
 
11
11
  /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
12
- /** @typedef {import("../ChunkGraph")} ChunkGraph */
13
- /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
12
+ /** @typedef {import("../Dependency").TRANSITIVE} TRANSITIVE */
14
13
  /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
15
- /** @typedef {import("../ModuleGraph")} ModuleGraph */
16
- /** @typedef {import("../util/Hash")} Hash */
17
14
 
18
15
  class NullDependency extends Dependency {
19
16
  get type() {
20
17
  return "null";
21
18
  }
19
+
20
+ /**
21
+ * @returns {boolean | TRANSITIVE} true, when changes to the referenced module could affect the referencing module; TRANSITIVE, when changes to the referenced module could affect referencing modules of the referencing module
22
+ */
23
+ couldAffectReferencingModule() {
24
+ return false;
25
+ }
22
26
  }
23
27
 
24
28
  NullDependency.Template = class NullDependencyTemplate extends (
@@ -5,10 +5,12 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const Dependency = require("../Dependency");
8
9
  const makeSerializable = require("../util/makeSerializable");
9
10
  const ModuleDependency = require("./ModuleDependency");
10
11
 
11
12
  /** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
13
+ /** @typedef {import("../Dependency").TRANSITIVE} TRANSITIVE */
12
14
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
13
15
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
14
16
 
@@ -23,6 +25,13 @@ class WebAssemblyExportImportedDependency extends ModuleDependency {
23
25
  this.valueType = valueType;
24
26
  }
25
27
 
28
+ /**
29
+ * @returns {boolean | TRANSITIVE} true, when changes to the referenced module could affect the referencing module; TRANSITIVE, when changes to the referenced module could affect referencing modules of the referencing module
30
+ */
31
+ couldAffectReferencingModule() {
32
+ return Dependency.TRANSITIVE;
33
+ }
34
+
26
35
  /**
27
36
  * Returns list of exports referenced by this dependency
28
37
  * @param {ModuleGraph} moduleGraph module graph