webpack 4.14.0 → 4.16.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.
Files changed (111) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +5 -2
  3. package/bin/webpack.js +7 -2
  4. package/buildin/amd-define.js +3 -3
  5. package/buildin/amd-options.js +2 -2
  6. package/buildin/system.js +7 -7
  7. package/hot/dev-server.js +2 -2
  8. package/hot/emitter.js +2 -2
  9. package/hot/only-dev-server.js +2 -2
  10. package/hot/poll.js +5 -2
  11. package/hot/signal.js +2 -2
  12. package/lib/AsyncDependenciesBlock.js +44 -0
  13. package/lib/AutomaticPrefetchPlugin.js +2 -2
  14. package/lib/Chunk.js +56 -6
  15. package/lib/ChunkGroup.js +2 -2
  16. package/lib/ChunkTemplate.js +14 -2
  17. package/lib/CommentCompilationWarning.js +3 -3
  18. package/lib/CompatibilityPlugin.js +1 -1
  19. package/lib/Compilation.js +442 -37
  20. package/lib/Compiler.js +57 -4
  21. package/lib/ContextModule.js +23 -16
  22. package/lib/DefinePlugin.js +49 -0
  23. package/lib/DelegatedModule.js +9 -1
  24. package/lib/DelegatedModuleFactoryPlugin.js +7 -1
  25. package/lib/DependenciesBlock.js +36 -3
  26. package/lib/DependenciesBlockVariable.js +22 -0
  27. package/lib/Dependency.js +33 -6
  28. package/lib/DllEntryPlugin.js +4 -1
  29. package/lib/DynamicEntryPlugin.js +21 -1
  30. package/lib/EntryOptionPlugin.js +12 -0
  31. package/lib/Entrypoint.js +1 -1
  32. package/lib/EnvironmentPlugin.js +8 -1
  33. package/lib/ExtendedAPIPlugin.js +8 -4
  34. package/lib/ExternalModuleFactoryPlugin.js +1 -1
  35. package/lib/Generator.js +1 -1
  36. package/lib/GraphHelpers.js +2 -1
  37. package/lib/HotModuleReplacement.runtime.js +8 -5
  38. package/lib/HotModuleReplacementPlugin.js +115 -117
  39. package/lib/IgnorePlugin.js +1 -1
  40. package/lib/MainTemplate.js +19 -4
  41. package/lib/MemoryOutputFileSystem.js +5 -5
  42. package/lib/Module.js +9 -3
  43. package/lib/ModuleReason.js +8 -0
  44. package/lib/MultiEntryPlugin.js +25 -3
  45. package/lib/NormalModule.js +5 -23
  46. package/lib/NullFactory.js +12 -12
  47. package/lib/OptionsApply.js +10 -10
  48. package/lib/RuleSet.js +3 -3
  49. package/lib/SingleEntryPlugin.js +20 -1
  50. package/lib/Stats.js +12 -5
  51. package/lib/Template.js +4 -1
  52. package/lib/UmdMainTemplatePlugin.js +12 -12
  53. package/lib/UseStrictPlugin.js +1 -1
  54. package/lib/WebpackError.js +4 -0
  55. package/lib/WebpackOptionsApply.js +92 -10
  56. package/lib/WebpackOptionsDefaulter.js +23 -6
  57. package/lib/WebpackOptionsValidationError.js +0 -1
  58. package/lib/compareLocations.js +13 -17
  59. package/lib/debug/ProfilingPlugin.js +5 -7
  60. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +4 -6
  61. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +0 -2
  62. package/lib/dependencies/AMDRequireItemDependency.js +22 -22
  63. package/lib/dependencies/CommonJsRequireDependency.js +22 -22
  64. package/lib/dependencies/CriticalDependencyWarning.js +20 -20
  65. package/lib/dependencies/DelegatedSourceDependency.js +18 -18
  66. package/lib/dependencies/DllEntryDependency.js +20 -20
  67. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -1
  68. package/lib/dependencies/LoaderDependency.js +3 -0
  69. package/lib/dependencies/LoaderPlugin.js +21 -2
  70. package/lib/dependencies/LocalModule.js +23 -23
  71. package/lib/dependencies/ModuleDependency.js +3 -0
  72. package/lib/dependencies/ModuleHotAcceptDependency.js +23 -23
  73. package/lib/dependencies/ModuleHotDeclineDependency.js +23 -23
  74. package/lib/dependencies/MultiEntryDependency.js +5 -0
  75. package/lib/dependencies/PrefetchDependency.js +18 -18
  76. package/lib/dependencies/RequireEnsureItemDependency.js +21 -21
  77. package/lib/dependencies/RequireResolveDependency.js +22 -22
  78. package/lib/dependencies/SingleEntryDependency.js +3 -0
  79. package/lib/dependencies/SystemPlugin.js +1 -1
  80. package/lib/formatLocation.js +55 -41
  81. package/lib/node/NodeMainTemplateAsync.runtime.js +1 -1
  82. package/lib/node/NodeMainTemplatePlugin.js +2 -2
  83. package/lib/node/NodeOutputFileSystem.js +22 -22
  84. package/lib/node/NodeSourcePlugin.js +1 -1
  85. package/lib/optimize/ConcatenatedModule.js +1 -0
  86. package/lib/optimize/NaturalChunkOrderPlugin.js +41 -0
  87. package/lib/optimize/OccurrenceChunkOrderPlugin.js +61 -0
  88. package/lib/optimize/OccurrenceModuleOrderPlugin.js +103 -0
  89. package/lib/optimize/OccurrenceOrderPlugin.js +4 -2
  90. package/lib/optimize/SplitChunksPlugin.js +168 -18
  91. package/lib/util/Semaphore.js +12 -0
  92. package/lib/util/SetHelpers.js +4 -4
  93. package/lib/util/SortableSet.js +1 -1
  94. package/lib/util/cachedMerge.js +1 -1
  95. package/lib/util/createHash.js +15 -0
  96. package/lib/util/deterministicGrouping.js +251 -0
  97. package/lib/util/identifier.js +27 -0
  98. package/lib/wasm/WasmFinalizeExportsPlugin.js +1 -1
  99. package/lib/wasm/WasmMainTemplatePlugin.js +10 -4
  100. package/lib/wasm/WebAssemblyGenerator.js +12 -12
  101. package/lib/wasm/WebAssemblyInInitialChunkError.js +88 -0
  102. package/lib/wasm/WebAssemblyModulesPlugin.js +28 -0
  103. package/lib/web/JsonpMainTemplatePlugin.js +1 -1
  104. package/lib/web/WebEnvironmentPlugin.js +18 -18
  105. package/lib/webpack.js +4 -0
  106. package/lib/webpack.web.js +2 -2
  107. package/lib/webworker/WebWorkerMainTemplatePlugin.js +1 -1
  108. package/package.json +27 -17
  109. package/schemas/WebpackOptions.json +71 -9
  110. package/schemas/plugins/optimize/OccurrenceOrderChunkIdsPlugin.json +10 -0
  111. package/schemas/plugins/optimize/OccurrenceOrderModuleIdsPlugin.json +10 -0
