Skip to content

feat(npm): restart stale tsmd in the shim, not postinstall#12

Merged
tashian merged 1 commit into
mainfrom
feat/shim-restart-stale-tsmd
May 5, 2026
Merged

feat(npm): restart stale tsmd in the shim, not postinstall#12
tashian merged 1 commit into
mainfrom
feat/shim-restart-stale-tsmd

Conversation

@tashian

@tashian tashian commented May 5, 2026

Copy link
Copy Markdown
Owner

Summary

  • Bun silently skips postinstall on bun install -g @tashian/tsm (no consumer package.json for trustedDependencies to apply), so the postinstall added in feat(npm): restart stale tsmd on package upgrade #9 never ran and the pre-upgrade tsmd kept owning the socket.
  • Move the restart logic into shim.js: on every tsm invocation, pgrep + ps for any tsmd whose argv[0] differs from TSM_TSMD_BIN, SIGTERM it, then exec the new tsm. Go's EnsureRunning respawns the new daemon at the right prefix.
  • Reverts npm/wrapper/scripts/postinstall.{js,test.js} and the scripts.postinstall entry in package.json. The shim is now the single point of staleness handling and works under npm, bun, and pnpm.

Test plan

  • node --test npm/wrapper/scripts/*.test.js — 13/13 pass
  • go test ./... — all packages pass
  • End-to-end: spawned stale tsmd at ~/.local/bin/tsmd, ran tsm status via the bun-installed wrapper, observed the stale pid die and a fresh daemon respawn at the bun prefix
  • Manual: install via bun on a clean machine with a previously-installed tsmd from another prefix; confirm the next tsm command picks up the new binary

Bun silently skips lifecycle scripts on global installs (no consumer
package.json for trustedDependencies to apply), so the postinstall
added in af4b56d never ran for `bun install -g @tashian/tsm` and a
pre-upgrade tsmd kept owning the socket. Move the restart logic into
shim.js, where it runs on every `tsm` invocation: pgrep + ps for any
tsmd whose argv[0] differs from TSM_TSMD_BIN, SIGTERM, then exec the
new tsm. Go's EnsureRunning respawns the new daemon at the right path.

The previous postinstall.js and its tests are removed; the shim is now
the single point of staleness handling and works under npm, bun, pnpm.

Tests: 13 node:test cases covering pgrep/ps parsing, path comparison,
race tolerance (process exits between pgrep and ps), and SIGTERM error
swallowing (ESRCH/EPERM). Verified end-to-end by spawning a stale
tsmd at a non-bun prefix, running tsm via the bun wrapper, and watching
the stale pid die and a fresh daemon respawn at the bun prefix.
@tashian tashian merged commit 0028308 into main May 5, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant