webpack 5.84.1 → 5.85.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.

Files changed (121) hide show
  1. package/lib/AsyncDependenciesBlock.js +2 -2
  2. package/lib/AutomaticPrefetchPlugin.js +1 -0
  3. package/lib/BannerPlugin.js +4 -0
  4. package/lib/CacheFacade.js +4 -0
  5. package/lib/ChunkGroup.js +5 -1
  6. package/lib/CleanPlugin.js +30 -7
  7. package/lib/CompatibilityPlugin.js +1 -1
  8. package/lib/Compilation.js +1 -1
  9. package/lib/Compiler.js +1 -1
  10. package/lib/ContextModuleFactory.js +1 -1
  11. package/lib/DllModuleFactory.js +1 -1
  12. package/lib/HookWebpackError.js +1 -1
  13. package/lib/IgnoreErrorModuleFactory.js +1 -1
  14. package/lib/Module.js +21 -9
  15. package/lib/ModuleFactory.js +1 -1
  16. package/lib/ModuleTypeConstants.js +2 -1
  17. package/lib/NormalModuleFactory.js +1 -1
  18. package/lib/NormalModuleReplacementPlugin.js +4 -2
  19. package/lib/NullFactory.js +1 -1
  20. package/lib/RecordIdsPlugin.js +4 -4
  21. package/lib/RuntimeModule.js +5 -5
  22. package/lib/RuntimePlugin.js +4 -0
  23. package/lib/RuntimeTemplate.js +2 -2
  24. package/lib/SelfModuleFactory.js +1 -1
  25. package/lib/Template.js +1 -1
  26. package/lib/UseStrictPlugin.js +4 -0
  27. package/lib/WarnDeprecatedOptionPlugin.js +7 -0
  28. package/lib/WatchIgnorePlugin.js +4 -0
  29. package/lib/WebpackOptionsApply.js +2 -1
  30. package/lib/asset/AssetGenerator.js +7 -2
  31. package/lib/asset/AssetModulesPlugin.js +7 -1
  32. package/lib/asset/AssetParser.js +4 -1
  33. package/lib/asset/RawDataUrlModule.js +5 -3
  34. package/lib/async-modules/InferAsyncModulesPlugin.js +1 -1
  35. package/lib/cache/PackFileCacheStrategy.js +7 -1
  36. package/lib/config/defaults.js +38 -10
  37. package/lib/config/normalization.js +2 -1
  38. package/lib/container/ContainerEntryModule.js +4 -0
  39. package/lib/container/ContainerEntryModuleFactory.js +1 -1
  40. package/lib/container/FallbackDependency.js +7 -0
  41. package/lib/container/FallbackItemDependency.js +3 -0
  42. package/lib/container/FallbackModule.js +4 -0
  43. package/lib/container/FallbackModuleFactory.js +1 -1
  44. package/lib/container/RemoteModule.js +4 -0
  45. package/lib/container/RemoteRuntimeModule.js +1 -0
  46. package/lib/container/RemoteToExternalDependency.js +3 -0
  47. package/lib/dependencies/CommonJsPlugin.js +14 -12
  48. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +1 -1
  49. package/lib/dependencies/HarmonyExports.js +3 -1
  50. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +16 -5
  51. package/lib/dependencies/HarmonyImportSpecifierDependency.js +75 -6
  52. package/lib/dependencies/WorkerPlugin.js +25 -1
  53. package/lib/esm/ModuleChunkFormatPlugin.js +13 -5
  54. package/lib/esm/ModuleChunkLoadingPlugin.js +9 -0
  55. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +10 -8
  56. package/lib/hmr/LazyCompilationPlugin.js +1 -1
  57. package/lib/ids/ChunkModuleIdRangePlugin.js +11 -0
  58. package/lib/ids/DeterministicChunkIdsPlugin.js +11 -2
  59. package/lib/ids/DeterministicModuleIdsPlugin.js +11 -7
  60. package/lib/ids/HashedModuleIdsPlugin.js +8 -1
  61. package/lib/ids/IdHelpers.js +6 -0
  62. package/lib/ids/NamedChunkIdsPlugin.js +13 -1
  63. package/lib/ids/NamedModuleIdsPlugin.js +14 -3
  64. package/lib/ids/OccurrenceChunkIdsPlugin.js +6 -2
  65. package/lib/ids/SyncModuleIdsPlugin.js +2 -2
  66. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +1 -1
  67. package/lib/javascript/BasicEvaluatedExpression.js +12 -1
  68. package/lib/javascript/ChunkHelpers.js +2 -2
  69. package/lib/javascript/EnableChunkLoadingPlugin.js +4 -0
  70. package/lib/javascript/JavascriptModulesPlugin.js +24 -19
  71. package/lib/javascript/JavascriptParser.js +42 -18
  72. package/lib/javascript/StartupHelpers.js +1 -1
  73. package/lib/json/JsonGenerator.js +7 -5
  74. package/lib/json/JsonParser.js +1 -1
  75. package/lib/library/AbstractLibraryPlugin.js +4 -0
  76. package/lib/library/AssignLibraryPlugin.js +6 -4
  77. package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
  78. package/lib/library/ModuleLibraryPlugin.js +6 -3
  79. package/lib/library/SystemLibraryPlugin.js +1 -0
  80. package/lib/library/UmdLibraryPlugin.js +4 -0
  81. package/lib/node/CommonJsChunkLoadingPlugin.js +17 -2
  82. package/lib/node/NodeTemplatePlugin.js +10 -2
  83. package/lib/node/NodeWatchFileSystem.js +1 -1
  84. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +4 -1
  85. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +8 -0
  86. package/lib/node/ReadFileCompileWasmPlugin.js +19 -2
  87. package/lib/node/RequireChunkLoadingRuntimeModule.js +4 -1
  88. package/lib/runtime/AsyncModuleRuntimeModule.js +1 -1
  89. package/lib/runtime/AutoPublicPathRuntimeModule.js +5 -1
  90. package/lib/runtime/BaseUriRuntimeModule.js +5 -1
  91. package/lib/runtime/EnsureChunkRuntimeModule.js +3 -0
  92. package/lib/runtime/GetChunkFilenameRuntimeModule.js +35 -16
  93. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
  94. package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
  95. package/lib/runtime/PublicPathRuntimeModule.js +5 -0
  96. package/lib/runtime/StartupChunkDependenciesPlugin.js +15 -0
  97. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +3 -0
  98. package/lib/runtime/StartupEntrypointRuntimeModule.js +3 -0
  99. package/lib/sharing/ProvideSharedModuleFactory.js +1 -1
  100. package/lib/util/createHash.js +1 -1
  101. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +9 -0
  102. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +9 -1
  103. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +13 -3
  104. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +19 -2
  105. package/lib/wasm-async/AsyncWebAssemblyParser.js +3 -0
  106. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +25 -1
  107. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +14 -5
  108. package/lib/wasm-sync/WebAssemblyGenerator.js +18 -5
  109. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -1
  110. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +12 -1
  111. package/lib/wasm-sync/WebAssemblyParser.js +9 -2
  112. package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
  113. package/lib/web/FetchCompileAsyncWasmPlugin.js +9 -0
  114. package/lib/web/FetchCompileWasmPlugin.js +19 -2
  115. package/lib/web/JsonpChunkLoadingPlugin.js +9 -0
  116. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +9 -0
  117. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
  118. package/package.json +1 -1
  119. package/schemas/WebpackOptions.check.js +1 -1
  120. package/schemas/WebpackOptions.json +12 -0
  121. package/types.d.ts +189 -141
