almostnode 0.1.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 +21 -0
- package/README.md +731 -0
- package/dist/__sw__.js +394 -0
- package/dist/ai-chatbot-demo-entry.d.ts +6 -0
- package/dist/ai-chatbot-demo-entry.d.ts.map +1 -0
- package/dist/ai-chatbot-demo.d.ts +42 -0
- package/dist/ai-chatbot-demo.d.ts.map +1 -0
- package/dist/assets/runtime-worker-D9x_Ddwz.js +60543 -0
- package/dist/assets/runtime-worker-D9x_Ddwz.js.map +1 -0
- package/dist/convex-app-demo-entry.d.ts +6 -0
- package/dist/convex-app-demo-entry.d.ts.map +1 -0
- package/dist/convex-app-demo.d.ts +68 -0
- package/dist/convex-app-demo.d.ts.map +1 -0
- package/dist/cors-proxy.d.ts +46 -0
- package/dist/cors-proxy.d.ts.map +1 -0
- package/dist/create-runtime.d.ts +42 -0
- package/dist/create-runtime.d.ts.map +1 -0
- package/dist/demo.d.ts +6 -0
- package/dist/demo.d.ts.map +1 -0
- package/dist/dev-server.d.ts +97 -0
- package/dist/dev-server.d.ts.map +1 -0
- package/dist/frameworks/next-dev-server.d.ts +202 -0
- package/dist/frameworks/next-dev-server.d.ts.map +1 -0
- package/dist/frameworks/vite-dev-server.d.ts +85 -0
- package/dist/frameworks/vite-dev-server.d.ts.map +1 -0
- package/dist/index.cjs +14965 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +71 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +14867 -0
- package/dist/index.mjs.map +1 -0
- package/dist/next-demo.d.ts +49 -0
- package/dist/next-demo.d.ts.map +1 -0
- package/dist/npm/index.d.ts +71 -0
- package/dist/npm/index.d.ts.map +1 -0
- package/dist/npm/registry.d.ts +66 -0
- package/dist/npm/registry.d.ts.map +1 -0
- package/dist/npm/resolver.d.ts +52 -0
- package/dist/npm/resolver.d.ts.map +1 -0
- package/dist/npm/tarball.d.ts +29 -0
- package/dist/npm/tarball.d.ts.map +1 -0
- package/dist/runtime-interface.d.ts +90 -0
- package/dist/runtime-interface.d.ts.map +1 -0
- package/dist/runtime.d.ts +103 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/sandbox-helpers.d.ts +43 -0
- package/dist/sandbox-helpers.d.ts.map +1 -0
- package/dist/sandbox-runtime.d.ts +65 -0
- package/dist/sandbox-runtime.d.ts.map +1 -0
- package/dist/server-bridge.d.ts +89 -0
- package/dist/server-bridge.d.ts.map +1 -0
- package/dist/shims/assert.d.ts +51 -0
- package/dist/shims/assert.d.ts.map +1 -0
- package/dist/shims/async_hooks.d.ts +37 -0
- package/dist/shims/async_hooks.d.ts.map +1 -0
- package/dist/shims/buffer.d.ts +20 -0
- package/dist/shims/buffer.d.ts.map +1 -0
- package/dist/shims/child_process-browser.d.ts +92 -0
- package/dist/shims/child_process-browser.d.ts.map +1 -0
- package/dist/shims/child_process.d.ts +93 -0
- package/dist/shims/child_process.d.ts.map +1 -0
- package/dist/shims/chokidar.d.ts +55 -0
- package/dist/shims/chokidar.d.ts.map +1 -0
- package/dist/shims/cluster.d.ts +52 -0
- package/dist/shims/cluster.d.ts.map +1 -0
- package/dist/shims/crypto.d.ts +122 -0
- package/dist/shims/crypto.d.ts.map +1 -0
- package/dist/shims/dgram.d.ts +34 -0
- package/dist/shims/dgram.d.ts.map +1 -0
- package/dist/shims/diagnostics_channel.d.ts +80 -0
- package/dist/shims/diagnostics_channel.d.ts.map +1 -0
- package/dist/shims/dns.d.ts +87 -0
- package/dist/shims/dns.d.ts.map +1 -0
- package/dist/shims/domain.d.ts +25 -0
- package/dist/shims/domain.d.ts.map +1 -0
- package/dist/shims/esbuild.d.ts +105 -0
- package/dist/shims/esbuild.d.ts.map +1 -0
- package/dist/shims/events.d.ts +37 -0
- package/dist/shims/events.d.ts.map +1 -0
- package/dist/shims/fs.d.ts +115 -0
- package/dist/shims/fs.d.ts.map +1 -0
- package/dist/shims/fsevents.d.ts +67 -0
- package/dist/shims/fsevents.d.ts.map +1 -0
- package/dist/shims/http.d.ts +217 -0
- package/dist/shims/http.d.ts.map +1 -0
- package/dist/shims/http2.d.ts +81 -0
- package/dist/shims/http2.d.ts.map +1 -0
- package/dist/shims/https.d.ts +36 -0
- package/dist/shims/https.d.ts.map +1 -0
- package/dist/shims/inspector.d.ts +25 -0
- package/dist/shims/inspector.d.ts.map +1 -0
- package/dist/shims/module.d.ts +22 -0
- package/dist/shims/module.d.ts.map +1 -0
- package/dist/shims/net.d.ts +100 -0
- package/dist/shims/net.d.ts.map +1 -0
- package/dist/shims/os.d.ts +159 -0
- package/dist/shims/os.d.ts.map +1 -0
- package/dist/shims/path.d.ts +72 -0
- package/dist/shims/path.d.ts.map +1 -0
- package/dist/shims/perf_hooks.d.ts +50 -0
- package/dist/shims/perf_hooks.d.ts.map +1 -0
- package/dist/shims/process.d.ts +93 -0
- package/dist/shims/process.d.ts.map +1 -0
- package/dist/shims/querystring.d.ts +23 -0
- package/dist/shims/querystring.d.ts.map +1 -0
- package/dist/shims/readdirp.d.ts +52 -0
- package/dist/shims/readdirp.d.ts.map +1 -0
- package/dist/shims/readline.d.ts +62 -0
- package/dist/shims/readline.d.ts.map +1 -0
- package/dist/shims/rollup.d.ts +34 -0
- package/dist/shims/rollup.d.ts.map +1 -0
- package/dist/shims/sentry.d.ts +163 -0
- package/dist/shims/sentry.d.ts.map +1 -0
- package/dist/shims/stream.d.ts +181 -0
- package/dist/shims/stream.d.ts.map +1 -0
- package/dist/shims/tls.d.ts +53 -0
- package/dist/shims/tls.d.ts.map +1 -0
- package/dist/shims/tty.d.ts +30 -0
- package/dist/shims/tty.d.ts.map +1 -0
- package/dist/shims/url.d.ts +64 -0
- package/dist/shims/url.d.ts.map +1 -0
- package/dist/shims/util.d.ts +106 -0
- package/dist/shims/util.d.ts.map +1 -0
- package/dist/shims/v8.d.ts +73 -0
- package/dist/shims/v8.d.ts.map +1 -0
- package/dist/shims/vfs-adapter.d.ts +126 -0
- package/dist/shims/vfs-adapter.d.ts.map +1 -0
- package/dist/shims/vm.d.ts +45 -0
- package/dist/shims/vm.d.ts.map +1 -0
- package/dist/shims/worker_threads.d.ts +66 -0
- package/dist/shims/worker_threads.d.ts.map +1 -0
- package/dist/shims/ws.d.ts +66 -0
- package/dist/shims/ws.d.ts.map +1 -0
- package/dist/shims/zlib.d.ts +161 -0
- package/dist/shims/zlib.d.ts.map +1 -0
- package/dist/transform.d.ts +24 -0
- package/dist/transform.d.ts.map +1 -0
- package/dist/virtual-fs.d.ts +226 -0
- package/dist/virtual-fs.d.ts.map +1 -0
- package/dist/vite-demo.d.ts +35 -0
- package/dist/vite-demo.d.ts.map +1 -0
- package/dist/vite-sw.js +132 -0
- package/dist/worker/runtime-worker.d.ts +8 -0
- package/dist/worker/runtime-worker.d.ts.map +1 -0
- package/dist/worker-runtime.d.ts +50 -0
- package/dist/worker-runtime.d.ts.map +1 -0
- package/package.json +85 -0
- package/src/ai-chatbot-demo-entry.ts +244 -0
- package/src/ai-chatbot-demo.ts +509 -0
- package/src/convex-app-demo-entry.ts +1107 -0
- package/src/convex-app-demo.ts +1316 -0
- package/src/cors-proxy.ts +81 -0
- package/src/create-runtime.ts +147 -0
- package/src/demo.ts +304 -0
- package/src/dev-server.ts +274 -0
- package/src/frameworks/next-dev-server.ts +2224 -0
- package/src/frameworks/vite-dev-server.ts +702 -0
- package/src/index.ts +101 -0
- package/src/next-demo.ts +1784 -0
- package/src/npm/index.ts +347 -0
- package/src/npm/registry.ts +152 -0
- package/src/npm/resolver.ts +385 -0
- package/src/npm/tarball.ts +209 -0
- package/src/runtime-interface.ts +103 -0
- package/src/runtime.ts +1046 -0
- package/src/sandbox-helpers.ts +173 -0
- package/src/sandbox-runtime.ts +252 -0
- package/src/server-bridge.ts +426 -0
- package/src/shims/assert.ts +664 -0
- package/src/shims/async_hooks.ts +86 -0
- package/src/shims/buffer.ts +75 -0
- package/src/shims/child_process-browser.ts +217 -0
- package/src/shims/child_process.ts +463 -0
- package/src/shims/chokidar.ts +313 -0
- package/src/shims/cluster.ts +67 -0
- package/src/shims/crypto.ts +830 -0
- package/src/shims/dgram.ts +47 -0
- package/src/shims/diagnostics_channel.ts +196 -0
- package/src/shims/dns.ts +172 -0
- package/src/shims/domain.ts +58 -0
- package/src/shims/esbuild.ts +805 -0
- package/src/shims/events.ts +195 -0
- package/src/shims/fs.ts +803 -0
- package/src/shims/fsevents.ts +63 -0
- package/src/shims/http.ts +904 -0
- package/src/shims/http2.ts +96 -0
- package/src/shims/https.ts +86 -0
- package/src/shims/inspector.ts +30 -0
- package/src/shims/module.ts +82 -0
- package/src/shims/net.ts +359 -0
- package/src/shims/os.ts +195 -0
- package/src/shims/path.ts +199 -0
- package/src/shims/perf_hooks.ts +92 -0
- package/src/shims/process.ts +346 -0
- package/src/shims/querystring.ts +97 -0
- package/src/shims/readdirp.ts +228 -0
- package/src/shims/readline.ts +110 -0
- package/src/shims/rollup.ts +80 -0
- package/src/shims/sentry.ts +133 -0
- package/src/shims/stream.ts +1126 -0
- package/src/shims/tls.ts +95 -0
- package/src/shims/tty.ts +64 -0
- package/src/shims/url.ts +171 -0
- package/src/shims/util.ts +312 -0
- package/src/shims/v8.ts +113 -0
- package/src/shims/vfs-adapter.ts +402 -0
- package/src/shims/vm.ts +83 -0
- package/src/shims/worker_threads.ts +111 -0
- package/src/shims/ws.ts +382 -0
- package/src/shims/zlib.ts +289 -0
- package/src/transform.ts +313 -0
- package/src/types/external.d.ts +67 -0
- package/src/virtual-fs.ts +903 -0
- package/src/vite-demo.ts +577 -0
- package/src/worker/runtime-worker.ts +128 -0
- package/src/worker-runtime.ts +145 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* async_hooks shim - Async tracking is not available in browser
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export class AsyncResource {
|
|
6
|
+
constructor(_type: string, _options?: object) {}
|
|
7
|
+
|
|
8
|
+
runInAsyncScope<T>(fn: (...args: unknown[]) => T, thisArg?: unknown, ...args: unknown[]): T {
|
|
9
|
+
return fn.apply(thisArg, args);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
emitDestroy(): this { return this; }
|
|
13
|
+
asyncId(): number { return 0; }
|
|
14
|
+
triggerAsyncId(): number { return 0; }
|
|
15
|
+
|
|
16
|
+
static bind<T extends (...args: unknown[]) => unknown>(fn: T, _type?: string): T {
|
|
17
|
+
return fn;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class AsyncLocalStorage<T> {
|
|
22
|
+
private store: T | undefined;
|
|
23
|
+
|
|
24
|
+
disable(): void {}
|
|
25
|
+
|
|
26
|
+
getStore(): T | undefined {
|
|
27
|
+
return this.store;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
run<R>(store: T, callback: () => R): R {
|
|
31
|
+
const prev = this.store;
|
|
32
|
+
this.store = store;
|
|
33
|
+
try {
|
|
34
|
+
return callback();
|
|
35
|
+
} finally {
|
|
36
|
+
this.store = prev;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
exit<R>(callback: () => R): R {
|
|
41
|
+
const prev = this.store;
|
|
42
|
+
this.store = undefined;
|
|
43
|
+
try {
|
|
44
|
+
return callback();
|
|
45
|
+
} finally {
|
|
46
|
+
this.store = prev;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
enterWith(store: T): void {
|
|
51
|
+
this.store = store;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface AsyncHook {
|
|
56
|
+
enable(): this;
|
|
57
|
+
disable(): this;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function createHook(_callbacks: object): AsyncHook {
|
|
61
|
+
return {
|
|
62
|
+
enable(): AsyncHook { return this; },
|
|
63
|
+
disable(): AsyncHook { return this; },
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function executionAsyncId(): number {
|
|
68
|
+
return 0;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function executionAsyncResource(): object {
|
|
72
|
+
return {};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function triggerAsyncId(): number {
|
|
76
|
+
return 0;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export default {
|
|
80
|
+
AsyncResource,
|
|
81
|
+
AsyncLocalStorage,
|
|
82
|
+
createHook,
|
|
83
|
+
executionAsyncId,
|
|
84
|
+
executionAsyncResource,
|
|
85
|
+
triggerAsyncId,
|
|
86
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js buffer module shim
|
|
3
|
+
* Provides Buffer class for browser environment
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Re-export Buffer from stream where it's defined
|
|
7
|
+
import { Buffer as BufferClass } from './stream';
|
|
8
|
+
|
|
9
|
+
// The buffer module exports Buffer as a named export
|
|
10
|
+
export const Buffer = BufferClass;
|
|
11
|
+
|
|
12
|
+
// SlowBuffer is deprecated but some packages still use it
|
|
13
|
+
export const SlowBuffer = BufferClass;
|
|
14
|
+
|
|
15
|
+
// kMaxLength is the maximum size of a Buffer
|
|
16
|
+
export const kMaxLength = 2147483647;
|
|
17
|
+
|
|
18
|
+
// INSPECT_MAX_BYTES controls how many bytes are shown when calling inspect()
|
|
19
|
+
export const INSPECT_MAX_BYTES = 50;
|
|
20
|
+
|
|
21
|
+
// Constants for Buffer pooling
|
|
22
|
+
export const constants = {
|
|
23
|
+
MAX_LENGTH: kMaxLength,
|
|
24
|
+
MAX_STRING_LENGTH: 536870888,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// transcode function - simplified
|
|
28
|
+
export function transcode(
|
|
29
|
+
source: Uint8Array,
|
|
30
|
+
_fromEnc: string,
|
|
31
|
+
_toEnc: string
|
|
32
|
+
): InstanceType<typeof Buffer> {
|
|
33
|
+
// Simplified - just return a copy
|
|
34
|
+
return Buffer.from(source);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// resolveObjectURL - returns undefined (no blob support)
|
|
38
|
+
export function resolveObjectURL(id: string): undefined {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// atob and btoa wrappers
|
|
43
|
+
export function atob(data: string): string {
|
|
44
|
+
return globalThis.atob(data);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function btoa(data: string): string {
|
|
48
|
+
return globalThis.btoa(data);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Default export as a plain object with all exports
|
|
52
|
+
// Using Object.create(null) and then assigning doesn't work well,
|
|
53
|
+
// so we use a regular object that has hasOwnProperty
|
|
54
|
+
const bufferModule: Record<string, unknown> = {
|
|
55
|
+
Buffer,
|
|
56
|
+
SlowBuffer,
|
|
57
|
+
kMaxLength,
|
|
58
|
+
INSPECT_MAX_BYTES,
|
|
59
|
+
constants,
|
|
60
|
+
transcode,
|
|
61
|
+
resolveObjectURL,
|
|
62
|
+
atob,
|
|
63
|
+
btoa,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// Ensure hasOwnProperty is accessible (should already be from Object.prototype)
|
|
67
|
+
// but we make it explicit
|
|
68
|
+
Object.defineProperty(bufferModule, 'hasOwnProperty', {
|
|
69
|
+
value: Object.prototype.hasOwnProperty,
|
|
70
|
+
enumerable: false,
|
|
71
|
+
configurable: true,
|
|
72
|
+
writable: true,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
export default bufferModule;
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-compatible child_process shim
|
|
3
|
+
* This version doesn't use just-bash and throws errors for commands
|
|
4
|
+
* Most CLI tools (like Convex CLI) don't actually need shell execution
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { EventEmitter } from './events';
|
|
8
|
+
import { Readable, Writable, Buffer } from './stream';
|
|
9
|
+
|
|
10
|
+
export interface ExecOptions {
|
|
11
|
+
cwd?: string;
|
|
12
|
+
env?: Record<string, string>;
|
|
13
|
+
encoding?: BufferEncoding | 'buffer';
|
|
14
|
+
timeout?: number;
|
|
15
|
+
maxBuffer?: number;
|
|
16
|
+
shell?: string | boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ExecResult {
|
|
20
|
+
stdout: string | Buffer;
|
|
21
|
+
stderr: string | Buffer;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type ExecCallback = (
|
|
25
|
+
error: Error | null,
|
|
26
|
+
stdout: string | Buffer,
|
|
27
|
+
stderr: string | Buffer
|
|
28
|
+
) => void;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Initialize child_process - no-op in browser version
|
|
32
|
+
*/
|
|
33
|
+
export function initChildProcess(): void {
|
|
34
|
+
// No-op - just-bash not used in browser version
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Execute a command in a shell
|
|
39
|
+
*/
|
|
40
|
+
export function exec(
|
|
41
|
+
command: string,
|
|
42
|
+
optionsOrCallback?: ExecOptions | ExecCallback,
|
|
43
|
+
callback?: ExecCallback
|
|
44
|
+
): ChildProcess {
|
|
45
|
+
let cb: ExecCallback | undefined;
|
|
46
|
+
|
|
47
|
+
if (typeof optionsOrCallback === 'function') {
|
|
48
|
+
cb = optionsOrCallback;
|
|
49
|
+
} else {
|
|
50
|
+
cb = callback;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const child = new ChildProcess();
|
|
54
|
+
|
|
55
|
+
// Execute asynchronously - emit error
|
|
56
|
+
setTimeout(() => {
|
|
57
|
+
const error = new Error(
|
|
58
|
+
`exec is not supported in browser environment: ${command}`
|
|
59
|
+
);
|
|
60
|
+
child.emit('error', error);
|
|
61
|
+
if (cb) cb(error, '', '');
|
|
62
|
+
}, 0);
|
|
63
|
+
|
|
64
|
+
return child;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Execute a command synchronously
|
|
69
|
+
*/
|
|
70
|
+
export function execSync(
|
|
71
|
+
command: string,
|
|
72
|
+
options?: ExecOptions
|
|
73
|
+
): string | Buffer {
|
|
74
|
+
throw new Error(
|
|
75
|
+
`execSync is not supported in browser environment: ${command}`
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface SpawnOptions {
|
|
80
|
+
cwd?: string;
|
|
81
|
+
env?: Record<string, string>;
|
|
82
|
+
shell?: boolean | string;
|
|
83
|
+
stdio?: 'pipe' | 'inherit' | 'ignore' | Array<'pipe' | 'inherit' | 'ignore'>;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Spawn a new process
|
|
88
|
+
*/
|
|
89
|
+
export function spawn(
|
|
90
|
+
command: string,
|
|
91
|
+
args?: string[] | SpawnOptions,
|
|
92
|
+
options?: SpawnOptions
|
|
93
|
+
): ChildProcess {
|
|
94
|
+
const child = new ChildProcess();
|
|
95
|
+
|
|
96
|
+
// Execute asynchronously - emit error
|
|
97
|
+
setTimeout(() => {
|
|
98
|
+
const error = new Error(
|
|
99
|
+
`spawn is not supported in browser environment: ${command}`
|
|
100
|
+
);
|
|
101
|
+
child.emit('error', error);
|
|
102
|
+
}, 0);
|
|
103
|
+
|
|
104
|
+
return child;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Spawn a new process synchronously
|
|
109
|
+
*/
|
|
110
|
+
export function spawnSync(
|
|
111
|
+
command: string,
|
|
112
|
+
args?: string[],
|
|
113
|
+
options?: SpawnOptions
|
|
114
|
+
): { stdout: Buffer; stderr: Buffer; status: number; error?: Error } {
|
|
115
|
+
throw new Error(
|
|
116
|
+
`spawnSync is not supported in browser environment: ${command}`
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Execute a file
|
|
122
|
+
*/
|
|
123
|
+
export function execFile(
|
|
124
|
+
file: string,
|
|
125
|
+
args?: string[] | ExecOptions | ExecCallback,
|
|
126
|
+
options?: ExecOptions | ExecCallback,
|
|
127
|
+
callback?: ExecCallback
|
|
128
|
+
): ChildProcess {
|
|
129
|
+
let cb: ExecCallback | undefined;
|
|
130
|
+
|
|
131
|
+
if (typeof args === 'function') {
|
|
132
|
+
cb = args;
|
|
133
|
+
} else if (typeof options === 'function') {
|
|
134
|
+
cb = options;
|
|
135
|
+
} else {
|
|
136
|
+
cb = callback;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const child = new ChildProcess();
|
|
140
|
+
|
|
141
|
+
setTimeout(() => {
|
|
142
|
+
const error = new Error(
|
|
143
|
+
`execFile is not supported in browser environment: ${file}`
|
|
144
|
+
);
|
|
145
|
+
child.emit('error', error);
|
|
146
|
+
if (cb) cb(error, '', '');
|
|
147
|
+
}, 0);
|
|
148
|
+
|
|
149
|
+
return child;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Fork is not supported in browser
|
|
154
|
+
*/
|
|
155
|
+
export function fork(): never {
|
|
156
|
+
throw new Error('fork is not supported in browser environment');
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* ChildProcess class
|
|
161
|
+
*/
|
|
162
|
+
export class ChildProcess extends EventEmitter {
|
|
163
|
+
pid: number;
|
|
164
|
+
connected: boolean = false;
|
|
165
|
+
killed: boolean = false;
|
|
166
|
+
exitCode: number | null = null;
|
|
167
|
+
signalCode: string | null = null;
|
|
168
|
+
spawnargs: string[] = [];
|
|
169
|
+
spawnfile: string = '';
|
|
170
|
+
|
|
171
|
+
stdin: Writable | null;
|
|
172
|
+
stdout: Readable | null;
|
|
173
|
+
stderr: Readable | null;
|
|
174
|
+
|
|
175
|
+
constructor() {
|
|
176
|
+
super();
|
|
177
|
+
this.pid = Math.floor(Math.random() * 10000) + 1000;
|
|
178
|
+
this.stdin = new Writable();
|
|
179
|
+
this.stdout = new Readable();
|
|
180
|
+
this.stderr = new Readable();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
kill(signal?: string): boolean {
|
|
184
|
+
this.killed = true;
|
|
185
|
+
this.emit('exit', null, signal || 'SIGTERM');
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
disconnect(): void {
|
|
190
|
+
this.connected = false;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
send(message: unknown, callback?: (error: Error | null) => void): boolean {
|
|
194
|
+
// IPC not supported
|
|
195
|
+
if (callback) callback(new Error('IPC not supported'));
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
ref(): this {
|
|
200
|
+
return this;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
unref(): this {
|
|
204
|
+
return this;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export default {
|
|
209
|
+
exec,
|
|
210
|
+
execSync,
|
|
211
|
+
execFile,
|
|
212
|
+
spawn,
|
|
213
|
+
spawnSync,
|
|
214
|
+
fork,
|
|
215
|
+
ChildProcess,
|
|
216
|
+
initChildProcess,
|
|
217
|
+
};
|