@sandblocks/cli 0.5.0-b.1 → 0.5.0-b.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/cli.js CHANGED
@@ -11878,8 +11878,10 @@ async function text(file) {
11878
11878
  }
11879
11879
 
11880
11880
  // src/runtime.ts
11881
- import { chmod as chmod2, mkdir as mkdir2, readdir, rm as rm2 } from "fs/promises";
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";
11884
+ import { pathToFileURL } from "url";
11883
11885
  var RUNTIME_PATTERN = /^[a-z][a-z0-9-]{0,62}$/;
11884
11886
  var NODE_ENV_RUNTIME = {
11885
11887
  production: "prod",
@@ -11897,25 +11899,42 @@ async function runRuntimeCommand(args) {
11897
11899
  const runtimeRoot = path4.join(targetRoot, runtime);
11898
11900
  const config = contained(root, option(options, "config") ?? "config/dotlocker.config.ts", "Dotlocker config");
11899
11901
  const dotlocker = path4.resolve(root, option(options, "dotlocker") ?? path4.join("node_modules", ".bin", "dotlocker"));
11900
- if (!await Bun.file(config).exists())
11902
+ if (!await exists2(config))
11901
11903
  throw new Error(`Dotlocker config does not exist: ${config}`);
11902
- if (!await Bun.file(dotlocker).exists()) {
11904
+ if (!await exists2(dotlocker)) {
11903
11905
  throw new Error("Dotlocker is not installed; add @dotlocker/dotlocker to the workspace");
11904
11906
  }
11905
11907
  await rm2(targetRoot, { recursive: true, force: true });
11906
11908
  await mkdir2(runtimeRoot, { recursive: true, mode: 493 });
11907
- const child = Bun.spawn([dotlocker, "pull", "--config", config, "--runtime", runtime, "--out", runtimeRoot], { cwd: root, env: process.env, stdin: "inherit", stdout: "inherit", stderr: "inherit" });
11908
- const exitCode = await child.exited;
11909
- if (exitCode !== 0)
11910
- throw new Error(`Dotlocker pull failed with exit code ${exitCode}`);
11909
+ await run(dotlocker, ["pull", "--config", config, "--runtime", runtime, "--out", runtimeRoot], root);
11911
11910
  const envFile = path4.join(runtimeRoot, ".env");
11912
- if (!await Bun.file(envFile).exists()) {
11911
+ if (!await exists2(envFile)) {
11913
11912
  throw new Error(`Dotlocker did not materialize ${path4.relative(root, envFile)}`);
11914
11913
  }
11915
11914
  await normalizePermissions(targetRoot);
11916
11915
  console.log(`runtime ${runtime}
11917
11916
  environment ${path4.relative(root, envFile)}`);
11918
11917
  }
11918
+ function run(executable, args, cwd) {
11919
+ return new Promise((resolve, reject) => {
11920
+ const child = spawn(executable, args, { cwd, env: process.env, stdio: "inherit" });
11921
+ child.once("error", reject);
11922
+ child.once("exit", (code, signal) => {
11923
+ if (code === 0)
11924
+ resolve();
11925
+ else
11926
+ reject(new Error(`Dotlocker pull failed (${signal ? `signal ${signal}` : `exit ${code ?? "unknown"}`})`));
11927
+ });
11928
+ });
11929
+ }
11930
+ async function exists2(file) {
11931
+ try {
11932
+ await access(file);
11933
+ return true;
11934
+ } catch {
11935
+ return false;
11936
+ }
11937
+ }
11919
11938
  function normalizedRuntime(value) {
11920
11939
  const runtime = NODE_ENV_RUNTIME[value.trim()] ?? value.trim();
11921
11940
  if (!RUNTIME_PATTERN.test(runtime))
@@ -11965,6 +11984,12 @@ function option(options, key) {
11965
11984
  const value = options[key];
11966
11985
  return typeof value === "string" ? value : undefined;
11967
11986
  }
11987
+ if (process.argv[1] && import.meta.url === pathToFileURL(path4.resolve(process.argv[1])).href) {
11988
+ runRuntimeCommand(process.argv.slice(2)).catch((error) => {
11989
+ console.error(`sandblocks-runtime: ${error instanceof Error ? error.message : String(error)}`);
11990
+ process.exitCode = 1;
11991
+ });
11992
+ }
11968
11993
 
11969
11994
  // src/sandbox.ts
11970
11995
  init_src();
@@ -12709,8 +12734,8 @@ import { dirname as dirname2, resolve as resolve7 } from "path";
12709
12734
  import { randomUUID as randomUUID2 } from "crypto";
12710
12735
  import { appendFile, cp, mkdir as mkdir4, readFile as readFile5, rm as rm4 } from "fs/promises";
12711
12736
  import { dirname, resolve } from "path";
12712
- import { spawn } from "child_process";
12713
- import { access, mkdir as mkdir22, writeFile as writeFile2 } from "fs/promises";
12737
+ import { spawn as spawn2 } from "child_process";
12738
+ import { access as access2, mkdir as mkdir22, writeFile as writeFile2 } from "fs/promises";
12714
12739
  import { resolve as resolve2 } from "path";
12715
12740
 
12716
12741
  class CommandAgent {
@@ -12966,7 +12991,7 @@ async function executeProcess(command, options = {}) {
12966
12991
  const [executable, ...args] = command;
12967
12992
  if (!executable)
12968
12993
  throw new Error("command executable is required");
12969
- const child = spawn(executable, args, {
12994
+ const child = spawn2(executable, args, {
12970
12995
  cwd: options.cwd ?? options.hostCwd,
12971
12996
  env: options.env ? { ...process.env, ...options.env } : process.env,
12972
12997
  stdio: [options.stdin === undefined ? "ignore" : "pipe", "pipe", "pipe"]
@@ -13223,7 +13248,7 @@ async function connectSandbox(options) {
13223
13248
  const runtime = await options.provider.reconnect({ id: options.id, cwd });
13224
13249
  return new SandblocksSandbox(runtime, { provider: options.provider, cwd, retention: options.retention ?? "always" }, { hostCwd: cwd, runtimeCwd: cwd });
13225
13250
  }
13226
- async function run(options) {
13251
+ async function run2(options) {
13227
13252
  const sandbox = await createSandbox(options);
13228
13253
  try {
13229
13254
  return await sandbox.run(options);
@@ -13406,7 +13431,7 @@ SANDBLOCKS_API_KEY=
13406
13431
  for (const [relative, content] of Object.entries(files)) {
13407
13432
  const path6 = resolve2(root, relative);
13408
13433
  await mkdir22(resolve2(path6, ".."), { recursive: true });
13409
- if (!options.force && await access(path6).then(() => true).catch(() => false))
13434
+ if (!options.force && await access2(path6).then(() => true).catch(() => false))
13410
13435
  continue;
13411
13436
  await writeFile2(path6, content, { mode: relative.includes(".env") ? 384 : 420 });
13412
13437
  written.push(path6);
@@ -13417,7 +13442,7 @@ SANDBLOCKS_API_KEY=
13417
13442
  // ../sdk/dist/providers/docker.js
13418
13443
  import { realpath as realpath3 } from "fs/promises";
13419
13444
  import { resolve as resolve3 } from "path";
13420
- import { spawn as spawn2 } from "child_process";
13445
+ import { spawn as spawn3 } from "child_process";
13421
13446
  async function executeProcess2(command, options = {}) {
13422
13447
  if (!command.length || command.some((part) => !part || part.includes("\x00"))) {
13423
13448
  throw new Error("command must contain safe non-empty arguments");
@@ -13426,7 +13451,7 @@ async function executeProcess2(command, options = {}) {
13426
13451
  const [executable, ...args] = command;
13427
13452
  if (!executable)
13428
13453
  throw new Error("command executable is required");
13429
- const child = spawn2(executable, args, {
13454
+ const child = spawn3(executable, args, {
13430
13455
  cwd: options.cwd ?? options.hostCwd,
13431
13456
  env: options.env ? { ...process.env, ...options.env } : process.env,
13432
13457
  stdio: [options.stdin === undefined ? "ignore" : "pipe", "pipe", "pipe"]
@@ -13663,7 +13688,7 @@ class DockerProvider extends OciProvider {
13663
13688
  // ../sdk/dist/providers/podman.js
13664
13689
  import { realpath as realpath4 } from "fs/promises";
13665
13690
  import { resolve as resolve5 } from "path";
13666
- import { spawn as spawn3 } from "child_process";
13691
+ import { spawn as spawn4 } from "child_process";
13667
13692
  async function executeProcess3(command, options = {}) {
13668
13693
  if (!command.length || command.some((part) => !part || part.includes("\x00"))) {
13669
13694
  throw new Error("command must contain safe non-empty arguments");
@@ -13672,7 +13697,7 @@ async function executeProcess3(command, options = {}) {
13672
13697
  const [executable, ...args] = command;
13673
13698
  if (!executable)
13674
13699
  throw new Error("command executable is required");
13675
- const child = spawn3(executable, args, {
13700
+ const child = spawn4(executable, args, {
13676
13701
  cwd: options.cwd ?? options.hostCwd,
13677
13702
  env: options.env ? { ...process.env, ...options.env } : process.env,
13678
13703
  stdio: [options.stdin === undefined ? "ignore" : "pipe", "pipe", "pipe"]
@@ -13911,7 +13936,7 @@ import { randomUUID as randomUUID3 } from "crypto";
13911
13936
  import { mkdtemp, readFile as readFile6, rm as rm5, stat as stat2, writeFile as writeFile3 } from "fs/promises";
13912
13937
  import { tmpdir } from "os";
13913
13938
  import { join } from "path";
13914
- import { spawn as spawn4 } from "child_process";
13939
+ import { spawn as spawn5 } from "child_process";
13915
13940
  async function executeProcess4(command, options = {}) {
13916
13941
  if (!command.length || command.some((part) => !part || part.includes("\x00"))) {
13917
13942
  throw new Error("command must contain safe non-empty arguments");
@@ -13920,7 +13945,7 @@ async function executeProcess4(command, options = {}) {
13920
13945
  const [executable, ...args] = command;
13921
13946
  if (!executable)
13922
13947
  throw new Error("command executable is required");
13923
- const child = spawn4(executable, args, {
13948
+ const child = spawn5(executable, args, {
13924
13949
  cwd: options.cwd ?? options.hostCwd,
13925
13950
  env: options.env ? { ...process.env, ...options.env } : process.env,
13926
13951
  stdio: [options.stdin === undefined ? "ignore" : "pipe", "pipe", "pipe"]
@@ -14233,7 +14258,7 @@ async function sourceBundle(cwd) {
14233
14258
  // ../sdk/dist/providers/unsafe-host.js
14234
14259
  import { cp as cp2, realpath as realpath5 } from "fs/promises";
14235
14260
  import { resolve as resolve6 } from "path";
14236
- import { spawn as spawn5 } from "child_process";
14261
+ import { spawn as spawn6 } from "child_process";
14237
14262
  async function executeProcess5(command, options = {}) {
14238
14263
  if (!command.length || command.some((part) => !part || part.includes("\x00"))) {
14239
14264
  throw new Error("command must contain safe non-empty arguments");
@@ -14242,7 +14267,7 @@ async function executeProcess5(command, options = {}) {
14242
14267
  const [executable, ...args] = command;
14243
14268
  if (!executable)
14244
14269
  throw new Error("command executable is required");
14245
- const child = spawn5(executable, args, {
14270
+ const child = spawn6(executable, args, {
14246
14271
  cwd: options.cwd ?? options.hostCwd,
14247
14272
  env: options.env ? { ...process.env, ...options.env } : process.env,
14248
14273
  stdio: [options.stdin === undefined ? "ignore" : "pipe", "pipe", "pipe"]
@@ -14355,7 +14380,7 @@ async function runSdkCommand(args, helpers) {
14355
14380
  const provider = providerFrom(options, helpers, cwd);
14356
14381
  const agent = agentFrom(options, helpers);
14357
14382
  const outputTag = helpers.option(options, "output-tag");
14358
- const result = await run({
14383
+ const result = await run2({
14359
14384
  provider,
14360
14385
  cwd,
14361
14386
  image: helpers.option(options, "image"),
@@ -14708,7 +14733,7 @@ Low-level deploy remains available with --workspace, --sandbox, --host,
14708
14733
  Authentication: --api-key or SANDBLOCKS_API_KEY
14709
14734
  API endpoint: --api-url or SANDBLOCKS_API_URL
14710
14735
  `;
14711
- async function run2(argv = process.argv.slice(2)) {
14736
+ async function run3(argv = process.argv.slice(2)) {
14712
14737
  await loadCliEnvironment(process.cwd());
14713
14738
  const [command = "help", ...args] = argv;
14714
14739
  if (command === "configure" || command === "init")
@@ -15423,15 +15448,15 @@ async function loadCliEnvironment(root) {
15423
15448
  }
15424
15449
  if (import.meta.main) {
15425
15450
  try {
15426
- await run2();
15451
+ await run3();
15427
15452
  } catch (error) {
15428
15453
  console.error(`sandblocks: ${error instanceof Error ? error.message : String(error)}`);
15429
15454
  process.exitCode = 1;
15430
15455
  }
15431
15456
  }
15432
15457
  export {
15433
- run2 as run,
15458
+ run3 as run,
15434
15459
  parse2 as parse
15435
15460
  };
15436
15461
 
15437
- //# debugId=EB337A76C8A48F0564756E2164756E21
15462
+ //# debugId=96A687238FDBFB8A64756E2164756E21