feat(npm): restart stale tsmd in the shim, not postinstall#12
Merged
Conversation
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.
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
postinstallonbun install -g @tashian/tsm(no consumerpackage.jsonfortrustedDependenciesto apply), so the postinstall added in feat(npm): restart stale tsmd on package upgrade #9 never ran and the pre-upgradetsmdkept owning the socket.shim.js: on everytsminvocation, pgrep + ps for anytsmdwhose argv[0] differs fromTSM_TSMD_BIN, SIGTERM it, then exec the newtsm. Go'sEnsureRunningrespawns the new daemon at the right prefix.npm/wrapper/scripts/postinstall.{js,test.js}and thescripts.postinstallentry inpackage.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 passgo test ./...— all packages pass~/.local/bin/tsmd, rantsm statusvia the bun-installed wrapper, observed the stale pid die and a fresh daemon respawn at the bun prefixtsmcommand picks up the new binary