@@ -91,7 +91,7 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
91
91
  /** @typedef {import("../Parser").ParserState} ParserState */
92
92
  /** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
93
93
  /** @typedef {{declaredScope: ScopeInfo, freeName: string | true, tagInfo: TagInfo | undefined}} VariableInfoInterface */
94
- /** @typedef {{ name: string | VariableInfo, rootInfo: string | VariableInfo, getMembers: () => string[], getMembersOptionals: () => boolean[] }} GetInfoResult */
94
+ /** @typedef {{ name: string | VariableInfo, rootInfo: string | VariableInfo, getMembers: () => string[], getMembersOptionals: () => boolean[], getMemberRanges: () => Range[] }} GetInfoResult */
95
95
 
96
96
  const EMPTY_ARRAY = [];
97
97
  const ALLOWED_MEMBER_TYPES_CALL_EXPRESSION = 0b01;
@@ -350,9 +350,15 @@ class JavascriptParser extends Parser {
350
350
  /** @type {HookMap<SyncBailHook<[BaseCallExpression], boolean | void>>} */
351
351
  call: new HookMap(() => new SyncBailHook(["expression"])),
352
352
  /** Something like "a.b()" */
353
- /** @type {HookMap<SyncBailHook<[CallExpression, string[], boolean[]], boolean | void>>} */
353
+ /** @type {HookMap<SyncBailHook<[CallExpression, string[], boolean[], Range[]], boolean | void>>} */
354
354
  callMemberChain: new HookMap(
355
- () => new SyncBailHook(["expression", "members", "membersOptionals"])
355
+ () =>
356
+ new SyncBailHook([
357
+ "expression",
358
+ "members",
359
+ "membersOptionals",
360
+ "memberRanges"
361
+ ])
356
362
  ),
357
363
  /** Something like "a.b().c.d" */
358
364
  /** @type {HookMap<SyncBailHook<[Expression, string[], CallExpression, string[]], boolean | void>>} */
@@ -384,9 +390,15 @@ class JavascriptParser extends Parser {
384
390
  binaryExpression: new SyncBailHook(["binaryExpression"]),
385
391
  /** @type {HookMap<SyncBailHook<[Expression], boolean | void>>} */
386
392
  expression: new HookMap(() => new SyncBailHook(["expression"])),
387
- /** @type {HookMap<SyncBailHook<[Expression, string[], boolean[]], boolean | void>>} */
393
+ /** @type {HookMap<SyncBailHook<[Expression, string[], boolean[], Range[]], boolean | void>>} */
388
394
  expressionMemberChain: new HookMap(
389
- () => new SyncBailHook(["expression", "members", "membersOptionals"])
395
+ () =>
396
+ new SyncBailHook([
397
+ "expression",
398
+ "members",
399
+ "membersOptionals",
400
+ "memberRanges"
401
+ ])
390
402
  ),
391
403
  /** @type {HookMap<SyncBailHook<[Expression, string[]], boolean | void>>} */
392
404
  unhandledExpressionMemberChain: new HookMap(
@@ -1150,7 +1162,8 @@ class JavascriptParser extends Parser {
1150
1162
  info.name,
1151
1163
  info.rootInfo,
1152
1164
  info.getMembers,
1153
- info.getMembersOptionals
1165
+ info.getMembersOptionals,
1166
+ info.getMemberRanges
1154
1167
  )
1155
1168
  .setRange(expr.range);
1156
1169
  }
@@ -1170,7 +1183,8 @@ class JavascriptParser extends Parser {
1170
1183
  name: info,
1171
1184
  rootInfo: info,
1172
1185
  getMembers: () => [],
1173
- getMembersOptionals: () => []
1186
+ getMembersOptionals: () => [],
1187
+ getMemberRanges: () => []
1174
1188
  };
1175
1189
  }
1176
1190
  });
