webpack 5.103.0 → 5.104.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 (176) hide show
  1. package/hot/dev-server.js +18 -3
  2. package/hot/emitter-event-target.js +7 -0
  3. package/hot/lazy-compilation-node.js +45 -29
  4. package/hot/lazy-compilation-universal.js +18 -0
  5. package/hot/lazy-compilation-web.js +15 -5
  6. package/hot/load-http.js +7 -0
  7. package/hot/only-dev-server.js +19 -4
  8. package/lib/APIPlugin.js +6 -0
  9. package/lib/Chunk.js +1 -1
  10. package/lib/ChunkGraph.js +9 -7
  11. package/lib/ChunkGroup.js +8 -5
  12. package/lib/CleanPlugin.js +6 -3
  13. package/lib/CodeGenerationResults.js +2 -1
  14. package/lib/CompatibilityPlugin.js +3 -0
  15. package/lib/Compilation.js +33 -19
  16. package/lib/Compiler.js +3 -3
  17. package/lib/ContextModule.js +6 -3
  18. package/lib/ContextModuleFactory.js +6 -4
  19. package/lib/DefinePlugin.js +34 -3
  20. package/lib/DelegatedModule.js +7 -4
  21. package/lib/DllModule.js +6 -3
  22. package/lib/DotenvPlugin.js +11 -6
  23. package/lib/ExportsInfo.js +5 -5
  24. package/lib/ExternalModule.js +8 -7
  25. package/lib/ExternalModuleFactoryPlugin.js +1 -1
  26. package/lib/FileSystemInfo.js +1 -1
  27. package/lib/Generator.js +10 -7
  28. package/lib/HookWebpackError.js +33 -4
  29. package/lib/HotModuleReplacementPlugin.js +22 -0
  30. package/lib/ManifestPlugin.js +1 -1
  31. package/lib/Module.js +24 -15
  32. package/lib/ModuleBuildError.js +1 -1
  33. package/lib/ModuleError.js +1 -1
  34. package/lib/ModuleFilenameHelpers.js +1 -1
  35. package/lib/ModuleGraph.js +27 -12
  36. package/lib/ModuleGraphConnection.js +2 -2
  37. package/lib/ModuleSourceTypeConstants.js +189 -0
  38. package/lib/ModuleTypeConstants.js +1 -4
  39. package/lib/ModuleWarning.js +1 -1
  40. package/lib/NodeStuffPlugin.js +52 -42
  41. package/lib/NormalModule.js +6 -4
  42. package/lib/NormalModuleFactory.js +7 -10
  43. package/lib/Parser.js +1 -1
  44. package/lib/RawModule.js +7 -4
  45. package/lib/RuntimeModule.js +1 -1
  46. package/lib/RuntimeTemplate.js +5 -1
  47. package/lib/SourceMapDevToolPlugin.js +6 -1
  48. package/lib/Template.js +17 -6
  49. package/lib/TemplatedPathPlugin.js +5 -6
  50. package/lib/WebpackError.js +0 -1
  51. package/lib/WebpackOptionsApply.js +37 -9
  52. package/lib/asset/AssetBytesGenerator.js +15 -11
  53. package/lib/asset/AssetGenerator.js +30 -24
  54. package/lib/asset/AssetSourceGenerator.js +15 -11
  55. package/lib/asset/RawDataUrlModule.js +6 -3
  56. package/lib/buildChunkGraph.js +4 -2
  57. package/lib/cache/PackFileCacheStrategy.js +6 -5
  58. package/lib/cli.js +2 -43
  59. package/lib/config/browserslistTargetHandler.js +19 -0
  60. package/lib/config/defaults.js +128 -43
  61. package/lib/config/normalization.js +2 -2
  62. package/lib/config/target.js +5 -0
  63. package/lib/container/ContainerEntryModule.js +6 -3
  64. package/lib/container/FallbackModule.js +6 -3
  65. package/lib/container/RemoteModule.js +1 -3
  66. package/lib/css/CssGenerator.js +26 -24
  67. package/lib/css/CssLoadingRuntimeModule.js +12 -4
  68. package/lib/css/CssModulesPlugin.js +29 -74
  69. package/lib/css/CssParser.js +828 -341
  70. package/lib/css/walkCssTokens.js +33 -13
  71. package/lib/dependencies/CachedConstDependency.js +24 -10
  72. package/lib/dependencies/CommonJsRequireContextDependency.js +1 -1
  73. package/lib/dependencies/ContextDependencyHelpers.js +2 -2
  74. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +3 -1
  75. package/lib/dependencies/CssIcssExportDependency.js +242 -104
  76. package/lib/dependencies/CssIcssImportDependency.js +61 -4
  77. package/lib/dependencies/CssIcssSymbolDependency.js +2 -6
  78. package/lib/dependencies/CssImportDependency.js +2 -1
  79. package/lib/dependencies/CssUrlDependency.js +3 -2
  80. package/lib/dependencies/DynamicExports.js +7 -7
  81. package/lib/dependencies/ExternalModuleDependency.js +7 -4
  82. package/lib/dependencies/ExternalModuleInitFragment.js +2 -1
  83. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +2 -1
  84. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -2
  85. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +1 -1
  86. package/lib/dependencies/HarmonyExports.js +4 -4
  87. package/lib/dependencies/HarmonyImportDependency.js +8 -3
  88. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
  89. package/lib/dependencies/ImportMetaPlugin.js +57 -0
  90. package/lib/dependencies/ImportParserPlugin.js +2 -2
  91. package/lib/dependencies/LocalModulesHelpers.js +3 -3
  92. package/lib/dependencies/WorkerPlugin.js +2 -2
  93. package/lib/dependencies/getFunctionExpression.js +1 -1
  94. package/lib/esm/ModuleChunkFormatPlugin.js +5 -4
  95. package/lib/hmr/HotModuleReplacement.runtime.js +2 -1
  96. package/lib/hmr/LazyCompilationPlugin.js +4 -3
  97. package/lib/ids/IdHelpers.js +16 -7
  98. package/lib/javascript/ChunkHelpers.js +1 -1
  99. package/lib/javascript/JavascriptGenerator.js +4 -3
  100. package/lib/javascript/JavascriptModulesPlugin.js +57 -24
  101. package/lib/javascript/JavascriptParser.js +19 -6
  102. package/lib/json/JsonGenerator.js +5 -4
  103. package/lib/json/JsonParser.js +2 -1
  104. package/lib/library/AbstractLibraryPlugin.js +1 -1
  105. package/lib/library/AmdLibraryPlugin.js +4 -1
  106. package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
  107. package/lib/library/ModuleLibraryPlugin.js +41 -13
  108. package/lib/library/SystemLibraryPlugin.js +4 -1
  109. package/lib/library/UmdLibraryPlugin.js +1 -1
  110. package/lib/logging/Logger.js +5 -4
  111. package/lib/logging/createConsoleLogger.js +2 -2
  112. package/lib/optimize/ConcatenatedModule.js +47 -32
  113. package/lib/optimize/ModuleConcatenationPlugin.js +5 -4
  114. package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
  115. package/lib/optimize/SplitChunksPlugin.js +60 -46
  116. package/lib/rules/RuleSetCompiler.js +1 -1
  117. package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -2
  118. package/lib/schemes/HttpUriPlugin.js +78 -7
  119. package/lib/serialization/AggregateErrorSerializer.js +1 -2
  120. package/lib/serialization/ObjectMiddleware.js +0 -2
  121. package/lib/serialization/SingleItemMiddleware.js +1 -1
  122. package/lib/sharing/ConsumeSharedModule.js +1 -1
  123. package/lib/sharing/ConsumeSharedPlugin.js +5 -3
  124. package/lib/sharing/ProvideSharedModule.js +1 -1
  125. package/lib/sharing/resolveMatchedConfigs.js +15 -9
  126. package/lib/sharing/utils.js +1 -1
  127. package/lib/stats/DefaultStatsFactoryPlugin.js +8 -5
  128. package/lib/stats/DefaultStatsPresetPlugin.js +1 -1
  129. package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
  130. package/lib/util/StringXor.js +1 -1
  131. package/lib/util/URLAbsoluteSpecifier.js +2 -2
  132. package/lib/util/binarySearchBounds.js +2 -2
  133. package/lib/util/comparators.js +53 -76
  134. package/lib/util/compileBooleanMatcher.js +78 -6
  135. package/lib/util/createHash.js +20 -199
  136. package/lib/util/deprecation.js +1 -1
  137. package/lib/util/deterministicGrouping.js +6 -3
  138. package/lib/util/fs.js +75 -75
  139. package/lib/util/hash/BatchedHash.js +10 -9
  140. package/lib/util/hash/BulkUpdateHash.js +138 -0
  141. package/lib/util/hash/DebugHash.js +75 -0
  142. package/lib/util/hash/hash-digest.js +216 -0
  143. package/lib/util/identifier.js +82 -17
  144. package/lib/util/internalSerializables.js +2 -6
  145. package/lib/util/runtime.js +3 -3
  146. package/lib/util/source.js +2 -2
  147. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +3 -2
  148. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +3 -2
  149. package/lib/wasm-sync/WebAssemblyGenerator.js +9 -6
  150. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +3 -2
  151. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +6 -2
  152. package/lib/webpack.js +1 -1
  153. package/package.json +29 -25
  154. package/schemas/WebpackOptions.check.js +1 -1
  155. package/schemas/WebpackOptions.json +59 -82
  156. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  157. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  158. package/types.d.ts +225 -157
  159. package/lib/ModuleSourceTypesConstants.js +0 -117
  160. package/lib/dependencies/CssIcssFromIdentifierDependency.js +0 -124
  161. package/lib/dependencies/CssIcssGlobalIdentifierDependency.js +0 -48
  162. package/lib/dependencies/CssIcssLocalIdentifierDependency.js +0 -61
  163. package/lib/dependencies/CssIcssSelfLocalIdentifierDependency.js +0 -190
  164. package/lib/util/jsonParseEvenBetterErrors.js +0 -10
  165. package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +0 -7
  166. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +0 -6
  167. package/schemas/plugins/css/CssAutoGeneratorOptions.json +0 -3
  168. package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +0 -7
  169. package/schemas/plugins/css/CssAutoParserOptions.check.js +0 -6
  170. package/schemas/plugins/css/CssAutoParserOptions.json +0 -3
  171. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +0 -7
  172. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +0 -6
  173. package/schemas/plugins/css/CssGlobalGeneratorOptions.json +0 -3
  174. package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +0 -7
  175. package/schemas/plugins/css/CssGlobalParserOptions.check.js +0 -6
  176. package/schemas/plugins/css/CssGlobalParserOptions.json +0 -3