@@ -26,7 +26,6 @@ const ChunkTemplate = require("./ChunkTemplate");
26
26
  const HotUpdateChunkTemplate = require("./HotUpdateChunkTemplate");
27
27
  const ModuleTemplate = require("./ModuleTemplate");
28
28
  const RuntimeTemplate = require("./RuntimeTemplate");
29
- const Dependency = require("./Dependency");
30
29
  const ChunkRenderError = require("./ChunkRenderError");
31
30
  const AsyncDependencyToInitialChunkError = require("./AsyncDependencyToInitialChunkError");
32
31
  const Stats = require("./Stats");
@@ -35,20 +34,91 @@ const createHash = require("./util/createHash");
35
34
  const Queue = require("./util/Queue");
36
35
  const SortableSet = require("./util/SortableSet");
37
36
  const GraphHelpers = require("./GraphHelpers");
37
+ const ModuleDependency = require("./dependencies/ModuleDependency");
38
+ const compareLocations = require("./compareLocations");
38
39
 
39
40
  /** @typedef {import("./Module")} Module */
41
+ /** @typedef {import("./Compiler")} Compiler */
42
+ /** @typedef {import("webpack-sources").Source} Source */
43
+ /** @typedef {import("./WebpackError")} WebpackError */
44
+ /** @typedef {import("./DependenciesBlockVariable")} DependenciesBlockVariable */
45
+ /** @typedef {import("./dependencies/SingleEntryDependency")} SingleEntryDependency */
46
+ /** @typedef {import("./dependencies/MultiEntryDependency")} MultiEntryDependency */
47
+ /** @typedef {import("./dependencies/DllEntryDependency")} DllEntryDependency */
40
48
  /** @typedef {import("./dependencies/DependencyReference")} DependencyReference */
41
- /** @typedef {import("./Dependency")} Dependency */
42
49
  /** @typedef {import("./DependenciesBlock")} DependenciesBlock */
43
50
  /** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
44
- /** @typedef {import("webpack-sources").Source} Source */
45
-
51
+ /** @typedef {import("./Dependency")} Dependency */
52
+ /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
53
+ /** @typedef {import("./Dependency").DependencyTemplate} DependencyTemplate */
54
+ /** @typedef {import("./util/createHash").Hash} Hash */
55
+
56
+ // TODO use @callback
57
+ /** @typedef {{[assetName: string]: Source}} CompilationAssets */
58
+ /** @typedef {(err: Error|null, result?: Module) => void } ModuleCallback */
59
+ /** @typedef {(err?: Error|null, result?: Module) => void } ModuleChainCallback */
60
+ /** @typedef {(module: Module) => void} OnModuleCallback */
61
+ /** @typedef {(err?: Error|null) => void} Callback */
62
+ /** @typedef {(d: Dependency) => any} DepBlockVarDependenciesCallback */
63
+ /** @typedef {new (...args: any[]) => Dependency} DepConstructor */
64
+ /** @typedef {{apply: () => void}} Plugin */
65
+
66
+ /**
67
+ * @typedef {Object} ModuleFactoryCreateDataContextInfo
68
+ * @property {string} issuer
69
+ * @property {string} compiler
70
+ */
71
+
72
+ /**
73
+ * @typedef {Object} ModuleFactoryCreateData
74
+ * @property {ModuleFactoryCreateDataContextInfo} contextInfo
75
+ * @property {any=} resolveOptions
76
+ * @property {string} context
77
+ * @property {Dependency[]} dependencies
78
+ */
79
+
80
+ /**
81
+ * @typedef {Object} ModuleFactory
82
+ * @property {(data: ModuleFactoryCreateData, callback: ModuleCallback) => any} create
83
+ */
84
+
85
+ /**
86
+ * @typedef {Object} SortedDependency
87
+ * @property {ModuleFactory} factory
88
+ * @property {Dependency[]} dependencies
89
+ */
90
+
91
+ /**
92
+ * @typedef {Object} AvailableModulesChunkGroupMapping
93
+ * @property {ChunkGroup} chunkGroup
94
+ * @property {Set<Module>} availableModules
95
+ */
96
+
97
+ /**
98
+ * @typedef {Object} DependenciesBlockLike
99
+ * @property {Dependency[]} dependencies
100
+ * @property {AsyncDependenciesBlock[]} blocks
101
+ * @property {DependenciesBlockVariable[]} variables
102
+ */
103
+
104
+ /**
105
+ * @param {Chunk} a first chunk to sort by id
106
+ * @param {Chunk} b second chunk to sort by id
107
+ * @returns {-1|0|1} sort value
108
+ */
46
109
  const byId = (a, b) => {
47
- if (a.id < b.id) return -1;
48
- if (a.id > b.id) return 1;
110
+ if (a.id !== null && b.id !== null) {
111
+ if (a.id < b.id) return -1;
112
+ if (a.id > b.id) return 1;
113
+ }
49
114
  return 0;
50
115
  };
51
116
 
