@nomac/cli 0.21.1 → 0.21.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nomac/cli",
3
- "version": "0.21.1",
3
+ "version": "0.21.2",
4
4
  "description": "A real cloud Mac for AI agents: Xcode, the iOS Simulator, signing, TestFlight and App Store publishing, by the minute, over MCP, SSH and HTTPS.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
@@ -4,17 +4,18 @@
4
4
  import { spawnSync } from "node:child_process";
5
5
  import { mkdirSync, rmSync, writeFileSync } from "node:fs";
6
6
  import { join } from "node:path";
7
- import { installedBin, pruneInstalls } from "./self-update.mjs";
7
+ import { installedBin, npmCommand, pruneInstalls } from "./self-update.mjs";
8
8
 
9
9
  const [version, dir] = process.argv.slice(2);
10
10
  if (!/^\d{1,4}\.\d{1,4}\.\d{1,4}$/.test(version ?? "") || !dir) process.exit(2);
11
- const windows = process.platform === "win32";
12
11
  try {
13
12
  rmSync(dir, { recursive: true, force: true });
14
13
  mkdirSync(dir, { recursive: true });
15
- const npm = spawnSync(windows ? "npm.cmd" : "npm", ["install", "--prefix", dir, "--no-audit", "--no-fund", "--omit=dev", "--loglevel=error", `@nomac/cli@${version}`],
16
- { stdio: "ignore", timeout: 10 * 60_000, shell: windows, windowsHide: true });
17
- if (npm.status !== 0) throw new Error("npm install failed");
14
+ const npm = npmCommand();
15
+ // Through a shell (npm.cmd on PATH, Windows) the words are joined as they are: a home folder with a space is quoted.
16
+ const words = ["install", "--prefix", dir, "--no-audit", "--no-fund", "--omit=dev", "--loglevel=error", `@nomac/cli@${version}`].map(word => (npm.shell && /\s/.test(word) ? `"${word}"` : word));
17
+ const install = spawnSync(npm.command, [...npm.args, ...words], { stdio: "ignore", timeout: 10 * 60_000, shell: npm.shell, windowsHide: true });
18
+ if (install.status !== 0) throw new Error("npm install failed");
18
19
  const check = spawnSync(process.execPath, [installedBin(version), "--version"], { encoding: "utf8", timeout: 30_000, env: { ...process.env, NOMAC_CLI_DELEGATED: "check", NOMAC_NO_AUTO_UPDATE: "1" }, windowsHide: true });
19
20
  if (check.status !== 0 || !check.stdout.includes(version)) throw new Error("the installed CLI did not run");
20
21
  writeFileSync(join(dir, ".nomac-ready"), `${new Date().toISOString()}\n`);
@@ -1,7 +1,7 @@
1
1
  import { spawn } from "node:child_process";
2
- import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
+ import { existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
3
3
  import { homedir } from "node:os";
4
- import { join } from "node:path";
4
+ import { dirname, join } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import { CLI_VERSION } from "./client-info.mjs";
7
7
 
@@ -105,6 +105,23 @@ export function updateNotice(state = readState(), now = Date.now()) {
105
105
  return `NoMac CLI ${state.latest} is out (this is ${CLI_VERSION}): npm install -g @nomac/cli@latest, or run nomac update.`;
106
106
  }
107
107
 
108
+ /**
109
+ * The npm that came with the Node running this CLI, run by that Node: an editor's SSH ProxyCommand or a desktop MCP
110
+ * client often starts the CLI by Node's full path with a PATH that has no npm, and an install that looked npm up on
111
+ * PATH failed there every time, silently (an account ran 0.13.6 for five days, about 24,000 commands, October 30).
112
+ * The places: beside node (a link to npm-cli.js: Linux packages, nvm, the official tarball), the prefix's lib or
113
+ * Homebrew's libexec, and Windows' node_modules beside node.exe. Else npm on PATH, as before.
114
+ */
115
+ export function npmCommand({ execPath = process.execPath, platform = process.platform, exists = existsSync, realpath = realpathSync } = {}) {
116
+ const bin = dirname(execPath), prefix = dirname(bin);
117
+ const beside = platform === "win32" ? [] : [join(bin, "npm")].filter(exists).map(link => { try { return realpath(link); } catch { return ""; } }).filter(file => file.endsWith(".js"));
118
+ const places = [...beside, ...(platform === "win32" ? [join(bin, "node_modules", "npm", "bin", "npm-cli.js")]
119
+ : [join(prefix, "lib", "node_modules", "npm", "bin", "npm-cli.js"), join(prefix, "libexec", "lib", "node_modules", "npm", "bin", "npm-cli.js")])];
120
+ const cli = places.find(file => exists(file));
121
+ if (cli) return { command: execPath, args: [cli], shell: false };
122
+ return platform === "win32" ? { command: "npm.cmd", args: [], shell: true } : { command: "npm", args: [], shell: false };
123
+ }
124
+
108
125
  /** Removes installed versions older than keep's predecessor (one older version stays for running commands). */
109
126
  export function pruneInstalls(keep) {
110
127
  const versions = installedVersions().filter(v => v !== keep).sort((a, b) => (newer(a, b) ? -1 : 1));