@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.
- package/LICENSE +43 -0
- package/README.md +240 -0
- package/dist/child_process-BJOMsZje.js +8233 -0
- package/dist/child_process-BJOMsZje.js.map +1 -0
- package/dist/child_process-Cj8vOcuc.cjs +7434 -0
- package/dist/child_process-Cj8vOcuc.cjs.map +1 -0
- package/dist/index-Cb1Cgdnd.js +35308 -0
- package/dist/index-Cb1Cgdnd.js.map +1 -0
- package/dist/index-DsMGS-xc.cjs +37195 -0
- package/dist/index-DsMGS-xc.cjs.map +1 -0
- package/dist/index.cjs +65 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.mjs +59 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +95 -0
- package/src/__tests__/smoke.test.ts +11 -0
- package/src/constants/cdn-urls.ts +18 -0
- package/src/constants/config.ts +236 -0
- package/src/cross-origin.ts +26 -0
- package/src/engine-factory.ts +176 -0
- package/src/engine-types.ts +56 -0
- package/src/helpers/byte-encoding.ts +39 -0
- package/src/helpers/digest.ts +9 -0
- package/src/helpers/event-loop.ts +96 -0
- package/src/helpers/wasm-cache.ts +133 -0
- package/src/iframe-sandbox.ts +141 -0
- package/src/index.ts +192 -0
- package/src/isolation-helpers.ts +148 -0
- package/src/memory-volume.ts +941 -0
- package/src/module-transformer.ts +368 -0
- package/src/packages/archive-extractor.ts +248 -0
- package/src/packages/browser-bundler.ts +284 -0
- package/src/packages/installer.ts +396 -0
- package/src/packages/registry-client.ts +131 -0
- package/src/packages/version-resolver.ts +411 -0
- package/src/polyfills/assert.ts +384 -0
- package/src/polyfills/async_hooks.ts +144 -0
- package/src/polyfills/buffer.ts +628 -0
- package/src/polyfills/child_process.ts +2288 -0
- package/src/polyfills/chokidar.ts +336 -0
- package/src/polyfills/cluster.ts +106 -0
- package/src/polyfills/console.ts +136 -0
- package/src/polyfills/constants.ts +123 -0
- package/src/polyfills/crypto.ts +885 -0
- package/src/polyfills/dgram.ts +87 -0
- package/src/polyfills/diagnostics_channel.ts +76 -0
- package/src/polyfills/dns.ts +134 -0
- package/src/polyfills/domain.ts +68 -0
- package/src/polyfills/esbuild.ts +854 -0
- package/src/polyfills/events.ts +276 -0
- package/src/polyfills/fs.ts +2888 -0
- package/src/polyfills/fsevents.ts +79 -0
- package/src/polyfills/http.ts +1449 -0
- package/src/polyfills/http2.ts +199 -0
- package/src/polyfills/https.ts +76 -0
- package/src/polyfills/inspector.ts +62 -0
- package/src/polyfills/lightningcss.ts +105 -0
- package/src/polyfills/module.ts +191 -0
- package/src/polyfills/net.ts +353 -0
- package/src/polyfills/os.ts +238 -0
- package/src/polyfills/path.ts +206 -0
- package/src/polyfills/perf_hooks.ts +102 -0
- package/src/polyfills/process.ts +690 -0
- package/src/polyfills/punycode.ts +159 -0
- package/src/polyfills/querystring.ts +93 -0
- package/src/polyfills/quic.ts +118 -0
- package/src/polyfills/readdirp.ts +229 -0
- package/src/polyfills/readline.ts +692 -0
- package/src/polyfills/repl.ts +134 -0
- package/src/polyfills/rollup.ts +119 -0
- package/src/polyfills/sea.ts +33 -0
- package/src/polyfills/sqlite.ts +78 -0
- package/src/polyfills/stream.ts +1620 -0
- package/src/polyfills/string_decoder.ts +25 -0
- package/src/polyfills/tailwindcss-oxide.ts +309 -0
- package/src/polyfills/test.ts +197 -0
- package/src/polyfills/timers.ts +32 -0
- package/src/polyfills/tls.ts +105 -0
- package/src/polyfills/trace_events.ts +50 -0
- package/src/polyfills/tty.ts +71 -0
- package/src/polyfills/url.ts +174 -0
- package/src/polyfills/util.ts +559 -0
- package/src/polyfills/v8.ts +126 -0
- package/src/polyfills/vm.ts +132 -0
- package/src/polyfills/volume-registry.ts +15 -0
- package/src/polyfills/wasi.ts +44 -0
- package/src/polyfills/worker_threads.ts +326 -0
- package/src/polyfills/ws.ts +595 -0
- package/src/polyfills/zlib.ts +881 -0
- package/src/request-proxy.ts +716 -0
- package/src/script-engine.ts +3375 -0
- package/src/sdk/nodepod-fs.ts +93 -0
- package/src/sdk/nodepod-process.ts +86 -0
- package/src/sdk/nodepod-terminal.ts +350 -0
- package/src/sdk/nodepod.ts +509 -0
- package/src/sdk/types.ts +70 -0
- package/src/shell/commands/bun.ts +121 -0
- package/src/shell/commands/directory.ts +297 -0
- package/src/shell/commands/file-ops.ts +525 -0
- package/src/shell/commands/git.ts +2142 -0
- package/src/shell/commands/node.ts +80 -0
- package/src/shell/commands/npm.ts +198 -0
- package/src/shell/commands/pm-types.ts +45 -0
- package/src/shell/commands/pnpm.ts +82 -0
- package/src/shell/commands/search.ts +264 -0
- package/src/shell/commands/shell-env.ts +352 -0
- package/src/shell/commands/text-processing.ts +1152 -0
- package/src/shell/commands/yarn.ts +84 -0
- package/src/shell/shell-builtins.ts +19 -0
- package/src/shell/shell-helpers.ts +250 -0
- package/src/shell/shell-interpreter.ts +514 -0
- package/src/shell/shell-parser.ts +429 -0
- package/src/shell/shell-types.ts +85 -0
- package/src/syntax-transforms.ts +561 -0
- package/src/threading/engine-worker.ts +64 -0
- package/src/threading/inline-worker.ts +372 -0
- package/src/threading/offload-types.ts +112 -0
- package/src/threading/offload-worker.ts +383 -0
- package/src/threading/offload.ts +271 -0
- package/src/threading/process-context.ts +92 -0
- package/src/threading/process-handle.ts +275 -0
- package/src/threading/process-manager.ts +956 -0
- package/src/threading/process-worker-entry.ts +854 -0
- package/src/threading/shared-vfs.ts +352 -0
- package/src/threading/sync-channel.ts +135 -0
- package/src/threading/task-queue.ts +177 -0
- package/src/threading/vfs-bridge.ts +231 -0
- package/src/threading/worker-pool.ts +233 -0
- package/src/threading/worker-protocol.ts +358 -0
- package/src/threading/worker-vfs.ts +218 -0
- package/src/types/externals.d.ts +38 -0
- package/src/types/fs-streams.ts +142 -0
- package/src/types/manifest.ts +17 -0
- package/src/worker-sandbox.ts +90 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// helpers for deploying a cross-origin sandbox environment
|
|
2
|
+
|
|
3
|
+
// Node.js-only helper. Uses opaque dynamic require so bundlers can't resolve it.
|
|
4
|
+
function readServiceWorkerSource(): string | null {
|
|
5
|
+
try {
|
|
6
|
+
// invisible to bundlers' static analysis
|
|
7
|
+
const _req = globalThis['require' as keyof typeof globalThis] as typeof require | undefined;
|
|
8
|
+
if (typeof _req !== 'function') return null;
|
|
9
|
+
const fs = _req('fs' + '');
|
|
10
|
+
const path = _req('path' + '');
|
|
11
|
+
let dir: string;
|
|
12
|
+
try {
|
|
13
|
+
const url = _req('url' + '');
|
|
14
|
+
dir = path.dirname(url.fileURLToPath(import.meta.url));
|
|
15
|
+
} catch {
|
|
16
|
+
dir = typeof __dirname !== 'undefined' ? __dirname : '.';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let swFile = path.join(dir, '__sw__.js');
|
|
20
|
+
if (fs.existsSync(swFile)) return fs.readFileSync(swFile, 'utf-8');
|
|
21
|
+
swFile = path.join(dir, '../dist/__sw__.js');
|
|
22
|
+
if (fs.existsSync(swFile)) return fs.readFileSync(swFile, 'utf-8');
|
|
23
|
+
return null;
|
|
24
|
+
} catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
import { DEFAULT_NODEPOD_CDN } from "./constants/config";
|
|
30
|
+
|
|
31
|
+
export interface SandboxPageConfig {
|
|
32
|
+
nodepodUrl?: string;
|
|
33
|
+
enableServiceWorker?: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function getSandboxPageHtml(config: SandboxPageConfig | string = {}): string {
|
|
37
|
+
const opts: SandboxPageConfig = typeof config === 'string' ? { nodepodUrl: config } : config;
|
|
38
|
+
const nodepodUrl = opts.nodepodUrl ?? DEFAULT_NODEPOD_CDN;
|
|
39
|
+
const withSW = opts.enableServiceWorker ?? true;
|
|
40
|
+
|
|
41
|
+
const swBlock = withSW ? `
|
|
42
|
+
if ('serviceWorker' in navigator) {
|
|
43
|
+
navigator.serviceWorker.register('/__sw__.js', { scope: '/' })
|
|
44
|
+
.then(() => console.log('[Sandbox] SW registered'))
|
|
45
|
+
.catch(e => console.warn('[Sandbox] SW failed:', e));
|
|
46
|
+
}
|
|
47
|
+
` : '';
|
|
48
|
+
|
|
49
|
+
return `<!DOCTYPE html>
|
|
50
|
+
<html>
|
|
51
|
+
<head><meta charset="UTF-8"><title>Nodepod Sandbox</title></head>
|
|
52
|
+
<body>
|
|
53
|
+
<script type="module">
|
|
54
|
+
import { MemoryVolume, ScriptEngine } from '${nodepodUrl}';
|
|
55
|
+
${swBlock}
|
|
56
|
+
let volume = null;
|
|
57
|
+
let engine = null;
|
|
58
|
+
|
|
59
|
+
window.addEventListener('message', async (event) => {
|
|
60
|
+
const { type, id, code, filename, snapshot, config, path, content } = event.data;
|
|
61
|
+
try {
|
|
62
|
+
switch (type) {
|
|
63
|
+
case 'init':
|
|
64
|
+
volume = MemoryVolume.fromSnapshot(snapshot);
|
|
65
|
+
engine = new ScriptEngine(volume, {
|
|
66
|
+
cwd: config?.cwd,
|
|
67
|
+
env: config?.env,
|
|
68
|
+
onConsole: (method, args) => {
|
|
69
|
+
parent.postMessage({ type: 'console', consoleMethod: method, consoleArgs: args }, '*');
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
break;
|
|
73
|
+
case 'syncFile':
|
|
74
|
+
if (volume) {
|
|
75
|
+
if (content === null) { try { volume.unlinkSync(path); } catch {} }
|
|
76
|
+
else { volume.writeFileSync(path, content); }
|
|
77
|
+
}
|
|
78
|
+
break;
|
|
79
|
+
case 'execute':
|
|
80
|
+
if (!engine) { parent.postMessage({ type: 'error', id, error: 'Engine not initialized' }, '*'); return; }
|
|
81
|
+
parent.postMessage({ type: 'result', id, result: engine.execute(code, filename) }, '*');
|
|
82
|
+
break;
|
|
83
|
+
case 'runFile':
|
|
84
|
+
if (!engine) { parent.postMessage({ type: 'error', id, error: 'Engine not initialized' }, '*'); return; }
|
|
85
|
+
parent.postMessage({ type: 'result', id, result: engine.runFile(filename) }, '*');
|
|
86
|
+
break;
|
|
87
|
+
case 'clearCache':
|
|
88
|
+
if (engine) engine.clearCache();
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
} catch (err) {
|
|
92
|
+
if (id) parent.postMessage({ type: 'error', id, error: err instanceof Error ? err.message : String(err) }, '*');
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
parent.postMessage({ type: 'ready' }, '*');
|
|
97
|
+
</script>
|
|
98
|
+
</body>
|
|
99
|
+
</html>`;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Vercel config with CORS headers for cross-origin iframe embedding
|
|
103
|
+
export function getSandboxHostingConfig(): object {
|
|
104
|
+
return {
|
|
105
|
+
headers: [{
|
|
106
|
+
source: '/(.*)',
|
|
107
|
+
headers: [
|
|
108
|
+
{ key: 'Access-Control-Allow-Origin', value: '*' },
|
|
109
|
+
{ key: 'Cross-Origin-Resource-Policy', value: 'cross-origin' },
|
|
110
|
+
],
|
|
111
|
+
}],
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface GeneratedSandboxFiles {
|
|
116
|
+
'index.html': string;
|
|
117
|
+
'vercel.json': string;
|
|
118
|
+
'__sw__.js'?: string;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function generateSandboxDeployment(config: SandboxPageConfig | string = {}): GeneratedSandboxFiles {
|
|
122
|
+
const opts: SandboxPageConfig = typeof config === 'string' ? { nodepodUrl: config } : config;
|
|
123
|
+
const withSW = opts.enableServiceWorker ?? true;
|
|
124
|
+
const swSource = withSW ? readServiceWorkerSource() : null;
|
|
125
|
+
|
|
126
|
+
const files: GeneratedSandboxFiles = {
|
|
127
|
+
'index.html': getSandboxPageHtml(opts),
|
|
128
|
+
'vercel.json': JSON.stringify(getSandboxHostingConfig(), null, 2),
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
if (swSource) files['__sw__.js'] = swSource;
|
|
132
|
+
return files;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export const SANDBOX_DEPLOYMENT_GUIDE = `
|
|
136
|
+
# Deploying a Nodepod Sandbox
|
|
137
|
+
|
|
138
|
+
## 1. Generate sandbox files
|
|
139
|
+
Use generateSandboxDeployment() to create the required files.
|
|
140
|
+
|
|
141
|
+
## 2. Deploy to a hosting provider
|
|
142
|
+
cd sandbox && vercel --prod
|
|
143
|
+
|
|
144
|
+
## 3. Use in your app
|
|
145
|
+
const engine = await spawnEngine(volume, {
|
|
146
|
+
sandboxUrl: 'https://your-sandbox.example.com'
|
|
147
|
+
});
|
|
148
|
+
`.trim();
|