117
+ /**
118
+ * @param {Module} a first module to sort by
119
+ * @param {Module} b second module to sort by
120
+ * @returns {-1|0|1} sort value
121
+ */
52
122
  const byIdOrIdentifier = (a, b) => {
53
123
  if (a.id < b.id) return -1;
54
124
  if (a.id > b.id) return 1;
@@ -59,6 +129,11 @@ const byIdOrIdentifier = (a, b) => {
59
129
  return 0;
60
130
  };
61
131
 
132
+ /**
133
+ * @param {Module} a first module to sort by
134
+ * @param {Module} b second module to sort by
135
+ * @returns {-1|0|1} sort value
136
+ */
62
137
  const byIndexOrIdentifier = (a, b) => {
63
138
  if (a.index < b.index) return -1;
64
139
  if (a.index > b.index) return 1;
@@ -69,14 +144,24 @@ const byIndexOrIdentifier = (a, b) => {
69
144
  return 0;
70
145
  };
71
146
 
147
+ /**
148
+ * @param {Compilation} a first compilation to sort by
149
+ * @param {Compilation} b second compilation to sort by
150
+ * @returns {-1|0|1} sort value
151
+ */
72
152
  const byNameOrHash = (a, b) => {
73
153
  if (a.name < b.name) return -1;
74
154
  if (a.name > b.name) return 1;
75
155
  if (a.fullHash < b.fullHash) return -1;
76
- if (a.fullhash > b.fullHash) return 1;
156
+ if (a.fullHash > b.fullHash) return 1;
77
157
  return 0;
78
158
  };
79
159
 
160
+ /**
161
+ * @param {DependenciesBlockVariable[]} variables DepBlock Variables to iterate over
162
+ * @param {DepBlockVarDependenciesCallback} fn callback to apply on iterated elements
163
+ * @returns {void}
164
+ */
80
165
  const iterationBlockVariable = (variables, fn) => {
81
166
  for (
82
167
  let indexVariable = 0;
@@ -90,25 +175,45 @@ const iterationBlockVariable = (variables, fn) => {
90
175
  }
91
176
  };
92
177
 
178
+ /**
179
+ * @template T
180
+ * @param {T[]} arr array of elements to iterate over
181
+ * @param {function(T): void} fn callback applied to each element
182
+ * @returns {void}
183
+ */
93
184
  const iterationOfArrayCallback = (arr, fn) => {
94
185
  for (let index = 0; index < arr.length; index++) {
95
186
  fn(arr[index]);
96
187
  }
97
188
  };
98
189
 
99
- function addAllToSet(set, otherSet) {
190
+ /**
191
+ * @template T
192
+ * @param {Set<T>} set set to add items to
193
+ * @param {Set<T>} otherSet set to add items from
194
+ * @returns {void}
195
+ */
196
+ const addAllToSet = (set, otherSet) => {
100
197
  for (const item of otherSet) {
101
198
  set.add(item);
102
199
  }
103
- }
200
+ };
104
201
 
105
202
  class Compilation extends Tapable {
203
+ /**
204
+ * Creates an instance of Compilation.
205
+ * @param {Compiler} compiler the compiler which created the compilation
206
+ */
106
207
  constructor(compiler) {
107
208
  super();
108
209
  this.hooks = {
210
+ /** @type {SyncHook<Module>} */
109
211
  buildModule: new SyncHook(["module"]),
212
+ /** @type {SyncHook<Module>} */
110
213
  rebuildModule: new SyncHook(["module"]),
214
+ /** @type {SyncHook<Module, Error>} */
111
215
  failedModule: new SyncHook(["module", "error"]),
216
+ /** @type {SyncHook<Module>} */
112
217
  succeedModule: new SyncHook(["module"]),
113
218
 
114
219
  /** @type {SyncWaterfallHook<DependencyReference, Dependency, Module>} */
@@ -118,84 +223,146 @@ class Compilation extends Tapable {
118
223
  "module"
119
224
  ]),
120
225
 
226
+ /** @type {SyncHook<Module[]>} */
121
227
  finishModules: new SyncHook(["modules"]),
228
+ /** @type {SyncHook<Module>} */
122
229
  finishRebuildingModule: new SyncHook(["module"]),
123
-
230
+ /** @type {SyncHook} */
124
231
  unseal: new SyncHook([]),
232
+ /** @type {SyncHook} */
125
233
  seal: new SyncHook([]),
126
234
 
235
+ /** @type {SyncHook} */
236
+ beforeChunks: new SyncHook([]),
237
+ /** @type {SyncHook<Chunk[]>} */
238
+ afterChunks: new SyncHook(["chunks"]),
239
+
240
+ /** @type {SyncBailHook<Module[]>} */
127
241
  optimizeDependenciesBasic: new SyncBailHook(["modules"]),
242
+ /** @type {SyncBailHook<Module[]>} */
128
243
  optimizeDependencies: new SyncBailHook(["modules"]),
244
+ /** @type {SyncBailHook<Module[]>} */
129
245
  optimizeDependenciesAdvanced: new SyncBailHook(["modules"]),
246
+ /** @type {SyncBailHook<Module[]>} */
130
247
  afterOptimizeDependencies: new SyncHook(["modules"]),
131
248
 
249
+ /** @type {SyncHook} */
132
250
  optimize: new SyncHook([]),
133
-
251
+ /** @type {SyncBailHook<Module[]>} */
134
252
  optimizeModulesBasic: new SyncBailHook(["modules"]),
253
+ /** @type {SyncBailHook<Module[]>} */
135
254
  optimizeModules: new SyncBailHook(["modules"]),
255
+ /** @type {SyncBailHook<Module[]>} */
136
256
  optimizeModulesAdvanced: new SyncBailHook(["modules"]),
257
+ /** @type {SyncHook<Module[]>} */
137
258
  afterOptimizeModules: new SyncHook(["modules"]),
138
259
 
260
+ /** @type {SyncBailHook<Chunk[], ChunkGroup[]>} */
139
261
  optimizeChunksBasic: new SyncBailHook(["chunks", "chunkGroups"]),
262
+ /** @type {SyncBailHook<Chunk[], ChunkGroup[]>} */
140
263
  optimizeChunks: new SyncBailHook(["chunks", "chunkGroups"]),
264
+ /** @type {SyncBailHook<Chunk[], ChunkGroup[]>} */
141
265
  optimizeChunksAdvanced: new SyncBailHook(["chunks", "chunkGroups"]),
266
+ /** @type {SyncHook<Chunk[], ChunkGroup[]>} */
142
267
  afterOptimizeChunks: new SyncHook(["chunks", "chunkGroups"]),
143
268
 
269
+ /** @type {AsyncSeriesHook<Chunk[], Module[]>} */
144
270
  optimizeTree: new AsyncSeriesHook(["chunks", "modules"]),
271
+ /** @type {SyncHook<Chunk[], Module[]>} */
145
272
  afterOptimizeTree: new SyncHook(["chunks", "modules"]),
146
273
 
274
+ /** @type {SyncBailHook<Chunk[], Module[]>} */
147
275
  optimizeChunkModulesBasic: new SyncBailHook(["chunks", "modules"]),
276
+ /** @type {SyncBailHook<Chunk[], Module[]>} */
148
277
  optimizeChunkModules: new SyncBailHook(["chunks", "modules"]),
278
+ /** @type {SyncBailHook<Chunk[], Module[]>} */
149
279
  optimizeChunkModulesAdvanced: new SyncBailHook(["chunks", "modules"]),
280
+ /** @type {SyncHook<Chunk[], Module[]>} */
150
281
  afterOptimizeChunkModules: new SyncHook(["chunks", "modules"]),
282
+ /** @type {SyncBailHook} */
151
283
  shouldRecord: new SyncBailHook([]),
152
284
 
285
+ /** @type {SyncHook<Module[], any>} */
153
286
  reviveModules: new SyncHook(["modules", "records"]),
287
+ /** @type {SyncHook<Module[]>} */
154
288
  optimizeModuleOrder: new SyncHook(["modules"]),
289
+ /** @type {SyncHook<Module[]>} */
155
290
  advancedOptimizeModuleOrder: new SyncHook(["modules"]),
291
+ /** @type {SyncHook<Module[]>} */
156
292
  beforeModuleIds: new SyncHook(["modules"]),
293
+ /** @type {SyncHook<Module[]>} */
157
294
  moduleIds: new SyncHook(["modules"]),
295
+ /** @type {SyncHook<Module[]>} */
158
296
  optimizeModuleIds: new SyncHook(["modules"]),
297
+ /** @type {SyncHook<Module[]>} */
159
298
  afterOptimizeModuleIds: new SyncHook(["modules"]),
160
299
 
300
+ /** @type {SyncHook<Chunk[], any>} */
161
301
  reviveChunks: new SyncHook(["chunks", "records"]),
302
+ /** @type {SyncHook<Chunk[]>} */
162
303
  optimizeChunkOrder: new SyncHook(["chunks"]),
304
+ /** @type {SyncHook<Chunk[]>} */
163
305
  beforeChunkIds: new SyncHook(["chunks"]),
306
+ /** @type {SyncHook<Chunk[]>} */
164
307
  optimizeChunkIds: new SyncHook(["chunks"]),
308
+ /** @type {SyncHook<Chunk[]>} */
165
309
  afterOptimizeChunkIds: new SyncHook(["chunks"]),
166
310
 
311
+ /** @type {SyncHook<Module[], any>} */
167
312
  recordModules: new SyncHook(["modules", "records"]),
313
+ /** @type {SyncHook<Chunk[], any>} */
168
314
  recordChunks: new SyncHook(["chunks", "records"]),
169
315
 
316
+ /** @type {SyncHook} */
170
317
  beforeHash: new SyncHook([]),
318
+ /** @type {SyncHook<Chunk>} */
171
319
  contentHash: new SyncHook(["chunk"]),
320
+ /** @type {SyncHook} */
172
321
  afterHash: new SyncHook([]),
173
-
322
+ /** @type {SyncHook<any>} */
174
323
  recordHash: new SyncHook(["records"]),
175
-
324
+ /** @type {SyncHook<Compilation, any>} */
176
325
  record: new SyncHook(["compilation", "records"]),
177
326
 
327
+ /** @type {SyncHook} */
178
328
  beforeModuleAssets: new SyncHook([]),
329
+ /** @type {SyncBailHook} */
179
330
  shouldGenerateChunkAssets: new SyncBailHook([]),
331
+ /** @type {SyncHook} */
180
332
  beforeChunkAssets: new SyncHook([]),
333
+ /** @type {SyncHook<Chunk[]>} */
181
334
  additionalChunkAssets: new SyncHook(["chunks"]),
182
335
 
336
+ /** @type {AsyncSeriesHook} */
183
337
  additionalAssets: new AsyncSeriesHook([]),
338
+ /** @type {AsyncSeriesHook<Chunk[]>} */
184
339
  optimizeChunkAssets: new AsyncSeriesHook(["chunks"]),
340
+ /** @type {SyncHook<Chunk[]>} */
185
341
  afterOptimizeChunkAssets: new SyncHook(["chunks"]),
342
+ /** @type {AsyncSeriesHook<CompilationAssets>} */
186
343
  optimizeAssets: new AsyncSeriesHook(["assets"]),
344
+ /** @type {SyncHook<CompilationAssets>} */
187
345
  afterOptimizeAssets: new SyncHook(["assets"]),
188
346
 
347
+ /** @type {SyncBailHook} */
189
348
  needAdditionalSeal: new SyncBailHook([]),
349
+ /** @type {AsyncSeriesHook} */
190
350
  afterSeal: new AsyncSeriesHook([]),
191
351
 
352
+ /** @type {SyncHook<Chunk, Hash>} */
192
353
  chunkHash: new SyncHook(["chunk", "chunkHash"]),
354
+ /** @type {SyncHook<Module, string>} */
193
355
  moduleAsset: new SyncHook(["module", "filename"]),
356
+ /** @type {SyncHook<Chunk, string>} */
194
357
  chunkAsset: new SyncHook(["chunk", "filename"]),
195
358
 
359
+ /** @type {SyncWaterfallHook<string, TODO>} */
196
360
  assetPath: new SyncWaterfallHook(["filename", "data"]), // TODO MainTemplate
197
361
 
362
+ /** @type {SyncBailHook} */
198
363
  needAdditionalPass: new SyncBailHook([]),
364
+
365
+ /** @type {SyncHook<Compiler, string, number>} */
199
366
  childCompiler: new SyncHook([
200
367
  "childCompiler",
201
368
  "compilerName",
@@ -204,11 +371,16 @@ class Compilation extends Tapable {
204
371
 
205
372
  // TODO the following hooks are weirdly located here
206
373
  // TODO move them for webpack 5
374
+ /** @type {SyncHook<object, Module>} */
207
375
  normalModuleLoader: new SyncHook(["loaderContext", "module"]),
208
376
 
377
+ /** @type {SyncBailHook<Chunk[]>} */
209
378
  optimizeExtractedChunksBasic: new SyncBailHook(["chunks"]),
379
+ /** @type {SyncBailHook<Chunk[]>} */
210
380
  optimizeExtractedChunks: new SyncBailHook(["chunks"]),
381
+ /** @type {SyncBailHook<Chunk[]>} */
211
382
  optimizeExtractedChunksAdvanced: new SyncBailHook(["chunks"]),
383
+ /** @type {SyncHook<Chunk[]>} */
212
384
  afterOptimizeExtractedChunks: new SyncHook(["chunks"])
213
385
  };
214
386
  this._pluginCompat.tap("Compilation", options => {
@@ -222,7 +394,9 @@ class Compilation extends Tapable {
222
394
  break;
223
395
  }
224
396
  });
397
+ /** @type {string=} */
225
398
  this.name = undefined;
399
+ /** @type {Compiler} */
226
400
  this.compiler = compiler;
227
401
  this.resolverFactory = compiler.resolverFactory;
228
402
  this.inputFileSystem = compiler.inputFileSystem;
@@ -230,6 +404,7 @@ class Compilation extends Tapable {
230
404
 
231
405
  const options = (this.options = compiler.options);
232
406
  this.outputOptions = options && options.output;
407
+ /** @type {boolean=} */
233
408
  this.bail = options && options.bail;
234
409
  this.profile = options && options.profile;
235
410
  this.performance = options && options.performance;
@@ -251,32 +426,53 @@ class Compilation extends Tapable {
251
426
  this.semaphore = new Semaphore(options.parallelism || 100);
252
427
 
253
428
  this.entries = [];
429
+ /** @private @type {{name: string, request: string, module: Module}[]} */
254
430
  this._preparedEntrypoints = [];
255
431
  this.entrypoints = new Map();
432
+ /** @type {Chunk[]} */
256
433
  this.chunks = [];
434
+ /** @type {ChunkGroup[]} */
257
435
  this.chunkGroups = [];
436
+ /** @type {Map<string, ChunkGroup>} */
258
437
  this.namedChunkGroups = new Map();
438
+ /** @type {Map<string, Chunk>} */
259
439
  this.namedChunks = new Map();
440
+ /** @type {Module[]} */
260
441
  this.modules = [];
442
+ /** @private @type {Map<string, Module>} */
261
443
  this._modules = new Map();
262
444
  this.cache = null;
263
445
  this.records = null;
446
+ /** @type {string[]} */
264
447
  this.additionalChunkAssets = [];
448
+ /** @type {CompilationAssets} */
265
449
  this.assets = {};
450
+ /** @type {WebpackError[]} */
266
451
  this.errors = [];
452
+ /** @type {WebpackError[]} */
267
453
  this.warnings = [];
454
+ /** @type {Compilation[]} */
268
455
  this.children = [];
456
+ /** @type {Map<DepConstructor, ModuleFactory>} */
269
457
  this.dependencyFactories = new Map();
458
+ /** @type {Map<DepConstructor|string, DependencyTemplate|string>} */
270
459
  this.dependencyTemplates = new Map();
460
+ // TODO refactor this in webpack 5 to a custom DependencyTemplates class with a hash property
271
461
  this.dependencyTemplates.set("hash", "");
272
462
  this.childrenCounters = {};
463
+ /** @type {Set<number|string>} */
273
464
  this.usedChunkIds = null;
465
+ /** @type {Set<number>} */
274
466
  this.usedModuleIds = null;
467
+ /** @type {Map<string, number>=} */
275
468
  this.fileTimestamps = undefined;
469
+ /** @type {Map<string, number>=} */
276
470
  this.contextTimestamps = undefined;
471
+ /** @type {Set<string>=} */
277
472
  this.compilationDependencies = undefined;
278
-
473
+ /** @private @type {Map<Module, Callback[]>} */
279
474
  this._buildingModules = new Map();
475
+ /** @private @type {Map<Module, Callback[]>} */
280
476
  this._rebuildingModules = new Map();
281
477
  }
282
478
 
@@ -284,6 +480,20 @@ class Compilation extends Tapable {
284
480
  return new Stats(this);
285
481
  }
286
482
 
483
+ /**
484
+ * @typedef {Object} AddModuleResult
485
+ * @property {Module} module the added or existing module
486
+ * @property {boolean} issuer was this the first request for this module
487
+ * @property {boolean} build should the module be build
488
+ * @property {boolean} dependencies should dependencies be walked
489
+ */
490
+
491
+ /**
492
+ * @param {Module} module module to be added that was created
493
+ * @param {any=} cacheGroup cacheGroup it is apart of
494
+ * @returns {AddModuleResult} returns meta about whether or not the module had built
495
+ * had an issuer, or any dependnecies
496
+ */
287
497
  addModule(module, cacheGroup) {
288
498
  const identifier = module.identifier();
289
499
  const alreadyAddedModule = this._modules.get(identifier);
@@ -344,15 +554,30 @@ class Compilation extends Tapable {
344
554
  };
345
555
  }
346
556
 
557
+ /**
558
+ * Fetches a module from a compilation by its identifier
559
+ * @param {Module} module the module provided
560
+ * @returns {Module} the module requested
561
+ */
347
562
  getModule(module) {
348
563
  const identifier = module.identifier();
349
564
  return this._modules.get(identifier);
350
565
  }
351
566
 
567
+ /**
568
+ * Attempts to search for a module by its identifier
569
+ * @param {string} identifier identifier (usually path) for module
570
+ * @returns {Module|undefined} attempt to search for module and return it, else undefined
571
+ */
352
572
  findModule(identifier) {
353
573
  return this._modules.get(identifier);
354
574
  }
355
575
 
576
+ /**
577
+ * @param {Module} module module with its callback list
578
+ * @param {Callback} callback the callback function
579
+ * @returns {void}
580
+ */
356
581
  waitForBuildingFinished(module, callback) {
357
582
  let callbackList = this._buildingModules.get(module);
358
583
  if (callbackList) {
@@ -362,6 +587,16 @@ class Compilation extends Tapable {
362
587
  }
363
588
  }
364
589
 
590
+ /**
591
+ * Builds the module object
592
+ *
593
+ * @param {Module} module module to be built
594
+ * @param {boolean} optional optional flag
595
+ * @param {Module=} origin origin module this module build was requested from
596
+ * @param {Dependency[]=} dependencies optional dependencies from the module to be built
597
+ * @param {TODO} thisCallback the callback
598
+ * @returns {TODO} returns the callback function with results
599
+ */
365
600
  buildModule(module, optional, origin, dependencies, thisCallback) {
366
601
  let callbackList = this._buildingModules.get(module);
367
602
  if (callbackList) {
@@ -407,7 +642,7 @@ class Compilation extends Tapable {
407
642
  war.dependencies = dependencies;
408
643
  this.warnings.push(war);
409
644
  }
410
- module.dependencies.sort(Dependency.compare);
645
+ module.dependencies.sort((a, b) => compareLocations(a.loc, b.loc));
411
646
  if (error) {
412
647
  this.hooks.failedModule.call(module, error);
413
648
  return callback(error);
@@ -418,6 +653,11 @@ class Compilation extends Tapable {
418
653
  );
419
654
  }
420
655
 
656
+ /**
657
+ * @param {Module} module to be processed for deps
658
+ * @param {ModuleCallback} callback callback to be triggered
659
+ * @returns {void}
660
+ */
421
661
  processModuleDependencies(module, callback) {
422
662
  const dependencies = new Map();
423
663
 
@@ -481,6 +721,15 @@ class Compilation extends Tapable {
481
721
  );
482
722
  }
483
723
 
724
+ /**
725
+ * @param {Module} module module to add deps to
726
+ * @param {SortedDependency[]} dependencies set of sorted dependencies to iterate through
727
+ * @param {(boolean|null)=} bail whether to bail or not
728
+ * @param {TODO} cacheGroup optional cacheGroup
729
+ * @param {boolean} recursive whether it is recursive traversal
730
+ * @param {function} callback callback for when dependencies are finished being added
731
+ * @returns {void}
732
+ */
484
733
  addModuleDependencies(
485
734
  module,
486
735
  dependencies,
@@ -639,6 +888,7 @@ class Compilation extends Tapable {
639
888
  // leaking the Compilation object.
640
889
 
641
890
  if (err) {
891
+ // eslint-disable-next-line no-self-assign
642
892
  err.stack = err.stack;
643
893
  return callback(err);
644
894
  }
@@ -648,6 +898,14 @@ class Compilation extends Tapable {
648
898
  );
649
899
  }
650
900
 
901
+ /**
902
+ *
903
+ * @param {string} context context string path
904
+ * @param {Dependency} dependency dependency used to create Module chain
905
+ * @param {OnModuleCallback} onModule function invoked on modules creation
906
+ * @param {ModuleChainCallback} callback callback for when module chain is complete
907
+ * @returns {void} will throw if dependency instance is not a valid Dependency
908
+ */
651
909
  _addModuleChain(context, dependency, onModule, callback) {
652
910
  const start = this.profile && Date.now();
653
911
  const currentProfile = this.profile && {};
@@ -669,8 +927,8 @@ class Compilation extends Tapable {
669
927
  ) {
670
928
  throw new Error("Parameter 'dependency' must be a Dependency");
671
929
  }
672
-
673
- const moduleFactory = this.dependencyFactories.get(dependency.constructor);
930
+ const Dep = /** @type {DepConstructor} */ (dependency.constructor);
931
+ const moduleFactory = this.dependencyFactories.get(Dep);
674
932
  if (!moduleFactory) {
675
933
  throw new Error(
676
934
  `No dependency factory available for this dependency type: ${
@@ -756,12 +1014,25 @@ class Compilation extends Tapable {
756
1014
  });
757
1015
  }
758
1016
 
1017
+ /**
1018
+ *
1019
+ * @param {string} context context path for entry
1020
+ * @param {Dependency} entry entry dependency being created
1021
+ * @param {string} name name of entry
1022
+ * @param {ModuleCallback} callback callback function
1023
+ * @returns {void} returns
1024
+ */
759
1025
  addEntry(context, entry, name, callback) {
760
1026
  const slot = {
761
1027
  name: name,
762
- request: entry.request,
1028
+ request: null,
763
1029
  module: null
764
1030
  };
1031
+
1032
+ if (entry instanceof ModuleDependency) {
1033
+ slot.request = entry.request;
1034
+ }
1035
+
765
1036
  this._preparedEntrypoints.push(slot);
766
1037
  this._addModuleChain(
767
1038
  context,
@@ -785,6 +1056,12 @@ class Compilation extends Tapable {
785
1056
  );
786
1057
  }
787
1058
 
1059
+ /**
1060
+ * @param {string} context context path string
1061
+ * @param {Dependency} dependency dep used to create module
1062
+ * @param {ModuleCallback} callback module callback sending module up a level
1063
+ * @returns {void}
1064
+ */
788
1065
  prefetch(context, dependency, callback) {
789
1066
  this._addModuleChain(
790
1067
  context,
@@ -796,6 +1073,11 @@ class Compilation extends Tapable {
796
1073
  );
797
1074
  }
798
1075
 
1076
+ /**
1077
+ * @param {Module} module module to be rebuilt
1078
+ * @param {Callback} thisCallback callback when module finishes rebuilding
1079
+ * @returns {void}
1080
+ */
799
1081
  rebuildModule(module, thisCallback) {
800
1082
  let callbackList = this._rebuildingModules.get(module);
801
1083
  if (callbackList) {
@@ -858,6 +1140,10 @@ class Compilation extends Tapable {
858
1140
  }
859
1141
  }
860
1142
 
1143
+ /**
1144
+ * @param {Callback} callback signals when the seal method is finishes
1145
+ * @returns {void}
1146
+ */
861
1147
  seal(callback) {
862
1148
  this.hooks.seal.call();
863
1149
 
@@ -870,6 +1156,7 @@ class Compilation extends Tapable {
870
1156
  }
871
1157
  this.hooks.afterOptimizeDependencies.call(this.modules);
872
1158
 
1159
+ this.hooks.beforeChunks.call();
873
1160
  for (const preparedEntrypoint of this._preparedEntrypoints) {
874
1161
  const module = preparedEntrypoint.module;
875
1162
  const name = preparedEntrypoint.name;
@@ -891,6 +1178,8 @@ class Compilation extends Tapable {
891
1178
  }
892
1179
  this.processDependenciesBlocksForChunkGroups(this.chunkGroups.slice());
893
1180
  this.sortModules(this.modules);
1181
+ this.hooks.afterChunks.call(this.chunks);
1182
+
894
1183
  this.hooks.optimize.call();
895
1184
 
896
1185
  while (
@@ -999,10 +1288,22 @@ class Compilation extends Tapable {
999
1288
  });
1000
1289
  }
1001
1290
 
1291
+ /**
1292
+ * @param {Module[]} modules the modules array on compilation to perform the sort for
1293
+ * @returns {void}
1294
+ */
1002
1295
  sortModules(modules) {
1296
+ // TODO webpack 5: this should only be enabled when `moduleIds: "natural"`
1297
+ // TODO move it into a plugin (NaturalModuleIdsPlugin) and use this in WebpackOptionsApply
1298
+ // TODO remove this method
1003
1299
  modules.sort(byIndexOrIdentifier);
1004
1300
  }
1005
1301
 
1302
+ /**
1303
+ * @param {Module} module moulde to report from
1304
+ * @param {DependenciesBlock[]} blocks blocks to report from
1305
+ * @returns {void}
1306
+ */
1006
1307
  reportDependencyErrorsAndWarnings(module, blocks) {
1007
1308
  for (let indexBlock = 0; indexBlock < blocks.length; indexBlock++) {
1008
1309
  const block = blocks[indexBlock];
@@ -1038,7 +1339,7 @@ class Compilation extends Tapable {
1038
1339
  /**
1039
1340
  * @param {TODO} groupOptions options for the chunk group
1040
1341
  * @param {Module} module the module the references the chunk group
1041
- * @param {TODO} loc the location from with the chunk group is reference (inside of module)
1342
+ * @param {DependencyLocation} loc the location from with the chunk group is referenced (inside of module)
1042
1343
  * @param {string} request the request from which the the chunk group is referenced
1043
1344
  * @returns {ChunkGroup} the new or existing chunk group
1044
1345
  */
@@ -1070,6 +1371,13 @@ class Compilation extends Tapable {
1070
1371
  return chunkGroup;
1071
1372
  }
1072
1373
 
1374
+ /**
1375
+ * This method first looks to see if a name is provided for a new chunk,
1376
+ * and first looks to see if any named chunks already exist and reuse that chunk instead.
1377
+ *
1378
+ * @param {string=} name optional chunk name to be provided
1379
+ * @returns {Chunk} create a chunk (invoked during seal event)
1380
+ */
1073
1381
  addChunk(name) {
1074
1382
  if (name) {
1075
1383
  const chunk = this.namedChunks.get(name);
@@ -1085,12 +1393,20 @@ class Compilation extends Tapable {
1085
1393
  return chunk;
1086
1394
  }
1087
1395
 
1396
+ /**
1397
+ * @param {Module} module module to assign depth
1398
+ * @returns {void}
1399
+ */
1088
1400
  assignDepth(module) {
1089
1401
  const queue = new Set([module]);
1090
1402
  let depth;
1091
1403
 
1092
1404
  module.depth = 0;
1093
1405
 
1406
+ /**
1407
+ * @param {Module} module module for processeing
1408
+ * @returns {void}
1409
+ */
1094
1410
  const enqueueJob = module => {
1095
1411
  const d = module.depth;
1096
1412
  if (typeof d === "number" && d <= depth) return;
@@ -1098,12 +1414,20 @@ class Compilation extends Tapable {
1098
1414
  module.depth = depth;
1099
1415
  };
1100
1416
 
1101
- const assignDepthToDependency = (dependency, depth) => {
1417
+ /**
1418
+ * @param {Dependency} dependency dependency to assign depth to
1419
+ * @returns {void}
1420
+ */
1421
+ const assignDepthToDependency = dependency => {
1102
1422
  if (dependency.module) {
1103
1423
  enqueueJob(dependency.module);
1104
1424
  }
1105
1425
  };
1106
1426
 
1427
+ /**
1428
+ * @param {DependenciesBlock} block block to assign depth to
1429
+ * @returns {void}
1430
+ */
1107
1431
  const assignDepthToDependencyBlock = block => {
1108
1432
  if (block.variables) {
1109
1433
  iterationBlockVariable(block.variables, assignDepthToDependency);
@@ -1133,7 +1457,7 @@ class Compilation extends Tapable {
1133
1457
  * @returns {DependencyReference} a reference for the dependency
1134
1458
  */
1135
1459
  getDependencyReference(module, dependency) {
1136
- // TODO remove dep.getReference existance check in webpack 5
1460
+ // TODO remove dep.getReference existence check in webpack 5
1137
1461
  if (typeof dependency.getReference !== "function") return null;
1138
1462
  const ref = dependency.getReference();
1139
1463
  if (!ref) return null;
@@ -1155,7 +1479,7 @@ class Compilation extends Tapable {
1155
1479
  // eachother and Blocks with Chunks. It stops traversing when all modules
1156
1480
  // for a chunk are already available. So it doesn't connect unneeded chunks.
1157
1481
 
1158
- /** @type {Map<Chunk, {block: DependenciesBlock, chunkGroup: ChunkGroup}[]>} */
1482
+ /** @type {Map<ChunkGroup, {block: AsyncDependenciesBlock, chunkGroup: ChunkGroup}[]>} */
1159
1483
  const chunkDependencies = new Map();
1160
1484
  const allCreatedChunkGroups = new Set();
1161
1485
 
@@ -1163,6 +1487,10 @@ class Compilation extends Tapable {
1163
1487
  /** @type {Map<DependenciesBlock, { modules: Module[], blocks: AsyncDependenciesBlock[]}>} */
1164
1488
  const blockInfoMap = new Map();
1165
1489
 
1490
+ /**
1491
+ * @param {Dependency} d dependency to iterate over
1492
+ * @returns {void}
1493
+ */
1166
1494
  const iteratorDependency = d => {
1167
1495
  // We skip Dependencies without Reference
1168
1496
  const ref = this.getDependencyReference(currentModule, d);
@@ -1182,6 +1510,10 @@ class Compilation extends Tapable {
1182
1510
  blockInfoModules.add(refModule);
1183
1511
  };
1184
1512
 
1513
+ /**
1514
+ * @param {AsyncDependenciesBlock} b blocks to prepare
1515
+ * @returns {void}
1516
+ */
1185
1517
  const iteratorBlockPrepare = b => {
1186
1518
  blockInfoBlocks.push(b);
1187
1519
  blockQueue.push(b);
@@ -1191,11 +1523,11 @@ class Compilation extends Tapable {
1191
1523
  let currentModule;
1192
1524
  /** @type {DependenciesBlock} */
1193
1525
  let block;
1194
- /** @type {TODO} */
1526
+ /** @type {DependenciesBlock[]} */
1195
1527
  let blockQueue;
1196
- /** @type {Set<TODO>} */
1528
+ /** @type {Set<Module>} */
1197
1529
  let blockInfoModules;
1198
- /** @type {TODO[]} */
1530
+ /** @type {AsyncDependenciesBlock[]} */
1199
1531
  let blockInfoBlocks;
1200
1532
 
1201
1533
  for (const module of this.modules) {
@@ -1272,9 +1604,18 @@ class Compilation extends Tapable {
1272
1604
  /** @type {QueueItem[]} */
1273
1605
  let queueDelayed = [];
1274
1606
 
1275
- let module, chunk, chunkGroup;
1607
+ /** @type {Module} */
1608
+ let module;
1609
+ /** @type {Chunk} */
1610
+ let chunk;
1611
+ /** @type {ChunkGroup} */
1612
+ let chunkGroup;
1276
1613
 
1277
1614
  // For each async Block in graph
1615
+ /**
1616
+ * @param {AsyncDependenciesBlock} b iterating over each Async DepBlock
1617
+ * @returns {void}
1618
+ */
1278
1619
  const iteratorBlock = b => {
1279
1620
  // 1. We create a chunk for this Block
1280
1621
  // but only once (blockChunkGroups map)
@@ -1416,9 +1757,10 @@ class Compilation extends Tapable {
1416
1757
  }
1417
1758
 
1418
1759
  // PART TWO
1419
-
1760
+ /** @type {Set<Module>} */
1420
1761
  let availableModules;
1421
1762
  let newAvailableModules;
1763
+ /** @type {Queue<AvailableModulesChunkGroupMapping>} */
1422
1764
  const queue2 = new Queue(
1423
1765
  inputChunkGroups.map(chunkGroup => ({
1424
1766
  chunkGroup,
@@ -1426,7 +1768,13 @@ class Compilation extends Tapable {
1426
1768
  }))
1427
1769
  );
1428
1770
 
1429
- // Helper function to check if all modules of a chunk are available
1771
+ /**
1772
+ * Helper function to check if all modules of a chunk are available
1773
+ *
1774
+ * @param {ChunkGroup} chunkGroup the chunkGroup to scan
1775
+ * @param {Set<Module>} availableModules the comparitor set
1776
+ * @returns {boolean} return true if all modules of a chunk are available
1777
+ */
1430
1778
  const areModulesAvailable = (chunkGroup, availableModules) => {
1431
1779
  for (const chunk of chunkGroup.chunks) {
1432
1780
  for (const module of chunk.modulesIterable) {
@@ -1437,14 +1785,18 @@ class Compilation extends Tapable {
1437
1785
  };
1438
1786
 
1439
1787
  // For each edge in the basic chunk graph
1788
+ /**
1789
+ * @param {TODO} dep the dependency used for filtering
1790
+ * @returns {boolean} used to filter "edges" (aka Dependencies) that were pointing
1791
+ * to modules that are already available. Also filters circular dependencies in the chunks graph
1792
+ */
1440
1793
  const filterFn = dep => {
1441
- // Filter egdes that are not needed because all modules are already available
1442
- // This also filters circular dependencies in the chunks graph
1443
1794
  const depChunkGroup = dep.chunkGroup;
1444
1795
  if (areModulesAvailable(depChunkGroup, newAvailableModules)) return false; // break all modules are already available
1445
1796
  return true;
1446
1797
  };
1447
1798
 
1799
+ /** @type {Map<ChunkGroup, Set<Module>>} */
1448
1800
  const minAvailableModulesMap = new Map();
1449
1801
 
1450
1802
  // Iterative traversing of the basic chunk graph
@@ -1529,6 +1881,12 @@ class Compilation extends Tapable {
1529
1881
  }
1530
1882
  }
1531
1883
 
1884
+ /**
1885
+ *
1886
+ * @param {Module} module module relationship for removal
1887
+ * @param {DependenciesBlockLike} block //TODO: good description
1888
+ * @returns {void}
1889
+ */
1532
1890
  removeReasonsOfDependencyBlock(module, block) {
1533
1891
  const iteratorDependency = d => {
1534
1892
  if (!d.module) {
@@ -1556,6 +1914,11 @@ class Compilation extends Tapable {
1556
1914
  }
1557
1915
  }
1558
1916
 
1917
+ /**
1918
+ * @param {Module} module module to patch tie
1919
+ * @param {Chunk} chunk chunk to patch tie
1920
+ * @returns {void}
1921
+ */
1559
1922
  patchChunksAfterReasonRemoval(module, chunk) {
1560
1923
  if (!module.hasReasons()) {
1561
1924
  this.removeReasonsOfDependencyBlock(module, module);
@@ -1567,6 +1930,12 @@ class Compilation extends Tapable {
1567
1930
  }
1568
1931
  }
1569
1932
 
1933
+ /**
1934
+ *
1935
+ * @param {DependenciesBlock} block block tie for Chunk
1936
+ * @param {Chunk} chunk chunk to remove from dep
1937
+ * @returns {void}
1938
+ */
1570
1939
  removeChunkFromDependencies(block, chunk) {
1571
1940
  const iteratorDependency = d => {
1572
1941
  if (!d.module) {
@@ -1577,12 +1946,16 @@ class Compilation extends Tapable {
1577
1946
 
1578
1947
  const blocks = block.blocks;
1579
1948
  for (let indexBlock = 0; indexBlock < blocks.length; indexBlock++) {
1580
- const chunks = blocks[indexBlock].chunks;
1949
+ const asyncBlock = blocks[indexBlock];
1950
+ // Grab all chunks from the first Block's AsyncDepBlock
1951
+ const chunks = asyncBlock.chunkGroup.chunks;
1952
+ // For each chunk in chunkGroup
1581
1953
  for (let indexChunk = 0; indexChunk < chunks.length; indexChunk++) {
1582
- const blockChunk = chunks[indexChunk];
1583
- chunk.removeChunk(blockChunk);
1584
- blockChunk.removeParent(chunk);
1585
- this.removeChunkFromDependencies(chunks, blockChunk);
1954
+ const iteratedChunk = chunks[indexChunk];
1955
+ asyncBlock.chunkGroup.removeChunk(iteratedChunk);
1956
+ asyncBlock.chunkGroup.removeParent(iteratedChunk);
1957
+ // Recurse
1958
+ this.removeChunkFromDependencies(block, iteratedChunk);
1586
1959
  }
1587
1960
  }
1588
1961
 
@@ -1646,6 +2019,7 @@ class Compilation extends Tapable {
1646
2019
  }
1647
2020
 
1648
2021
  applyChunkIds() {
2022
+ /** @type {Set<number>} */
1649
2023
  const usedIds = new Set();
1650
2024
 
1651
2025
  // Get used ids from usedChunkIds property (i. e. from records)
@@ -1680,6 +2054,7 @@ class Compilation extends Tapable {
1680
2054
  nextFreeChunkId++;
1681
2055
 
1682
2056
  // Determine free chunk ids from 0 to maximum
2057
+ /** @type {number[]} */
1683
2058
  const unusedIds = [];
1684
2059
  if (nextFreeChunkId > 0) {
1685
2060
  let index = nextFreeChunkId;
@@ -1716,7 +2091,7 @@ class Compilation extends Tapable {
1716
2091
 
1717
2092
  const chunks = this.chunks;
1718
2093
  for (let indexChunk = 0; indexChunk < chunks.length; indexChunk++) {
1719
- chunks[indexChunk].sortItems(false);
2094
+ chunks[indexChunk].sortItems();
1720
2095
  }
1721
2096
  }
1722
2097
 
@@ -1737,9 +2112,19 @@ class Compilation extends Tapable {
1737
2112
 
1738
2113
  const chunks = this.chunks;
1739
2114
  for (let indexChunk = 0; indexChunk < chunks.length; indexChunk++) {
1740
- chunks[indexChunk].sortItems(true);
2115
+ chunks[indexChunk].sortItems();
1741
2116
  }
1742
2117
 
2118
+ /**
2119
+ * Used to sort errors and warnings in compilation. this.warnings, and
2120
+ * this.errors contribute to the compilation hash and therefore should be
2121
+ * updated whenever other references (having a chunk id) are sorted. This preserves the hash
2122
+ * integrity
2123
+ *
2124
+ * @param {WebpackError} a first WebpackError instance (including subclasses)
2125
+ * @param {WebpackError} b second WebpackError instance (including subclasses)
2126
+ * @returns {-1|0|1} sort order index
2127
+ */
1743
2128
  const byMessage = (a, b) => {
1744
2129
  const ma = `${a.message}`;
1745
2130
  const mb = `${b.message}`;
@@ -1867,6 +2252,10 @@ class Compilation extends Tapable {
1867
2252
  this.hash = this.fullHash.substr(0, hashDigestLength);
1868
2253
  }
1869
2254
 
2255
+ /**
2256
+ * @param {string} update extra information
2257
+ * @returns {void}
2258
+ */
1870
2259
  modifyHash(update) {
1871
2260
  const outputOptions = this.outputOptions;
1872
2261
  const hashFunction = outputOptions.hashFunction;
@@ -1989,12 +2378,27 @@ class Compilation extends Tapable {
1989
2378
  }
1990
2379
  }
1991
2380
 
2381
+ /**
2382
+ * @param {string} filename used to get asset path with hash
2383
+ * @param {TODO=} data // TODO: figure out this param type
2384
+ * @returns {string} interpolated path
2385
+ */
1992
2386
  getPath(filename, data) {
1993
2387
  data = data || {};
1994
2388
  data.hash = data.hash || this.hash;
1995
2389
  return this.mainTemplate.getAssetPath(filename, data);
1996
2390
  }
1997
2391
 
2392
+ /**
2393
+ * This function allows you to run another instance of webpack inside of webpack however as
2394
+ * a child with different settings and configurations (if desired) applied. It copies all hooks, plugins
2395
+ * from parent (or top level compiler) and creates a child Compilation
2396
+ *
2397
+ * @param {string} name name of the child compiler
2398
+ * @param {TODO} outputOptions // Need to convert config schema to types for this
2399
+ * @param {Plugin[]} plugins webpack plugins that will be applied
2400
+ * @returns {Compiler} creates a child Compiler instance
2401
+ */
1998
2402
  createChildCompiler(name, outputOptions, plugins) {
1999
2403
  const idx = this.childrenCounters[name] || 0;
2000
2404
  this.childrenCounters[name] = idx + 1;
@@ -2008,6 +2412,7 @@ class Compilation extends Tapable {
2008
2412
  }
2009
2413
 
2010
2414
  checkConstraints() {
2415
+ /** @type {Set<number|string>} */
2011
2416
  const usedIds = new Set();
2012
2417
 
2013
2418
  const modules = this.modules;