mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-10 18:18:56 -04:00
fix: type of hash from @pnpm/crypto.polyfill (#9252)
This commit is contained in:
5
.changeset/three-frogs-lay.md
Normal file
5
.changeset/three-frogs-lay.md
Normal 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`.
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user