@tryglen/cli 0.6.0 → 0.6.1
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.
|
@@ -15,11 +15,13 @@ type Outcome = {
|
|
|
15
15
|
readonly hadExisting: boolean;
|
|
16
16
|
};
|
|
17
17
|
/**
|
|
18
|
-
* Make sure a current `glen` binary is reachable on PATH,
|
|
19
|
-
* updating it globally via npm when it isn't. `npx
|
|
20
|
-
* runs this CLI from npx's cache without ever
|
|
21
|
-
* without this step the plugins' hooks would have
|
|
22
|
-
* silently do nothing.
|
|
18
|
+
* Make sure a current, PERSISTENT `glen` binary is reachable on PATH,
|
|
19
|
+
* installing or updating it globally via npm when it isn't. `npx
|
|
20
|
+
* @tryglen/cli install` runs this CLI from npx's transient cache without ever
|
|
21
|
+
* linking a global binary — without this step the plugins' hooks would have
|
|
22
|
+
* no `glen` to call and silently do nothing. We deliberately ignore npx's own
|
|
23
|
+
* ephemeral shim (see persistentGlenPath) so a fresh machine always gets a
|
|
24
|
+
* real global install.
|
|
23
25
|
*
|
|
24
26
|
* `onInstallStart(hadExisting)` fires just before the (slow) npm install so
|
|
25
27
|
* the caller can print a progress line first.
|
|
@@ -3,10 +3,33 @@ import { join } from "node:path";
|
|
|
3
3
|
import { newer } from "./update.js";
|
|
4
4
|
import { cliVersion } from "./version.js";
|
|
5
5
|
import { isInstalled } from "./which.js";
|
|
6
|
-
/**
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Path to a PERSISTENT global `glen` on PATH, or null when the only matches
|
|
8
|
+
* are npx's transient shims. `npx @tryglen/cli install` runs this CLI from
|
|
9
|
+
* `~/.npm/_npx/<hash>/…/glen`, which is on PATH *only* while npx is running —
|
|
10
|
+
* it vanishes on exit, leaving the agents' hooks (which call bare `glen`)
|
|
11
|
+
* with nothing to run. A naive `which glen` reports that doomed shim, so we
|
|
12
|
+
* list every PATH match with `which -a` and ignore the ephemeral npx ones.
|
|
13
|
+
*/
|
|
14
|
+
const persistentGlenPath = () => {
|
|
15
|
+
try {
|
|
16
|
+
const out = execFileSync("which", ["-a", "glen"], {
|
|
17
|
+
encoding: "utf8",
|
|
18
|
+
timeout: 10_000,
|
|
19
|
+
});
|
|
20
|
+
return (out
|
|
21
|
+
.split("\n")
|
|
22
|
+
.map((line) => line.trim())
|
|
23
|
+
.find((line) => line.length > 0 && !line.includes("/_npx/")) ?? null);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
/** Version reported by the `glen` at `glenPath`, or null when unreadable. */
|
|
30
|
+
const versionAt = (glenPath) => {
|
|
8
31
|
try {
|
|
9
|
-
const out = execFileSync(
|
|
32
|
+
const out = execFileSync(glenPath, ["--version"], {
|
|
10
33
|
encoding: "utf8",
|
|
11
34
|
timeout: 10_000,
|
|
12
35
|
});
|
|
@@ -46,19 +69,21 @@ const installGlobally = () => {
|
|
|
46
69
|
}
|
|
47
70
|
};
|
|
48
71
|
/**
|
|
49
|
-
* Make sure a current `glen` binary is reachable on PATH,
|
|
50
|
-
* updating it globally via npm when it isn't. `npx
|
|
51
|
-
* runs this CLI from npx's cache without ever
|
|
52
|
-
* without this step the plugins' hooks would have
|
|
53
|
-
* silently do nothing.
|
|
72
|
+
* Make sure a current, PERSISTENT `glen` binary is reachable on PATH,
|
|
73
|
+
* installing or updating it globally via npm when it isn't. `npx
|
|
74
|
+
* @tryglen/cli install` runs this CLI from npx's transient cache without ever
|
|
75
|
+
* linking a global binary — without this step the plugins' hooks would have
|
|
76
|
+
* no `glen` to call and silently do nothing. We deliberately ignore npx's own
|
|
77
|
+
* ephemeral shim (see persistentGlenPath) so a fresh machine always gets a
|
|
78
|
+
* real global install.
|
|
54
79
|
*
|
|
55
80
|
* `onInstallStart(hadExisting)` fires just before the (slow) npm install so
|
|
56
81
|
* the caller can print a progress line first.
|
|
57
82
|
*/
|
|
58
83
|
const ensureGlobalCli = (onInstallStart) => {
|
|
59
|
-
const
|
|
60
|
-
if (
|
|
61
|
-
const version =
|
|
84
|
+
const existing = persistentGlenPath();
|
|
85
|
+
if (existing) {
|
|
86
|
+
const version = versionAt(existing);
|
|
62
87
|
// Up to date (or ahead, e.g. a dev build) — nothing to do. A stale or
|
|
63
88
|
// unreadable version falls through to a reinstall.
|
|
64
89
|
if (version && !newer(cliVersion, version))
|
|
@@ -66,17 +91,22 @@ const ensureGlobalCli = (onInstallStart) => {
|
|
|
66
91
|
}
|
|
67
92
|
if (!isInstalled("npm"))
|
|
68
93
|
return { status: "no-npm" };
|
|
69
|
-
onInstallStart?.(
|
|
94
|
+
onInstallStart?.(existing !== null);
|
|
70
95
|
const result = installGlobally();
|
|
71
96
|
if (!result.ok) {
|
|
72
|
-
return {
|
|
97
|
+
return {
|
|
98
|
+
status: "failed",
|
|
99
|
+
permission: result.permission,
|
|
100
|
+
hadExisting: existing !== null,
|
|
101
|
+
};
|
|
73
102
|
}
|
|
74
|
-
if (
|
|
103
|
+
if (existing)
|
|
75
104
|
return { status: "updated" };
|
|
76
|
-
|
|
105
|
+
// Re-probe: npm linked the binary; is a persistent (non-npx) glen now on PATH?
|
|
106
|
+
if (persistentGlenPath() !== null)
|
|
77
107
|
return { status: "installed" };
|
|
78
|
-
// npm succeeded but `glen` still doesn't resolve: the global
|
|
79
|
-
// not on PATH (common with version managers / fresh Homebrew node).
|
|
108
|
+
// npm succeeded but `glen` still doesn't resolve persistently: the global
|
|
109
|
+
// bin dir is not on PATH (common with version managers / fresh Homebrew node).
|
|
80
110
|
return { status: "path-missing", binDir: npmGlobalBinDir() };
|
|
81
111
|
};
|
|
82
112
|
export { ensureGlobalCli };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ensure-global-cli.js","sourceRoot":"","sources":["../../src/_utils/ensure-global-cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,M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