webpack 4.13.0 → 4.16.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.
Files changed (93) hide show
  1. package/bin/webpack.js +7 -2
  2. package/hot/dev-server.js +2 -2
  3. package/hot/only-dev-server.js +2 -2
  4. package/hot/poll.js +5 -2
  5. package/hot/signal.js +2 -2
  6. package/lib/AsyncDependenciesBlock.js +44 -0
  7. package/lib/AutomaticPrefetchPlugin.js +2 -2
  8. package/lib/Chunk.js +56 -6
  9. package/lib/ChunkGroup.js +2 -2
  10. package/lib/ChunkTemplate.js +14 -2
  11. package/lib/CommentCompilationWarning.js +3 -3
  12. package/lib/CompatibilityPlugin.js +1 -1
  13. package/lib/Compilation.js +494 -36
  14. package/lib/Compiler.js +57 -4
  15. package/lib/ContextModule.js +23 -16
  16. package/lib/DelegatedModule.js +9 -1
  17. package/lib/DelegatedModuleFactoryPlugin.js +7 -1
  18. package/lib/DependenciesBlock.js +36 -3
  19. package/lib/DependenciesBlockVariable.js +22 -0
  20. package/lib/Dependency.js +33 -6
  21. package/lib/DllEntryPlugin.js +4 -1
  22. package/lib/DynamicEntryPlugin.js +21 -1
  23. package/lib/EntryOptionPlugin.js +12 -0
  24. package/lib/Entrypoint.js +1 -1
  25. package/lib/EnvironmentPlugin.js +8 -1
  26. package/lib/ExtendedAPIPlugin.js +8 -4
  27. package/lib/ExternalModuleFactoryPlugin.js +1 -1
  28. package/lib/FlagDependencyUsagePlugin.js +18 -13
  29. package/lib/Generator.js +1 -1
  30. package/lib/GraphHelpers.js +2 -1
  31. package/lib/HotModuleReplacement.runtime.js +8 -5
  32. package/lib/HotModuleReplacementPlugin.js +115 -117
  33. package/lib/IgnorePlugin.js +1 -1
  34. package/lib/MainTemplate.js +19 -4
  35. package/lib/Module.js +9 -3
  36. package/lib/ModuleReason.js +8 -0
  37. package/lib/MultiEntryPlugin.js +25 -3
  38. package/lib/NormalModule.js +5 -23
  39. package/lib/RuleSet.js +3 -3
  40. package/lib/RuntimeTemplate.js +4 -0
  41. package/lib/SingleEntryPlugin.js +20 -1
  42. package/lib/Stats.js +12 -5
  43. package/lib/Template.js +4 -1
  44. package/lib/UmdMainTemplatePlugin.js +12 -12
  45. package/lib/UseStrictPlugin.js +1 -1
  46. package/lib/WebpackError.js +4 -0
  47. package/lib/WebpackOptionsApply.js +92 -10
  48. package/lib/WebpackOptionsDefaulter.js +23 -6
  49. package/lib/WebpackOptionsValidationError.js +0 -1
  50. package/lib/compareLocations.js +13 -17
  51. package/lib/debug/ProfilingPlugin.js +5 -7
  52. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +4 -6
  53. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +0 -2
  54. package/lib/dependencies/DependencyReference.js +4 -0
  55. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +18 -8
  56. package/lib/dependencies/LoaderDependency.js +3 -0
  57. package/lib/dependencies/LoaderPlugin.js +21 -2
  58. package/lib/dependencies/ModuleDependency.js +3 -0
  59. package/lib/dependencies/MultiEntryDependency.js +5 -0
  60. package/lib/dependencies/SingleEntryDependency.js +3 -0
  61. package/lib/dependencies/SystemPlugin.js +1 -1
  62. package/lib/formatLocation.js +55 -41
  63. package/lib/node/NodeMainTemplateAsync.runtime.js +1 -1
  64. package/lib/node/NodeMainTemplatePlugin.js +2 -2
  65. package/lib/node/NodeSourcePlugin.js +1 -1
  66. package/lib/optimize/ConcatenatedModule.js +24 -8
  67. package/lib/optimize/ModuleConcatenationPlugin.js +29 -14
  68. package/lib/optimize/NaturalChunkOrderPlugin.js +41 -0
  69. package/lib/optimize/OccurrenceChunkOrderPlugin.js +61 -0
  70. package/lib/optimize/OccurrenceModuleOrderPlugin.js +103 -0
  71. package/lib/optimize/OccurrenceOrderPlugin.js +2 -0
  72. package/lib/optimize/SplitChunksPlugin.js +168 -18
  73. package/lib/util/Semaphore.js +12 -0
  74. package/lib/util/SetHelpers.js +4 -4
  75. package/lib/util/SortableSet.js +1 -1
  76. package/lib/util/cachedMerge.js +1 -1
  77. package/lib/util/createHash.js +15 -0
  78. package/lib/util/deterministicGrouping.js +251 -0
  79. package/lib/util/identifier.js +27 -0
  80. package/lib/wasm/WasmFinalizeExportsPlugin.js +5 -2
  81. package/lib/wasm/WasmMainTemplatePlugin.js +10 -4
  82. package/lib/wasm/WebAssemblyGenerator.js +12 -12
  83. package/lib/wasm/WebAssemblyInInitialChunkError.js +88 -0
  84. package/lib/wasm/WebAssemblyModulesPlugin.js +28 -0
  85. package/lib/web/JsonpMainTemplatePlugin.js +1 -1
  86. package/lib/web/WebEnvironmentPlugin.js +18 -18
  87. package/lib/webpack.js +7 -0
  88. package/lib/webpack.web.js +2 -2
  89. package/lib/webworker/WebWorkerMainTemplatePlugin.js +1 -1
  90. package/package.json +21 -11
  91. package/schemas/WebpackOptions.json +70 -4
  92. package/schemas/plugins/optimize/OccurrenceOrderChunkIdsPlugin.json +10 -0
  93. package/schemas/plugins/optimize/OccurrenceOrderModuleIdsPlugin.json +10 -0
