deepspace 0.2.7 → 0.2.8

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
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/cli/cli.ts
4
- import { defineCommand as defineCommand13, runMain } from "citty";
4
+ import { defineCommand as defineCommand14, runMain } from "citty";
5
5
  import { execSync as execSync5 } from "child_process";
6
6
  import { readFileSync as readFileSync9, existsSync as existsSync11 } from "fs";
7
7
  import { dirname as dirname2, join as join12 } from "path";
@@ -392,13 +392,174 @@ function resolvePort(arg) {
392
392
  return n;
393
393
  }
394
394
 
395
- // src/cli/commands/test.ts
395
+ // src/cli/commands/kill.ts
396
396
  import { defineCommand as defineCommand4 } from "citty";
397
+ import { spawnSync } from "child_process";
398
+ import { setTimeout as wait } from "timers/promises";
399
+ var DEFAULT_PORT2 = 5173;
400
+ var SIGTERM_GRACE_MS = 1500;
401
+ var IS_WIN = process.platform === "win32";
402
+ var kill_default = defineCommand4({
403
+ meta: {
404
+ name: "kill",
405
+ description: "Kill the local dev server and any orphaned workerd processes"
406
+ },
407
+ args: {
408
+ port: {
409
+ type: "string",
410
+ description: `Port the dev server is bound to (default ${DEFAULT_PORT2}, or $DEEPSPACE_PORT)`,
411
+ required: false
412
+ },
413
+ all: {
414
+ type: "boolean",
415
+ description: "Also kill stray workerd/wrangler processes across all ports",
416
+ default: false
417
+ }
418
+ },
419
+ async run({ args }) {
420
+ const port = resolvePort2(args.port);
421
+ const targets = /* @__PURE__ */ new Set();
422
+ for (const pid of listenerPids(port)) targets.add(pid);
423
+ for (const pid of [...targets]) {
424
+ for (const child of childPids(pid)) targets.add(child);
425
+ }
426
+ if (args.all) {
427
+ for (const pid of processPidsByName(["workerd", "wrangler", "vite"])) {
428
+ targets.add(pid);
429
+ }
430
+ }
431
+ if (targets.size === 0) {
432
+ console.log(
433
+ args.all ? `Nothing listening on :${port} and no stray workerd/wrangler/vite processes found.` : `Nothing listening on :${port}. (Pass --all to sweep stray workerd/wrangler.)`
434
+ );
435
+ return;
436
+ }
437
+ for (const pid of targets) {
438
+ if (sendSignal(pid, "SIGTERM")) {
439
+ console.log(`SIGTERM \u2192 pid ${pid}`);
440
+ }
441
+ }
442
+ await wait(SIGTERM_GRACE_MS);
443
+ const stillAlive = [];
444
+ for (const pid of targets) {
445
+ if (isAlive(pid)) stillAlive.push(pid);
446
+ }
447
+ for (const pid of stillAlive) {
448
+ if (sendSignal(pid, "SIGKILL")) {
449
+ console.log(`SIGKILL \u2192 pid ${pid} (did not exit on SIGTERM)`);
450
+ }
451
+ }
452
+ await wait(200);
453
+ const remaining = listenerPids(port);
454
+ if (remaining.length > 0) {
455
+ console.error(
456
+ `Port ${port} is still held by pid(s) ${remaining.join(", ")} \u2014 try \`deepspace kill --port ${port}\` again, or kill manually.`
457
+ );
458
+ process.exit(1);
459
+ }
460
+ console.log(`Port ${port} is free.`);
461
+ }
462
+ });
463
+ function resolvePort2(arg) {
464
+ const raw = arg ?? process.env.DEEPSPACE_PORT;
465
+ if (!raw) return DEFAULT_PORT2;
466
+ const n = Number(raw);
467
+ if (!Number.isInteger(n) || n < 1 || n > 65535) {
468
+ console.error(`Invalid port: ${raw}. Must be an integer between 1 and 65535.`);
469
+ process.exit(1);
470
+ }
471
+ return n;
472
+ }
473
+ function listenerPids(port) {
474
+ if (IS_WIN) {
475
+ return runPowershell(
476
+ `Get-NetTCPConnection -LocalPort ${port} -State Listen -ErrorAction SilentlyContinue | Select-Object -ExpandProperty OwningProcess`
477
+ );
478
+ }
479
+ return run(["lsof", "-nP", `-iTCP:${port}`, "-sTCP:LISTEN", "-t"]);
480
+ }
481
+ function childPids(parentPid) {
482
+ if (IS_WIN) {
483
+ return runPowershell(
484
+ `Get-CimInstance Win32_Process -Filter "ParentProcessId=${parentPid}" | Select-Object -ExpandProperty ProcessId`
485
+ );
486
+ }
487
+ return run(["pgrep", "-P", String(parentPid)]);
488
+ }
489
+ function processPidsByName(names) {
490
+ const all = /* @__PURE__ */ new Set();
491
+ if (IS_WIN) {
492
+ const orClauses = names.map((n) => `($_.Name -like '*${n}*') -or ($_.CommandLine -like '*${n}*')`).join(" -or ");
493
+ const script = `Get-CimInstance Win32_Process | Where-Object { ${orClauses} } | Select-Object -ExpandProperty ProcessId`;
494
+ for (const pid of runPowershell(script)) {
495
+ if (pid !== process.pid) all.add(pid);
496
+ }
497
+ return [...all];
498
+ }
499
+ for (const name of names) {
500
+ for (const pid of run(["pgrep", "-f", name])) {
501
+ if (pid !== process.pid) all.add(pid);
502
+ }
503
+ }
504
+ return [...all];
505
+ }
506
+ function run(cmd) {
507
+ try {
508
+ const r = spawnSync(cmd[0], cmd.slice(1), { encoding: "utf-8" });
509
+ if (r.status !== 0) return [];
510
+ return parsePidLines(r.stdout);
511
+ } catch {
512
+ return [];
513
+ }
514
+ }
515
+ function runPowershell(script) {
516
+ const exe = pwshOrPowershell();
517
+ try {
518
+ const r = spawnSync(
519
+ exe,
520
+ ["-NoProfile", "-NonInteractive", "-Command", script],
521
+ { encoding: "utf-8" }
522
+ );
523
+ if (r.status !== 0) return [];
524
+ return parsePidLines(r.stdout);
525
+ } catch {
526
+ return [];
527
+ }
528
+ }
529
+ function pwshOrPowershell() {
530
+ const probe = spawnSync("pwsh", ["-NoProfile", "-Command", "$PSVersionTable.PSVersion.Major"], {
531
+ encoding: "utf-8"
532
+ });
533
+ if (probe.status === 0) return "pwsh";
534
+ return "powershell.exe";
535
+ }
536
+ function parsePidLines(stdout) {
537
+ return stdout.split(/\s+/).map((s) => Number.parseInt(s, 10)).filter((n) => Number.isFinite(n) && n > 0);
538
+ }
539
+ function sendSignal(pid, signal) {
540
+ try {
541
+ process.kill(pid, signal);
542
+ return true;
543
+ } catch {
544
+ return false;
545
+ }
546
+ }
547
+ function isAlive(pid) {
548
+ try {
549
+ process.kill(pid, 0);
550
+ return true;
551
+ } catch {
552
+ return false;
553
+ }
554
+ }
555
+
556
+ // src/cli/commands/test.ts
557
+ import { defineCommand as defineCommand5 } from "citty";
397
558
  import { existsSync as existsSync5 } from "fs";