package/lib/util/fs.js CHANGED
@@ -45,7 +45,7 @@ const path = require("path");
45
45
  */
46
46
 
47
47
  /**
48
- * @typedef {IStatsBase<bigint> & { atimeNs: bigint, mtimeNs: bigint, ctimeNs: bigint, birthtimeNs: bigint }} IBigIntStats
48
+ * @typedef {IStatsBase<bigint> & { atimeNs: bigint, mtimeNs: bigint, ctimeNs: bigint, birthtimeNs: bigint }} IBigIntStats
49
49
  */
50
50
 
51
51
  /**
@@ -137,18 +137,18 @@ const path = require("path");
137
137
 
138
138
  /**
139
139
  * @typedef {{
140
- * (path: PathOrFileDescriptor, options: ({ encoding?: null | undefined, flag?: string | undefined } & import("events").Abortable) | undefined | null, callback: BufferCallback): void;
141
- * (path: PathOrFileDescriptor, options: ({ encoding: BufferEncoding, flag?: string | undefined } & import("events").Abortable) | BufferEncoding, callback: StringCallback): void;
142
- * (path: PathOrFileDescriptor, options: (ObjectEncodingOptions & { flag?: string | undefined } & import("events").Abortable) | BufferEncoding | undefined | null, callback: StringOrBufferCallback): void;
143
- * (path: PathOrFileDescriptor, callback: BufferCallback): void;
140
+ * (path: PathOrFileDescriptor, options: ({ encoding?: null | undefined, flag?: string | undefined } & import("events").Abortable) | undefined | null, callback: BufferCallback): void,
141
+ * (path: PathOrFileDescriptor, options: ({ encoding: BufferEncoding, flag?: string | undefined } & import("events").Abortable) | BufferEncoding, callback: StringCallback): void,
142
+ * (path: PathOrFileDescriptor, options: (ObjectEncodingOptions & { flag?: string | undefined } & import("events").Abortable) | BufferEncoding | undefined | null, callback: StringOrBufferCallback): void,
143
+ * (path: PathOrFileDescriptor, callback: BufferCallback): void,
144
144
  * }} ReadFile
145
145
  */
