webpack 5.99.6 → 5.99.7

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 (107) hide show
  1. package/lib/AutomaticPrefetchPlugin.js +21 -22
  2. package/lib/BannerPlugin.js +31 -35
  3. package/lib/CleanPlugin.js +5 -3
  4. package/lib/Compilation.js +9 -8
  5. package/lib/Compiler.js +2 -1
  6. package/lib/ContextExclusionPlugin.js +4 -2
  7. package/lib/ContextReplacementPlugin.js +5 -3
  8. package/lib/DelegatedPlugin.js +4 -2
  9. package/lib/DllEntryPlugin.js +4 -2
  10. package/lib/DllPlugin.js +5 -3
  11. package/lib/DllReferencePlugin.js +56 -60
  12. package/lib/DynamicEntryPlugin.js +4 -2
  13. package/lib/EntryOptionPlugin.js +3 -1
  14. package/lib/EntryPlugin.js +4 -2
  15. package/lib/EnvironmentPlugin.js +4 -2
  16. package/lib/EvalDevToolModulePlugin.js +9 -7
  17. package/lib/EvalSourceMapDevToolPlugin.js +137 -138
  18. package/lib/ExternalsPlugin.js +3 -1
  19. package/lib/FlagDependencyExportsPlugin.js +2 -1
  20. package/lib/IgnorePlugin.js +6 -4
  21. package/lib/IgnoreWarningsPlugin.js +4 -2
  22. package/lib/LibManifestPlugin.js +3 -4
  23. package/lib/LoaderOptionsPlugin.js +4 -2
  24. package/lib/LoaderTargetPlugin.js +4 -2
  25. package/lib/Module.js +19 -12
  26. package/lib/ModuleInfoHeaderPlugin.js +11 -12
  27. package/lib/MultiCompiler.js +5 -3
  28. package/lib/NoEmitOnErrorsPlugin.js +5 -3
  29. package/lib/NormalModule.js +5 -1
  30. package/lib/NormalModuleReplacementPlugin.js +33 -36
  31. package/lib/PlatformPlugin.js +3 -1
  32. package/lib/PrefetchPlugin.js +4 -2
  33. package/lib/ProgressPlugin.js +23 -26
  34. package/lib/RecordIdsPlugin.js +72 -102
  35. package/lib/RuntimePlugin.js +34 -32
  36. package/lib/SourceMapDevToolPlugin.js +7 -5
  37. package/lib/WarnCaseSensitiveModulesPlugin.js +36 -37
  38. package/lib/WarnNoModeSetPlugin.js +3 -1
  39. package/lib/WatchIgnorePlugin.js +3 -1
  40. package/lib/WebpackError.js +11 -3
  41. package/lib/WebpackOptionsApply.js +5 -3
  42. package/lib/async-modules/InferAsyncModulesPlugin.js +25 -26
  43. package/lib/cache/IdleFileCachePlugin.js +11 -12
  44. package/lib/cache/MemoryWithGcCachePlugin.js +7 -5
  45. package/lib/cache/ResolverCachePlugin.js +8 -6
  46. package/lib/cli.js +5 -1
  47. package/lib/config/normalization.js +9 -3
  48. package/lib/container/ContainerReferencePlugin.js +24 -26
  49. package/lib/container/ModuleFederationPlugin.js +2 -1
  50. package/lib/css/CssGenerator.js +1 -1
  51. package/lib/css/CssModulesPlugin.js +6 -4
  52. package/lib/dependencies/HarmonyDetectionParserPlugin.js +9 -15
  53. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -15
  54. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +4 -2
  55. package/lib/dependencies/LoaderPlugin.js +5 -3
  56. package/lib/dependencies/RequireContextDependencyParserPlugin.js +46 -46
  57. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +94 -100
  58. package/lib/esm/ModuleChunkLoadingPlugin.js +72 -73
  59. package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
  60. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +0 -1
  61. package/lib/hmr/LazyCompilationPlugin.js +17 -18
  62. package/lib/ids/ChunkModuleIdRangePlugin.js +6 -6
  63. package/lib/ids/DeterministicModuleIdsPlugin.js +47 -48
  64. package/lib/ids/HashedModuleIdsPlugin.js +4 -2
  65. package/lib/ids/NamedChunkIdsPlugin.js +4 -2
  66. package/lib/ids/NamedModuleIdsPlugin.js +4 -2
  67. package/lib/ids/NaturalChunkIdsPlugin.js +4 -2
  68. package/lib/ids/NaturalModuleIdsPlugin.js +4 -2
  69. package/lib/ids/OccurrenceChunkIdsPlugin.js +4 -2
  70. package/lib/ids/OccurrenceModuleIdsPlugin.js +4 -2
  71. package/lib/javascript/JavascriptParser.js +634 -656
  72. package/lib/library/ModuleLibraryPlugin.js +60 -42
  73. package/lib/node/CommonJsChunkLoadingPlugin.js +69 -73
  74. package/lib/node/NodeEnvironmentPlugin.js +3 -1
  75. package/lib/optimize/AggressiveSplittingPlugin.js +224 -232
  76. package/lib/optimize/ConcatenatedModule.js +12 -15
  77. package/lib/optimize/FlagIncludedChunksPlugin.js +92 -97
  78. package/lib/optimize/LimitChunkCountPlugin.js +4 -2
  79. package/lib/optimize/MangleExportsPlugin.js +15 -16
  80. package/lib/optimize/MinChunkSizePlugin.js +4 -2
  81. package/lib/optimize/ModuleConcatenationPlugin.js +4 -2
  82. package/lib/optimize/RealContentHashPlugin.js +4 -2
  83. package/lib/optimize/RemoveEmptyChunksPlugin.js +5 -3
  84. package/lib/optimize/RemoveParentModulesPlugin.js +4 -2
  85. package/lib/optimize/RuntimeChunkPlugin.js +17 -18
  86. package/lib/optimize/SplitChunksPlugin.js +7 -5
  87. package/lib/performance/SizeLimitsPlugin.js +3 -1
  88. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +61 -62
  89. package/lib/runtime/StartupChunkDependenciesPlugin.js +39 -42
  90. package/lib/schemes/DataUriPlugin.js +5 -3
  91. package/lib/schemes/FileUriPlugin.js +5 -3
  92. package/lib/schemes/HttpUriPlugin.js +32 -39
  93. package/lib/serialization/AggregateErrorSerializer.js +42 -0
  94. package/lib/serialization/ErrorObjectSerializer.js +7 -2
  95. package/lib/serialization/ObjectMiddleware.js +13 -0
  96. package/lib/sharing/ProvideSharedPlugin.js +6 -4
  97. package/lib/stats/DefaultStatsFactoryPlugin.js +89 -33
  98. package/lib/stats/DefaultStatsPresetPlugin.js +25 -20
  99. package/lib/stats/DefaultStatsPrinterPlugin.js +306 -341
  100. package/lib/util/concatenate.js +4 -2
  101. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +55 -57
  102. package/lib/web/JsonpChunkLoadingPlugin.js +73 -74
  103. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +77 -78
  104. package/package.json +4 -3
  105. package/schemas/WebpackOptions.check.js +1 -1
  106. package/schemas/WebpackOptions.json +24 -2
  107. package/types.d.ts +148 -55
