@yuanchuan/aivo 0.31.0 → 0.31.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/bin/aivo.js +15 -72
- package/package.json +1 -1
- package/lib/update.js +0 -54
package/bin/aivo.js
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const { spawn
|
|
3
|
+
const { spawn } = require("node:child_process");
|
|
4
4
|
const os = require("node:os");
|
|
5
|
-
const { getInstalledBinaryPath
|
|
5
|
+
const { getInstalledBinaryPath } = require("../lib/paths");
|
|
6
6
|
const { formatLaunchError } = require("../lib/launcher");
|
|
7
|
-
const {
|
|
8
|
-
WINDOWS_NPM_UPDATE_COMMAND,
|
|
9
|
-
shouldDelegateWindowsNpmUpdate,
|
|
10
|
-
spawnWindowsNpmUpdate
|
|
11
|
-
} = require("../lib/update");
|
|
12
7
|
|
|
13
8
|
const args = process.argv.slice(2);
|
|
14
9
|
|
|
@@ -23,68 +18,16 @@ function forwardExit(child) {
|
|
|
23
18
|
});
|
|
24
19
|
}
|
|
25
20
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
timeout: 5000
|
|
40
|
-
});
|
|
41
|
-
if (result.status === 0 && typeof result.stdout === "string") {
|
|
42
|
-
const trimmed = result.stdout.trim();
|
|
43
|
-
if (trimmed) {
|
|
44
|
-
const parts = trimmed.split(/\s+/);
|
|
45
|
-
return parts[parts.length - 1];
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
} catch {
|
|
49
|
-
// best-effort: fall through to null
|
|
50
|
-
}
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function runWindowsNpmUpdate() {
|
|
55
|
-
console.log(`${CYAN}→${RESET} Updating via npm...`);
|
|
56
|
-
console.log(` ${DIM}Running:${RESET} ${GREEN}${WINDOWS_NPM_UPDATE_COMMAND}${RESET}`);
|
|
57
|
-
|
|
58
|
-
const child = spawnWindowsNpmUpdate(spawn);
|
|
59
|
-
child.on("error", (error) => {
|
|
60
|
-
console.error(`Failed to launch npm.cmd for update: ${error.message}`);
|
|
61
|
-
process.exit(1);
|
|
62
|
-
});
|
|
63
|
-
child.on("exit", (code, signal) => {
|
|
64
|
-
if (signal) {
|
|
65
|
-
process.exitCode = 128 + (os.constants.signals[signal] || 1);
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
if (code === 0) {
|
|
69
|
-
const version = readInstalledVersion();
|
|
70
|
-
const suffix = version ? ` to version ${version}` : "";
|
|
71
|
-
console.log(`${GREEN}✓${RESET} Updated${suffix}`);
|
|
72
|
-
}
|
|
73
|
-
process.exit(code ?? 1);
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (shouldDelegateWindowsNpmUpdate(args, { packageRoot: getPackageRoot() })) {
|
|
78
|
-
runWindowsNpmUpdate();
|
|
79
|
-
} else {
|
|
80
|
-
const binaryPath = getInstalledBinaryPath();
|
|
81
|
-
const child = spawn(binaryPath, args, {
|
|
82
|
-
stdio: "inherit"
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
forwardExit(child);
|
|
86
|
-
child.on("error", (error) => {
|
|
87
|
-
console.error(formatLaunchError(error, binaryPath));
|
|
88
|
-
process.exit(1);
|
|
89
|
-
});
|
|
90
|
-
}
|
|
21
|
+
// Every subcommand — including `update` — runs through the native binary. `update`
|
|
22
|
+
// self-updates in place (download + atomic rename), which works even on Windows
|
|
23
|
+
// where `npm install -g` can't overwrite the in-use global package binary.
|
|
24
|
+
const binaryPath = getInstalledBinaryPath();
|
|
25
|
+
const child = spawn(binaryPath, args, {
|
|
26
|
+
stdio: "inherit"
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
forwardExit(child);
|
|
30
|
+
child.on("error", (error) => {
|
|
31
|
+
console.error(formatLaunchError(error, binaryPath));
|
|
32
|
+
process.exit(1);
|
|
33
|
+
});
|
package/package.json
CHANGED
package/lib/update.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const WINDOWS_NPM_UPDATE_COMMAND = "npm.cmd install -g @yuanchuan/aivo@latest";
|
|
4
|
-
|
|
5
|
-
function normalizePathForMatch(value) {
|
|
6
|
-
return String(value || "")
|
|
7
|
-
.replace(/\\/g, "/")
|
|
8
|
-
.replace(/^\/\/\?\//, "")
|
|
9
|
-
.toLowerCase();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function isNpmManagedPackageRoot(packageRoot) {
|
|
13
|
-
const normalized = normalizePathForMatch(packageRoot);
|
|
14
|
-
return normalized.includes("/node_modules/@yuanchuan/aivo");
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function shouldDelegateWindowsNpmUpdate(argv, options = {}) {
|
|
18
|
-
const platform = options.platform || process.platform;
|
|
19
|
-
const packageRoot = options.packageRoot;
|
|
20
|
-
|
|
21
|
-
if (platform !== "win32") {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (!isNpmManagedPackageRoot(packageRoot)) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (!Array.isArray(argv) || argv[0] !== "update") {
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const rest = argv.slice(1);
|
|
34
|
-
if (rest.length === 0) {
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return rest.every((arg) => arg === "--no-color");
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function spawnWindowsNpmUpdate(spawnImpl, options = {}) {
|
|
42
|
-
const comspec = options.comspec || process.env.ComSpec || process.env.COMSPEC || "cmd.exe";
|
|
43
|
-
return spawnImpl(comspec, ["/d", "/s", "/c", WINDOWS_NPM_UPDATE_COMMAND], {
|
|
44
|
-
stdio: "inherit"
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
module.exports = {
|
|
49
|
-
WINDOWS_NPM_UPDATE_COMMAND,
|
|
50
|
-
isNpmManagedPackageRoot,
|
|
51
|
-
normalizePathForMatch,
|
|
52
|
-
shouldDelegateWindowsNpmUpdate,
|
|
53
|
-
spawnWindowsNpmUpdate
|
|
54
|
-
};
|