@m8t-stack/cli 0.2.58 → 0.2.59

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
@@ -1364,7 +1364,7 @@ var init_enable_hosted_brain = __esm({
1364
1364
  import { Builtins, Cli } from "clipanion";
1365
1365
 
1366
1366
  // src/lib/package-version.ts
1367
- var CLI_VERSION = "0.2.58";
1367
+ var CLI_VERSION = "0.2.59";
1368
1368
 
1369
1369
  // src/lib/render-error.ts
1370
1370
  init_errors();
@@ -30650,6 +30650,29 @@ function defaultLaunch(executable) {
30650
30650
  child.unref();
30651
30651
  return Promise.resolve();
30652
30652
  }
30653
+ async function companionIsRunning(platform, executable) {
30654
+ if (platform !== "win32") return false;
30655
+ let handle;
30656
+ try {
30657
+ handle = await fs32.open(executable, "r+");
30658
+ } catch (error) {
30659
+ const code = error.code;
30660
+ if (code === "ENOENT") return false;
30661
+ if (code === "EBUSY" || code === "EPERM" || code === "EACCES") return true;
30662
+ throw error;
30663
+ } finally {
30664
+ await handle?.close().catch(() => void 0);
30665
+ }
30666
+ return false;
30667
+ }
30668
+ async function assertCompanionNotRunning(options, executable) {
30669
+ const running = options.isRunning ?? ((owned) => companionIsRunning(options.platform, owned));
30670
+ if (await running(executable)) {
30671
+ throw new Error(
30672
+ "The desktop companions are running. Quit them from the tray, then run this again."
30673
+ );
30674
+ }
30675
+ }
30653
30676
  async function readInstalled(options) {
30654
30677
  const paths = companionInstallPaths(options);
30655
30678
  await assertNotSymlink(paths.installManifest, "Install manifest");
@@ -30778,6 +30801,15 @@ async function converge(options, force) {
30778
30801
  if (!force && current.state === "installed" && current.version === artifactManifest.version && current.artifactTreeSha256 === artifactManifest.treeSha256 && current.startAtLogin) {
30779
30802
  return current;
30780
30803
  }
30804
+ if (priorInstalled) {
30805
+ await assertCompanionNotRunning(
30806
+ options,
30807
+ path35.join(
30808
+ priorInstalled.paths.targetRoot,
30809
+ ...priorInstalled.install.entryRelativePath.split("/")
30810
+ )
30811
+ );
30812
+ }
30781
30813
  if (current.state === "not-installed") {
30782
30814
  try {
30783
30815
  await fs32.lstat(paths.targetRoot);
@@ -30928,6 +30960,7 @@ async function uninstallCompanion(options) {
30928
30960
  paths.targetRoot,
30929
30961
  ...install.entryRelativePath.split("/")
30930
30962
  );
30963
+ await assertCompanionNotRunning(options, executable);
30931
30964
  await (options.setStartAtLogin ?? (() => Promise.resolve()))(executable, false);
30932
30965
  const remove = options.removeOwnedPath ?? (async (ownedPath, recursive) => {
30933
30966
  await fs32.rm(ownedPath, { recursive, force: true });
@@ -31053,7 +31086,7 @@ function defaultLocalCompanionInstallOptions() {
31053
31086
  getStartAtLogin: (executable) => getCompanionStartAtLogin({ homeDirectory, platform, executable })
31054
31087
  };
31055
31088
  }
31056
- async function convergeCompanionFromChannel(converge2, stagedDirectory) {
31089
+ async function convergeCompanionFromChannel(converge2, stagedDirectory, resourceGroup) {
31057
31090
  let artifactManifestPath;
31058
31091
  let dispose = () => Promise.resolve();
31059
31092
  if (stagedDirectory !== void 0) {
@@ -31065,7 +31098,7 @@ async function convergeCompanionFromChannel(converge2, stagedDirectory) {
31065
31098
  artifactManifestPath = build.artifactManifestPath;
31066
31099
  dispose = build.dispose;
31067
31100
  }
31068
- const gateway = await resolveGatewayContext({ interactive: false });
31101
+ const gateway = await resolveGatewayContext({ interactive: false, resourceGroup });
31069
31102
  try {
31070
31103
  return await converge2({
31071
31104
  ...defaultLocalCompanionInstallOptions(),
@@ -31110,10 +31143,13 @@ var CompanionInstallCommand = class extends M8tCommand {
31110
31143
  from = Option52.String("--from", {
31111
31144
  description: "A locally staged build directory instead of the released one."
31112
31145
  });
31146
+ resourceGroup = Option52.String("--resource-group", {
31147
+ description: "Which deployment to bind to, when the subscription holds more than one."
31148
+ });
31113
31149
  async executeCommand() {
31114
31150
  return runCompanionInstallCommand(
31115
31151
  this.context.stdout,
31116
- () => convergeCompanionFromChannel(installCompanion, this.from)
31152
+ () => convergeCompanionFromChannel(installCompanion, this.from, this.resourceGroup)
31117
31153
  );
31118
31154
  }
31119
31155
  };
@@ -33575,7 +33611,7 @@ var CompanionStatusCommand = class extends M8tCommand {
33575
33611
  };
33576
33612
 
33577
33613
  // src/commands/companion/repair.ts
33578
- import { Command as Command63 } from "clipanion";
33614
+ import { Command as Command63, Option as Option58 } from "clipanion";
33579
33615
  async function runCompanionRepairCommand(stdout, repair) {
33580
33616
  const state = await repair();
33581
33617
  if (state.state === "not-released") {
@@ -33595,12 +33631,15 @@ async function runCompanionRepairCommand(stdout, repair) {
33595
33631
  var CompanionRepairCommand = class extends M8tCommand {
33596
33632
  static paths = [["companion", "repair"]];
33597
33633
  static usage = Command63.Usage({
33598
- description: "Restore the internal desktop companion and start-at-login state."
33634
+ description: "Restore the desktop companions and start-at-login state."
33635
+ });
33636
+ resourceGroup = Option58.String("--resource-group", {
33637
+ description: "Which deployment to bind to, when the subscription holds more than one."
33599
33638
  });
33600
33639
  async executeCommand() {
33601
33640
  return runCompanionRepairCommand(
33602
33641
  this.context.stdout,
33603
- () => convergeCompanionFromChannel(repairCompanion)
33642
+ () => convergeCompanionFromChannel(repairCompanion, void 0, this.resourceGroup)
33604
33643
  );
33605
33644
  }
33606
33645
  };