@sandblocks/cli 0.5.0-b.1 → 0.5.0-b.3
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/cli.js +44 -26
- package/dist/cli.js.map +3 -3
- package/dist/runtime-bin.js +114 -0
- package/package.json +4 -3
package/dist/cli.js
CHANGED
|
@@ -11878,7 +11878,8 @@ async function text(file) {
|
|
|
11878
11878
|
}
|
|
11879
11879
|
|
|
11880
11880
|
// src/runtime.ts
|
|
11881
|
-
import {
|
|
11881
|
+
import { spawn } from "child_process";
|
|
11882
|
+
import { access, chmod as chmod2, mkdir as mkdir2, readdir, rm as rm2 } from "fs/promises";
|
|
11882
11883
|
import path4 from "path";
|
|
11883
11884
|
var RUNTIME_PATTERN = /^[a-z][a-z0-9-]{0,62}$/;
|
|
11884
11885
|
var NODE_ENV_RUNTIME = {
|
|
@@ -11897,25 +11898,42 @@ async function runRuntimeCommand(args) {
|
|
|
11897
11898
|
const runtimeRoot = path4.join(targetRoot, runtime);
|
|
11898
11899
|
const config = contained(root, option(options, "config") ?? "config/dotlocker.config.ts", "Dotlocker config");
|
|
11899
11900
|
const dotlocker = path4.resolve(root, option(options, "dotlocker") ?? path4.join("node_modules", ".bin", "dotlocker"));
|
|
11900
|
-
if (!await
|
|
11901
|
+
if (!await exists2(config))
|
|
11901
11902
|
throw new Error(`Dotlocker config does not exist: ${config}`);
|
|
11902
|
-
if (!await
|
|
11903
|
+
if (!await exists2(dotlocker)) {
|
|
11903
11904
|
throw new Error("Dotlocker is not installed; add @dotlocker/dotlocker to the workspace");
|
|
11904
11905
|
}
|
|
11905
11906
|
await rm2(targetRoot, { recursive: true, force: true });
|
|
11906
11907
|
await mkdir2(runtimeRoot, { recursive: true, mode: 493 });
|
|
11907
|
-
|
|
11908
|
-
const exitCode = await child.exited;
|
|
11909
|
-
if (exitCode !== 0)
|
|
11910
|
-
throw new Error(`Dotlocker pull failed with exit code ${exitCode}`);
|
|
11908
|
+
await run(dotlocker, ["pull", "--config", config, "--runtime", runtime, "--out", runtimeRoot], root);
|
|
11911
11909
|
const envFile = path4.join(runtimeRoot, ".env");
|
|
11912
|
-
if (!await
|
|
11910
|
+
if (!await exists2(envFile)) {
|
|
11913
11911
|
throw new Error(`Dotlocker did not materialize ${path4.relative(root, envFile)}`);
|
|
11914
11912
|
}
|
|
11915
11913
|
await normalizePermissions(targetRoot);
|
|
11916
11914
|
console.log(`runtime ${runtime}
|
|
11917
11915
|
environment ${path4.relative(root, envFile)}`);
|
|
11918
11916
|
}
|
|
11917
|
+
function run(executable, args, cwd) {
|
|
11918
|
+
return new Promise((resolve, reject) => {
|
|
11919
|
+
const child = spawn(executable, args, { cwd, env: process.env, stdio: "inherit" });
|
|
11920
|
+
child.once("error", reject);
|
|
11921
|
+
child.once("exit", (code, signal) => {
|
|
11922
|
+
if (code === 0)
|
|
11923
|
+
resolve();
|
|
11924
|
+
else
|
|
11925
|
+
reject(new Error(`Dotlocker pull failed (${signal ? `signal ${signal}` : `exit ${code ?? "unknown"}`})`));
|
|
11926
|
+
});
|
|
11927
|
+
});
|
|
11928
|
+
}
|
|
11929
|
+
async function exists2(file) {
|
|
11930
|
+
try {
|
|
11931
|
+
await access(file);
|
|
11932
|
+
return true;
|
|
11933
|
+
} catch {
|
|
11934
|
+
return false;
|
|
11935
|
+
}
|
|
11936
|
+
}
|
|
11919
11937
|
function normalizedRuntime(value) {
|
|
11920
11938
|
const runtime = NODE_ENV_RUNTIME[value.trim()] ?? value.trim();
|
|
11921
11939
|
if (!RUNTIME_PATTERN.test(runtime))
|
|
@@ -12709,8 +12727,8 @@ import { dirname as dirname2, resolve as resolve7 } from "path";
|
|
|
12709
12727
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
12710
12728
|
import { appendFile, cp, mkdir as mkdir4, readFile as readFile5, rm as rm4 } from "fs/promises";
|
|
12711
12729
|
import { dirname, resolve } from "path";
|
|
12712
|
-
import { spawn } from "child_process";
|
|
12713
|
-
import { access, mkdir as mkdir22, writeFile as writeFile2 } from "fs/promises";
|
|
12730
|
+
import { spawn as spawn2 } from "child_process";
|
|
12731
|
+
import { access as access2, mkdir as mkdir22, writeFile as writeFile2 } from "fs/promises";
|
|
12714
12732
|
import { resolve as resolve2 } from "path";
|
|
12715
12733
|
|
|
12716
12734
|
class CommandAgent {
|
|
@@ -12966,7 +12984,7 @@ async function executeProcess(command, options = {}) {
|
|
|
12966
12984
|
const [executable, ...args] = command;
|
|
12967
12985
|
if (!executable)
|
|
12968
12986
|
throw new Error("command executable is required");
|
|
12969
|
-
const child =
|
|
12987
|
+
const child = spawn2(executable, args, {
|
|
12970
12988
|
cwd: options.cwd ?? options.hostCwd,
|
|
12971
12989
|
env: options.env ? { ...process.env, ...options.env } : process.env,
|
|
12972
12990
|
stdio: [options.stdin === undefined ? "ignore" : "pipe", "pipe", "pipe"]
|
|
@@ -13223,7 +13241,7 @@ async function connectSandbox(options) {
|
|
|
13223
13241
|
const runtime = await options.provider.reconnect({ id: options.id, cwd });
|
|
13224
13242
|
return new SandblocksSandbox(runtime, { provider: options.provider, cwd, retention: options.retention ?? "always" }, { hostCwd: cwd, runtimeCwd: cwd });
|
|
13225
13243
|
}
|
|
13226
|
-
async function
|
|
13244
|
+
async function run2(options) {
|
|
13227
13245
|
const sandbox = await createSandbox(options);
|
|
13228
13246
|
try {
|
|
13229
13247
|
return await sandbox.run(options);
|
|
@@ -13406,7 +13424,7 @@ SANDBLOCKS_API_KEY=
|
|
|
13406
13424
|
for (const [relative, content] of Object.entries(files)) {
|
|
13407
13425
|
const path6 = resolve2(root, relative);
|
|
13408
13426
|
await mkdir22(resolve2(path6, ".."), { recursive: true });
|
|
13409
|
-
if (!options.force && await
|
|
13427
|
+
if (!options.force && await access2(path6).then(() => true).catch(() => false))
|
|
13410
13428
|
continue;
|
|
13411
13429
|
await writeFile2(path6, content, { mode: relative.includes(".env") ? 384 : 420 });
|
|
13412
13430
|
written.push(path6);
|
|
@@ -13417,7 +13435,7 @@ SANDBLOCKS_API_KEY=
|
|
|
13417
13435
|
// ../sdk/dist/providers/docker.js
|
|
13418
13436
|
import { realpath as realpath3 } from "fs/promises";
|
|
13419
13437
|
import { resolve as resolve3 } from "path";
|
|
13420
|
-
import { spawn as
|
|
13438
|
+
import { spawn as spawn3 } from "child_process";
|
|
13421
13439
|
async function executeProcess2(command, options = {}) {
|
|
13422
13440
|
if (!command.length || command.some((part) => !part || part.includes("\x00"))) {
|
|
13423
13441
|
throw new Error("command must contain safe non-empty arguments");
|
|
@@ -13426,7 +13444,7 @@ async function executeProcess2(command, options = {}) {
|
|
|
13426
13444
|
const [executable, ...args] = command;
|
|
13427
13445
|
if (!executable)
|
|
13428
13446
|
throw new Error("command executable is required");
|
|
13429
|
-
const child =
|
|
13447
|
+
const child = spawn3(executable, args, {
|
|
13430
13448
|
cwd: options.cwd ?? options.hostCwd,
|
|
13431
13449
|
env: options.env ? { ...process.env, ...options.env } : process.env,
|
|
13432
13450
|
stdio: [options.stdin === undefined ? "ignore" : "pipe", "pipe", "pipe"]
|
|
@@ -13663,7 +13681,7 @@ class DockerProvider extends OciProvider {
|
|
|
13663
13681
|
// ../sdk/dist/providers/podman.js
|
|
13664
13682
|
import { realpath as realpath4 } from "fs/promises";
|
|
13665
13683
|
import { resolve as resolve5 } from "path";
|
|
13666
|
-
import { spawn as
|
|
13684
|
+
import { spawn as spawn4 } from "child_process";
|
|
13667
13685
|
async function executeProcess3(command, options = {}) {
|
|
13668
13686
|
if (!command.length || command.some((part) => !part || part.includes("\x00"))) {
|
|
13669
13687
|
throw new Error("command must contain safe non-empty arguments");
|
|
@@ -13672,7 +13690,7 @@ async function executeProcess3(command, options = {}) {
|
|
|
13672
13690
|
const [executable, ...args] = command;
|
|
13673
13691
|
if (!executable)
|
|
13674
13692
|
throw new Error("command executable is required");
|
|
13675
|
-
const child =
|
|
13693
|
+
const child = spawn4(executable, args, {
|
|
13676
13694
|
cwd: options.cwd ?? options.hostCwd,
|
|
13677
13695
|
env: options.env ? { ...process.env, ...options.env } : process.env,
|
|
13678
13696
|
stdio: [options.stdin === undefined ? "ignore" : "pipe", "pipe", "pipe"]
|
|
@@ -13911,7 +13929,7 @@ import { randomUUID as randomUUID3 } from "crypto";
|
|
|
13911
13929
|
import { mkdtemp, readFile as readFile6, rm as rm5, stat as stat2, writeFile as writeFile3 } from "fs/promises";
|
|
13912
13930
|
import { tmpdir } from "os";
|
|
13913
13931
|
import { join } from "path";
|
|
13914
|
-
import { spawn as
|
|
13932
|
+
import { spawn as spawn5 } from "child_process";
|
|
13915
13933
|
async function executeProcess4(command, options = {}) {
|
|
13916
13934
|
if (!command.length || command.some((part) => !part || part.includes("\x00"))) {
|
|
13917
13935
|
throw new Error("command must contain safe non-empty arguments");
|
|
@@ -13920,7 +13938,7 @@ async function executeProcess4(command, options = {}) {
|
|
|
13920
13938
|
const [executable, ...args] = command;
|
|
13921
13939
|
if (!executable)
|
|
13922
13940
|
throw new Error("command executable is required");
|
|
13923
|
-
const child =
|
|
13941
|
+
const child = spawn5(executable, args, {
|
|
13924
13942
|
cwd: options.cwd ?? options.hostCwd,
|
|
13925
13943
|
env: options.env ? { ...process.env, ...options.env } : process.env,
|
|
13926
13944
|
stdio: [options.stdin === undefined ? "ignore" : "pipe", "pipe", "pipe"]
|
|
@@ -14233,7 +14251,7 @@ async function sourceBundle(cwd) {
|
|
|
14233
14251
|
// ../sdk/dist/providers/unsafe-host.js
|
|
14234
14252
|
import { cp as cp2, realpath as realpath5 } from "fs/promises";
|
|
14235
14253
|
import { resolve as resolve6 } from "path";
|
|
14236
|
-
import { spawn as
|
|
14254
|
+
import { spawn as spawn6 } from "child_process";
|
|
14237
14255
|
async function executeProcess5(command, options = {}) {
|
|
14238
14256
|
if (!command.length || command.some((part) => !part || part.includes("\x00"))) {
|
|
14239
14257
|
throw new Error("command must contain safe non-empty arguments");
|
|
@@ -14242,7 +14260,7 @@ async function executeProcess5(command, options = {}) {
|
|
|
14242
14260
|
const [executable, ...args] = command;
|
|
14243
14261
|
if (!executable)
|
|
14244
14262
|
throw new Error("command executable is required");
|
|
14245
|
-
const child =
|
|
14263
|
+
const child = spawn6(executable, args, {
|
|
14246
14264
|
cwd: options.cwd ?? options.hostCwd,
|
|
14247
14265
|
env: options.env ? { ...process.env, ...options.env } : process.env,
|
|
14248
14266
|
stdio: [options.stdin === undefined ? "ignore" : "pipe", "pipe", "pipe"]
|
|
@@ -14355,7 +14373,7 @@ async function runSdkCommand(args, helpers) {
|
|
|
14355
14373
|
const provider = providerFrom(options, helpers, cwd);
|
|
14356
14374
|
const agent = agentFrom(options, helpers);
|
|
14357
14375
|
const outputTag = helpers.option(options, "output-tag");
|
|
14358
|
-
const result = await
|
|
14376
|
+
const result = await run2({
|
|
14359
14377
|
provider,
|
|
14360
14378
|
cwd,
|
|
14361
14379
|
image: helpers.option(options, "image"),
|
|
@@ -14708,7 +14726,7 @@ Low-level deploy remains available with --workspace, --sandbox, --host,
|
|
|
14708
14726
|
Authentication: --api-key or SANDBLOCKS_API_KEY
|
|
14709
14727
|
API endpoint: --api-url or SANDBLOCKS_API_URL
|
|
14710
14728
|
`;
|
|
14711
|
-
async function
|
|
14729
|
+
async function run3(argv = process.argv.slice(2)) {
|
|
14712
14730
|
await loadCliEnvironment(process.cwd());
|
|
14713
14731
|
const [command = "help", ...args] = argv;
|
|
14714
14732
|
if (command === "configure" || command === "init")
|
|
@@ -15423,15 +15441,15 @@ async function loadCliEnvironment(root) {
|
|
|
15423
15441
|
}
|
|
15424
15442
|
if (import.meta.main) {
|
|
15425
15443
|
try {
|
|
15426
|
-
await
|
|
15444
|
+
await run3();
|
|
15427
15445
|
} catch (error) {
|
|
15428
15446
|
console.error(`sandblocks: ${error instanceof Error ? error.message : String(error)}`);
|
|
15429
15447
|
process.exitCode = 1;
|
|
15430
15448
|
}
|
|
15431
15449
|
}
|
|
15432
15450
|
export {
|
|
15433
|
-
|
|
15451
|
+
run3 as run,
|
|
15434
15452
|
parse2 as parse
|
|
15435
15453
|
};
|
|
15436
15454
|
|
|
15437
|
-
//# debugId=
|
|
15455
|
+
//# debugId=C62D0719A3A5D1E864756E2164756E21
|