Skip to content

feat: update notifier — warn when perchd is outdated#4

Merged
irwansetiawan merged 2 commits into
mainfrom
feat/update-notifier
Jul 12, 2026
Merged

feat: update notifier — warn when perchd is outdated#4
irwansetiawan merged 2 commits into
mainfrom
feat/update-notifier

Conversation

@irwansetiawan

Copy link
Copy Markdown
Owner

On each run, if the installed perchd is behind npm's latest, print a one-line notice:

⚠ Your perchd version 0.5.0 is outdated. Latest is 0.6.0.
  Update with: npm i -g perchd@latest

Design — never delay a command, never corrupt output

Mirrors update-notifier: the notice reflects the previous background check; the hot path is one small file read.

  • Async, off the hot path. A stale cache (>24h) triggers a detached, unref'd perchd __update-check (hidden argv branch, handled before cac) that fetches the registry and writes $XDG_CACHE_HOME/perchd/update-check.json. The current command never awaits the network; the result shows next time.
  • Off stdout — load-bearing. The notice goes to stderr, and the whole feature is skipped when stdout isn't a TTY. perchd path is read via $(...) in the shell cd function, so a notice on stdout would corrupt it. Verified: p=$(perchd path main) stays clean.
  • Fail-silent + quiet where it should be. Offline / 404 / timeout leaves the cache untouched (no crash). Skipped under CI, NO_UPDATE_NOTIFIER=1, and pnpm dev (running from source).
  • No new dependency — native fetch (Node 20) to registry.npmjs.org/perchd/latest.

Files

  • src/core/update.tsisNewer, updateNotice, cache read/write, isStale, runUpdateCheck (injectable fetcher), refreshInBackground, maybeNotifyUpdate, updateCheckSuppressed.
  • src/cli.ts — hidden __update-check branch + one maybeNotifyUpdate(version) call.

Verification

  • pnpm typecheck clean · pnpm test 135/135 (10 new unit tests).
  • Drove the real binary end-to-end with a temp XDG_CACHE_HOME: real registry fetch writes the cache; a seeded "outdated" cache prints the notice (via pty); perchd path stdout stays clean; a stale cache triggers the detached refresh that advances checkedAt and pulls latest from the registry after the parent exits; and it correctly stays silent when you're ahead of latest.

Release

Additive, non-breaking. Filed under [Unreleased] in the CHANGELOG — no version bump here; it'll ride whatever you publish next (0.5.0 is still unpublished).

On each run, print a one-line notice if the installed version is behind npm's
latest. The check never delays a command: the notice reflects the previous
check, and a stale cache (>24h) triggers a detached, unref'd `perchd
__update-check` that fetches the registry and writes ~/.cache/perchd. Notice goes
to stderr and the whole feature is skipped when stdout isn't a TTY, so it can't
corrupt `perchd path` in the shell cd function. Off under CI/NO_UPDATE_NOTIFIER/
pnpm dev. Native fetch, no new dependency.
@irwansetiawan
irwansetiawan merged commit fe5f622 into main Jul 12, 2026
4 checks 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