yaver-cli 1.99.4 → 1.99.5
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 +1 -1
- package/src/postinstall.js +58 -0
package/package.json
CHANGED
package/src/postinstall.js
CHANGED
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
// Must NEVER fail npm install. This is best-effort bootstrap only.
|
|
8
8
|
|
|
9
9
|
const { ensureAgentBinary, runAgentCommand } = require("./agent-runtime");
|
|
10
|
+
const { execSync } = require("child_process");
|
|
11
|
+
const fs = require("fs");
|
|
12
|
+
const os = require("os");
|
|
13
|
+
const path = require("path");
|
|
10
14
|
|
|
11
15
|
function envEnabled(name) {
|
|
12
16
|
const raw = String(process.env[name] || "").trim().toLowerCase();
|
|
@@ -24,6 +28,58 @@ function log(message) {
|
|
|
24
28
|
console.error(`[yaver postinstall] ${message}`);
|
|
25
29
|
}
|
|
26
30
|
|
|
31
|
+
// Make sure `yaver` resolves on PATH for the next shell session. npm's
|
|
32
|
+
// global prefix (e.g. ~/.npm-global/bin) is not on PATH by default on
|
|
33
|
+
// most Linux distros — so `npm install -g yaver-cli` succeeds but
|
|
34
|
+
// `yaver auth` then exits with command-not-found. That is the #1 fail
|
|
35
|
+
// mode on fresh machines, so we self-heal by appending a one-line,
|
|
36
|
+
// idempotent PATH export into the user's shell rc files. Never throws.
|
|
37
|
+
function ensurePathOnUnix() {
|
|
38
|
+
try {
|
|
39
|
+
if (process.platform === "win32") return; // Windows users have Scoop/Winget
|
|
40
|
+
const prefix = (process.env.npm_config_prefix || "").trim();
|
|
41
|
+
if (!prefix) return;
|
|
42
|
+
const binDir = path.join(prefix, "bin");
|
|
43
|
+
if (!fs.existsSync(path.join(binDir, "yaver"))) return;
|
|
44
|
+
|
|
45
|
+
const currentPath = (process.env.PATH || "").split(path.delimiter);
|
|
46
|
+
if (currentPath.includes(binDir)) return;
|
|
47
|
+
|
|
48
|
+
// Also confirm `yaver` isn't already findable under a different name
|
|
49
|
+
// (e.g. brew-installed /opt/homebrew/bin/yaver takes precedence).
|
|
50
|
+
try {
|
|
51
|
+
const found = execSync("command -v yaver", { stdio: ["ignore", "pipe", "ignore"] })
|
|
52
|
+
.toString()
|
|
53
|
+
.trim();
|
|
54
|
+
if (found) return;
|
|
55
|
+
} catch (_) {
|
|
56
|
+
// `command -v` returns nonzero when not found — fall through and patch PATH.
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const home = os.homedir();
|
|
60
|
+
const rcFiles = [".bashrc", ".zshrc", ".profile"]
|
|
61
|
+
.map((f) => path.join(home, f))
|
|
62
|
+
.filter((p) => fs.existsSync(p));
|
|
63
|
+
|
|
64
|
+
const marker = "# yaver-cli PATH";
|
|
65
|
+
const line = `case \":$PATH:\" in *\":${binDir}:\"*) ;; *) export PATH=\"${binDir}:$PATH\" ;; esac`;
|
|
66
|
+
const block = `\n${marker} (added by yaver-cli postinstall)\n${line}\n`;
|
|
67
|
+
|
|
68
|
+
let patched = false;
|
|
69
|
+
for (const rc of rcFiles) {
|
|
70
|
+
const content = fs.readFileSync(rc, "utf8");
|
|
71
|
+
if (content.includes(marker)) continue;
|
|
72
|
+
fs.appendFileSync(rc, block);
|
|
73
|
+
patched = true;
|
|
74
|
+
}
|
|
75
|
+
if (patched) {
|
|
76
|
+
log(`Added ${binDir} to PATH in shell rc files. Run 'exec $SHELL -l' or open a new terminal.`);
|
|
77
|
+
}
|
|
78
|
+
} catch (err) {
|
|
79
|
+
// Best-effort only.
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
27
83
|
async function main() {
|
|
28
84
|
if (envEnabled("YAVER_SKIP_POSTINSTALL") || envEnabled("YAVER_SKIP_POSTINSTALL_BOOTSTRAP")) {
|
|
29
85
|
return;
|
|
@@ -39,6 +95,8 @@ async function main() {
|
|
|
39
95
|
return;
|
|
40
96
|
}
|
|
41
97
|
|
|
98
|
+
ensurePathOnUnix();
|
|
99
|
+
|
|
42
100
|
if (process.platform !== "linux" && process.platform !== "darwin") {
|
|
43
101
|
return;
|
|
44
102
|
}
|