memorizz 0.6.0 → 0.6.2
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/bin/memorizz.js +51 -7
- package/package.json +1 -1
package/bin/memorizz.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Copyright (c) 2024 Richmond Alake. Licensed under PolyForm Noncommercial 1.0.0.
|
|
3
3
|
//
|
|
4
|
-
// Thin launcher: exec the uv-installed `memorizz`, forwarding
|
|
5
|
-
// code. Falls back to `uv tool run
|
|
6
|
-
//
|
|
4
|
+
// Thin launcher: exec the exact uv-installed `memorizz`, forwarding
|
|
5
|
+
// argv/stdio/exit code. Falls back to `uv tool run` with the pinned package
|
|
6
|
+
// specification when the managed binary is missing or stale.
|
|
7
7
|
"use strict";
|
|
8
8
|
|
|
9
9
|
const { spawnSync } = require("child_process");
|
|
@@ -12,6 +12,17 @@ const path = require("path");
|
|
|
12
12
|
const fs = require("fs");
|
|
13
13
|
const VERSION = require("../package.json").version;
|
|
14
14
|
const PACKAGE_SPEC = `memorizz[mcp]==${VERSION}`;
|
|
15
|
+
const EXPECTED_VERSION = `memorizz ${VERSION}`;
|
|
16
|
+
|
|
17
|
+
function realpath(value) {
|
|
18
|
+
try {
|
|
19
|
+
return fs.realpathSync(value);
|
|
20
|
+
} catch (_) {
|
|
21
|
+
return path.resolve(value);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const LAUNCHER_PATH = realpath(__filename);
|
|
15
26
|
|
|
16
27
|
function findExe(name) {
|
|
17
28
|
const finder = process.platform === "win32" ? "where" : "which";
|
|
@@ -28,19 +39,52 @@ function findExe(name) {
|
|
|
28
39
|
return null;
|
|
29
40
|
}
|
|
30
41
|
|
|
42
|
+
function uvToolBinDir(uv) {
|
|
43
|
+
const result = spawnSync(uv, ["tool", "dir", "--bin"], {
|
|
44
|
+
encoding: "utf8",
|
|
45
|
+
});
|
|
46
|
+
if (result.status !== 0 || !result.stdout.trim()) return null;
|
|
47
|
+
return result.stdout.trim().split(/\r?\n/).pop();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function isExpectedCli(candidate) {
|
|
51
|
+
if (!candidate || !fs.existsSync(candidate)) return false;
|
|
52
|
+
if (realpath(candidate) === LAUNCHER_PATH) return false;
|
|
53
|
+
const result = spawnSync(candidate, ["--version"], { encoding: "utf8" });
|
|
54
|
+
return result.status === 0 && result.stdout.trim() === EXPECTED_VERSION;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function findUvManagedCli(uv) {
|
|
58
|
+
const binDir = uvToolBinDir(uv);
|
|
59
|
+
if (!binDir) return null;
|
|
60
|
+
const executable = process.platform === "win32" ? "memorizz.exe" : "memorizz";
|
|
61
|
+
const candidate = path.join(binDir, executable);
|
|
62
|
+
return isExpectedCli(candidate) ? candidate : null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function findCompatibleCliOnPath() {
|
|
66
|
+
const executable = process.platform === "win32" ? "memorizz.exe" : "memorizz";
|
|
67
|
+
for (const directory of (process.env.PATH || "").split(path.delimiter)) {
|
|
68
|
+
if (!directory) continue;
|
|
69
|
+
const candidate = path.join(directory, executable);
|
|
70
|
+
if (isExpectedCli(candidate)) return candidate;
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
|
|
31
75
|
const args = process.argv.slice(2);
|
|
32
|
-
const
|
|
76
|
+
const uv = findExe("uv");
|
|
77
|
+
const exe = (uv && findUvManagedCli(uv)) || findCompatibleCliOnPath();
|
|
33
78
|
|
|
34
79
|
let res;
|
|
35
80
|
if (exe) {
|
|
36
81
|
res = spawnSync(exe, args, { stdio: "inherit" });
|
|
37
82
|
} else {
|
|
38
|
-
const uv = findExe("uv");
|
|
39
83
|
if (!uv) {
|
|
40
84
|
process.stderr.write(
|
|
41
|
-
|
|
85
|
+
`[memorizz] MemoRizz ${VERSION} is not installed and uv was not found.\n` +
|
|
42
86
|
" Try: npm rebuild -g memorizz (re-runs the bootstrapper)\n" +
|
|
43
|
-
|
|
87
|
+
` Or: uv tool install '${PACKAGE_SPEC}'\n`
|
|
44
88
|
);
|
|
45
89
|
process.exit(127);
|
|
46
90
|
}
|
package/package.json
CHANGED