//#region src/runtime/detect.d.ts /** * Auto-detects the current JavaScript runtime environment. * * Uses `globalThis` feature detection (version globals) to identify * the runtime without importing platform-specific modules. This is * the recommended approach because each runtime defines a unique * global marker: * * - **Bun:** `globalThis.Bun.version` (string) * - **Deno:** `globalThis.Deno.version` (object with `deno` key) * - **Node:** `globalThis.process.versions.node` (string) * * Detection order matters: Bun provides a Node-compatible `process` * global, so it must be checked *before* Node to avoid misidentification. * * @module @kjanat/dreamcli/runtime/detect */ /** * Known JavaScript runtime environments. * * - `'node'` — Node.js * - `'bun'` — Bun * - `'deno'` — Deno * - `'unknown'` — Unrecognized environment */ type Runtime = 'node' | 'bun' | 'deno' | 'unknown'; /** * All known runtime values as a readonly tuple. * * Useful for validation, iteration, and exhaustiveness checks. * * @example * ```ts * if (RUNTIMES.includes(value)) { * // value is a valid Runtime * } * ``` */ declare const RUNTIMES: readonly ['node', 'bun', 'deno', 'unknown']; /** * Minimal `globalThis` shape used for runtime detection. * * Each field is optional — only the present one identifies the runtime. * Typed as `unknown` where we only need truthiness; version fields are * typed just enough to distinguish runtimes safely. */ interface GlobalForDetect { /** Present when running on Bun. */ readonly Bun?: { readonly version?: string; }; /** Present when running on Deno. */ readonly Deno?: { readonly version?: { readonly deno?: string; }; }; /** Present on Node.js (and Bun, which mimics it). */ readonly process?: { readonly versions?: { readonly node?: string; readonly bun?: string; }; }; } /** * Detect the current JavaScript runtime. * * Uses `globalThis` feature detection to identify the host runtime. * Detection order is significant: Bun is checked before Node because * Bun exposes a Node-compatible `process` global. * * @param globals - Override `globalThis` for testing. Production callers * should omit this parameter. * @returns The detected {@link Runtime} identifier. * * @example * ```ts * const rt = detectRuntime(); * // rt === 'node' | 'bun' | 'deno' | 'unknown' * ``` */ declare function detectRuntime(globals?: GlobalForDetect): Runtime; //#endregion export { type GlobalForDetect, RUNTIMES, type Runtime, detectRuntime };