146
146
 
147
147
  /**
148
148
  * @typedef {{
149
- * (path: PathOrFileDescriptor, options?: { encoding?: null | undefined, flag?: string | undefined } | null): Buffer;
150
- * (path: PathOrFileDescriptor, options: { encoding: BufferEncoding, flag?: string | undefined } | BufferEncoding): string;
151
- * (path: PathOrFileDescriptor, options?: (ObjectEncodingOptions & { flag?: string | undefined }) | BufferEncoding | null): string | Buffer;
149
+ * (path: PathOrFileDescriptor, options?: { encoding?: null | undefined, flag?: string | undefined } | null): Buffer,
150
+ * (path: PathOrFileDescriptor, options: { encoding: BufferEncoding, flag?: string | undefined } | BufferEncoding): string,
151
+ * (path: PathOrFileDescriptor, options?: (ObjectEncodingOptions & { flag?: string | undefined }) | BufferEncoding | null): string | Buffer,
152
152
  * }} ReadFileSync
153
153
  */
154
154
 
@@ -157,7 +157,7 @@ const path = require("path");
157
157
  */
158
158
 
159
159
  /**
160
- * @typedef {'buffer'| { encoding: 'buffer' }} BufferEncodingOption
160
+ * @typedef {"buffer" | { encoding: "buffer" }} BufferEncodingOption
161
161
  */
162
162
 
163
163
  /**
@@ -173,98 +173,98 @@ const path = require("path");
173
173
 
174
174
  /**
175
175
  * @typedef {{
176
- * (path: PathLike, options: EncodingOption, callback: StringCallback): void;
177
- * (path: PathLike, options: BufferEncodingOption, callback: BufferCallback): void;
178
- * (path: PathLike, options: EncodingOption, callback: StringOrBufferCallback): void;
179
- * (path: PathLike, callback: StringCallback): void;
176
+ * (path: PathLike, options: EncodingOption, callback: StringCallback): void,
177
+ * (path: PathLike, options: BufferEncodingOption, callback: BufferCallback): void,
178
+ * (path: PathLike, options: EncodingOption, callback: StringOrBufferCallback): void,
179
+ * (path: PathLike, callback: StringCallback): void,
180
180
  * }} Readlink
181
181
  */
182
182
 
183
183
  /**
184
184
  * @typedef {{
185
- * (path: PathLike, options?: EncodingOption): string;
186
- * (path: PathLike, options: BufferEncodingOption): Buffer;
187
- * (path: PathLike, options?: EncodingOption): string | Buffer;
185
+ * (path: PathLike, options?: EncodingOption): string,
186
+ * (path: PathLike, options: BufferEncodingOption): Buffer,
187
+ * (path: PathLike, options?: EncodingOption): string | Buffer,
188
188
  * }} ReadlinkSync
189
189
  */
190
190
 
