fix: type of hash from @pnpm/crypto.polyfill (#9252)

This commit is contained in:
Khải
2025-03-09 21:10:43 +07:00
committed by GitHub
parent 81a90dae51
commit 58d859793f
2 changed files with 9 additions and 6 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/crypto.polyfill": minor
---
Fix the type of `hash`. It was `any` because `crypto.hash` not being declared would fall back to `any`.

View File

@@ -1,10 +1,8 @@
import crypto from 'crypto'
export const hash =
export type Hash = (algorithm: string, data: crypto.BinaryLike, outputEncoding: crypto.BinaryToTextEncoding) => string
export const hash: Hash =
// @ts-expect-error -- crypto.hash is supported in Node 21.7.0+, 20.12.0+
crypto.hash ??
((
algorithm: string,
data: crypto.BinaryLike,
outputEncoding: crypto.BinaryToTextEncoding
) => crypto.createHash(algorithm).update(data).digest(outputEncoding))
((algorithm, data, outputEncoding) => crypto.createHash(algorithm).update(data).digest(outputEncoding))