@run0/jiki 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/dist/browser-bundle.d.ts +40 -0
  2. package/dist/builtins.d.ts +22 -0
  3. package/dist/code-transform.d.ts +7 -0
  4. package/dist/config/cdn.d.ts +13 -0
  5. package/dist/container.d.ts +101 -0
  6. package/dist/dev-server.d.ts +69 -0
  7. package/dist/errors.d.ts +19 -0
  8. package/dist/frameworks/code-transforms.d.ts +32 -0
  9. package/dist/frameworks/next-api-handler.d.ts +72 -0
  10. package/dist/frameworks/next-dev-server.d.ts +141 -0
  11. package/dist/frameworks/next-html-generator.d.ts +36 -0
  12. package/dist/frameworks/next-route-resolver.d.ts +19 -0
  13. package/dist/frameworks/next-shims.d.ts +78 -0
  14. package/dist/frameworks/remix-dev-server.d.ts +47 -0
  15. package/dist/frameworks/sveltekit-dev-server.d.ts +43 -0
  16. package/dist/frameworks/vite-dev-server.d.ts +50 -0
  17. package/dist/fs-errors.d.ts +36 -0
  18. package/dist/index.cjs +14916 -0
  19. package/dist/index.cjs.map +1 -0
  20. package/dist/index.d.ts +61 -0
  21. package/dist/index.mjs +14898 -0
  22. package/dist/index.mjs.map +1 -0
  23. package/dist/kernel.d.ts +48 -0
  24. package/dist/memfs.d.ts +144 -0
  25. package/dist/metrics.d.ts +78 -0
  26. package/dist/module-resolver.d.ts +60 -0
  27. package/dist/network-interceptor.d.ts +71 -0
  28. package/dist/npm/cache.d.ts +76 -0
  29. package/dist/npm/index.d.ts +60 -0
  30. package/dist/npm/lockfile-reader.d.ts +32 -0
  31. package/dist/npm/pnpm.d.ts +18 -0
  32. package/dist/npm/registry.d.ts +45 -0
  33. package/dist/npm/resolver.d.ts +39 -0
  34. package/dist/npm/sync-installer.d.ts +18 -0
  35. package/dist/npm/tarball.d.ts +4 -0
  36. package/dist/npm/workspaces.d.ts +46 -0
  37. package/dist/persistence.d.ts +94 -0
  38. package/dist/plugin.d.ts +156 -0
  39. package/dist/polyfills/assert.d.ts +30 -0
  40. package/dist/polyfills/child_process.d.ts +116 -0
  41. package/dist/polyfills/chokidar.d.ts +18 -0
  42. package/dist/polyfills/crypto.d.ts +49 -0
  43. package/dist/polyfills/events.d.ts +28 -0
  44. package/dist/polyfills/fs.d.ts +82 -0
  45. package/dist/polyfills/http.d.ts +147 -0
  46. package/dist/polyfills/module.d.ts +29 -0
  47. package/dist/polyfills/net.d.ts +53 -0
  48. package/dist/polyfills/os.d.ts +91 -0
  49. package/dist/polyfills/path.d.ts +96 -0
  50. package/dist/polyfills/perf_hooks.d.ts +21 -0
  51. package/dist/polyfills/process.d.ts +99 -0
  52. package/dist/polyfills/querystring.d.ts +15 -0
  53. package/dist/polyfills/readdirp.d.ts +18 -0
  54. package/dist/polyfills/readline.d.ts +32 -0
  55. package/dist/polyfills/stream.d.ts +106 -0
  56. package/dist/polyfills/stubs.d.ts +737 -0
  57. package/dist/polyfills/tty.d.ts +25 -0
  58. package/dist/polyfills/url.d.ts +41 -0
  59. package/dist/polyfills/util.d.ts +61 -0
  60. package/dist/polyfills/v8.d.ts +43 -0
  61. package/dist/polyfills/vm.d.ts +76 -0
  62. package/dist/polyfills/worker-threads.d.ts +77 -0
  63. package/dist/polyfills/ws.d.ts +32 -0
  64. package/dist/polyfills/zlib.d.ts +87 -0
  65. package/dist/runtime-helpers.d.ts +4 -0
  66. package/dist/runtime-interface.d.ts +39 -0
  67. package/dist/sandbox.d.ts +69 -0
  68. package/dist/server-bridge.d.ts +55 -0
  69. package/dist/shell-commands.d.ts +2 -0
  70. package/dist/shell.d.ts +101 -0
  71. package/dist/transpiler.d.ts +47 -0
  72. package/dist/type-checker.d.ts +57 -0
  73. package/dist/types/package-json.d.ts +17 -0
  74. package/dist/utils/binary-encoding.d.ts +4 -0
  75. package/dist/utils/hash.d.ts +6 -0
  76. package/dist/utils/safe-path.d.ts +6 -0
  77. package/dist/worker-runtime.d.ts +34 -0
  78. package/package.json +59 -0
  79. package/src/browser-bundle.ts +498 -0
  80. package/src/builtins.ts +222 -0
  81. package/src/code-transform.ts +183 -0
  82. package/src/config/cdn.ts +17 -0
  83. package/src/container.ts +343 -0
  84. package/src/dev-server.ts +322 -0
  85. package/src/errors.ts +604 -0
  86. package/src/frameworks/code-transforms.ts +667 -0
  87. package/src/frameworks/next-api-handler.ts +366 -0
  88. package/src/frameworks/next-dev-server.ts +1252 -0
  89. package/src/frameworks/next-html-generator.ts +585 -0
  90. package/src/frameworks/next-route-resolver.ts +521 -0
  91. package/src/frameworks/next-shims.ts +1084 -0
  92. package/src/frameworks/remix-dev-server.ts +163 -0
  93. package/src/frameworks/sveltekit-dev-server.ts +197 -0
  94. package/src/frameworks/vite-dev-server.ts +370 -0
  95. package/src/fs-errors.ts +118 -0
  96. package/src/index.ts +188 -0
  97. package/src/kernel.ts +381 -0
  98. package/src/memfs.ts +1006 -0
  99. package/src/metrics.ts +140 -0
  100. package/src/module-resolver.ts +511 -0
  101. package/src/network-interceptor.ts +143 -0
  102. package/src/npm/cache.ts +172 -0
  103. package/src/npm/index.ts +377 -0
  104. package/src/npm/lockfile-reader.ts +105 -0
  105. package/src/npm/pnpm.ts +108 -0
  106. package/src/npm/registry.ts +120 -0
  107. package/src/npm/resolver.ts +339 -0
  108. package/src/npm/sync-installer.ts +217 -0
  109. package/src/npm/tarball.ts +136 -0
  110. package/src/npm/workspaces.ts +255 -0
  111. package/src/persistence.ts +235 -0
  112. package/src/plugin.ts +293 -0
  113. package/src/polyfills/assert.ts +164 -0
  114. package/src/polyfills/child_process.ts +535 -0
  115. package/src/polyfills/chokidar.ts +52 -0
  116. package/src/polyfills/crypto.ts +433 -0
  117. package/src/polyfills/events.ts +178 -0
  118. package/src/polyfills/fs.ts +297 -0
  119. package/src/polyfills/http.ts +478 -0
  120. package/src/polyfills/module.ts +97 -0
  121. package/src/polyfills/net.ts +123 -0
  122. package/src/polyfills/os.ts +108 -0
  123. package/src/polyfills/path.ts +169 -0
  124. package/src/polyfills/perf_hooks.ts +30 -0
  125. package/src/polyfills/process.ts +349 -0
  126. package/src/polyfills/querystring.ts +66 -0
  127. package/src/polyfills/readdirp.ts +72 -0
  128. package/src/polyfills/readline.ts +80 -0
  129. package/src/polyfills/stream.ts +610 -0
  130. package/src/polyfills/stubs.ts +600 -0
  131. package/src/polyfills/tty.ts +43 -0
  132. package/src/polyfills/url.ts +97 -0
  133. package/src/polyfills/util.ts +173 -0
  134. package/src/polyfills/v8.ts +62 -0
  135. package/src/polyfills/vm.ts +111 -0
  136. package/src/polyfills/worker-threads.ts +189 -0
  137. package/src/polyfills/ws.ts +73 -0
  138. package/src/polyfills/zlib.ts +244 -0
  139. package/src/runtime-helpers.ts +83 -0
  140. package/src/runtime-interface.ts +46 -0
  141. package/src/sandbox.ts +178 -0
  142. package/src/server-bridge.ts +473 -0
  143. package/src/service-worker.ts +153 -0
  144. package/src/shell-commands.ts +708 -0
  145. package/src/shell.ts +795 -0
  146. package/src/transpiler.ts +282 -0
  147. package/src/type-checker.ts +241 -0
  148. package/src/types/package-json.ts +17 -0
  149. package/src/utils/binary-encoding.ts +38 -0
  150. package/src/utils/hash.ts +24 -0
  151. package/src/utils/safe-path.ts +38 -0
  152. package/src/worker-runtime.ts +42 -0
