@swmansion/argent 0.14.1-next.2 → 0.14.1-next.21

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.
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swmansion/argent",
3
- "version": "0.14.1-next.2",
3
+ "version": "0.14.1-next.21",
4
4
  "description": "MCP server for iOS Simulator and Android Emulator control",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -8,20 +8,66 @@ const os = require("os");
8
8
  const fs = require("fs");
9
9
  const path = require("path");
10
10
 
11
- // Always kill any running tool-server so the new binary takes effect on next use.
12
- const stateFile = path.join(os.homedir(), ".argent", "tool-server.json");
11
+ // Kill the running tool-server so the freshly-installed binary takes effect on
12
+ // next use but ONLY when the tracked server belongs to THIS package's bundle.
13
+ // A repo-local devDependency install of argent must not tear down a tool-server
14
+ // spawned by a *different* install (another project's local copy, or the global
15
+ // binary) that an unrelated editor session is actively using.
16
+ //
17
+ // State records are per-install files (tool-server-<hash>.json) plus the legacy
18
+ // single-slot tool-server.json written by older versions — scan them all rather
19
+ // than reproducing the launcher's hash.
20
+ const stateDir = path.join(os.homedir(), ".argent");
21
+ const ownBundlePath = path.resolve(__dirname, "..", "dist", "tool-server.cjs");
22
+
23
+ function sameBundle(recorded) {
24
+ if (!recorded) return false;
25
+ if (path.resolve(recorded) === ownBundlePath) return true;
26
+ // Tolerate symlinked install layouts (npm global prefix, pnpm store) where the
27
+ // recorded path and our __dirname resolve to the same real file.
28
+ try {
29
+ return fs.realpathSync(recorded) === fs.realpathSync(ownBundlePath);
30
+ } catch {
31
+ return false;
32
+ }
33
+ }
34
+
35
+ function shouldKill(recorded) {
36
+ if (!recorded) return false;
37
+ if (sameBundle(recorded)) return true;
38
+ // A recorded bundle whose file is GONE can never serve again: pnpm/yarn
39
+ // global layouts keep the package in a version-pinned dir, so an upgrade
40
+ // replaces the dir instead of rewriting it in place and sameBundle never
41
+ // matches. No live install's server can be running from a nonexistent
42
+ // path, so retiring it is safe for every other session.
43
+ try {
44
+ fs.accessSync(recorded);
45
+ return false;
46
+ } catch {
47
+ return true;
48
+ }
49
+ }
50
+
13
51
  try {
14
- const state = JSON.parse(fs.readFileSync(stateFile, "utf8"));
15
- if (state && state.pid) {
52
+ for (const name of fs.readdirSync(stateDir)) {
53
+ if (!/^tool-server(-[0-9a-f]{12})?\.json$/.test(name)) continue;
54
+ const stateFile = path.join(stateDir, name);
16
55
  try {
17
- process.kill(state.pid, "SIGTERM");
56
+ const state = JSON.parse(fs.readFileSync(stateFile, "utf8"));
57
+ if (state && state.pid && shouldKill(state.bundlePath)) {
58
+ try {
59
+ process.kill(state.pid, "SIGTERM");
60
+ } catch {
61
+ /* process already gone — nothing to kill */
62
+ }
63
+ fs.unlinkSync(stateFile);
64
+ }
18
65
  } catch {
19
- /* process already gone nothing to kill */
66
+ /* unreadable recordleave it alone */
20
67
  }
21
68
  }
22
- fs.unlinkSync(stateFile);
23
69
  } catch {
24
- /* no state file or unreadable — nothing to clean up */
70
+ /* no state dir — nothing to clean up */
25
71
  }
26
72
 
27
73
  // node-pty (optional dep, used by `argent lens`'s agent PTY proxy) ships its