191
191
  /**
192
192
  * @typedef {{
193
- * (path: PathLike, options: { encoding: BufferEncoding | null, withFileTypes?: false | undefined, recursive?: boolean | undefined } | BufferEncoding | undefined | null, callback: (err: NodeJS.ErrnoException | null, files?: string[]) => void): void;
194
- * (path: PathLike, options: { encoding: 'buffer', withFileTypes?: false | undefined, recursive?: boolean | undefined } | 'buffer', callback: (err: NodeJS.ErrnoException | null, files?: Buffer[]) => void): void;
195
- * (path: PathLike, options: (ObjectEncodingOptions & { withFileTypes?: false | undefined, recursive?: boolean | undefined }) | BufferEncoding | undefined | null, callback: (err: NodeJS.ErrnoException | null, files?: string[] | Buffer[]) => void): void;
196
- * (path: PathLike, callback: (err: NodeJS.ErrnoException | null, files?: string[]) => void): void;
197
- * (path: PathLike, options: ObjectEncodingOptions & { withFileTypes: true, recursive?: boolean | undefined }, callback: (err: NodeJS.ErrnoException | null, files?: Dirent<string>[]) => void): void;
198
- * (path: PathLike, options: { encoding: 'buffer', withFileTypes: true, recursive?: boolean | undefined }, callback: (err: NodeJS.ErrnoException | null, files: Dirent<Buffer>[]) => void): void;
193
+ * (path: PathLike, options: { encoding: BufferEncoding | null, withFileTypes?: false | undefined, recursive?: boolean | undefined } | BufferEncoding | undefined | null, callback: (err: NodeJS.ErrnoException | null, files?: string[]) => void): void,
194
+ * (path: PathLike, options: { encoding: "buffer", withFileTypes?: false | undefined, recursive?: boolean | undefined } | "buffer", callback: (err: NodeJS.ErrnoException | null, files?: Buffer[]) => void): void,
195
+ * (path: PathLike, options: (ObjectEncodingOptions & { withFileTypes?: false | undefined, recursive?: boolean | undefined }) | BufferEncoding | undefined | null, callback: (err: NodeJS.ErrnoException | null, files?: string[] | Buffer[]) => void): void,
196
+ * (path: PathLike, callback: (err: NodeJS.ErrnoException | null, files?: string[]) => void): void,
197
+ * (path: PathLike, options: ObjectEncodingOptions & { withFileTypes: true, recursive?: boolean | undefined }, callback: (err: NodeJS.ErrnoException | null, files?: Dirent<string>[]) => void): void,
198
+ * (path: PathLike, options: { encoding: "buffer", withFileTypes: true, recursive?: boolean | undefined }, callback: (err: NodeJS.ErrnoException | null, files: Dirent<Buffer>[]) => void): void,
199
199
  * }} Readdir
200
200
  */
201
201
 
202
202
  /**
203
203
  * @typedef {{
204
- * (path: PathLike, options?: { encoding: BufferEncoding | null, withFileTypes?: false | undefined, recursive?: boolean | undefined; } | BufferEncoding | null): string[];
205
- * (path: PathLike, options: { encoding: 'buffer', withFileTypes?: false | undefined, recursive?: boolean | undefined } | 'buffer'): Buffer[];
206
- * (path: PathLike, options?: (ObjectEncodingOptions & { withFileTypes?: false | undefined, recursive?: boolean | undefined }) | BufferEncoding | null): string[] | Buffer[];
207
- * (path: PathLike, options: ObjectEncodingOptions & { withFileTypes: true, recursive?: boolean | undefined }): Dirent[];
208
- * (path: PathLike, options: { encoding: "buffer", withFileTypes: true, recursive?: boolean | undefined }): Dirent<Buffer>[];
204
+ * (path: PathLike, options?: { encoding: BufferEncoding | null, withFileTypes?: false | undefined, recursive?: boolean | undefined; } | BufferEncoding | null): string[],
205
+ * (path: PathLike, options: { encoding: "buffer", withFileTypes?: false | undefined, recursive?: boolean | undefined } | "buffer"): Buffer[],
206
+ * (path: PathLike, options?: (ObjectEncodingOptions & { withFileTypes?: false | undefined, recursive?: boolean | undefined }) | BufferEncoding | null): string[] | Buffer[],
207
+ * (path: PathLike, options: ObjectEncodingOptions & { withFileTypes: true, recursive?: boolean | undefined }): Dirent[],
208
+ * (path: PathLike, options: { encoding: "buffer", withFileTypes: true, recursive?: boolean | undefined }): Dirent<Buffer>[],
209
209
  * }} ReaddirSync
210
210
  */
211
211
 
212
212
  /**
213
213
  * @typedef {{
214
- * (path: PathLike, callback: StatsCallback): void;
215
- * (path: PathLike, options: (StatOptions & { bigint?: false | undefined }) | undefined, callback: StatsCallback): void;
216
- * (path: PathLike, options: StatOptions & { bigint: true }, callback: BigIntStatsCallback): void;
217
- * (path: PathLike, options: StatOptions | undefined, callback: StatsOrBigIntStatsCallback): void;
214
+ * (path: PathLike, callback: StatsCallback): void,
215
+ * (path: PathLike, options: (StatOptions & { bigint?: false | undefined }) | undefined, callback: StatsCallback): void,
216
+ * (path: PathLike, options: StatOptions & { bigint: true }, callback: BigIntStatsCallback): void,
217
+ * (path: PathLike, options: StatOptions | undefined, callback: StatsOrBigIntStatsCallback): void,
218
218
  * }} Stat
219
219
  */
