forked from oven-sh/bun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode_fallbacks.zig
514 lines (491 loc) · 21.3 KB
/
node_fallbacks.zig
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
const std = @import("std");
const string = @import("./string_types.zig").string;
const PackageJSON = @import("./resolver/package_json.zig").PackageJSON;
const logger = @import("root").bun.logger;
const Fs = @import("./fs.zig");
const ComptimeStringMap = @import("./comptime_string_map.zig").ComptimeStringMap;
const assert_code: string = @embedFile("./node-fallbacks/out/assert.js");
const buffer_code: string = @embedFile("./node-fallbacks/out/buffer.js");
const console_code: string = @embedFile("./node-fallbacks/out/console.js");
const constants_code: string = @embedFile("./node-fallbacks/out/constants.js");
const crypto_code: string = @embedFile("./node-fallbacks/out/crypto.js");
const domain_code: string = @embedFile("./node-fallbacks/out/domain.js");
const events_code: string = @embedFile("./node-fallbacks/out/events.js");
const http_code: string = @embedFile("./node-fallbacks/out/http.js");
const https_code: string = @embedFile("./node-fallbacks/out/https.js");
const net_code: string = @embedFile("./node-fallbacks/out/net.js");
const os_code: string = @embedFile("./node-fallbacks/out/os.js");
const path_code: string = @embedFile("./node-fallbacks/out/path.js");
const process_code: string = @embedFile("./node-fallbacks/out/process.js");
const punycode_code: string = @embedFile("./node-fallbacks/out/punycode.js");
const querystring_code: string = @embedFile("./node-fallbacks/out/querystring.js");
const stream_code: string = @embedFile("./node-fallbacks/out/stream.js");
const string_decoder_code: string = @embedFile("./node-fallbacks/out/string_decoder.js");
const sys_code: string = @embedFile("./node-fallbacks/out/sys.js");
const timers_code: string = @embedFile("./node-fallbacks/out/timers.js");
const tty_code: string = @embedFile("./node-fallbacks/out/tty.js");
const url_code: string = @embedFile("./node-fallbacks/out/url.js");
const util_code: string = @embedFile("./node-fallbacks/out/util.js");
const zlib_code: string = @embedFile("./node-fallbacks/out/zlib.js");
const supports_color_code: string = @embedFile("./node-fallbacks/out/supports-color.js");
const node_fetch_code: string = @embedFile("./node-fallbacks/out/node-fetch.js");
const isomorphic_fetch_code: string = @embedFile("./node-fallbacks/out/isomorphic-fetch.js");
const vercel_fetch_code: string = @embedFile("./node-fallbacks/out/@vercel_fetch.js");
const assert_import_path = "/bun-vfs/node_modules/assert/index.js";
const buffer_import_path = "/bun-vfs/node_modules/buffer/index.js";
const console_import_path = "/bun-vfs/node_modules/console/index.js";
const constants_import_path = "/bun-vfs/node_modules/constants/index.js";
const crypto_import_path = "/bun-vfs/node_modules/crypto/index.js";
const domain_import_path = "/bun-vfs/node_modules/domain/index.js";
const events_import_path = "/bun-vfs/node_modules/events/index.js";
const http_import_path = "/bun-vfs/node_modules/http/index.js";
const https_import_path = "/bun-vfs/node_modules/https/index.js";
const net_import_path = "/bun-vfs/node_modules/net/index.js";
const os_import_path = "/bun-vfs/node_modules/os/index.js";
const path_import_path = "/bun-vfs/node_modules/path/index.js";
const process_import_path = "/bun-vfs/node_modules/process/index.js";
const punycode_import_path = "/bun-vfs/node_modules/punycode/index.js";
const querystring_import_path = "/bun-vfs/node_modules/querystring/index.js";
const stream_import_path = "/bun-vfs/node_modules/stream/index.js";
const string_decoder_import_path = "/bun-vfs/node_modules/string_decoder/index.js";
const sys_import_path = "/bun-vfs/node_modules/sys/index.js";
const timers_import_path = "/bun-vfs/node_modules/timers/index.js";
const tty_import_path = "/bun-vfs/node_modules/tty/index.js";
const url_import_path = "/bun-vfs/node_modules/url/index.js";
const util_import_path = "/bun-vfs/node_modules/util/index.js";
const zlib_import_path = "/bun-vfs/node_modules/zlib/index.js";
const supports_color_import_path = "/bun-vfs/node_modules/supports-color/index.js";
const node_fetch_import_path = "/bun-vfs/node_modules/node-fetch/index.js";
const isomorphic_fetch_import_path = "/bun-vfs/node_modules/isomorphic-fetch/index.js";
const vercel_fetch_import_path = "/bun-vfs/node_modules/@vercel/fetch/index.js";
const assert_package_json = PackageJSON{
.name = "assert",
.version = "0.0.0-polyfill",
.module_type = .cjs,
.hash = @truncate(u32, std.hash.Wyhash.hash(0, "[email protected]")),
.main_fields = undefined,
.browser_map = undefined,
.source = logger.Source.initPathString("/bun-vfs/node_modules/assert/package.json", ""),
};
const buffer_package_json = PackageJSON{
.name = "buffer",
.version = "0.0.0-polyfill",
.module_type = .cjs,
.hash = @truncate(u32, std.hash.Wyhash.hash(0, "[email protected]")),
.main_fields = undefined,
.browser_map = undefined,
.source = logger.Source.initPathString("/bun-vfs/node_modules/buffer/package.json", ""),
};
const console_package_json = PackageJSON{
.name = "console",
.version = "0.0.0-polyfill",
.module_type = .cjs,
.hash = @truncate(u32, std.hash.Wyhash.hash(0, "[email protected]")),
.main_fields = undefined,
.browser_map = undefined,
.source = logger.Source.initPathString("/bun-vfs/node_modules/console/package.json", ""),
};
const constants_package_json = PackageJSON{
.name = "constants",
.version = "0.0.0-polyfill",
.module_type = .cjs,
.hash = @truncate(u32, std.hash.Wyhash.hash(0, "[email protected]")),
.main_fields = undefined,
.browser_map = undefined,
.source = logger.Source.initPathString("/bun-vfs/node_modules/constants/package.json", ""),
};
const crypto_package_json = PackageJSON{
.name = "crypto",
.version = "0.0.0-polyfill",
.module_type = .cjs,
.hash = @truncate(u32, std.hash.Wyhash.hash(0, "[email protected]")),
.main_fields = undefined,
.browser_map = undefined,
.source = logger.Source.initPathString("/bun-vfs/node_modules/crypto/package.json", ""),
};
const domain_package_json = PackageJSON{
.name = "domain",
.version = "0.0.0-polyfill",
.module_type = .cjs,
.hash = @truncate(u32, std.hash.Wyhash.hash(0, "[email protected]")),
.main_fields = undefined,
.browser_map = undefined,
.source = logger.Source.initPathString("/bun-vfs/node_modules/domain/package.json", ""),
};
const events_package_json = PackageJSON{
.name = "events",
.version = "0.0.0-polyfill",
.module_type = .cjs,
.hash = @truncate(u32, std.hash.Wyhash.hash(0, "[email protected]")),
.main_fields = undefined,
.browser_map = undefined,
.source = logger.Source.initPathString("/bun-vfs/node_modules/events/package.json", ""),
};
const http_package_json = PackageJSON{
.name = "http",
.version = "0.0.0-polyfill",
.module_type = .cjs,
.hash = @truncate(u32, std.hash.Wyhash.hash(0, "[email protected]")),
.main_fields = undefined,
.browser_map = undefined,
.source = logger.Source.initPathString("/bun-vfs/node_modules/http/package.json", ""),
};
const https_package_json = PackageJSON{
.name = "https",
.version = "0.0.0-polyfill",
.module_type = .cjs,
.hash = @truncate(u32, std.hash.Wyhash.hash(0, "[email protected]")),
.main_fields = undefined,
.browser_map = undefined,
.source = logger.Source.initPathString("/bun-vfs/node_modules/https/package.json", ""),
};
const net_package_json = PackageJSON{
.name = "net",
.version = "0.0.0-polyfill",
.module_type = .cjs,
.hash = @truncate(u32, std.hash.Wyhash.hash(0, "[email protected]")),
.main_fields = undefined,
.browser_map = undefined,
.source = logger.Source.initPathString("/bun-vfs/node_modules/net/package.json", ""),
};
const os_package_json = PackageJSON{
.name = "os",
.version = "0.0.0-polyfill",
.module_type = .cjs,
.hash = @truncate(u32, std.hash.Wyhash.hash(0, "[email protected]")),
.main_fields = undefined,
.browser_map = undefined,
.source = logger.Source.initPathString("/bun-vfs/node_modules/os/package.json", ""),
};
const path_package_json = PackageJSON{
.name = "path",
.version = "0.0.0-polyfill",
.module_type = .cjs,
.hash = @truncate(u32, std.hash.Wyhash.hash(0, "[email protected]")),
.main_fields = undefined,
.browser_map = undefined,
.source = logger.Source.initPathString("/bun-vfs/node_modules/path/package.json", ""),
};
const process_package_json = PackageJSON{
.name = "process",
.version = "0.0.0-polyfill",
.module_type = .cjs,
.hash = @truncate(u32, std.hash.Wyhash.hash(0, "[email protected]")),
.main_fields = undefined,
.browser_map = undefined,
.source = logger.Source.initPathString("/bun-vfs/node_modules/process/package.json", ""),
};
const punycode_package_json = PackageJSON{
.name = "punycode",
.version = "0.0.0-polyfill",
.module_type = .cjs,
.hash = @truncate(u32, std.hash.Wyhash.hash(0, "[email protected]")),
.main_fields = undefined,
.browser_map = undefined,
.source = logger.Source.initPathString("/bun-vfs/node_modules/punycode/package.json", ""),
};
const querystring_package_json = PackageJSON{
.name = "querystring",
.version = "0.0.0-polyfill",
.module_type = .cjs,
.hash = @truncate(u32, std.hash.Wyhash.hash(0, "[email protected]")),
.main_fields = undefined,
.browser_map = undefined,
.source = logger.Source.initPathString("/bun-vfs/node_modules/querystring/package.json", ""),
};
const stream_package_json = PackageJSON{
.name = "stream",
.version = "0.0.0-polyfill",
.module_type = .cjs,
.hash = @truncate(u32, std.hash.Wyhash.hash(0, "[email protected]")),
.main_fields = undefined,
.browser_map = undefined,
.source = logger.Source.initPathString("/bun-vfs/node_modules/stream/package.json", ""),
};
const string_decoder_package_json = PackageJSON{
.name = "string_decoder",
.version = "0.0.0-polyfill",
.module_type = .cjs,
.hash = brk: {
@setEvalBranchQuota(9999);
break :brk @truncate(u32, std.hash.Wyhash.hash(0, "[email protected]"));
},
.main_fields = undefined,
.browser_map = undefined,
.source = logger.Source.initPathString("/bun-vfs/node_modules/string_decoder/package.json", ""),
};
const sys_package_json = PackageJSON{
.name = "sys",
.version = "0.0.0-polyfill",
.module_type = .cjs,
.hash = @truncate(u32, std.hash.Wyhash.hash(0, "[email protected]")),
.main_fields = undefined,
.browser_map = undefined,
.source = logger.Source.initPathString("/bun-vfs/node_modules/sys/package.json", ""),
};
const timers_package_json = PackageJSON{
.name = "timers",
.version = "0.0.0-polyfill",
.module_type = .cjs,
.hash = @truncate(u32, std.hash.Wyhash.hash(0, "[email protected]")),
.main_fields = undefined,
.browser_map = undefined,
.source = logger.Source.initPathString("/bun-vfs/node_modules/timers/package.json", ""),
};
const tty_package_json = PackageJSON{
.name = "tty",
.version = "0.0.0-polyfill",
.module_type = .cjs,
.hash = @truncate(u32, std.hash.Wyhash.hash(0, "[email protected]")),
.main_fields = undefined,
.browser_map = undefined,
.source = logger.Source.initPathString("/bun-vfs/node_modules/tty/package.json", ""),
};
const url_package_json = PackageJSON{
.name = "url",
.version = "0.0.0-polyfill",
.module_type = .cjs,
.hash = @truncate(u32, std.hash.Wyhash.hash(0, "[email protected]")),
.main_fields = undefined,
.browser_map = undefined,
.source = logger.Source.initPathString("/bun-vfs/node_modules/url/package.json", ""),
};
const util_package_json = PackageJSON{
.name = "util",
.version = "0.0.0-polyfill",
.module_type = .cjs,
.hash = @truncate(u32, std.hash.Wyhash.hash(0, "[email protected]")),
.main_fields = undefined,
.browser_map = undefined,
.source = logger.Source.initPathString("/bun-vfs/node_modules/util/package.json", ""),
};
const zlib_package_json = PackageJSON{
.name = "zlib",
.version = "0.0.0-polyfill",
.module_type = .cjs,
.hash = @truncate(u32, std.hash.Wyhash.hash(0, "[email protected]")),
.main_fields = undefined,
.browser_map = undefined,
.source = logger.Source.initPathString("/bun-vfs/node_modules/zlib/package.json", ""),
};
const node_fetch_package_json = PackageJSON{
.name = "node-fetch",
.version = "0.0.0-polyfill",
.module_type = .cjs,
.hash = @truncate(u32, std.hash.Wyhash.hash(0, "[email protected]")),
.main_fields = undefined,
.browser_map = undefined,
.source = logger.Source.initPathString("/bun-vfs/node_modules/node-fetch/package.json", ""),
};
const isomorphic_fetch_package_json = PackageJSON{
.name = "isomorphic-fetch",
.version = "0.0.0-polyfill",
.module_type = .cjs,
.hash = @truncate(u32, std.hash.Wyhash.hash(0, "[email protected]")),
.main_fields = undefined,
.browser_map = undefined,
.source = logger.Source.initPathString("/bun-vfs/node_modules/isomorphic-fetch/package.json", ""),
};
const supports_color_package_json = PackageJSON{
.name = "supports-color",
.version = "0.0.0-polyfill",
.module_type = .cjs,
.hash = @truncate(u32, std.hash.Wyhash.hash(0, "[email protected]")),
.main_fields = undefined,
.browser_map = undefined,
.source = logger.Source.initPathString("/bun-vfs/node_modules/supports-color/package.json", ""),
};
const vercel_fetch_package_json = PackageJSON{
.name = "@vercel/fetch",
.version = "0.0.0-polyfill",
.module_type = .cjs,
.hash = @truncate(u32, std.hash.Wyhash.hash(0, "@vercel/[email protected]")),
.main_fields = undefined,
.browser_map = undefined,
.source = logger.Source.initPathString("/bun-vfs/node_modules/@vercel/fetch/package.json", ""),
};
pub const FallbackModule = struct {
path: Fs.Path,
code: string,
package_json: *const PackageJSON,
pub const assert = FallbackModule{
.path = Fs.Path.initWithNamespaceVirtual(assert_import_path, "node", "assert"),
.code = assert_code,
.package_json = &assert_package_json,
};
pub const buffer = FallbackModule{
.path = Fs.Path.initWithNamespaceVirtual(buffer_import_path, "node", "buffer"),
.code = buffer_code,
.package_json = &buffer_package_json,
};
pub const console = FallbackModule{
.path = Fs.Path.initWithNamespaceVirtual(console_import_path, "node", "console"),
.code = console_code,
.package_json = &console_package_json,
};
pub const constants = FallbackModule{
.path = Fs.Path.initWithNamespaceVirtual(constants_import_path, "node", "constants"),
.code = constants_code,
.package_json = &constants_package_json,
};
pub const crypto = FallbackModule{
.path = Fs.Path.initWithNamespaceVirtual(crypto_import_path, "node", "crypto"),
.code = crypto_code,
.package_json = &crypto_package_json,
};
pub const domain = FallbackModule{
.path = Fs.Path.initWithNamespaceVirtual(domain_import_path, "node", "domain"),
.code = domain_code,
.package_json = &domain_package_json,
};
pub const events = FallbackModule{
.path = Fs.Path.initWithNamespaceVirtual(events_import_path, "node", "events"),
.code = events_code,
.package_json = &events_package_json,
};
pub const http = FallbackModule{
.path = Fs.Path.initWithNamespaceVirtual(http_import_path, "node", "http"),
.code = http_code,
.package_json = &http_package_json,
};
pub const https = FallbackModule{
.path = Fs.Path.initWithNamespaceVirtual(https_import_path, "node", "https"),
.code = https_code,
.package_json = &https_package_json,
};
pub const net = FallbackModule{
.path = Fs.Path.initWithNamespaceVirtual(net_import_path, "node", "net"),
.code = net_code,
.package_json = &net_package_json,
};
pub const os = FallbackModule{
.path = Fs.Path.initWithNamespaceVirtual(os_import_path, "node", "os"),
.code = os_code,
.package_json = &os_package_json,
};
pub const path = FallbackModule{
.path = Fs.Path.initWithNamespaceVirtual(path_import_path, "node", "path"),
.code = path_code,
.package_json = &path_package_json,
};
pub const process = FallbackModule{
.path = Fs.Path.initWithNamespaceVirtual(process_import_path, "node", "process"),
.code = process_code,
.package_json = &process_package_json,
};
pub const punycode = FallbackModule{
.path = Fs.Path.initWithNamespaceVirtual(punycode_import_path, "node", "punycode"),
.code = punycode_code,
.package_json = &punycode_package_json,
};
pub const querystring = FallbackModule{
.path = Fs.Path.initWithNamespaceVirtual(querystring_import_path, "node", "querystring"),
.code = querystring_code,
.package_json = &querystring_package_json,
};
pub const stream = FallbackModule{
.path = Fs.Path.initWithNamespaceVirtual(stream_import_path, "node", "stream"),
.code = stream_code,
.package_json = &stream_package_json,
};
pub const string_decoder = FallbackModule{
.path = Fs.Path.initWithNamespaceVirtual(string_decoder_import_path, "node", "string_decoder"),
.code = string_decoder_code,
.package_json = &string_decoder_package_json,
};
pub const sys = FallbackModule{
.path = Fs.Path.initWithNamespaceVirtual(sys_import_path, "node", "sys"),
.code = sys_code,
.package_json = &sys_package_json,
};
pub const timers = FallbackModule{
.path = Fs.Path.initWithNamespaceVirtual(timers_import_path, "node", "timers"),
.code = timers_code,
.package_json = &timers_package_json,
};
pub const tty = FallbackModule{
.path = Fs.Path.initWithNamespaceVirtual(tty_import_path, "node", "tty"),
.code = tty_code,
.package_json = &tty_package_json,
};
pub const url = FallbackModule{
.path = Fs.Path.initWithNamespaceVirtual(url_import_path, "node", "url"),
.code = url_code,
.package_json = &url_package_json,
};
pub const util = FallbackModule{
.path = Fs.Path.initWithNamespaceVirtual(util_import_path, "node", "util"),
.code = util_code,
.package_json = &util_package_json,
};
pub const zlib = FallbackModule{
.path = Fs.Path.initWithNamespaceVirtual(zlib_import_path, "node", "zlib"),
.code = zlib_code,
.package_json = &zlib_package_json,
};
pub const @"node-fetch" = FallbackModule{
.path = Fs.Path.initWithNamespaceVirtual(node_fetch_import_path, "node", "node-fetch"),
.code = node_fetch_code,
.package_json = &node_fetch_package_json,
};
pub const @"isomorphic-fetch" = FallbackModule{
.path = Fs.Path.initWithNamespaceVirtual(isomorphic_fetch_import_path, "node", "isomorphic-fetch"),
.code = isomorphic_fetch_code,
.package_json = &isomorphic_fetch_package_json,
};
pub const @"@vercel/fetch" = FallbackModule{
.path = Fs.Path.initWithNamespaceVirtual(vercel_fetch_import_path, "node", "@vercel/fetch"),
.code = vercel_fetch_code,
.package_json = &vercel_fetch_package_json,
};
pub const @"supports-color" = FallbackModule{
.path = Fs.Path.initWithNamespaceVirtual(supports_color_import_path, "node", "supports-color"),
.code = supports_color_code,
.package_json = &supports_color_package_json,
};
};
pub const Map = ComptimeStringMap(FallbackModule, .{
&.{ "assert", FallbackModule.assert },
&.{ "buffer", FallbackModule.buffer },
&.{ "console", FallbackModule.console },
&.{ "constants", FallbackModule.constants },
&.{ "crypto", FallbackModule.crypto },
&.{ "domain", FallbackModule.domain },
&.{ "events", FallbackModule.events },
&.{ "http", FallbackModule.http },
&.{ "https", FallbackModule.https },
&.{ "net", FallbackModule.net },
&.{ "os", FallbackModule.os },
&.{ "path", FallbackModule.path },
&.{ "process", FallbackModule.process },
&.{ "punycode", FallbackModule.punycode },
&.{ "querystring", FallbackModule.querystring },
&.{ "stream", FallbackModule.stream },
&.{ "string_decoder", FallbackModule.string_decoder },
&.{ "sys", FallbackModule.sys },
&.{ "timers", FallbackModule.timers },
&.{ "tty", FallbackModule.tty },
&.{ "url", FallbackModule.url },
&.{ "util", FallbackModule.util },
&.{ "zlib", FallbackModule.zlib },
&.{ "supports-color", FallbackModule.@"supports-color" },
&.{ "node-fetch", FallbackModule.@"node-fetch" },
&.{ "isomorphic-fetch", FallbackModule.@"isomorphic-fetch" },
&.{ "@vercel/fetch", FallbackModule.@"@vercel/fetch" },
});
pub fn contentsFromPath(path: string) ?string {
@setCold(true);
var module_name = path["/bun-vfs/node_modules/".len..];
if (module_name[0] == '@') {
var end = std.mem.indexOfScalar(u8, module_name, '/').? + 1;
end += std.mem.indexOfScalar(u8, module_name[end..], '/').?;
module_name = module_name[0..end];
} else {
module_name = module_name[0..std.mem.indexOfScalar(u8, module_name, '/').?];
}
if (Map.get(module_name)) |mod| {
return mod.code;
}
return null;
}
pub const buffer_fallback_import_name: string = "node:buffer";