/
cloudflare.ts
45 lines (42 loc) · 1.09 KB
/
cloudflare.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import type { Preset } from "../types";
// https://developers.cloudflare.com/workers/runtime-apis/nodejs/
// https://github.com/cloudflare/workerd/tree/main/src/node
// Last checked: 2024-05-11
const cloudflareNodeCompatModules = [
"_stream_duplex",
"_stream_passthrough",
"_stream_readable",
"_stream_transform",
"_stream_writable",
"assert",
"async_hooks",
"buffer",
"crypto",
"diagnostics_channel",
"events",
"path",
"process",
"stream",
"stream/consumers",
"stream/promises",
"stream/web",
"string_decoder",
"util",
];
const cloudflarePreset: Preset = {
alias: {
...Object.fromEntries(
cloudflareNodeCompatModules.map((p) => [p, `node:${p}`]),
),
...Object.fromEntries(
cloudflareNodeCompatModules.map((p) => [`node:${p}`, `node:${p}`]),
),
// The `node:assert` implementation of workerd uses strict semantics by default
"assert/strict": "node:assert",
"node:assert/strict": "node:assert",
},
inject: {},
polyfill: [],
external: cloudflareNodeCompatModules.map((p) => `node:${p}`),
};
export default cloudflarePreset;