@scelar/nodepod 1.0.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 (134) hide show
  1. package/LICENSE +43 -0
  2. package/README.md +240 -0
  3. package/dist/child_process-BJOMsZje.js +8233 -0
  4. package/dist/child_process-BJOMsZje.js.map +1 -0
  5. package/dist/child_process-Cj8vOcuc.cjs +7434 -0
  6. package/dist/child_process-Cj8vOcuc.cjs.map +1 -0
  7. package/dist/index-Cb1Cgdnd.js +35308 -0
  8. package/dist/index-Cb1Cgdnd.js.map +1 -0
  9. package/dist/index-DsMGS-xc.cjs +37195 -0
  10. package/dist/index-DsMGS-xc.cjs.map +1 -0
  11. package/dist/index.cjs +65 -0
  12. package/dist/index.cjs.map +1 -0
  13. package/dist/index.mjs +59 -0
  14. package/dist/index.mjs.map +1 -0
  15. package/package.json +95 -0
  16. package/src/__tests__/smoke.test.ts +11 -0
  17. package/src/constants/cdn-urls.ts +18 -0
  18. package/src/constants/config.ts +236 -0
  19. package/src/cross-origin.ts +26 -0
  20. package/src/engine-factory.ts +176 -0
  21. package/src/engine-types.ts +56 -0
  22. package/src/helpers/byte-encoding.ts +39 -0
  23. package/src/helpers/digest.ts +9 -0
  24. package/src/helpers/event-loop.ts +96 -0
  25. package/src/helpers/wasm-cache.ts +133 -0
  26. package/src/iframe-sandbox.ts +141 -0
  27. package/src/index.ts +192 -0
  28. package/src/isolation-helpers.ts +148 -0
  29. package/src/memory-volume.ts +941 -0
  30. package/src/module-transformer.ts +368 -0
  31. package/src/packages/archive-extractor.ts +248 -0
  32. package/src/packages/browser-bundler.ts +284 -0
  33. package/src/packages/installer.ts +396 -0
  34. package/src/packages/registry-client.ts +131 -0
  35. package/src/packages/version-resolver.ts +411 -0
  36. package/src/polyfills/assert.ts +384 -0
  37. package/src/polyfills/async_hooks.ts +144 -0
  38. package/src/polyfills/buffer.ts +628 -0
  39. package/src/polyfills/child_process.ts +2288 -0
  40. package/src/polyfills/chokidar.ts +336 -0
  41. package/src/polyfills/cluster.ts +106 -0
  42. package/src/polyfills/console.ts +136 -0
  43. package/src/polyfills/constants.ts +123 -0
  44. package/src/polyfills/crypto.ts +885 -0
  45. package/src/polyfills/dgram.ts +87 -0
  46. package/src/polyfills/diagnostics_channel.ts +76 -0
  47. package/src/polyfills/dns.ts +134 -0
  48. package/src/polyfills/domain.ts +68 -0
  49. package/src/polyfills/esbuild.ts +854 -0
  50. package/src/polyfills/events.ts +276 -0
  51. package/src/polyfills/fs.ts +2888 -0
  52. package/src/polyfills/fsevents.ts +79 -0
  53. package/src/polyfills/http.ts +1449 -0
  54. package/src/polyfills/http2.ts +199 -0
  55. package/src/polyfills/https.ts +76 -0
  56. package/src/polyfills/inspector.ts +62 -0
  57. package/src/polyfills/lightningcss.ts +105 -0
  58. package/src/polyfills/module.ts +191 -0
  59. package/src/polyfills/net.ts +353 -0
  60. package/src/polyfills/os.ts +238 -0
  61. package/src/polyfills/path.ts +206 -0
  62. package/src/polyfills/perf_hooks.ts +102 -0
  63. package/src/polyfills/process.ts +690 -0
  64. package/src/polyfills/punycode.ts +159 -0
  65. package/src/polyfills/querystring.ts +93 -0
  66. package/src/polyfills/quic.ts +118 -0
  67. package/src/polyfills/readdirp.ts +229 -0
  68. package/src/polyfills/readline.ts +692 -0
  69. package/src/polyfills/repl.ts +134 -0
  70. package/src/polyfills/rollup.ts +119 -0
  71. package/src/polyfills/sea.ts +33 -0
  72. package/src/polyfills/sqlite.ts +78 -0
  73. package/src/polyfills/stream.ts +1620 -0
  74. package/src/polyfills/string_decoder.ts +25 -0
  75. package/src/polyfills/tailwindcss-oxide.ts +309 -0
  76. package/src/polyfills/test.ts +197 -0
  77. package/src/polyfills/timers.ts +32 -0
  78. package/src/polyfills/tls.ts +105 -0
  79. package/src/polyfills/trace_events.ts +50 -0
  80. package/src/polyfills/tty.ts +71 -0
  81. package/src/polyfills/url.ts +174 -0
  82. package/src/polyfills/util.ts +559 -0
  83. package/src/polyfills/v8.ts +126 -0
  84. package/src/polyfills/vm.ts +132 -0
  85. package/src/polyfills/volume-registry.ts +15 -0
  86. package/src/polyfills/wasi.ts +44 -0
  87. package/src/polyfills/worker_threads.ts +326 -0
  88. package/src/polyfills/ws.ts +595 -0
  89. package/src/polyfills/zlib.ts +881 -0
  90. package/src/request-proxy.ts +716 -0
  91. package/src/script-engine.ts +3375 -0
  92. package/src/sdk/nodepod-fs.ts +93 -0
  93. package/src/sdk/nodepod-process.ts +86 -0
  94. package/src/sdk/nodepod-terminal.ts +350 -0
  95. package/src/sdk/nodepod.ts +509 -0
  96. package/src/sdk/types.ts +70 -0
  97. package/src/shell/commands/bun.ts +121 -0
  98. package/src/shell/commands/directory.ts +297 -0
  99. package/src/shell/commands/file-ops.ts +525 -0
  100. package/src/shell/commands/git.ts +2142 -0
  101. package/src/shell/commands/node.ts +80 -0
  102. package/src/shell/commands/npm.ts +198 -0
  103. package/src/shell/commands/pm-types.ts +45 -0
  104. package/src/shell/commands/pnpm.ts +82 -0
  105. package/src/shell/commands/search.ts +264 -0
  106. package/src/shell/commands/shell-env.ts +352 -0
  107. package/src/shell/commands/text-processing.ts +1152 -0
  108. package/src/shell/commands/yarn.ts +84 -0
  109. package/src/shell/shell-builtins.ts +19 -0
  110. package/src/shell/shell-helpers.ts +250 -0
  111. package/src/shell/shell-interpreter.ts +514 -0
  112. package/src/shell/shell-parser.ts +429 -0
  113. package/src/shell/shell-types.ts +85 -0
  114. package/src/syntax-transforms.ts +561 -0
  115. package/src/threading/engine-worker.ts +64 -0
  116. package/src/threading/inline-worker.ts +372 -0
  117. package/src/threading/offload-types.ts +112 -0
  118. package/src/threading/offload-worker.ts +383 -0
  119. package/src/threading/offload.ts +271 -0
  120. package/src/threading/process-context.ts +92 -0
  121. package/src/threading/process-handle.ts +275 -0
  122. package/src/threading/process-manager.ts +956 -0
  123. package/src/threading/process-worker-entry.ts +854 -0
  124. package/src/threading/shared-vfs.ts +352 -0
  125. package/src/threading/sync-channel.ts +135 -0
  126. package/src/threading/task-queue.ts +177 -0
  127. package/src/threading/vfs-bridge.ts +231 -0
  128. package/src/threading/worker-pool.ts +233 -0
  129. package/src/threading/worker-protocol.ts +358 -0
  130. package/src/threading/worker-vfs.ts +218 -0
  131. package/src/types/externals.d.ts +38 -0
  132. package/src/types/fs-streams.ts +142 -0
  133. package/src/types/manifest.ts +17 -0
  134. package/src/worker-sandbox.ts +90 -0
