@xyrlan/mnemo 0.13.2 → 0.13.3

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 CHANGED
@@ -39,12 +39,10 @@ function runShell(cmd, { quiet = false } = {}) {
39
39
 
40
40
 
41
41
  function verifyOnPath() {
42
- try {
43
- execSync("mnemo --version", { stdio: "ignore" });
44
- return true;
45
- } catch (_e) {
46
- return false;
47
- }
42
+ const { resolveMnemoBinary } = require("./runMnemo");
43
+ const path = require("node:path");
44
+ const selfBinDir = process.argv[1] ? path.dirname(process.argv[1]) : null;
45
+ return Boolean(resolveMnemoBinary({ selfBinDir }));
48
46
  }
49
47
 
50
48
 
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,32 @@ function buildUninstallArgs({ scope, quiet, yes = true }) {
22
24
  }
23
25
 
24
26
 
25
- function runMnemo(args, { quiet = false } = {}) {
26
- const result = spawnSync("mnemo", args, { stdio: quiet ? "ignore" : "inherit" });
27
+ // Resolve the real Python `mnemo` entry point, skipping the npx-injected
28
+ // wrapper bin so spawnSync doesn't recurse into us.
29
+ // `selfBinDir` defaults to the directory of the currently executing
30
+ // wrapper (process.argv[1]); override for testing.
31
+ function resolveMnemoBinary({ env = process.env, platform = process.platform, selfBinDir } = {}) {
32
+ const exeName = platform === "win32" ? "mnemo.exe" : "mnemo";
33
+ const sep = platform === "win32" ? ";" : ":";
34
+ const rawPath = (env.PATH || env.Path || "").split(sep);
35
+ const skip = new Set();
36
+ if (selfBinDir) skip.add(path.resolve(selfBinDir));
37
+ return rawPath
38
+ .filter((dir) => dir && !skip.has(path.resolve(dir)) && !/[\\/]_npx[\\/]/.test(dir))
39
+ .map((dir) => path.join(dir, exeName))
40
+ .find((candidate) => {
41
+ try { return fs.statSync(candidate).isFile(); }
42
+ catch (_e) { return false; }
43
+ }) || null;
44
+ }
45
+
46
+
47
+ function runMnemo(args, { quiet = false, selfBinDir } = {}) {
48
+ const bin = resolveMnemoBinary({ selfBinDir: selfBinDir || (process.argv[1] && path.dirname(process.argv[1])) });
49
+ const target = bin || "mnemo";
50
+ const result = spawnSync(target, args, { stdio: quiet ? "ignore" : "inherit" });
27
51
  return result.status === null ? 1 : result.status;
28
52
  }
29
53
 
30
54
 
31
- module.exports = { buildInitArgs, buildUninstallArgs, runMnemo };
55
+ module.exports = { buildInitArgs, buildUninstallArgs, runMnemo, resolveMnemoBinary };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyrlan/mnemo",
3
- "version": "0.13.2",
3
+ "version": "0.13.3",
4
4
  "description": "One-command installer for mnemo (the Obsidian that populates itself).",
5
5
  "bin": {
6
6
  "mnemo": "bin/mnemo.js"