webpack 5.84.0 → 5.85.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 (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 +18 -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 +11 -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 +50 -16
  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 +186 -141
@@ -17,7 +17,9 @@ const {
17
17
  } = require("../javascript/JavascriptModulesPlugin");
18
18
  const { updateHashForEntryStartup } = require("../javascript/StartupHelpers");
19
19
 
20
+ /** @typedef {import("../Chunk")} Chunk */
20
21
  /** @typedef {import("../Compiler")} Compiler */
22
+ /** @typedef {import("../Entrypoint")} Entrypoint */
21
23
 
22
24
  class ModuleChunkFormatPlugin {
23
25
  /**
@@ -73,7 +75,9 @@ class ModuleChunkFormatPlugin {
73
75
  chunkGraph.getChunkEntryModulesWithChunkGroupIterable(chunk)
74
76
  );
75
77
  if (entries.length > 0) {
76
- const runtimeChunk = entries[0][1].getRuntimeChunk();
78
+ const runtimeChunk =
79
+ /** @type {Entrypoint[][]} */
80
+ (entries)[0][1].getRuntimeChunk();
77
81
  const currentOutputName = compilation
78
82
  .getPath(
79
83
  getChunkFilenameTemplate(chunk, compilation.outputOptions),
@@ -87,6 +91,10 @@ class ModuleChunkFormatPlugin {
87
91
  // remove filename, we only need the directory
88
92
  currentOutputName.pop();
89
93
 
94
+ /**
95
+ * @param {Chunk} chunk the chunk
96
+ * @returns {string} the relative path
97
+ */
90
98
  const getRelativePath = chunk => {
91
99
  const baseOutputName = currentOutputName.slice();
92
100
  const chunkOutputName = compilation
@@ -124,7 +132,7 @@ class ModuleChunkFormatPlugin {
124
132
  entrySource.add(";\n\n// load runtime\n");
125
133
  entrySource.add(
126
134
  `import ${RuntimeGlobals.require} from ${JSON.stringify(
127
- getRelativePath(runtimeChunk)
135
+ getRelativePath(/** @type {Chunk} */ (runtimeChunk))
128
136
  )};\n`
129
137
  );
130
138
 
@@ -143,8 +151,8 @@ class ModuleChunkFormatPlugin {
143
151
  const final = i + 1 === entries.length;
144
152
  const moduleId = chunkGraph.getModuleId(module);
145
153
  const chunks = getAllChunks(
146
- entrypoint,
147
- runtimeChunk,
154
+ /** @type {Entrypoint} */ (entrypoint),
155
+ /** @type {Chunk} */ (runtimeChunk),
148
156
  undefined
149
157
  );
150
158
  for (const chunk of chunks) {
@@ -166,7 +174,7 @@ class ModuleChunkFormatPlugin {
166
174
  }
167
175
  startupSource.add(
168
176
  `${
169
- final ? "var __webpack_exports__ = " : ""
177
+ final ? `var ${RuntimeGlobals.exports} = ` : ""
170
178
  }__webpack_exec__(${JSON.stringify(moduleId)});\n`
171
179
  );
172
180
  }
@@ -9,6 +9,7 @@ const RuntimeGlobals = require("../RuntimeGlobals");
9
9
  const ExportWebpackRequireRuntimeModule = require("./ExportWebpackRequireRuntimeModule");
10
10
  const ModuleChunkLoadingRuntimeModule = require("./ModuleChunkLoadingRuntimeModule");
11
11
 
12
+ /** @typedef {import("../Chunk")} Chunk */
12
13
  /** @typedef {import("../Compiler")} Compiler */
13
14
 
14
15
  class ModuleChunkLoadingPlugin {
@@ -22,6 +23,10 @@ class ModuleChunkLoadingPlugin {
22
23
  "ModuleChunkLoadingPlugin",
23
24
  compilation => {
24
25
  const globalChunkLoading = compilation.outputOptions.chunkLoading;
26
+ /**
27
+ * @param {Chunk} chunk chunk to check
28
+ * @returns {boolean} true, when the plugin is enabled for the chunk
29
+ */
25
30
  const isEnabledForChunk = chunk => {
26
31
  const options = chunk.getEntryOptions();
27
32
  const chunkLoading =
@@ -31,6 +36,10 @@ class ModuleChunkLoadingPlugin {
31
36
  return chunkLoading === "import";
32
37
  };
33
38
  const onceForChunkSet = new WeakSet();
39
+ /**
40
+ * @param {Chunk} chunk chunk to check
41
+ * @param {Set<string>} set runtime requirements
42
+ */
34
43
  const handler = (chunk, set) => {
35
44
  if (onceForChunkSet.has(chunk)) return;
36
45
  onceForChunkSet.add(chunk);
@@ -18,6 +18,7 @@ const compileBooleanMatcher = require("../util/compileBooleanMatcher");
18
18
  const { getUndoPath } = require("../util/identifier");
19
19
 
20
20
  /** @typedef {import("../Chunk")} Chunk */
21
+ /** @typedef {import("../ChunkGraph")} ChunkGraph */
21
22
 
22
23
  /**
23
24
  * @typedef {Object} JsonpCompilationPluginHooks
@@ -69,11 +70,10 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
69
70
  if (options && options.baseUri) {
70
71
  return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`;
71
72
  }
73
+ const compilation = /** @type {Compilation} */ (this.compilation);
72
74
  const {
73
- compilation: {
74
- outputOptions: { importMetaName }
75
- }
76
- } = this;
75
+ outputOptions: { importMetaName }
76
+ } = compilation;
77
77
  return `${RuntimeGlobals.baseURI} = new URL(${JSON.stringify(
78
78
  rootOutputDir
79
79
  )}, ${importMetaName}.url);`;
@@ -83,7 +83,9 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
83
83
  * @returns {string} runtime code
84
84
  */
85
85
  generate() {
86
- const { compilation, chunk, chunkGraph } = this;
86
+ const compilation = /** @type {Compilation} */ (this.compilation);
87
+ const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
88
+ const chunk = /** @type {Chunk} */ (this.chunk);
87
89
  const {
88
90
  runtimeTemplate,
89
91
  outputOptions: { importFunctionName }
@@ -106,8 +108,8 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
106
108
  const hasJsMatcher = compileBooleanMatcher(conditionMap);
107
109
  const initialChunkIds = getInitialChunkIds(chunk, chunkGraph, chunkHasJs);
108
110
 
109
- const outputName = this.compilation.getPath(
110
- getChunkFilenameTemplate(chunk, this.compilation.outputOptions),
111
+ const outputName = compilation.getPath(
112
+ getChunkFilenameTemplate(chunk, compilation.outputOptions),
111
113
  {
112
114
  chunk,
113
115
  contentHashType: "javascript"
@@ -115,7 +117,7 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
115
117
  );
116
118
  const rootOutputDir = getUndoPath(
117
119
  outputName,
118
- /** @type {string} */ (this.compilation.outputOptions.path),
120
+ /** @type {string} */ (compilation.outputOptions.path),
119
121
  true
120
122
  );
121
123
 
@@ -303,7 +303,7 @@ class LazyCompilationDependencyFactory extends ModuleFactory {
303
303
 
304
304
  /**
305
305
  * @param {ModuleFactoryCreateData} data data object
306
- * @param {function(Error=, ModuleFactoryResult=): void} callback callback
306
+ * @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
307
307
  * @returns {void}
308
308
  */
309
309
  create(data, callback) {
@@ -13,7 +13,18 @@ const {
13
13
 
14
14
  /** @typedef {import("../Compiler")} Compiler */
15
15
 
16
+ /**
17
+ * @typedef {Object} ChunkModuleIdRangePluginOptions
18
+ * @property {string} name the chunk name
19
+ * @property {("index" | "index2" | "preOrderIndex" | "postOrderIndex")=} order order
20
+ * @property {number=} start start id
21
+ * @property {number=} end end id
22
+ */
23
+
16
24
  class ChunkModuleIdRangePlugin {
25
+ /**
26
+ * @param {ChunkModuleIdRangePluginOptions} options options object
27
+ */
17
28
  constructor(options) {
18
29
  this.options = options;
19
30
  }
@@ -15,9 +15,18 @@ const {
15
15
  /** @typedef {import("../Compiler")} Compiler */
16
16
  /** @typedef {import("../Module")} Module */
17
17
 
18
+ /**
19
+ * @typedef {Object} DeterministicChunkIdsPluginOptions
20
+ * @property {string=} context context for ids
21
+ * @property {number=} maxLength maximum length of ids
22
+ */
23
+
18
24
  class DeterministicChunkIdsPlugin {
19
- constructor(options) {
20
- this.options = options || {};
25
+ /**
26
+ * @param {DeterministicChunkIdsPluginOptions} [options] options
27
+ */
28
+ constructor(options = {}) {
29
+ this.options = options;
21
30
  }
22
31
 
23
32
  /**
@@ -17,15 +17,19 @@ const {
17
17
  /** @typedef {import("../Compiler")} Compiler */
18
18
  /** @typedef {import("../Module")} Module */
19
19
 
20
+ /**
21
+ * @typedef {Object} DeterministicModuleIdsPluginOptions
22
+ * @property {string=} context context relative to which module identifiers are computed
23
+ * @property {function(Module): boolean=} test selector function for modules
24
+ * @property {number=} maxLength maximum id length in digits (used as starting point)
25
+ * @property {number=} salt hash salt for ids
26
+ * @property {boolean=} fixedLength do not increase the maxLength to find an optimal id space size
27
+ * @property {boolean=} failOnConflict throw an error when id conflicts occur (instead of rehashing)
28
+ */
29
+
20
30
  class DeterministicModuleIdsPlugin {
21
31
  /**
22
- * @param {Object} options options
23
- * @param {string=} options.context context relative to which module identifiers are computed
24
- * @param {function(Module): boolean=} options.test selector function for modules
25
- * @param {number=} options.maxLength maximum id length in digits (used as starting point)
26
- * @param {number=} options.salt hash salt for ids
27
- * @param {boolean=} options.fixedLength do not increase the maxLength to find an optimal id space size
28
- * @param {boolean=} options.failOnConflict throw an error when id conflicts occur (instead of rehashing)
32
+ * @param {DeterministicModuleIdsPluginOptions} [options] options
29
33
  */
30
34
  constructor(options = {}) {
31
35
  this.options = options;
@@ -16,6 +16,7 @@ const {
16
16
  } = require("./IdHelpers");
17
17
 
18
18
  /** @typedef {import("../../declarations/plugins/HashedModuleIdsPlugin").HashedModuleIdsPluginOptions} HashedModuleIdsPluginOptions */
19
+ /** @typedef {import("../Compiler")} Compiler */
19
20
 
20
21
  const validate = createSchemaValidation(
21
22
  require("../../schemas/plugins/HashedModuleIdsPlugin.check.js"),
@@ -43,6 +44,11 @@ class HashedModuleIdsPlugin {
43
44
  };
44
45
  }
45
46
 
47
+ /**
48
+ * Apply the plugin
49
+ * @param {Compiler} compiler the compiler instance
50
+ * @returns {void}
51
+ */
46
52
  apply(compiler) {
47
53
  const options = this.options;
48
54
  compiler.hooks.compilation.tap("HashedModuleIdsPlugin", compilation => {
@@ -64,7 +70,8 @@ class HashedModuleIdsPlugin {
64
70
  hash.digest(options.hashDigest)
65
71
  );
66
72
  let len = options.hashDigestLength;
67
- while (usedIds.has(hashId.slice(0, len))) len++;
73
+ while (usedIds.has(hashId.slice(0, len)))
74
+ /** @type {number} */ (len)++;
68
75
  const moduleId = hashId.slice(0, len);
69
76
  chunkGraph.setModuleId(module, moduleId);
70
77
  usedIds.add(moduleId);
@@ -427,6 +427,9 @@ const assignAscendingModuleIds = (usedIds, modules, compilation) => {
427
427
  let nextId = 0;
428
428
  let assignId;
429
429
  if (usedIds.size > 0) {
430
+ /**
431
+ * @param {Module} module the module
432
+ */
430
433
  assignId = module => {
431
434
  if (chunkGraph.getModuleId(module) === null) {
432
435
  while (usedIds.has(nextId + "")) nextId++;
@@ -434,6 +437,9 @@ const assignAscendingModuleIds = (usedIds, modules, compilation) => {
434
437
  }
435
438
  };
436
439
  } else {
440
+ /**
441
+ * @param {Module} module the module
442
+ */
437
443
  assignId = module => {
438
444
  if (chunkGraph.getModuleId(module) === null) {
439
445
  chunkGraph.setModuleId(module, nextId++);
@@ -14,11 +14,21 @@ const {
14
14
  assignAscendingChunkIds
15
15
  } = require("./IdHelpers");
16
16
 
17
+ /** @typedef {import("../../declarations/WebpackOptions").OutputNormalized} Output */
17
18
  /** @typedef {import("../Chunk")} Chunk */
18
19
  /** @typedef {import("../Compiler")} Compiler */
19
20
  /** @typedef {import("../Module")} Module */
20
21
 
22
+ /**
23
+ * @typedef {Object} NamedChunkIdsPluginOptions
24
+ * @property {string} [context] context
25
+ * @property {string} [delimiter] delimiter
26
+ */
27
+
21
28
  class NamedChunkIdsPlugin {
29
+ /**
30
+ * @param {NamedChunkIdsPluginOptions=} options options
31
+ */
22
32
  constructor(options) {
23
33
  this.delimiter = (options && options.delimiter) || "-";
24
34
  this.context = options && options.context;
@@ -31,7 +41,9 @@ class NamedChunkIdsPlugin {
31
41
  */
32
42
  apply(compiler) {
33
43
  compiler.hooks.compilation.tap("NamedChunkIdsPlugin", compilation => {
34
- const { hashFunction } = compilation.outputOptions;
44
+ const hashFunction =
45
+ /** @type {NonNullable<Output["hashFunction"]>} */
46
+ (compilation.outputOptions.hashFunction);
35
47
  compilation.hooks.chunkIds.tap("NamedChunkIdsPlugin", chunks => {
36
48
  const chunkGraph = compilation.chunkGraph;
37
49
  const context = this.context ? this.context : compiler.context;
@@ -14,12 +14,21 @@ const {
14
14
  assignAscendingModuleIds
15
15
  } = require("./IdHelpers");
16
16
 
17
+ /** @typedef {import("../../declarations/WebpackOptions").OutputNormalized} Output */
17
18
  /** @typedef {import("../Compiler")} Compiler */
18
19
  /** @typedef {import("../Module")} Module */
19
20
 
21
+ /**
22
+ * @typedef {Object} NamedModuleIdsPluginOptions
23
+ * @property {string} [context] context
24
+ */
25
+
20
26
  class NamedModuleIdsPlugin {
21
- constructor(options) {
22
- this.options = options || {};
27
+ /**
28
+ * @param {NamedModuleIdsPluginOptions} [options] options
29
+ */
30
+ constructor(options = {}) {
31
+ this.options = options;
23
32
  }
24
33
 
25
34
  /**
@@ -30,7 +39,9 @@ class NamedModuleIdsPlugin {
30
39
  apply(compiler) {
31
40
  const { root } = compiler;
32
41
  compiler.hooks.compilation.tap("NamedModuleIdsPlugin", compilation => {
33
- const { hashFunction } = compilation.outputOptions;
42
+ const hashFunction =
43
+ /** @type {NonNullable<Output["hashFunction"]>} */
44
+ (compilation.outputOptions.hashFunction);
34
45
  compilation.hooks.moduleIds.tap("NamedModuleIdsPlugin", () => {
35
46
  const chunkGraph = compilation.chunkGraph;
36
47
  const context = this.options.context
@@ -60,8 +60,12 @@ class OccurrenceChunkIdsPlugin {
60
60
 
61
61
  const chunksInOccurrenceOrder = Array.from(chunks).sort((a, b) => {
62
62
  if (prioritiseInitial) {
63
- const aEntryOccurs = occursInInitialChunksMap.get(a);
64
- const bEntryOccurs = occursInInitialChunksMap.get(b);
63
+ const aEntryOccurs =
64
+ /** @type {number} */
65
+ (occursInInitialChunksMap.get(a));
66
+ const bEntryOccurs =
67
+ /** @type {number} */
68
+ (occursInInitialChunksMap.get(b));
65
69
  if (aEntryOccurs > bEntryOccurs) return -1;
66
70
  if (aEntryOccurs < bEntryOccurs) return 1;
67
71
  }
@@ -50,7 +50,7 @@ class SyncModuleIdsPlugin {
50
50
  }
51
51
  return callback();
52
52
  }
53
- const json = JSON.parse(buffer.toString());
53
+ const json = JSON.parse(/** @type {Buffer} */ (buffer).toString());
54
54
  data = new Map();
55
55
  for (const key of Object.keys(json)) {
56
56
  data.set(key, json[key]);
@@ -98,7 +98,7 @@ class SyncModuleIdsPlugin {
98
98
  err.module = module;
99
99
  compilation.errors.push(err);
100
100
  }
101
- chunkGraph.setModuleId(module, id);
101
+ chunkGraph.setModuleId(module, /** @type {string | number} */ (id));
102
102
  usedIds.add(idAsString);
103
103
  }
104
104
  });
@@ -121,7 +121,7 @@ class ArrayPushCallbackChunkFormatPlugin {
121
121
  .getChunkRuntimeRequirements(chunk)
122
122
  .has(RuntimeGlobals.returnExportsFromRuntime)
123
123
  ) {
124
- runtime.add("return __webpack_exports__;\n");
124
+ runtime.add(`return ${RuntimeGlobals.exports};\n`);
125
125
  }
126
126
  }
127
127
  runtime.add("}\n");
@@ -70,6 +70,8 @@ class BasicEvaluatedExpression {
70
70
  this.getMembers = undefined;
71
71
  /** @type {() => boolean[]} */
72
72
  this.getMembersOptionals = undefined;
73
+ /** @type {() => number[]} */
74
+ this.getMemberRangeStarts = undefined;
73
75
  /** @type {EsTreeNode} */
74
76
  this.expression = undefined;
75
77
  }
@@ -384,14 +386,22 @@ class BasicEvaluatedExpression {
384
386
  * @param {string | VariableInfoInterface} rootInfo root info
385
387
  * @param {() => string[]} getMembers members
386
388
  * @param {() => boolean[]=} getMembersOptionals optional members
389
+ * @param {() => number[]=} getMemberRangeStarts range start of progressively increasing sub-expressions
387
390
  * @returns {this} this
388
391
  */
389
- setIdentifier(identifier, rootInfo, getMembers, getMembersOptionals) {
392
+ setIdentifier(
393
+ identifier,
394
+ rootInfo,
395
+ getMembers,
396
+ getMembersOptionals,
397
+ getMemberRangeStarts
398
+ ) {
390
399
  this.type = TypeIdentifier;
391
400
  this.identifier = identifier;
392
401
  this.rootInfo = rootInfo;
393
402
  this.getMembers = getMembers;
394
403
  this.getMembersOptionals = getMembersOptionals;
404
+ this.getMemberRangeStarts = getMemberRangeStarts;
395
405
  this.sideEffects = true;
396
406
  return this;
397
407
  }
@@ -11,8 +11,8 @@ const Entrypoint = require("../Entrypoint");
11
11
 
12
12
  /**
13
13
  * @param {Entrypoint} entrypoint a chunk group
14
- * @param {Chunk} excludedChunk1 current chunk which is excluded
15
- * @param {Chunk} excludedChunk2 runtime chunk which is excluded
14
+ * @param {Chunk=} excludedChunk1 current chunk which is excluded
15
+ * @param {Chunk=} excludedChunk2 runtime chunk which is excluded
16
16
  * @returns {Set<Chunk>} chunks
17
17
  */
18
18
  const getAllChunks = (entrypoint, excludedChunk1, excludedChunk2) => {
@@ -11,6 +11,10 @@
11
11
  /** @type {WeakMap<Compiler, Set<ChunkLoadingType>>} */
12
12
  const enabledTypes = new WeakMap();
13
13
 
14
+ /**
15
+ * @param {Compiler} compiler compiler
16
+ * @returns {Set<ChunkLoadingType>} enabled types
17
+ */
14
18
  const getEnabledTypes = compiler => {
15
19
  let set = enabledTypes.get(compiler);
16
20
  if (set === undefined) {
@@ -130,8 +130,8 @@ const printGeneratedCodeForStack = (module, code) => {
130
130
  * @property {SyncWaterfallHook<[Source, Module, StartupRenderContext]>} renderStartup
131
131
  * @property {SyncWaterfallHook<[string, RenderBootstrapContext]>} renderRequire
132
132
  * @property {SyncBailHook<[Module, RenderBootstrapContext], string>} inlineInRuntimeBailout
133
- * @property {SyncBailHook<[Module, RenderContext], string>} embedInRuntimeBailout
134
- * @property {SyncBailHook<[RenderContext], string>} strictRuntimeBailout
133
+ * @property {SyncBailHook<[Module, RenderContext], string | void>} embedInRuntimeBailout
134
+ * @property {SyncBailHook<[RenderContext], string | void>} strictRuntimeBailout
135
135
  * @property {SyncHook<[Chunk, Hash, ChunkHashContext]>} chunkHash
136
136
  * @property {SyncBailHook<[Chunk, RenderContext], boolean>} useSourceMap
137
137
  */
@@ -691,6 +691,7 @@ class JavascriptModulesPlugin {
691
691
  );
692
692
 
693
693
  const hasEntryModules = chunkGraph.getNumberOfEntryModules(chunk) > 0;
694
+ /** @type {Set<Module> | undefined} */
694
695
  let inlinedModules;
695
696
  if (bootstrap.allowInlineStartup && hasEntryModules) {
696
697
  inlinedModules = new Set(chunkGraph.getChunkEntryModulesIterable(chunk));
@@ -732,7 +733,9 @@ class JavascriptModulesPlugin {
732
733
  const chunkModules = Template.renderChunkModules(
733
734
  chunkRenderContext,
734
735
  inlinedModules
735
- ? allModules.filter(m => !inlinedModules.has(m))
736
+ ? allModules.filter(
737
+ m => !(/** @type {Set<Module>} */ (inlinedModules).has(m))
738
+ )
736
739
  : allModules,
737
740
  module => this.renderModule(module, chunkRenderContext, hooks, true),
738
741
  prefix
@@ -798,7 +801,7 @@ class JavascriptModulesPlugin {
798
801
  }
799
802
  const lastInlinedModule = last(inlinedModules);
800
803
  const startupSource = new ConcatSource();
801
- startupSource.add(`var __webpack_exports__ = {};\n`);
804
+ startupSource.add(`var ${RuntimeGlobals.exports} = {};\n`);
802
805
  for (const m of inlinedModules) {
803
806
  const renderedModule = this.renderModule(
804
807
  m,
@@ -814,7 +817,7 @@ class JavascriptModulesPlugin {
814
817
  );
815
818
  const exports = runtimeRequirements.has(RuntimeGlobals.exports);
816
819
  const webpackExports =
817
- exports && m.exportsArgument === "__webpack_exports__";
820
+ exports && m.exportsArgument === RuntimeGlobals.exports;
818
821
  let iife = innerStrict
819
822
  ? "it need to be in strict mode."
820
823
  : inlinedModules.size > 1
@@ -846,9 +849,9 @@ class JavascriptModulesPlugin {
846
849
  if (exports) {
847
850
  if (m !== lastInlinedModule)
848
851
  startupSource.add(`var ${m.exportsArgument} = {};\n`);
849
- else if (m.exportsArgument !== "__webpack_exports__")
852
+ else if (m.exportsArgument !== RuntimeGlobals.exports)
850
853
  startupSource.add(
851
- `var ${m.exportsArgument} = __webpack_exports__;\n`
854
+ `var ${m.exportsArgument} = ${RuntimeGlobals.exports};\n`
852
855
  );
853
856
  }
854
857
  startupSource.add(renderedModule);
@@ -857,7 +860,7 @@ class JavascriptModulesPlugin {
857
860
  }
858
861
  if (runtimeRequirements.has(RuntimeGlobals.onChunksLoaded)) {
859
862
  startupSource.add(
860
- `__webpack_exports__ = ${RuntimeGlobals.onChunksLoaded}(__webpack_exports__);\n`
863
+ `${RuntimeGlobals.exports} = ${RuntimeGlobals.onChunksLoaded}(${RuntimeGlobals.exports});\n`
861
864
  );
862
865
  }
863
866
  source.add(
@@ -909,7 +912,7 @@ class JavascriptModulesPlugin {
909
912
  hasEntryModules &&
910
913
  runtimeRequirements.has(RuntimeGlobals.returnExportsFromRuntime)
911
914
  ) {
912
- source.add(`${prefix}return __webpack_exports__;\n`);
915
+ source.add(`${prefix}return ${RuntimeGlobals.exports};\n`);
913
916
  }
914
917
  if (iife) {
915
918
  source.add("/******/ })()\n");
@@ -1158,7 +1161,7 @@ class JavascriptModulesPlugin {
1158
1161
  }
1159
1162
  if (chunks.length > 0) {
1160
1163
  buf2.push(
1161
- `${i === 0 ? "var __webpack_exports__ = " : ""}${
1164
+ `${i === 0 ? `var ${RuntimeGlobals.exports} = ` : ""}${
1162
1165
  RuntimeGlobals.onChunksLoaded
1163
1166
  }(undefined, ${JSON.stringify(
1164
1167
  chunks.map(c => c.id)
@@ -1168,22 +1171,22 @@ class JavascriptModulesPlugin {
1168
1171
  );
1169
1172
  } else if (useRequire) {
1170
1173
  buf2.push(
1171
- `${i === 0 ? "var __webpack_exports__ = " : ""}${
1174
+ `${i === 0 ? `var ${RuntimeGlobals.exports} = ` : ""}${
1172
1175
  RuntimeGlobals.require
1173
1176
  }(${moduleIdExpr});`
1174
1177
  );
1175
1178
  } else {
1176
- if (i === 0) buf2.push("var __webpack_exports__ = {};");
1179
+ if (i === 0) buf2.push(`var ${RuntimeGlobals.exports} = {};`);
1177
1180
  if (requireScopeUsed) {
1178
1181
  buf2.push(
1179
1182
  `__webpack_modules__[${moduleIdExpr}](0, ${
1180
- i === 0 ? "__webpack_exports__" : "{}"
1183
+ i === 0 ? RuntimeGlobals.exports : "{}"
1181
1184
  }, ${RuntimeGlobals.require});`
1182
1185
  );
1183
1186
  } else if (entryRuntimeRequirements.has(RuntimeGlobals.exports)) {
1184
1187
  buf2.push(
1185
1188
  `__webpack_modules__[${moduleIdExpr}](0, ${
1186
- i === 0 ? "__webpack_exports__" : "{}"
1189
+ i === 0 ? RuntimeGlobals.exports : "{}"
1187
1190
  });`
1188
1191
  );
1189
1192
  } else {
@@ -1193,7 +1196,7 @@ class JavascriptModulesPlugin {
1193
1196
  }
1194
1197
  if (runtimeRequirements.has(RuntimeGlobals.onChunksLoaded)) {
1195
1198
  buf2.push(
1196
- `__webpack_exports__ = ${RuntimeGlobals.onChunksLoaded}(__webpack_exports__);`
1199
+ `${RuntimeGlobals.exports} = ${RuntimeGlobals.onChunksLoaded}(${RuntimeGlobals.exports});`
1197
1200
  );
1198
1201
  }
1199
1202
  if (
@@ -1206,13 +1209,13 @@ class JavascriptModulesPlugin {
1206
1209
  buf.push(
1207
1210
  `${RuntimeGlobals.startup} = ${runtimeTemplate.basicFunction("", [
1208
1211
  ...buf2,
1209
- "return __webpack_exports__;"
1212
+ `return ${RuntimeGlobals.exports};`
1210
1213
  ])};`
1211
1214
  );
1212
1215
  buf.push("");
1213
1216
  startup.push("// run startup");
1214
1217
  startup.push(
1215
- `var __webpack_exports__ = ${RuntimeGlobals.startup}();`
1218
+ `var ${RuntimeGlobals.exports} = ${RuntimeGlobals.startup}();`
1216
1219
  );
1217
1220
  } else if (runtimeRequirements.has(RuntimeGlobals.startupOnlyBefore)) {
1218
1221
  buf.push("// the startup function");
@@ -1260,7 +1263,9 @@ class JavascriptModulesPlugin {
1260
1263
  `${RuntimeGlobals.startup} = ${runtimeTemplate.emptyFunction()};`
1261
1264
  );
1262
1265
  startup.push("// run startup");
1263
- startup.push(`var __webpack_exports__ = ${RuntimeGlobals.startup}();`);
1266
+ startup.push(
1267
+ `var ${RuntimeGlobals.exports} = ${RuntimeGlobals.startup}();`
1268
+ );
1264
1269
  }
1265
1270
  return result;
1266
1271
  }
@@ -1346,7 +1351,7 @@ class JavascriptModulesPlugin {
1346
1351
  ? Template.asString([
1347
1352
  "",
1348
1353
  "// Flag the module as loaded",
1349
- "module.loaded = true;",
1354
+ `${RuntimeGlobals.moduleLoaded} = true;`,
1350
1355
  ""
1351
1356
  ])
1352
1357
  : "",