@@ -1184,7 +1198,8 @@ class JavascriptParser extends Parser {
1184
1198
  name: info,
1185
1199
  rootInfo: info,
1186
1200
  getMembers: () => [],
1187
- getMembersOptionals: () => []
1201
+ getMembersOptionals: () => [],
1202
+ getMemberRanges: () => []
1188
1203
  };
1189
1204
  }
1190
1205
  });
@@ -3248,7 +3263,8 @@ class JavascriptParser extends Parser {
3248
3263
  callee.getMembers(),
3249
3264
  callee.getMembersOptionals
3250
3265
  ? callee.getMembersOptionals()
3251
- : callee.getMembers().map(() => false)
3266
+ : callee.getMembers().map(() => false),
3267
+ callee.getMemberRanges ? callee.getMemberRanges() : []
3252
3268
  );
3253
3269
  if (result1 === true) return;
3254
3270
  const result2 = this.callHooksForInfo(
@@ -3292,12 +3308,14 @@ class JavascriptParser extends Parser {
3292
3308
  if (result1 === true) return;
3293
3309
  const members = exprInfo.getMembers();
3294
3310
  const membersOptionals = exprInfo.getMembersOptionals();
3311
+ const memberRanges = exprInfo.getMemberRanges();
3295
3312
  const result2 = this.callHooksForInfo(
3296
3313
  this.hooks.expressionMemberChain,
3297
3314
  exprInfo.rootInfo,
3298
3315
  expression,
3299
3316
  members,
3300
- membersOptionals
3317
+ membersOptionals,
3318
+ memberRanges
3301
3319
  );
3302
3320
  if (result2 === true) return;
3303
3321
  this.walkMemberExpressionWithExpressionName(
@@ -4253,20 +4271,23 @@ class JavascriptParser extends Parser {
4253
4271
 
4254
4272
  /**
4255
4273
  * @param {MemberExpression} expression a member expression
4256
- * @returns {{ members: string[], object: Expression | Super, membersOptionals: boolean[] }} member names (reverse order) and remaining object
4274
+ * @returns {{ members: string[], object: Expression | Super, membersOptionals: boolean[], memberRanges: Range[] }} member names (reverse order) and remaining object
4257
4275
  */
4258
4276
  extractMemberExpressionChain(expression) {
4259
4277
  /** @type {AnyNode} */
4260
4278
  let expr = expression;
4261
4279
  const members = [];
4262
4280
  const membersOptionals = [];
4281
+ const memberRanges = [];
4263
4282
  while (expr.type === "MemberExpression") {
4264
4283
  if (expr.computed) {
4265
4284
  if (expr.property.type !== "Literal") break;
4266
- members.push(`${expr.property.value}`);
4285
+ members.push(`${expr.property.value}`); // the literal
4286
+ memberRanges.push(expr.object.range); // the range of the expression fragment before the literal
4267
4287
  } else {
4268
4288
  if (expr.property.type !== "Identifier") break;
4269
- members.push(expr.property.name);
4289
+ members.push(expr.property.name); // the identifier
4290
+ memberRanges.push(expr.object.range); // the range of the expression fragment before the identifier
4270
4291
  }
4271
4292
  membersOptionals.push(expr.optional);
4272
4293
  expr = expr.object;
@@ -4275,6 +4296,7 @@ class JavascriptParser extends Parser {
4275
4296
  return {
4276
4297
  members,
4277
4298
  membersOptionals,
4299
+ memberRanges,
4278
4300
  object: expr
4279
4301
  };
4280
4302
  }
@@ -4297,8 +4319,8 @@ class JavascriptParser extends Parser {
4297
4319
  return { info, name };
4298
4320
  }
4299
4321
 
4300
- /** @typedef {{ type: "call", call: CallExpression, calleeName: string, rootInfo: string | VariableInfo, getCalleeMembers: () => string[], name: string, getMembers: () => string[], getMembersOptionals: () => boolean[]}} CallExpressionInfo */
4301
- /** @typedef {{ type: "expression", rootInfo: string | VariableInfo, name: string, getMembers: () => string[], getMembersOptionals: () => boolean[]}} ExpressionExpressionInfo */
4322
+ /** @typedef {{ type: "call", call: CallExpression, calleeName: string, rootInfo: string | VariableInfo, getCalleeMembers: () => string[], name: string, getMembers: () => string[], getMembersOptionals: () => boolean[], getMemberRanges: () => Range[]}} CallExpressionInfo */
4323
+ /** @typedef {{ type: "expression", rootInfo: string | VariableInfo, name: string, getMembers: () => string[], getMembersOptionals: () => boolean[], getMemberRanges: () => Range[]}} ExpressionExpressionInfo */
4302
4324
 
4303
4325
  /**
4304
4326
  * @param {MemberExpression} expression a member expression
@@ -4306,7 +4328,7 @@ class JavascriptParser extends Parser {
4306
4328
  * @returns {CallExpressionInfo | ExpressionExpressionInfo | undefined} expression info
4307
4329
  */
4308
4330
  getMemberExpressionInfo(expression, allowedTypes) {
4309
- const { object, members, membersOptionals } =
4331
+ const { object, members, membersOptionals, memberRanges } =
4310
4332
  this.extractMemberExpressionChain(expression);
4311
4333
  switch (object.type) {
4312
4334
  case "CallExpression": {
@@ -4332,7 +4354,8 @@ class JavascriptParser extends Parser {
4332
4354
  getCalleeMembers: memoize(() => rootMembers.reverse()),
4333
4355
  name: objectAndMembersToName(`${calleeName}()`, members),
4334
4356
  getMembers: memoize(() => members.reverse()),
4335
- getMembersOptionals: memoize(() => membersOptionals.reverse())
4357
+ getMembersOptionals: memoize(() => membersOptionals.reverse()),
4358
+ getMemberRanges: memoize(() => memberRanges.reverse())
4336
4359
  };
4337
4360
  }
4338
4361
  case "Identifier":
@@ -4351,7 +4374,8 @@ class JavascriptParser extends Parser {
4351
4374
  name: objectAndMembersToName(resolvedRoot, members),
4352
4375
  rootInfo,
4353
4376
  getMembers: memoize(() => members.reverse()),
4354
- getMembersOptionals: memoize(() => membersOptionals.reverse())
4377
+ getMembersOptionals: memoize(() => membersOptionals.reverse()),
4378
+ getMemberRanges: memoize(() => memberRanges.reverse())
4355
4379
  };
4356
4380
  }
4357
4381
  }
@@ -19,7 +19,7 @@ const { getAllChunks } = require("./ChunkHelpers");
19
19
  /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
20
20
  /** @typedef {(string|number)[]} EntryItem */
21
21
 
22
- const EXPORT_PREFIX = "var __webpack_exports__ = ";
22
+ const EXPORT_PREFIX = `var ${RuntimeGlobals.exports} = `;
23
23
 
24
24
  /**
25
25
  * @param {ChunkGraph} chunkGraph chunkGraph
@@ -45,13 +45,14 @@ const createObjectForExportsInfo = (data, exportsInfo, runtime) => {
45
45
  if (exportsInfo.otherExportsInfo.getUsed(runtime) !== UsageState.Unused)
46
46
  return data;
47
47
  const isArray = Array.isArray(data);
48
+ /** @type {RawJsonData} */
48
49
  const reducedData = isArray ? [] : {};
49
50
  for (const key of Object.keys(data)) {
50
51
  const exportInfo = exportsInfo.getReadOnlyExportInfo(key);
51
52
  const used = exportInfo.getUsed(runtime);
52
53
  if (used === UsageState.Unused) continue;
53
54
 
54
- /** @type {any} */
55
+ /** @type {RawJsonData} */
55
56
  let value;
56
57
  if (used === UsageState.OnlyPropertiesUsed && exportInfo.exportsInfo) {
57
58
  value = createObjectForExportsInfo(
@@ -62,8 +63,9 @@ const createObjectForExportsInfo = (data, exportsInfo, runtime) => {
62
63
  } else {
63
64
  value = data[key];
64
65
  }
65
- const name = exportInfo.getUsedName(key, runtime);
66
- reducedData[name] = value;
66
+
67
+ const name = /** @type {string} */ (exportInfo.getUsedName(key, runtime));
68
+ /** @type {Record<string, RawJsonData>} */ (reducedData)[name] = value;
67
69
  }
68
70
  if (isArray) {
69
71
  let arrayLengthWhenUsed =
@@ -130,7 +132,7 @@ class JsonGenerator extends Generator {
130
132
  module.buildInfo.jsonData &&
131
133
  module.buildInfo.jsonData.get();
132
134
  if (!data) return 0;
133
- return stringifySafe(data).length + 10;
135
+ return /** @type {string} */ (stringifySafe(data)).length + 10;
134
136
  }
135
137
 
136
138
  /**
@@ -178,7 +180,7 @@ class JsonGenerator extends Generator {
178
180
  ? createObjectForExportsInfo(data, exportsInfo, runtime)
179
181
  : data;
180
182
  // Use JSON because JSON.parse() is much faster than JavaScript evaluation
181
- const jsonStr = stringifySafe(finalJson);
183
+ const jsonStr = /** @type {string} */ (stringifySafe(finalJson));
182
184
  const jsonExpr =
183
185
  jsonStr.length > 20 && typeof finalJson === "object"
184
186
  ? `JSON.parse('${jsonStr.replace(/[\\']/g, "\\$&")}')`
@@ -34,7 +34,7 @@ class JsonParser extends Parser {
34
34
  source = source.toString("utf-8");
35
35
  }
36
36
 
37
- /** @type {JsonModulesPluginParserOptions["parse"]} */
37
+ /** @type {NonNullable<JsonModulesPluginParserOptions["parse"]>} */
38
38
  const parseFn =
39
39
  typeof this.options.parse === "function" ? this.options.parse : parseJson;
40
40
  /** @type {Buffer | RawJsonData} */
@@ -87,6 +87,10 @@ class AbstractLibraryPlugin {
87
87
  }
88
88
  );
89
89
 
90
+ /**
91
+ * @param {Chunk} chunk chunk
92
+ * @returns {TODO} options for the chunk
93
+ */
90
94
  const getOptionsForChunk = chunk => {
91
95
  if (compilation.chunkGraph.getNumberOfEntryModules(chunk) === 0)
92
96
  return false;
@@ -7,6 +7,7 @@
7
7
 
8
8
  const { ConcatSource } = require("webpack-sources");
9
9
  const { UsageState } = require("../ExportsInfo");
10
+ const RuntimeGlobals = require("../RuntimeGlobals");
10
11
  const Template = require("../Template");
11
12
  const propertyAccess = require("../util/propertyAccess");
12
13
  const { getEntryRuntime } = require("../util/runtime");
@@ -296,7 +297,7 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
296
297
  if (!exportInfo.provided) continue;
297
298
  const nameAccess = propertyAccess([exportInfo.name]);
298
299
  result.add(
299
- `${exportTarget}${nameAccess} = __webpack_exports__${exportAccess}${nameAccess};\n`
300
+ `${exportTarget}${nameAccess} = ${RuntimeGlobals.exports}${exportAccess}${nameAccess};\n`
300
301
  );
301
302
  }
302
303
  result.add(
@@ -310,10 +311,11 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
310
311
  true
311
312
  )};\n`
312
313
  );
313
- let exports = "__webpack_exports__";
314
+ /** @type {String} */
315
+ let exports = RuntimeGlobals.exports;
314
316
  if (exportAccess) {
315
317
  result.add(
316
- `var __webpack_exports_export__ = __webpack_exports__${exportAccess};\n`
318
+ `var __webpack_exports_export__ = ${RuntimeGlobals.exports}${exportAccess};\n`
317
319
  );
318
320
  exports = "__webpack_exports_export__";
319
321
  }
@@ -329,7 +331,7 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
329
331
  fullNameResolved,
330
332
  this._getPrefix(compilation).length,
331
333
  false
332
- )} = __webpack_exports__${exportAccess};\n`
334
+ )} = ${RuntimeGlobals.exports}${exportAccess};\n`
333
335
  );
334
336
  }
335
337
  return result;
@@ -7,6 +7,7 @@
7
7
 
8
8
  const { ConcatSource } = require("webpack-sources");
9
9
  const { UsageState } = require("../ExportsInfo");
10
+ const RuntimeGlobals = require("../RuntimeGlobals");
10
11
  const propertyAccess = require("../util/propertyAccess");
11
12
  const { getEntryRuntime } = require("../util/runtime");
12
13
  const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
@@ -103,7 +104,9 @@ class ExportPropertyLibraryPlugin extends AbstractLibraryPlugin {
103
104
  */
104
105
  renderStartup(source, module, renderContext, { options }) {
105
106
  if (!options.export) return source;
106
- const postfix = `__webpack_exports__ = __webpack_exports__${propertyAccess(
107
+ const postfix = `${RuntimeGlobals.exports} = ${
108
+ RuntimeGlobals.exports
109
+ }${propertyAccess(
107
110
  Array.isArray(options.export) ? options.export : [options.export]
108
111
  )};\n`;
109
112
  return new ConcatSource(source, postfix);
@@ -6,6 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  const { ConcatSource } = require("webpack-sources");
9
+ const RuntimeGlobals = require("../RuntimeGlobals");
9
10
  const Template = require("../Template");
10
11
  const propertyAccess = require("../util/propertyAccess");
11
12
  const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
@@ -80,15 +81,17 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
80
81
  const exports = [];
81
82
  const isAsync = moduleGraph.isAsync(module);
82
83
  if (isAsync) {
83
- result.add(`__webpack_exports__ = await __webpack_exports__;\n`);
84
+ result.add(
85
+ `${RuntimeGlobals.exports} = await ${RuntimeGlobals.exports};\n`
86
+ );
84
87
  }
85
88
  for (const exportInfo of exportsInfo.orderedExports) {
86
89
  if (!exportInfo.provided) continue;
87
- const varName = `__webpack_exports__${Template.toIdentifier(
90
+ const varName = `${RuntimeGlobals.exports}${Template.toIdentifier(
88
91
  exportInfo.name
89
92
  )}`;
90
93
  result.add(
91
- `var ${varName} = __webpack_exports__${propertyAccess([
94
+ `var ${varName} = ${RuntimeGlobals.exports}${propertyAccess([
92
95
  /** @type {string} */
93
96
  (exportInfo.getUsedName(exportInfo.name, chunk.runtime))
94
97
  ])};\n`
@@ -106,6 +106,7 @@ class SystemLibraryPlugin extends AbstractLibraryPlugin {
106
106
  .join("\n");
107
107
 
108
108
  // Define __esModule flag on all internal variables and helpers
109
+ /** @type {string[]} */
109
110
  const externalVarInitialization = [];
110
111
 
111
112
  // The system.register format requires an array of setter functions for externals.
@@ -208,6 +208,10 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
208
208
  );
209
209
  };
210
210
 
211
+ /**
212
+ * @param {ExternalModule[]} modules external modules
213
+ * @returns {string} arguments
214
+ */
211
215
  const externalsArguments = modules => {
212
216
  return modules
213
217
  .map(
@@ -8,11 +8,18 @@
8
8
  const RuntimeGlobals = require("../RuntimeGlobals");
9
9
  const StartupChunkDependenciesPlugin = require("../runtime/StartupChunkDependenciesPlugin");
10
10
 
11
+ /** @typedef {import("../Chunk")} Chunk */
11
12
  /** @typedef {import("../Compiler")} Compiler */
12
13
 
14
+ /** @typedef {Object} CommonJsChunkLoadingPluginOptions
15
+ * @property {boolean} [asyncChunkLoading] enable async chunk loading
16
+ */
17
+
13
18
  class CommonJsChunkLoadingPlugin {
14
- constructor(options) {
15
- options = options || {};
19
+ /**
20
+ * @param {CommonJsChunkLoadingPluginOptions} [options] options
21
+ */
22
+ constructor(options = {}) {
16
23
  this._asyncChunkLoading = options.asyncChunkLoading;
17
24
  }
18
25
 
@@ -36,6 +43,10 @@ class CommonJsChunkLoadingPlugin {
36
43
  "CommonJsChunkLoadingPlugin",
37
44
  compilation => {
38
45
  const globalChunkLoading = compilation.outputOptions.chunkLoading;
46
+ /**
47
+ * @param {Chunk} chunk chunk
48
+ * @returns {boolean} true, if wasm loading is enabled for the chunk
49
+ */
39
50
  const isEnabledForChunk = chunk => {
40
51
  const options = chunk.getEntryOptions();
41
52
  const chunkLoading =
@@ -45,6 +56,10 @@ class CommonJsChunkLoadingPlugin {
45
56
  return chunkLoading === chunkLoadingValue;
46
57
  };
47
58
  const onceForChunkSet = new WeakSet();
59
+ /**
60
+ * @param {Chunk} chunk chunk
61
+ * @param {Set<string>} set runtime requirements
62
+ */
48
63
  const handler = (chunk, set) => {
49
64
  if (onceForChunkSet.has(chunk)) return;
50
65
  onceForChunkSet.add(chunk);
@@ -10,9 +10,17 @@ const EnableChunkLoadingPlugin = require("../javascript/EnableChunkLoadingPlugin
10
10
 
11
11
  /** @typedef {import("../Compiler")} Compiler */
12
12
 
13
+ /**
14
+ * @typedef {Object} NodeTemplatePluginOptions
15
+ * @property {boolean} [asyncChunkLoading] enable async chunk loading
16
+ */
17
+
13
18
  class NodeTemplatePlugin {
14
- constructor(options) {
15
- this._options = options || {};
19
+ /**
20
+ * @param {NodeTemplatePluginOptions} [options] options object
21
+ */
22
+ constructor(options = {}) {
23
+ this._options = options;
16
24
  }
17
25
 
18
26
  /**
@@ -29,7 +29,7 @@ class NodeWatchFileSystem {
29
29
  * @param {Iterable<string>} missing watched exitance entries
30
30
  * @param {number} startTime timestamp of start time
31
31
  * @param {WatchOptions} options options object
32
- * @param {function(Error=, Map<string, FileSystemInfoEntry>, Map<string, FileSystemInfoEntry>, Set<string>, Set<string>): void} callback aggregated callback
32
+ * @param {function((Error | null)=, Map<string, FileSystemInfoEntry>, Map<string, FileSystemInfoEntry>, Set<string>, Set<string>): void} callback aggregated callback
33
33
  * @param {function(string, number): void} callbackUndelayed callback when the first change was detected
34
34
  * @returns {Watcher} a watcher
35
35
  */
@@ -18,6 +18,9 @@ const { getUndoPath } = require("../util/identifier");
18
18
  /** @typedef {import("../Chunk")} Chunk */
19
19
 
20
20
  class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
21
+ /**
22
+ * @param {ReadonlySet<string>} runtimeRequirements runtime requirements
23
+ */
21
24
  constructor(runtimeRequirements) {
22
25
  super("readFile chunk loading", RuntimeModule.STAGE_ATTACH);
23
26
  this.runtimeRequirements = runtimeRequirements;
@@ -78,7 +81,7 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
78
81
  );
79
82
  const rootOutputDir = getUndoPath(
80
83
  outputName,
81
- this.compilation.outputOptions.path,
84
+ /** @type {string} */ (this.compilation.outputOptions.path),
82
85
  false
83
86
  );
84
87
 
@@ -10,6 +10,7 @@ const RuntimeGlobals = require("../RuntimeGlobals");
10
10
  const Template = require("../Template");
11
11
  const AsyncWasmLoadingRuntimeModule = require("../wasm-async/AsyncWasmLoadingRuntimeModule");
12
12
 
13
+ /** @typedef {import("../Chunk")} Chunk */
13
14
  /** @typedef {import("../Compiler")} Compiler */
14
15
 
15
16
  class ReadFileCompileAsyncWasmPlugin {
@@ -27,6 +28,10 @@ class ReadFileCompileAsyncWasmPlugin {
27
28
  "ReadFileCompileAsyncWasmPlugin",
28
29
  compilation => {
29
30
  const globalWasmLoading = compilation.outputOptions.wasmLoading;
31
+ /**
32
+ * @param {Chunk} chunk chunk
33
+ * @returns {boolean} true, if wasm loading is enabled for the chunk
34
+ */
30
35
  const isEnabledForChunk = chunk => {
31
36
  const options = chunk.getEntryOptions();
32
37
  const wasmLoading =
@@ -35,6 +40,9 @@ class ReadFileCompileAsyncWasmPlugin {
35
40
  : globalWasmLoading;
36
41
  return wasmLoading === this._type;
37
42
  };
43
+ /**
44
+ * @type {(path: string) => string}
45
+ */
38
46
  const generateLoadBinaryCode = this._import
39
47
  ? path =>
40
48
  Template.asString([
@@ -10,13 +10,22 @@ const RuntimeGlobals = require("../RuntimeGlobals");
10
10
  const Template = require("../Template");
11
11
  const WasmChunkLoadingRuntimeModule = require("../wasm-sync/WasmChunkLoadingRuntimeModule");
12
12
 
13
+ /** @typedef {import("../Chunk")} Chunk */
13
14
  /** @typedef {import("../Compiler")} Compiler */
14
15
 
16
+ /**
17
+ * @typedef {Object} ReadFileCompileWasmPluginOptions
18
+ * @property {boolean} [mangleImports] mangle imports
19
+ */
20
+
15
21
  // TODO webpack 6 remove
16
22
 
17
23
  class ReadFileCompileWasmPlugin {
18
- constructor(options) {
19
- this.options = options || {};
24
+ /**
25
+ * @param {ReadFileCompileWasmPluginOptions} [options] options object
26
+ */
27
+ constructor(options = {}) {
28
+ this.options = options;
20
29
  }
21
30
 
22
31
  /**
@@ -29,6 +38,10 @@ class ReadFileCompileWasmPlugin {
29
38
  "ReadFileCompileWasmPlugin",
30
39
  compilation => {
31
40
  const globalWasmLoading = compilation.outputOptions.wasmLoading;
41
+ /**
42
+ * @param {Chunk} chunk chunk
43
+ * @returns {boolean} true, when wasm loading is enabled for the chunk
44
+ */
32
45
  const isEnabledForChunk = chunk => {
33
46
  const options = chunk.getEntryOptions();
34
47
  const wasmLoading =
@@ -37,6 +50,10 @@ class ReadFileCompileWasmPlugin {
37
50
  : globalWasmLoading;
38
51
  return wasmLoading === "async-node";
39
52
  };
53
+ /**
54
+ * @param {string} path path to wasm file
55
+ * @returns {string} generated code to load the wasm file
56
+ */
40
57
  const generateLoadBinaryCode = path =>
41
58
  Template.asString([
42
59
  "new Promise(function (resolve, reject) {",
@@ -18,6 +18,9 @@ const { getUndoPath } = require("../util/identifier");
18
18
  /** @typedef {import("../Chunk")} Chunk */
19
19
 
20
20
  class RequireChunkLoadingRuntimeModule extends RuntimeModule {
21
+ /**
22
+ * @param {ReadonlySet<string>} runtimeRequirements runtime requirements
23
+ */
21
24
  constructor(runtimeRequirements) {
22
25
  super("require chunk loading", RuntimeModule.STAGE_ATTACH);
23
26
  this.runtimeRequirements = runtimeRequirements;
@@ -78,7 +81,7 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
78
81
  );
79
82
  const rootOutputDir = getUndoPath(
80
83
  outputName,
81
- this.compilation.outputOptions.path,
84
+ /** @type {string} */ (this.compilation.outputOptions.path),
82
85
  true
83
86
  );
84
87
 
@@ -21,7 +21,7 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
21
21
  const fn = RuntimeGlobals.asyncModule;
22
22
  return Template.asString([
23
23
  'var webpackQueues = typeof Symbol === "function" ? Symbol("webpack queues") : "__webpack_queues__";',
24
- 'var webpackExports = typeof Symbol === "function" ? Symbol("webpack exports") : "__webpack_exports__";',
24
+ `var webpackExports = typeof Symbol === "function" ? Symbol("webpack exports") : "${RuntimeGlobals.exports}";`,
25
25
  'var webpackError = typeof Symbol === "function" ? Symbol("webpack error") : "__webpack_error__";',
26
26
  `var resolveQueue = ${runtimeTemplate.basicFunction("queue", [
27
27
  "if(queue && !queue.d) {",
@@ -31,7 +31,11 @@ class AutoPublicPathRuntimeModule extends RuntimeModule {
31
31
  contentHashType: "javascript"
32
32
  }
33
33
  );
34
- const undoPath = getUndoPath(chunkName, path, false);
34
+ const undoPath = getUndoPath(
35
+ chunkName,
36
+ /** @type {string} */ (path),
37
+ false
38
+ );
35
39
 
36
40
  return Template.asString([
37
41
  "var scriptUrl;",
@@ -8,6 +8,8 @@
8
8
  const RuntimeGlobals = require("../RuntimeGlobals");
9
9
  const RuntimeModule = require("../RuntimeModule");
10
10
 
11
+ /** @typedef {import("../../declarations/WebpackOptions").EntryDescriptionNormalized} EntryDescriptionNormalized */
12
+
11
13
  class BaseUriRuntimeModule extends RuntimeModule {
12
14
  constructor() {
13
15
  super("base uri", RuntimeModule.STAGE_ATTACH);
@@ -19,7 +21,9 @@ class BaseUriRuntimeModule extends RuntimeModule {
19
21
  generate() {
20
22
  const { chunk } = this;
21
23
 
22
- const options = chunk.getEntryOptions();
24
+ const options =
25
+ /** @type {EntryDescriptionNormalized} */
26
+ (chunk.getEntryOptions());
23
27
  return `${RuntimeGlobals.baseURI} = ${
24
28
  options.baseUri === undefined
25
29
  ? "undefined"
@@ -9,6 +9,9 @@ const RuntimeModule = require("../RuntimeModule");
9
9
  const Template = require("../Template");
10
10
 
11
11
  class EnsureChunkRuntimeModule extends RuntimeModule {
12
+ /**
13
+ * @param {ReadonlySet<string>} runtimeRequirements runtime requirements
14
+ */
12
15
  constructor(runtimeRequirements) {
13
16
  super("ensure chunk");
14
17
  this.runtimeRequirements = runtimeRequirements;