220
220
 
221
221
  /**
222
222
  * @typedef {{
223
- * (path: PathLike, options?: undefined): IStats;
224
- * (path: PathLike, options?: StatSyncOptions & { bigint?: false | undefined, throwIfNoEntry: false }): IStats | undefined;
225
- * (path: PathLike, options: StatSyncOptions & { bigint: true, throwIfNoEntry: false }): IBigIntStats | undefined;
226
- * (path: PathLike, options?: StatSyncOptions & { bigint?: false | undefined }): IStats;
227
- * (path: PathLike, options: StatSyncOptions & { bigint: true }): IBigIntStats;
228
- * (path: PathLike, options: StatSyncOptions & { bigint: boolean, throwIfNoEntry?: false | undefined }): IStats | IBigIntStats;
229
- * (path: PathLike, options?: StatSyncOptions): IStats | IBigIntStats | undefined;
223
+ * (path: PathLike, options?: undefined): IStats,
224
+ * (path: PathLike, options?: StatSyncOptions & { bigint?: false | undefined, throwIfNoEntry: false }): IStats | undefined,
225
+ * (path: PathLike, options: StatSyncOptions & { bigint: true, throwIfNoEntry: false }): IBigIntStats | undefined,
226
+ * (path: PathLike, options?: StatSyncOptions & { bigint?: false | undefined }): IStats,
227
+ * (path: PathLike, options: StatSyncOptions & { bigint: true }): IBigIntStats,
228
+ * (path: PathLike, options: StatSyncOptions & { bigint: boolean, throwIfNoEntry?: false | undefined }): IStats | IBigIntStats,
229
+ * (path: PathLike, options?: StatSyncOptions): IStats | IBigIntStats | undefined,
230
230
  * }} StatSync
231
231
  */
232
232
 
233
233
  /**
234
234
  * @typedef {{
235
- * (path: PathLike, callback: StatsCallback): void;
236
- * (path: PathLike, options: (StatOptions & { bigint?: false | undefined }) | undefined, callback: StatsCallback): void;
237
- * (path: PathLike, options: StatOptions & { bigint: true }, callback: BigIntStatsCallback): void;
238
- * (path: PathLike, options: StatOptions | undefined, callback: StatsOrBigIntStatsCallback): void;
235
+ * (path: PathLike, callback: StatsCallback): void,
236
+ * (path: PathLike, options: (StatOptions & { bigint?: false | undefined }) | undefined, callback: StatsCallback): void,
237
+ * (path: PathLike, options: StatOptions & { bigint: true }, callback: BigIntStatsCallback): void,
238
+ * (path: PathLike, options: StatOptions | undefined, callback: StatsOrBigIntStatsCallback): void,
239
239
  * }} LStat
240
240
  */
241
241
 
242
242
  /**
243
243
  * @typedef {{
244
- * (path: PathLike, options?: undefined): IStats;
245
- * (path: PathLike, options?: StatSyncOptions & { bigint?: false | undefined, throwIfNoEntry: false }): IStats | undefined;
246
- * (path: PathLike, options: StatSyncOptions & { bigint: true, throwIfNoEntry: false }): IBigIntStats | undefined;
247
- * (path: PathLike, options?: StatSyncOptions & { bigint?: false | undefined }): IStats;
248
- * (path: PathLike, options: StatSyncOptions & { bigint: true }): IBigIntStats;
249
- * (path: PathLike, options: StatSyncOptions & { bigint: boolean, throwIfNoEntry?: false | undefined }): IStats | IBigIntStats;
250
- * (path: PathLike, options?: StatSyncOptions): IStats | IBigIntStats | undefined;
244
+ * (path: PathLike, options?: undefined): IStats,
245
+ * (path: PathLike, options?: StatSyncOptions & { bigint?: false | undefined, throwIfNoEntry: false }): IStats | undefined,
246
+ * (path: PathLike, options: StatSyncOptions & { bigint: true, throwIfNoEntry: false }): IBigIntStats | undefined,
247
+ * (path: PathLike, options?: StatSyncOptions & { bigint?: false | undefined }): IStats,
248
+ * (path: PathLike, options: StatSyncOptions & { bigint: true }): IBigIntStats,
249
+ * (path: PathLike, options: StatSyncOptions & { bigint: boolean, throwIfNoEntry?: false | undefined }): IStats | IBigIntStats,
250
+ * (path: PathLike, options?: StatSyncOptions): IStats | IBigIntStats | undefined,
251
251
  * }} LStatSync
252
252
  */
253
253
 
254
254
  /**
255
255
  * @typedef {{
256
- * (path: PathLike, options: EncodingOption, callback: StringCallback): void;
257
- * (path: PathLike, options: BufferEncodingOption, callback: BufferCallback): void;
258
- * (path: PathLike, options: EncodingOption, callback: StringOrBufferCallback): void;
256
+ * (path: PathLike, options: EncodingOption, callback: StringCallback): void,
257
+ * (path: PathLike, options: BufferEncodingOption, callback: BufferCallback): void,
258
+ * (path: PathLike, options: EncodingOption, callback: StringOrBufferCallback): void,
259
259
  * (path: PathLike, callback: StringCallback): void;
260
260
  * }} RealPath
261
261
  */