@@ -12,6 +12,7 @@ const ProgressPlugin = require("../ProgressPlugin");
12
12
  /** @typedef {import("./PackFileCacheStrategy")} PackFileCacheStrategy */
13
13
 
14
14
  const BUILD_DEPENDENCIES_KEY = Symbol("build dependencies key");
15
+ const PLUGIN_NAME = "IdleFileCachePlugin";
15
16
 
16
17
  class IdleFileCachePlugin {
17
18
  /**
@@ -55,7 +56,7 @@ class IdleFileCachePlugin {
55
56
  const pendingIdleTasks = new Map();
56
57
 
57
58
  compiler.cache.hooks.store.tap(
58
- { name: "IdleFileCachePlugin", stage: Cache.STAGE_DISK },
59
+ { name: PLUGIN_NAME, stage: Cache.STAGE_DISK },
59
60
  (identifier, etag, data) => {
60
61
  pendingIdleTasks.set(identifier, () =>
61
62
  strategy.store(identifier, etag, data)
@@ -64,7 +65,7 @@ class IdleFileCachePlugin {
64
65
  );
65
66
 
66
67
  compiler.cache.hooks.get.tapPromise(
67
- { name: "IdleFileCachePlugin", stage: Cache.STAGE_DISK },
68
+ { name: PLUGIN_NAME, stage: Cache.STAGE_DISK },
68
69
  (identifier, etag, gotHandlers) => {
69
70
  const restore = () =>
70
71
  strategy.restore(identifier, etag).then(cacheEntry => {
@@ -91,7 +92,7 @@ class IdleFileCachePlugin {
91
92
  );
92
93
 
93
94
  compiler.cache.hooks.storeBuildDependencies.tap(
94
- { name: "IdleFileCachePlugin", stage: Cache.STAGE_DISK },
95
+ { name: PLUGIN_NAME, stage: Cache.STAGE_DISK },
95
96
  dependencies => {
96
97
  pendingIdleTasks.set(BUILD_DEPENDENCIES_KEY, () =>
97
98
  Promise.resolve().then(() =>
@@ -102,7 +103,7 @@ class IdleFileCachePlugin {
102
103
  );
103
104
 
104
105
  compiler.cache.hooks.shutdown.tapPromise(
105
- { name: "IdleFileCachePlugin", stage: Cache.STAGE_DISK },
106
+ { name: PLUGIN_NAME, stage: Cache.STAGE_DISK },
106
107
  () => {
107
108
  if (idleTimer) {
108
109
  clearTimeout(idleTimer);
@@ -165,9 +166,7 @@ class IdleFileCachePlugin {
165
166
  timeSpendInBuild = 0;
166
167
  })
167
168
  .catch(err => {
168
- const logger = compiler.getInfrastructureLogger(
169
- "IdleFileCachePlugin"
170
- );
169
+ const logger = compiler.getInfrastructureLogger(PLUGIN_NAME);
171
170
  logger.warn(`Background tasks during idle failed: ${err.message}`);
172
171
  logger.debug(err.stack);
173
172
  });
@@ -177,12 +176,12 @@ class IdleFileCachePlugin {
177
176
  /** @type {ReturnType<typeof setTimeout> | undefined} */
178
177
  let idleTimer;
179
178
  compiler.cache.hooks.beginIdle.tap(
180
- { name: "IdleFileCachePlugin", stage: Cache.STAGE_DISK },
179
+ { name: PLUGIN_NAME, stage: Cache.STAGE_DISK },
181
180
  () => {
182
181
  const isLargeChange = timeSpendInBuild > avgTimeSpendInStore * 2;
183
182
  if (isInitialStore && idleTimeoutForInitialStore < idleTimeout) {
184
183
  compiler
185
- .getInfrastructureLogger("IdleFileCachePlugin")
184
+ .getInfrastructureLogger(PLUGIN_NAME)
186
185
  .log(
187
186
  `Initial cache was generated and cache will be persisted in ${
188
187
  idleTimeoutForInitialStore / 1000
@@ -193,7 +192,7 @@ class IdleFileCachePlugin {
193
192
  idleTimeoutAfterLargeChanges < idleTimeout
194
193
  ) {
195
194
  compiler
196
- .getInfrastructureLogger("IdleFileCachePlugin")
195
+ .getInfrastructureLogger(PLUGIN_NAME)
197
196
  .log(
198
197
  `Spend ${Math.round(timeSpendInBuild) / 1000}s in build and ${
199
198
  Math.round(avgTimeSpendInStore) / 1000
@@ -218,7 +217,7 @@ class IdleFileCachePlugin {
218
217
  }
219
218
  );
220
219
  compiler.cache.hooks.endIdle.tap(
221
- { name: "IdleFileCachePlugin", stage: Cache.STAGE_DISK },
220
+ { name: PLUGIN_NAME, stage: Cache.STAGE_DISK },
222
221
  () => {
223
222
  if (idleTimer) {
224
223
  clearTimeout(idleTimer);
@@ -227,7 +226,7 @@ class IdleFileCachePlugin {
227
226
  isIdle = false;
228
227
  }
229
228
  );
230
- compiler.hooks.done.tap("IdleFileCachePlugin", stats => {
229
+ compiler.hooks.done.tap(PLUGIN_NAME, stats => {
231
230
  // 10% build overhead is ignored, as it's not cacheable
232
231
  timeSpendInBuild *= 0.9;
233
232
  timeSpendInBuild +=
@@ -18,6 +18,8 @@ const Cache = require("../Cache");
18
18
  * @property {number} maxGenerations max generations
19
19
  */
20
20
 
21
+ const PLUGIN_NAME = "MemoryWithGcCachePlugin";
22
+
21
23
  class MemoryWithGcCachePlugin {
22
24
  /**
23
25
  * @param {MemoryWithGcCachePluginOptions} options options
@@ -39,8 +41,8 @@ class MemoryWithGcCachePlugin {
39
41
  const oldCache = new Map();
40
42
  let generation = 0;
41
43
  let cachePosition = 0;
42
- const logger = compiler.getInfrastructureLogger("MemoryWithGcCachePlugin");
43
- compiler.hooks.afterDone.tap("MemoryWithGcCachePlugin", () => {
44
+ const logger = compiler.getInfrastructureLogger(PLUGIN_NAME);
45
+ compiler.hooks.afterDone.tap(PLUGIN_NAME, () => {
44
46
  generation++;
45
47
  let clearedEntries = 0;
46
48
  let lastClearedIdentifier;
@@ -91,13 +93,13 @@ class MemoryWithGcCachePlugin {
91
93
  }
92
94
  });
93
95
  compiler.cache.hooks.store.tap(
94
- { name: "MemoryWithGcCachePlugin", stage: Cache.STAGE_MEMORY },
96
+ { name: PLUGIN_NAME, stage: Cache.STAGE_MEMORY },
95
97
  (identifier, etag, data) => {
96
98
  cache.set(identifier, { etag, data });
97
99
  }
98
100
  );
99
101
  compiler.cache.hooks.get.tap(
100
- { name: "MemoryWithGcCachePlugin", stage: Cache.STAGE_MEMORY },
102
+ { name: PLUGIN_NAME, stage: Cache.STAGE_MEMORY },
101
103
  (identifier, etag, gotHandlers) => {
102
104
  const cacheEntry = cache.get(identifier);
103
105
  if (cacheEntry === null) {
@@ -129,7 +131,7 @@ class MemoryWithGcCachePlugin {
129
131
  }
130
132
  );
131
133
  compiler.cache.hooks.shutdown.tap(
132
- { name: "MemoryWithGcCachePlugin", stage: Cache.STAGE_MEMORY },
134
+ { name: PLUGIN_NAME, stage: Cache.STAGE_MEMORY },
133
135
  () => {
134
136
  cache.clear();
135
137
  oldCache.clear();
@@ -97,6 +97,8 @@ const objectToString = (object, excludeContext) => {
97
97
 
98
98
  /** @typedef {NonNullable<ResolveContext["yield"]>} Yield */
99
99
 
100
+ const PLUGIN_NAME = "ResolverCachePlugin";
101
+
100
102
  class ResolverCachePlugin {
101
103
  /**
102
104
  * Apply the plugin
@@ -104,7 +106,7 @@ class ResolverCachePlugin {
104
106
  * @returns {void}
105
107
  */
106
108
  apply(compiler) {
107
- const cache = compiler.getCache("ResolverCachePlugin");
109
+ const cache = compiler.getCache(PLUGIN_NAME);
108
110
  /** @type {FileSystemInfo} */
109
111
  let fileSystemInfo;
110
112
  /** @type {SnapshotOptions | undefined} */
@@ -113,12 +115,12 @@ class ResolverCachePlugin {
113
115
  let cachedResolves = 0;
114
116
  let cacheInvalidResolves = 0;
115
117
  let concurrentResolves = 0;
116
- compiler.hooks.thisCompilation.tap("ResolverCachePlugin", compilation => {
118
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
117
119
  snapshotOptions = compilation.options.snapshot.resolve;
118
120
  fileSystemInfo = compilation.fileSystemInfo;
119
- compilation.hooks.finishModules.tap("ResolverCachePlugin", () => {
121
+ compilation.hooks.finishModules.tap(PLUGIN_NAME, () => {
120
122
  if (realResolves + cachedResolves > 0) {
121
- const logger = compilation.getLogger("webpack.ResolverCachePlugin");
123
+ const logger = compilation.getLogger(`webpack.${PLUGIN_NAME}`);
122
124
  logger.log(
123
125
  `${Math.round(
124
126
  (100 * realResolves) / (realResolves + cachedResolves)
@@ -260,7 +262,7 @@ class ResolverCachePlugin {
260
262
  const hook =
261
263
  /** @type {SyncHook<[Resolver, ResolveOptions, ResolveOptionsWithDependencyType]>} */
262
264
  (_hook);
263
- hook.tap("ResolverCachePlugin", (resolver, options, userOptions) => {
265
+ hook.tap(PLUGIN_NAME, (resolver, options, userOptions) => {
264
266
  if (
265
267
  /** @type {ResolveOptions & { cache: boolean }} */
266
268
  (options).cache !== true
@@ -273,7 +275,7 @@ class ResolverCachePlugin {
273
275
  : false;
274
276
  resolver.hooks.resolve.tapAsync(
275
277
  {
276
- name: "ResolverCachePlugin",
278
+ name: PLUGIN_NAME,
277
279
  stage: -100
278
280
  },
279
281
  (request, resolveContext, callback) => {
package/lib/cli.js CHANGED
@@ -8,7 +8,11 @@
8
8
  const path = require("path");
9
9
  const webpackSchema = require("../schemas/WebpackOptions.json");
10
10
 
11
- /** @typedef {Parameters<import("schema-utils").validate>[0] & { absolutePath: boolean, instanceof: string, cli: { helper?: boolean, exclude?: boolean, description?: string, negatedDescription?: string, resetDescription?: string } }} Schema */
11
+ /** @typedef {import("json-schema").JSONSchema4} JSONSchema4 */
12
+ /** @typedef {import("json-schema").JSONSchema6} JSONSchema6 */
13
+ /** @typedef {import("json-schema").JSONSchema7} JSONSchema7 */
14
+ /** @typedef {JSONSchema4 | JSONSchema6 | JSONSchema7} JSONSchema */
15
+ /** @typedef {JSONSchema & { absolutePath: boolean, instanceof: string, cli: { helper?: boolean, exclude?: boolean, description?: string, negatedDescription?: string, resetDescription?: string } }} Schema */
12
16
 
13
17
  // TODO add originPath to PathItem for better errors
14
18
  /**
@@ -22,6 +22,7 @@ const util = require("util");
22
22
  /** @typedef {import("../../declarations/WebpackOptions").WebpackOptions} WebpackOptions */
23
23
  /** @typedef {import("../../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptionsNormalized */
24
24
  /** @typedef {import("../Entrypoint")} Entrypoint */
25
+ /** @typedef {import("../WebpackError")} WebpackError */
25
26
 
26
27
  const handledDeprecatedNoEmitOnErrors = util.deprecate(
27
28
  /**
@@ -210,14 +211,19 @@ const getNormalizedWebpackOptions = config => ({
210
211
  }
211
212
  if (
212
213
  i.module &&
213
- (!warning.module ||
214
+ (!(/** @type {WebpackError} */ (warning).module) ||
214
215
  !i.module.test(
215
- warning.module.readableIdentifier(requestShortener)
216
+ /** @type {WebpackError} */
217
+ (warning).module.readableIdentifier(requestShortener)
216
218
  ))
217
219
  ) {
218
220
  return false;
219
221
  }
220
- if (i.file && (!warning.file || !i.file.test(warning.file))) {
222
+ if (
223
+ i.file &&
224
+ (!(/** @type {WebpackError} */ (warning).file) ||
225
+ !i.file.test(/** @type {WebpackError} */ (warning).file))
226
+ ) {
221
227
  return false;
222
228
  }
223
229
  return true;
@@ -31,6 +31,7 @@ const validate = createSchemaValidation(
31
31
  );
32
32
 
33
33
  const slashCode = "/".charCodeAt(0);
34
+ const PLUGIN_NAME = "ContainerReferencePlugin";
34
35
 
35
36
  class ContainerReferencePlugin {
36
37
  /**
@@ -79,7 +80,7 @@ class ContainerReferencePlugin {
79
80
  new ExternalsPlugin(remoteType, remoteExternals).apply(compiler);
80
81
 
81
82
  compiler.hooks.compilation.tap(
82
- "ContainerReferencePlugin",
83
+ PLUGIN_NAME,
83
84
  (compilation, { normalModuleFactory }) => {
84
85
  compilation.dependencyFactories.set(
85
86
  RemoteToExternalDependency,
@@ -96,37 +97,34 @@ class ContainerReferencePlugin {
96
97
  new FallbackModuleFactory()
97
98
  );
98
99
 
99
- normalModuleFactory.hooks.factorize.tap(
100
- "ContainerReferencePlugin",
101
- data => {
102
- if (!data.request.includes("!")) {
103
- for (const [key, config] of remotes) {
104
- if (
105
- data.request.startsWith(`${key}`) &&
106
- (data.request.length === key.length ||
107
- data.request.charCodeAt(key.length) === slashCode)
108
- ) {
109
- return new RemoteModule(
110
- data.request,
111
- config.external.map((external, i) =>
112
- external.startsWith("internal ")
113
- ? external.slice(9)
114
- : `webpack/container/reference/${key}${
115
- i ? `/fallback-${i}` : ""
116
- }`
117
- ),
118
- `.${data.request.slice(key.length)}`,
119
- config.shareScope
120
- );
121
- }
100
+ normalModuleFactory.hooks.factorize.tap(PLUGIN_NAME, data => {
101
+ if (!data.request.includes("!")) {
102
+ for (const [key, config] of remotes) {
103
+ if (
104
+ data.request.startsWith(`${key}`) &&
105
+ (data.request.length === key.length ||
106
+ data.request.charCodeAt(key.length) === slashCode)
107
+ ) {
108
+ return new RemoteModule(
109
+ data.request,
110
+ config.external.map((external, i) =>
111
+ external.startsWith("internal ")
112
+ ? external.slice(9)
113
+ : `webpack/container/reference/${key}${
114
+ i ? `/fallback-${i}` : ""
115
+ }`
116
+ ),
117
+ `.${data.request.slice(key.length)}`,
118
+ config.shareScope
119
+ );
122
120
  }
123
121
  }
124
122
  }
125
- );
123
+ });
126
124
 
127
125
  compilation.hooks.runtimeRequirementInTree
128
126
  .for(RuntimeGlobals.ensureChunkHandlers)
129
- .tap("ContainerReferencePlugin", (chunk, set) => {
127
+ .tap(PLUGIN_NAME, (chunk, set) => {
130
128
  set.add(RuntimeGlobals.module);
131
129
  set.add(RuntimeGlobals.moduleFactoriesAddOnly);
132
130
  set.add(RuntimeGlobals.hasOwnProperty);
@@ -37,6 +37,7 @@ const validate = createSchemaValidation(
37
37
 
38
38
  /** @type {WeakMap<Compilation, CompilationHooks>} */
39
39
  const compilationHooksMap = new WeakMap();
40
+ const PLUGIN_NAME = "ModuleFederationPlugin";
40
41
 
41
42
  class ModuleFederationPlugin {
42
43
  /**
@@ -89,7 +90,7 @@ class ModuleFederationPlugin {
89
90
  ) {
90
91
  compiler.options.output.enabledLibraryTypes.push(library.type);
91
92
  }
92
- compiler.hooks.afterPlugins.tap("ModuleFederationPlugin", () => {
93
+ compiler.hooks.afterPlugins.tap(PLUGIN_NAME, () => {
93
94
  if (
94
95
  options.exposes &&
95
96
  (Array.isArray(options.exposes)
@@ -292,7 +292,7 @@ class CssGenerator extends Generator {
292
292
  Array.from(exports).reduce((obj, [key, value]) => {
293
293
  obj[key] = value;
294
294
  return obj;
295
- }, {})
295
+ }, /** @type {Record<string, string>} */ ({}))
296
296
  );
297
297
 
298
298
  return stringifiedExports.length + 42;
@@ -385,15 +385,17 @@ class CssModulesPlugin {
385
385
  compilation
386
386
  ).renderModuleContent.tap(PLUGIN_NAME, (source, module) => {
387
387
  if (module instanceof CssModule && module.hot) {
388
- const exports =
389
- /** @type {BuildInfo} */
390
- (module.buildInfo).cssData.exports;
388
+ const cssData = /** @type {BuildInfo} */ (module.buildInfo).cssData;
389
+ if (!cssData) {
390
+ return source;
391
+ }
392
+ const exports = cssData.exports;
391
393
  const stringifiedExports = JSON.stringify(
392
394
  JSON.stringify(
393
395
  Array.from(exports).reduce((obj, [key, value]) => {
394
396
  obj[key] = value;
395
397
  return obj;
396
- }, {})
398
+ }, /** @type {Record<string, string>} */ ({}))
397
399
  )
398
400
  );
399
401
 
@@ -15,6 +15,8 @@ const HarmonyExports = require("./HarmonyExports");
15
15
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
16
16
  /** @typedef {import("./HarmonyModulesPlugin").HarmonyModulesPluginOptions} HarmonyModulesPluginOptions */
17
17
 
18
+ const PLUGIN_NAME = "HarmonyDetectionParserPlugin";
19
+
18
20
  module.exports = class HarmonyDetectionParserPlugin {
19
21
  /**
20
22
  * @param {HarmonyModulesPluginOptions} options options
@@ -29,7 +31,7 @@ module.exports = class HarmonyDetectionParserPlugin {
29
31
  * @returns {void}
30
32
  */
31
33
  apply(parser) {
32
- parser.hooks.program.tap("HarmonyDetectionParserPlugin", ast => {
34
+ parser.hooks.program.tap(PLUGIN_NAME, ast => {
33
35
  const isStrictHarmony =
34
36
  parser.state.module.type === JAVASCRIPT_MODULE_TYPE_ESM;
35
37
  const isHarmony =
@@ -62,7 +64,7 @@ module.exports = class HarmonyDetectionParserPlugin {
62
64
  }
63
65
  });
64
66
 
65
- parser.hooks.topLevelAwait.tap("HarmonyDetectionParserPlugin", () => {
67
+ parser.hooks.topLevelAwait.tap(PLUGIN_NAME, () => {
66
68
  const module = parser.state.module;
67
69
  if (!this.topLevelAwait) {
68
70
  throw new Error(
@@ -105,19 +107,11 @@ module.exports = class HarmonyDetectionParserPlugin {
105
107
  for (const identifier of nonHarmonyIdentifiers) {
106
108
  parser.hooks.evaluateTypeof
107
109
  .for(identifier)
108
- .tap("HarmonyDetectionParserPlugin", nullInHarmony);
109
- parser.hooks.typeof
110
- .for(identifier)
111
- .tap("HarmonyDetectionParserPlugin", skipInHarmony);
112
- parser.hooks.evaluate
113
- .for(identifier)
114
- .tap("HarmonyDetectionParserPlugin", nullInHarmony);
115
- parser.hooks.expression
116
- .for(identifier)
117
- .tap("HarmonyDetectionParserPlugin", skipInHarmony);
118
- parser.hooks.call
119
- .for(identifier)
120
- .tap("HarmonyDetectionParserPlugin", skipInHarmony);
110
+ .tap(PLUGIN_NAME, nullInHarmony);
111
+ parser.hooks.typeof.for(identifier).tap(PLUGIN_NAME, skipInHarmony);
112
+ parser.hooks.evaluate.for(identifier).tap(PLUGIN_NAME, nullInHarmony);
113
+ parser.hooks.expression.for(identifier).tap(PLUGIN_NAME, skipInHarmony);
114
+ parser.hooks.call.for(identifier).tap(PLUGIN_NAME, skipInHarmony);
121
115
  }
122
116
  }
123
117
  };
@@ -12,27 +12,27 @@ const HarmonyExports = require("./HarmonyExports");
12
12
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
13
13
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
14
14
 
15
+ const PLUGIN_NAME = "HarmonyTopLevelThisParserPlugin";
16
+
15
17
  class HarmonyTopLevelThisParserPlugin {
16
18
  /**
17
19
  * @param {JavascriptParser} parser the parser
18
20
  * @returns {void}
19
21
  */
20
22
  apply(parser) {
21
- parser.hooks.expression
22
- .for("this")
23
- .tap("HarmonyTopLevelThisParserPlugin", node => {
24
- if (!parser.scope.topLevelScope) return;
25
- if (HarmonyExports.isEnabled(parser.state)) {
26
- const dep = new ConstDependency(
27
- "undefined",
28
- /** @type {Range} */ (node.range),
29
- null
30
- );
31
- dep.loc = /** @type {DependencyLocation} */ (node.loc);
32
- parser.state.module.addPresentationalDependency(dep);
33
- return true;
34
- }
35
- });
23
+ parser.hooks.expression.for("this").tap(PLUGIN_NAME, node => {
24
+ if (!parser.scope.topLevelScope) return;
25
+ if (HarmonyExports.isEnabled(parser.state)) {
26
+ const dep = new ConstDependency(
27
+ "undefined",
28
+ /** @type {Range} */ (node.range),
29
+ null
30
+ );
31
+ dep.loc = /** @type {DependencyLocation} */ (node.loc);
32
+ parser.state.module.addPresentationalDependency(dep);
33
+ return true;
34
+ }
35
+ });
36
36
  }
37
37
  }
38
38
 
@@ -52,6 +52,8 @@ function createError(msg, loc) {
52
52
  return error;
53
53
  }
54
54
 
55
+ const PLUGIN_NAME = "ImportMetaContextDependencyParserPlugin";
56
+
55
57
  module.exports = class ImportMetaContextDependencyParserPlugin {
56
58
  /**
57
59
  * @param {JavascriptParser} parser the parser
@@ -60,7 +62,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
60
62
  apply(parser) {
61
63
  parser.hooks.evaluateIdentifier
62
64
  .for("import.meta.webpackContext")
63
- .tap("ImportMetaContextDependencyParserPlugin", expr =>
65
+ .tap(PLUGIN_NAME, expr =>
64
66
  evaluateToIdentifier(
65
67
  "import.meta.webpackContext",
66
68
  "import.meta",
@@ -70,7 +72,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
70
72
  );
71
73
  parser.hooks.call
72
74
  .for("import.meta.webpackContext")
73
- .tap("ImportMetaContextDependencyParserPlugin", expr => {
75
+ .tap(PLUGIN_NAME, expr => {
74
76
  if (expr.arguments.length < 1 || expr.arguments.length > 2) return;
75
77
  const [directoryNode, optionsNode] = expr.arguments;
76
78
  if (optionsNode && optionsNode.type !== "ObjectExpression") return;
@@ -31,6 +31,8 @@ const LoaderImportDependency = require("./LoaderImportDependency");
31
31
  * @property {string=} baseUri target base uri
32
32
  */
33
33
 
34
+ const PLUGIN_NAME = "LoaderPlugin";
35
+
34
36
  class LoaderPlugin {
35
37
  /**
36
38
  * Apply the plugin
@@ -39,7 +41,7 @@ class LoaderPlugin {
39
41
  */
40
42
  apply(compiler) {
41
43
  compiler.hooks.compilation.tap(
42
- "LoaderPlugin",
44
+ PLUGIN_NAME,
43
45
  (compilation, { normalModuleFactory }) => {
44
46
  compilation.dependencyFactories.set(
45
47
  LoaderDependency,
@@ -52,10 +54,10 @@ class LoaderPlugin {
52
54
  }
53
55
  );
54
56
 
55
- compiler.hooks.compilation.tap("LoaderPlugin", compilation => {
57
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
56
58
  const moduleGraph = compilation.moduleGraph;
57
59
  NormalModule.getCompilationHooks(compilation).loader.tap(
58
- "LoaderPlugin",
60
+ PLUGIN_NAME,
59
61
  loaderContext => {
60
62
  loaderContext.loadModule = (request, callback) => {
61
63
  const dep = new LoaderDependency(request);
@@ -12,58 +12,58 @@ const RequireContextDependency = require("./RequireContextDependency");
12
12
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
13
13
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
14
14
 
15
+ const PLUGIN_NAME = "RequireContextDependencyParserPlugin";
16
+
15
17
  module.exports = class RequireContextDependencyParserPlugin {
16
18
  /**
17
19
  * @param {JavascriptParser} parser the parser
18
20
  * @returns {void}
19
21
  */
20
22
  apply(parser) {
21
- parser.hooks.call
22
- .for("require.context")
23
- .tap("RequireContextDependencyParserPlugin", expr => {
24
- let regExp = /^\.\/.*$/;
25
- let recursive = true;
26
- /** @type {ContextMode} */
27
- let mode = "sync";
28
- switch (expr.arguments.length) {
29
- case 4: {
30
- const modeExpr = parser.evaluateExpression(expr.arguments[3]);
31
- if (!modeExpr.isString()) return;
32
- mode = /** @type {ContextMode} */ (modeExpr.string);
33
- }
34
- // falls through
35
- case 3: {
36
- const regExpExpr = parser.evaluateExpression(expr.arguments[2]);
37
- if (!regExpExpr.isRegExp()) return;
38
- regExp = /** @type {RegExp} */ (regExpExpr.regExp);
39
- }
40
- // falls through
41
- case 2: {
42
- const recursiveExpr = parser.evaluateExpression(expr.arguments[1]);
43
- if (!recursiveExpr.isBoolean()) return;
44
- recursive = /** @type {boolean} */ (recursiveExpr.bool);
45
- }
46
- // falls through
47
- case 1: {
48
- const requestExpr = parser.evaluateExpression(expr.arguments[0]);
49
- if (!requestExpr.isString()) return;
50
- const dep = new RequireContextDependency(
51
- {
52
- request: /** @type {string} */ (requestExpr.string),
53
- recursive,
54
- regExp,
55
- mode,
56
- category: "commonjs"
57
- },
58
- /** @type {Range} */
59
- (expr.range)
60
- );
61
- dep.loc = /** @type {DependencyLocation} */ (expr.loc);
62
- dep.optional = Boolean(parser.scope.inTry);
63
- parser.state.current.addDependency(dep);
64
- return true;
65
- }
23
+ parser.hooks.call.for("require.context").tap(PLUGIN_NAME, expr => {
24
+ let regExp = /^\.\/.*$/;
25
+ let recursive = true;
26
+ /** @type {ContextMode} */
27
+ let mode = "sync";
28
+ switch (expr.arguments.length) {
29
+ case 4: {
30
+ const modeExpr = parser.evaluateExpression(expr.arguments[3]);
31
+ if (!modeExpr.isString()) return;
32
+ mode = /** @type {ContextMode} */ (modeExpr.string);
33
+ }
34
+ // falls through
35
+ case 3: {
36
+ const regExpExpr = parser.evaluateExpression(expr.arguments[2]);
37
+ if (!regExpExpr.isRegExp()) return;
38
+ regExp = /** @type {RegExp} */ (regExpExpr.regExp);
39
+ }
40
+ // falls through
41
+ case 2: {
42
+ const recursiveExpr = parser.evaluateExpression(expr.arguments[1]);
43
+ if (!recursiveExpr.isBoolean()) return;
44
+ recursive = /** @type {boolean} */ (recursiveExpr.bool);
45
+ }
46
+ // falls through
47
+ case 1: {
48
+ const requestExpr = parser.evaluateExpression(expr.arguments[0]);
49
+ if (!requestExpr.isString()) return;
50
+ const dep = new RequireContextDependency(
51
+ {
52
+ request: /** @type {string} */ (requestExpr.string),
53
+ recursive,
54
+ regExp,
55
+ mode,
56
+ category: "commonjs"
57
+ },
58
+ /** @type {Range} */
59
+ (expr.range)
60
+ );
61
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
62
+ dep.optional = Boolean(parser.scope.inTry);
63
+ parser.state.current.addDependency(dep);
64
+ return true;
66
65
  }
67
- });
66
+ }
67
+ });
68
68
  }
69
69
  };