@@ -0,0 +1,600 @@
1
+ /**
2
+ * Consolidated stubs for Node.js modules that cannot run in the browser.
3
+ * Each export is a minimal shim that satisfies import resolution without real functionality.
4
+ *
5
+ * Each stub emits a one-time console.warn when first used, so developers are aware
6
+ * that the module is not fully functional in the browser environment.
7
+ */
8
+
9
+ import { EventEmitter } from "./events";
10
+
11
+ /**
12
+ * Tracks which stub module warnings have already been emitted.
13
+ * Each warning is shown only once per session to avoid flooding the console.
14
+ */
15
+ export const _warnedStubs = new Set<string>();
16
+
17
+ /**
18
+ * Emit a one-time warning that a stub module is being used.
19
+ * @param moduleName - The name of the Node.js module being stubbed.
20
+ */
21
+ function warnStub(moduleName: string): void {
22
+ if (_warnedStubs.has(moduleName)) return;
23
+ _warnedStubs.add(moduleName);
24
+ console.warn(
25
+ `[jiki] "${moduleName}" is a stub module — it provides no real functionality in the browser runtime.`,
26
+ );
27
+ }
28
+
29
+ // --- async_hooks ---
30
+
31
+ export const async_hooks = (() => {
32
+ warnStub("async_hooks");
33
+ class AsyncLocalStorage<T = unknown> {
34
+ #store: T | undefined;
35
+
36
+ getStore(): T | undefined {
37
+ return this.#store;
38
+ }
39
+
40
+ run<R>(
41
+ store: T,
42
+ callback: (...args: unknown[]) => R,
43
+ ...args: unknown[]
44
+ ): R {
45
+ const prev = this.#store;
46
+ this.#store = store;
47
+ try {
48
+ return callback(...args);
49
+ } finally {
50
+ this.#store = prev;
51
+ }
52
+ }
53
+
54
+ exit<R>(callback: (...args: unknown[]) => R, ...args: unknown[]): R {
55
+ const prev = this.#store;
56
+ this.#store = undefined;
57
+ try {
58
+ return callback(...args);
59
+ } finally {
60
+ this.#store = prev;
61
+ }
62
+ }
63
+
64
+ enterWith(store: T): void {
65
+ this.#store = store;
66
+ }
67
+ disable(): void {
68
+ this.#store = undefined;
69
+ }
70
+
71
+ snapshot(): <R>(fn: (...args: unknown[]) => R, ...args: unknown[]) => R {
72
+ const captured = this.#store;
73
+ return <R>(fn: (...args: unknown[]) => R, ...args: unknown[]): R => {
74
+ const prev = this.#store;
75
+ this.#store = captured;
76
+ try {
77
+ return fn(...args);
78
+ } finally {
79
+ this.#store = prev;
80
+ }
81
+ };
82
+ }
83
+
84
+ static bind<F extends (...args: unknown[]) => unknown>(fn: F): F {
85
+ return fn;
86
+ }
87
+
88
+ static snapshot(): <R>(
89
+ fn: (...args: unknown[]) => R,
90
+ ...args: unknown[]
91
+ ) => R {
92
+ return <R>(fn: (...args: unknown[]) => R, ...args: unknown[]): R =>
93
+ fn(...args);
94
+ }
95
+ }
96
+
97
+ class AsyncResource {
98
+ type: string;
99
+ constructor(type: string, _opts?: unknown) {
100
+ this.type = type;
101
+ }
102
+ runInAsyncScope<R>(
103
+ fn: (...args: unknown[]) => R,
104
+ thisArg?: unknown,
105
+ ...args: unknown[]
106
+ ): R {
107
+ return fn.apply(thisArg, args);
108
+ }
109
+ emitDestroy(): this {
110
+ return this;
111
+ }
112
+ asyncId(): number {
113
+ return 0;
114
+ }
115
+ triggerAsyncId(): number {
116
+ return 0;
117
+ }
118
+ bind<F extends (...args: unknown[]) => unknown>(fn: F): F {
119
+ return fn;
120
+ }
121
+ static bind<F extends (...args: unknown[]) => unknown>(
122
+ fn: F,
123
+ _type?: string,
124
+ ): F {
125
+ return fn;
126
+ }
127
+ }
128
+
129
+ return {
130
+ AsyncLocalStorage,
131
+ AsyncResource,
132
+ executionAsyncId: () => 0,
133
+ triggerAsyncId: () => 0,
134
+ executionAsyncResource: () => ({}),
135
+ createHook: () => ({ enable() {}, disable() {} }),
136
+ };
137
+ })();
138
+
139
+ // --- cluster ---
140
+
141
+ export const cluster = (() => {
142
+ warnStub("cluster");
143
+ return {
144
+ isWorker: false,
145
+ isMaster: true,
146
+ isPrimary: true,
147
+ workers: {} as Record<string, unknown>,
148
+ fork: () => new EventEmitter(),
149
+ setupMaster() {},
150
+ setupPrimary() {},
151
+ disconnect() {},
152
+ settings: {},
153
+ SCHED_NONE: 1,
154
+ SCHED_RR: 2,
155
+ schedulingPolicy: 2,
156
+ };
157
+ })();
158
+
159
+ // --- dgram ---
160
+
161
+ export const dgram = (() => {
162
+ warnStub("dgram");
163
+ class Socket extends EventEmitter {
164
+ bind() {
165
+ return this;
166
+ }
167
+ send() {}
168
+ close() {
169
+ this.emit("close");
170
+ }
171
+ address() {
172
+ return { address: "0.0.0.0", family: "IPv4", port: 0 };
173
+ }
174
+ setBroadcast() {}
175
+ setTTL() {}
176
+ setMulticastTTL() {}
177
+ addMembership() {}
178
+ dropMembership() {}
179
+ ref() {
180
+ return this;
181
+ }
182
+ unref() {
183
+ return this;
184
+ }
185
+ }
186
+ return { Socket, createSocket: () => new Socket() };
187
+ })();
188
+
189
+ // --- diagnostics_channel ---
190
+
191
+ export const diagnostics_channel = (() => {
192
+ warnStub("diagnostics_channel");
193
+ class Channel {
194
+ name: string;
195
+ constructor(name: string) {
196
+ this.name = name;
197
+ }
198
+ get hasSubscribers() {
199
+ return false;
200
+ }
201
+ subscribe() {}
202
+ unsubscribe() {
203
+ return false;
204
+ }
205
+ publish() {}
206
+ }
207
+
208
+ class TracingChannel {
209
+ start: Channel;
210
+ end: Channel;
211
+ asyncStart: Channel;
212
+ asyncEnd: Channel;
213
+ error: Channel;
214
+ constructor(name: string) {
215
+ this.start = new Channel(`tracing:${name}:start`);
216
+ this.end = new Channel(`tracing:${name}:end`);
217
+ this.asyncStart = new Channel(`tracing:${name}:asyncStart`);
218
+ this.asyncEnd = new Channel(`tracing:${name}:asyncEnd`);
219
+ this.error = new Channel(`tracing:${name}:error`);
220
+ }
221
+ subscribe(_subscribers: Record<string, unknown>) {}
222
+ unsubscribe(_subscribers: Record<string, unknown>) {}
223
+ traceSync(
224
+ fn: (...a: unknown[]) => unknown,
225
+ _ctx?: object,
226
+ thisArg?: unknown,
227
+ ...args: unknown[]
228
+ ) {
229
+ return fn.apply(thisArg, args);
230
+ }
231
+ tracePromise(
232
+ fn: (...a: unknown[]) => unknown,
233
+ _ctx?: object,
234
+ thisArg?: unknown,
235
+ ...args: unknown[]
236
+ ) {
237
+ return fn.apply(thisArg, args);
238
+ }
239
+ traceCallback(
240
+ fn: (...a: unknown[]) => unknown,
241
+ _pos?: number,
242
+ _ctx?: object,
243
+ thisArg?: unknown,
244
+ ...args: unknown[]
245
+ ) {
246
+ return fn.apply(thisArg, args);
247
+ }
248
+ }
249
+
250
+ return {
251
+ Channel,
252
+ TracingChannel,
253
+ channel: (n: string) => new Channel(n),
254
+ tracingChannel: (n: string) => new TracingChannel(n),
255
+ hasSubscribers: () => false,
256
+ };
257
+ })();
258
+
259
+ // --- dns ---
260
+
261
+ export const dns = (() => {
262
+ warnStub("dns");
263
+ return {
264
+ lookup: (_h: string, optsOrCb: unknown, maybeCb?: unknown) => {
265
+ const cb = typeof optsOrCb === "function" ? optsOrCb : maybeCb;
266
+ const opts =
267
+ typeof optsOrCb === "object" && optsOrCb !== null
268
+ ? (optsOrCb as Record<string, unknown>)
269
+ : {};
270
+ if (typeof cb !== "function") return;
271
+ if (opts.all) {
272
+ cb(null, [{ address: "127.0.0.1", family: 4 }]);
273
+ } else {
274
+ cb(null, "127.0.0.1", 4);
275
+ }
276
+ },
277
+ resolve: (_h: string, cb: (e: Error | null, a: string[]) => void) =>
278
+ cb(null, ["127.0.0.1"]),
279
+ resolve4: (_h: string, cb: (e: Error | null, a: string[]) => void) =>
280
+ cb(null, ["127.0.0.1"]),
281
+ resolve6: (_h: string, cb: (e: Error | null, a: string[]) => void) =>
282
+ cb(null, ["::1"]),
283
+ reverse: (_ip: string, cb: (e: Error | null, h: string[]) => void) =>
284
+ cb(null, ["localhost"]),
285
+ getServers: () => ["8.8.8.8"],
286
+ setServers() {},
287
+ NODATA: "ENODATA",
288
+ FORMERR: "EFORMERR",
289
+ SERVFAIL: "ESERVFAIL",
290
+ NOTFOUND: "ENOTFOUND",
291
+ promises: {
292
+ lookup: async (_h: string, opts?: Record<string, unknown>) => {
293
+ if (opts?.all) return [{ address: "127.0.0.1", family: 4 }];
294
+ return { address: "127.0.0.1", family: 4 };
295
+ },
296
+ resolve: async () => ["127.0.0.1"],
297
+ resolve4: async () => ["127.0.0.1"],
298
+ resolve6: async () => ["::1"],
299
+ },
300
+ };
301
+ })();
302
+
303
+ // --- domain ---
304
+
305
+ export const domain = (() => {
306
+ warnStub("domain");
307
+ class Domain extends EventEmitter {
308
+ members: unknown[] = [];
309
+ add() {}
310
+ remove() {}
311
+ bind(cb: Function) {
312
+ return cb;
313
+ }
314
+ intercept(cb: Function) {
315
+ return cb;
316
+ }
317
+ run(fn: Function) {
318
+ fn();
319
+ }
320
+ dispose() {}
321
+ enter() {}
322
+ exit() {}
323
+ }
324
+ return { Domain, create: () => new Domain() };
325
+ })();
326
+
327
+ // --- esbuild (delegates to real esbuild-wasm) ---
328
+
329
+ import * as _esbuildWasm from "esbuild-wasm";
330
+ import { initTranspiler } from "../transpiler";
331
+
332
+ export const esbuild = {
333
+ initialize: (opts?: Record<string, unknown>) => initTranspiler(),
334
+ build: (...args: Parameters<typeof _esbuildWasm.build>) => {
335
+ return _esbuildWasm.build(...args);
336
+ },
337
+ transform: (...args: Parameters<typeof _esbuildWasm.transform>) => {
338
+ return _esbuildWasm.transform(...args);
339
+ },
340
+ buildSync: (...args: Parameters<typeof _esbuildWasm.buildSync>) => {
341
+ return _esbuildWasm.buildSync(...args);
342
+ },
343
+ transformSync: (...args: Parameters<typeof _esbuildWasm.transformSync>) => {
344
+ return _esbuildWasm.transformSync(...args);
345
+ },
346
+ formatMessages: (...args: Parameters<typeof _esbuildWasm.formatMessages>) => {
347
+ return _esbuildWasm.formatMessages(...args);
348
+ },
349
+ analyzeMetafile: (
350
+ ...args: Parameters<typeof _esbuildWasm.analyzeMetafile>
351
+ ) => {
352
+ return _esbuildWasm.analyzeMetafile(...args);
353
+ },
354
+ stop: () => _esbuildWasm.stop(),
355
+ version: _esbuildWasm.version,
356
+ };
357
+
358
+ // --- fsevents ---
359
+
360
+ export const fsevents = (() => {
361
+ warnStub("fsevents");
362
+ return {
363
+ watch: () => ({ stop() {} }),
364
+ getInfo: () => ({ event: "", path: "", type: "", changes: {} }),
365
+ constants: {
366
+ None: 0,
367
+ MustScanSubDirs: 1,
368
+ UserDropped: 2,
369
+ KernelDropped: 4,
370
+ EventIdsWrapped: 8,
371
+ },
372
+ };
373
+ })();
374
+
375
+ // --- http2 ---
376
+
377
+ export const http2 = (() => {
378
+ warnStub("http2");
379
+ return {
380
+ createServer: () => ({ listen() {}, close() {}, on() {} }),
381
+ createSecureServer: () => ({ listen() {}, close() {}, on() {} }),
382
+ connect: () => ({ on() {}, close() {} }),
383
+ getDefaultSettings: () => ({}),
384
+ getPackedSettings: () => new Uint8Array(0),
385
+ getUnpackedSettings: () => ({}),
386
+ constants: {
387
+ NGHTTP2_SESSION_SERVER: 0,
388
+ NGHTTP2_SESSION_CLIENT: 1,
389
+ HTTP2_HEADER_STATUS: ":status",
390
+ HTTP2_HEADER_METHOD: ":method",
391
+ HTTP2_HEADER_PATH: ":path",
392
+ },
393
+ sensitiveHeaders: Symbol("sensitiveHeaders"),
394
+ };
395
+ })();
396
+
397
+ // --- inspector ---
398
+
399
+ export const inspector = (() => {
400
+ warnStub("inspector");
401
+ return {
402
+ Session: class {
403
+ connect() {}
404
+ connectToMainThread() {}
405
+ disconnect() {}
406
+ post(_m: string, _p?: unknown, cb?: () => void) {
407
+ if (cb) setTimeout(cb, 0);
408
+ }
409
+ on() {}
410
+ },
411
+ open() {},
412
+ close() {},
413
+ url: () => undefined as string | undefined,
414
+ waitForDebugger() {},
415
+ console: globalThis.console,
416
+ };
417
+ })();
418
+
419
+ // --- rollup ---
420
+
421
+ function rollupParseAst(code: string, _options?: Record<string, unknown>) {
422
+ // Use acorn as the parser (ESTree-compatible like Rollup's native parser)
423
+ try {
424
+ const acorn = require("acorn");
425
+ if (acorn && acorn.parse) {
426
+ return acorn.parse(code, {
427
+ ecmaVersion: "latest",
428
+ sourceType: "module",
429
+ allowReturnOutsideFunction: true,
430
+ locations: true,
431
+ });
432
+ }
433
+ } catch {}
434
+ return { type: "Program", body: [], sourceType: "module" };
435
+ }
436
+
437
+ export const rollup_stub = {
438
+ async rollup() {
439
+ return {
440
+ async generate() {
441
+ return { output: [] };
442
+ },
443
+ async write() {
444
+ return { output: [] };
445
+ },
446
+ async close() {},
447
+ };
448
+ },
449
+ watch: () => ({ on() {}, close() {} }),
450
+ VERSION: "4.0.0",
451
+ parseAst: rollupParseAst,
452
+ parseAstAsync: async (code: string, opts?: Record<string, unknown>) =>
453
+ rollupParseAst(code, opts),
454
+ };
455
+
456
+ export const rollup_parseAst_stub = {
457
+ parseAst: rollupParseAst,
458
+ parseAstAsync: async (code: string, opts?: Record<string, unknown>) =>
459
+ rollupParseAst(code, opts),
460
+ };
461
+
462
+ export const rollup_native_stub = {
463
+ parse: rollupParseAst,
464
+ parseAsync: async (code: string, opts?: Record<string, unknown>) =>
465
+ rollupParseAst(code, opts),
466
+ };
467
+
468
+ // --- tls ---
469
+
470
+ export const tls = (() => {
471
+ warnStub("tls");
472
+ return {
473
+ TLSSocket: class TLSSocket extends EventEmitter {
474
+ authorized = true;
475
+ encrypted = true;
476
+ },
477
+ connect: (_opts: unknown, cb?: () => void) => {
478
+ const s = new EventEmitter();
479
+ if (cb) setTimeout(cb, 0);
480
+ return s;
481
+ },
482
+ createServer: () => ({ listen() {}, close() {}, on() {} }),
483
+ createSecureContext: () => ({}),
484
+ DEFAULT_MIN_VERSION: "TLSv1.2",
485
+ DEFAULT_MAX_VERSION: "TLSv1.3",
486
+ DEFAULT_ECDH_CURVE: "auto",
487
+ rootCertificates: [] as string[],
488
+ };
489
+ })();
490
+
491
+ // --- worker_threads ---
492
+
493
+ export const worker_threads = (() => {
494
+ warnStub("worker_threads");
495
+ let nextThreadId = 1;
496
+
497
+ class WTMessagePort extends EventEmitter {
498
+ #peer: WTMessagePort | null = null;
499
+ #started = false;
500
+
501
+ postMessage(value: unknown) {
502
+ if (this.#peer) {
503
+ const target = this.#peer;
504
+ setTimeout(() => target.emit("message", value), 0);
505
+ }
506
+ }
507
+ close() {
508
+ this.#peer = null;
509
+ this.emit("close");
510
+ }
511
+ start() {
512
+ this.#started = true;
513
+ }
514
+ ref() {
515
+ return this;
516
+ }
517
+ unref() {
518
+ return this;
519
+ }
520
+
521
+ static createPair(): [WTMessagePort, WTMessagePort] {
522
+ const a = new WTMessagePort();
523
+ const b = new WTMessagePort();
524
+ a.#peer = b;
525
+ b.#peer = a;
526
+ return [a, b];
527
+ }
528
+ }
529
+
530
+ class WTMessageChannel {
531
+ port1: WTMessagePort;
532
+ port2: WTMessagePort;
533
+ constructor() {
534
+ [this.port1, this.port2] = WTMessagePort.createPair();
535
+ }
536
+ }
537
+
538
+ class Worker extends EventEmitter {
539
+ threadId: number;
540
+ #parentPort: WTMessagePort;
541
+ #childPort: WTMessagePort;
542
+
543
+ constructor(_filename: string, _opts?: Record<string, unknown>) {
544
+ super();
545
+ this.threadId = nextThreadId++;
546
+ [this.#parentPort, this.#childPort] = WTMessagePort.createPair();
547
+
548
+ this.#parentPort.on("message", (msg: unknown) => {
549
+ this.emit("message", msg);
550
+ });
551
+ }
552
+
553
+ postMessage(value: unknown) {
554
+ this.#parentPort.postMessage(value);
555
+ }
556
+
557
+ terminate() {
558
+ this.#parentPort.close();
559
+ this.#childPort.close();
560
+ this.emit("exit", 0);
561
+ return Promise.resolve(0);
562
+ }
563
+
564
+ ref() {
565
+ return this;
566
+ }
567
+ unref() {
568
+ return this;
569
+ }
570
+
571
+ getChildPort(): WTMessagePort {
572
+ return this.#childPort;
573
+ }
574
+ }
575
+
576
+ class BroadcastChannel extends EventEmitter {
577
+ name: string;
578
+ constructor(name: string) {
579
+ super();
580
+ this.name = name;
581
+ }
582
+ postMessage() {}
583
+ close() {}
584
+ }
585
+
586
+ return {
587
+ isMainThread: true,
588
+ parentPort: null as WTMessagePort | null,
589
+ workerData: null as unknown,
590
+ threadId: 0,
591
+ resourceLimits: {},
592
+ Worker,
593
+ MessageChannel: WTMessageChannel,
594
+ MessagePort: WTMessagePort,
595
+ BroadcastChannel,
596
+ markAsUntransferable() {},
597
+ moveMessagePortToContext: (p: unknown) => p,
598
+ receiveMessageOnPort: () => undefined,
599
+ };
600
+ })();
@@ -0,0 +1,43 @@
1
+ import { Readable, Writable } from "./stream";
2
+
3
+ export class ReadStream extends Readable {
4
+ isTTY = true;
5
+ isRaw = false;
6
+ setRawMode(mode: boolean): this {
7
+ this.isRaw = mode;
8
+ return this;
9
+ }
10
+ }
11
+
12
+ export class WriteStream extends Writable {
13
+ isTTY = true;
14
+ columns = 80;
15
+ rows = 24;
16
+ getColorDepth(): number {
17
+ return 8;
18
+ }
19
+ hasColors(count?: number): boolean {
20
+ return (count || 1) <= 256;
21
+ }
22
+ getWindowSize(): [number, number] {
23
+ return [this.columns, this.rows];
24
+ }
25
+ clearLine(_dir: number, _cb?: () => void): boolean {
26
+ return true;
27
+ }
28
+ clearScreenDown(_cb?: () => void): boolean {
29
+ return true;
30
+ }
31
+ cursorTo(_x: number, _y?: number, _cb?: () => void): boolean {
32
+ return true;
33
+ }
34
+ moveCursor(_dx: number, _dy: number, _cb?: () => void): boolean {
35
+ return true;
36
+ }
37
+ }
38
+
39
+ export function isatty(_fd: number): boolean {
40
+ return false;
41
+ }
42
+
43
+ export default { ReadStream, WriteStream, isatty };