webpack 5.91.0 → 5.92.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (174) hide show
  1. package/bin/webpack.js +1 -2
  2. package/lib/APIPlugin.js +6 -2
  3. package/lib/Cache.js +1 -1
  4. package/lib/Chunk.js +7 -4
  5. package/lib/ChunkGraph.js +20 -7
  6. package/lib/ChunkGroup.js +9 -3
  7. package/lib/CleanPlugin.js +1 -1
  8. package/lib/Compilation.js +33 -27
  9. package/lib/Compiler.js +28 -8
  10. package/lib/ConcatenationScope.js +3 -3
  11. package/lib/ContextModule.js +95 -43
  12. package/lib/DefinePlugin.js +14 -4
  13. package/lib/Dependency.js +8 -8
  14. package/lib/DependencyTemplate.js +10 -5
  15. package/lib/DllReferencePlugin.js +1 -1
  16. package/lib/EvalDevToolModulePlugin.js +11 -0
  17. package/lib/ExportsInfo.js +22 -4
  18. package/lib/ExternalModule.js +49 -18
  19. package/lib/FileSystemInfo.js +68 -41
  20. package/lib/FlagDependencyExportsPlugin.js +21 -7
  21. package/lib/Generator.js +2 -3
  22. package/lib/HotModuleReplacementPlugin.js +108 -45
  23. package/lib/IgnorePlugin.js +4 -1
  24. package/lib/LibManifestPlugin.js +2 -2
  25. package/lib/Module.js +11 -12
  26. package/lib/ModuleFactory.js +3 -3
  27. package/lib/ModuleFilenameHelpers.js +29 -16
  28. package/lib/ModuleGraph.js +5 -5
  29. package/lib/MultiCompiler.js +36 -1
  30. package/lib/NormalModule.js +10 -12
  31. package/lib/NormalModuleFactory.js +17 -8
  32. package/lib/Parser.js +1 -1
  33. package/lib/PlatformPlugin.js +39 -0
  34. package/lib/ProgressPlugin.js +1 -1
  35. package/lib/RecordIdsPlugin.js +4 -4
  36. package/lib/ResolverFactory.js +3 -3
  37. package/lib/RuntimeTemplate.js +22 -18
  38. package/lib/Stats.js +1 -1
  39. package/lib/Template.js +5 -5
  40. package/lib/TemplatedPathPlugin.js +16 -1
  41. package/lib/asset/AssetGenerator.js +15 -0
  42. package/lib/buildChunkGraph.js +3 -3
  43. package/lib/cache/MemoryWithGcCachePlugin.js +1 -1
  44. package/lib/cache/PackFileCacheStrategy.js +2 -2
  45. package/lib/cache/ResolverCachePlugin.js +8 -8
  46. package/lib/cache/getLazyHashedEtag.js +1 -1
  47. package/lib/cli.js +5 -5
  48. package/lib/config/browserslistTargetHandler.js +7 -1
  49. package/lib/config/defaults.js +85 -34
  50. package/lib/config/target.js +18 -11
  51. package/lib/container/ContainerEntryModule.js +1 -1
  52. package/lib/css/CssExportsGenerator.js +43 -17
  53. package/lib/css/CssGenerator.js +22 -12
  54. package/lib/css/CssLoadingRuntimeModule.js +8 -5
  55. package/lib/css/CssModulesPlugin.js +197 -100
  56. package/lib/css/CssParser.js +24 -15
  57. package/lib/css/walkCssTokens.js +1 -1
  58. package/lib/debug/ProfilingPlugin.js +1 -1
  59. package/lib/dependencies/ContextElementDependency.js +2 -2
  60. package/lib/dependencies/CssExportDependency.js +2 -2
  61. package/lib/dependencies/CssLocalIdentifierDependency.js +9 -2
  62. package/lib/dependencies/CssUrlDependency.js +5 -4
  63. package/lib/dependencies/ExportsInfoDependency.js +1 -1
  64. package/lib/dependencies/ExternalModuleDependency.js +4 -2
  65. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +2 -2
  66. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -2
  67. package/lib/dependencies/HarmonyImportDependency.js +2 -2
  68. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +41 -18
  69. package/lib/dependencies/HarmonyImportSideEffectDependency.js +2 -2
  70. package/lib/dependencies/HarmonyImportSpecifierDependency.js +43 -32
  71. package/lib/dependencies/ImportDependency.js +2 -2
  72. package/lib/dependencies/ImportEagerDependency.js +2 -2
  73. package/lib/dependencies/ImportMetaPlugin.js +1 -1
  74. package/lib/dependencies/ImportParserPlugin.js +3 -1
  75. package/lib/dependencies/ImportWeakDependency.js +2 -2
  76. package/lib/dependencies/LoaderPlugin.js +2 -2
  77. package/lib/dependencies/ModuleDependency.js +2 -2
  78. package/lib/dependencies/PureExpressionDependency.js +63 -49
  79. package/lib/dependencies/WorkerDependency.js +1 -1
  80. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +90 -2
  81. package/lib/hmr/LazyCompilationPlugin.js +2 -2
  82. package/lib/ids/ChunkModuleIdRangePlugin.js +1 -1
  83. package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
  84. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  85. package/lib/ids/IdHelpers.js +6 -6
  86. package/lib/ids/NamedChunkIdsPlugin.js +1 -1
  87. package/lib/ids/NamedModuleIdsPlugin.js +1 -1
  88. package/lib/ids/SyncModuleIdsPlugin.js +2 -2
  89. package/lib/index.js +11 -0
  90. package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
  91. package/lib/javascript/JavascriptGenerator.js +0 -1
  92. package/lib/javascript/JavascriptModulesPlugin.js +174 -17
  93. package/lib/javascript/JavascriptParser.js +37 -16
  94. package/lib/library/AbstractLibraryPlugin.js +2 -2
  95. package/lib/library/AmdLibraryPlugin.js +2 -2
  96. package/lib/library/AssignLibraryPlugin.js +3 -3
  97. package/lib/library/ExportPropertyLibraryPlugin.js +2 -2
  98. package/lib/library/JsonpLibraryPlugin.js +2 -2
  99. package/lib/library/ModuleLibraryPlugin.js +2 -2
  100. package/lib/library/SystemLibraryPlugin.js +2 -2
  101. package/lib/library/UmdLibraryPlugin.js +33 -12
  102. package/lib/logging/createConsoleLogger.js +2 -2
  103. package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
  104. package/lib/node/NodeEnvironmentPlugin.js +1 -1
  105. package/lib/node/NodeTemplatePlugin.js +1 -1
  106. package/lib/node/ReadFileCompileWasmPlugin.js +1 -1
  107. package/lib/node/nodeConsole.js +1 -1
  108. package/lib/optimize/AggressiveMergingPlugin.js +1 -1
  109. package/lib/optimize/ConcatenatedModule.js +11 -76
  110. package/lib/optimize/InnerGraph.js +1 -1
  111. package/lib/optimize/LimitChunkCountPlugin.js +1 -2
  112. package/lib/optimize/ModuleConcatenationPlugin.js +1 -1
  113. package/lib/optimize/RealContentHashPlugin.js +3 -3
  114. package/lib/optimize/SideEffectsFlagPlugin.js +2 -2
  115. package/lib/optimize/SplitChunksPlugin.js +8 -8
  116. package/lib/performance/SizeLimitsPlugin.js +2 -2
  117. package/lib/rules/ObjectMatcherRulePlugin.js +11 -1
  118. package/lib/rules/RuleSetCompiler.js +9 -7
  119. package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
  120. package/lib/runtime/StartupChunkDependenciesPlugin.js +1 -1
  121. package/lib/schemes/HttpUriPlugin.js +1 -1
  122. package/lib/serialization/BinaryMiddleware.js +4 -4
  123. package/lib/serialization/FileMiddleware.js +3 -3
  124. package/lib/serialization/NullPrototypeObjectSerializer.js +2 -2
  125. package/lib/serialization/ObjectMiddleware.js +6 -5
  126. package/lib/serialization/PlainObjectSerializer.js +2 -2
  127. package/lib/serialization/SerializerMiddleware.js +2 -2
  128. package/lib/serialization/SingleItemMiddleware.js +2 -2
  129. package/lib/serialization/types.js +1 -1
  130. package/lib/sharing/ConsumeSharedModule.js +1 -1
  131. package/lib/sharing/ProvideSharedPlugin.js +1 -1
  132. package/lib/sharing/resolveMatchedConfigs.js +1 -1
  133. package/lib/stats/DefaultStatsFactoryPlugin.js +20 -20
  134. package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
  135. package/lib/stats/StatsFactory.js +2 -2
  136. package/lib/stats/StatsPrinter.js +6 -6
  137. package/lib/util/ArrayQueue.js +14 -21
  138. package/lib/util/AsyncQueue.js +1 -1
  139. package/lib/util/Queue.js +8 -2
  140. package/lib/util/SortableSet.js +16 -4
  141. package/lib/util/TupleQueue.js +8 -2
  142. package/lib/util/WeakTupleMap.js +3 -3
  143. package/lib/util/binarySearchBounds.js +1 -1
  144. package/lib/util/cleverMerge.js +2 -2
  145. package/lib/util/comparators.js +4 -2
  146. package/lib/util/conventions.js +1 -1
  147. package/lib/util/createHash.js +3 -5
  148. package/lib/util/deprecation.js +3 -3
  149. package/lib/util/deterministicGrouping.js +2 -2
  150. package/lib/util/findGraphRoots.js +1 -1
  151. package/lib/util/fs.js +15 -15
  152. package/lib/util/identifier.js +5 -5
  153. package/lib/util/mergeScope.js +79 -0
  154. package/lib/util/runtime.js +2 -17
  155. package/lib/util/semver.js +3 -0
  156. package/lib/util/smartGrouping.js +3 -3
  157. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +4 -2
  158. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
  159. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
  160. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +1 -1
  161. package/lib/wasm-sync/WebAssemblyGenerator.js +17 -17
  162. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
  163. package/lib/wasm-sync/WebAssemblyUtils.js +2 -1
  164. package/lib/web/FetchCompileWasmPlugin.js +1 -1
  165. package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
  166. package/lib/webpack.js +12 -3
  167. package/package.json +20 -18
  168. package/schemas/WebpackOptions.check.js +1 -1
  169. package/schemas/WebpackOptions.json +30 -2
  170. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
  171. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  172. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  173. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  174. package/types.d.ts +213 -81
