@gorlitzer-labs/seldon 0.1.22 → 0.1.24

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.
Files changed (3) hide show
  1. package/README.md +16 -6
  2. package/bin/seldon.js +139 -29
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -86,9 +86,14 @@ seldon uninstall --all # remove the whole stack (also drops ~/.seldon)
86
86
  seldon uninstall <ids> --yes # skip the confirm prompt
87
87
  ```
88
88
 
89
- Node tools are removed from the global store; demerzel's isolated venv and
90
- bifrost's binary + config are deleted. Your system Python, tmux, tailscale,
91
- sops/age are never touched.
89
+ Node tools are removed from **every** global store that has them (npm, each pnpm
90
+ on PATH — Homebrew's and corepack's can both be there — bun, and a copy loose
91
+ next to node), one package at a time. Each is checked afterwards: "removed"
92
+ means the files are gone, not that a command exited 0. Already gone counts as
93
+ success; anything still there is named with its path and the command exits 1.
94
+ demerzel's isolated venv and bifrost's binary + config are deleted. Your system
95
+ Python, tmux, tailscale, sops/age, and your comb vault (`~/.comb`) are never
96
+ touched. seldon itself stays; the last line tells you how to remove it too.
92
97
 
93
98
  ## The stack
94
99
 
@@ -113,9 +118,14 @@ It's a stack, not a bundle — install only what you use:
113
118
 
114
119
  ## Package managers
115
120
 
116
- Node tools install with **pnpm** when it can global-install (much faster than npm),
117
- else **npm**. **bun** is supported but opt-in — `seldon install --pm=bun` (also
118
- `--pm=pnpm|npm` to force any of them).
121
+ Node tools install with **the package manager that installed seldon itself**, so
122
+ `npm i -g @gorlitzer-labs/seldon` gives you an all-npm stack and `pnpm add -g …`
123
+ an all-pnpm one. Force one with `--pm=pnpm|npm|bun`.
124
+
125
+ Install leaves **exactly one copy** of each tool: if an older one sits under a
126
+ different package manager (a second pnpm, npm, or loose next to node), it is
127
+ removed, and the installer says so. Two copies is how a stale tool keeps
128
+ answering after you upgraded.
119
129
 
120
130
  demerzel (Python) always installs into its **own isolated venv** — never your
121
131
  system or active Python. It pins **CPython 3.12** (its `kokoro` pin caps Python at
package/bin/seldon.js CHANGED
@@ -88,32 +88,140 @@ const pnpmGlobalReady = () => {
88
88
  } catch { return false; }
89
89
  };
90
90
 
91
- // Pick the node package manager: --pm=<x> override (pnpm|bun|npm), else pnpm
92
- // when it can global-install, else npm (the universal fallback). bun is not
93
- // auto-preferred — opt in with --pm=bun.
91
+ // ---- where the node CLIs actually live --------------------------------------
92
+ // A global package can sit under npm, under pnpm, or under two pnpms at once:
93
+ // Homebrew's pnpm and corepack's are different majors, and pnpm 11 refuses to
94
+ // run unless $PNPM_HOME/bin is on PATH. So everything here answers from the
95
+ // filesystem, never from a package manager's exit code — `npm rm -g` of a
96
+ // package npm never had exits 0, and that used to be printed as "removed".
97
+
98
+ const realpath = (p) => { try { return fs.realpathSync(p); } catch { return path.resolve(p); } };
99
+ const defaultPnpmHome = () => process.env.PNPM_HOME
100
+ || (process.platform === "darwin" ? path.join(process.env.HOME, "Library", "pnpm") : path.join(process.env.HOME, ".local", "share", "pnpm"));
101
+
102
+ // Env for running one package-manager binary: its own dir first (so the right
103
+ // node is found), and pnpm's bin dir on PATH (pnpm 11 checks for it, even to rm).
104
+ function pmEnv(bin) {
105
+ const extra = path.isAbsolute(bin) ? [path.dirname(bin)] : [];
106
+ if (path.basename(bin) === "pnpm") extra.push(defaultPnpmHome(), path.join(defaultPnpmHome(), "bin"));
107
+ return { ...process.env, PATH: [...extra, process.env.PATH || ""].join(":") };
108
+ }
109
+
110
+ // Every distinct executable for a package manager on PATH (realpath-deduped).
111
+ function pmBins(pm) {
112
+ const seen = new Set(), out = [];
113
+ let found = "";
114
+ try { found = execSync(`which -a ${pm}`, { stdio: ["ignore", "pipe", "ignore"] }).toString(); } catch {}
115
+ for (const p of found.split("\n").map((l) => l.trim()).filter(Boolean)) {
116
+ const r = realpath(p);
117
+ if (!seen.has(r)) { seen.add(r); out.push(p); }
118
+ }
119
+ return out;
120
+ }
121
+
122
+ // The global node_modules one package-manager binary installs into.
123
+ function rootOf(bin) {
124
+ if (path.basename(bin) === "bun") return path.join(process.env.HOME, ".bun", "install", "global", "node_modules");
125
+ try { return execSync(`"${bin}" root -g`, { stdio: ["ignore", "pipe", "ignore"], env: pmEnv(bin) }).toString().trim().split("\n").pop() || ""; }
126
+ catch { return ""; }
127
+ }
128
+
129
+ let rootsCache = null;
130
+ // Every global node_modules this machine has: one per package-manager binary,
131
+ // plus the one next to node itself (`npm i -g` with a node-prefixed npm puts
132
+ // packages there, and no other npm can see them to remove them).
133
+ function globalRoots() {
134
+ if (rootsCache) return rootsCache;
135
+ const seen = new Set(), out = [];
136
+ const push = (r) => { const k = realpath(r.root); if (r.root && !seen.has(k)) { seen.add(k); out.push(r); } };
137
+ for (const pm of ["pnpm", "npm", "bun"]) {
138
+ for (const bin of pmBins(pm)) {
139
+ const root = rootOf(bin);
140
+ if (root) push({ pm, bin, root });
141
+ }
142
+ }
143
+ const prefix = process.env.SELDON_NODE_PREFIX || path.resolve(path.dirname(process.execPath), "..");
144
+ push({ pm: "node-prefix", bin: "", root: path.join(prefix, "lib", "node_modules") });
145
+ return (rootsCache = out);
146
+ }
147
+
148
+ const pkgDir = (root, pkg) => path.join(root, ...pkg.split("/"));
149
+ const installedAt = (pkg) => globalRoots().filter((r) => fs.existsSync(path.join(pkgDir(r.root, pkg), "package.json")));
150
+
151
+ // The package manager that installed seldon itself — the stack goes there too,
152
+ // so one `npm i -g @gorlitzer-labs/seldon` never ends up split across two.
153
+ // Compare against the RESOLVED package dir, not the root: pnpm's global
154
+ // node_modules/<pkg> is a symlink into a .pnpm store beside it, so the running
155
+ // file's real path is never under the root itself.
156
+ function homePM() {
157
+ const self = realpath(process.argv[1] || "");
158
+ return globalRoots().find((r) => {
159
+ if (!r.bin) return false;
160
+ const dir = pkgDir(r.root, "@gorlitzer-labs/seldon");
161
+ return fs.existsSync(dir) && self.startsWith(realpath(dir) + path.sep);
162
+ }) || null;
163
+ }
164
+
165
+ // Pick the node package manager: --pm=<x> override (pnpm|bun|npm), else the one
166
+ // seldon lives under, else pnpm when it can global-install, else npm.
94
167
  function nodePM() {
95
168
  const ov = (process.argv.find((a) => a.startsWith("--pm=")) || "").split("=")[1];
96
- if (ov) return ov;
97
- if (has("pnpm") && pnpmGlobalReady()) return "pnpm";
98
- return "npm";
169
+ if (ov) return { pm: ov, bin: ov };
170
+ const home = homePM();
171
+ if (home) return { pm: home.pm, bin: home.bin };
172
+ if (has("pnpm") && pnpmGlobalReady()) return { pm: "pnpm", bin: "pnpm" };
173
+ return { pm: "npm", bin: "npm" };
174
+ }
175
+
176
+ // Remove one package from one root. A node-prefix root has no package manager
177
+ // that can see it, so its dir and the bin links pointing into it go directly.
178
+ function removeAt(loc, pkg) {
179
+ const dir = pkgDir(loc.root, pkg);
180
+ if (loc.pm === "node-prefix") {
181
+ const binDir = path.join(loc.root, "..", "..", "bin");
182
+ try {
183
+ for (const f of fs.readdirSync(binDir)) {
184
+ const l = path.join(binDir, f);
185
+ try { if (fs.lstatSync(l).isSymbolicLink() && realpath(l).startsWith(realpath(dir) + path.sep)) fs.rmSync(l); } catch {}
186
+ }
187
+ } catch {}
188
+ console.log(C.dim(` $ rm -rf ${dir}`));
189
+ fs.rmSync(dir, { recursive: true, force: true });
190
+ } else {
191
+ run(loc.bin, [loc.pm === "bun" ? "remove" : "rm", "-g", pkg], { env: pmEnv(loc.bin) });
192
+ }
193
+ rootsCache = null;
194
+ return !fs.existsSync(path.join(dir, "package.json"));
99
195
  }
100
196
 
101
197
  function installNpm(m, dev) {
102
- const pm = nodePM();
198
+ const { pm, bin } = nodePM();
103
199
  if (dev && IN_CHECKOUT) {
104
200
  const dir = path.join(REPO_ROOT, m.dir);
105
201
  const pj = JSON.parse(fs.readFileSync(path.join(dir, "package.json")));
106
- if (pj.scripts?.build) run(pm, ["run", "build"], { cwd: dir });
202
+ if (pj.scripts?.build) run(bin, ["run", "build"], { cwd: dir, env: pmEnv(bin) });
107
203
  const link = pm === "pnpm" ? ["link", "--global"] : ["link"]; // bun/npm: `link`
108
- if (run(pm, link, { cwd: dir })) return true;
204
+ if (run(bin, link, { cwd: dir, env: pmEnv(bin) })) return true;
109
205
  if (pm !== "npm") { console.log(C.dim(" falling back to npm link…")); return run("npm", ["link"], { cwd: dir }); }
110
206
  return false;
111
207
  }
112
208
  // pnpm/bun: `add -g` · npm: `install -g` — a global CLI, no project touched
113
209
  const add = pm === "npm" ? ["install", "-g", m.pkg] : ["add", "-g", m.pkg];
114
- if (run(pm, add)) return true;
115
- if (pm !== "npm") { console.log(C.dim(` ${pm} failed — falling back to npm…`)); return run("npm", ["install", "-g", m.pkg]); }
116
- return false;
210
+ let used = bin;
211
+ let ok = run(bin, add, { env: pmEnv(bin) });
212
+ if (!ok && pm !== "npm") { console.log(C.dim(` ${pm} failed — falling back to npm…`)); used = "npm"; ok = run("npm", ["install", "-g", m.pkg]); }
213
+ if (!ok) return false;
214
+ // Exactly one copy: an older one under another package manager would shadow
215
+ // or outlive this one (that is how a stale factory kept answering).
216
+ rootsCache = null;
217
+ const here = rootOf(used);
218
+ if (!here) return true; // can't tell which copy is the new one — touch nothing
219
+ for (const loc of installedAt(m.pkg)) {
220
+ if (realpath(loc.root) === realpath(here)) continue;
221
+ console.log(C.dim(` removing the older copy under ${loc.pm}: ${pkgDir(loc.root, m.pkg)}`));
222
+ removeAt(loc, m.pkg);
223
+ }
224
+ return true;
117
225
  }
118
226
 
119
227
  function installShell(m, dev) {
@@ -215,15 +323,17 @@ async function doInstall(ids, { dev } = {}) {
215
323
  // npm and bun; try the chosen PM first, then any other present (a tool may have
216
324
  // been installed under a different one). Removing an absent package is success.
217
325
  function uninstallNpm(m) {
218
- const pm = nodePM();
219
- const tried = new Set();
220
- for (const cand of [pm, "pnpm", "npm", "bun"]) {
221
- if (tried.has(cand) || !has(cand)) continue;
222
- tried.add(cand);
223
- if (run(cand, ["rm", "-g", m.pkg])) return true;
224
- }
225
- console.log(C.dim(` ${m.id} not found in any global store (already gone)`));
226
- return true;
326
+ const locs = installedAt(m.pkg);
327
+ if (!locs.length) {
328
+ const stray = has(m.bin) ? execSync(`command -v ${m.bin}`, { stdio: ["ignore", "pipe", "ignore"] }).toString().trim() : "";
329
+ if (stray) { console.log(C.red(` no package manager has ${m.pkg}, but \`${m.bin}\` is still on PATH: ${stray} — remove it by hand`)); return false; }
330
+ console.log(C.dim(` ${m.id} is not installed (already gone)`));
331
+ return true;
332
+ }
333
+ for (const loc of locs) removeAt(loc, m.pkg);
334
+ const left = installedAt(m.pkg);
335
+ for (const loc of left) console.log(C.red(` still installed under ${loc.pm}: ${pkgDir(loc.root, m.pkg)}`));
336
+ return left.length === 0;
227
337
  }