398
559
  import { join as join6, resolve as resolve2 } from "path";
399
- import { execSync, spawnSync } from "child_process";
400
- var DEFAULT_PORT2 = 5173;
401
- var test_default = defineCommand4({
560
+ import { execSync, spawnSync as spawnSync2 } from "child_process";
561
+ var DEFAULT_PORT3 = 5173;
562
+ var test_default = defineCommand5({
402
563
  meta: {
403
564
  name: "test",
404
565
  description: "Run tests for your DeepSpace app"
@@ -411,14 +572,14 @@ var test_default = defineCommand4({
411
572
  },
412
573
  port: {
413
574
  type: "string",
414
- description: `Port for vite/webServer (default ${DEFAULT_PORT2}, or $DEEPSPACE_PORT)`,
575
+ description: `Port for vite/webServer (default ${DEFAULT_PORT3}, or $DEEPSPACE_PORT)`,
415
576
  required: false
416
577
  }
417
578
  },
418
579
  async run({ args }) {
419
580
  const appDir = resolve2(".");
420
581
  const suite = args.suite ?? "default";
421
- const port = resolvePort2(args.port);
582
+ const port = resolvePort3(args.port);
422
583
  if (!existsSync5(join6(appDir, "wrangler.toml"))) {
423
584
  console.error("No wrangler.toml found. Are you in a DeepSpace app directory?");
424
585
  process.exit(1);
@@ -471,7 +632,7 @@ var test_default = defineCommand4({
471
632
  }
472
633
  });
473
634
  function runPlaywright(appDir, testFiles, port) {
474
- const result = spawnSync("npx", [
635
+ const result = spawnSync2("npx", [
475
636
  "playwright",
476
637
  "test",
477
638
  "--config",
@@ -486,7 +647,7 @@ function runPlaywright(appDir, testFiles, port) {
486
647
  return result.status ?? 1;
487
648
  }
488
649
  function runVitest(appDir) {
489
- const result = spawnSync("npx", ["vitest", "run", "--passWithNoTests"], {
650
+ const result = spawnSync2("npx", ["vitest", "run", "--passWithNoTests"], {
490
651
  cwd: appDir,
491
652
  stdio: "inherit",
492
653
  shell: process.platform === "win32"
@@ -503,16 +664,16 @@ function ensurePlaywright(appDir) {
503
664
  const isLinux = process.platform === "linux";
504
665
  const isRoot = isLinux && typeof process.getuid === "function" && process.getuid() === 0;
505
666
  const args = isRoot ? ["install", "--with-deps", "chromium"] : ["install", "chromium"];
506
- const result = spawnSync("npx", ["playwright", ...args], { cwd: appDir, stdio: "inherit" });
667
+ const result = spawnSync2("npx", ["playwright", ...args], { cwd: appDir, stdio: "inherit" });
507
668
  if (result.status !== 0) {
508
669
  console.error("\nPlaywright install failed. On Linux, system libs may be missing \u2014 try:");
509
670
  console.error(" sudo npx playwright install --with-deps chromium");
510
671
  process.exit(1);
511
672
  }
512
673
  }
513
- function resolvePort2(arg) {
674
+ function resolvePort3(arg) {
514
675
  const raw = arg ?? process.env.DEEPSPACE_PORT;
515
- if (!raw) return DEFAULT_PORT2;
676
+ if (!raw) return DEFAULT_PORT3;
516
677
  const n = Number(raw);
517
678
  if (!Number.isInteger(n) || n < 1 || n > 65535) {
518
679
  console.error(`Invalid port: ${raw}. Must be an integer between 1 and 65535.`);
@@ -522,7 +683,7 @@ function resolvePort2(arg) {
522
683
  }
523
684
 
524
685
  // src/cli/commands/test-accounts.ts
525
- import { defineCommand as defineCommand5 } from "citty";
686
+ import { defineCommand as defineCommand6 } from "citty";
526
687
  import * as p2 from "@clack/prompts";
527
688
  import { readFileSync as readFileSync4, writeFileSync as writeFileSync4, existsSync as existsSync6, mkdirSync as mkdirSync3 } from "fs";
528
689
  import { join as join7 } from "path";
@@ -567,7 +728,7 @@ async function deleteRemote(id) {
567
728
  throw new Error(data.error ?? `DELETE returned ${res.status}`);
568
729
  }
569
730
  }
570
- var create = defineCommand5({
731
+ var create = defineCommand6({
571
732
  meta: {
572
733
  name: "create",
573
734
  description: "Create a test account"
@@ -637,7 +798,7 @@ var create = defineCommand5({
637
798
  Saved to ${ACCOUNTS_PATH}`);
638
799
  }
639
800
  });
640
- var list = defineCommand5({
801
+ var list = defineCommand6({
641
802
  meta: {
642
803
  name: "list",
643
804
  description: "List your test accounts"
@@ -672,7 +833,7 @@ var list = defineCommand5({
672
833
  }
673
834
  }
674
835
  });
675
- var del = defineCommand5({
836
+ var del = defineCommand6({
676
837
  meta: {
677
838
  name: "delete",
678
839
  description: "Delete a test account by --email or --id"
@@ -729,7 +890,7 @@ var del = defineCommand5({
729
890
  console.log(`Test account deleted${targetEmail ? `: ${targetEmail}` : `: ${targetId}`}`);
730
891
  }
731
892
  });
732
- var clear = defineCommand5({
893
+ var clear = defineCommand6({
733
894
  meta: {
734
895
  name: "clear",
735
896
  description: "Delete all your test accounts (or those matching --label)"
@@ -795,7 +956,7 @@ Failed:`);
795
956
  }
796
957
  }
797
958
  });
798
- var test_accounts_default = defineCommand5({
959
+ var test_accounts_default = defineCommand6({
799
960
  meta: {
800
961
  name: "test-accounts",
801
962
  description: "Manage test accounts for development"
@@ -809,14 +970,14 @@ var test_accounts_default = defineCommand5({
809
970
  });
810
971
 
811
972
  // src/cli/commands/deploy.ts
812
- import { defineCommand as defineCommand6 } from "citty";
973
+ import { defineCommand as defineCommand7 } from "citty";
813
974
  import { execSync as execSync2 } from "child_process";
814
975
  import { readFileSync as readFileSync5, readdirSync, existsSync as existsSync7 } from "fs";
815
976
  import { parse as parseToml2 } from "smol-toml";
816
977
  import { join as join8, resolve as resolve3, dirname } from "path";
817
978
  import * as p3 from "@clack/prompts";
818
979
  var DEPLOY_URL = process.env.DEEPSPACE_DEPLOY_URL ?? ENVS.prod.deploy;
819
- var deploy_default = defineCommand6({
980
+ var deploy_default = defineCommand7({
820
981
  meta: {
821
982
  name: "deploy",
822
983
  description: "Build and deploy your DeepSpace app"
@@ -944,13 +1105,13 @@ function collectAssets(dir) {
944
1105
  }
945
1106
 
946
1107
  // src/cli/commands/undeploy.ts
947
- import { defineCommand as defineCommand7 } from "citty";
1108
+ import { defineCommand as defineCommand8 } from "citty";
948
1109
  import { readFileSync as readFileSync6, existsSync as existsSync8 } from "fs";
949
1110
  import { join as join9 } from "path";
950
1111
  import { parse as parseToml3 } from "smol-toml";
951
1112
  import * as p4 from "@clack/prompts";
952
1113
  var DEPLOY_URL2 = process.env.DEEPSPACE_DEPLOY_URL ?? ENVS.prod.deploy;
953
- var undeploy_default = defineCommand7({
1114
+ var undeploy_default = defineCommand8({
954
1115
  meta: {
955
1116
  name: "undeploy",
956
1117
  description: "Remove a deployed DeepSpace app"
@@ -1001,8 +1162,8 @@ var undeploy_default = defineCommand7({
1001
1162
  });
1002
1163
 
1003
1164
  // src/cli/commands/whoami.ts
1004
- import { defineCommand as defineCommand8 } from "citty";
1005
- var whoami_default = defineCommand8({
1165
+ import { defineCommand as defineCommand9 } from "citty";
1166
+ var whoami_default = defineCommand9({
1006
1167
  meta: {
1007
1168
  name: "whoami",
1008
1169
  description: "Show the currently logged-in user"
@@ -1056,7 +1217,7 @@ var whoami_default = defineCommand8({
1056
1217
  });
1057
1218
 
1058
1219
  // src/cli/commands/add.ts
1059
- import { defineCommand as defineCommand9 } from "citty";
1220
+ import { defineCommand as defineCommand10 } from "citty";
1060
1221
  import { existsSync as existsSync9 } from "fs";
1061
1222
  import { resolve as resolve4, join as join10 } from "path";
1062
1223
  import { execSync as execSync3 } from "child_process";
@@ -1065,7 +1226,7 @@ function findScript(from) {
1065
1226
  if (existsSync9(candidate)) return candidate;
1066
1227
  return null;
1067
1228
  }
1068
- var add_default = defineCommand9({
1229
+ var add_default = defineCommand10({
1069
1230
  meta: {
1070
1231
  name: "add",
1071
1232
  description: "Add a feature to your DeepSpace app"
@@ -1119,7 +1280,7 @@ var add_default = defineCommand9({
1119
1280
  });
1120
1281
 
1121
1282
  // src/cli/commands/domain.ts
1122
- import { defineCommand as defineCommand10 } from "citty";
1283
+ import { defineCommand as defineCommand11 } from "citty";
1123
1284
  import { execSync as execSync4 } from "child_process";
1124
1285
 
1125
1286
  // src/cli/lib/app-context.ts
@@ -1188,7 +1349,7 @@ async function confirm2(message) {
1188
1349
  });
1189
1350
  });
1190
1351
  }
1191
- var search = defineCommand10({
1352
+ var search = defineCommand11({
1192
1353
  meta: { name: "search", description: "Search for available domains" },
1193
1354
  args: {
1194
1355
  query: { type: "positional", description: "Domain or keyword", required: true },
@@ -1218,7 +1379,7 @@ var search = defineCommand10({
1218
1379
  }
1219
1380
  }
1220
1381
  });
1221
- var buy = defineCommand10({
1382
+ var buy = defineCommand11({
1222
1383
  meta: { name: "buy", description: "Buy a domain and attach it to an app" },
1223
1384
  args: {
1224
1385
  domain: { type: "positional", description: "Domain to buy", required: true },
@@ -1307,7 +1468,7 @@ var buy = defineCommand10({
1307
1468
  process.exit(1);
1308
1469
  }
1309
1470
  });
1310
- var list2 = defineCommand10({
1471
+ var list2 = defineCommand11({
1311
1472
  meta: { name: "list", description: "List your domains" },
1312
1473
  args: {
1313
1474
  json: { type: "boolean", description: "Emit JSON" }
@@ -1331,7 +1492,7 @@ var list2 = defineCommand10({
1331
1492
  }
1332
1493
  }
1333
1494
  });
1334
- var status = defineCommand10({
1495
+ var status = defineCommand11({
1335
1496
  meta: { name: "status", description: "Show details for one domain" },
1336
1497
  args: {
1337
1498
  domain: { type: "positional", description: "Domain", required: true },
@@ -1359,7 +1520,7 @@ var status = defineCommand10({
1359
1520
  console.log(`Charged: ${fmtCents(found.chargedCents)}/yr`);
1360
1521
  }
1361
1522
  });
1362
- var attach = defineCommand10({
1523
+ var attach = defineCommand11({
1363
1524
  meta: { name: "attach", description: "Re-point a domain at a different app" },
1364
1525
  args: {
1365
1526
  domain: { type: "positional", description: "Domain to re-point", required: true },
@@ -1390,7 +1551,7 @@ var attach = defineCommand10({
1390
1551
  console.log(`\u2713 ${args.domain} now points at ${targetApp}`);
1391
1552
  }
1392
1553
  });
1393
- var detach = defineCommand10({
1554
+ var detach = defineCommand11({
1394
1555
  meta: {
1395
1556
  name: "detach",
1396
1557
  description: "Stop routing the domain (keeps the registration; auto-renew unchanged)"
@@ -1420,7 +1581,7 @@ var detach = defineCommand10({
1420
1581
  console.log(`\u2713 ${args.domain} detached. Use \`deepspace domain attach\` to re-route, or \`renew --auto off\` to stop auto-renewal.`);
1421
1582
  }
1422
1583
  });
1423
- var renew = defineCommand10({
1584
+ var renew = defineCommand11({
1424
1585
  meta: { name: "renew", description: "Toggle auto-renewal at the registrar" },
1425
1586
  args: {
1426
1587
  domain: { type: "positional", description: "Domain", required: true },
@@ -1454,13 +1615,13 @@ function openBrowser2(url) {
1454
1615
  } catch {
1455
1616
  }
1456
1617
  }
1457
- var domain_default = defineCommand10({
1618
+ var domain_default = defineCommand11({
1458
1619
  meta: { name: "domain", description: "Buy and manage custom domains" },
1459
1620
  subCommands: { search, buy, list: list2, status, attach, detach, renew }
1460
1621
  });
1461
1622
 
1462
1623
  // src/cli/commands/integrations.ts
1463
- import { defineCommand as defineCommand11 } from "citty";
1624
+ import { defineCommand as defineCommand12 } from "citty";
1464
1625
 
1465
1626
  // src/cli/commands/_invoke-impl.ts
1466
1627
  import { readFileSync as readFileSync8 } from "fs";
@@ -1634,7 +1795,7 @@ async function runInvoke(args) {
1634
1795
  }
1635
1796
 
1636
1797
  // src/cli/commands/integrations.ts
1637
- var list3 = defineCommand11({
1798
+ var list3 = defineCommand12({
1638
1799
  meta: {
1639
1800
  name: "list",
1640
1801
  description: "List all available integrations"
@@ -1655,7 +1816,7 @@ var list3 = defineCommand11({
1655
1816
  }
1656
1817
  }
1657
1818
  });
1658
- var info = defineCommand11({
1819
+ var info = defineCommand12({
1659
1820
  meta: {
1660
1821
  name: "info",
1661
1822
  description: "Print schema + example body for an integration endpoint"
@@ -1681,7 +1842,7 @@ var info = defineCommand11({
1681
1842
  }
1682
1843
  }
1683
1844
  });
1684
- var invoke = defineCommand11({
1845
+ var invoke = defineCommand12({
1685
1846
  meta: {
1686
1847
  name: "invoke",
1687
1848
  description: "Invoke a platform integration as the logged-in user"
@@ -1734,7 +1895,7 @@ var invoke = defineCommand11({
1734
1895
  }
1735
1896
  }
1736
1897
  });
1737
- var integrations_default = defineCommand11({
1898
+ var integrations_default = defineCommand12({
1738
1899
  meta: {
1739
1900
  name: "integrations",
1740
1901
  description: "List, inspect, and invoke platform integrations"
@@ -1747,8 +1908,8 @@ var integrations_default = defineCommand11({
1747
1908
  });
1748
1909
 
1749
1910
  // src/cli/commands/invoke.ts
1750
- import { defineCommand as defineCommand12 } from "citty";
1751
- var invoke_default = defineCommand12({
1911
+ import { defineCommand as defineCommand13 } from "citty";
1912
+ var invoke_default = defineCommand13({
1752
1913
  meta: {
1753
1914
  name: "invoke",
1754
1915
  description: "Invoke a platform integration as the logged-in user"
@@ -1826,7 +1987,7 @@ var pkg = JSON.parse(readFileSync9(join12(__dirname, "..", "package.json"), "utf
1826
1987
  if (process.platform === "linux" && !process.env.SSL_CERT_FILE && existsSync11("/etc/ssl/certs/ca-certificates.crt")) {
1827
1988
  process.env.SSL_CERT_FILE = "/etc/ssl/certs/ca-certificates.crt";
1828
1989
  }
1829
- var create2 = defineCommand13({
1990
+ var create2 = defineCommand14({
1830
1991
  meta: {
1831
1992
  name: "create",
1832
1993
  description: "Create a new DeepSpace app"
@@ -1845,7 +2006,7 @@ var create2 = defineCommand13({
1845
2006
  execSync5(`npm create deepspace@latest${name}`, { stdio: "inherit" });
1846
2007
  }
1847
2008
  });
1848
- var main = defineCommand13({
2009
+ var main = defineCommand14({
1849
2010
  meta: {
1850
2011
  name: "deepspace",
1851
2012
  version: pkg.version,
@@ -1857,6 +2018,7 @@ var main = defineCommand13({
1857
2018
  logout: logout_default,
1858
2019
  whoami: whoami_default,
1859
2020
  dev: dev_default,
2021
+ kill: kill_default,
1860
2022
  test: test_default,
1861
2023
  "test-accounts": test_accounts_default,
1862
2024
  add: add_default,