@@ -89,7 +89,7 @@ const memoize = require("./util/memoize");
89
89
  /** @typedef {UnsafeCacheData & { parser: undefined | Parser, parserOptions: undefined | ParserOptions, generator: undefined | Generator, generatorOptions: undefined | GeneratorOptions }} NormalModuleUnsafeCacheData */
90
90
 
91
91
  /**
92
- * @typedef {Object} SourceMap
92
+ * @typedef {object} SourceMap
93
93
  * @property {number} version
94
94
  * @property {string[]} sources
95
95
  * @property {string} mappings
@@ -107,7 +107,7 @@ const getValidate = memoize(() => require("schema-utils").validate);
107
107
  const ABSOLUTE_PATH_REGEX = /^([a-zA-Z]:\\|\\\\|\/)/;
108
108
 
109
109
  /**
110
- * @typedef {Object} LoaderItem
110
+ * @typedef {object} LoaderItem
111
111
  * @property {string} loader
112
112
  * @property {any} options
113
113
  * @property {string?} ident
@@ -117,7 +117,7 @@ const ABSOLUTE_PATH_REGEX = /^([a-zA-Z]:\\|\\\\|\/)/;
117
117
  /**
118
118
  * @param {string} context absolute context path
119
119
  * @param {string} source a source path
120
- * @param {Object=} associatedObjectForCache an object to which the cache will be attached
120
+ * @param {object=} associatedObjectForCache an object to which the cache will be attached
121
121
  * @returns {string} new source path
122
122
  */
