memtrace 0.3.9 → 0.3.10

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 (2) hide show
  1. package/install.js +44 -1
  2. package/package.json +4 -4
package/install.js CHANGED
@@ -41,10 +41,53 @@ function getBinaryPath() {
41
41
  }
42
42
  }
43
43
 
44
+ // ── Optional-dep self-heal ───────────────────────────────────────────────────
45
+ //
46
+ // `optionalDependencies` is supposed to fan out platform binaries
47
+ // automatically. In practice some npm configs (npm 11 strict modes,
48
+ // CI caches with `--omit=optional`, corporate `omit=optional` in
49
+ // global config) drop the platform package silently. The user then
50
+ // runs `memtrace start` and gets "Could not find binary for X".
51
+ //
52
+ // Fallback: detect the missing platform package during postinstall
53
+ // and `npm install` it directly into our own node_modules dir. The
54
+ // versioned name comes from the same map the runtime resolver uses.
55
+ function selfHealPlatformPackage() {
56
+ const key = getPlatformKey();
57
+ const pkg = PLATFORM_MAP[key];
58
+ if (!pkg) return; // unsupported platform — getBinaryPath will surface it later
59
+ try {
60
+ require.resolve(`${pkg}/package.json`);
61
+ return; // already installed via optionalDependencies
62
+ } catch (_) {
63
+ // not installed — fall through to install
64
+ }
65
+ const ourPkg = require("./package.json");
66
+ const versioned = `${pkg}@${ourPkg.version}`;
67
+ console.log(
68
+ `memtrace: optional platform dep ${pkg} was not installed; ` +
69
+ `running 'npm install ${versioned}' to fetch it…`
70
+ );
71
+ const result = spawnSync(
72
+ process.platform === "win32" ? "npm.cmd" : "npm",
73
+ ["install", "--no-save", versioned],
74
+ { cwd: __dirname, stdio: "inherit", env: process.env }
75
+ );
76
+ if (result.status !== 0) {
77
+ console.warn(
78
+ `memtrace: self-heal install of ${versioned} failed (exit ${result.status}). ` +
79
+ `Run manually: npm install -g memtrace --include=optional`
80
+ );
81
+ }
82
+ }
83
+
44
84
  // ── Main postinstall ─────────────────────────────────────────────────────────
45
85
 
46
86
  if (require.main === module) {
47
- // 1. Verify binary exists + is executable
87
+ // 1. Verify binary exists + is executable. If the optional platform
88
+ // dep was silently omitted by npm, fetch it directly.
89
+ selfHealPlatformPackage();
90
+
48
91
  let binaryPath = null;
49
92
  try {
50
93
  binaryPath = getBinaryPath();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "memtrace",
3
- "version": "0.3.9",
3
+ "version": "0.3.10",
4
4
  "description": "Code intelligence graph — MCP server + AI agent skills + visualization UI",
5
5
  "keywords": [
6
6
  "mcp",
@@ -36,9 +36,9 @@
36
36
  "fs-extra": "^11.0.0"
37
37
  },
38
38
  "optionalDependencies": {
39
- "@memtrace/darwin-arm64": "0.3.9",
40
- "@memtrace/linux-x64": "0.3.9",
41
- "@memtrace/win32-x64": "0.3.9"
39
+ "@memtrace/darwin-arm64": "0.3.10",
40
+ "@memtrace/linux-x64": "0.3.10",
41
+ "@memtrace/win32-x64": "0.3.10"
42
42
  },
43
43
  "engines": {
44
44
  "node": ">=18"