Skip to content

feat(update): perchd update + opt-in background auto-update#6

Draft
irwansetiawan wants to merge 1 commit into
mainfrom
feat/self-update
Draft

feat(update): perchd update + opt-in background auto-update#6
irwansetiawan wants to merge 1 commit into
mainfrom
feat/self-update

Conversation

@irwansetiawan

Copy link
Copy Markdown
Owner

What

Answers "can perchd auto-update?" — yes, two tiers:

  1. perchd update — explicit, always-safe in-place update.
  2. Opt-in background auto-update via PERCHD_AUTO_UPDATE=1 (default off).

Why manager-aware

npm i -g, pnpm add -g, and bun add -g install into different global prefixes. If perchd was installed with pnpm/bun and we blindly ran npm 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 update runs 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.
  • Auto-update reuses the existing detached, once-a-day __update-check process: 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.
  • The update notice now points at perchd update (or says Auto-updating in the background … when the flag is on) instead of a raw npm i -g string.

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 (detectManager npm/pnpm/bun, updateCommand, autoUpdateEnabled, reworded notice + auto variant, runUpdateCheck auto-update on/off/up-to-date, runUpdate command). Full suite green (156 passed), typecheck clean.

Verified end-to-end against the built binary with stubbed package managers:

  • perchd update → detects npm, runs npm install -g perchd@latest, reports success.
  • Notice: Run: perchd update (manual) vs Auto-updating in the background … (opt-in).
  • __update-check 0.1.0 with PERCHD_AUTO_UPDATE=1 → invokes the install; without the flag → does not.

`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.
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