@myapihq/cli 1.0.71 → 1.0.73
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/commands/update.js +33 -9
- package/package.json +1 -1
package/dist/commands/update.js
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
import { execSync } from 'child_process';
|
|
2
|
+
import { existsSync } from 'fs';
|
|
2
3
|
import { loadConfig } from '../config.js';
|
|
3
4
|
import { info, success } from '../output.js';
|
|
4
5
|
import { installSkills } from './setup.js';
|
|
5
6
|
const REGISTRY_URL = 'https://registry.npmjs.org/@myapihq/cli/latest';
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
// Resolve the npm binary and global prefix to use for self-update.
|
|
8
|
+
// We install to the same prefix where the current myapi binary lives,
|
|
9
|
+
// so the update actually replaces the running binary.
|
|
10
|
+
function npmInstallArgs(version) {
|
|
11
|
+
const npmCandidate = process.execPath.replace(/[/\\]node(\.exe)?$/, '/npm');
|
|
12
|
+
const bin = existsSync(npmCandidate) ? npmCandidate : 'npm';
|
|
13
|
+
// Find where the currently-running myapi binary is, derive its npm prefix.
|
|
14
|
+
try {
|
|
15
|
+
const self = process.argv[1]; // e.g. /usr/local/bin/myapi or ~/.nvm/.../bin/myapi
|
|
16
|
+
const binDir = self.replace(/[/\\][^/\\]+$/, ''); // strip the filename
|
|
17
|
+
const prefix = binDir.replace(/[/\\]bin$/, ''); // strip /bin
|
|
18
|
+
return { bin, args: ['install', '-g', '--prefix', prefix, `@myapihq/cli@${version}`] };
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return { bin, args: ['install', '-g', `@myapihq/cli@${version}`] };
|
|
22
|
+
}
|
|
9
23
|
}
|
|
10
24
|
// checkForUpdate runs silently in the background on every command.
|
|
11
25
|
// Auto-installs if a newer version is available.
|
|
@@ -17,12 +31,21 @@ export async function checkForUpdate(currentVersion) {
|
|
|
17
31
|
const data = await res.json();
|
|
18
32
|
const latest = data.version;
|
|
19
33
|
if (latest && isNewer(latest, currentVersion)) {
|
|
34
|
+
// Verify the tarball is actually available before attempting install —
|
|
35
|
+
// the registry metadata can report a new version before the tarball is uploaded.
|
|
36
|
+
const tarballUrl = `https://registry.npmjs.org/@myapihq/cli/-/cli-${latest}.tgz`;
|
|
37
|
+
try {
|
|
38
|
+
const check = await fetch(tarballUrl, { method: 'HEAD', signal: AbortSignal.timeout(3000) });
|
|
39
|
+
if (!check.ok)
|
|
40
|
+
return; // Tarball not ready yet — silently skip, retry next command.
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
20
45
|
info(`\n› New version available (${currentVersion} → ${latest}) — installing…`);
|
|
21
46
|
try {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// its tarball is available.
|
|
25
|
-
execSync(`"${npmBin()}" install -g @myapihq/cli@latest`, { stdio: 'pipe' });
|
|
47
|
+
const { bin, args } = npmInstallArgs(latest);
|
|
48
|
+
execSync(`"${bin}" ${args.map(a => `"${a}"`).join(' ')}`, { stdio: 'pipe' });
|
|
26
49
|
const config = loadConfig();
|
|
27
50
|
if (config?.skills_installed) {
|
|
28
51
|
await installSkills();
|
|
@@ -59,8 +82,9 @@ export async function update(flags = {}) {
|
|
|
59
82
|
}
|
|
60
83
|
catch { /* proceed anyway */ }
|
|
61
84
|
try {
|
|
62
|
-
const
|
|
63
|
-
|
|
85
|
+
const ver = latest || 'latest';
|
|
86
|
+
const { bin, args } = npmInstallArgs(ver);
|
|
87
|
+
execSync(`"${bin}" ${args.map((a) => `"${a}"`).join(' ')}`, { stdio: 'inherit' });
|
|
64
88
|
}
|
|
65
89
|
catch {
|
|
66
90
|
process.exit(1);
|