@@ -0,0 +1,358 @@
1
+ // Worker Protocol — typed messages for main<->worker communication.
2
+ // Flows via postMessage. Binary data (VFS snapshots) transferred zero-copy.
3
+
4
+ // --- VFS snapshot (binary transfer) ---
5
+
6
+ export interface VFSBinarySnapshot {
7
+ manifest: VFSSnapshotEntry[];
8
+ data: ArrayBuffer;
9
+ }
10
+
11
+ export interface VFSSnapshotEntry {
12
+ path: string;
13
+ offset: number;
14
+ length: number;
15
+ isDirectory: boolean;
16
+ }
17
+
18
+ // --- Main -> Worker messages ---
19
+
20
+ export interface MainToWorker_Init {
21
+ type: "init";
22
+ pid: number;
23
+ cwd: string;
24
+ env: Record<string, string>;
25
+ snapshot: VFSBinarySnapshot;
26
+ sharedBuffer?: SharedArrayBuffer;
27
+ syncBuffer?: SharedArrayBuffer;
28
+ }
29
+
30
+ export interface MainToWorker_Exec {
31
+ type: "exec";
32
+ filePath: string;
33
+ args: string[];
34
+ cwd?: string;
35
+ env?: Record<string, string>;
36
+ isShell?: boolean;
37
+ shellCommand?: string;
38
+ isFork?: boolean;
39
+ // If true, worker sends "shell-done" instead of "exit" and stays alive
40
+ persistent?: boolean;
41
+ isWorkerThread?: boolean;
42
+ workerData?: unknown;
43
+ threadId?: number;
44
+ }
45
+
46
+ export interface MainToWorker_Stdin {
47
+ type: "stdin";
48
+ data: string;
49
+ }
50
+
51
+ export interface MainToWorker_Signal {
52
+ type: "signal";
53
+ signal: string;
54
+ }
55
+
56
+ export interface MainToWorker_Resize {
57
+ type: "resize";
58
+ cols: number;
59
+ rows: number;
60
+ }
61
+
62
+ export interface MainToWorker_VFSSync {
63
+ type: "vfs-sync";
64
+ path: string;
65
+ content: ArrayBuffer | null; // null = deleted
66
+ isDirectory: boolean;
67
+ }
68
+
69
+ export interface MainToWorker_VFSChunk {
70
+ type: "vfs-chunk";
71
+ chunkIndex: number;
72
+ totalChunks: number;
73
+ data: ArrayBuffer;
74
+ manifest: VFSSnapshotEntry[];
75
+ }
76
+
77
+ export interface MainToWorker_SpawnResult {
78
+ type: "spawn-result";
79
+ requestId: number;
80
+ pid: number;
81
+ error?: string;
82
+ }
83
+
84
+ export interface MainToWorker_ChildOutput {
85
+ type: "child-output";
86
+ requestId: number;
87
+ stream: "stdout" | "stderr";
88
+ data: string;
89
+ }
90
+
91
+ export interface MainToWorker_ChildExit {
92
+ type: "child-exit";
93
+ requestId: number;
94
+ exitCode: number;
95
+ stdout: string;
96
+ stderr: string;
97
+ }
98
+
99
+ export interface MainToWorker_HttpRequest {
100
+ type: "http-request";
101
+ requestId: number;
102
+ port: number;
103
+ method: string;
104
+ path: string;
105
+ headers: Record<string, string>;
106
+ body: string | null;
107
+ }
108
+
109
+ export interface MainToWorker_IPC {
110
+ type: "ipc-message";
111
+ data: unknown;
112
+ // Routes to a specific fork callback when sent to a parent worker
113
+ targetRequestId?: number;
114
+ }
115
+
116
+ export interface MainToWorker_WsUpgrade {
117
+ type: "ws-upgrade";
118
+ uid: string;
119
+ port: number;
120
+ path: string;
121
+ headers: Record<string, string>;
122
+ }
123
+
124
+ export interface MainToWorker_WsData {
125
+ type: "ws-data";
126
+ uid: string;
127
+ frame: number[]; // encoded WS frame bytes (number[] for postMessage)
128
+ }
129
+
130
+ export interface MainToWorker_WsClose {
131
+ type: "ws-close";
132
+ uid: string;
133
+ code: number;
134
+ }
135
+
136
+ export type MainToWorkerMessage =
137
+ | MainToWorker_Init
138
+ | MainToWorker_Exec
139
+ | MainToWorker_Stdin
140
+ | MainToWorker_Signal
141
+ | MainToWorker_Resize
142
+ | MainToWorker_VFSSync
143
+ | MainToWorker_VFSChunk
144
+ | MainToWorker_SpawnResult
145
+ | MainToWorker_ChildOutput
146
+ | MainToWorker_ChildExit
147
+ | MainToWorker_HttpRequest
148
+ | MainToWorker_IPC
149
+ | MainToWorker_WsUpgrade
150
+ | MainToWorker_WsData
151
+ | MainToWorker_WsClose;
152
+
153
+ // --- Worker -> Main messages ---
154
+
155
+ export interface WorkerToMain_Ready {
156
+ type: "ready";
157
+ pid: number;
158
+ }
159
+
160
+ export interface WorkerToMain_Stdout {
161
+ type: "stdout";
162
+ data: string;
163
+ }
164
+
165
+ export interface WorkerToMain_Stderr {
166
+ type: "stderr";
167
+ data: string;
168
+ }
169
+
170
+ export interface WorkerToMain_Exit {
171
+ type: "exit";
172
+ exitCode: number;
173
+ stdout: string;
174
+ stderr: string;
175
+ }
176
+
177
+ export interface WorkerToMain_Console {
178
+ type: "console";
179
+ method: string;
180
+ args: string[];
181
+ }
182
+
183
+ export interface WorkerToMain_VFSWrite {
184
+ type: "vfs-write";
185
+ path: string;
186
+ content: ArrayBuffer;
187
+ isDirectory: boolean;
188
+ }
189
+
190
+ export interface WorkerToMain_VFSDelete {
191
+ type: "vfs-delete";
192
+ path: string;
193
+ }
194
+
195
+ export interface WorkerToMain_VFSRead {
196
+ type: "vfs-read";
197
+ requestId: number;
198
+ path: string;
199
+ }
200
+
201
+ export interface WorkerToMain_SpawnRequest {
202
+ type: "spawn-request";
203
+ requestId: number;
204
+ command: string;
205
+ args: string[];
206
+ cwd: string;
207
+ env: Record<string, string>;
208
+ stdio: "pipe" | "inherit";
209
+ }
210
+
211
+ export interface WorkerToMain_ForkRequest {
212
+ type: "fork-request";
213
+ requestId: number;
214
+ modulePath: string;
215
+ args: string[];
216
+ cwd: string;
217
+ env: Record<string, string>;
218
+ }
219
+
220
+ export interface WorkerToMain_WorkerThreadRequest {
221
+ type: "workerthread-request";
222
+ requestId: number;
223
+ modulePath: string; // absolute path, or inline code if isEval
224
+ isEval?: boolean;
225
+ args: string[];
226
+ cwd: string;
227
+ env: Record<string, string>;
228
+ workerData: unknown;
229
+ threadId: number;
230
+ }
231
+
232
+ export interface WorkerToMain_SpawnSync {
233
+ type: "spawn-sync";
234
+ requestId: number;
235
+ command: string;
236
+ args: string[];
237
+ cwd: string;
238
+ env: Record<string, string>;
239
+ syncSlot: number; // index in the sync SAB for Atomics.wait/notify
240
+ shellCommand?: string;
241
+ }
242
+
243
+ export interface WorkerToMain_ServerListen {
244
+ type: "server-listen";
245
+ port: number;
246
+ hostname: string;
247
+ }
248
+
249
+ export interface WorkerToMain_ServerClose {
250
+ type: "server-close";
251
+ port: number;
252
+ }
253
+
254
+ export interface WorkerToMain_HttpRequest {
255
+ type: "http-request";
256
+ requestId: number;
257
+ port: number;
258
+ method: string;
259
+ path: string;
260
+ headers: Record<string, string>;
261
+ body: string | null;
262
+ }
263
+
264
+ export interface WorkerToMain_CwdChange {
265
+ type: "cwd-change";
266
+ cwd: string;
267
+ }
268
+
269
+ export interface WorkerToMain_StdinRawStatus {
270
+ type: "stdin-raw-status";
271
+ isRaw: boolean;
272
+ }
273
+
274
+ export interface WorkerToMain_HttpResponse {
275
+ type: "http-response";
276
+ requestId: number;
277
+ statusCode: number;
278
+ statusMessage: string;
279
+ headers: Record<string, string>;
280
+ body: string;
281
+ }
282
+
283
+ export interface WorkerToMain_IPC {
284
+ type: "ipc-message";
285
+ data: unknown;
286
+ targetRequestId?: number;
287
+ }
288
+
289
+ export interface WorkerToMain_ShellDone {
290
+ type: "shell-done";
291
+ exitCode: number;
292
+ stdout: string;
293
+ stderr: string;
294
+ }
295
+
296
+ export interface WorkerToMain_Error {
297
+ type: "error";
298
+ message: string;
299
+ stack?: string;
300
+ }
301
+
302
+ export interface WorkerToMain_WsFrame {
303
+ type: "ws-frame";
304
+ uid: string;
305
+ kind: string; // "open" | "text" | "binary" | "close" | "error"
306
+ data?: string;
307
+ bytes?: number[];
308
+ code?: number;
309
+ message?: string;
310
+ }
311
+
312
+ export type WorkerToMainMessage =
313
+ | WorkerToMain_Ready
314
+ | WorkerToMain_Stdout
315
+ | WorkerToMain_Stderr
316
+ | WorkerToMain_Exit
317
+ | WorkerToMain_Console
318
+ | WorkerToMain_VFSWrite
319
+ | WorkerToMain_VFSDelete
320
+ | WorkerToMain_VFSRead
321
+ | WorkerToMain_SpawnRequest
322
+ | WorkerToMain_ForkRequest
323
+ | WorkerToMain_WorkerThreadRequest
324
+ | WorkerToMain_SpawnSync
325
+ | WorkerToMain_ServerListen
326
+ | WorkerToMain_ServerClose
327
+ | WorkerToMain_HttpRequest
328
+ | WorkerToMain_CwdChange
329
+ | WorkerToMain_StdinRawStatus
330
+ | WorkerToMain_HttpResponse
331
+ | WorkerToMain_IPC
332
+ | WorkerToMain_ShellDone
333
+ | WorkerToMain_Error
334
+ | WorkerToMain_WsFrame;
335
+
336
+ // --- Spawn config ---
337
+
338
+ export interface SpawnConfig {
339
+ command: string;
340
+ args: string[];
341
+ cwd: string;
342
+ env: Record<string, string>;
343
+ snapshot: VFSBinarySnapshot;
344
+ sharedBuffer?: SharedArrayBuffer;
345
+ syncBuffer?: SharedArrayBuffer;
346
+ parentPid?: number;
347
+ }
348
+
349
+ // --- Process info ---
350
+
351
+ export interface ProcessInfo {
352
+ pid: number;
353
+ command: string;
354
+ args: string[];
355
+ state: "starting" | "running" | "exited";
356
+ exitCode?: number;
357
+ parentPid?: number;
358
+ }
@@ -0,0 +1,218 @@
1
+ // WorkerVFS — worker-side filesystem proxy.
2
+ // Reads are instant (local Map). Writes go to both local store + main thread.
3
+
4
+ import type { VFSBinarySnapshot, VFSSnapshotEntry } from "./worker-protocol";
5
+
6
+ export class WorkerVFS {
7
+ private _files = new Map<string, Uint8Array>();
8
+ private _dirs = new Set<string>();
9
+ private _onWrite: ((path: string, content: Uint8Array, isDir: boolean) => void) | null = null;
10
+ private _onDelete: ((path: string) => void) | null = null;
11
+ private _decoder = new TextDecoder();
12
+ private _encoder = new TextEncoder();
13
+
14
+ constructor() {
15
+ this._dirs.add("/");
16
+ }
17
+
18
+ initFromSnapshot(snapshot: VFSBinarySnapshot): void {
19
+ const data = new Uint8Array(snapshot.data);
20
+
21
+ for (const entry of snapshot.manifest) {
22
+ if (entry.isDirectory) {
23
+ this._dirs.add(entry.path);
24
+ } else {
25
+ this._files.set(entry.path, data.slice(entry.offset, entry.offset + entry.length));
26
+ this._ensureParentDirs(entry.path);
27
+ }
28
+ }
29
+ }
30
+
31
+ setWriteCallback(cb: (path: string, content: Uint8Array, isDir: boolean) => void): void {
32
+ this._onWrite = cb;
33
+ }
34
+
35
+ setDeleteCallback(cb: (path: string) => void): void {
36
+ this._onDelete = cb;
37
+ }
38
+
39
+ readFileSync(path: string, encoding?: string): string | Uint8Array {
40
+ const data = this._files.get(path);
41
+ if (!data) {
42
+ const err = new Error(`ENOENT: no such file or directory, open '${path}'`) as Error & { code: string; errno: number };
43
+ err.code = "ENOENT";
44
+ err.errno = -2;
45
+ throw err;
46
+ }
47
+ if (encoding === "utf8" || encoding === "utf-8") {
48
+ return this._decoder.decode(data);
49
+ }
50
+ return new Uint8Array(data);
51
+ }
52
+
53
+ existsSync(path: string): boolean {
54
+ return this._files.has(path) || this._dirs.has(path);
55
+ }
56
+
57
+ statSync(path: string): { isFile: () => boolean; isDirectory: () => boolean; size: number } {
58
+ if (this._dirs.has(path)) {
59
+ return {
60
+ isFile: () => false,
61
+ isDirectory: () => true,
62
+ size: 0,
63
+ };
64
+ }
65
+ const data = this._files.get(path);
66
+ if (data) {
67
+ return {
68
+ isFile: () => true,
69
+ isDirectory: () => false,
70
+ size: data.byteLength,
71
+ };
72
+ }
73
+ const err = new Error(`ENOENT: no such file or directory, stat '${path}'`) as Error & { code: string; errno: number };
74
+ err.code = "ENOENT";
75
+ err.errno = -2;
76
+ throw err;
77
+ }
78
+
79
+ readdirSync(path: string): string[] {
80
+ if (!this._dirs.has(path)) {
81
+ const err = new Error(`ENOENT: no such file or directory, scandir '${path}'`) as Error & { code: string; errno: number };
82
+ err.code = "ENOENT";
83
+ err.errno = -2;
84
+ throw err;
85
+ }
86
+
87
+ const prefix = path === "/" ? "/" : path + "/";
88
+ const entries = new Set<string>();
89
+
90
+ for (const filePath of this._files.keys()) {
91
+ if (filePath.startsWith(prefix)) {
92
+ const rest = filePath.slice(prefix.length);
93
+ const slashIdx = rest.indexOf("/");
94
+ entries.add(slashIdx === -1 ? rest : rest.slice(0, slashIdx));
95
+ }
96
+ }
97
+
98
+ for (const dirPath of this._dirs) {
99
+ if (dirPath.startsWith(prefix) && dirPath !== path) {
100
+ const rest = dirPath.slice(prefix.length);
101
+ const slashIdx = rest.indexOf("/");
102
+ entries.add(slashIdx === -1 ? rest : rest.slice(0, slashIdx));
103
+ }
104
+ }
105
+
106
+ return Array.from(entries).filter(Boolean).sort();
107
+ }
108
+
109
+ writeFileSync(path: string, content: string | Uint8Array): void {
110
+ const bytes = typeof content === "string" ? this._encoder.encode(content) : new Uint8Array(content);
111
+ this._files.set(path, bytes);
112
+ this._ensureParentDirs(path);
113
+ if (this._onWrite) this._onWrite(path, bytes, false);
114
+ }
115
+
116
+ mkdirSync(path: string, opts?: { recursive?: boolean }): void {
117
+ if (this._dirs.has(path)) return;
118
+ if (opts?.recursive) {
119
+ const parts = path.split("/").filter(Boolean);
120
+ let current = "";
121
+ for (const part of parts) {
122
+ current += "/" + part;
123
+ if (!this._dirs.has(current)) {
124
+ this._dirs.add(current);
125
+ if (this._onWrite) this._onWrite(current, new Uint8Array(0), true);
126
+ }
127
+ }
128
+ } else {
129
+ this._dirs.add(path);
130
+ if (this._onWrite) this._onWrite(path, new Uint8Array(0), true);
131
+ }
132
+ }
133
+
134
+ unlinkSync(path: string): void {
135
+ if (!this._files.has(path)) {
136
+ const err = new Error(`ENOENT: no such file or directory, unlink '${path}'`) as Error & { code: string; errno: number };
137
+ err.code = "ENOENT";
138
+ err.errno = -2;
139
+ throw err;
140
+ }
141
+ this._files.delete(path);
142
+ if (this._onDelete) this._onDelete(path);
143
+ }
144
+
145
+ rmdirSync(path: string): void {
146
+ this._dirs.delete(path);
147
+ if (this._onDelete) this._onDelete(path);
148
+ }
149
+
150
+ renameSync(src: string, dest: string): void {
151
+ const data = this._files.get(src);
152
+ if (data) {
153
+ this._files.delete(src);
154
+ this._files.set(dest, data);
155
+ if (this._onDelete) this._onDelete(src);
156
+ if (this._onWrite) this._onWrite(dest, data, false);
157
+ } else if (this._dirs.has(src)) {
158
+ this._dirs.delete(src);
159
+ this._dirs.add(dest);
160
+ if (this._onDelete) this._onDelete(src);
161
+ if (this._onWrite) this._onWrite(dest, new Uint8Array(0), true);
162
+ }
163
+ }
164
+
165
+ appendFileSync(path: string, content: string | Uint8Array): void {
166
+ const existing = this._files.get(path) ?? new Uint8Array(0);
167
+ const bytes = typeof content === "string" ? this._encoder.encode(content) : new Uint8Array(content);
168
+ const merged = new Uint8Array(existing.byteLength + bytes.byteLength);
169
+ merged.set(existing, 0);
170
+ merged.set(bytes, existing.byteLength);
171
+ this._files.set(path, merged);
172
+ this._ensureParentDirs(path);
173
+ if (this._onWrite) this._onWrite(path, merged, false);
174
+ }
175
+
176
+ copyFileSync(src: string, dest: string): void {
177
+ const data = this._files.get(src);
178
+ if (!data) {
179
+ const err = new Error(`ENOENT: no such file or directory, copyfile '${src}'`) as Error & { code: string; errno: number };
180
+ err.code = "ENOENT";
181
+ err.errno = -2;
182
+ throw err;
183
+ }
184
+ const copy = new Uint8Array(data);
185
+ this._files.set(dest, copy);
186
+ this._ensureParentDirs(dest);
187
+ if (this._onWrite) this._onWrite(dest, copy, false);
188
+ }
189
+
190
+ applySync(path: string, content: ArrayBuffer | null, isDirectory: boolean): void {
191
+ if (content === null) {
192
+ this._files.delete(path);
193
+ this._dirs.delete(path);
194
+ } else if (isDirectory) {
195
+ this._dirs.add(path);
196
+ } else {
197
+ this._files.set(path, new Uint8Array(content));
198
+ this._ensureParentDirs(path);
199
+ }
200
+ }
201
+
202
+ private _ensureParentDirs(path: string): void {
203
+ const parts = path.split("/").filter(Boolean);
204
+ let current = "";
205
+ for (let i = 0; i < parts.length - 1; i++) {
206
+ current += "/" + parts[i];
207
+ this._dirs.add(current);
208
+ }
209
+ }
210
+
211
+ get fileCount(): number {
212
+ return this._files.size;
213
+ }
214
+
215
+ get dirCount(): number {
216
+ return this._dirs.size;
217
+ }
218
+ }
@@ -0,0 +1,38 @@
1
+ interface EsbuildTransformConfig {
2
+ loader?: string;
3
+ jsx?: string;
4
+ jsxFactory?: string;
5
+ jsxFragment?: string;
6
+ jsxImportSource?: string;
7
+ sourcemap?: boolean | 'inline' | 'external' | 'both';
8
+ sourcefile?: string;
9
+ target?: string | string[];
10
+ format?: 'iife' | 'cjs' | 'esm';
11
+ minify?: boolean;
12
+ tsconfigRaw?: string | object;
13
+ platform?: 'browser' | 'node' | 'neutral';
14
+ define?: Record<string, string>;
15
+ }
16
+
17
+ interface EsbuildTransformOutput {
18
+ code: string;
19
+ map: string;
20
+ warnings: unknown[];
21
+ }
22
+
23
+ declare module 'esbuild-wasm' {
24
+ export function initialize(options?: { wasmURL?: string; worker?: boolean }): Promise<void>;
25
+ export function transform(input: string, options?: EsbuildTransformConfig): Promise<EsbuildTransformOutput>;
26
+ export function build(options: unknown): Promise<unknown>;
27
+ export function formatMessages(messages: unknown[], options: unknown): Promise<string[]>;
28
+ export const version: string;
29
+ }
30
+
31
+ interface Window {
32
+ __esbuildEngine?: typeof import('esbuild-wasm');
33
+ __esbuildReady?: Promise<void>;
34
+ }
35
+
36
+ declare module 'virtual:process-worker-bundle' {
37
+ export const PROCESS_WORKER_BUNDLE: string;
38
+ }