webpack 5.102.1 → 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.
- package/README.md +121 -134
- package/hot/dev-server.js +18 -3
- package/hot/emitter-event-target.js +7 -0
- package/hot/lazy-compilation-node.js +45 -29
- package/hot/lazy-compilation-universal.js +18 -0
- package/hot/lazy-compilation-web.js +15 -5
- package/hot/load-http.js +7 -0
- package/hot/only-dev-server.js +19 -4
- package/lib/APIPlugin.js +6 -0
- package/lib/Chunk.js +1 -1
- package/lib/ChunkGraph.js +9 -7
- package/lib/ChunkGroup.js +8 -5
- package/lib/CleanPlugin.js +6 -3
- package/lib/CodeGenerationResults.js +2 -1
- package/lib/CompatibilityPlugin.js +28 -2
- package/lib/Compilation.js +58 -21
- package/lib/Compiler.js +3 -3
- package/lib/ConcatenationScope.js +0 -15
- package/lib/ContextModule.js +6 -3
- package/lib/ContextModuleFactory.js +6 -4
- package/lib/CssModule.js +6 -1
- package/lib/DefinePlugin.js +45 -14
- package/lib/DelegatedModule.js +7 -4
- package/lib/Dependency.js +8 -1
- package/lib/DependencyTemplate.js +1 -0
- package/lib/DllModule.js +6 -3
- package/lib/DotenvPlugin.js +462 -0
- package/lib/EnvironmentPlugin.js +19 -16
- package/lib/EvalSourceMapDevToolPlugin.js +16 -0
- package/lib/ExportsInfo.js +6 -2
- package/lib/ExternalModule.js +28 -35
- package/lib/ExternalModuleFactoryPlugin.js +11 -9
- package/lib/ExternalsPlugin.js +2 -1
- package/lib/FileSystemInfo.js +1 -1
- package/lib/Generator.js +10 -7
- package/lib/HookWebpackError.js +33 -4
- package/lib/HotModuleReplacementPlugin.js +22 -0
- package/lib/ManifestPlugin.js +235 -0
- package/lib/Module.js +27 -15
- package/lib/ModuleBuildError.js +1 -1
- package/lib/ModuleError.js +1 -1
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +29 -13
- package/lib/ModuleGraphConnection.js +2 -2
- package/lib/ModuleSourceTypeConstants.js +189 -0
- package/lib/ModuleTypeConstants.js +1 -4
- package/lib/ModuleWarning.js +1 -1
- package/lib/MultiCompiler.js +1 -1
- package/lib/NodeStuffPlugin.js +424 -116
- package/lib/NormalModule.js +23 -20
- package/lib/NormalModuleFactory.js +7 -10
- package/lib/Parser.js +1 -1
- package/lib/RawModule.js +7 -4
- package/lib/RuntimeGlobals.js +22 -4
- package/lib/RuntimeModule.js +1 -1
- package/lib/RuntimePlugin.js +27 -6
- package/lib/RuntimeTemplate.js +120 -57
- package/lib/SourceMapDevToolPlugin.js +26 -1
- package/lib/Template.js +17 -6
- package/lib/TemplatedPathPlugin.js +5 -6
- package/lib/WebpackError.js +0 -1
- package/lib/WebpackOptionsApply.js +67 -15
- package/lib/asset/AssetBytesGenerator.js +16 -12
- package/lib/asset/AssetGenerator.js +31 -26
- package/lib/asset/AssetSourceGenerator.js +16 -12
- package/lib/asset/RawDataUrlModule.js +6 -3
- package/lib/buildChunkGraph.js +4 -2
- package/lib/cache/PackFileCacheStrategy.js +6 -5
- package/lib/cli.js +2 -43
- package/lib/config/browserslistTargetHandler.js +24 -0
- package/lib/config/defaults.js +226 -61
- package/lib/config/normalization.js +4 -3
- package/lib/config/target.js +11 -0
- package/lib/container/ContainerEntryModule.js +6 -3
- package/lib/container/FallbackModule.js +6 -3
- package/lib/container/RemoteModule.js +1 -3
- package/lib/css/CssGenerator.js +304 -76
- package/lib/css/CssLoadingRuntimeModule.js +14 -4
- package/lib/css/CssMergeStyleSheetsRuntimeModule.js +56 -0
- package/lib/css/CssModulesPlugin.js +72 -67
- package/lib/css/CssParser.js +1726 -732
- package/lib/css/walkCssTokens.js +128 -11
- package/lib/dependencies/CachedConstDependency.js +24 -10
- package/lib/dependencies/CommonJsImportsParserPlugin.js +0 -9
- package/lib/dependencies/CommonJsPlugin.js +12 -0
- package/lib/dependencies/CommonJsRequireContextDependency.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +2 -2
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +3 -1
- package/lib/dependencies/CssIcssExportDependency.js +389 -12
- package/lib/dependencies/CssIcssImportDependency.js +114 -51
- package/lib/dependencies/CssIcssSymbolDependency.js +31 -33
- package/lib/dependencies/CssImportDependency.js +17 -6
- package/lib/dependencies/CssUrlDependency.js +3 -2
- package/lib/dependencies/DynamicExports.js +7 -7
- package/lib/dependencies/ExternalModuleDependency.js +7 -4
- package/lib/dependencies/ExternalModuleInitFragment.js +3 -2
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +96 -0
- package/lib/dependencies/HarmonyAcceptDependency.js +6 -1
- package/lib/dependencies/HarmonyAcceptImportDependency.js +2 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +35 -23
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +13 -9
- package/lib/dependencies/HarmonyExports.js +4 -4
- package/lib/dependencies/HarmonyImportDependency.js +28 -27
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +28 -69
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -3
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -8
- package/lib/dependencies/ImportDependency.js +8 -2
- package/lib/dependencies/ImportEagerDependency.js +6 -3
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/ImportMetaPlugin.js +154 -9
- package/lib/dependencies/ImportParserPlugin.js +21 -23
- package/lib/dependencies/ImportPhase.js +121 -0
- package/lib/dependencies/ImportWeakDependency.js +6 -3
- package/lib/dependencies/LocalModulesHelpers.js +3 -3
- package/lib/dependencies/ModuleDependency.js +5 -1
- package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +2 -2
- package/lib/dependencies/getFunctionExpression.js +1 -1
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -8
- package/lib/esm/ModuleChunkFormatPlugin.js +5 -4
- package/lib/hmr/HotModuleReplacement.runtime.js +2 -1
- package/lib/hmr/LazyCompilationPlugin.js +5 -3
- package/lib/ids/IdHelpers.js +20 -8
- package/lib/index.js +6 -0
- package/lib/javascript/ChunkHelpers.js +16 -5
- package/lib/javascript/JavascriptGenerator.js +105 -104
- package/lib/javascript/JavascriptModulesPlugin.js +80 -37
- package/lib/javascript/JavascriptParser.js +161 -44
- package/lib/json/JsonGenerator.js +5 -4
- package/lib/json/JsonParser.js +9 -2
- package/lib/library/AbstractLibraryPlugin.js +1 -1
- package/lib/library/AmdLibraryPlugin.js +4 -1
- package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
- package/lib/library/ModuleLibraryPlugin.js +41 -23
- package/lib/library/SystemLibraryPlugin.js +8 -1
- package/lib/library/UmdLibraryPlugin.js +2 -2
- package/lib/logging/Logger.js +5 -4
- package/lib/logging/createConsoleLogger.js +2 -2
- package/lib/node/NodeTargetPlugin.js +9 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +0 -2
- package/lib/optimize/ConcatenatedModule.js +208 -167
- package/lib/optimize/ModuleConcatenationPlugin.js +5 -4
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
- package/lib/optimize/SplitChunksPlugin.js +60 -46
- package/lib/rules/RuleSetCompiler.js +1 -1
- package/lib/runtime/AsyncModuleRuntimeModule.js +28 -18
- package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -2
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +89 -55
- package/lib/schemes/HttpUriPlugin.js +78 -7
- package/lib/serialization/AggregateErrorSerializer.js +1 -2
- package/lib/serialization/ObjectMiddleware.js +0 -2
- package/lib/serialization/SingleItemMiddleware.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +1 -1
- package/lib/sharing/ConsumeSharedPlugin.js +5 -3
- package/lib/sharing/ProvideSharedModule.js +1 -1
- package/lib/sharing/resolveMatchedConfigs.js +15 -9
- package/lib/sharing/utils.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +8 -5
- package/lib/stats/DefaultStatsPresetPlugin.js +1 -1
- package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
- package/lib/util/StringXor.js +1 -1
- package/lib/util/URLAbsoluteSpecifier.js +2 -2
- package/lib/util/binarySearchBounds.js +2 -2
- package/lib/util/comparators.js +54 -76
- package/lib/util/compileBooleanMatcher.js +78 -6
- package/lib/util/createHash.js +20 -199
- package/lib/util/deprecation.js +1 -1
- package/lib/util/deterministicGrouping.js +6 -3
- package/lib/util/fs.js +75 -75
- package/lib/util/hash/BatchedHash.js +10 -9
- package/lib/util/hash/BulkUpdateHash.js +138 -0
- package/lib/util/hash/DebugHash.js +75 -0
- package/lib/util/hash/hash-digest.js +216 -0
- package/lib/util/identifier.js +82 -17
- package/lib/util/internalSerializables.js +2 -6
- package/lib/util/runtime.js +3 -3
- package/lib/util/source.js +2 -2
- package/lib/wasm/EnableWasmLoadingPlugin.js +10 -4
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +3 -2
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +11 -7
- package/lib/wasm-sync/WebAssemblyGenerator.js +9 -6
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +11 -6
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +6 -2
- package/lib/web/FetchCompileWasmPlugin.js +0 -2
- package/lib/webpack.js +85 -82
- package/module.d.ts +5 -0
- package/package.json +34 -28
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +160 -101
- package/schemas/plugins/{css/CssAutoParserOptions.check.d.ts → ManifestPlugin.check.d.ts} +1 -1
- package/schemas/plugins/ManifestPlugin.check.js +6 -0
- package/schemas/plugins/ManifestPlugin.json +98 -0
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +16 -3
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +4 -1
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +4 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/schemas/plugins/json/JsonModulesPluginParser.check.js +1 -1
- package/types.d.ts +771 -436
- package/lib/ModuleSourceTypesConstants.js +0 -123
- package/lib/dependencies/CssLocalIdentifierDependency.js +0 -250
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +0 -112
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +0 -6
- package/schemas/plugins/css/CssAutoGeneratorOptions.json +0 -3
- package/schemas/plugins/css/CssAutoParserOptions.check.js +0 -6
- package/schemas/plugins/css/CssAutoParserOptions.json +0 -3
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +0 -6
- package/schemas/plugins/css/CssGlobalGeneratorOptions.json +0 -3
- package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssGlobalParserOptions.check.js +0 -6
- 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
|
|
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 {
|
|
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:
|
|
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:
|
|
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:
|
|
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
|
|
55
|
+
update(this.hash, this.string, this.encoding);
|
|
55
56
|
} else {
|
|
56
|
-
this.hash
|
|
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
|
|
70
|
+
update(this.hash, data, inputEncoding);
|
|
70
71
|
} else {
|
|
71
|
-
this.hash
|
|
72
|
+
update(this.hash, data);
|
|
72
73
|
}
|
|
73
74
|
} else {
|
|
74
|
-
this.hash
|
|
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
|
|
99
|
+
update(this.hash, this.string, this.encoding);
|
|
99
100
|
} else {
|
|
100
|
-
this.hash
|
|
101
|
+
update(this.hash, this.string);
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
104
|
if (!encoding) {
|
|
104
|
-
return this.hash
|
|
105
|
+
return digest(this.hash);
|
|
105
106
|
}
|
|
106
|
-
return this.hash
|
|
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;
|