fix: logic

This commit is contained in:
alexander-akait 2025-10-07 15:44:25 +03:00
parent 4c17f5160c
commit 63411bd7f0
5 changed files with 42 additions and 16 deletions

View File

@ -539,12 +539,7 @@ export type GlobalObject = string;
/** /**
* Digest type used for the hash. * Digest type used for the hash.
*/ */
export type HashDigest = Encoding; export type HashDigest =
/**
* This interface was referenced by `WebpackOptions`'s JSON-Schema
* via the `definition` "Encoding".
*/
export type Encoding =
| "base64" | "base64"
| "base64url" | "base64url"
| "hex" | "hex"
@ -808,6 +803,22 @@ export type CssParserUrl = boolean;
* Options for defer import. * Options for defer import.
*/ */
export type DeferImportExperimentOptions = boolean; export type DeferImportExperimentOptions = boolean;
/**
* Supported encoding.
*/
export type Encoding =
| "base64"
| "base64url"
| "hex"
| "binary"
| "utf8"
| "utf-8"
| "utf16le"
| "utf-16le"
| "latin1"
| "ascii"
| "ucs2"
| "ucs-2";
/** /**
* A Function returning a Promise resolving to a normalized entry. * A Function returning a Promise resolving to a normalized entry.
*/ */

View File

@ -127,7 +127,12 @@ class BulkUpdateDecorator extends Hash {
} }
return result; return result;
} }
const result = this.hash.digest(encoding); const digestResult = this.hash.digest(encoding);
// Compatibility with the old hash library
const result =
typeof digestResult === "string"
? digestResult
: /** @type {NodeJS.TypedArray} */ (digestResult).toString();
if (digestCache !== undefined) { if (digestCache !== undefined) {
digestCache.set(buffer, result); digestCache.set(buffer, result);
} }

File diff suppressed because one or more lines are too long

View File

@ -661,6 +661,7 @@
} }
}, },
"Encoding": { "Encoding": {
"description": "Supported encoding.",
"enum": [ "enum": [
"base64", "base64",
"base64url", "base64url",
@ -1584,12 +1585,8 @@
"minLength": 1 "minLength": 1
}, },
"HashDigest": { "HashDigest": {
"description": "Digest type used for the hash.", "$ref": "#/definitions/Encoding",
"anyOf": [ "description": "Digest type used for the hash."
{
"$ref": "#/definitions/Encoding"
}
]
}, },
"HashDigestLength": { "HashDigestLength": {
"description": "Number of chars which are used for the hash.", "description": "Number of chars which are used for the hash.",

17
types.d.ts vendored
View File

@ -6272,6 +6272,19 @@ declare class Hash {
*/ */
digest(encoding: Encoding): string; digest(encoding: Encoding): string;
} }
type HashDigest =
| "base64"
| "base64url"
| "hex"
| "binary"
| "utf8"
| "utf-8"
| "utf16le"
| "utf-16le"
| "latin1"
| "ascii"
| "ucs2"
| "ucs-2";
type HashFunction = string | typeof Hash; type HashFunction = string | typeof Hash;
declare interface HashLike { declare interface HashLike {
/** /**
@ -11729,7 +11742,7 @@ declare interface NormalModuleLoaderContext<OptionsType> {
mode: "none" | "development" | "production"; mode: "none" | "development" | "production";
webpack?: boolean; webpack?: boolean;
hashFunction: HashFunction; hashFunction: HashFunction;
hashDigest: Encoding; hashDigest: HashDigest;
hashDigestLength: number; hashDigestLength: number;
hashSalt?: string; hashSalt?: string;
_module?: NormalModule; _module?: NormalModule;
@ -14431,7 +14444,7 @@ declare interface RealContentHashPluginOptions {
/** /**
* the hash digest to use * the hash digest to use
*/ */
hashDigest: Encoding; hashDigest: HashDigest;
} }
declare interface RealDependencyLocation { declare interface RealDependencyLocation {
start: SourcePosition; start: SourcePosition;