feat(update): perchd update + opt-in background auto-update#6
Draft
irwansetiawan wants to merge 1 commit into
Draft
feat(update): perchd update + opt-in background auto-update#6irwansetiawan wants to merge 1 commit into
irwansetiawan wants to merge 1 commit into
Conversation
`perchd update` updates perchd in place using the package manager that installed it (npm/pnpm/bun), detected from the running binary's path — so it never installs a second, shadowing copy in a different global prefix. Foreground + inherited stdio, so a sudo-needing system-node install surfaces its own error. Opt-in `PERCHD_AUTO_UPDATE=1` (default off): the existing once-a-day detached __update-check, after caching, installs a newer version silently — applied on the next run, never hot-swapping the live process. Fail-silent, so an unwritable/sudo install just no-ops and the notice persists. The notice now points at `perchd update` (or says it's auto-updating when the flag is on) instead of a raw npm string. The current version rides along in the __update-check argv so the child can compare without re-reading package.json.
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.
What
Answers "can perchd auto-update?" — yes, two tiers:
perchd update— explicit, always-safe in-place update.PERCHD_AUTO_UPDATE=1(default off).Why manager-aware
npm i -g,pnpm add -g, andbun add -ginstall into different global prefixes. If perchd was installed with pnpm/bun and we blindly rannpm i -g perchd@latest, npm would create a second, shadowing copy and never update the real one. So the updater sniffs the manager from the running binary's path (/.bun/→bun,/pnpm/or$PNPM_HOME→pnpm, else npm) and runs the matching command.Behavior
perchd updateruns in the foreground with inherited stdio — a sudo-needing (system-node) install surfaces its own error so you can re-run. Reports which manager it used.__update-checkprocess: after caching the latest version, if opted in and behind, it installs silently and the new version applies on your next run (never hot-swaps the live process). Fail-silent — an unwritable/sudo install just no-ops and the notice keeps showing, so it can't brick or block.perchd update(or saysAuto-updating in the background …when the flag is on) instead of a rawnpm i -gstring.Default-off is deliberate: silently mutating a user-installed binary is surprising, and install methods can be ambiguous (symlinked dev checkouts). Opt-in keeps it safe.
Tests / verification
TDD — 11 new unit tests (
detectManagernpm/pnpm/bun,updateCommand,autoUpdateEnabled, reworded notice + auto variant,runUpdateCheckauto-update on/off/up-to-date,runUpdatecommand). Full suite green (156 passed), typecheck clean.Verified end-to-end against the built binary with stubbed package managers:
perchd update→ detects npm, runsnpm install -g perchd@latest, reports success.Run: perchd update(manual) vsAuto-updating in the background …(opt-in).__update-check 0.1.0withPERCHD_AUTO_UPDATE=1→ invokes the install; without the flag → does not.