262
262
 
263
263
  /**
264
264
  * @typedef {{
265
- * (path: PathLike, options?: EncodingOption): string;
266
- * (path: PathLike, options: BufferEncodingOption): Buffer;
267
- * (path: PathLike, options?: EncodingOption): string | Buffer;
265
+ * (path: PathLike, options?: EncodingOption): string,
266
+ * (path: PathLike, options: BufferEncodingOption): Buffer,
267
+ * (path: PathLike, options?: EncodingOption): string | Buffer,
268
268
  * }} RealPathSync
269
269
  */
270
270
 
@@ -312,8 +312,8 @@ const path = require("path");
312
312
 
313
313
  /**
314
314
  * @typedef {{
315
- * (file: PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, options: WriteFileOptions, callback: NoParamCallback): void;
316
- * (file: PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, callback: NoParamCallback): void;
315
+ * (file: PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, options: WriteFileOptions, callback: NoParamCallback): void,
316
+ * (file: PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, callback: NoParamCallback): void,
317
317
  * }} WriteFile
318
318
  */
319
319
 
@@ -323,10 +323,10 @@ const path = require("path");
323
323
 
324
324
  /**
325
325
  * @typedef {{
326
- * (file: PathLike, options: MakeDirectoryOptions & { recursive: true }, callback: StringCallback): void;
327
- * (file: PathLike, options: Mode | (MakeDirectoryOptions & { recursive?: false | undefined; }) | null | undefined, callback: NoParamCallback): void;
328
- * (file: PathLike, options: Mode | MakeDirectoryOptions | null | undefined, callback: StringCallback): void;
329
- * (file: PathLike, callback: NoParamCallback): void;
326
+ * (file: PathLike, options: MakeDirectoryOptions & { recursive: true }, callback: StringCallback): void,
327
+ * (file: PathLike, options: Mode | (MakeDirectoryOptions & { recursive?: false | undefined; }) | null | undefined, callback: NoParamCallback): void,
328
+ * (file: PathLike, options: Mode | MakeDirectoryOptions | null | undefined, callback: StringCallback): void,
329
+ * (file: PathLike, callback: NoParamCallback): void,
330
330
  * }} Mkdir
331
331
  */
332
332
 
@@ -336,8 +336,8 @@ const path = require("path");
336
336
 
337
337
  /**
338
338
  * @typedef {{
339
- * (file: PathLike, callback: NoParamCallback): void;
340
- * (file: PathLike, options: RmDirOptions, callback: NoParamCallback): void;
339
+ * (file: PathLike, callback: NoParamCallback): void,
340
+ * (file: PathLike, options: RmDirOptions, callback: NoParamCallback): void,
341
341
  * }} Rmdir
342
342
  */
343
343
 
@@ -380,9 +380,9 @@ const path = require("path");
380
380
 
381
381
  /**
382
382
  * @typedef {{
383
- * (path: PathLike, options: MakeDirectoryOptions & { recursive: true }): string | undefined;
384
- * (path: PathLike, options?: Mode | (MakeDirectoryOptions & { recursive?: false | undefined }) | null): void;
385
- * (path: PathLike, options?: Mode | MakeDirectoryOptions | null): string | undefined;
383
+ * (path: PathLike, options: MakeDirectoryOptions & { recursive: true }): string | undefined,
384
+ * (path: PathLike, options?: Mode | (MakeDirectoryOptions & { recursive?: false | undefined }) | null): void,
385
+ * (path: PathLike, options?: Mode | MakeDirectoryOptions | null): string | undefined,
386
386
  * }} MkdirSync
387
387
  */
388
388
 
@@ -422,9 +422,9 @@ const path = require("path");
422
422
 
423
423
  /**
424
424
  * @typedef {{
425
- * (file: PathLike, flags: OpenMode | undefined, mode: Mode | undefined | null, callback: NumberCallback): void;
426
- * (file: PathLike, flags: OpenMode | undefined, callback: NumberCallback): void;
427
- * (file: PathLike, callback: NumberCallback): void;
425
+ * (file: PathLike, flags: OpenMode | undefined, mode: Mode | undefined | null, callback: NumberCallback): void,
426
+ * (file: PathLike, flags: OpenMode | undefined, callback: NumberCallback): void,
427
+ * (file: PathLike, callback: NumberCallback): void,
428
428
  * }} Open
429
429
  */
430
430
 
@@ -451,9 +451,9 @@ const path = require("path");
451
451
  /**
452
452
  * @template {NodeJS.ArrayBufferView} [TBuffer=NodeJS.ArrayBufferView]
453
453
  * @typedef {{
454
- * (fd: number, buffer: TBuffer, offset: number, length: number, position: ReadPosition | null, callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void): void;
455
- * (fd: number, options: ReadAsyncOptions<TBuffer>, callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void): void;
456
- * (fd: number, callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: NodeJS.ArrayBufferView) => void): void;
454
+ * (fd: number, buffer: TBuffer, offset: number, length: number, position: ReadPosition | null, callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void): void,
455
+ * (fd: number, options: ReadAsyncOptions<TBuffer>, callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void): void,
456
+ * (fd: number, callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: NodeJS.ArrayBufferView) => void): void,
457
457
  * }} Read
458
458
  */
