@todoforai/update-notifier
v0.4.0
Published
Zero-dep, cached update notifier for TODOforAI CLIs
Downloads
980
Readme
@todoforai/update-notifier
Zero-dep update notifier and self-updater used by TODOforAI CLIs.
import { checkForUpdates, autoUpdate, selfUpdate } from "@todoforai/update-notifier";
import pkg from "../package.json" with { type: "json" };
checkForUpdates(pkg); // just print "update available" (fire-and-forget)
backgroundUpdate(pkg); // short-lived CLIs: detached install, next run is updated
autoUpdate(pkg); // long-running daemons: install newer version at startup
await selfUpdate(pkg); // `<cli> update` command: query registry, install, report- Cached for 24h under
~/.config/todoforai/notifier-<pkg>.json - Silent on CI / non-TTY / when
NO_UPDATE_NOTIFIERis set / when running from abun link/npm linksource checkout - Registry fetch runs in background with a 3s timeout
autoUpdate(pkg)
Non-blocking: decides from the cached version, so an offline or slow registry
never delays startup (a fresh release lands on the run after the background
refresh picks it up). On update it runs npm i -g <pkg>@<latest> and re-execs
the process with the same args; the child gets TODOFORAI_NO_AUTO_UPDATE=1 to
rule out update loops. No-op for linked checkouts and standalone binaries.
backgroundUpdate(pkg)
For short-lived CLIs. Never blocks: reads the 24h cache and, if a newer version
is known, spawns a detached npm i -g <pkg>@<latest> (or bun add -g) and
returns. Each version is tried once; if the install didn't land (e.g. global
prefix needs sudo) the normal "Update available" banner is shown instead.
selfUpdate(pkg)
User-initiated (<cli> update): queries the registry directly (10s), installs,
prints the outcome, returns true if a new version was installed. No re-exec.