228
338
 
229
339
  // demerzel & co: the isolated venv lives under ~/.seldon/<id>. Just delete it.
@@ -315,6 +425,11 @@ async function doUninstall(ids, { yes = false, all = false } = {}) {
315
425
  const good = results.filter(([, r]) => r).map(([i]) => i);
316
426
  const bad = results.filter(([, r]) => !r).map(([i]) => i);
317
427
  console.log("\n" + C.bold("Done. ") + C.green("removed: " + (good.join(", ") || "—")) + (bad.length ? " " + C.red("failed: " + bad.join(", ")) : ""));
428
+ if (bad.length) process.exitCode = 1;
429
+ if (all) {
430
+ const self = installedAt("@gorlitzer-labs/seldon")[0];
431
+ if (self && self.bin) console.log(C.dim(` seldon itself stays — to remove it too: ${path.basename(self.bin)} rm -g @gorlitzer-labs/seldon`));
432
+ }
318
433
  }
319
434
 
320
435
  // ---- up / down / status : the friendly front door ---------------------------
@@ -659,15 +774,10 @@ function down() {
659
774
  console.log(parts.length ? C.green(parts.join(" · ")) : C.dim("nothing was running."));
660
775
  }
661
776
 
662
- // Version of a globally-installed node package, across pnpm / npm / bun roots.
777
+ // Version of a globally-installed node package, across every global root.
663
778
  function npmGlobalVersion(pkg) {
664
- const roots = [];
665
- for (const c of ["pnpm root -g", "npm root -g"]) {
666
- try { roots.push(execSync(c, { stdio: ["ignore", "pipe", "ignore"] }).toString().trim()); } catch {}
667
- }
668
- roots.push(path.join(process.env.HOME, ".bun/install/global/node_modules"));
669
- for (const r of roots) {
670
- try { const pj = path.join(r, pkg, "package.json"); if (fs.existsSync(pj)) return JSON.parse(fs.readFileSync(pj, "utf8")).version; } catch {}
779
+ for (const r of installedAt(pkg)) {
780
+ try { return JSON.parse(fs.readFileSync(path.join(pkgDir(r.root, pkg), "package.json"), "utf8")).version; } catch {}
671
781
  }
672
782
  return "";
673
783
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gorlitzer-labs/seldon",
3
- "version": "0.1.22",
3
+ "version": "0.1.24",
4
4
  "description": "Install the Seldon stack — pick your tools from a checklist; each installs via its native method.",
5
5
  "type": "module",
6
6
  "bin": {