Lines 1-45javascript
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/npx-run-guard.test.ts,
3// packages/daemon/src/update/package-root-paths.test.ts, packages/daemon/src/update/self-update.test.ts
6 * Self-update mechanism for the Telora daemon.
8 * Handles the full update lifecycle:
9 * 1. Detect installation mode (npm global, npx cache, or git source)
10 * 2. Dependency-ordered rebuild chain for git source mode
11 * 3. Pre-update snapshot for rollback
12 * 4. Update orchestration (stop engines, update, restart)
13 * 5. Version check and up-to-date detection
14 * 6. Migration auto-apply after update
16 * Three installation modes:
17 * - **npm**: Installed globally via `npm install -g @telora/daemon`.
18 * Updates via `npm install -g @telora/daemon@latest`.
19 * - **npx**: Running from an ephemeral npx cache (`~/.npm/_npx/<hash>/`).
20 * Self-update can't replace the running binary in place. The update path
21 * clears the npx cache and instructs the user to re-run via `npx`, which
22 * will then fetch the latest version. Auto-update is disabled.
23 * - **git**: Running from a git checkout (development mode).
24 * Updates via `git pull` + dependency-ordered rebuild.
26import { execFileSync, execFile } from 'node:child_process';
27import { 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 · L16 HighChild Process
Package source references child process execution.
dist/update/self-update.jsView on unpkg · L25 28import { dirname, resolve, join } from 'node:path';
29import { fileURLToPath } from 'node:url';
30import { checkForUpdates } from './version-check.js';
31import { createLogger } from '../shell/log.js';
32import { loadEnvConfig } from '@telora/daemon-core';
33const log = createLogger({ module: 'self-update' });
34// ---------------------------------------------------------------------------
35// Installation mode detection (TEL-1)
36// ---------------------------------------------------------------------------
38 * Detect whether the daemon is running from an npm global install,
39 * an ephemeral npx cache, or a git source checkout.
41 * Heuristics (in order):
42 * - Path contains `/_npx/` -> npx mode (ephemeral cache).
43 * - Source directory contains a `.git` directory (or a parent does) -> git mode.
44 * - Otherwise -> npm mode (global install, project node_modules, etc.).