@scelar/nodepod 1.0.1 → 1.0.2
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/dist/__tests__/smoke.test.d.ts +1 -0
- package/dist/constants/cdn-urls.d.ts +12 -0
- package/dist/constants/config.d.ts +121 -0
- package/dist/cross-origin.d.ts +5 -0
- package/dist/engine-factory.d.ts +24 -0
- package/dist/engine-types.d.ts +40 -0
- package/dist/helpers/byte-encoding.d.ts +4 -0
- package/dist/helpers/digest.d.ts +1 -0
- package/dist/helpers/event-loop.d.ts +12 -0
- package/dist/helpers/wasm-cache.d.ts +6 -0
- package/dist/iframe-sandbox.d.ts +25 -0
- package/dist/index.d.ts +86 -0
- package/dist/isolation-helpers.d.ts +13 -0
- package/dist/memory-volume.d.ts +147 -0
- package/dist/module-transformer.d.ts +6 -0
- package/dist/packages/archive-extractor.d.ts +28 -0
- package/dist/packages/browser-bundler.d.ts +14 -0
- package/dist/packages/installer.d.ts +41 -0
- package/dist/packages/registry-client.d.ts +46 -0
- package/dist/packages/version-resolver.d.ts +37 -0
- package/dist/polyfills/assert.d.ts +54 -0
- package/dist/polyfills/async_hooks.d.ts +46 -0
- package/dist/polyfills/buffer.d.ts +111 -0
- package/dist/polyfills/child_process.d.ts +141 -0
- package/dist/polyfills/chokidar.d.ts +63 -0
- package/dist/polyfills/cluster.d.ts +55 -0
- package/dist/polyfills/console.d.ts +72 -0
- package/dist/polyfills/constants.d.ts +207 -0
- package/dist/polyfills/crypto.d.ts +189 -0
- package/dist/polyfills/dgram.d.ts +37 -0
- package/dist/polyfills/diagnostics_channel.d.ts +27 -0
- package/dist/polyfills/dns.d.ts +76 -0
- package/dist/polyfills/domain.d.ts +27 -0
- package/dist/polyfills/esbuild.d.ts +106 -0
- package/dist/polyfills/events.d.ts +39 -0
- package/dist/polyfills/fs.d.ts +274 -0
- package/dist/polyfills/fsevents.d.ts +62 -0
- package/dist/polyfills/http.d.ts +215 -0
- package/dist/polyfills/http2.d.ts +119 -0
- package/dist/polyfills/https.d.ts +24 -0
- package/dist/polyfills/inspector.d.ts +29 -0
- package/dist/polyfills/lightningcss.d.ts +70 -0
- package/dist/polyfills/module.d.ts +35 -0
- package/dist/polyfills/net.d.ts +91 -0
- package/dist/polyfills/os.d.ts +240 -0
- package/dist/polyfills/path.d.ts +95 -0
- package/dist/polyfills/perf_hooks.d.ts +48 -0
- package/dist/polyfills/process.d.ts +190 -0
- package/dist/polyfills/punycode.d.ts +21 -0
- package/dist/polyfills/querystring.d.ts +18 -0
- package/dist/polyfills/quic.d.ts +42 -0
- package/dist/polyfills/readdirp.d.ts +48 -0
- package/dist/polyfills/readline.d.ts +87 -0
- package/dist/polyfills/repl.d.ts +45 -0
- package/dist/polyfills/rollup.d.ts +37 -0
- package/dist/polyfills/sea.d.ts +11 -0
- package/dist/polyfills/sqlite.d.ts +30 -0
- package/dist/polyfills/stream.d.ts +160 -0
- package/dist/polyfills/string_decoder.d.ts +16 -0
- package/dist/polyfills/tailwindcss-oxide.d.ts +42 -0
- package/dist/polyfills/test.d.ts +60 -0
- package/dist/polyfills/timers.d.ts +23 -0
- package/dist/polyfills/tls.d.ts +61 -0
- package/dist/polyfills/trace_events.d.ts +22 -0
- package/dist/polyfills/tty.d.ts +38 -0
- package/dist/polyfills/url.d.ts +55 -0
- package/dist/polyfills/util.d.ts +135 -0
- package/dist/polyfills/v8.d.ts +97 -0
- package/dist/polyfills/vm.d.ts +66 -0
- package/dist/polyfills/volume-registry.d.ts +3 -0
- package/dist/polyfills/wasi.d.ts +16 -0
- package/dist/polyfills/worker_threads.d.ts +111 -0
- package/dist/polyfills/ws.d.ts +92 -0
- package/dist/polyfills/zlib.d.ts +278 -0
- package/dist/request-proxy.d.ts +63 -0
- package/dist/script-engine.d.ts +79 -0
- package/dist/sdk/nodepod-fs.d.ts +27 -0
- package/dist/sdk/nodepod-process.d.ts +28 -0
- package/dist/sdk/nodepod-terminal.d.ts +48 -0
- package/dist/sdk/nodepod.d.ts +39 -0
- package/dist/sdk/types.d.ts +53 -0
- package/dist/shell/commands/bun.d.ts +4 -0
- package/dist/shell/commands/directory.d.ts +2 -0
- package/dist/shell/commands/file-ops.d.ts +2 -0
- package/dist/shell/commands/git.d.ts +2 -0
- package/dist/shell/commands/node.d.ts +4 -0
- package/dist/shell/commands/npm.d.ts +3 -0
- package/dist/shell/commands/pm-types.d.ts +25 -0
- package/dist/shell/commands/pnpm.d.ts +3 -0
- package/dist/shell/commands/search.d.ts +2 -0
- package/dist/shell/commands/shell-env.d.ts +3 -0
- package/dist/shell/commands/text-processing.d.ts +2 -0
- package/dist/shell/commands/yarn.d.ts +3 -0
- package/dist/shell/shell-builtins.d.ts +2 -0
- package/dist/shell/shell-helpers.d.ts +28 -0
- package/dist/shell/shell-interpreter.d.ts +48 -0
- package/dist/shell/shell-parser.d.ts +6 -0
- package/dist/shell/shell-types.d.ts +48 -0
- package/dist/syntax-transforms.d.ts +3 -0
- package/dist/threading/engine-worker.d.ts +1 -0
- package/dist/threading/inline-worker.d.ts +2 -0
- package/dist/threading/offload-types.d.ts +87 -0
- package/dist/threading/offload-worker.d.ts +1 -0
- package/dist/threading/offload.d.ts +16 -0
- package/dist/threading/process-context.d.ts +40 -0
- package/dist/threading/process-handle.d.ts +42 -0
- package/dist/threading/process-manager.d.ts +52 -0
- package/dist/threading/process-worker-entry.d.ts +24 -0
- package/dist/threading/shared-vfs.d.ts +36 -0
- package/dist/threading/sync-channel.d.ts +21 -0
- package/dist/threading/task-queue.d.ts +15 -0
- package/dist/threading/vfs-bridge.d.ts +25 -0
- package/dist/threading/worker-pool.d.ts +38 -0
- package/dist/threading/worker-protocol.d.ts +264 -0
- package/dist/threading/worker-vfs.d.ts +34 -0
- package/dist/types/fs-streams.d.ts +122 -0
- package/dist/types/manifest.d.ts +17 -0
- package/dist/worker-sandbox.d.ts +19 -0
- package/package.json +1 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { CompletedResponse } from "./polyfills/http";
|
|
2
|
+
import { Server } from "./polyfills/http";
|
|
3
|
+
import { EventEmitter } from "./polyfills/events";
|
|
4
|
+
export interface IVirtualServer {
|
|
5
|
+
listening: boolean;
|
|
6
|
+
address(): {
|
|
7
|
+
port: number;
|
|
8
|
+
address: string;
|
|
9
|
+
family: string;
|
|
10
|
+
} | null;
|
|
11
|
+
dispatchRequest(method: string, url: string, headers: Record<string, string>, body?: Buffer | string): Promise<CompletedResponse>;
|
|
12
|
+
}
|
|
13
|
+
export interface RegisteredServer {
|
|
14
|
+
server: Server | IVirtualServer;
|
|
15
|
+
port: number;
|
|
16
|
+
hostname: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ProxyOptions {
|
|
19
|
+
baseUrl?: string;
|
|
20
|
+
onServerReady?: (port: number, url: string) => void;
|
|
21
|
+
}
|
|
22
|
+
export interface ServiceWorkerConfig {
|
|
23
|
+
swUrl?: string;
|
|
24
|
+
}
|
|
25
|
+
export { CompletedResponse };
|
|
26
|
+
export declare class RequestProxy extends EventEmitter {
|
|
27
|
+
static DEBUG: boolean;
|
|
28
|
+
private registry;
|
|
29
|
+
private baseUrl;
|
|
30
|
+
private opts;
|
|
31
|
+
private channel;
|
|
32
|
+
private swReady;
|
|
33
|
+
private heartbeat;
|
|
34
|
+
private _processManager;
|
|
35
|
+
private _workerWsConns;
|
|
36
|
+
private _previewScript;
|
|
37
|
+
constructor(opts?: ProxyOptions);
|
|
38
|
+
setProcessManager(pm: any): void;
|
|
39
|
+
register(server: Server | IVirtualServer, port: number, hostname?: string): void;
|
|
40
|
+
unregister(port: number): void;
|
|
41
|
+
setPreviewScript(script: string | null): void;
|
|
42
|
+
setWatermark(enabled: boolean): void;
|
|
43
|
+
private _sendPreviewScriptToSW;
|
|
44
|
+
serverUrl(port: number): string;
|
|
45
|
+
activePorts(): number[];
|
|
46
|
+
handleRequest(port: number, method: string, url: string, headers: Record<string, string>, body?: ArrayBuffer): Promise<CompletedResponse>;
|
|
47
|
+
initServiceWorker(config?: ServiceWorkerConfig): Promise<void>;
|
|
48
|
+
private _normalizeSwUrl;
|
|
49
|
+
private onSWMessage;
|
|
50
|
+
private handleStreaming;
|
|
51
|
+
private _wsBridge;
|
|
52
|
+
private _wsConns;
|
|
53
|
+
private _startWsBridge;
|
|
54
|
+
private _handleWsConnect;
|
|
55
|
+
private _handleWorkerWsFrame;
|
|
56
|
+
private _handleWsSend;
|
|
57
|
+
private _handleWsClose;
|
|
58
|
+
private notifySW;
|
|
59
|
+
createFetchHandler(): (req: Request) => Promise<Response>;
|
|
60
|
+
}
|
|
61
|
+
export declare function getProxyInstance(opts?: ProxyOptions): RequestProxy;
|
|
62
|
+
export declare function resetProxy(): void;
|
|
63
|
+
export default RequestProxy;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { MemoryVolume } from "./memory-volume";
|
|
2
|
+
import type { ExecutionOutcome } from "./engine-types";
|
|
3
|
+
import { ProcessObject } from "./polyfills/process";
|
|
4
|
+
export declare function setChildProcessPolyfill(mod: any): void;
|
|
5
|
+
export interface ModuleRecord {
|
|
6
|
+
id: string;
|
|
7
|
+
filename: string;
|
|
8
|
+
exports: unknown;
|
|
9
|
+
loaded: boolean;
|
|
10
|
+
children: ModuleRecord[];
|
|
11
|
+
paths: string[];
|
|
12
|
+
}
|
|
13
|
+
export interface EngineOptions {
|
|
14
|
+
cwd?: string;
|
|
15
|
+
env?: Record<string, string>;
|
|
16
|
+
onConsole?: (method: string, args: unknown[]) => void;
|
|
17
|
+
onStdout?: (data: string) => void;
|
|
18
|
+
onStderr?: (data: string) => void;
|
|
19
|
+
workerThreadsOverride?: {
|
|
20
|
+
isMainThread: boolean;
|
|
21
|
+
parentPort: unknown;
|
|
22
|
+
workerData: unknown;
|
|
23
|
+
threadId: number;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export interface ResolverFn {
|
|
27
|
+
(id: string): unknown;
|
|
28
|
+
resolve: (id: string, options?: {
|
|
29
|
+
paths?: string[];
|
|
30
|
+
}) => string;
|
|
31
|
+
cache: Record<string, ModuleRecord>;
|
|
32
|
+
extensions: Record<string, unknown>;
|
|
33
|
+
main: ModuleRecord | null;
|
|
34
|
+
}
|
|
35
|
+
export declare class ScriptEngine {
|
|
36
|
+
private vol;
|
|
37
|
+
private fsBridge;
|
|
38
|
+
private proc;
|
|
39
|
+
private moduleRegistry;
|
|
40
|
+
private opts;
|
|
41
|
+
private transformCache;
|
|
42
|
+
constructor(vol: MemoryVolume, opts?: EngineOptions);
|
|
43
|
+
private patchTextDecoder;
|
|
44
|
+
private patchStackTraceApi;
|
|
45
|
+
execute(code: string, filename?: string): {
|
|
46
|
+
exports: unknown;
|
|
47
|
+
module: ModuleRecord;
|
|
48
|
+
};
|
|
49
|
+
executeSync: (code: string, filename?: string) => {
|
|
50
|
+
exports: unknown;
|
|
51
|
+
module: ModuleRecord;
|
|
52
|
+
};
|
|
53
|
+
executeAsync(code: string, filename?: string): Promise<ExecutionOutcome>;
|
|
54
|
+
runFile(filename: string): {
|
|
55
|
+
exports: unknown;
|
|
56
|
+
module: ModuleRecord;
|
|
57
|
+
};
|
|
58
|
+
runFileSync: (filename: string) => {
|
|
59
|
+
exports: unknown;
|
|
60
|
+
module: ModuleRecord;
|
|
61
|
+
};
|
|
62
|
+
runFileTLA(filename: string): Promise<{
|
|
63
|
+
exports: unknown;
|
|
64
|
+
module: ModuleRecord;
|
|
65
|
+
}>;
|
|
66
|
+
runFileAsync(filename: string): Promise<ExecutionOutcome>;
|
|
67
|
+
clearCache(): void;
|
|
68
|
+
getVolume(): MemoryVolume;
|
|
69
|
+
getProcess(): ProcessObject;
|
|
70
|
+
createREPL(): {
|
|
71
|
+
eval: (code: string) => unknown;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
export declare function executeCode(code: string, vol: MemoryVolume, opts?: EngineOptions): {
|
|
75
|
+
exports: unknown;
|
|
76
|
+
module: ModuleRecord;
|
|
77
|
+
};
|
|
78
|
+
export type { IScriptEngine, ExecutionOutcome, EngineConfig, } from "./engine-types";
|
|
79
|
+
export default ScriptEngine;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { MemoryVolume } from "../memory-volume";
|
|
2
|
+
import type { StatResult } from "./types";
|
|
3
|
+
export declare class NodepodFS {
|
|
4
|
+
private _vol;
|
|
5
|
+
constructor(_vol: MemoryVolume);
|
|
6
|
+
writeFile(path: string, data: string | Uint8Array): Promise<void>;
|
|
7
|
+
readFile(path: string, encoding?: "utf-8" | "utf8"): Promise<string>;
|
|
8
|
+
readFile(path: string): Promise<Uint8Array>;
|
|
9
|
+
mkdir(path: string, opts?: {
|
|
10
|
+
recursive?: boolean;
|
|
11
|
+
}): Promise<void>;
|
|
12
|
+
readdir(path: string): Promise<string[]>;
|
|
13
|
+
exists(path: string): Promise<boolean>;
|
|
14
|
+
stat(path: string): Promise<StatResult>;
|
|
15
|
+
unlink(path: string): Promise<void>;
|
|
16
|
+
rmdir(path: string, opts?: {
|
|
17
|
+
recursive?: boolean;
|
|
18
|
+
}): Promise<void>;
|
|
19
|
+
rename(from: string, to: string): Promise<void>;
|
|
20
|
+
watch(path: string, optionsOrCb?: {
|
|
21
|
+
recursive?: boolean;
|
|
22
|
+
} | ((event: string, filename: string | null) => void), cb?: (event: string, filename: string | null) => void): {
|
|
23
|
+
close(): void;
|
|
24
|
+
};
|
|
25
|
+
get volume(): MemoryVolume;
|
|
26
|
+
private _removeRecursive;
|
|
27
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { EventEmitter } from "../polyfills/events";
|
|
2
|
+
export declare class NodepodProcess extends EventEmitter {
|
|
3
|
+
private _abortController;
|
|
4
|
+
private _resolve;
|
|
5
|
+
private _stdout;
|
|
6
|
+
private _stderr;
|
|
7
|
+
private _exitCode;
|
|
8
|
+
private _sendStdinFn;
|
|
9
|
+
private _killFn;
|
|
10
|
+
readonly completion: Promise<{
|
|
11
|
+
stdout: string;
|
|
12
|
+
stderr: string;
|
|
13
|
+
exitCode: number;
|
|
14
|
+
}>;
|
|
15
|
+
constructor();
|
|
16
|
+
_setSendStdin(fn: (data: string) => void): void;
|
|
17
|
+
_setKillFn(fn: () => void): void;
|
|
18
|
+
_pushStdout(chunk: string): void;
|
|
19
|
+
_pushStderr(chunk: string): void;
|
|
20
|
+
_finish(exitCode: number): void;
|
|
21
|
+
get signal(): AbortSignal;
|
|
22
|
+
get exited(): boolean;
|
|
23
|
+
write(data: string): void;
|
|
24
|
+
kill(): void;
|
|
25
|
+
on(event: "output", handler: (chunk: string) => void): this;
|
|
26
|
+
on(event: "error", handler: (chunk: string) => void): this;
|
|
27
|
+
on(event: "exit", handler: (code: number) => void): this;
|
|
28
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { TerminalOptions, TerminalTheme } from "./types";
|
|
2
|
+
export interface TerminalWiring {
|
|
3
|
+
onCommand: (cmd: string) => Promise<void>;
|
|
4
|
+
getSendStdin: () => ((data: string) => void) | null;
|
|
5
|
+
getIsStdinRaw: () => boolean;
|
|
6
|
+
getActiveAbort: () => AbortController | null;
|
|
7
|
+
setActiveAbort: (ac: AbortController | null) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare class NodepodTerminal {
|
|
10
|
+
private _term;
|
|
11
|
+
private _fitAddon;
|
|
12
|
+
private _dataDisposable;
|
|
13
|
+
private _resizeHandler;
|
|
14
|
+
private _lineBuffer;
|
|
15
|
+
private _history;
|
|
16
|
+
private _historyIndex;
|
|
17
|
+
private _savedLine;
|
|
18
|
+
private _running;
|
|
19
|
+
private _cwd;
|
|
20
|
+
private _promptFn;
|
|
21
|
+
private _theme;
|
|
22
|
+
private _opts;
|
|
23
|
+
private _wiring;
|
|
24
|
+
constructor(opts: TerminalOptions);
|
|
25
|
+
_wireExecution(wiring: TerminalWiring): void;
|
|
26
|
+
_setRunning(running: boolean): void;
|
|
27
|
+
_writePrompt(): void;
|
|
28
|
+
_getCols(): number;
|
|
29
|
+
_getRows(): number;
|
|
30
|
+
_writeOutput(text: string, isError?: boolean): void;
|
|
31
|
+
attach(target: HTMLElement | string): void;
|
|
32
|
+
detach(): void;
|
|
33
|
+
clear(): void;
|
|
34
|
+
input(text: string): void;
|
|
35
|
+
setTheme(theme: Partial<TerminalTheme>): void;
|
|
36
|
+
fit(): void;
|
|
37
|
+
write(text: string): void;
|
|
38
|
+
writeln(text: string): void;
|
|
39
|
+
showPrompt(): void;
|
|
40
|
+
setCwd(cwd: string): void;
|
|
41
|
+
getCwd(): string;
|
|
42
|
+
get xterm(): any;
|
|
43
|
+
private _handleInput;
|
|
44
|
+
private _historyUp;
|
|
45
|
+
private _historyDown;
|
|
46
|
+
private _replaceLineWith;
|
|
47
|
+
private _executeCommand;
|
|
48
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { MemoryVolume } from "../memory-volume";
|
|
2
|
+
import { ScriptEngine } from "../script-engine";
|
|
3
|
+
import { DependencyInstaller } from "../packages/installer";
|
|
4
|
+
import { RequestProxy } from "../request-proxy";
|
|
5
|
+
import type { NodepodOptions, TerminalOptions, Snapshot, SpawnOptions } from "./types";
|
|
6
|
+
import { NodepodFS } from "./nodepod-fs";
|
|
7
|
+
import { NodepodProcess } from "./nodepod-process";
|
|
8
|
+
import { NodepodTerminal } from "./nodepod-terminal";
|
|
9
|
+
import { ProcessManager } from "../threading/process-manager";
|
|
10
|
+
export declare class Nodepod {
|
|
11
|
+
readonly fs: NodepodFS;
|
|
12
|
+
private _volume;
|
|
13
|
+
private _engine;
|
|
14
|
+
private _packages;
|
|
15
|
+
private _proxy;
|
|
16
|
+
private _cwd;
|
|
17
|
+
private _processManager;
|
|
18
|
+
private _vfsBridge;
|
|
19
|
+
private _sharedVFS;
|
|
20
|
+
private _syncChannel;
|
|
21
|
+
private _unwatchVFS;
|
|
22
|
+
private constructor();
|
|
23
|
+
static boot(opts?: NodepodOptions): Promise<Nodepod>;
|
|
24
|
+
spawn(cmd: string, args?: string[], opts?: SpawnOptions): Promise<NodepodProcess>;
|
|
25
|
+
private _resolveCommand;
|
|
26
|
+
createTerminal(opts: TerminalOptions): NodepodTerminal;
|
|
27
|
+
setPreviewScript(script: string): Promise<void>;
|
|
28
|
+
clearPreviewScript(): Promise<void>;
|
|
29
|
+
port(num: number): string | null;
|
|
30
|
+
snapshot(): Snapshot;
|
|
31
|
+
restore(snapshot: Snapshot): void;
|
|
32
|
+
teardown(): void;
|
|
33
|
+
get volume(): MemoryVolume;
|
|
34
|
+
get engine(): ScriptEngine;
|
|
35
|
+
get packages(): DependencyInstaller;
|
|
36
|
+
get proxy(): RequestProxy;
|
|
37
|
+
get processManager(): ProcessManager;
|
|
38
|
+
get cwd(): string;
|
|
39
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { VolumeSnapshot } from "../engine-types";
|
|
2
|
+
export interface NodepodOptions {
|
|
3
|
+
files?: Record<string, string | Uint8Array>;
|
|
4
|
+
env?: Record<string, string>;
|
|
5
|
+
workdir?: string;
|
|
6
|
+
swUrl?: string;
|
|
7
|
+
onServerReady?: (port: number, url: string) => void;
|
|
8
|
+
/** Show a small "nodepod" watermark link in preview iframes. Defaults to true. */
|
|
9
|
+
watermark?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface TerminalTheme {
|
|
12
|
+
background?: string;
|
|
13
|
+
foreground?: string;
|
|
14
|
+
cursor?: string;
|
|
15
|
+
selectionBackground?: string;
|
|
16
|
+
black?: string;
|
|
17
|
+
red?: string;
|
|
18
|
+
green?: string;
|
|
19
|
+
yellow?: string;
|
|
20
|
+
blue?: string;
|
|
21
|
+
magenta?: string;
|
|
22
|
+
cyan?: string;
|
|
23
|
+
white?: string;
|
|
24
|
+
brightBlack?: string;
|
|
25
|
+
brightRed?: string;
|
|
26
|
+
brightGreen?: string;
|
|
27
|
+
brightYellow?: string;
|
|
28
|
+
brightBlue?: string;
|
|
29
|
+
brightMagenta?: string;
|
|
30
|
+
brightCyan?: string;
|
|
31
|
+
brightWhite?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface TerminalOptions {
|
|
34
|
+
Terminal: any;
|
|
35
|
+
FitAddon?: any;
|
|
36
|
+
WebglAddon?: any;
|
|
37
|
+
theme?: TerminalTheme;
|
|
38
|
+
fontSize?: number;
|
|
39
|
+
fontFamily?: string;
|
|
40
|
+
prompt?: (cwd: string) => string;
|
|
41
|
+
}
|
|
42
|
+
export interface StatResult {
|
|
43
|
+
isFile: boolean;
|
|
44
|
+
isDirectory: boolean;
|
|
45
|
+
size: number;
|
|
46
|
+
mtime: number;
|
|
47
|
+
}
|
|
48
|
+
export type Snapshot = VolumeSnapshot;
|
|
49
|
+
export interface SpawnOptions {
|
|
50
|
+
cwd?: string;
|
|
51
|
+
env?: Record<string, string>;
|
|
52
|
+
signal?: AbortSignal;
|
|
53
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ShellResult, ShellContext } from "../shell-types";
|
|
2
|
+
export type PkgManager = "npm" | "pnpm" | "yarn" | "bun";
|
|
3
|
+
export interface PmDeps {
|
|
4
|
+
installPackages: (args: string[], ctx: ShellContext, pm?: PkgManager) => Promise<ShellResult>;
|
|
5
|
+
uninstallPackages: (args: string[], ctx: ShellContext, pm?: PkgManager) => Promise<ShellResult>;
|
|
6
|
+
listPackages: (ctx: ShellContext, pm?: PkgManager) => Promise<ShellResult>;
|
|
7
|
+
runScript: (args: string[], ctx: ShellContext) => Promise<ShellResult>;
|
|
8
|
+
npmInitOrCreate: (args: string[], sub: string, ctx: ShellContext) => Promise<ShellResult>;
|
|
9
|
+
npmInfo: (args: string[], ctx: ShellContext) => Promise<ShellResult>;
|
|
10
|
+
npmPack: (ctx: ShellContext) => ShellResult;
|
|
11
|
+
npmConfig: (args: string[], ctx: ShellContext) => ShellResult;
|
|
12
|
+
npxExecute: (params: string[], ctx: ShellContext) => Promise<ShellResult>;
|
|
13
|
+
executeNodeBinary: (filePath: string, args: string[], ctx: ShellContext, opts?: {
|
|
14
|
+
isFork?: boolean;
|
|
15
|
+
}) => Promise<ShellResult>;
|
|
16
|
+
evalCode: (code: string, ctx: ShellContext) => ShellResult;
|
|
17
|
+
printCode: (code: string, ctx: ShellContext) => ShellResult;
|
|
18
|
+
removeNodeModules: (cwd: string) => void;
|
|
19
|
+
formatErr: (msg: string, pm: PkgManager) => string;
|
|
20
|
+
formatWarn: (msg: string, pm: PkgManager) => string;
|
|
21
|
+
hasFile: (path: string) => boolean;
|
|
22
|
+
readFile: (path: string) => string;
|
|
23
|
+
writeFile: (path: string, data: string) => void;
|
|
24
|
+
npmPkg?: (args: string[], ctx: ShellContext) => ShellResult;
|
|
25
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ShellResult } from "./shell-types";
|
|
2
|
+
import * as pathModule from "../polyfills/path";
|
|
3
|
+
export declare const RESET = "\u001B[0m";
|
|
4
|
+
export declare const DIM = "\u001B[2m";
|
|
5
|
+
export declare const GREEN = "\u001B[32m";
|
|
6
|
+
export declare const MAGENTA = "\u001B[35m";
|
|
7
|
+
export declare const CYAN = "\u001B[36m";
|
|
8
|
+
export declare const BOLD_BLUE = "\u001B[1;34m";
|
|
9
|
+
export declare const BOLD_RED = "\u001B[1;31m";
|
|
10
|
+
export declare const ok: (stdout?: string) => ShellResult;
|
|
11
|
+
export declare const fail: (stderr: string, code?: number) => ShellResult;
|
|
12
|
+
export declare const EXIT_OK: ShellResult;
|
|
13
|
+
export declare const EXIT_FAIL: ShellResult;
|
|
14
|
+
export declare const MONTHS_SHORT: readonly ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
15
|
+
export declare const MONTHS_LONG: readonly ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
|
16
|
+
export declare const DAYS_SHORT: readonly ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
17
|
+
export declare const DAYS_LONG: readonly ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
|
18
|
+
export declare function resolvePath(p: string, cwd: string): string;
|
|
19
|
+
export { pathModule };
|
|
20
|
+
export declare function parseArgs(args: string[], knownFlags: string[], knownOpts?: string[]): {
|
|
21
|
+
flags: Set<string>;
|
|
22
|
+
opts: Record<string, string>;
|
|
23
|
+
positional: string[];
|
|
24
|
+
};
|
|
25
|
+
export declare function expandCharClass(s: string): string;
|
|
26
|
+
export declare function processEscapes(s: string): string;
|
|
27
|
+
export declare function humanSize(bytes: number): string;
|
|
28
|
+
export declare function globToRegex(pattern: string): string;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ShellResult, ShellCommand } from "./shell-types";
|
|
2
|
+
import type { MemoryVolume } from "../memory-volume";
|
|
3
|
+
export type SpawnChildCallback = (command: string, args: string[], opts?: {
|
|
4
|
+
cwd?: string;
|
|
5
|
+
env?: Record<string, string>;
|
|
6
|
+
stdio?: "pipe" | "inherit";
|
|
7
|
+
}) => Promise<{
|
|
8
|
+
pid: number;
|
|
9
|
+
exitCode: number;
|
|
10
|
+
stdout: string;
|
|
11
|
+
stderr: string;
|
|
12
|
+
}>;
|
|
13
|
+
export declare class NodepodShell {
|
|
14
|
+
private volume;
|
|
15
|
+
private cwd;
|
|
16
|
+
private env;
|
|
17
|
+
private commands;
|
|
18
|
+
private lastExit;
|
|
19
|
+
private aliases;
|
|
20
|
+
private _execQueue;
|
|
21
|
+
private _spawnChild;
|
|
22
|
+
constructor(volume: MemoryVolume, opts?: {
|
|
23
|
+
cwd?: string;
|
|
24
|
+
env?: Record<string, string>;
|
|
25
|
+
});
|
|
26
|
+
registerCommand(cmd: ShellCommand): void;
|
|
27
|
+
setSpawnChildCallback(cb: SpawnChildCallback | null): void;
|
|
28
|
+
getSpawnChildCallback(): SpawnChildCallback | null;
|
|
29
|
+
getCwd(): string;
|
|
30
|
+
setCwd(cwd: string): void;
|
|
31
|
+
getEnv(): Record<string, string>;
|
|
32
|
+
exec(command: string, opts?: {
|
|
33
|
+
cwd?: string;
|
|
34
|
+
env?: Record<string, string>;
|
|
35
|
+
}): Promise<ShellResult>;
|
|
36
|
+
private _execInner;
|
|
37
|
+
private execList;
|
|
38
|
+
private execPipeline;
|
|
39
|
+
private execCommand;
|
|
40
|
+
private buildContext;
|
|
41
|
+
private resolvePath;
|
|
42
|
+
private resolveFromPath;
|
|
43
|
+
private normalizePath;
|
|
44
|
+
private applyRedirects;
|
|
45
|
+
private expandCommandSubstitution;
|
|
46
|
+
private handleAlias;
|
|
47
|
+
private handleSource;
|
|
48
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Token, ListNode } from "./shell-types";
|
|
2
|
+
import type { MemoryVolume } from "../memory-volume";
|
|
3
|
+
export declare function expandVariables(raw: string, env: Record<string, string>, lastExit: number): string;
|
|
4
|
+
export declare function expandGlob(pattern: string, cwd: string, volume: MemoryVolume): string[];
|
|
5
|
+
export declare function tokenize(input: string, env: Record<string, string>, lastExit: number): Token[];
|
|
6
|
+
export declare function parse(input: string, env: Record<string, string>, lastExit?: number): ListNode;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { MemoryVolume } from "../memory-volume";
|
|
2
|
+
export interface ShellResult {
|
|
3
|
+
stdout: string;
|
|
4
|
+
stderr: string;
|
|
5
|
+
exitCode: number;
|
|
6
|
+
}
|
|
7
|
+
export interface ShellContext {
|
|
8
|
+
cwd: string;
|
|
9
|
+
env: Record<string, string>;
|
|
10
|
+
volume: MemoryVolume;
|
|
11
|
+
exec: (cmd: string, opts?: {
|
|
12
|
+
cwd?: string;
|
|
13
|
+
env?: Record<string, string>;
|
|
14
|
+
}) => Promise<ShellResult>;
|
|
15
|
+
}
|
|
16
|
+
export interface ShellCommand {
|
|
17
|
+
name: string;
|
|
18
|
+
execute(args: string[], ctx: ShellContext): Promise<ShellResult>;
|
|
19
|
+
}
|
|
20
|
+
export interface RedirectNode {
|
|
21
|
+
type: "write" | "append" | "read" | "stderr-to-stdout";
|
|
22
|
+
target: string;
|
|
23
|
+
}
|
|
24
|
+
export interface CommandNode {
|
|
25
|
+
kind: "command";
|
|
26
|
+
args: string[];
|
|
27
|
+
redirects: RedirectNode[];
|
|
28
|
+
assignments: Record<string, string>;
|
|
29
|
+
}
|
|
30
|
+
export interface PipelineNode {
|
|
31
|
+
kind: "pipeline";
|
|
32
|
+
commands: CommandNode[];
|
|
33
|
+
}
|
|
34
|
+
export type ListOperator = "&&" | "||" | ";";
|
|
35
|
+
export interface ListEntry {
|
|
36
|
+
pipeline: PipelineNode;
|
|
37
|
+
next?: ListOperator;
|
|
38
|
+
}
|
|
39
|
+
export interface ListNode {
|
|
40
|
+
kind: "list";
|
|
41
|
+
entries: ListEntry[];
|
|
42
|
+
}
|
|
43
|
+
export type TokenType = "word" | "pipe" | "and" | "or" | "semi" | "redirect-out" | "redirect-app" | "redirect-in" | "redirect-2to1" | "newline" | "eof";
|
|
44
|
+
export interface Token {
|
|
45
|
+
type: TokenType;
|
|
46
|
+
value: string;
|
|
47
|
+
}
|
|
48
|
+
export type BuiltinFn = (args: string[], ctx: ShellContext, stdin?: string) => Promise<ShellResult> | ShellResult;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
export declare enum TaskPriority {
|
|
2
|
+
HIGH = 0,// runtime transforms (user waiting)
|
|
3
|
+
NORMAL = 1,// install-time bulk transforms
|
|
4
|
+
LOW = 2
|
|
5
|
+
}
|
|
6
|
+
export interface TransformTask {
|
|
7
|
+
type: "transform";
|
|
8
|
+
id: string;
|
|
9
|
+
source: string;
|
|
10
|
+
filePath: string;
|
|
11
|
+
options?: {
|
|
12
|
+
loader?: "js" | "jsx" | "ts" | "tsx";
|
|
13
|
+
format?: "cjs" | "esm";
|
|
14
|
+
target?: string;
|
|
15
|
+
platform?: string;
|
|
16
|
+
define?: Record<string, string>;
|
|
17
|
+
};
|
|
18
|
+
priority: TaskPriority;
|
|
19
|
+
}
|
|
20
|
+
export interface TransformResult {
|
|
21
|
+
type: "transform";
|
|
22
|
+
id: string;
|
|
23
|
+
code: string;
|
|
24
|
+
warnings: string[];
|
|
25
|
+
}
|
|
26
|
+
export interface ExtractTask {
|
|
27
|
+
type: "extract";
|
|
28
|
+
id: string;
|
|
29
|
+
tarballUrl: string;
|
|
30
|
+
stripComponents: number;
|
|
31
|
+
priority: TaskPriority;
|
|
32
|
+
}
|
|
33
|
+
export interface ExtractedFile {
|
|
34
|
+
path: string;
|
|
35
|
+
data: string;
|
|
36
|
+
isBinary: boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface ExtractResult {
|
|
39
|
+
type: "extract";
|
|
40
|
+
id: string;
|
|
41
|
+
files: ExtractedFile[];
|
|
42
|
+
}
|
|
43
|
+
export interface BuildTask {
|
|
44
|
+
type: "build";
|
|
45
|
+
id: string;
|
|
46
|
+
files: Record<string, string>;
|
|
47
|
+
entryPoints?: string[];
|
|
48
|
+
stdin?: {
|
|
49
|
+
contents: string;
|
|
50
|
+
resolveDir?: string;
|
|
51
|
+
loader?: string;
|
|
52
|
+
};
|
|
53
|
+
bundle?: boolean;
|
|
54
|
+
format?: "iife" | "cjs" | "esm";
|
|
55
|
+
platform?: "browser" | "node" | "neutral";
|
|
56
|
+
target?: string | string[];
|
|
57
|
+
minify?: boolean;
|
|
58
|
+
external?: string[];
|
|
59
|
+
absWorkingDir?: string;
|
|
60
|
+
priority: TaskPriority;
|
|
61
|
+
}
|
|
62
|
+
export interface BuildOutputFile {
|
|
63
|
+
path: string;
|
|
64
|
+
text: string;
|
|
65
|
+
}
|
|
66
|
+
export interface BuildResult {
|
|
67
|
+
type: "build";
|
|
68
|
+
id: string;
|
|
69
|
+
outputFiles: BuildOutputFile[];
|
|
70
|
+
errors: string[];
|
|
71
|
+
warnings: string[];
|
|
72
|
+
}
|
|
73
|
+
export type OffloadTask = TransformTask | ExtractTask | BuildTask;
|
|
74
|
+
export type OffloadResult = TransformResult | ExtractResult | BuildResult;
|
|
75
|
+
export interface OffloadWorkerEndpoint {
|
|
76
|
+
init(): Promise<void>;
|
|
77
|
+
transform(task: TransformTask): Promise<TransformResult>;
|
|
78
|
+
extract(task: ExtractTask): Promise<ExtractResult>;
|
|
79
|
+
build(task: BuildTask): Promise<BuildResult>;
|
|
80
|
+
ping(): boolean;
|
|
81
|
+
}
|
|
82
|
+
export interface PoolConfig {
|
|
83
|
+
minWorkers?: number;
|
|
84
|
+
maxWorkers?: number;
|
|
85
|
+
idleTimeoutMs?: number;
|
|
86
|
+
warmUpOnCreate?: boolean;
|
|
87
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|