@xyrlan/mnemo 0.13.2 → 0.13.4
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/lib/bootstrap.js +12 -8
- package/lib/runMnemo.js +34 -3
- package/package.json +1 -1
package/lib/bootstrap.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const { execSync, spawnSync } = require("node:child_process");
|
|
4
4
|
const { probeOnPath } = require("./detect");
|
|
5
|
+
const { resolveMnemoBinary } = require("./runMnemo");
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
const PIN_SPEC = "mnemo-claude>=0.13,<0.14";
|
|
@@ -27,8 +28,13 @@ function buildUpgradeCmd(installer) {
|
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
// Detect a real mnemo install. We can NOT trust `command -v mnemo` here:
|
|
32
|
+
// when running under `npx @xyrlan/mnemo`, npm injects the wrapper itself
|
|
33
|
+
// onto PATH, so `command -v mnemo` resolves to us. resolveMnemoBinary
|
|
34
|
+
// filters npx temp dirs so it only matches a real Python install.
|
|
35
|
+
function isAlreadyInstalled(resolverFn = resolveMnemoBinary) {
|
|
36
|
+
const selfBinDir = process.argv[1] ? require("node:path").dirname(process.argv[1]) : null;
|
|
37
|
+
return Boolean(resolverFn({ selfBinDir }));
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
|
|
@@ -39,12 +45,10 @@ function runShell(cmd, { quiet = false } = {}) {
|
|
|
39
45
|
|
|
40
46
|
|
|
41
47
|
function verifyOnPath() {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
+
const { resolveMnemoBinary } = require("./runMnemo");
|
|
49
|
+
const path = require("node:path");
|
|
50
|
+
const selfBinDir = process.argv[1] ? path.dirname(process.argv[1]) : null;
|
|
51
|
+
return Boolean(resolveMnemoBinary({ selfBinDir }));
|
|
48
52
|
}
|
|
49
53
|
|
|
50
54
|
|
package/lib/runMnemo.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const { spawnSync } = require("node:child_process");
|
|
4
|
+
const fs = require("node:fs");
|
|
5
|
+
const path = require("node:path");
|
|
4
6
|
|
|
5
7
|
|
|
6
8
|
function buildInitArgs({ scope, vaultRoot, quiet, yes = true }) {
|
|
@@ -22,10 +24,39 @@ function buildUninstallArgs({ scope, quiet, yes = true }) {
|
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
// Resolve the real Python `mnemo` entry point, skipping the npx-injected
|
|
28
|
+
// wrapper bin so spawnSync doesn't recurse into us.
|
|
29
|
+
function resolveMnemoBinary({ env = process.env, platform = process.platform, selfBinDir } = {}) {
|
|
30
|
+
const exeName = platform === "win32" ? "mnemo.exe" : "mnemo";
|
|
31
|
+
const sep = platform === "win32" ? ";" : ":";
|
|
32
|
+
const rawPath = (env.PATH || env.Path || "").split(sep);
|
|
33
|
+
const skip = new Set();
|
|
34
|
+
if (selfBinDir) skip.add(path.resolve(selfBinDir));
|
|
35
|
+
return rawPath
|
|
36
|
+
.filter((dir) => dir && !skip.has(path.resolve(dir)) && !/[\\/]_npx[\\/]/.test(dir))
|
|
37
|
+
.map((dir) => path.join(dir, exeName))
|
|
38
|
+
.find((candidate) => {
|
|
39
|
+
try { return fs.statSync(candidate).isFile(); }
|
|
40
|
+
catch (_e) { return false; }
|
|
41
|
+
}) || null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
// Decide what to spawn. If we have a resolved real binary, run it directly.
|
|
46
|
+
// Otherwise fall back to `python3 -m mnemo` so we never recurse into the
|
|
47
|
+
// npx-injected wrapper that may still be on PATH.
|
|
48
|
+
function buildSpawnPlan(bin, args) {
|
|
49
|
+
if (bin) return { cmd: bin, args };
|
|
50
|
+
return { cmd: "python3", args: ["-m", "mnemo", ...args] };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
function runMnemo(args, { quiet = false, selfBinDir } = {}) {
|
|
55
|
+
const bin = resolveMnemoBinary({ selfBinDir: selfBinDir || (process.argv[1] && path.dirname(process.argv[1])) });
|
|
56
|
+
const plan = buildSpawnPlan(bin, args);
|
|
57
|
+
const result = spawnSync(plan.cmd, plan.args, { stdio: quiet ? "ignore" : "inherit" });
|
|
27
58
|
return result.status === null ? 1 : result.status;
|
|
28
59
|
}
|
|
29
60
|
|
|
30
61
|
|
|
31
|
-
module.exports = { buildInitArgs, buildUninstallArgs, runMnemo };
|
|
62
|
+
module.exports = { buildInitArgs, buildUninstallArgs, runMnemo, resolveMnemoBinary, buildSpawnPlan };
|