123
123
  const contextifySourceUrl = (context, source, associatedObjectForCache) => {
@@ -132,7 +132,7 @@ const contextifySourceUrl = (context, source, associatedObjectForCache) => {
132
132
  /**
133
133
  * @param {string} context absolute context path
134
134
  * @param {SourceMap} sourceMap a source map
135
- * @param {Object=} associatedObjectForCache an object to which the cache will be attached
135
+ * @param {object=} associatedObjectForCache an object to which the cache will be attached
136
136
  * @returns {SourceMap} new source map
137
137
  */
138
138
  const contextifySourceMap = (context, sourceMap, associatedObjectForCache) => {
@@ -199,7 +199,7 @@ makeSerializable(
199
199
  );
200
200
 
201
201
  /**
202
- * @typedef {Object} NormalModuleCompilationHooks
202
+ * @typedef {object} NormalModuleCompilationHooks
203
203
  * @property {SyncHook<[object, NormalModule]>} loader
204
204
  * @property {SyncHook<[LoaderItem[], NormalModule, object]>} beforeLoaders
205
205
  * @property {SyncHook<[NormalModule]>} beforeParse
@@ -210,7 +210,7 @@ makeSerializable(
210
210
  */
211
211
 
212
212
  /**
213
- * @typedef {Object} NormalModuleCreateData
213
+ * @typedef {object} NormalModuleCreateData
214
214
  * @property {string=} layer an optional layer in which the module is
215
215
  * @property {JavaScriptModuleTypes | ""} type module type. When deserializing, this is set to an empty string "".
216
216
  * @property {string} request request string
@@ -344,12 +344,12 @@ class NormalModule extends Module {
344
344
  /**
345
345
  * @private
346
346
  * @type {Map<string, number> | undefined}
347
- **/
347
+ */
348
348
  this._sourceSizes = undefined;
349
349
  /**
350
350
  * @private
351
351
  * @type {undefined | SourceTypes}
352
- **/
352
+ */
353
353
  this._sourceTypes = undefined;
354
354
 
355
355
  // Cache
@@ -499,7 +499,7 @@ class NormalModule extends Module {
499
499
  * @param {string} name the asset name
500
500
  * @param {string | Buffer} content the content
501
501
  * @param {(string | SourceMap)=} sourceMap an optional source map
502
- * @param {Object=} associatedObjectForCache object for caching
502
+ * @param {object=} associatedObjectForCache object for caching
503
503
  * @returns {Source} the created source
504
504
  */
505
505
  createSourceForAsset(
@@ -776,7 +776,7 @@ class NormalModule extends Module {
776
776
  * @param {string} context the compilation context
777
777
  * @param {string | Buffer} content the content
778
778
  * @param {(string | SourceMapSource)=} sourceMap an optional source map
779
- * @param {Object=} associatedObjectForCache object for caching
779
+ * @param {object=} associatedObjectForCache object for caching
780
780
  * @returns {Source} the created source
781
781
  */
782
782
  createSource(context, content, sourceMap, associatedObjectForCache) {
@@ -1327,7 +1327,6 @@ class NormalModule extends Module {
1327
1327
  moduleGraph,
1328
1328
  chunkGraph,
1329
1329
  runtime,
1330
- runtimes,
1331
1330
  concatenationScope,
1332
1331
  codeGenerationResults,
1333
1332
  sourceTypes
@@ -1361,7 +1360,6 @@ class NormalModule extends Module {
1361
1360
  chunkGraph,
1362
1361
  runtimeRequirements,
1363
1362
  runtime,
1364
- runtimes,
1365
1363
  concatenationScope,
1366
1364
  codeGenerationResults,
1367
1365
  getData,
@@ -56,7 +56,7 @@ const {
56
56
  /** @typedef {Partial<NormalModuleCreateData & {settings: ModuleSettings}>} CreateData */
57
57
 
58
58
  /**
59
- * @typedef {Object} ResolveData
59
+ * @typedef {object} ResolveData
60
60
  * @property {ModuleFactoryCreateData["contextInfo"]} contextInfo
61
61
  * @property {ModuleFactoryCreateData["resolveOptions"]} resolveOptions
62
62
  * @property {string} context
@@ -72,7 +72,7 @@ const {
72
72
  */
73
73
 
74
74
  /**
75
- * @typedef {Object} ResourceData
75
+ * @typedef {object} ResourceData
76
76
  * @property {string} resource
77
77
  * @property {string=} path
78
78
  * @property {string=} query
@@ -83,7 +83,7 @@ const {
83
83
  /** @typedef {ResourceData & { data: Record<string, any> }} ResourceDataWithData */
84
84
 
85
85
  /**
86
- * @typedef {Object} ParsedLoaderRequest
86
+ * @typedef {object} ParsedLoaderRequest
87
87
  * @property {string} loader loader
88
88
  * @property {string|undefined} options options
89
89
  */
@@ -227,7 +227,16 @@ const ruleSetCompiler = new RuleSetCompiler([
227
227
  new BasicMatcherRulePlugin("issuer"),
228
228
  new BasicMatcherRulePlugin("compiler"),
229
229
  new BasicMatcherRulePlugin("issuerLayer"),
230
- new ObjectMatcherRulePlugin("assert", "assertions"),
230
+ new ObjectMatcherRulePlugin(
231
+ "assert",
232
+ "assertions",
233
+ value => value && /** @type {any} */ (value)._isLegacyAssert !== undefined
234
+ ),
235
+ new ObjectMatcherRulePlugin(
236
+ "with",
237
+ "assertions",
238
+ value => value && !(/** @type {any} */ (value)._isLegacyAssert)
239
+ ),
231
240
  new ObjectMatcherRulePlugin("descriptionData"),
232
241
  new BasicEffectRulePlugin("type"),
233
242
  new BasicEffectRulePlugin("sideEffects"),
@@ -240,12 +249,12 @@ const ruleSetCompiler = new RuleSetCompiler([
240
249
 
241
250
  class NormalModuleFactory extends ModuleFactory {
242
251
  /**
243
- * @param {Object} param params
252
+ * @param {object} param params
244
253
  * @param {string=} param.context context
245
254
  * @param {InputFileSystem} param.fs file system
246
255
  * @param {ResolverFactory} param.resolverFactory resolverFactory
247
256
  * @param {ModuleOptions} param.options options
248
- * @param {Object=} param.associatedObjectForCache an object to which the cache will be attached
257
+ * @param {object=} param.associatedObjectForCache an object to which the cache will be attached
249
258
  * @param {boolean=} param.layers enable layers
250
259
  */
251
260
  constructor({
@@ -308,9 +317,9 @@ class NormalModuleFactory extends ModuleFactory {
308
317
  this.fs = fs;
309
318
  this._globalParserOptions = options.parser;
310
319
  this._globalGeneratorOptions = options.generator;
311
- /** @type {Map<string, WeakMap<Object, Parser>>} */
320
+ /** @type {Map<string, WeakMap<object, Parser>>} */
312
321
  this.parserCache = new Map();
313
- /** @type {Map<string, WeakMap<Object, Generator>>} */
322
+ /** @type {Map<string, WeakMap<object, Generator>>} */
314
323
  this.generatorCache = new Map();
315
324
  /** @type {Set<Module>} */
316
325
  this._restoredUnsafeCacheEntries = new Set();
package/lib/Parser.js CHANGED
@@ -11,7 +11,7 @@
11
11
  /** @typedef {Record<string, any>} PreparsedAst */
12
12
 
13
13
  /**
14
- * @typedef {Object} ParserStateBase
14
+ * @typedef {object} ParserStateBase
15
15
  * @property {string | Buffer} source
16
16
  * @property {NormalModule} current
17
17
  * @property {NormalModule} module
@@ -0,0 +1,39 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Authors Ivan Kopeykin @vankop
4
+ */
5
+
6
+ "use strict";
7
+
8
+ /** @typedef {import("./Compiler")} Compiler */
9
+ /** @typedef {import("./config/target").PlatformTargetProperties} PlatformTargetProperties */
10
+
11
+ /**
12
+ * Should be used only for "target === false" or
13
+ * when you want to overwrite platform target properties
14
+ */
15
+ class PlatformPlugin {
16
+ /**
17
+ * @param {Partial<PlatformTargetProperties>} platform target properties
18
+ */
19
+ constructor(platform) {
20
+ /** @type {Partial<PlatformTargetProperties>} */
21
+ this.platform = platform;
22
+ }
23
+
24
+ /**
25
+ * Apply the plugin
26
+ * @param {Compiler} compiler the compiler instance
27
+ * @returns {void}
28
+ */
29
+ apply(compiler) {
30
+ compiler.hooks.environment.tap("PlatformPlugin", () => {
31
+ compiler.platform = {
32
+ ...compiler.platform,
33
+ ...this.platform
34
+ };
35
+ });
36
+ }
37
+ }
38
+
39
+ module.exports = PlatformPlugin;
@@ -21,7 +21,7 @@ const { contextify } = require("./util/identifier");
21
21
  /** @typedef {import("./logging/Logger").Logger} Logger */
22
22
 
23
23
  /**
24
- * @typedef {Object} CountsData
24
+ * @typedef {object} CountsData
25
25
  * @property {number} modulesCount modules count
26
26
  * @property {number} dependenciesCount dependencies count
27
27
  */
@@ -13,28 +13,28 @@ const identifierUtils = require("./util/identifier");
13
13
  /** @typedef {import("./Module")} Module */
14
14
 
15
15
  /**
16
- * @typedef {Object} RecordsChunks
16
+ * @typedef {object} RecordsChunks
17
17
  * @property {Record<string, number>=} byName
18
18
  * @property {Record<string, number>=} bySource
19
19
  * @property {number[]=} usedIds
20
20
  */
21
21
 
22
22
  /**
23
- * @typedef {Object} RecordsModules
23
+ * @typedef {object} RecordsModules
24
24
  * @property {Record<string, number>=} byIdentifier
25
25
  * @property {Record<string, number>=} bySource
26
26
  * @property {number[]=} usedIds
27
27
  */
28
28
 
29
29
  /**
30
- * @typedef {Object} Records
30
+ * @typedef {object} Records
31
31
  * @property {RecordsChunks=} chunks
32
32
  * @property {RecordsModules=} modules
33
33
  */
34
34
 
35
35
  class RecordIdsPlugin {
36
36
  /**
37
- * @param {Object} options Options object
37
+ * @param {object} options Options object
38
38
  * @param {boolean=} options.portableIds true, when ids need to be portable
39
39
  */
40
40
  constructor(options) {
@@ -22,7 +22,7 @@ const {
22
22
 
23
23
  /** @typedef {WebpackResolveOptions & {dependencyType?: string, resolveToContext?: boolean }} ResolveOptionsWithDependencyType */
24
24
  /**
25
- * @typedef {Object} WithOptions
25
+ * @typedef {object} WithOptions
26
26
  * @property {function(Partial<ResolveOptionsWithDependencyType>): ResolverWithOptions} withOptions create a resolver with additional/different options
27
27
  */
28
28
 
@@ -68,8 +68,8 @@ const convertToResolveOptions = resolveOptionsWithDepType => {
68
68
  };
69
69
 
70
70
  /**
71
- * @typedef {Object} ResolverCache
72
- * @property {WeakMap<Object, ResolverWithOptions>} direct
71
+ * @typedef {object} ResolverCache
72
+ * @property {WeakMap<object, ResolverWithOptions>} direct
73
73
  * @property {Map<string, ResolverWithOptions>} stringified
74
74
  */
75
75
 
@@ -151,6 +151,11 @@ class RuntimeTemplate {
151
151
  .templateLiteral;
152
152
  }
153
153
 
154
+ supportNodePrefixForCoreModules() {
155
+ return /** @type {Environment} */ (this.outputOptions.environment)
156
+ .nodePrefixForCoreModules;
157
+ }
158
+
154
159
  /**
155
160
  * @param {string} returnValue return value
156
161
  * @param {string} args arguments
@@ -389,7 +394,7 @@ class RuntimeTemplate {
389
394
  }
390
395
 
391
396
  /**
392
- * @param {Object} options options object
397
+ * @param {object} options options object
393
398
  * @param {ChunkGraph} options.chunkGraph the chunk graph
394
399
  * @param {Module} options.module the module
395
400
  * @param {string=} options.request the request that should be printed as comment
@@ -426,7 +431,7 @@ class RuntimeTemplate {
426
431
  }
427
432
 
428
433
  /**
429
- * @param {Object} options options object
434
+ * @param {object} options options object
430
435
  * @param {Module} options.module the module
431
436
  * @param {ChunkGraph} options.chunkGraph the chunk graph
432
437
  * @param {string=} options.request the request that should be printed as comment
@@ -455,7 +460,7 @@ class RuntimeTemplate {
455
460
  }
456
461
 
457
462
  /**
458
- * @param {Object} options options object
463
+ * @param {object} options options object
459
464
  * @param {Module | null} options.module the module
460
465
  * @param {ChunkGraph} options.chunkGraph the chunk graph
461
466
  * @param {string=} options.request the request that should be printed as comment
@@ -498,7 +503,7 @@ class RuntimeTemplate {
498
503
  }
499
504
 
500
505
  /**
501
- * @param {Object} options options object
506
+ * @param {object} options options object
502
507
  * @param {Module | null} options.module the module
503
508
  * @param {ChunkGraph} options.chunkGraph the chunk graph
504
509
  * @param {string} options.request the request that should be printed as comment
@@ -517,7 +522,7 @@ class RuntimeTemplate {
517
522
  }
518
523
 
519
524
  /**
520
- * @param {Object} options options object
525
+ * @param {object} options options object
521
526
  * @param {Module} options.module the module
522
527
  * @param {ChunkGraph} options.chunkGraph the chunk graph
523
528
  * @param {string} options.request the request that should be printed as comment
@@ -586,7 +591,7 @@ class RuntimeTemplate {
586
591
  }
587
592
 
588
593
  /**
589
- * @param {Object} options options object
594
+ * @param {object} options options object
590
595
  * @param {ChunkGraph} options.chunkGraph the chunk graph
591
596
  * @param {AsyncDependenciesBlock=} options.block the current dependencies block
592
597
  * @param {Module} options.module the module
@@ -736,7 +741,7 @@ class RuntimeTemplate {
736
741
  }
737
742
 
738
743
  /**
739
- * @param {Object} options options object
744
+ * @param {object} options options object
740
745
  * @param {ChunkGraph} options.chunkGraph the chunk graph
741
746
  * @param {RuntimeSpec=} options.runtime runtime for which this code will be generated
742
747
  * @param {RuntimeSpec | boolean=} options.runtimeCondition only execute the statement in some runtimes
@@ -774,7 +779,7 @@ class RuntimeTemplate {
774
779
 
775
780
  /**
776
781
  *
777
- * @param {Object} options options object
782
+ * @param {object} options options object
778
783
  * @param {boolean=} options.update whether a new variable should be created or the existing one updated
779
784
  * @param {Module} options.module the module
780
785
  * @param {ChunkGraph} options.chunkGraph the chunk graph
@@ -851,7 +856,7 @@ class RuntimeTemplate {
851
856
  }
852
857
 
853
858
  /**
854
- * @param {Object} options options
859
+ * @param {object} options options
855
860
  * @param {ModuleGraph} options.moduleGraph the module graph
856
861
  * @param {Module} options.module the module
857
862
  * @param {string} options.request the request
@@ -974,7 +979,7 @@ class RuntimeTemplate {
974
979
  }
975
980
 
976
981
  /**
977
- * @param {Object} options options
982
+ * @param {object} options options
978
983
  * @param {AsyncDependenciesBlock | undefined} options.block the async block
979
984
  * @param {string} options.message the message
980
985
  * @param {ChunkGraph} options.chunkGraph the chunk graph
@@ -1041,7 +1046,7 @@ class RuntimeTemplate {
1041
1046
  }
1042
1047
 
1043
1048
  /**
1044
- * @param {Object} options options
1049
+ * @param {object} options options
1045
1050
  * @param {AsyncDependenciesBlock} options.block the async block
1046
1051
  * @param {ChunkGraph} options.chunkGraph the chunk graph
1047
1052
  * @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
@@ -1073,7 +1078,7 @@ class RuntimeTemplate {
1073
1078
  }
1074
1079
 
1075
1080
  /**
1076
- * @param {Object} options options
1081
+ * @param {object} options options
1077
1082
  * @param {Dependency} options.dependency the dependency
1078
1083
  * @param {ChunkGraph} options.chunkGraph the chunk graph
1079
1084
  * @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
@@ -1094,7 +1099,7 @@ class RuntimeTemplate {
1094
1099
  }
1095
1100
 
1096
1101
  /**
1097
- * @param {Object} options options
1102
+ * @param {object} options options
1098
1103
  * @param {string} options.exportsArgument the name of the exports object
1099
1104
  * @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
1100
1105
  * @returns {string} statement
@@ -1106,14 +1111,13 @@ class RuntimeTemplate {
1106
1111
  }
1107
1112
 
1108
1113
  /**
1109
- * @param {Object} options options object
1114
+ * @param {object} options options object
1110
1115
  * @param {Module} options.module the module
1111
- * @param {string} options.publicPath the public path
1112
1116
  * @param {RuntimeSpec=} options.runtime runtime
1113
1117
  * @param {CodeGenerationResults} options.codeGenerationResults the code generation results
1114
1118
  * @returns {string} the url of the asset
1115
1119
  */
1116
- assetUrl({ publicPath, runtime, module, codeGenerationResults }) {
1120
+ assetUrl({ runtime, module, codeGenerationResults }) {
1117
1121
  if (!module) {
1118
1122
  return "data:,";
1119
1123
  }
@@ -1123,8 +1127,8 @@ class RuntimeTemplate {
1123
1127
  );
1124
1128
  const url = data.get("url");
1125
1129
  if (url) return url.toString();
1126
- const filename = data.get("filename");
1127
- return publicPath + filename;
1130
+ const assetPath = data.get("assetPathForCss");
1131
+ return assetPath;
1128
1132
  }
1129
1133
  }
1130
1134
 
package/lib/Stats.js CHANGED
@@ -35,7 +35,7 @@ class Stats {
35
35
  */
36
36
  hasWarnings() {
37
37
  return (
38
- this.compilation.warnings.length > 0 ||
38
+ this.compilation.getWarnings().length > 0 ||
39
39
  this.compilation.children.some(child => child.getStats().hasWarnings())
40
40
  );
41
41
  }
package/lib/Template.js CHANGED
@@ -41,7 +41,7 @@ const PATH_NAME_NORMALIZE_REPLACE_REGEX = /[^a-zA-Z0-9_!§$()=\-^°]+/g;
41
41
  const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
42
42
 
43
43
  /**
44
- * @typedef {Object} RenderManifestOptions
44
+ * @typedef {object} RenderManifestOptions
45
45
  * @property {Chunk} chunk the chunk used to render
46
46
  * @property {string} hash
47
47
  * @property {string} fullHash
@@ -57,7 +57,7 @@ const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
57
57
  /** @typedef {RenderManifestEntryTemplated | RenderManifestEntryStatic} RenderManifestEntry */
58
58
 
59
59
  /**
60
- * @typedef {Object} RenderManifestEntryTemplated
60
+ * @typedef {object} RenderManifestEntryTemplated
61
61
  * @property {function(): Source} render
62
62
  * @property {string | function(PathData, AssetInfo=): string} filenameTemplate
63
63
  * @property {PathData=} pathOptions
@@ -68,7 +68,7 @@ const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
68
68
  */
69
69
 
70
70
  /**
71
- * @typedef {Object} RenderManifestEntryStatic
71
+ * @typedef {object} RenderManifestEntryStatic
72
72
  * @property {function(): Source} render
73
73
  * @property {string} filename
74
74
  * @property {AssetInfo} info
@@ -78,7 +78,7 @@ const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
78
78
  */
79
79
 
80
80
  /**
81
- * @typedef {Object} HasId
81
+ * @typedef {object} HasId
82
82
  * @property {number | string} id
83
83
  */
84
84
 
@@ -252,7 +252,7 @@ class Template {
252
252
  }
253
253
 
254
254
  /**
255
- * @typedef {Object} WithId
255
+ * @typedef {object} WithId
256
256
  * @property {string|number} id
257
257
  */
258
258
 
@@ -37,7 +37,22 @@ const prepareId = id => {
37
37
  return id.replace(/(^[.-]|[^a-zA-Z0-9_-])+/g, "_");
38
38
  };
39
39
 
40
+ /**
41
+ * @callback ReplacerFunction
42
+ * @param {string} match
43
+ * @param {string | undefined} arg
44
+ * @param {string} input
45
+ */
46
+
47
+ /**
48
+ * @param {ReplacerFunction} replacer replacer
49
+ * @param {((arg0: number) => string) | undefined} handler handler
50
+ * @param {AssetInfo | undefined} assetInfo asset info
51
+ * @param {string} hashName hash name
52
+ * @returns {ReplacerFunction} hash replacer function
53
+ */
40
54
  const hashLength = (replacer, handler, assetInfo, hashName) => {
55
+ /** @type {ReplacerFunction} */
41
56
  const fn = (match, arg, input) => {
42
57
  let result;
43
58
  const length = arg && parseInt(arg, 10);
@@ -117,7 +132,7 @@ const deprecated = (fn, message, code) => {
117
132
  /**
118
133
  * @param {string | function(PathData, AssetInfo=): string} path the raw path
119
134
  * @param {PathData} data context data
120
- * @param {AssetInfo} assetInfo extra info about the asset (will be written to)
135
+ * @param {AssetInfo | undefined} assetInfo extra info about the asset (will be written to)
121
136
  * @returns {string} the interpolated path
122
137
  */
123
138
  const replacePathVariables = (path, data, assetInfo) => {
@@ -12,6 +12,7 @@ const ConcatenationScope = require("../ConcatenationScope");
12
12
  const Generator = require("../Generator");
13
13
  const { ASSET_MODULE_TYPE } = require("../ModuleTypeConstants");
14
14
  const RuntimeGlobals = require("../RuntimeGlobals");
15
+ const CssUrlDependency = require("../dependencies/CssUrlDependency");
15
16
  const createHash = require("../util/createHash");
16
17
  const { makePathsRelative } = require("../util/identifier");
17
18
  const nonNumericOnlyHash = require("../util/nonNumericOnlyHash");
@@ -321,6 +322,7 @@ class AssetGenerator extends Generator {
321
322
  }
322
323
  );
323
324
  let assetPath;
325
+ let assetPathForCss;
324
326
  if (this.publicPath !== undefined) {
325
327
  const { path, info } =
326
328
  runtimeTemplate.compilation.getAssetPathWithInfo(
@@ -335,12 +337,24 @@ class AssetGenerator extends Generator {
335
337
  );
336
338
  assetInfo = mergeAssetInfo(assetInfo, info);
337
339
  assetPath = JSON.stringify(path + filename);
340
+ assetPathForCss = path + filename;
338
341
  } else {
339
342
  runtimeRequirements.add(RuntimeGlobals.publicPath); // add __webpack_require__.p
340
343
  assetPath = runtimeTemplate.concatenation(
341
344
  { expr: RuntimeGlobals.publicPath },
342
345
  filename
343
346
  );
347
+ const compilation = runtimeTemplate.compilation;
348
+ const path =
349
+ compilation.outputOptions.publicPath === "auto"
350
+ ? CssUrlDependency.PUBLIC_PATH_AUTO
351
+ : compilation.getAssetPath(
352
+ compilation.outputOptions.publicPath,
353
+ {
354
+ hash: compilation.hash
355
+ }
356
+ );
357
+ assetPathForCss = path + filename;
344
358
  }
345
359
  assetInfo = {
346
360
  sourceFilename,
@@ -371,6 +385,7 @@ class AssetGenerator extends Generator {
371
385
  data.set("fullContentHash", fullHash);
372
386
  data.set("filename", filename);
373
387
  data.set("assetInfo", assetInfo);
388
+ data.set("assetPathForCss", assetPathForCss);
374
389
  }
375
390
  content = assetPath;
376
391
  }
@@ -25,7 +25,7 @@ const { getEntryRuntime, mergeRuntime } = require("./util/runtime");
25
25
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
26
26
 
27
27
  /**
28
- * @typedef {Object} QueueItem
28
+ * @typedef {object} QueueItem
29
29
  * @property {number} action
30
30
  * @property {DependenciesBlock} block
31
31
  * @property {Module} module
@@ -35,7 +35,7 @@ const { getEntryRuntime, mergeRuntime } = require("./util/runtime");
35
35
  */
36
36
 
37
37
  /**
38
- * @typedef {Object} ChunkGroupInfo
38
+ * @typedef {object} ChunkGroupInfo
39
39
  * @property {ChunkGroup} chunkGroup the chunk group
40
40
  * @property {RuntimeSpec} runtime the runtimes
41
41
  * @property {bigint | undefined} minAvailableModules current minimal set of modules available at this point
@@ -53,7 +53,7 @@ const { getEntryRuntime, mergeRuntime } = require("./util/runtime");
53
53
  */
54
54
 
55
55
  /**
56
- * @typedef {Object} BlockChunkGroupConnection
56
+ * @typedef {object} BlockChunkGroupConnection
57
57
  * @property {ChunkGroupInfo} originChunkGroupInfo origin chunk group
58
58
  * @property {ChunkGroup} chunkGroup referenced chunk group
59
59
  */
@@ -14,7 +14,7 @@ const Cache = require("../Cache");
14
14
 
15
15
  class MemoryWithGcCachePlugin {
16
16
  /**
17
- * @param {Object} options Options
17
+ * @param {object} options Options
18
18
  * @param {number} options.maxGenerations max generations
19
19
  */
20
20
  constructor({ maxGenerations }) {
@@ -34,7 +34,7 @@ const {
34
34
 
35
35
  class PackContainer {
36
36
  /**
37
- * @param {Object} data stored data
37
+ * @param {object} data stored data
38
38
  * @param {string} version version identifier
39
39
  * @param {Snapshot} buildSnapshot snapshot of all build dependencies
40
40
  * @param {BuildDependencies} buildDependencies list of all unresolved build dependencies captured
@@ -1027,7 +1027,7 @@ const allowCollectingMemory = buf => {
1027
1027
 
1028
1028
  class PackFileCacheStrategy {
1029
1029
  /**
1030
- * @param {Object} options options
1030
+ * @param {object} options options
1031
1031
  * @param {Compiler} options.compiler the compiler
1032
1032
  * @param {IntermediateFileSystem} options.fs the filesystem
1033
1033
  * @param {string} options.context the context directory
@@ -50,7 +50,7 @@ const addAllToSet = (set, otherSet) => {
50
50
  };
51
51
 
52
52
  /**
53
- * @param {Object} object an object
53
+ * @param {object} object an object
54
54
  * @param {boolean} excludeContext if true, context is not included in string
55
55
  * @returns {string} stringified version
56
56
  */
@@ -104,9 +104,9 @@ class ResolverCachePlugin {
104
104
  /**
105
105
  * @param {ItemCacheFacade} itemCache cache
106
106
  * @param {Resolver} resolver the resolver
107
- * @param {Object} resolveContext context for resolving meta info
108
- * @param {Object} request the request info object
109
- * @param {function((Error | null)=, Object=): void} callback callback function
107
+ * @param {object} resolveContext context for resolving meta info
108
+ * @param {object} request the request info object
109
+ * @param {function((Error | null)=, object=): void} callback callback function
110
110
  * @returns {void}
111
111
  */
112
112
  const doRealResolve = (
@@ -188,16 +188,16 @@ class ResolverCachePlugin {
188
188
  };
189
189
  compiler.resolverFactory.hooks.resolver.intercept({
190
190
  factory(type, hook) {
191
- /** @type {Map<string, (function(Error=, Object=): void)[]>} */
191
+ /** @type {Map<string, (function(Error=, object=): void)[]>} */
192
192
  const activeRequests = new Map();
193
- /** @type {Map<string, [function(Error=, Object=): void, function(Error=, Object=): void][]>} */
193
+ /** @type {Map<string, [function(Error=, object=): void, function(Error=, object=): void][]>} */
194
194
  const activeRequestsWithYield = new Map();
195
195
  hook.tap(
196
196
  "ResolverCachePlugin",
197
197
  /**
198
198
  * @param {Resolver} resolver the resolver
199
- * @param {Object} options resolve options
200
- * @param {Object} userOptions resolve options passed by the user
199
+ * @param {object} options resolve options
200
+ * @param {object} userOptions resolve options passed by the user
201
201
  * @returns {void}
202
202
  */
203
203
  (resolver, options, userOptions) => {