sandboxedjs 0.1.12 → 0.1.14
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/index.cjs +150 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +150 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1509,6 +1509,7 @@ declare class Container {
|
|
|
1509
1509
|
private readonly hooks;
|
|
1510
1510
|
private disposed;
|
|
1511
1511
|
private defaultSession;
|
|
1512
|
+
private readonly restoreNodeChildProcessBridge;
|
|
1512
1513
|
private constructor();
|
|
1513
1514
|
static create(opts?: ContainerOptions): Promise<Container>;
|
|
1514
1515
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1509,6 +1509,7 @@ declare class Container {
|
|
|
1509
1509
|
private readonly hooks;
|
|
1510
1510
|
private disposed;
|
|
1511
1511
|
private defaultSession;
|
|
1512
|
+
private readonly restoreNodeChildProcessBridge;
|
|
1512
1513
|
private constructor();
|
|
1513
1514
|
static create(opts?: ContainerOptions): Promise<Container>;
|
|
1514
1515
|
/**
|
package/dist/index.js
CHANGED
|
@@ -22542,7 +22542,13 @@ async function loadFactory() {
|
|
|
22542
22542
|
const { createRequire } = await nodeBuiltin("module");
|
|
22543
22543
|
const fs = await nodeBuiltin("fs/promises");
|
|
22544
22544
|
const path = await nodeBuiltin("path");
|
|
22545
|
-
const
|
|
22545
|
+
const packageRequire = createRequire(import.meta.url);
|
|
22546
|
+
let require2 = packageRequire;
|
|
22547
|
+
try {
|
|
22548
|
+
require2.resolve("@ffmpeg/core/wasm");
|
|
22549
|
+
} catch {
|
|
22550
|
+
require2 = createRequire(path.join(process.cwd(), "index.js"));
|
|
22551
|
+
}
|
|
22546
22552
|
const wasmPath = require2.resolve("@ffmpeg/core/wasm");
|
|
22547
22553
|
const wasm = await fs.readFile(wasmPath);
|
|
22548
22554
|
const module = await Promise.resolve().then(() => (init_ffmpeg_core(), ffmpeg_core_exports));
|
|
@@ -23670,6 +23676,146 @@ var Session = class {
|
|
|
23670
23676
|
}
|
|
23671
23677
|
};
|
|
23672
23678
|
|
|
23679
|
+
// src/runtime/node-child-process-bridge.ts
|
|
23680
|
+
var KernelChildProcess = class {
|
|
23681
|
+
pid;
|
|
23682
|
+
command;
|
|
23683
|
+
args;
|
|
23684
|
+
parentPid;
|
|
23685
|
+
state = "running";
|
|
23686
|
+
exitCode;
|
|
23687
|
+
stdout = "";
|
|
23688
|
+
stderr = "";
|
|
23689
|
+
listeners = /* @__PURE__ */ new Map();
|
|
23690
|
+
kernel;
|
|
23691
|
+
cred;
|
|
23692
|
+
cwd;
|
|
23693
|
+
env;
|
|
23694
|
+
stdin = new Pipe();
|
|
23695
|
+
process;
|
|
23696
|
+
started = false;
|
|
23697
|
+
cancelled = false;
|
|
23698
|
+
constructor(kernel, cred, config, pid) {
|
|
23699
|
+
this.kernel = kernel;
|
|
23700
|
+
this.cred = cred;
|
|
23701
|
+
this.pid = pid;
|
|
23702
|
+
this.command = config.command;
|
|
23703
|
+
this.args = config.args?.slice() ?? [];
|
|
23704
|
+
this.parentPid = config.parentPid;
|
|
23705
|
+
this.cwd = config.cwd ?? "/";
|
|
23706
|
+
this.env = { ...config.env };
|
|
23707
|
+
}
|
|
23708
|
+
on(event, listener) {
|
|
23709
|
+
let listeners = this.listeners.get(event);
|
|
23710
|
+
if (!listeners) {
|
|
23711
|
+
listeners = /* @__PURE__ */ new Set();
|
|
23712
|
+
this.listeners.set(event, listeners);
|
|
23713
|
+
}
|
|
23714
|
+
listeners.add(listener);
|
|
23715
|
+
return this;
|
|
23716
|
+
}
|
|
23717
|
+
emit(event, ...args) {
|
|
23718
|
+
for (const listener of this.listeners.get(event) ?? []) listener(...args);
|
|
23719
|
+
}
|
|
23720
|
+
exec() {
|
|
23721
|
+
if (this.started) return;
|
|
23722
|
+
this.started = true;
|
|
23723
|
+
queueMicrotask(() => {
|
|
23724
|
+
if (this.cancelled) {
|
|
23725
|
+
this.finish(143);
|
|
23726
|
+
return;
|
|
23727
|
+
}
|
|
23728
|
+
const stdout = new ChildOutput(this, "stdout");
|
|
23729
|
+
const stderr = new ChildOutput(this, "stderr");
|
|
23730
|
+
try {
|
|
23731
|
+
this.process = this.kernel.spawn([this.command, ...this.args], {
|
|
23732
|
+
cwd: this.cwd,
|
|
23733
|
+
env: this.env,
|
|
23734
|
+
cred: this.cred,
|
|
23735
|
+
stdin: this.stdin,
|
|
23736
|
+
stdout,
|
|
23737
|
+
stderr,
|
|
23738
|
+
ppid: 1
|
|
23739
|
+
});
|
|
23740
|
+
void this.process.wait().then((code) => {
|
|
23741
|
+
stdout.end();
|
|
23742
|
+
stderr.end();
|
|
23743
|
+
this.finish(code);
|
|
23744
|
+
});
|
|
23745
|
+
} catch (error) {
|
|
23746
|
+
stderr.write(error instanceof Error ? error.message : String(error));
|
|
23747
|
+
stderr.end();
|
|
23748
|
+
stdout.end();
|
|
23749
|
+
this.finish(1);
|
|
23750
|
+
}
|
|
23751
|
+
});
|
|
23752
|
+
}
|
|
23753
|
+
sendStdin(data) {
|
|
23754
|
+
try {
|
|
23755
|
+
this.stdin.write(data);
|
|
23756
|
+
} catch {
|
|
23757
|
+
}
|
|
23758
|
+
}
|
|
23759
|
+
kill(signal = "SIGTERM") {
|
|
23760
|
+
if (this.process) {
|
|
23761
|
+
this.process.deliver(signal);
|
|
23762
|
+
return;
|
|
23763
|
+
}
|
|
23764
|
+
this.cancelled = true;
|
|
23765
|
+
}
|
|
23766
|
+
finish(code) {
|
|
23767
|
+
if (this.state === "exited") return;
|
|
23768
|
+
this.state = "exited";
|
|
23769
|
+
this.exitCode = code;
|
|
23770
|
+
this.emit("exit", code);
|
|
23771
|
+
}
|
|
23772
|
+
append(stream, text) {
|
|
23773
|
+
this[stream] += text;
|
|
23774
|
+
this.emit(stream, text);
|
|
23775
|
+
}
|
|
23776
|
+
};
|
|
23777
|
+
var ChildOutput = class {
|
|
23778
|
+
constructor(child, stream) {
|
|
23779
|
+
this.child = child;
|
|
23780
|
+
this.stream = stream;
|
|
23781
|
+
}
|
|
23782
|
+
child;
|
|
23783
|
+
stream;
|
|
23784
|
+
isTTY = false;
|
|
23785
|
+
closedState = false;
|
|
23786
|
+
decoder = new TextDecoder();
|
|
23787
|
+
get closed() {
|
|
23788
|
+
return this.closedState;
|
|
23789
|
+
}
|
|
23790
|
+
write(data) {
|
|
23791
|
+
if (this.closedState) return;
|
|
23792
|
+
const text = typeof data === "string" ? data : this.decoder.decode(data, { stream: true });
|
|
23793
|
+
if (text) this.child.append(this.stream, text);
|
|
23794
|
+
}
|
|
23795
|
+
end() {
|
|
23796
|
+
if (this.closedState) return;
|
|
23797
|
+
this.closedState = true;
|
|
23798
|
+
const tail2 = this.decoder.decode();
|
|
23799
|
+
if (tail2) this.child.append(this.stream, tail2);
|
|
23800
|
+
}
|
|
23801
|
+
};
|
|
23802
|
+
var nextBridgePid = 1073741824;
|
|
23803
|
+
function installNodeChildProcessBridge(pod, kernel, cred) {
|
|
23804
|
+
const manager = pod.processManager;
|
|
23805
|
+
const originalSpawn = manager.spawn;
|
|
23806
|
+
manager.spawn = (config) => {
|
|
23807
|
+
const resolved = kernel.resolveExecutable(config.command, config.cwd ?? "/", config.env ?? {}, cred);
|
|
23808
|
+
if (resolved?.kind === "builtin" && resolved.command?.name !== "node" && resolved.command?.name !== "nodejs") {
|
|
23809
|
+
return new KernelChildProcess(kernel, cred, config, nextBridgePid++);
|
|
23810
|
+
}
|
|
23811
|
+
return originalSpawn.call(manager, config);
|
|
23812
|
+
};
|
|
23813
|
+
return () => {
|
|
23814
|
+
if (manager.spawn === originalSpawn) return;
|
|
23815
|
+
manager.spawn = originalSpawn;
|
|
23816
|
+
};
|
|
23817
|
+
}
|
|
23818
|
+
|
|
23673
23819
|
// src/container/container.ts
|
|
23674
23820
|
var Container = class _Container {
|
|
23675
23821
|
kernel;
|
|
@@ -23680,6 +23826,7 @@ var Container = class _Container {
|
|
|
23680
23826
|
hooks;
|
|
23681
23827
|
disposed = false;
|
|
23682
23828
|
defaultSession = null;
|
|
23829
|
+
restoreNodeChildProcessBridge;
|
|
23683
23830
|
constructor(kernel, pod, opts) {
|
|
23684
23831
|
this.kernel = kernel;
|
|
23685
23832
|
this.pod = pod;
|
|
@@ -23708,6 +23855,7 @@ var Container = class _Container {
|
|
|
23708
23855
|
};
|
|
23709
23856
|
if (opts.timeoutMs !== void 0) this.defaults.timeoutMs = opts.timeoutMs;
|
|
23710
23857
|
this.hooks = { onStdout: opts.onStdout, onStderr: opts.onStderr };
|
|
23858
|
+
this.restoreNodeChildProcessBridge = installNodeChildProcessBridge(pod, kernel, cred);
|
|
23711
23859
|
}
|
|
23712
23860
|
// ── boot ──────────────────────────────────────────────────────────────────
|
|
23713
23861
|
static async create(opts = {}) {
|
|
@@ -24118,6 +24266,7 @@ var Container = class _Container {
|
|
|
24118
24266
|
dispose() {
|
|
24119
24267
|
if (this.disposed) return;
|
|
24120
24268
|
this.disposed = true;
|
|
24269
|
+
this.restoreNodeChildProcessBridge();
|
|
24121
24270
|
this.kernel.dispose();
|
|
24122
24271
|
try {
|
|
24123
24272
|
this.pod.teardown();
|