@scelar/nodepod 1.0.8 → 1.0.9
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.
- package/README.md +252 -252
- package/dist/{child_process-BD0fAFc1.cjs → child_process-DldQfPd9.cjs} +5 -5
- package/dist/child_process-DldQfPd9.cjs.map +1 -0
- package/dist/{child_process-DV4uXIWL.js → child_process-eiM1_nmq.js} +4 -4
- package/dist/child_process-eiM1_nmq.js.map +1 -0
- package/dist/{index-DpqCP69G.js → index-CK6KRbI1.js} +353 -6
- package/dist/index-CK6KRbI1.js.map +1 -0
- package/dist/{index-DVbLKdL5.cjs → index-DfyUKyNH.cjs} +365 -20
- package/dist/index-DfyUKyNH.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/script-engine.d.ts +1 -1
- package/package.json +1 -1
- package/src/cross-origin.ts +75 -75
- package/src/iframe-sandbox.ts +145 -145
- package/src/isolation-helpers.ts +154 -154
- package/src/packages/archive-extractor.ts +251 -251
- package/src/polyfills/net.ts +353 -353
- package/src/polyfills/util.ts +559 -559
- package/src/polyfills/worker_threads.ts +326 -326
- package/src/script-engine.ts +3733 -3722
- package/src/shell/shell-builtins.ts +19 -19
- package/src/threading/offload-types.ts +113 -113
- package/dist/child_process-BD0fAFc1.cjs.map +0 -1
- package/dist/child_process-DV4uXIWL.js.map +0 -1
- package/dist/index-DVbLKdL5.cjs.map +0 -1
- package/dist/index-DpqCP69G.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,252 +1,252 @@
|
|
|
1
|
-
# nodepod
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/@scelar/nodepod)
|
|
4
|
-
[](https://github.com/ScelarOrg/Nodepod/blob/main/LICENSE)
|
|
5
|
-
|
|
6
|
-
Browser-native Node.js runtime. Run real Node.js code — filesystem, modules, `require()`, npm packages, HTTP servers — entirely inside the browser.
|
|
7
|
-
|
|
8
|
-
No backend. No containers. No WASM Node binary. Just polyfills, an in-memory filesystem, and a JavaScript execution engine.
|
|
9
|
-
|
|
10
|
-
Built by [@R1ck404](https://github.com/R1ck404) — powering [Scelar](https://scelar.com), the AI app builder that actually COMPLETELY builds your apps, from idea to production in a matter of minutes.
|
|
11
|
-
|
|
12
|
-
## Features
|
|
13
|
-
|
|
14
|
-
- **Virtual Filesystem** — Full in-memory `fs` API (read, write, watch, streams, symlinks, glob)
|
|
15
|
-
- **Module System** — `require()`, `import`, `module.exports`, `package.json` resolution, conditional exports
|
|
16
|
-
- **npm Packages** — Install real packages from the npm registry, extracted and resolved in-browser
|
|
17
|
-
- **HTTP Servers** — Run Express, Hono, Elysia, vite and other frameworks with real request/response routing
|
|
18
|
-
- **Shell** — Built-in bash-like shell with 35+ commands (ls, cat, grep, find, sed, etc.), pipes, redirections, variable expansion
|
|
19
|
-
- **Process Model** — Web Worker-based processes with `child_process.exec/spawn/fork`, `worker_threads`, and IPC
|
|
20
|
-
- **Terminal** — Drop-in xterm.js integration with line editing, history, raw mode, Ctrl+C
|
|
21
|
-
- **Preview** — Service Worker-based iframe preview with script injection and WebSocket bridging
|
|
22
|
-
- **Snapshots** — Save and restore the entire filesystem state
|
|
23
|
-
|
|
24
|
-
## Install
|
|
25
|
-
|
|
26
|
-
```bash
|
|
27
|
-
npm install @scelar/nodepod
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
## Quick Start
|
|
31
|
-
|
|
32
|
-
```typescript
|
|
33
|
-
import { Nodepod } from '@scelar/nodepod';
|
|
34
|
-
|
|
35
|
-
// Boot a nodepod instance with some files
|
|
36
|
-
const nodepod = await Nodepod.boot({
|
|
37
|
-
files: {
|
|
38
|
-
'/index.js': 'console.log("Hello from the browser!")',
|
|
39
|
-
},
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
// Run a script
|
|
43
|
-
const proc = await nodepod.spawn('node', ['index.js']);
|
|
44
|
-
proc.on('output', (text) => console.log(text));
|
|
45
|
-
await proc.completion;
|
|
46
|
-
|
|
47
|
-
// Read/write files
|
|
48
|
-
await nodepod.fs.writeFile('/data.json', JSON.stringify({ hello: 'world' }));
|
|
49
|
-
const content = await nodepod.fs.readFile('/data.json', 'utf8');
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
## Terminal Integration
|
|
53
|
-
|
|
54
|
-
nodepod provides built-in xterm.js terminal support:
|
|
55
|
-
|
|
56
|
-
```typescript
|
|
57
|
-
import { Nodepod } from '@scelar/nodepod';
|
|
58
|
-
import { Terminal } from '@xterm/xterm';
|
|
59
|
-
import { FitAddon } from '@xterm/addon-fit';
|
|
60
|
-
|
|
61
|
-
const nodepod = await Nodepod.boot();
|
|
62
|
-
const terminal = nodepod.createTerminal({ Terminal, FitAddon });
|
|
63
|
-
terminal.attach('#terminal-container');
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
The terminal handles line editing, command history, prompt rendering, raw/cooked mode, and streaming output out of the box.
|
|
67
|
-
|
|
68
|
-
## Running an Express Server
|
|
69
|
-
|
|
70
|
-
```typescript
|
|
71
|
-
const nodepod = await Nodepod.boot({
|
|
72
|
-
files: {
|
|
73
|
-
'/server.js': `
|
|
74
|
-
const express = require('express');
|
|
75
|
-
const app = express();
|
|
76
|
-
app.get('/', (req, res) => res.json({ status: 'ok' }));
|
|
77
|
-
app.listen(3000, () => console.log('Server running on port 3000'));
|
|
78
|
-
`,
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
// Install express
|
|
83
|
-
await nodepod.install(['express']);
|
|
84
|
-
|
|
85
|
-
// Run the server
|
|
86
|
-
const proc = await nodepod.spawn('node', ['server.js']);
|
|
87
|
-
|
|
88
|
-
// Dispatch requests to the virtual server
|
|
89
|
-
const response = await nodepod.request(3000, 'GET', '/');
|
|
90
|
-
console.log(response.body); // { status: 'ok' }
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
## Preview Script Injection
|
|
94
|
-
|
|
95
|
-
Inject scripts into preview iframes before any page content loads — useful for setting up bridges between the main window and the iframe:
|
|
96
|
-
|
|
97
|
-
```typescript
|
|
98
|
-
await nodepod.setPreviewScript(`
|
|
99
|
-
window.__bridge = {
|
|
100
|
-
sendToParent(msg) { window.parent.postMessage(msg, '*'); }
|
|
101
|
-
};
|
|
102
|
-
`);
|
|
103
|
-
|
|
104
|
-
// Remove it later
|
|
105
|
-
await nodepod.clearPreviewScript();
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
## SDK API
|
|
109
|
-
|
|
110
|
-
### `Nodepod.boot(options?)`
|
|
111
|
-
|
|
112
|
-
Creates a fully wired nodepod instance.
|
|
113
|
-
|
|
114
|
-
| Option | Type | Default | Description |
|
|
115
|
-
|--------|------|---------|-------------|
|
|
116
|
-
| `files` | `Record<string, string>` | — | Initial files to populate the filesystem |
|
|
117
|
-
| `workdir` | `string` | `"/"` | Working directory |
|
|
118
|
-
| `env` | `Record<string, string>` | — | Environment variables |
|
|
119
|
-
| `swUrl` | `string` | — | Service Worker URL (enables preview iframes) |
|
|
120
|
-
| `watermark` | `boolean` | `true` | Show a small "nodepod" badge in preview iframes |
|
|
121
|
-
| `onServerReady` | `(port, url) => void` | — | Callback when a virtual server starts listening |
|
|
122
|
-
| `allowedFetchDomains` | `string[] \| null` | npm/github defaults | Extra domains allowed through the CORS proxy. Pass `null` to allow all |
|
|
123
|
-
|
|
124
|
-
### Instance Methods
|
|
125
|
-
|
|
126
|
-
| Method | Description |
|
|
127
|
-
|--------|-------------|
|
|
128
|
-
| `spawn(cmd, args?)` | Run a command, returns `NodepodProcess` |
|
|
129
|
-
| `createTerminal(opts)` | Create an interactive terminal |
|
|
130
|
-
| `install(packages)` | Install npm packages |
|
|
131
|
-
| `fs.readFile(path, enc?)` | Read a file |
|
|
132
|
-
| `fs.writeFile(path, data)` | Write a file |
|
|
133
|
-
| `fs.readdir(path)` | List directory contents |
|
|
134
|
-
| `fs.stat(path)` | Get file stats |
|
|
135
|
-
| `fs.mkdir(path, opts?)` | Create a directory |
|
|
136
|
-
| `fs.rm(path, opts?)` | Remove files/directories |
|
|
137
|
-
| `snapshot()` | Capture filesystem state |
|
|
138
|
-
| `restore(snapshot)` | Restore filesystem from snapshot |
|
|
139
|
-
| `setPreviewScript(script)` | Inject JS into preview iframes |
|
|
140
|
-
| `clearPreviewScript()` | Remove injected preview script |
|
|
141
|
-
| `port(num)` | Get preview URL for a virtual server port |
|
|
142
|
-
|
|
143
|
-
### `NodepodProcess`
|
|
144
|
-
|
|
145
|
-
Returned by `spawn()`. An EventEmitter with:
|
|
146
|
-
|
|
147
|
-
| Event | Payload | Description |
|
|
148
|
-
|-------|---------|-------------|
|
|
149
|
-
| `output` | `string` | stdout data |
|
|
150
|
-
| `error` | `string` | stderr data |
|
|
151
|
-
| `exit` | `number` | exit code |
|
|
152
|
-
|
|
153
|
-
Property: `completion` — a `Promise<void>` that resolves when the process exits.
|
|
154
|
-
|
|
155
|
-
## Security
|
|
156
|
-
|
|
157
|
-
nodepod includes several security measures for running untrusted code:
|
|
158
|
-
|
|
159
|
-
- **CORS proxy domain whitelist** — Proxied fetch requests only go through to whitelisted domains (npm registry, GitHub, esm.sh, etc by default). Extend via the `allowedFetchDomains` boot option or pass `null` to disable
|
|
160
|
-
- **Service Worker auth** — Control messages to the SW require a random token generated at boot, so other scripts on the same origin can't inject preview content
|
|
161
|
-
- **WebSocket bridge auth** — The BroadcastChannel used for WS bridging between preview iframes and the main thread is token-authenticated
|
|
162
|
-
- **Package integrity** — Downloaded npm tarballs are checked against the registry's `shasum` before extraction
|
|
163
|
-
- **Iframe sandbox** — The cross-origin iframe mode uses `sandbox="allow-scripts"` to prevent top-frame navigation, popups, and form submissions
|
|
164
|
-
- **Origin-checked messaging** — The sandbox page validates `event.origin` on incoming messages and only responds to the configured parent origin
|
|
165
|
-
|
|
166
|
-
## Architecture
|
|
167
|
-
|
|
168
|
-
```
|
|
169
|
-
nodepod
|
|
170
|
-
├── src/
|
|
171
|
-
│ ├── script-engine.ts # JavaScript execution engine (require, ESM→CJS, REPL)
|
|
172
|
-
│ ├── memory-volume.ts # In-memory virtual filesystem
|
|
173
|
-
│ ├── syntax-transforms.ts # ESM-to-CJS conversion via acorn
|
|
174
|
-
│ ├── module-transformer.ts # esbuild-wasm code transforms
|
|
175
|
-
│ ├── polyfills/ # Node.js built-in module polyfills
|
|
176
|
-
│ │ ├── fs.ts # Filesystem (read, write, watch, streams, glob)
|
|
177
|
-
│ │ ├── http.ts # HTTP server/client
|
|
178
|
-
│ │ ├── stream.ts # Readable, Writable, Transform, Duplex
|
|
179
|
-
│ │ ├── events.ts # EventEmitter
|
|
180
|
-
│ │ ├── path.ts # Path operations
|
|
181
|
-
│ │ ├── crypto.ts # Hashing, randomBytes, randomUUID
|
|
182
|
-
│ │ ├── child_process.ts # exec, spawn, fork, execSync
|
|
183
|
-
│ │ ├── net.ts # TCP Socket, Server
|
|
184
|
-
│ │ └── ... # 40+ more polyfills
|
|
185
|
-
│ ├── shell/ # Bash-like shell interpreter
|
|
186
|
-
│ │ ├── shell-parser.ts # Tokenizer + recursive-descent parser
|
|
187
|
-
│ │ ├── shell-builtins.ts # 35+ built-in commands
|
|
188
|
-
│ │ └── shell-interpreter.ts # AST executor, pipes, redirections
|
|
189
|
-
│ ├── packages/ # npm package management
|
|
190
|
-
│ │ ├── installer.ts # Package installer
|
|
191
|
-
│ │ ├── registry-client.ts # npm registry client
|
|
192
|
-
│ │ └── version-resolver.ts # Semver resolution
|
|
193
|
-
│ ├── threading/ # Worker-based process model
|
|
194
|
-
│ │ ├── process-manager.ts # Process lifecycle management
|
|
195
|
-
│ │ └── process-handle.ts # Process I/O handle
|
|
196
|
-
│ └── sdk/ # Public SDK layer
|
|
197
|
-
│ ├── nodepod.ts # Nodepod.boot() entry point
|
|
198
|
-
│ ├── nodepod-fs.ts # Async filesystem facade
|
|
199
|
-
│ ├── nodepod-process.ts # Process handle
|
|
200
|
-
│ └── nodepod-terminal.ts # xterm.js terminal integration
|
|
201
|
-
└── static/
|
|
202
|
-
└── __sw__.js # Service Worker for HTTP request interception
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
## Supported Node.js Modules
|
|
206
|
-
|
|
207
|
-
**Full implementations:** fs, path, events, stream, buffer, process, http, https, net, crypto, zlib, url, querystring, util, os, tty, child_process, assert, readline, module, timers, string_decoder, perf_hooks, constants, punycode
|
|
208
|
-
|
|
209
|
-
**Shims/stubs:** dns, worker_threads, vm, v8, tls, dgram, cluster, http2, inspector, domain, diagnostics_channel, async_hooks
|
|
210
|
-
|
|
211
|
-
## CDN Usage
|
|
212
|
-
Once published to npm, nodepod is automatically available on CDNs:
|
|
213
|
-
|
|
214
|
-
```html
|
|
215
|
-
<!-- unpkg -->
|
|
216
|
-
<script src="https://unpkg.com/@scelar/nodepod"></script>
|
|
217
|
-
|
|
218
|
-
<!-- jsDelivr -->
|
|
219
|
-
<script src="https://cdn.jsdelivr.net/npm/@scelar/nodepod"></script>
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
## Development
|
|
223
|
-
|
|
224
|
-
```bash
|
|
225
|
-
git clone https://github.com/ScelarOrg/Nodepod.git
|
|
226
|
-
cd Nodepod
|
|
227
|
-
npm install
|
|
228
|
-
npm run type-check # TypeScript validation
|
|
229
|
-
npm run build:lib # Build ESM + CJS bundles
|
|
230
|
-
npm test # Run tests
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
## Contributing
|
|
234
|
-
|
|
235
|
-
See [CONTRIBUTING.md](./CONTRIBUTING.md) for setup instructions and guidelines.
|
|
236
|
-
|
|
237
|
-
## Author
|
|
238
|
-
|
|
239
|
-
Created by [@R1ck404](https://github.com/R1ck404). Part of the [Scelar](https://scelar.com) ecosystem.
|
|
240
|
-
|
|
241
|
-
## License
|
|
242
|
-
|
|
243
|
-
[MIT + Commons Clause](./LICENSE)
|
|
244
|
-
|
|
245
|
-
This project uses the MIT license with the [Commons Clause](https://commonsclause.com/) restriction. In plain terms:
|
|
246
|
-
|
|
247
|
-
- **Use it** freely in your own projects, including commercial ones
|
|
248
|
-
- **Modify it**, fork it, learn from it
|
|
249
|
-
- **Ship products** built with nodepod — that's totally fine
|
|
250
|
-
- **Don't resell nodepod itself** as a standalone product or hosted service
|
|
251
|
-
|
|
252
|
-
Basically, build whatever you want with it — just don't take nodepod, rebrand it, and sell it as your own thing.
|
|
1
|
+
# nodepod
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@scelar/nodepod)
|
|
4
|
+
[](https://github.com/ScelarOrg/Nodepod/blob/main/LICENSE)
|
|
5
|
+
|
|
6
|
+
Browser-native Node.js runtime. Run real Node.js code — filesystem, modules, `require()`, npm packages, HTTP servers — entirely inside the browser.
|
|
7
|
+
|
|
8
|
+
No backend. No containers. No WASM Node binary. Just polyfills, an in-memory filesystem, and a JavaScript execution engine.
|
|
9
|
+
|
|
10
|
+
Built by [@R1ck404](https://github.com/R1ck404) — powering [Scelar](https://scelar.com), the AI app builder that actually COMPLETELY builds your apps, from idea to production in a matter of minutes.
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- **Virtual Filesystem** — Full in-memory `fs` API (read, write, watch, streams, symlinks, glob)
|
|
15
|
+
- **Module System** — `require()`, `import`, `module.exports`, `package.json` resolution, conditional exports
|
|
16
|
+
- **npm Packages** — Install real packages from the npm registry, extracted and resolved in-browser
|
|
17
|
+
- **HTTP Servers** — Run Express, Hono, Elysia, vite and other frameworks with real request/response routing
|
|
18
|
+
- **Shell** — Built-in bash-like shell with 35+ commands (ls, cat, grep, find, sed, etc.), pipes, redirections, variable expansion
|
|
19
|
+
- **Process Model** — Web Worker-based processes with `child_process.exec/spawn/fork`, `worker_threads`, and IPC
|
|
20
|
+
- **Terminal** — Drop-in xterm.js integration with line editing, history, raw mode, Ctrl+C
|
|
21
|
+
- **Preview** — Service Worker-based iframe preview with script injection and WebSocket bridging
|
|
22
|
+
- **Snapshots** — Save and restore the entire filesystem state
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install @scelar/nodepod
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import { Nodepod } from '@scelar/nodepod';
|
|
34
|
+
|
|
35
|
+
// Boot a nodepod instance with some files
|
|
36
|
+
const nodepod = await Nodepod.boot({
|
|
37
|
+
files: {
|
|
38
|
+
'/index.js': 'console.log("Hello from the browser!")',
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// Run a script
|
|
43
|
+
const proc = await nodepod.spawn('node', ['index.js']);
|
|
44
|
+
proc.on('output', (text) => console.log(text));
|
|
45
|
+
await proc.completion;
|
|
46
|
+
|
|
47
|
+
// Read/write files
|
|
48
|
+
await nodepod.fs.writeFile('/data.json', JSON.stringify({ hello: 'world' }));
|
|
49
|
+
const content = await nodepod.fs.readFile('/data.json', 'utf8');
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Terminal Integration
|
|
53
|
+
|
|
54
|
+
nodepod provides built-in xterm.js terminal support:
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import { Nodepod } from '@scelar/nodepod';
|
|
58
|
+
import { Terminal } from '@xterm/xterm';
|
|
59
|
+
import { FitAddon } from '@xterm/addon-fit';
|
|
60
|
+
|
|
61
|
+
const nodepod = await Nodepod.boot();
|
|
62
|
+
const terminal = nodepod.createTerminal({ Terminal, FitAddon });
|
|
63
|
+
terminal.attach('#terminal-container');
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
The terminal handles line editing, command history, prompt rendering, raw/cooked mode, and streaming output out of the box.
|
|
67
|
+
|
|
68
|
+
## Running an Express Server
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
const nodepod = await Nodepod.boot({
|
|
72
|
+
files: {
|
|
73
|
+
'/server.js': `
|
|
74
|
+
const express = require('express');
|
|
75
|
+
const app = express();
|
|
76
|
+
app.get('/', (req, res) => res.json({ status: 'ok' }));
|
|
77
|
+
app.listen(3000, () => console.log('Server running on port 3000'));
|
|
78
|
+
`,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// Install express
|
|
83
|
+
await nodepod.install(['express']);
|
|
84
|
+
|
|
85
|
+
// Run the server
|
|
86
|
+
const proc = await nodepod.spawn('node', ['server.js']);
|
|
87
|
+
|
|
88
|
+
// Dispatch requests to the virtual server
|
|
89
|
+
const response = await nodepod.request(3000, 'GET', '/');
|
|
90
|
+
console.log(response.body); // { status: 'ok' }
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Preview Script Injection
|
|
94
|
+
|
|
95
|
+
Inject scripts into preview iframes before any page content loads — useful for setting up bridges between the main window and the iframe:
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
await nodepod.setPreviewScript(`
|
|
99
|
+
window.__bridge = {
|
|
100
|
+
sendToParent(msg) { window.parent.postMessage(msg, '*'); }
|
|
101
|
+
};
|
|
102
|
+
`);
|
|
103
|
+
|
|
104
|
+
// Remove it later
|
|
105
|
+
await nodepod.clearPreviewScript();
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## SDK API
|
|
109
|
+
|
|
110
|
+
### `Nodepod.boot(options?)`
|
|
111
|
+
|
|
112
|
+
Creates a fully wired nodepod instance.
|
|
113
|
+
|
|
114
|
+
| Option | Type | Default | Description |
|
|
115
|
+
|--------|------|---------|-------------|
|
|
116
|
+
| `files` | `Record<string, string>` | — | Initial files to populate the filesystem |
|
|
117
|
+
| `workdir` | `string` | `"/"` | Working directory |
|
|
118
|
+
| `env` | `Record<string, string>` | — | Environment variables |
|
|
119
|
+
| `swUrl` | `string` | — | Service Worker URL (enables preview iframes) |
|
|
120
|
+
| `watermark` | `boolean` | `true` | Show a small "nodepod" badge in preview iframes |
|
|
121
|
+
| `onServerReady` | `(port, url) => void` | — | Callback when a virtual server starts listening |
|
|
122
|
+
| `allowedFetchDomains` | `string[] \| null` | npm/github defaults | Extra domains allowed through the CORS proxy. Pass `null` to allow all |
|
|
123
|
+
|
|
124
|
+
### Instance Methods
|
|
125
|
+
|
|
126
|
+
| Method | Description |
|
|
127
|
+
|--------|-------------|
|
|
128
|
+
| `spawn(cmd, args?)` | Run a command, returns `NodepodProcess` |
|
|
129
|
+
| `createTerminal(opts)` | Create an interactive terminal |
|
|
130
|
+
| `install(packages)` | Install npm packages |
|
|
131
|
+
| `fs.readFile(path, enc?)` | Read a file |
|
|
132
|
+
| `fs.writeFile(path, data)` | Write a file |
|
|
133
|
+
| `fs.readdir(path)` | List directory contents |
|
|
134
|
+
| `fs.stat(path)` | Get file stats |
|
|
135
|
+
| `fs.mkdir(path, opts?)` | Create a directory |
|
|
136
|
+
| `fs.rm(path, opts?)` | Remove files/directories |
|
|
137
|
+
| `snapshot()` | Capture filesystem state |
|
|
138
|
+
| `restore(snapshot)` | Restore filesystem from snapshot |
|
|
139
|
+
| `setPreviewScript(script)` | Inject JS into preview iframes |
|
|
140
|
+
| `clearPreviewScript()` | Remove injected preview script |
|
|
141
|
+
| `port(num)` | Get preview URL for a virtual server port |
|
|
142
|
+
|
|
143
|
+
### `NodepodProcess`
|
|
144
|
+
|
|
145
|
+
Returned by `spawn()`. An EventEmitter with:
|
|
146
|
+
|
|
147
|
+
| Event | Payload | Description |
|
|
148
|
+
|-------|---------|-------------|
|
|
149
|
+
| `output` | `string` | stdout data |
|
|
150
|
+
| `error` | `string` | stderr data |
|
|
151
|
+
| `exit` | `number` | exit code |
|
|
152
|
+
|
|
153
|
+
Property: `completion` — a `Promise<void>` that resolves when the process exits.
|
|
154
|
+
|
|
155
|
+
## Security
|
|
156
|
+
|
|
157
|
+
nodepod includes several security measures for running untrusted code:
|
|
158
|
+
|
|
159
|
+
- **CORS proxy domain whitelist** — Proxied fetch requests only go through to whitelisted domains (npm registry, GitHub, esm.sh, etc by default). Extend via the `allowedFetchDomains` boot option or pass `null` to disable
|
|
160
|
+
- **Service Worker auth** — Control messages to the SW require a random token generated at boot, so other scripts on the same origin can't inject preview content
|
|
161
|
+
- **WebSocket bridge auth** — The BroadcastChannel used for WS bridging between preview iframes and the main thread is token-authenticated
|
|
162
|
+
- **Package integrity** — Downloaded npm tarballs are checked against the registry's `shasum` before extraction
|
|
163
|
+
- **Iframe sandbox** — The cross-origin iframe mode uses `sandbox="allow-scripts"` to prevent top-frame navigation, popups, and form submissions
|
|
164
|
+
- **Origin-checked messaging** — The sandbox page validates `event.origin` on incoming messages and only responds to the configured parent origin
|
|
165
|
+
|
|
166
|
+
## Architecture
|
|
167
|
+
|
|
168
|
+
```
|
|
169
|
+
nodepod
|
|
170
|
+
├── src/
|
|
171
|
+
│ ├── script-engine.ts # JavaScript execution engine (require, ESM→CJS, REPL)
|
|
172
|
+
│ ├── memory-volume.ts # In-memory virtual filesystem
|
|
173
|
+
│ ├── syntax-transforms.ts # ESM-to-CJS conversion via acorn
|
|
174
|
+
│ ├── module-transformer.ts # esbuild-wasm code transforms
|
|
175
|
+
│ ├── polyfills/ # Node.js built-in module polyfills
|
|
176
|
+
│ │ ├── fs.ts # Filesystem (read, write, watch, streams, glob)
|
|
177
|
+
│ │ ├── http.ts # HTTP server/client
|
|
178
|
+
│ │ ├── stream.ts # Readable, Writable, Transform, Duplex
|
|
179
|
+
│ │ ├── events.ts # EventEmitter
|
|
180
|
+
│ │ ├── path.ts # Path operations
|
|
181
|
+
│ │ ├── crypto.ts # Hashing, randomBytes, randomUUID
|
|
182
|
+
│ │ ├── child_process.ts # exec, spawn, fork, execSync
|
|
183
|
+
│ │ ├── net.ts # TCP Socket, Server
|
|
184
|
+
│ │ └── ... # 40+ more polyfills
|
|
185
|
+
│ ├── shell/ # Bash-like shell interpreter
|
|
186
|
+
│ │ ├── shell-parser.ts # Tokenizer + recursive-descent parser
|
|
187
|
+
│ │ ├── shell-builtins.ts # 35+ built-in commands
|
|
188
|
+
│ │ └── shell-interpreter.ts # AST executor, pipes, redirections
|
|
189
|
+
│ ├── packages/ # npm package management
|
|
190
|
+
│ │ ├── installer.ts # Package installer
|
|
191
|
+
│ │ ├── registry-client.ts # npm registry client
|
|
192
|
+
│ │ └── version-resolver.ts # Semver resolution
|
|
193
|
+
│ ├── threading/ # Worker-based process model
|
|
194
|
+
│ │ ├── process-manager.ts # Process lifecycle management
|
|
195
|
+
│ │ └── process-handle.ts # Process I/O handle
|
|
196
|
+
│ └── sdk/ # Public SDK layer
|
|
197
|
+
│ ├── nodepod.ts # Nodepod.boot() entry point
|
|
198
|
+
│ ├── nodepod-fs.ts # Async filesystem facade
|
|
199
|
+
│ ├── nodepod-process.ts # Process handle
|
|
200
|
+
│ └── nodepod-terminal.ts # xterm.js terminal integration
|
|
201
|
+
└── static/
|
|
202
|
+
└── __sw__.js # Service Worker for HTTP request interception
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## Supported Node.js Modules
|
|
206
|
+
|
|
207
|
+
**Full implementations:** fs, path, events, stream, buffer, process, http, https, net, crypto, zlib, url, querystring, util, os, tty, child_process, assert, readline, module, timers, string_decoder, perf_hooks, constants, punycode
|
|
208
|
+
|
|
209
|
+
**Shims/stubs:** dns, worker_threads, vm, v8, tls, dgram, cluster, http2, inspector, domain, diagnostics_channel, async_hooks
|
|
210
|
+
|
|
211
|
+
## CDN Usage
|
|
212
|
+
Once published to npm, nodepod is automatically available on CDNs:
|
|
213
|
+
|
|
214
|
+
```html
|
|
215
|
+
<!-- unpkg -->
|
|
216
|
+
<script src="https://unpkg.com/@scelar/nodepod"></script>
|
|
217
|
+
|
|
218
|
+
<!-- jsDelivr -->
|
|
219
|
+
<script src="https://cdn.jsdelivr.net/npm/@scelar/nodepod"></script>
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## Development
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
git clone https://github.com/ScelarOrg/Nodepod.git
|
|
226
|
+
cd Nodepod
|
|
227
|
+
npm install
|
|
228
|
+
npm run type-check # TypeScript validation
|
|
229
|
+
npm run build:lib # Build ESM + CJS bundles
|
|
230
|
+
npm test # Run tests
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
## Contributing
|
|
234
|
+
|
|
235
|
+
See [CONTRIBUTING.md](./CONTRIBUTING.md) for setup instructions and guidelines.
|
|
236
|
+
|
|
237
|
+
## Author
|
|
238
|
+
|
|
239
|
+
Created by [@R1ck404](https://github.com/R1ck404). Part of the [Scelar](https://scelar.com) ecosystem.
|
|
240
|
+
|
|
241
|
+
## License
|
|
242
|
+
|
|
243
|
+
[MIT + Commons Clause](./LICENSE)
|
|
244
|
+
|
|
245
|
+
This project uses the MIT license with the [Commons Clause](https://commonsclause.com/) restriction. In plain terms:
|
|
246
|
+
|
|
247
|
+
- **Use it** freely in your own projects, including commercial ones
|
|
248
|
+
- **Modify it**, fork it, learn from it
|
|
249
|
+
- **Ship products** built with nodepod — that's totally fine
|
|
250
|
+
- **Don't resell nodepod itself** as a standalone product or hosted service
|
|
251
|
+
|
|
252
|
+
Basically, build whatever you want with it — just don't take nodepod, rebrand it, and sell it as your own thing.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const index = require('./index-
|
|
5
|
+
const index = require('./index-DfyUKyNH.cjs');
|
|
6
6
|
|
|
7
7
|
function expandVariables(raw, env, lastExit) {
|
|
8
8
|
let result = "";
|
|
@@ -6087,7 +6087,7 @@ function formatWarn(msg, pm) {
|
|
|
6087
6087
|
}
|
|
6088
6088
|
}
|
|
6089
6089
|
async function installPackages(args, ctx, pm = "npm") {
|
|
6090
|
-
const { DependencyInstaller } = await Promise.resolve().then(() => require('./index-
|
|
6090
|
+
const { DependencyInstaller } = await Promise.resolve().then(() => require('./index-DfyUKyNH.cjs')).then(n => n.installer);
|
|
6091
6091
|
const installer = new DependencyInstaller(_vol, { cwd: ctx.cwd });
|
|
6092
6092
|
let out = "";
|
|
6093
6093
|
const write = _stdoutSink ?? ((_s) => {
|
|
@@ -6184,7 +6184,7 @@ async function uninstallPackages(args, ctx, pm = "npm") {
|
|
|
6184
6184
|
return { stdout: out, stderr: "", exitCode: 0 };
|
|
6185
6185
|
}
|
|
6186
6186
|
async function listPackages(ctx, pm = "npm") {
|
|
6187
|
-
const { DependencyInstaller } = await Promise.resolve().then(() => require('./index-
|
|
6187
|
+
const { DependencyInstaller } = await Promise.resolve().then(() => require('./index-DfyUKyNH.cjs')).then(n => n.installer);
|
|
6188
6188
|
const installer = new DependencyInstaller(_vol, { cwd: ctx.cwd });
|
|
6189
6189
|
const pkgs = installer.listInstalled();
|
|
6190
6190
|
const entries = Object.entries(pkgs);
|
|
@@ -6321,7 +6321,7 @@ async function npmInfo(args, ctx) {
|
|
|
6321
6321
|
}
|
|
6322
6322
|
}
|
|
6323
6323
|
try {
|
|
6324
|
-
const { RegistryClient } = await Promise.resolve().then(() => require('./index-
|
|
6324
|
+
const { RegistryClient } = await Promise.resolve().then(() => require('./index-DfyUKyNH.cjs')).then(n => n.registryClient);
|
|
6325
6325
|
const client = new RegistryClient();
|
|
6326
6326
|
const meta = await client.fetchManifest(name);
|
|
6327
6327
|
const latest = meta["dist-tags"]?.latest;
|
|
@@ -7428,4 +7428,4 @@ exports.setSyncChannel = setSyncChannel;
|
|
|
7428
7428
|
exports.shellExec = shellExec;
|
|
7429
7429
|
exports.spawn = spawn;
|
|
7430
7430
|
exports.spawnSync = spawnSync;
|
|
7431
|
-
//# sourceMappingURL=child_process-
|
|
7431
|
+
//# sourceMappingURL=child_process-DldQfPd9.cjs.map
|