/** * Updating without being asked to. * * `/update` has always been there, and almost nobody runs it. The version people are on is * whatever they installed the day they installed it, which means every fix in this file's * neighbourhood reaches them only if they happen to think of looking. Asked for directly, with a * screenshot of another tool doing it: install quietly in the background, then say so in one line * โ€” "Update installed ยท Restart to update". * * The restart is the honest part of that sentence. A running Node process has its code in memory; * replacing the files on disk changes nothing about the session already underway, and pretending * otherwise would be worse than saying nothing. So the new version is put in place and the line * says exactly what is true: it is installed, and it takes effect next time. * * What this must never do is surprise somebody. It only ever touches an installation it can see * is a global npm one; it refuses point blank to run against a git checkout or a linked * development copy, where overwriting is not an upgrade but a loss of work; it runs at most once * a day; and `autoUpdate: false` turns it off entirely. */ export type AutoUpdateOutcome = { state: 'installed'; version: string; } | { state: 'skipped'; reason: string; } | { state: 'failed'; reason: string; }; interface AutoUpdateState { attemptedAt: number; /** The version installed, so a session that starts after it can still mention the restart. */ installed?: string; /** What went wrong, kept only to avoid hammering a broken setup. */ failed?: string; } /** * Whether this copy is one that `npm install -g` can safely replace. * * The test is the path it is running from. A global install lives under `node_modules/koneck`, * and replacing those files is exactly what an upgrade is. A checkout does not, and running the * installer against one would either do nothing or quietly shadow the very code being worked on * โ€” the sort of thing that is only noticed an hour later. `npm link` also produces a path under * `node_modules`, but through a symlink, so the real path is resolved before this is asked. * * Pure, and takes the path, so every branch can be checked without installing anything anywhere. */ export declare function canSelfUpdate(modulePath: string): { ok: boolean; reason?: string; }; /** Whether enough time has passed since the last attempt to make another one reasonable. */ export declare function dueForAttempt(state: AutoUpdateState | null, now: number): boolean; /** * Check, and install if there is something newer. * * Returns what happened rather than throwing: this runs in the background of somebody else's * session, and nothing it discovers is worth interrupting them over except success. */ export declare function autoUpdate(opts: { currentVersion: string; modulePath: string; enabled: boolean; /** Injected so the whole path can be driven in a test without touching the network or npm. */ latest?: (current: string) => Promise; install?: (version: string) => Promise<{ ok: boolean; output: string; }>; now?: () => number; /** * Where the last attempt is remembered. Injected so the throttle can be exercised without * every test in the file inheriting the previous one's state through the real home directory * โ€” which is exactly what happened the first time these were written. */ statePath?: string; }): Promise; export {}; //# sourceMappingURL=auto-update.d.ts.map