feat(npm): restart stale tsmd on package upgrade#9
Merged
Conversation
Adds a postinstall script to the npm wrapper that SIGTERMs any running tsmd on darwin so the next `tsm` invocation picks up the freshly installed binary via EnsureRunning. No respawn, no pidfile, no JSON-RPC dependency. Two pgrep passes: a path-strict pass against the new tsmd's absolute path, plus a permissive owned-pid pass (`pgrep -u $USER -f 'tsmd( |$)'`) to catch cross-prefix upgrades like Homebrew to npm. EPERM is downgraded to a warning, ESRCH is silent, and any other error keeps the install succeeding. Refactored as small functions (resolveTsmdPath, findRunningTsmdPids, stopPids, main) with injectable dependencies so node:test can cover every branch without spawning real processes. Closes #5
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
postinstallscript to the npm wrapper that SIGTERMs any running tsmd on darwin so the nexttsmcommand picks up the new binary.Closes #5
Implementation notes
resolveTsmdPath,findRunningTsmdPids,stopPids,main) with injectable deps (requireResolve,execFileSync,process.kill) sonode:testcovers every branch without spawning real processes.if (require.main === module) main()keepsrequire()side-effect-free for the test harness.EPERMonkill(daemon owned by another user after a straysudo) downgrades to a warning, never fails the install.ESRCHswallowed silently (race betweenpgrepandkill). Unknown error codes are warned but still non-fatal.package.jsonfileslistsscripts/postinstall.jsexplicitly so the test file (scripts/postinstall.test.js) is not shipped in the published tarball.npm/wrapper/README.mdnotes the upgrade behavior and the--ignore-scriptsopt-out.RELEASING.mdgets a one-liner about the postinstall.Deferred
ci.ymlwith a Node test step is a follow-up. The unit tests are runnable today vianode --test npm/wrapper/scripts/postinstall.test.js.npm install -g .smoke test) is deferred to manual verification by the maintainer, per the task constraints (do not mutate the user's global npm prefix from automation).Test plan
node --test npm/wrapper/scripts/postinstall.test.jspasses (16/16)npm pack --dry-runfromnpm/wrapper/includesscripts/postinstall.jsand excludes the test filetsm status(spawn daemon) →cd npm/wrapper && npm install -g .→pgrep -fl tsmdempty →tsm statusrespawns