@chandresh726/switchy 1.3.9 → 1.3.12

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
@@ -20,7 +20,7 @@ var init_package = __esm({
20
20
  "package.json"() {
21
21
  package_default = {
22
22
  name: "@chandresh726/switchy",
23
- version: "1.3.9",
23
+ version: "1.3.12",
24
24
  description: "Install, run, update, and stop the local-first Switchy application.",
25
25
  license: "MIT",
26
26
  type: "module",
@@ -52,12 +52,13 @@ var init_package = __esm({
52
52
  prepack: "pnpm build"
53
53
  },
54
54
  dependencies: {
55
- tar: "^7.5.22"
55
+ tar: "^7.5.23"
56
56
  },
57
57
  devDependencies: {
58
- "@types/node": "^24.13.3",
59
- esbuild: "^0.28.1",
60
- typescript: "^5.9.3"
58
+ "@types/node": "^24.19.2",
59
+ "@typescript/native": "npm:typescript@^7.0.2",
60
+ esbuild: "^0.28.2",
61
+ typescript: "npm:@typescript/typescript6@^6.0.2"
61
62
  }
62
63
  };
63
64
  }
@@ -687,7 +688,148 @@ var init_process_manager = __esm({
687
688
  }
688
689
  });
689
690
 
691
+ // src/paths.ts
692
+ import { mkdir as mkdir5 } from "node:fs/promises";
693
+ import os3 from "node:os";
694
+ import path13 from "node:path";
695
+ function getSwitchyPaths(configuredRoot = process.env.SWITCHY_HOME) {
696
+ const override = configuredRoot?.trim();
697
+ if (override && !path13.isAbsolute(override)) {
698
+ throw new Error("SWITCHY_HOME must be an absolute path");
699
+ }
700
+ const root = override ? path13.normalize(override) : path13.join(os3.homedir(), ".switchy");
701
+ const data = path13.join(root, "data");
702
+ const app = path13.join(root, "app");
703
+ const runtime = path13.join(root, "runtime");
704
+ const logs = path13.join(root, "logs");
705
+ const cache = path13.join(root, "cache");
706
+ return {
707
+ root,
708
+ data,
709
+ productionData: path13.join(data, "production"),
710
+ app,
711
+ versions: path13.join(app, "versions"),
712
+ currentVersion: path13.join(app, "current.json"),
713
+ runtime,
714
+ processRecord: path13.join(runtime, "process.json"),
715
+ installLock: path13.join(runtime, "install.lock"),
716
+ startLock: path13.join(runtime, "start.lock"),
717
+ logs,
718
+ logFile: path13.join(logs, "switchy.log"),
719
+ cache,
720
+ downloads: path13.join(cache, "downloads"),
721
+ playwright: path13.join(cache, "playwright"),
722
+ updateSnapshots: path13.join(root, "update-snapshots")
723
+ };
724
+ }
725
+ async function ensureSwitchyDirectories(paths) {
726
+ for (const directory of [
727
+ paths.root,
728
+ paths.data,
729
+ paths.app,
730
+ paths.versions,
731
+ paths.runtime,
732
+ paths.logs,
733
+ paths.cache,
734
+ paths.downloads,
735
+ paths.playwright,
736
+ paths.updateSnapshots
737
+ ]) {
738
+ await mkdir5(directory, { recursive: true, mode: 448 });
739
+ }
740
+ }
741
+ var init_paths = __esm({
742
+ "src/paths.ts"() {
743
+ "use strict";
744
+ }
745
+ });
746
+
747
+ // src/open.ts
748
+ var open_exports = {};
749
+ __export(open_exports, {
750
+ openCommand: () => openCommand
751
+ });
752
+ import { spawn as spawn4 } from "node:child_process";
753
+ async function openCommand() {
754
+ const running = await getRunningProcess(getSwitchyPaths());
755
+ if (!running?.live) throw new Error("Switchy is not running or is unresponsive");
756
+ const url = `http://${running.record.hostname}:${running.record.port}`;
757
+ const [executable, args] = process.platform === "darwin" ? ["open", [url]] : process.platform === "win32" ? ["cmd", ["/c", "start", "", url]] : ["xdg-open", [url]];
758
+ const child = spawn4(executable, args, { detached: true, stdio: "ignore" });
759
+ await new Promise((resolve, reject) => {
760
+ child.once("spawn", resolve);
761
+ child.once("error", reject);
762
+ });
763
+ child.unref();
764
+ console.log(url);
765
+ }
766
+ var init_open = __esm({
767
+ "src/open.ts"() {
768
+ "use strict";
769
+ init_paths();
770
+ init_process_manager();
771
+ }
772
+ });
773
+
774
+ // src/arguments.ts
775
+ var OPTIONS = {
776
+ start: { "--port": "value", "--app-version": "value", "--foreground": "flag" },
777
+ stop: { "--force": "flag" },
778
+ restart: {},
779
+ status: { "--json": "flag" },
780
+ doctor: {},
781
+ update: { "--check": "flag", "--download": "flag", "--apply": "flag" },
782
+ startup: {},
783
+ logs: {},
784
+ open: {},
785
+ version: {},
786
+ help: {}
787
+ };
788
+ function parseArguments(args) {
789
+ const command = args[0] ?? "help";
790
+ if (args.includes("--help") || args.includes("-h")) return { command: "help", values: /* @__PURE__ */ new Map(), startup: "status" };
791
+ const selected = command === "--version" || command === "-v" ? "version" : command;
792
+ const options = Object.hasOwn(OPTIONS, selected) ? OPTIONS[selected] : void 0;
793
+ if (!options) throw new Error(`Unknown command: ${command}`);
794
+ const values = /* @__PURE__ */ new Map();
795
+ let startup = "status";
796
+ for (let index = 1; index < args.length; index++) {
797
+ const name = args[index];
798
+ if (selected === "startup" && index === 1 && ["enable", "disable", "status"].includes(name)) {
799
+ startup = name;
800
+ continue;
801
+ }
802
+ const kind = Object.hasOwn(options, name) ? options[name] : void 0;
803
+ if (!kind) throw new Error(`Unknown option for ${selected}: ${name}`);
804
+ if (values.has(name)) throw new Error(`Duplicate option: ${name}`);
805
+ if (kind === "value") {
806
+ const value = args[++index];
807
+ if (!value || value.startsWith("-")) throw new Error(`${name} requires a value`);
808
+ values.set(name, value);
809
+ } else values.set(name, true);
810
+ }
811
+ if (selected === "update" && values.size > 1) throw new Error("Choose one update action: --check, --download, or --apply");
812
+ const port = values.get("--port");
813
+ if (typeof port === "string" && (!/^\d+$/u.test(port) || Number(port) < 1 || Number(port) > 65535)) {
814
+ throw new Error("--port must be an integer between 1 and 65535");
815
+ }
816
+ return { command: selected, values, startup };
817
+ }
818
+
819
+ // src/commands.ts
820
+ init_config();
821
+ import path16 from "node:path";
822
+
823
+ // src/controller.ts
824
+ init_config();
825
+ init_files();
826
+ init_lifecycle_state2();
827
+ init_process_manager();
828
+ import path12 from "node:path";
829
+
690
830
  // src/preferences.ts
831
+ init_files();
832
+ init_lifecycle_state2();
691
833
  import { randomUUID as randomUUID4 } from "node:crypto";
692
834
  async function saveRuntimePreference(paths, changes) {
693
835
  await withDirectoryLock(lifecycleFiles(paths).preferencesLock, async () => {
@@ -700,40 +842,10 @@ async function setRunningPreference(paths, running, port) {
700
842
  async function requestRuntimeStop(paths) {
701
843
  await saveRuntimePreference(paths, { running: false, stopToken: randomUUID4() });
702
844
  }
703
- var init_preferences = __esm({
704
- "src/preferences.ts"() {
705
- "use strict";
706
- init_files();
707
- init_lifecycle_state2();
708
- }
709
- });
710
-
711
- // src/platform.ts
712
- function isSupportedTarget(target) {
713
- return supportedTargets.has(target);
714
- }
715
- function currentTarget(platform = process.platform, architecture = process.arch) {
716
- const target = `${platform}-${architecture}`;
717
- if (!isSupportedTarget(target)) {
718
- throw new Error(`Switchy does not provide a runtime for ${target}`);
719
- }
720
- return target;
721
- }
722
- var SUPPORTED_TARGETS, supportedTargets;
723
- var init_platform = __esm({
724
- "src/platform.ts"() {
725
- "use strict";
726
- SUPPORTED_TARGETS = [
727
- "darwin-arm64",
728
- "linux-arm64",
729
- "linux-x64",
730
- "win32-x64"
731
- ];
732
- supportedTargets = new Set(SUPPORTED_TARGETS);
733
- }
734
- });
735
845
 
736
846
  // src/release.ts
847
+ init_config();
848
+ init_files();
737
849
  import { createHash, randomUUID as randomUUID5 } from "node:crypto";
738
850
  import { createReadStream, createWriteStream } from "node:fs";
739
851
  import {
@@ -748,6 +860,29 @@ import { Readable, Transform } from "node:stream";
748
860
  import { pipeline } from "node:stream/promises";
749
861
  import path8 from "node:path";
750
862
  import { extract } from "tar";
863
+
864
+ // src/platform.ts
865
+ var SUPPORTED_TARGETS = [
866
+ "darwin-arm64",
867
+ "linux-arm64",
868
+ "linux-x64",
869
+ "win32-x64"
870
+ ];
871
+ var supportedTargets = new Set(SUPPORTED_TARGETS);
872
+ function isSupportedTarget(target) {
873
+ return supportedTargets.has(target);
874
+ }
875
+ function currentTarget(platform = process.platform, architecture = process.arch) {
876
+ const target = `${platform}-${architecture}`;
877
+ if (!isSupportedTarget(target)) {
878
+ throw new Error(`Switchy does not provide a runtime for ${target}`);
879
+ }
880
+ return target;
881
+ }
882
+
883
+ // src/release.ts
884
+ var STABLE_VERSION_PATTERN = /^\d+\.\d+\.\d+$/u;
885
+ var MACOS_NOTIFIER_EXECUTABLE = "bin/Switchy Notifications.app/Contents/MacOS/SwitchyNotifier";
751
886
  function notificationRuntimeFiles(target) {
752
887
  if (!target.startsWith("darwin-")) return [];
753
888
  return [
@@ -979,21 +1114,19 @@ async function setCurrentVersion(paths, version, previousVersion) {
979
1114
  };
980
1115
  await writeJsonFileAtomic(paths.currentVersion, value);
981
1116
  }
982
- var STABLE_VERSION_PATTERN, MACOS_NOTIFIER_EXECUTABLE;
983
- var init_release = __esm({
984
- "src/release.ts"() {
985
- "use strict";
986
- init_config();
987
- init_files();
988
- init_platform();
989
- STABLE_VERSION_PATTERN = /^\d+\.\d+\.\d+$/u;
990
- MACOS_NOTIFIER_EXECUTABLE = "bin/Switchy Notifications.app/Contents/MacOS/SwitchyNotifier";
991
- }
992
- });
1117
+
1118
+ // src/updater.ts
1119
+ import { cp as cp3, readdir as readdir5, rename as rename4, rm as rm5, stat as stat6 } from "node:fs/promises";
1120
+ import path11 from "node:path";
993
1121
 
994
1122
  // src/cleanup.ts
995
1123
  import { readdir as readdir3, rm as rm4, stat as stat4 } from "node:fs/promises";
996
1124
  import path9 from "node:path";
1125
+ var STABLE_VERSION_PATTERN2 = /^\d+\.\d+\.\d+$/u;
1126
+ var DOWNLOAD_ARCHIVE_PATTERN = /^switchy-(\d+\.\d+\.\d+)-(?:darwin|linux|win32)-(?:arm64|x64)\.tar\.gz$/u;
1127
+ var INSTALL_DIRECTORY_PREFIX = ".install-";
1128
+ var UPDATE_SNAPSHOT_PREFIX = "update-";
1129
+ var RETAINED_UPDATE_SNAPSHOTS = 3;
997
1130
  async function listEntries(directory) {
998
1131
  try {
999
1132
  return await readdir3(directory, { withFileTypes: true });
@@ -1046,19 +1179,15 @@ async function pruneInstallArtifacts(paths, retainedVersions) {
1046
1179
  }
1047
1180
  return result;
1048
1181
  }
1049
- var STABLE_VERSION_PATTERN2, DOWNLOAD_ARCHIVE_PATTERN, INSTALL_DIRECTORY_PREFIX, UPDATE_SNAPSHOT_PREFIX, RETAINED_UPDATE_SNAPSHOTS;
1050
- var init_cleanup = __esm({
1051
- "src/cleanup.ts"() {
1052
- "use strict";
1053
- STABLE_VERSION_PATTERN2 = /^\d+\.\d+\.\d+$/u;
1054
- DOWNLOAD_ARCHIVE_PATTERN = /^switchy-(\d+\.\d+\.\d+)-(?:darwin|linux|win32)-(?:arm64|x64)\.tar\.gz$/u;
1055
- INSTALL_DIRECTORY_PREFIX = ".install-";
1056
- UPDATE_SNAPSHOT_PREFIX = "update-";
1057
- RETAINED_UPDATE_SNAPSHOTS = 3;
1058
- }
1059
- });
1182
+
1183
+ // src/updater.ts
1184
+ init_files();
1185
+ init_lifecycle_state2();
1186
+ init_process_manager();
1060
1187
 
1061
1188
  // src/runtime.ts
1189
+ init_lifecycle_state2();
1190
+ init_files();
1062
1191
  import { spawn as spawn2 } from "node:child_process";
1063
1192
  import { cp as cp2, mkdir as mkdir4, open as open4, readdir as readdir4, stat as stat5 } from "node:fs/promises";
1064
1193
  import path10 from "node:path";
@@ -1169,17 +1298,8 @@ async function syncTree(directory) {
1169
1298
  }
1170
1299
  await syncDirectory(directory);
1171
1300
  }
1172
- var init_runtime = __esm({
1173
- "src/runtime.ts"() {
1174
- "use strict";
1175
- init_lifecycle_state2();
1176
- init_files();
1177
- }
1178
- });
1179
1301
 
1180
1302
  // src/updater.ts
1181
- import { cp as cp3, readdir as readdir5, rename as rename4, rm as rm5, stat as stat6 } from "node:fs/promises";
1182
- import path11 from "node:path";
1183
1303
  async function appRequest(paths, route, method = "GET") {
1184
1304
  const running = await getRunningProcess(paths);
1185
1305
  if (!running?.live || running.live.instanceId !== running.record.instanceId) {
@@ -1410,21 +1530,8 @@ async function withUpdateLock(paths, operation) {
1410
1530
  }
1411
1531
  });
1412
1532
  }
1413
- var init_updater = __esm({
1414
- "src/updater.ts"() {
1415
- "use strict";
1416
- init_cleanup();
1417
- init_files();
1418
- init_lifecycle_state2();
1419
- init_process_manager();
1420
- init_preferences();
1421
- init_release();
1422
- init_runtime();
1423
- }
1424
- });
1425
1533
 
1426
1534
  // src/controller.ts
1427
- import path12 from "node:path";
1428
1535
  async function startRuntime(paths, options = {}) {
1429
1536
  const stopToken = (await readPreferences(paths)).stopToken;
1430
1537
  await withDirectoryLock(paths.startLock, () => recoverInterruptedUpdate(paths));
@@ -1497,82 +1604,37 @@ async function restartRuntime(paths) {
1497
1604
  return record;
1498
1605
  });
1499
1606
  }
1500
- var init_controller = __esm({
1501
- "src/controller.ts"() {
1502
- "use strict";
1503
- init_config();
1504
- init_files();
1505
- init_lifecycle_state2();
1506
- init_process_manager();
1507
- init_preferences();
1508
- init_release();
1509
- init_updater();
1510
- }
1511
- });
1512
1607
 
1513
- // src/paths.ts
1514
- import { mkdir as mkdir5 } from "node:fs/promises";
1515
- import os3 from "node:os";
1516
- import path13 from "node:path";
1517
- function getSwitchyPaths(configuredRoot = process.env.SWITCHY_HOME) {
1518
- const override = configuredRoot?.trim();
1519
- if (override && !path13.isAbsolute(override)) {
1520
- throw new Error("SWITCHY_HOME must be an absolute path");
1521
- }
1522
- const root = override ? path13.normalize(override) : path13.join(os3.homedir(), ".switchy");
1523
- const data = path13.join(root, "data");
1524
- const app = path13.join(root, "app");
1525
- const runtime = path13.join(root, "runtime");
1526
- const logs = path13.join(root, "logs");
1527
- const cache = path13.join(root, "cache");
1528
- return {
1529
- root,
1530
- data,
1531
- productionData: path13.join(data, "production"),
1532
- app,
1533
- versions: path13.join(app, "versions"),
1534
- currentVersion: path13.join(app, "current.json"),
1535
- runtime,
1536
- processRecord: path13.join(runtime, "process.json"),
1537
- installLock: path13.join(runtime, "install.lock"),
1538
- startLock: path13.join(runtime, "start.lock"),
1539
- logs,
1540
- logFile: path13.join(logs, "switchy.log"),
1541
- cache,
1542
- downloads: path13.join(cache, "downloads"),
1543
- playwright: path13.join(cache, "playwright"),
1544
- updateSnapshots: path13.join(root, "update-snapshots")
1545
- };
1546
- }
1547
- async function ensureSwitchyDirectories(paths) {
1548
- for (const directory of [
1549
- paths.root,
1550
- paths.data,
1551
- paths.app,
1552
- paths.versions,
1553
- paths.runtime,
1554
- paths.logs,
1555
- paths.cache,
1556
- paths.downloads,
1557
- paths.playwright,
1558
- paths.updateSnapshots
1559
- ]) {
1560
- await mkdir5(directory, { recursive: true, mode: 448 });
1561
- }
1562
- }
1563
- var init_paths = __esm({
1564
- "src/paths.ts"() {
1565
- "use strict";
1566
- }
1567
- });
1608
+ // src/commands.ts
1609
+ init_files();
1610
+ init_lifecycle_state2();
1611
+
1612
+ // src/lifecycle-daemon.ts
1613
+ init_files();
1614
+ import { watch } from "node:fs";
1615
+ import { mkdir as mkdir7 } from "node:fs/promises";
1616
+
1617
+ // src/lifecycle-manager.ts
1618
+ import { randomUUID as randomUUID7 } from "node:crypto";
1619
+ import { readdir as readdir6, rename as rename6 } from "node:fs/promises";
1620
+ import path15 from "node:path";
1621
+ init_files();
1622
+ init_lifecycle_state2();
1623
+ init_paths();
1624
+ init_process_manager();
1568
1625
 
1569
1626
  // src/startup.ts
1627
+ init_files();
1628
+ init_startup_environment();
1629
+ init_lifecycle_state2();
1570
1630
  import { execFile, spawn as spawn3 } from "node:child_process";
1571
1631
  import { randomUUID as randomUUID6 } from "node:crypto";
1572
1632
  import { chmod, copyFile, link, mkdir as mkdir6, open as open5, readFile as readFile4, rename as rename5, rm as rm6, stat as stat7 } from "node:fs/promises";
1573
1633
  import os4 from "node:os";
1574
1634
  import path14 from "node:path";
1575
1635
  import { promisify } from "node:util";
1636
+ var execute = promisify(execFile);
1637
+ var LABEL = "com.switchy.lifecycle";
1576
1638
  function escapeXml(value) {
1577
1639
  return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&apos;");
1578
1640
  }
@@ -1592,6 +1654,39 @@ function startupPlist(paths, executable = path14.join(lifecycleFiles(paths).host
1592
1654
  </dict></plist>
1593
1655
  `;
1594
1656
  }
1657
+ var SUPERVISOR = `const fs = require('node:fs');
1658
+ const path = require('node:path');
1659
+ const { spawn } = require('node:child_process');
1660
+ const root = process.env.SWITCHY_HOME;
1661
+ let login = process.argv.includes('--login');
1662
+ let child;
1663
+ let stopping = false;
1664
+ for (const signal of ['SIGINT', 'SIGTERM']) process.once(signal, () => {
1665
+ stopping = true;
1666
+ if (child) child.kill('SIGTERM'); else process.exit(0);
1667
+ });
1668
+ function start() {
1669
+ let current;
1670
+ try { current = JSON.parse(fs.readFileSync(path.join(root, 'app/current.json'), 'utf8')); }
1671
+ catch (error) { if (error.code === 'ENOENT') return; throw error; }
1672
+ if (!/^\\d+\\.\\d+\\.\\d+$/.test(current.version)) throw Error('Invalid installed version');
1673
+ const worker = path.join(root, 'app/versions', current.version, 'bin/lifecycle.cjs');
1674
+ if (!fs.existsSync(worker)) return;
1675
+ const metadata = JSON.parse(fs.readFileSync(path.join(root, 'app/host/node.json'), 'utf8'));
1676
+ child = spawn(path.join(root, 'app/host', metadata.file), [worker, login ? 'serve-login' : 'serve'], {
1677
+ env: { ...process.env, SWITCHY_HOME: root }, stdio: 'inherit', windowsHide: true
1678
+ });
1679
+ child.once('error', error => { console.error('Switchy lifecycle:', error.message); process.exitCode = 1; });
1680
+ child.once('exit', code => {
1681
+ child = undefined;
1682
+ if (stopping || code === 20) return;
1683
+ login = false;
1684
+ if (code === 21) start();
1685
+ else setTimeout(start, 30000);
1686
+ });
1687
+ }
1688
+ start();
1689
+ `;
1595
1690
  async function hostNode(paths) {
1596
1691
  const metadata = await readJsonFile(path14.join(lifecycleFiles(paths).host, "node.json"));
1597
1692
  if (!metadata || !/^node-24\.\d+\.\d+(?:\.exe)?$/u.test(metadata.file)) throw new Error("Switchy manager Node metadata is invalid");
@@ -1687,55 +1782,8 @@ async function setStartupRegistration(paths, enabled) {
1687
1782
  if (uid !== void 0) await execute("/bin/launchctl", ["enable", `gui/${uid}/${LABEL}`]);
1688
1783
  }
1689
1784
  }
1690
- var execute, LABEL, SUPERVISOR;
1691
- var init_startup = __esm({
1692
- "src/startup.ts"() {
1693
- "use strict";
1694
- init_files();
1695
- init_startup_environment();
1696
- init_lifecycle_state2();
1697
- execute = promisify(execFile);
1698
- LABEL = "com.switchy.lifecycle";
1699
- SUPERVISOR = `const fs = require('node:fs');
1700
- const path = require('node:path');
1701
- const { spawn } = require('node:child_process');
1702
- const root = process.env.SWITCHY_HOME;
1703
- let login = process.argv.includes('--login');
1704
- let child;
1705
- let stopping = false;
1706
- for (const signal of ['SIGINT', 'SIGTERM']) process.once(signal, () => {
1707
- stopping = true;
1708
- if (child) child.kill('SIGTERM'); else process.exit(0);
1709
- });
1710
- function start() {
1711
- let current;
1712
- try { current = JSON.parse(fs.readFileSync(path.join(root, 'app/current.json'), 'utf8')); }
1713
- catch (error) { if (error.code === 'ENOENT') return; throw error; }
1714
- if (!/^\\d+\\.\\d+\\.\\d+$/.test(current.version)) throw Error('Invalid installed version');
1715
- const worker = path.join(root, 'app/versions', current.version, 'bin/lifecycle.cjs');
1716
- if (!fs.existsSync(worker)) return;
1717
- const metadata = JSON.parse(fs.readFileSync(path.join(root, 'app/host/node.json'), 'utf8'));
1718
- child = spawn(path.join(root, 'app/host', metadata.file), [worker, login ? 'serve-login' : 'serve'], {
1719
- env: { ...process.env, SWITCHY_HOME: root }, stdio: 'inherit', windowsHide: true
1720
- });
1721
- child.once('error', error => { console.error('Switchy lifecycle:', error.message); process.exitCode = 1; });
1722
- child.once('exit', code => {
1723
- child = undefined;
1724
- if (stopping || code === 20) return;
1725
- login = false;
1726
- if (code === 21) start();
1727
- else setTimeout(start, 30000);
1728
- });
1729
- }
1730
- start();
1731
- `;
1732
- }
1733
- });
1734
1785
 
1735
1786
  // src/lifecycle-manager.ts
1736
- import { readdir as readdir6, rename as rename6 } from "node:fs/promises";
1737
- import { randomUUID as randomUUID7 } from "node:crypto";
1738
- import path15 from "node:path";
1739
1787
  async function configureLifecycle(paths, changes) {
1740
1788
  await withDirectoryLock(lifecycleFiles(paths).preferencesLock, async () => {
1741
1789
  const running = await getRunningProcess(paths);
@@ -1766,7 +1814,7 @@ async function lifecycleTick(login = false) {
1766
1814
  const preferences = await readPreferences(paths);
1767
1815
  const current = { version: record.version };
1768
1816
  if (login && preferences.openAtLogin) {
1769
- const { openCommand: openCommand2 } = await Promise.resolve().then(() => (init_commands(), commands_exports));
1817
+ const { openCommand: openCommand2 } = await Promise.resolve().then(() => (init_open(), open_exports));
1770
1818
  await openCommand2();
1771
1819
  }
1772
1820
  const queued = await nextUpdateRequest(paths);
@@ -1825,24 +1873,11 @@ async function takeLegacyRequest(file) {
1825
1873
  }
1826
1874
  return { file: claimed, request: await readJsonFile(claimed) };
1827
1875
  }
1828
- var init_lifecycle_manager = __esm({
1829
- "src/lifecycle-manager.ts"() {
1830
- "use strict";
1831
- init_files();
1832
- init_lifecycle_state2();
1833
- init_paths();
1834
- init_process_manager();
1835
- init_release();
1836
- init_startup();
1837
- init_controller();
1838
- init_preferences();
1839
- init_updater();
1840
- }
1841
- });
1842
1876
 
1843
1877
  // src/lifecycle-daemon.ts
1844
- import { watch } from "node:fs";
1845
- import { mkdir as mkdir7 } from "node:fs/promises";
1878
+ init_lifecycle_state2();
1879
+ init_paths();
1880
+ init_logs();
1846
1881
  async function serveLifecycle(login) {
1847
1882
  const paths = getSwitchyPaths();
1848
1883
  await ensureSwitchyDirectories(paths);
@@ -1909,18 +1944,10 @@ async function serveLifecycle(login) {
1909
1944
  throw error;
1910
1945
  }
1911
1946
  }
1912
- var init_lifecycle_daemon = __esm({
1913
- "src/lifecycle-daemon.ts"() {
1914
- "use strict";
1915
- init_files();
1916
- init_lifecycle_manager();
1917
- init_lifecycle_state2();
1918
- init_paths();
1919
- init_logs();
1920
- }
1921
- });
1922
1947
 
1923
1948
  // src/lifecycle.ts
1949
+ init_lifecycle_state2();
1950
+ init_paths();
1924
1951
  async function prepareLifecycleHost(paths, runtimeDirectory) {
1925
1952
  if (process.env.SWITCHY_DISABLE_LIFECYCLE === "1") return;
1926
1953
  if (!await installHost(paths, runtimeDirectory)) return;
@@ -1951,32 +1978,11 @@ async function lifecycleCommand(action) {
1951
1978
  throw new Error("Use startup enable, disable, or status");
1952
1979
  }
1953
1980
  }
1954
- var init_lifecycle = __esm({
1955
- "src/lifecycle.ts"() {
1956
- "use strict";
1957
- init_lifecycle_daemon();
1958
- init_lifecycle_manager();
1959
- init_lifecycle_state2();
1960
- init_paths();
1961
- init_startup();
1962
- }
1963
- });
1964
1981
 
1965
1982
  // src/commands.ts
1966
- var commands_exports = {};
1967
- __export(commands_exports, {
1968
- doctorCommand: () => doctorCommand,
1969
- logsCommand: () => logsCommand,
1970
- openCommand: () => openCommand,
1971
- restartCommand: () => restartCommand,
1972
- startCommand: () => startCommand,
1973
- statusCommand: () => statusCommand,
1974
- stopCommand: () => stopCommand,
1975
- updateCommand: () => updateCommand,
1976
- versionCommand: () => versionCommand
1977
- });
1978
- import { spawn as spawn4 } from "node:child_process";
1979
- import path16 from "node:path";
1983
+ init_logs();
1984
+ init_paths();
1985
+ init_process_manager();
1980
1986
  async function startCommand(options = {}) {
1981
1987
  const paths = getSwitchyPaths();
1982
1988
  await ensureSwitchyDirectories(paths);
@@ -2082,87 +2088,13 @@ async function updateCommand(action = "install") {
2082
2088
  async function logsCommand() {
2083
2089
  console.log(await readLogTail(getSwitchyPaths().logFile));
2084
2090
  }
2085
- async function openCommand() {
2086
- const running = await getRunningProcess(getSwitchyPaths());
2087
- if (!running?.live) throw new Error("Switchy is not running or is unresponsive");
2088
- const url = `http://${running.record.hostname}:${running.record.port}`;
2089
- const [executable, args] = process.platform === "darwin" ? ["open", [url]] : process.platform === "win32" ? ["cmd", ["/c", "start", "", url]] : ["xdg-open", [url]];
2090
- const child = spawn4(executable, args, { detached: true, stdio: "ignore" });
2091
- await new Promise((resolve, reject) => {
2092
- child.once("spawn", resolve);
2093
- child.once("error", reject);
2094
- });
2095
- child.unref();
2096
- console.log(url);
2097
- }
2098
2091
  function versionCommand() {
2099
2092
  console.log(CLI_VERSION);
2100
2093
  }
2101
- var init_commands = __esm({
2102
- "src/commands.ts"() {
2103
- "use strict";
2104
- init_config();
2105
- init_controller();
2106
- init_files();
2107
- init_lifecycle();
2108
- init_lifecycle_state2();
2109
- init_logs();
2110
- init_paths();
2111
- init_process_manager();
2112
- init_release();
2113
- init_updater();
2114
- }
2115
- });
2116
-
2117
- // src/arguments.ts
2118
- var OPTIONS = {
2119
- start: { "--port": "value", "--app-version": "value", "--foreground": "flag" },
2120
- stop: { "--force": "flag" },
2121
- restart: {},
2122
- status: { "--json": "flag" },
2123
- doctor: {},
2124
- update: { "--check": "flag", "--download": "flag", "--apply": "flag" },
2125
- startup: {},
2126
- logs: {},
2127
- open: {},
2128
- version: {},
2129
- help: {}
2130
- };
2131
- function parseArguments(args) {
2132
- const command = args[0] ?? "help";
2133
- if (args.includes("--help") || args.includes("-h")) return { command: "help", values: /* @__PURE__ */ new Map(), startup: "status" };
2134
- const selected = command === "--version" || command === "-v" ? "version" : command;
2135
- const options = Object.hasOwn(OPTIONS, selected) ? OPTIONS[selected] : void 0;
2136
- if (!options) throw new Error(`Unknown command: ${command}`);
2137
- const values = /* @__PURE__ */ new Map();
2138
- let startup = "status";
2139
- for (let index = 1; index < args.length; index++) {
2140
- const name = args[index];
2141
- if (selected === "startup" && index === 1 && ["enable", "disable", "status"].includes(name)) {
2142
- startup = name;
2143
- continue;
2144
- }
2145
- const kind = Object.hasOwn(options, name) ? options[name] : void 0;
2146
- if (!kind) throw new Error(`Unknown option for ${selected}: ${name}`);
2147
- if (values.has(name)) throw new Error(`Duplicate option: ${name}`);
2148
- if (kind === "value") {
2149
- const value = args[++index];
2150
- if (!value || value.startsWith("-")) throw new Error(`${name} requires a value`);
2151
- values.set(name, value);
2152
- } else values.set(name, true);
2153
- }
2154
- if (selected === "update" && values.size > 1) throw new Error("Choose one update action: --check, --download, or --apply");
2155
- const port = values.get("--port");
2156
- if (typeof port === "string" && (!/^\d+$/u.test(port) || Number(port) < 1 || Number(port) > 65535)) {
2157
- throw new Error("--port must be an integer between 1 and 65535");
2158
- }
2159
- return { command: selected, values, startup };
2160
- }
2161
2094
 
2162
2095
  // src/cli.ts
2163
- init_commands();
2164
2096
  init_config();
2165
- init_lifecycle();
2097
+ init_open();
2166
2098
  async function main() {
2167
2099
  assertSupportedNodeVersion();
2168
2100
  const { command, values, startup } = parseArguments(process.argv.slice(2));