Skip to content

Commit bd21fc5

Browse files
anonrigvicb
andauthored
remove node:crypto polyfills (#10443)
Co-authored-by: Victor Berchet <[email protected]>
1 parent 31ecfeb commit bd21fc5

File tree

8 files changed

+30
-192
lines changed

8 files changed

+30
-192
lines changed

.changeset/eleven-eels-change.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudflare/unenv-preset": patch
3+
---
4+
5+
Removes node:crypto polyfills

fixtures/nodejs-hybrid-app/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ GzEf4UxiLBbUB6WRBgyVyquGfUMlKl/tnm4q0yeYQloYKSoHpGeHVJuN
120120
}
121121

122122
function testGetRandomValues() {
123-
assert.strictEqual(webcrypto.getRandomValues, getRandomValues);
124123
assert.strictEqual(nodeCrypto.getRandomValues, getRandomValues);
125124

126125
return Response.json([

packages/unenv-preset/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
},
5050
"peerDependencies": {
5151
"unenv": "2.0.0-rc.19",
52-
"workerd": "^1.20250827.0"
52+
"workerd": "^1.20250828.1"
5353
},
5454
"peerDependenciesMeta": {
5555
"workerd": {

packages/unenv-preset/src/preset.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const nativeModules = [
2020
"async_hooks",
2121
"buffer",
2222
"constants",
23+
"crypto",
2324
"diagnostics_channel",
2425
"dns",
2526
"dns/promises",
@@ -44,7 +45,7 @@ const nativeModules = [
4445
];
4546

4647
// Modules implemented via a mix of workerd APIs and polyfills.
47-
const hybridModules = ["console", "crypto", "process", "util"];
48+
const hybridModules = ["console", "process", "util"];
4849

4950
/**
5051
* Creates the Cloudflare preset for the given compatibility date and compatibility flags

packages/unenv-preset/src/runtime/node/crypto.ts

Lines changed: 0 additions & 184 deletions
This file was deleted.

packages/vite-plugin-cloudflare/playground/node-compat/worker-random/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ export default {
88
} satisfies ExportedHandler;
99

1010
function testGetRandomValues() {
11-
assert(
12-
webcrypto.getRandomValues === getRandomValues,
13-
"Unexpected identity for webcrypto.getRandomValues"
14-
);
1511
assert(
1612
nodeCrypto.getRandomValues === getRandomValues,
1713
"Unexpected identity for nodeCrypto.getRandomValues"

packages/wrangler/e2e/unenv-preset/worker/index.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,26 @@ export const WorkerdTests: Record<string, () => void> = {
6969
assert(array.every((v) => v >= 0 && v <= 0xff_ff_ff_ff));
7070
},
7171

72+
async testCrypto() {
73+
const crypto = await import("node:crypto");
74+
75+
assert.strictEqual(typeof crypto.pseudoRandomBytes, "function");
76+
77+
const removeEolV22 = getRuntimeFlagValue("remove_nodejs_compat_eol_v22");
78+
79+
if (removeEolV22) {
80+
assert.strictEqual(crypto.Cipher, undefined);
81+
assert.strictEqual(crypto.Decipher, undefined);
82+
assert.strictEqual(crypto.createCipher, undefined);
83+
assert.strictEqual(crypto.createDecipher, undefined);
84+
} else {
85+
assert.strictEqual(typeof crypto.Cipher, "function");
86+
assert.strictEqual(typeof crypto.Decipher, "function");
87+
assert.strictEqual(typeof crypto.createCipher, "function");
88+
assert.strictEqual(typeof crypto.createDecipher, "function");
89+
}
90+
},
91+
7292
async testImplementsBuffer() {
7393
const encoder = new TextEncoder();
7494
const buffer = await import("node:buffer");
@@ -108,6 +128,7 @@ export const WorkerdTests: Record<string, () => void> = {
108128
"async_hooks",
109129
"buffer",
110130
"constants",
131+
"crypto",
111132
"diagnostics_channel",
112133
"dns",
113134
"dns/promises",

pnpm-lock.yaml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)