@gorlitzer-labs/seldon 0.1.22 → 0.1.23

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 +132 -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,133 @@ 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
+ function homePM() {
154
+ const self = realpath(process.argv[1] || "");
155
+ return globalRoots().find((r) => r.bin && self.startsWith(realpath(r.root) + path.sep)) || null;
156
+ }
157
+
158
+ // Pick the node package manager: --pm=<x> override (pnpm|bun|npm), else the one
159
+ // seldon lives under, else pnpm when it can global-install, else npm.
94
160
  function nodePM() {
95
161
  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";
162
+ if (ov) return { pm: ov, bin: ov };
163
+ const home = homePM();
164
+ if (home) return { pm: home.pm, bin: home.bin };
165
+ if (has("pnpm") && pnpmGlobalReady()) return { pm: "pnpm", bin: "pnpm" };
166
+ return { pm: "npm", bin: "npm" };
167
+ }
168
+
169
+ // Remove one package from one root. A node-prefix root has no package manager
170
+ // that can see it, so its dir and the bin links pointing into it go directly.
171
+ function removeAt(loc, pkg) {
172
+ const dir = pkgDir(loc.root, pkg);
173
+ if (loc.pm === "node-prefix") {
174
+ const binDir = path.join(loc.root, "..", "..", "bin");
175
+ try {
176
+ for (const f of fs.readdirSync(binDir)) {
177
+ const l = path.join(binDir, f);
178
+ try { if (fs.lstatSync(l).isSymbolicLink() && realpath(l).startsWith(realpath(dir) + path.sep)) fs.rmSync(l); } catch {}
179
+ }
180
+ } catch {}
181
+ console.log(C.dim(` $ rm -rf ${dir}`));
182
+ fs.rmSync(dir, { recursive: true, force: true });
183
+ } else {
184
+ run(loc.bin, [loc.pm === "bun" ? "remove" : "rm", "-g", pkg], { env: pmEnv(loc.bin) });
185
+ }
186
+ rootsCache = null;
187
+ return !fs.existsSync(path.join(dir, "package.json"));
99
188
  }
100
189
 
101
190
  function installNpm(m, dev) {
102
- const pm = nodePM();
191
+ const { pm, bin } = nodePM();
103
192
  if (dev && IN_CHECKOUT) {
104
193
  const dir = path.join(REPO_ROOT, m.dir);
105
194
  const pj = JSON.parse(fs.readFileSync(path.join(dir, "package.json")));
106
- if (pj.scripts?.build) run(pm, ["run", "build"], { cwd: dir });
195
+ if (pj.scripts?.build) run(bin, ["run", "build"], { cwd: dir, env: pmEnv(bin) });
107
196
  const link = pm === "pnpm" ? ["link", "--global"] : ["link"]; // bun/npm: `link`
108
- if (run(pm, link, { cwd: dir })) return true;
197
+ if (run(bin, link, { cwd: dir, env: pmEnv(bin) })) return true;
109
198
  if (pm !== "npm") { console.log(C.dim(" falling back to npm link…")); return run("npm", ["link"], { cwd: dir }); }
110
199
  return false;
111
200
  }
112
201
  // pnpm/bun: `add -g` · npm: `install -g` — a global CLI, no project touched
113
202
  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;
203
+ let used = bin;
204
+ let ok = run(bin, add, { env: pmEnv(bin) });
205
+ if (!ok && pm !== "npm") { console.log(C.dim(` ${pm} failed — falling back to npm…`)); used = "npm"; ok = run("npm", ["install", "-g", m.pkg]); }
206
+ if (!ok) return false;
207
+ // Exactly one copy: an older one under another package manager would shadow
208
+ // or outlive this one (that is how a stale factory kept answering).
209
+ rootsCache = null;
210
+ const here = rootOf(used);
211
+ if (!here) return true; // can't tell which copy is the new one — touch nothing
212
+ for (const loc of installedAt(m.pkg)) {
213
+ if (realpath(loc.root) === realpath(here)) continue;
214
+ console.log(C.dim(` removing the older copy under ${loc.pm}: ${pkgDir(loc.root, m.pkg)}`));
215
+ removeAt(loc, m.pkg);
216
+ }
217
+ return true;
117
218
  }
118
219
 
119
220
  function installShell(m, dev) {
@@ -215,15 +316,17 @@ async function doInstall(ids, { dev } = {}) {
215
316
  // npm and bun; try the chosen PM first, then any other present (a tool may have
216
317
  // been installed under a different one). Removing an absent package is success.
217
318
  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;
319
+ const locs = installedAt(m.pkg);
320
+ if (!locs.length) {
321
+ const stray = has(m.bin) ? execSync(`command -v ${m.bin}`, { stdio: ["ignore", "pipe", "ignore"] }).toString().trim() : "";
322
+ 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; }
323
+ console.log(C.dim(` ${m.id} is not installed (already gone)`));
324
+ return true;
325
+ }
326
+ for (const loc of locs) removeAt(loc, m.pkg);
327
+ const left = installedAt(m.pkg);
328
+ for (const loc of left) console.log(C.red(` still installed under ${loc.pm}: ${pkgDir(loc.root, m.pkg)}`));
329
+ return left.length === 0;
227
330
  }
228
331
 
229
332
  // demerzel & co: the isolated venv lives under ~/.seldon/<id>. Just delete it.
@@ -315,6 +418,11 @@ async function doUninstall(ids, { yes = false, all = false } = {}) {
315
418
  const good = results.filter(([, r]) => r).map(([i]) => i);
316
419
  const bad = results.filter(([, r]) => !r).map(([i]) => i);
317
420
  console.log("\n" + C.bold("Done. ") + C.green("removed: " + (good.join(", ") || "—")) + (bad.length ? " " + C.red("failed: " + bad.join(", ")) : ""));
421
+ if (bad.length) process.exitCode = 1;
422
+ if (all) {
423
+ const self = installedAt("@gorlitzer-labs/seldon")[0];
424
+ if (self && self.bin) console.log(C.dim(` seldon itself stays — to remove it too: ${path.basename(self.bin)} rm -g @gorlitzer-labs/seldon`));
425
+ }
318
426
  }
319
427
 
320
428
  // ---- up / down / status : the friendly front door ---------------------------
@@ -659,15 +767,10 @@ function down() {
659
767
  console.log(parts.length ? C.green(parts.join(" · ")) : C.dim("nothing was running."));
660
768
  }
661
769
 
662
- // Version of a globally-installed node package, across pnpm / npm / bun roots.
770
+ // Version of a globally-installed node package, across every global root.
663
771
  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 {}
772
+ for (const r of installedAt(pkg)) {
773
+ try { return JSON.parse(fs.readFileSync(path.join(pkgDir(r.root, pkg), "package.json"), "utf8")).version; } catch {}
671
774
  }
672
775
  return "";
673
776
  }
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.23",
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": {