459
459
 
@@ -474,7 +474,7 @@ const path = require("path");
474
474
  /** @typedef {InputFileSystem & OutputFileSystem & IntermediateFileSystemExtras} IntermediateFileSystem */
475
475
 
476
476
  /**
477
- * @param {InputFileSystem | OutputFileSystem|undefined} fs a file system
477
+ * @param {InputFileSystem | OutputFileSystem | undefined} fs a file system
478
478
  * @param {string} rootPath the root path
479
479
  * @param {string} targetPath the target path
480
480
  * @returns {string} location of targetPath relative to rootPath
@@ -493,7 +493,7 @@ const relative = (fs, rootPath, targetPath) => {
493
493
  };
494
494
 
495
495
  /**
496
- * @param {InputFileSystem|OutputFileSystem|undefined} fs a file system
496
+ * @param {InputFileSystem | OutputFileSystem | undefined} fs a file system
497
497
  * @param {string} rootPath a path
498
498
  * @param {string} filename a filename
499
499
  * @returns {string} the joined path
@@ -512,7 +512,7 @@ const join = (fs, rootPath, filename) => {
512
512
  };
513
513
 
514
514
  /**
515
- * @param {InputFileSystem|OutputFileSystem|undefined} fs a file system
515
+ * @param {InputFileSystem | OutputFileSystem | undefined} fs a file system
516
516
  * @param {string} absPath an absolute path
517
517
  * @returns {string} the parent directory of the absolute path
518
518
  */
@@ -6,6 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  const Hash = require("../Hash");
9
+ const { digest, update } = require("./hash-digest");
9
10
  const MAX_SHORT_STRING = require("./wasm-hash").MAX_SHORT_STRING;
10
11
 
11
12
  /** @typedef {import("../../../declarations/WebpackOptions").HashDigest} Encoding */
@@ -51,9 +52,9 @@ class BatchedHash extends Hash {
51
52
  return this;
52
53
  }
53
54
  if (this.encoding) {
54
- this.hash.update(this.string, this.encoding);
55
+ update(this.hash, this.string, this.encoding);
55
56
  } else {
56
- this.hash.update(this.string);
57
+ update(this.hash, this.string);
57
58
  }
58
59
  this.string = undefined;
59
60
  }
@@ -66,12 +67,12 @@ class BatchedHash extends Hash {
66
67
  this.string = data;
67
68
  this.encoding = inputEncoding;
68
69
  } else if (inputEncoding) {
69
- this.hash.update(data, inputEncoding);
70
+ update(this.hash, data, inputEncoding);
70
71
  } else {
71
- this.hash.update(data);
72
+ update(this.hash, data);
72
73
  }
73
74
  } else {
74
- this.hash.update(data);
75
+ update(this.hash, data);
75
76
  }
76
77
  return this;
77
78
  }
@@ -95,15 +96,15 @@ class BatchedHash extends Hash {
95
96
  digest(encoding) {
96
97
  if (this.string !== undefined) {
97
98
  if (this.encoding) {
98
- this.hash.update(this.string, this.encoding);
99
+ update(this.hash, this.string, this.encoding);
99
100
  } else {
100
- this.hash.update(this.string);
101
+ update(this.hash, this.string);
101
102
  }
102
103
  }
103
104
  if (!encoding) {
104
- return this.hash.digest();
105
+ return digest(this.hash);
105
106
  }
106
- return this.hash.digest(encoding);
107
+ return digest(this.hash, encoding);
107
108
  }
108
109
  }
109
110
 
