fix: avoid 'node:crypto' cloudflare warnings (#17612)

* fix: avoid 'node:crypto' cloudflare warnings

* format

* changeset

* Apply suggestion from @teemingc
pull/17614/head
Tee Ming 5 days ago committed by GitHub
parent bc4dc1d10d
commit baba15ab98
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: avoid Cloudflare warnings about not having the "node:crypto" module

@ -12,7 +12,8 @@ export async function sha256(data) {
crypto ??= globalThis.crypto?.subtle?.digest
? globalThis.crypto
: // @ts-ignore - we don't install node types in the prod build
(await import('node:crypto')).webcrypto;
// don't use 'node:crypto' because static analysers will think we rely on node when we don't
(await import('node:' + 'crypto')).webcrypto;
const hash_buffer = await crypto.subtle.digest('SHA-256', text_encoder.encode(data));

Loading…
Cancel
Save