Lines 1-47javascript
1// PINNED-BY-BEGIN (generated by gen:pinned-by -- do not hand-edit; checked by lint:pinned-by)
2// Pinned by: packages/daemon/src/update/auto-update.test.ts,
3// packages/daemon/src/update/npx-run-guard.test.ts, packages/daemon/src/update/package-root-paths.test.ts,
4// packages/daemon/src/update/self-update.test.ts
7 * Self-update mechanism for the Telora daemon.
9 * Handles the full update lifecycle:
10 * 1. Detect installation mode (npm global, npx cache, or git source)
11 * 2. Dependency-ordered rebuild chain for git source mode
12 * 3. Pre-update snapshot for rollback
13 * 4. Update orchestration (stop engines, update, restart)
14 * 5. Version check and up-to-date detection
15 * 6. Migration auto-apply after update
17 * Three installation modes:
18 * - **npm**: Installed globally via `npm install -g @telora/daemon`.
19 * Updates via `npm install -g --@telora:registry=<channel> @telora/daemon@latest`
20 * (the update channel: npmjs unless TELORA_REGISTRY_URL overrides it).
21 * - **npx**: Running from an ephemeral npx cache (`~/.npm/_npx/<hash>/`).
22 * Self-update can't replace the running binary in place. The update path
23 * clears the npx cache and instructs the user to re-run via `npx`, which
24 * will then fetch the latest version. Auto-update is disabled.
25 * - **git**: Running from a git checkout (development mode).
26 * Updates via `git pull` + dependency-ordered rebuild.
28import { execFileSync, execFile } from 'node:child_process';
29import { existsSync, readFileSync, writeFileSync, mkdirSync, rmSync } from 'node:fs';
HighRuntime Package Install
Package source invokes a package manager install command at runtime.
dist/update/self-update.jsView on unpkg · L17 HighChild Process
Package source references child process execution.
dist/update/self-update.jsView on unpkg · L27 30import { dirname, resolve, join } from 'node:path';
31import { fileURLToPath } from 'node:url';
32import { checkForUpdates, resolveUpdateChannelUrl, scopedInstallArgs, scopedInstallCommand, } from './version-check.js';
33import { createLogger } from '../shell/log.js';
34import { loadEnvConfig } from '@telora/daemon-core';
35const log = createLogger({ module: 'self-update' });
36// ---------------------------------------------------------------------------
37// Installation mode detection (TEL-1)
38// ---------------------------------------------------------------------------
40 * Detect whether the daemon is running from an npm global install,
41 * an ephemeral npx cache, or a git source checkout.
43 * Heuristics (in order):
44 * - Path contains `/_npx/` -> npx mode (ephemeral cache).
45 * - Source directory contains a `.git` directory (or a parent does) -> git mode.
46 * - Otherwise -> npm mode (global install, project node_modules, etc.).