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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
// This generates a list of all the shapes of all builtin modules and their typeof values.
//
// To run:
//
// bun generate-exports.mjs > node-exports.bun-${version}.json
// bun generate-exports.mjs bun > bun-exports.bun-${version}.json
// node generate-exports.mjs > node-exports.node-$(node --version).json
//
import { createRequire } from "node:module";
import process from "node:process";
const nodeBuiltins = [
"_http_agent",
"_http_client",
"_http_common",
"_http_incoming",
"_http_outgoing",
"_http_server",
"_stream_duplex",
"_stream_passthrough",
"_stream_readable",
"_stream_transform",
"_stream_wrap",
"_stream_writable",
"_tls_common",
"_tls_wrap",
"assert",
"assert/strict",
"async_hooks",
"buffer",
"child_process",
"cluster",
"console",
"constants",
"crypto",
"dgram",
"diagnostics_channel",
"dns",
"dns/promises",
"domain",
"events",
"fs",
"fs/promises",
"http",
"http2",
"https",
"inspector",
"inspector/promises",
"module",
"net",
"os",
"path",
"path/posix",
"path/win32",
"perf_hooks",
"process",
"punycode",
"querystring",
"readline",
"readline/promises",
"repl",
"stream",
"stream/consumers",
"stream/promises",
"stream/web",
"string_decoder",
"sys",
"test/reporters",
"timers",
"timers/promises",
"tls",
"trace_events",
"tty",
"url",
"util",
"util/types",
"v8",
"vm",
"wasi",
"worker_threads",
"zlib",
]
.map(a => "node:" + a)
.sort();
const bunBuiltins = [
"buffer",
"bun:ffi",
"bun:jsc",
"bun:main",
"bun:sqlite",
"bun:events_native",
"detect-libc",
"node:assert",
"node:assert/strict",
"node:async_hooks",
"node:buffer",
"node:child_process",
"node:cluster",
"node:crypto",
"node:dgram",
"node:diagnostics_channel",
"node:dns",
"node:dns/promises",
"node:events",
"node:fs",
"node:fs/promises",
"node:http",
"node:http2",
"node:https",
"node:inspector",
"node:module",
"node:net",
"node:os",
"node:path",
"node:path/posix",
"node:path/win32",
"node:perf_hooks",
"node:process",
"node:readline",
"node:readline/promises",
"node:repl",
"node:stream",
"node:stream/consumers",
"node:stream/promises",
"node:stream/web",
"node:string_decoder",
"node:timers",
"node:timers/promises",
"node:tls",
"node:trace_events",
"node:tty",
"node:url",
"node:util",
"node:util/types",
"node:v8",
"node:vm",
"node:wasi",
"node:zlib",
].sort();
const require = createRequire(import.meta.url);
const imported = {};
const required = {};
const errors = {};
function resolveNested([key, v], stop) {
let nested;
if ((v && typeof v === "object") || typeof v === "function") {
const entries = Object.fromEntries(
Object.entries(v)
.map(([ak, av]) => {
var display = typeof av;
if (av && (typeof av === "function" || typeof av === "object")) {
const list = Object.fromEntries(
Object.entries(av)
.map(([ak2, av2]) => [ak2, typeof av2])
.sort(),
);
for (let key in list) {
display = list;
break;
}
}
return [ak, display];
})
.sort(),
);
for (let key in entries) {
nested = entries;
break;
}
}
return [key, nested || typeof v];
}
async function processBuiltins(builtins) {
for (const builtin of builtins) {
try {
imported[builtin] = Object.fromEntries(
Object.entries(await import(builtin))
.map(resolveNested)
.sort(),
);
required[builtin] = Object.fromEntries(Object.entries(require(builtin)).map(resolveNested).sort());
} catch ({ name, message }) {
errors[builtin] = { name, message };
}
}
}
process.stdout.write(
JSON.stringify(
{
builtins: await processBuiltins(process.argv.at(-1) === "bun" ? bunBuiltins : nodeBuiltins),
import: imported,
require: required,
runtime: typeof Bun !== "undefined" ? "bun" : "node",
version: typeof Bun !== "undefined" ? Bun.version : process.version,
errors,
},
null,
2,
),
);
|