@@ -0,0 +1,138 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Alexander Akait @alexander-akait
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const Hash = require("../Hash");
9
+ const { digest, update } = require("./hash-digest");
10
+
11
+ /** @typedef {import("../../../declarations/WebpackOptions").HashDigest} Encoding */
12
+ /** @typedef {() => Hash} HashFactory */
13
+
14
+ const BULK_SIZE = 3;
15
+
16
+ // We are using an object instead of a Map as this will stay static during the runtime
17
+ // so access to it can be optimized by v8
18
+ /** @type {{[key: string]: Map<string, string>}} */
19
+ const digestCaches = {};
20
+
21
+ class BulkUpdateHash extends Hash {
22
+ /**
23
+ * @param {Hash | HashFactory} hashOrFactory function to create a hash
24
+ * @param {string=} hashKey key for caching
25
+ */
26
+ constructor(hashOrFactory, hashKey) {
27
+ super();
28
+ this.hashKey = hashKey;
29
+ if (typeof hashOrFactory === "function") {
30
+ this.hashFactory = hashOrFactory;
31
+ this.hash = undefined;
32
+ } else {
33
+ this.hashFactory = undefined;
34
+ this.hash = hashOrFactory;
35
+ }
36
+ this.buffer = "";
37
+ }
38
+
39
+ /**
40
+ * Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
41
+ * @overload
42
+ * @param {string | Buffer} data data
43
+ * @returns {Hash} updated hash
44
+ */
45
+ /**
46
+ * Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
47
+ * @overload
48
+ * @param {string} data data
49
+ * @param {Encoding} inputEncoding data encoding
50
+ * @returns {Hash} updated hash
51
+ */
52
+ /**
53
+ * Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
54
+ * @param {string | Buffer} data data
55
+ * @param {Encoding=} inputEncoding data encoding
56
+ * @returns {Hash} updated hash
57
+ */
58
+ update(data, inputEncoding) {
59
+ if (
60
+ inputEncoding !== undefined ||
61
+ typeof data !== "string" ||
62
+ data.length > BULK_SIZE
63
+ ) {
64
+ if (this.hash === undefined) {
65
+ this.hash = /** @type {HashFactory} */ (this.hashFactory)();
66
+ }
67
+ if (this.buffer.length > 0) {
68
+ update(this.hash, this.buffer);
69
+ this.buffer = "";
70
+ }
71
+ if (typeof data === "string" && inputEncoding) {
72
+ update(this.hash, data, inputEncoding);
73
+ } else {
74
+ update(this.hash, data);
75
+ }
76
+ } else {
77
+ this.buffer += data;
78
+ if (this.buffer.length > BULK_SIZE) {
79
+ if (this.hash === undefined) {
80
+ this.hash = /** @type {HashFactory} */ (this.hashFactory)();
81
+ }
82
+ update(this.hash, this.buffer);
83
+ this.buffer = "";
84
+ }
85
+ }
86
+ return this;
87
+ }
88
+
89
+ /**
90
+ * Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
91
+ * @overload
92
+ * @returns {Buffer} digest
93
+ */
94
+ /**
95
+ * Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
96
+ * @overload
97
+ * @param {Encoding} encoding encoding of the return value
98
+ * @returns {string} digest
99
+ */
100
+ /**
101
+ * Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
102
+ * @param {Encoding=} encoding encoding of the return value
103
+ * @returns {string | Buffer} digest
104
+ */
105
+ digest(encoding) {
106
+ let digestCache;
107
+ const buffer = this.buffer;
108
+ if (this.hash === undefined) {
109
+ // short data for hash, we can use caching
110
+ const cacheKey = `${this.hashKey}-${encoding}`;
111
+ digestCache = digestCaches[cacheKey];
112
+ if (digestCache === undefined) {
113
+ digestCache = digestCaches[cacheKey] = new Map();
114
+ }
115
+ const cacheEntry = digestCache.get(buffer);
116
+ if (cacheEntry !== undefined) return cacheEntry;
117
+ this.hash = /** @type {HashFactory} */ (this.hashFactory)();
118
+ }
119
+
120
+ if (buffer.length > 0) {
121
+ update(this.hash, buffer);
122
+ }
123
+ if (!encoding) {
124
+ const result = digest(this.hash, undefined, Boolean(this.hashKey));
125
+ if (digestCache !== undefined) {
126
+ digestCache.set(buffer, result);
127
+ }
128
+ return result;
129
+ }
130
+ const result = digest(this.hash, encoding, Boolean(this.hashKey));
131
+ if (digestCache !== undefined) {
132
+ digestCache.set(buffer, result);
133
+ }
134
+ return result;
135
+ }
136
+ }
137
+
138
+ module.exports = BulkUpdateHash;
@@ -0,0 +1,75 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Alexander Akait @alexander-akait
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const Hash = require("../Hash");
9
+
10
+ /** @typedef {import("../../../declarations/WebpackOptions").HashDigest} Encoding */
11
+
12
+ /* istanbul ignore next */
13
+ class DebugHash extends Hash {
14
+ constructor() {
15
+ super();
16
+ this.string = "";
17
+ }
18
+
19
+ /**
20
+ * Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
21
+ * @overload
22
+ * @param {string | Buffer} data data
23
+ * @returns {Hash} updated hash
24
+ */
25
+ /**
26
+ * Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
27
+ * @overload
28
+ * @param {string} data data
29
+ * @param {Encoding} inputEncoding data encoding
30
+ * @returns {Hash} updated hash
31
+ */
32
+ /**
33
+ * Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
34
+ * @param {string | Buffer} data data
35
+ * @param {Encoding=} inputEncoding data encoding
36
+ * @returns {Hash} updated hash
37
+ */
38
+ update(data, inputEncoding) {
39
+ if (typeof data !== "string") data = data.toString("utf8");
40
+ const prefix = Buffer.from("@webpack-debug-digest@").toString("hex");
41
+ if (data.startsWith(prefix)) {
42
+ data = Buffer.from(data.slice(prefix.length), "hex").toString();
43
+ }
44
+ this.string += `[${data}](${
45
+ /** @type {string} */
46
+ (
47
+ // eslint-disable-next-line unicorn/error-message
48
+ new Error().stack
49
+ ).split("\n", 3)[2]
50
+ })\n`;
51
+ return this;
52
+ }
53
+
54
+ /**
55
+ * Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
56
+ * @overload
57
+ * @returns {Buffer} digest
58
+ */
59
+ /**
60
+ * Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
61
+ * @overload
62
+ * @param {Encoding} encoding encoding of the return value
63
+ * @returns {string} digest
64
+ */
65
+ /**
66
+ * Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
67
+ * @param {Encoding=} encoding encoding of the return value
68
+ * @returns {string | Buffer} digest
69
+ */
70
+ digest(encoding) {
71
+ return Buffer.from(`@webpack-debug-digest@${this.string}`).toString("hex");
72
+ }
73
+ }
74
+
75
+ module.exports = DebugHash;