@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,142 @@
1
+ // Types for fs ReadStream/WriteStream. These are old-style function constructors
2
+ // (not classes) because graceful-fs uses .apply(this, arguments) which breaks classes.
3
+
4
+ /* ---- ReadableState ---- */
5
+
6
+ export interface FsReadableState {
7
+ readonly objectMode: boolean;
8
+ readonly highWaterMark: number;
9
+ readonly ended: boolean;
10
+ endEmitted: boolean;
11
+ flowing: boolean | null;
12
+ readonly reading: boolean;
13
+ readonly length: number;
14
+ readonly destroyed: boolean;
15
+ readonly errored: Error | null;
16
+ readonly closed: boolean;
17
+ pipes: unknown[];
18
+ awaitDrainWriters: unknown;
19
+ multiAwaitDrain: boolean;
20
+ readableListening: boolean;
21
+ resumeScheduled: boolean;
22
+ paused: boolean;
23
+ emitClose: boolean;
24
+ readonly autoDestroy: boolean;
25
+ defaultEncoding: string;
26
+ needReadable: boolean;
27
+ emittedReadable: boolean;
28
+ readingMore: boolean;
29
+ dataEmitted: boolean;
30
+ }
31
+
32
+ /* ---- WritableState ---- */
33
+
34
+ export interface FsWritableState {
35
+ readonly objectMode: boolean;
36
+ readonly highWaterMark: number;
37
+ finished: boolean;
38
+ ended: boolean;
39
+ readonly destroyed: boolean;
40
+ readonly errored: Error | null;
41
+ readonly closed: boolean;
42
+ readonly corked: number;
43
+ readonly length: number;
44
+ readonly needDrain: boolean;
45
+ writing: boolean;
46
+ errorEmitted: boolean;
47
+ emitClose: boolean;
48
+ readonly autoDestroy: boolean;
49
+ defaultEncoding: string;
50
+ finalCalled: boolean;
51
+ ending: boolean;
52
+ bufferedIndex: number;
53
+ }
54
+
55
+ /* ---- FsReadStream ---- */
56
+
57
+ export interface FsReadStreamInstance {
58
+ _queue: Array<Buffer | null>;
59
+ _active: boolean;
60
+ _terminated: boolean;
61
+ _endFired: boolean;
62
+ _endEmitted: boolean;
63
+ _objectMode: boolean;
64
+ _reading: boolean;
65
+ _highWaterMark: number;
66
+ _autoDestroy: boolean;
67
+ _encoding: string | null;
68
+ _readableByteLength: number;
69
+ _draining: boolean;
70
+
71
+ readable: boolean;
72
+ readableEnded: boolean;
73
+ readableFlowing: boolean | null;
74
+ destroyed: boolean;
75
+ closed: boolean;
76
+ errored: Error | null;
77
+ readableObjectMode: boolean;
78
+ readableHighWaterMark: number;
79
+ readableDidRead: boolean;
80
+ readableAborted: boolean;
81
+
82
+ _readableState: FsReadableState;
83
+
84
+ path: string;
85
+ fd: number | null;
86
+ flags: string;
87
+ mode: number;
88
+ autoClose: boolean;
89
+
90
+ open(): void;
91
+ _read(): void;
92
+ close(cb?: (err?: Error | null) => void): void;
93
+
94
+ push(chunk: unknown): boolean;
95
+ destroy(err?: unknown): void;
96
+ emit(event: string, ...args: unknown[]): boolean;
97
+ on(event: string, fn: (...args: unknown[]) => void): this;
98
+ pipe(dest: unknown): unknown;
99
+ }
100
+
101
+ /* ---- FsWriteStream ---- */
102
+
103
+ export interface FsWriteStreamInstance {
104
+ _parts: Uint8Array[];
105
+ _closed: boolean;
106
+ _objectMode: boolean;
107
+ _highWaterMark: number;
108
+ _autoDestroy: boolean;
109
+ _corked: number;
110
+ _corkedWrites: Array<{ chunk: unknown; encoding: string; cb: (err?: Error | null) => void }>;
111
+ _writableByteLength: number;
112
+
113
+ writable: boolean;
114
+ writableEnded: boolean;
115
+ writableFinished: boolean;
116
+ writableNeedDrain: boolean;
117
+ destroyed: boolean;
118
+ closed: boolean;
119
+ errored: Error | null;
120
+ writableObjectMode: boolean;
121
+ writableHighWaterMark: number;
122
+ writableCorked: number;
123
+
124
+ _writableState: FsWritableState;
125
+
126
+ path: string;
127
+ fd: number | null;
128
+ flags: string;
129
+ mode: number;
130
+ autoClose: boolean;
131
+ bytesWritten: number;
132
+ _chunks: Uint8Array[];
133
+ _enc: TextEncoder;
134
+
135
+ open(): void;
136
+ close(cb?: (err?: Error | null) => void): void;
137
+
138
+ destroy(err?: unknown): void;
139
+ emit(event: string, ...args: unknown[]): boolean;
140
+ end(chunk?: unknown, encoding?: string, cb?: () => void): void;
141
+ write(chunk: unknown, encoding?: string, cb?: (err?: Error | null) => void): boolean;
142
+ }
@@ -0,0 +1,17 @@
1
+ export interface PackageManifest {
2
+ name?: string;
3
+ version?: string;
4
+ main?: string;
5
+ module?: string;
6
+ browser?: string | Record<string, string | false>;
7
+ types?: string;
8
+ exports?: Record<string, unknown> | string;
9
+ imports?: Record<string, unknown>;
10
+ dependencies?: Record<string, string>;
11
+ devDependencies?: Record<string, string>;
12
+ peerDependencies?: Record<string, string>;
13
+ optionalDependencies?: Record<string, string>;
14
+ scripts?: Record<string, string>;
15
+ bin?: string | Record<string, string>;
16
+ [key: string]: unknown;
17
+ }
@@ -0,0 +1,90 @@
1
+ // executes code in a dedicated Web Worker behind the IScriptEngine interface
2
+
3
+ import { wrap, proxy, Remote } from 'comlink';
4
+ import type { MemoryVolume } from './memory-volume';
5
+ import type { IScriptEngine, ExecutionOutcome, EngineConfig, VolumeSnapshot } from './engine-types';
6
+
7
+ interface WorkerEndpoint {
8
+ init(snapshot: VolumeSnapshot, config: EngineConfig): void;
9
+ setConsoleForwarder(cb: ((method: string, args: unknown[]) => void) | null): void;
10
+ syncFile(path: string, content: string | null): void;
11
+ execute(code: string, filename?: string): Promise<ExecutionOutcome>;
12
+ runFile(filename: string): Promise<ExecutionOutcome>;
13
+ clearCache(): void;
14
+ getSnapshot(): VolumeSnapshot | null;
15
+ }
16
+
17
+ // URL is built at runtime so bundlers can't statically resolve it
18
+ function createWorker(): Worker {
19
+ const base = import.meta.url;
20
+ const path = './threading/engine-worker' + '.ts';
21
+ const url = new (globalThis.URL)(path, base);
22
+ return new (globalThis.Worker)(url, { type: 'module' });
23
+ }
24
+
25
+ export class WorkerSandbox implements IScriptEngine {
26
+ private thread: Worker;
27
+ private endpoint: Remote<WorkerEndpoint>;
28
+ private vol: MemoryVolume;
29
+ private cfg: EngineConfig;
30
+ private ready: Promise<void>;
31
+ private onFileChange: ((path: string, content: string) => void) | null = null;
32
+ private onFileDelete: ((path: string) => void) | null = null;
33
+
34
+ constructor(vol: MemoryVolume, cfg: EngineConfig = {}) {
35
+ this.vol = vol;
36
+ this.cfg = cfg;
37
+
38
+ this.thread = createWorker();
39
+
40
+ this.endpoint = wrap<WorkerEndpoint>(this.thread);
41
+ this.ready = this.bootstrap();
42
+ this.attachVolumeSync();
43
+ }
44
+
45
+ private async bootstrap(): Promise<void> {
46
+ const snapshot = this.vol.toSnapshot();
47
+ const workerCfg: EngineConfig = { cwd: this.cfg.cwd, env: this.cfg.env };
48
+ await this.endpoint.init(snapshot, workerCfg);
49
+
50
+ if (this.cfg.onConsole) {
51
+ await this.endpoint.setConsoleForwarder(proxy(this.cfg.onConsole));
52
+ }
53
+ }
54
+
55
+ private attachVolumeSync(): void {
56
+ this.onFileChange = (path: string, content: string) => {
57
+ this.endpoint.syncFile(path, content);
58
+ };
59
+ this.vol.on('change', this.onFileChange);
60
+
61
+ this.onFileDelete = (path: string) => {
62
+ this.endpoint.syncFile(path, null);
63
+ };
64
+ this.vol.on('delete', this.onFileDelete);
65
+ }
66
+
67
+ async execute(code: string, filename?: string): Promise<ExecutionOutcome> {
68
+ await this.ready;
69
+ return this.endpoint.execute(code, filename);
70
+ }
71
+
72
+ async runFile(filename: string): Promise<ExecutionOutcome> {
73
+ await this.ready;
74
+ return this.endpoint.runFile(filename);
75
+ }
76
+
77
+ clearCache(): void {
78
+ this.endpoint.clearCache();
79
+ }
80
+
81
+ getVolume(): MemoryVolume {
82
+ return this.vol;
83
+ }
84
+
85
+ terminate(): void {
86
+ if (this.onFileChange) this.vol.off('change', this.onFileChange);
87
+ if (this.onFileDelete) this.vol.off('delete', this.onFileDelete);
88
+ this.thread.terminate();
89
+ }
90
+ }