@@ -4,6 +4,11 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
+ /** @typedef {import("./Module")} Module */
8
+ /** @typedef {import("./DependenciesBlock")} DependenciesBlock */
9
+
10
+ /** @typedef {false | true | string[]} UsedExports */
11
+
7
12
  const addToSet = (a, b) => {
8
13
  for (const item of b) {
9
14
  if (!a.includes(item)) a.push(item);
@@ -54,37 +59,36 @@ class FlagDependencyUsagePlugin {
54
59
  return;
55
60
  }
56
61
 
57
- queue.push([module, module.usedExports]);
62
+ queue.push([module, module, module.usedExports]);
58
63
  };
59
64
 
60
- const processDependenciesBlock = (depBlock, usedExports) => {
65
+ const processDependenciesBlock = (module, depBlock, usedExports) => {
61
66
  for (const dep of depBlock.dependencies) {
62
- processDependency(dep);
67
+ processDependency(module, dep);
63
68
  }
64
69
  for (const variable of depBlock.variables) {
65
70
  for (const dep of variable.dependencies) {
66
- processDependency(dep);
71
+ processDependency(module, dep);
67
72
  }
68
73
  }
69
74
  for (const block of depBlock.blocks) {
70
- queue.push([block, usedExports]);
75
+ queue.push([module, block, usedExports]);
71
76
  }
72
77
  };
73
78
 
74
- const processDependency = dep => {
75
- // TODO remove dep.getReference existance check in webpack 5
76
- const reference = dep.getReference && dep.getReference();
79
+ const processDependency = (module, dep) => {
80
+ const reference = compilation.getDependencyReference(module, dep);
77
81
  if (!reference) return;
78
- const module = reference.module;
82
+ const referenceModule = reference.module;
79
83
  const importedNames = reference.importedNames;
80
- const oldUsed = module.used;
81
- const oldUsedExports = module.usedExports;
84
+ const oldUsed = referenceModule.used;
85
+ const oldUsedExports = referenceModule.usedExports;
82
86
  if (
83
87
  !oldUsed ||
84
88
  (importedNames &&
85
89
  (!oldUsedExports || !isSubset(oldUsedExports, importedNames)))
86
90
  ) {
87
- processModule(module, importedNames);
91
+ processModule(referenceModule, importedNames);
88
92
  }
89
93
  };
90
94
 
@@ -92,6 +96,7 @@ class FlagDependencyUsagePlugin {
92
96
  module.used = false;
93
97
  }
94
98
 
99
+ /** @type {[Module, DependenciesBlock, UsedExports][]} */
95
100
  const queue = [];
96
101
  for (const preparedEntrypoint of compilation._preparedEntrypoints) {
97
102
  if (preparedEntrypoint.module) {
@@ -101,7 +106,7 @@ class FlagDependencyUsagePlugin {
101
106
 
102
107
  while (queue.length) {
103
108
  const queueItem = queue.pop();
104
- processDependenciesBlock(queueItem[0], queueItem[1]);
109
+ processDependenciesBlock(queueItem[0], queueItem[1], queueItem[2]);
105
110
  }
106
111
  }
107
112
  );
package/lib/Generator.js CHANGED
@@ -25,7 +25,7 @@ class Generator {
25
25
  * @returns {Source} generated code
26
26
  */
27
27
  generate(module, dependencyTemplates, runtimeTemplate, type) {
28
- throw new Error("Generator.generate: must be overriden");
28
+ throw new Error("Generator.generate: must be overridden");
29
29
  }
30
30
  }
31
31
 
@@ -2,6 +2,7 @@
2
2
  /** @typedef {import("./ChunkGroup")} ChunkGroup */
3
3
  /** @typedef {import("./Module")} Module */
4
4
  /** @typedef {import("./DependenciesBlock")} DependenciesBlock */
5
+ /** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
5
6
 
6
7
  /**
7
8
  * @param {ChunkGroup} chunkGroup the ChunkGroup to connect
@@ -47,7 +48,7 @@ const disconnectChunkAndModule = (chunk, module) => {
47
48
  };
48
49
 
49
50
  /**
50
- * @param {DependenciesBlock} depBlock DepBlock being tied to ChunkGroup
51
+ * @param {AsyncDependenciesBlock} depBlock DepBlock being tied to ChunkGroup
51
52
  * @param {ChunkGroup} chunkGroup ChunkGroup being tied to DepBlock
52
53
  * @returns {void}
53
54
  */
@@ -5,12 +5,15 @@
5
5
  /*global $hash$ $requestTimeout$ installedModules $require$ hotDownloadManifest hotDownloadUpdateChunk hotDisposeChunk modules */
6
6
  module.exports = function() {
7
7
  var hotApplyOnUpdate = true;
8
- var hotCurrentHash = $hash$; // eslint-disable-line no-unused-vars
8
+ // eslint-disable-next-line no-unused-vars
9
+ var hotCurrentHash = $hash$;
9
10
  var hotRequestTimeout = $requestTimeout$;
10
11
  var hotCurrentModuleData = {};
11
- var hotCurrentChildModule; // eslint-disable-line no-unused-vars
12
- var hotCurrentParents = []; // eslint-disable-line no-unused-vars
13
- var hotCurrentParentsTemp = []; // eslint-disable-line no-unused-vars
12
+ var hotCurrentChildModule;
13
+ // eslint-disable-next-line no-unused-vars
14
+ var hotCurrentParents = [];
15
+ // eslint-disable-next-line no-unused-vars
16
+ var hotCurrentParentsTemp = [];
14
17
 
15
18
  // eslint-disable-next-line no-unused-vars
16
19
  function hotCreateRequire(moduleId) {
@@ -199,8 +202,8 @@ module.exports = function() {
199
202
  });
200
203
  hotUpdate = {};
201
204
  /*foreachInstalledChunks*/
205
+ // eslint-disable-next-line no-lone-blocks
202
206
  {
203
- // eslint-disable-line no-lone-blocks
204
207
  /*globals chunkId */
205
208
  hotEnsureUpdateChunk(chunkId);
206
209
  }
@@ -35,6 +35,118 @@ module.exports = class HotModuleReplacementPlugin {
35
35
  return callback();
36
36
  }
37
37
  );
38
+
39
+ const addParserPlugins = (parser, parserOptions) => {
40
+ parser.hooks.expression
41
+ .for("__webpack_hash__")
42
+ .tap(
43
+ "HotModuleReplacementPlugin",
44
+ ParserHelpers.toConstantDependencyWithWebpackRequire(
45
+ parser,
46
+ "__webpack_require__.h()"
47
+ )
48
+ );
49
+ parser.hooks.evaluateTypeof
50
+ .for("__webpack_hash__")
51
+ .tap(
52
+ "HotModuleReplacementPlugin",
53
+ ParserHelpers.evaluateToString("string")
54
+ );
55
+ parser.hooks.evaluateIdentifier.for("module.hot").tap(
56
+ {
57
+ name: "HotModuleReplacementPlugin",
58
+ before: "NodeStuffPlugin"
59
+ },
60
+ expr => {
61
+ return ParserHelpers.evaluateToIdentifier(
62
+ "module.hot",
63
+ !!parser.state.compilation.hotUpdateChunkTemplate
64
+ )(expr);
65
+ }
66
+ );
67
+ // TODO webpack 5: refactor this, no custom hooks
68
+ if (!parser.hooks.hotAcceptCallback) {
69
+ parser.hooks.hotAcceptCallback = new SyncBailHook([
70
+ "expression",
71
+ "requests"
72
+ ]);
73
+ }
74
+ if (!parser.hooks.hotAcceptWithoutCallback) {
75
+ parser.hooks.hotAcceptWithoutCallback = new SyncBailHook([
76
+ "expression",
77
+ "requests"
78
+ ]);
79
+ }
80
+ parser.hooks.call
81
+ .for("module.hot.accept")
82
+ .tap("HotModuleReplacementPlugin", expr => {
83
+ if (!parser.state.compilation.hotUpdateChunkTemplate) {
84
+ return false;
85
+ }
86
+ if (expr.arguments.length >= 1) {
87
+ const arg = parser.evaluateExpression(expr.arguments[0]);
88
+ let params = [];
89
+ let requests = [];
90
+ if (arg.isString()) {
91
+ params = [arg];
92
+ } else if (arg.isArray()) {
93
+ params = arg.items.filter(param => param.isString());
94
+ }
95
+ if (params.length > 0) {
96
+ params.forEach((param, idx) => {
97
+ const request = param.string;
98
+ const dep = new ModuleHotAcceptDependency(request, param.range);
99
+ dep.optional = true;
100
+ dep.loc = Object.create(expr.loc);
101
+ dep.loc.index = idx;
102
+ parser.state.module.addDependency(dep);
103
+ requests.push(request);
104
+ });
105
+ if (expr.arguments.length > 1) {
106
+ parser.hooks.hotAcceptCallback.call(
107
+ expr.arguments[1],
108
+ requests
109
+ );
110
+ parser.walkExpression(expr.arguments[1]); // other args are ignored
111
+ return true;
112
+ } else {
113
+ parser.hooks.hotAcceptWithoutCallback.call(expr, requests);
114
+ return true;
115
+ }
116
+ }
117
+ }
118
+ });
119
+ parser.hooks.call
120
+ .for("module.hot.decline")
121
+ .tap("HotModuleReplacementPlugin", expr => {
122
+ if (!parser.state.compilation.hotUpdateChunkTemplate) {
123
+ return false;
124
+ }
125
+ if (expr.arguments.length === 1) {
126
+ const arg = parser.evaluateExpression(expr.arguments[0]);
127
+ let params = [];
128
+ if (arg.isString()) {
129
+ params = [arg];
130
+ } else if (arg.isArray()) {
131
+ params = arg.items.filter(param => param.isString());
132
+ }
133
+ params.forEach((param, idx) => {
134
+ const dep = new ModuleHotDeclineDependency(
135
+ param.string,
136
+ param.range
137
+ );
138
+ dep.optional = true;
139
+ dep.loc = Object.create(expr.loc);
140
+ dep.loc.index = idx;
141
+ parser.state.module.addDependency(dep);
142
+ });
143
+ }
144
+ });
145
+ parser.hooks.expression
146
+ .for("module.hot")
147
+ .tap("HotModuleReplacementPlugin", ParserHelpers.skipTraversal);
148
+ };
149
+
38
150
  compiler.hooks.compilation.tap(
39
151
  "HotModuleReplacementPlugin",
40
152
  (compilation, { normalModuleFactory }) => {
@@ -275,127 +387,13 @@ module.exports = class HotModuleReplacementPlugin {
275
387
  }
276
388
  );
277
389
 
278
- const handler = (parser, parserOptions) => {
279
- parser.hooks.expression
280
- .for("__webpack_hash__")
281
- .tap(
282
- "HotModuleReplacementPlugin",
283
- ParserHelpers.toConstantDependencyWithWebpackRequire(
284
- parser,
285
- "__webpack_require__.h()"
286
- )
287
- );
288
- parser.hooks.evaluateTypeof
289
- .for("__webpack_hash__")
290
- .tap(
291
- "HotModuleReplacementPlugin",
292
- ParserHelpers.evaluateToString("string")
293
- );
294
- parser.hooks.evaluateIdentifier.for("module.hot").tap(
295
- {
296
- name: "HotModuleReplacementPlugin",
297
- before: "NodeStuffPlugin"
298
- },
299
- expr => {
300
- return ParserHelpers.evaluateToIdentifier(
301
- "module.hot",
302
- !!parser.state.compilation.hotUpdateChunkTemplate
303
- )(expr);
304
- }
305
- );
306
- // TODO webpack 5: refactor this, no custom hooks
307
- if (!parser.hooks.hotAcceptCallback) {
308
- parser.hooks.hotAcceptCallback = new SyncBailHook([
309
- "expression",
310
- "requests"
311
- ]);
312
- }
313
- if (!parser.hooks.hotAcceptWithoutCallback) {
314
- parser.hooks.hotAcceptWithoutCallback = new SyncBailHook([
315
- "expression",
316
- "requests"
317
- ]);
318
- }
319
- parser.hooks.call
320
- .for("module.hot.accept")
321
- .tap("HotModuleReplacementPlugin", expr => {
322
- if (!parser.state.compilation.hotUpdateChunkTemplate) {
323
- return false;
324
- }
325
- if (expr.arguments.length >= 1) {
326
- const arg = parser.evaluateExpression(expr.arguments[0]);
327
- let params = [];
328
- let requests = [];
329
- if (arg.isString()) {
330
- params = [arg];
331
- } else if (arg.isArray()) {
332
- params = arg.items.filter(param => param.isString());
333
- }
334
- if (params.length > 0) {
335
- params.forEach((param, idx) => {
336
- const request = param.string;
337
- const dep = new ModuleHotAcceptDependency(
338
- request,
339
- param.range
340
- );
341
- dep.optional = true;
342
- dep.loc = Object.create(expr.loc);
343
- dep.loc.index = idx;
344
- parser.state.module.addDependency(dep);
345
- requests.push(request);
346
- });
347
- if (expr.arguments.length > 1) {
348
- parser.hooks.hotAcceptCallback.call(
349
- expr.arguments[1],
350
- requests
351
- );
352
- parser.walkExpression(expr.arguments[1]); // other args are ignored
353
- return true;
354
- } else {
355
- parser.hooks.hotAcceptWithoutCallback.call(expr, requests);
356
- return true;
357
- }
358
- }
359
- }
360
- });
361
- parser.hooks.call
362
- .for("module.hot.decline")
363
- .tap("HotModuleReplacementPlugin", expr => {
364
- if (!parser.state.compilation.hotUpdateChunkTemplate) {
365
- return false;
366
- }
367
- if (expr.arguments.length === 1) {
368
- const arg = parser.evaluateExpression(expr.arguments[0]);
369
- let params = [];
370
- if (arg.isString()) {
371
- params = [arg];
372
- } else if (arg.isArray()) {
373
- params = arg.items.filter(param => param.isString());
374
- }
375
- params.forEach((param, idx) => {
376
- const dep = new ModuleHotDeclineDependency(
377
- param.string,
378
- param.range
379
- );
380
- dep.optional = true;
381
- dep.loc = Object.create(expr.loc);
382
- dep.loc.index = idx;
383
- parser.state.module.addDependency(dep);
384
- });
385
- }
386
- });
387
- parser.hooks.expression
388
- .for("module.hot")
389
- .tap("HotModuleReplacementPlugin", ParserHelpers.skipTraversal);
390
- };
391
-
392
390
  // TODO add HMR support for javascript/esm
393
391
  normalModuleFactory.hooks.parser
394
392
  .for("javascript/auto")
395
- .tap("HotModuleReplacementPlugin", handler);
393
+ .tap("HotModuleReplacementPlugin", addParserPlugins);
396
394
  normalModuleFactory.hooks.parser
397
395
  .for("javascript/dynamic")
398
- .tap("HotModuleReplacementPlugin", handler);
396
+ .tap("HotModuleReplacementPlugin", addParserPlugins);
399
397
 
400
398
  compilation.hooks.normalModuleLoader.tap(
401
399
  "HotModuleReplacementPlugin",
@@ -409,5 +407,5 @@ module.exports = class HotModuleReplacementPlugin {
409
407
  };
410
408
 
411
409
  const hotInitCode = Template.getFunctionContent(
412
- require("./HotModuleReplacement.runtime.js")
410
+ require("./HotModuleReplacement.runtime")
413
411
  );
@@ -4,7 +4,7 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
- /** @typedef {import("./Compiler.js")} Compiler */
7
+ /** @typedef {import("./Compiler")} Compiler */
8
8
 
9
9
  class IgnorePlugin {
10
10
  /**
@@ -19,15 +19,17 @@ const {
19
19
  const Template = require("./Template");
20
20
 
21
21
  /** @typedef {import("webpack-sources").ConcatSource} ConcatSource */
22
+ /** @typedef {import("webpack-sources").Source} Source */
22
23
  /** @typedef {import("./ModuleTemplate")} ModuleTemplate */
23
24
  /** @typedef {import("./Chunk")} Chunk */
24
25
  /** @typedef {import("./Module")} Module} */
25
- /** @typedef {import("crypto").Hash} Hash} */
26
+ /** @typedef {import("./util/createHash").Hash} Hash} */
27
+ /** @typedef {import("./Dependency").DependencyTemplate} DependencyTemplate} */
26
28
 
27
29
  /**
28
30
  * @typedef {Object} RenderManifestOptions
29
31
  * @property {Chunk} chunk the chunk used to render
30
- * @property {Hash} hash
32
+ * @property {string} hash
31
33
  * @property {string} fullHash
32
34
  * @property {TODO} outputOptions
33
35
  * @property {{javascript: ModuleTemplate, webassembly: ModuleTemplate}} moduleTemplates
@@ -92,7 +94,9 @@ module.exports = class MainTemplate extends Tapable {
92
94
  localVars: new SyncWaterfallHook(["source", "chunk", "hash"]),
93
95
  require: new SyncWaterfallHook(["source", "chunk", "hash"]),
94
96
  requireExtensions: new SyncWaterfallHook(["source", "chunk", "hash"]),
97
+ /** @type {SyncWaterfallHook<string, Chunk, string>} */
95
98
  beforeStartup: new SyncWaterfallHook(["source", "chunk", "hash"]),
99
+ /** @type {SyncWaterfallHook<string, Chunk, string>} */
96
100
  startup: new SyncWaterfallHook(["source", "chunk", "hash"]),
97
101
  render: new SyncWaterfallHook([
98
102
  "source",
@@ -361,7 +365,7 @@ module.exports = class MainTemplate extends Tapable {
361
365
  * @param {string} hash hash to be used for render call
362
366
  * @param {Chunk} chunk Chunk instance
363
367
  * @param {ModuleTemplate} moduleTemplate ModuleTemplate instance for render
364
- * @param {TODO} dependencyTemplates DependencyTemplate[]s
368
+ * @param {Map<Function, DependencyTemplate>} dependencyTemplates dependency templates
365
369
  * @returns {ConcatSource} the newly generated source from rendering
366
370
  */
367
371
  render(hash, chunk, moduleTemplate, dependencyTemplates) {
@@ -447,7 +451,7 @@ module.exports = class MainTemplate extends Tapable {
447
451
  /**
448
452
  *
449
453
  * @param {string} hash string hash
450
- * @param {number} length length
454
+ * @param {number=} length length
451
455
  * @returns {string} call hook return
452
456
  */
453
457
  renderCurrentHashCode(hash, length) {
@@ -474,6 +478,11 @@ module.exports = class MainTemplate extends Tapable {
474
478
  return this.hooks.assetPath.call(path, options);
475
479
  }
476
480
 
481
+ /**
482
+ * Updates hash with information from this template
483
+ * @param {Hash} hash the hash to update
484
+ * @returns {void}
485
+ */
477
486
  updateHash(hash) {
478
487
  hash.update("maintemplate");
479
488
  hash.update("3");
@@ -481,6 +490,12 @@ module.exports = class MainTemplate extends Tapable {
481
490
  this.hooks.hash.call(hash);
482
491
  }
483
492
 
493
+ /**
494
+ * Updates hash with chunk-specific information from this template
495
+ * @param {Hash} hash the hash to update
496
+ * @param {Chunk} chunk the chunk
497
+ * @returns {void}
498
+ */
484
499
  updateHashForChunk(hash, chunk) {
485
500
  this.updateHash(hash);
486
501
  this.hooks.hashForChunk.call(hash, chunk);
package/lib/Module.js CHANGED
@@ -13,6 +13,7 @@ const Template = require("./Template");
13
13
 
14
14
  /** @typedef {import("./Chunk")} Chunk */
15
15
  /** @typedef {import("./RequestShortener")} RequestShortener */
16
+ /** @typedef {import("./WebpackError")} WebpackError */
16
17
 
17
18
  const EMPTY_RESOLVE_OPTIONS = {};
18
19
 
@@ -47,15 +48,15 @@ class Module extends DependenciesBlock {
47
48
  this.renderedHash = undefined;
48
49
 
49
50
  // Info from Factory
50
- /** @type {object} */
51
+ /** @type {TODO} */
51
52
  this.resolveOptions = EMPTY_RESOLVE_OPTIONS;
52
53
  /** @type {object} */
53
54
  this.factoryMeta = {};
54
55
 
55
56
  // Info from Build
56
- /** @type {Error[]} */
57
+ /** @type {WebpackError[]} */
57
58
  this.warnings = [];
58
- /** @type {Error[]} */
59
+ /** @type {WebpackError[]} */
59
60
  this.errors = [];
60
61
  /** @type {object} */
61
62
  this.buildMeta = undefined;
@@ -181,6 +182,9 @@ class Module extends DependenciesBlock {
181
182
  );
182
183
  }
183
184
 
185
+ /**
186
+ * @returns {Chunk[]} all chunks which contain the module
187
+ */
184
188
  getChunks() {
185
189
  return Array.from(this._chunks);
186
190
  }
@@ -380,6 +384,8 @@ Module.prototype.build = null;
380
384
  Module.prototype.source = null;
381
385
  Module.prototype.size = null;
382
386
  Module.prototype.nameForCondition = null;
387
+ /** @type {null | function(Chunk): boolean} */
388
+ Module.prototype.chunkCondition = null;
383
389
  Module.prototype.updateCacheModule = null;
384
390
 
385
391
  module.exports = Module;
@@ -4,7 +4,15 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
+ /** @typedef {import("./Module")} Module */
8
+ /** @typedef {import("./Dependency")} Dependency */
9
+
7
10
  class ModuleReason {
11
+ /**
12
+ * @param {Module} module the referencing module
13
+ * @param {Dependency} dependency the referencing dependency
14
+ * @param {string=} explanation some extra detail
15
+ */
8
16
  constructor(module, dependency, explanation) {
9
17
  this.module = module;
10
18
  this.dependency = dependency;
@@ -8,13 +8,25 @@ const MultiEntryDependency = require("./dependencies/MultiEntryDependency");
8
8
  const SingleEntryDependency = require("./dependencies/SingleEntryDependency");
9
9
  const MultiModuleFactory = require("./MultiModuleFactory");
10
10
 
11
- module.exports = class MultiEntryPlugin {
11
+ /** @typedef {import("./Compiler")} Compiler */
12
+
13
+ class MultiEntryPlugin {
14
+ /**
15
+ * The MultiEntryPlugin is invoked whenever this.options.entry value is an array of paths
16
+ * @param {string} context context path
17
+ * @param {string[]} entries array of entry paths
18
+ * @param {string} name entry key name
19
+ */
12
20
  constructor(context, entries, name) {
13
21
  this.context = context;
14
22
  this.entries = entries;
15
23
  this.name = name;
16
24
  }
17
25
 
26
+ /**
27
+ * @param {Compiler} compiler the compiler instance
28
+ * @returns {void}
29
+ */
18
30
  apply(compiler) {
19
31
  compiler.hooks.compilation.tap(
20
32
  "MultiEntryPlugin",
@@ -43,16 +55,26 @@ module.exports = class MultiEntryPlugin {
43
55
  );
44
56
  }
45
57
 
58
+ /**
59
+ * @param {string[]} entries each entry path string
60
+ * @param {string} name name of the entry
61
+ * @returns {MultiEntryDependency} returns a constructed Dependency
62
+ */
46
63
  static createDependency(entries, name) {
47
64
  return new MultiEntryDependency(
48
65
  entries.map((e, idx) => {
49
66
  const dep = new SingleEntryDependency(e);
50
67
  // Because entrypoints are not dependencies found in an
51
68
  // existing module, we give it a synthetic id
52
- dep.loc = `${name}:${100000 + idx}`;
69
+ dep.loc = {
70
+ name,
71
+ index: idx
72
+ };
53
73
  return dep;
54
74
  }),
55
75
  name
56
76
  );
57
77
  }
58
- };
78
+ }
79
+
80
+ module.exports = MultiEntryPlugin;
@@ -4,7 +4,6 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
- const path = require("path");
8
7
  const NativeModule = require("module");
9
8
 
10
9
  const {
@@ -23,6 +22,7 @@ const ModuleBuildError = require("./ModuleBuildError");
23
22
  const ModuleError = require("./ModuleError");
24
23
  const ModuleWarning = require("./ModuleWarning");
25
24
  const createHash = require("./util/createHash");
25
+ const contextify = require("./util/identifier").contextify;
26
26
 
27
27
  const asString = buf => {
28
28
  if (Buffer.isBuffer(buf)) {
@@ -38,28 +38,6 @@ const asBuffer = str => {
38
38
  return str;
39
39
  };
40
40
 
41
- const contextify = (context, request) => {
42
- return request
43
- .split("!")
44
- .map(r => {
45
- const splitPath = r.split("?");
46
- if (/^[a-zA-Z]:\\/.test(splitPath[0])) {
47
- splitPath[0] = path.win32.relative(context, splitPath[0]);
48
- if (!/^[a-zA-Z]:\\/.test(splitPath[0])) {
49
- splitPath[0] = splitPath[0].replace(/\\/g, "/");
50
- }
51
- }
52
- if (/^\//.test(splitPath[0])) {
53
- splitPath[0] = path.posix.relative(context, splitPath[0]);
54
- }
55
- if (!/^(\.\.\/|\/|[a-zA-Z]:\\)/.test(splitPath[0])) {
56
- splitPath[0] = "./" + splitPath[0];
57
- }
58
- return splitPath.join("?");
59
- })
60
- .join("!");
61
- };
62
-
63
41
  class NonErrorEmittedError extends WebpackError {
64
42
  constructor(error) {
65
43
  super();
@@ -191,6 +169,7 @@ class NormalModule extends Module {
191
169
  })
192
170
  );
193
171
  },
172
+ // TODO remove in webpack 5
194
173
  exec: (code, filename) => {
195
174
  // @ts-ignore Argument of type 'this' is not assignable to parameter of type 'Module'.
196
175
  const module = new NativeModule(filename, this);
@@ -265,6 +244,8 @@ class NormalModule extends Module {
265
244
  }
266
245
 
267
246
  if (Buffer.isBuffer(source)) {
247
+ // @ts-ignore
248
+ // TODO We need to fix @types/webpack-sources to allow RawSource to take a Buffer | string
268
249
  return new RawSource(source);
269
250
  }
270
251
 
@@ -486,6 +467,7 @@ class NormalModule extends Module {
486
467
  }
487
468
 
488
469
  getHashDigest(dependencyTemplates) {
470
+ // TODO webpack 5 refactor
489
471
  let dtHash = dependencyTemplates.get("hash");
490
472
  return `${this.hash}-${dtHash}`;
491
473
  }
package/lib/RuleSet.js CHANGED
@@ -75,13 +75,13 @@ normalized:
75
75
  "use strict";
76
76
 
77
77
  const notMatcher = matcher => {
78
- return function(str) {
78
+ return str => {
79
79
  return !matcher(str);
80
80
  };
81
81
  };
82
82
 
83
83
  const orMatcher = items => {
84
- return function(str) {
84
+ return str => {
85
85
  for (let i = 0; i < items.length; i++) {
86
86
  if (items[i](str)) return true;
87
87
  }
@@ -90,7 +90,7 @@ const orMatcher = items => {
90
90
  };
91
91
 
92
92
  const andMatcher = items => {
93
- return function(str) {
93
+ return str => {
94
94
  for (let i = 0; i < items.length; i++) {
95
95
  if (!items[i](str)) return false;
96
96
  }