Skip to content

Commit 3779c3a

Browse files
authored
fix!: remove debug hash algorithm (#12951)
1 parent d97104c commit 3779c3a

File tree

2 files changed

+1
-62
lines changed

2 files changed

+1
-62
lines changed

packages/rspack/etc/core.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9564,7 +9564,7 @@ export type UseInputFileSystem = false | RegExp[];
95649564

95659565
// @public (undocumented)
95669566
export const util: {
9567-
createHash: (algorithm: "debug" | "xxhash64" | "md4" | "native-md4" | (string & {}) | (new () => Hash)) => Hash;
9567+
createHash: (algorithm: "xxhash64" | "md4" | "native-md4" | (string & {}) | (new () => Hash)) => Hash;
95689568
cleverMerge: <First, Second>(first: First, second: Second) => First | Second | (First & Second);
95699569
};
95709570

packages/rspack/src/util/createHash.ts

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -121,63 +121,6 @@ class BulkUpdateDecorator extends Hash {
121121
}
122122
}
123123

124-
class DebugHash extends Hash {
125-
string: string;
126-
127-
constructor() {
128-
super();
129-
this.string = '';
130-
}
131-
132-
/**
133-
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
134-
* @param data data
135-
* @param inputEncoding data encoding
136-
* @returns updated hash
137-
*/
138-
update(data: string, inputEncoding: string): this;
139-
update(data: Buffer): this;
140-
update(data: string | Buffer): this {
141-
let normalizedData: string;
142-
if (Buffer.isBuffer(data)) {
143-
normalizedData = data.toString('utf-8');
144-
} else {
145-
normalizedData = data;
146-
}
147-
148-
if (normalizedData.startsWith('debug-digest-')) {
149-
normalizedData = Buffer.from(
150-
normalizedData.slice('debug-digest-'.length),
151-
'hex',
152-
).toString();
153-
}
154-
155-
this.string += `[${normalizedData}](${new Error().stack?.split('\n', 3)[2]})\n`;
156-
return this;
157-
}
158-
159-
/**
160-
* Calculates the digest without encoding
161-
* @returns {Buffer} digest
162-
*/
163-
digest(): Buffer;
164-
/**
165-
* Calculates the digest with encoding
166-
* @param encoding encoding of the return value
167-
* @returns {string} digest
168-
*/
169-
digest(encoding: string): string;
170-
/**
171-
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
172-
* @param {string=} encoding encoding of the return value
173-
* @returns {string|Buffer} digest
174-
*/
175-
digest(encoding?: string): string | Buffer {
176-
const result = `debug-digest-${Buffer.from(this.string).toString('hex')}`;
177-
return encoding ? result : Buffer.from(result);
178-
}
179-
}
180-
181124
class WasmHashAdapter extends Hash {
182125
private wasmHash: any;
183126

@@ -231,7 +174,6 @@ class WasmHashAdapter extends Hash {
231174
*/
232175
export const createHash = (
233176
algorithm:
234-
| 'debug'
235177
| 'xxhash64'
236178
| 'md4'
237179
| 'native-md4'
@@ -242,9 +184,6 @@ export const createHash = (
242184
return new BulkUpdateDecorator(() => new algorithm());
243185
}
244186
switch (algorithm) {
245-
// TODO add non-cryptographic algorithm here
246-
case 'debug':
247-
return new DebugHash();
248187
case 'xxhash64': {
249188
const hash = createXXHash64();
250189
return new WasmHashAdapter(hash);

0 commit comments

Comments
 (0)