import { n as RuntimeAdapter } from "./adapter-D0hbBNVB.mjs"; //#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 //#region src/runtime/auto.d.ts /** * Create a runtime adapter for the current environment. * * Detection order follows {@link detectRuntime}: Bun → Deno → Node → unknown. * Only Deno needs a distinct adapter; Bun, Node, and unknown runtimes all use * the Node adapter because they expose a Node-compatible `process` global. * * @param globals - Override `globalThis` for testing. Production callers * should omit this parameter. * @returns A {@linkcode RuntimeAdapter} for the detected runtime. * * @example * ```ts * import { cli } from '@kjanat/dreamcli'; * * // Auto-detects Node/Bun/Deno and creates the right adapter * cli('mycli').run(); // uses createAdapter() internally * ``` */ declare function createAdapter(globals?: GlobalForDetect): RuntimeAdapter; //#endregion //#region src/runtime/deno.d.ts /** * Minimal subset of the Deno namespace needed by the adapter. * * We avoid `@types/deno` to keep the core runtime-agnostic at the type level. * This interface declares only what `createDenoAdapter` actually reads. * * The `env` property is optional because it requires `--allow-env` permission. * When permission is denied, the adapter catches the error and falls back to * an empty env object. */ interface DenoNamespace { /** Build target metadata (OS detection). */ readonly build: { readonly os: 'darwin' | 'linux' | 'android' | 'windows' | 'freebsd' | 'netbsd' | 'aix' | 'solaris' | 'illumos'; }; /** Deno version info — used for minimum-version guard. */ readonly version?: { readonly deno?: string; }; /** Raw command-line args (excludes the binary/script — Deno pre-strips them). */ readonly args: readonly string[]; /** Environment variable access (requires `--allow-env`). */ readonly env: { /** Get a single env var. Returns `undefined` if unset or permission denied. */ get(key: string): string | undefined; /** Get all env vars as a plain object. Throws on permission denied. */ toObject(): Record; }; /** Current working directory (may throw if `--allow-read` is denied for cwd). */ cwd(): string; /** Standard output — synchronous byte writer with TTY detection. */ readonly stdout: { /** Write raw bytes to stdout synchronously. */ writeSync(p: Uint8Array): number; /** Whether stdout is connected to a TTY. */ isTerminal(): boolean; }; /** Current console dimensions. */ consoleSize?(): { readonly columns: number; readonly rows: number; }; /** Register a native signal listener. */ addSignalListener?(signal: 'SIGWINCH', listener: () => void): void; /** Remove a native signal listener. */ removeSignalListener?(signal: 'SIGWINCH', listener: () => void): void; /** Standard error — synchronous byte writer. */ readonly stderr: { /** Write raw bytes to stderr synchronously. */ writeSync(p: Uint8Array): number; }; /** Standard input — TTY detection and readable byte stream. */ readonly stdin: { /** Whether stdin is connected to a TTY. */ isTerminal(): boolean; /** Readable stream for stdin bytes. */ readonly readable: ReadableStream; }; /** Exit the process with the given code. */ exit(code: number): never; /** Read a file as UTF-8 text (requires `--allow-read`). */ readTextFile(path: string): Promise; /** Probe a filesystem path (requires `--allow-read`). */ stat(path: string): Promise<{ readonly isDirectory: boolean; }>; /** Create a directory (requires `--allow-write`). */ mkdir(path: string, options?: { readonly recursive?: boolean; }): Promise; } /** * Create a runtime adapter backed by the Deno namespace. * * Reads `Deno.args`, `Deno.env`, `Deno.cwd()`, and wraps Deno's stream-based * I/O into the {@linkcode WriteFn}/{@linkcode ReadFn} functions expected by the framework. * * Unlike Node/Bun, Deno strips the binary and script path from `Deno.args`. * The adapter prepends synthetic entries (`['deno', 'run']`) so the argv * shape matches the {@linkcode RuntimeAdapter} contract (binary + script + user args). * * @param ns - Override the Deno namespace (useful for testing the adapter itself). * @returns A {@linkcode RuntimeAdapter} backed by Deno's namespace APIs. * * @example * ```ts * import { cli } from '@kjanat/dreamcli'; * import { createDenoAdapter } from '@kjanat/dreamcli/runtime'; * * cli('mycli') * .command(deploy) * .run({ adapter: createDenoAdapter() }); * ``` */ declare function createDenoAdapter(ns?: DenoNamespace): RuntimeAdapter; //#endregion //#region src/runtime/node.d.ts /** * Minimal subset of the Node.js `process` object needed by the adapter. * * We avoid importing `@types/node` to keep the core runtime-agnostic * at the type level. This interface declares only what `createNodeAdapter` * actually reads from the global. */ interface NodeProcess { /** Raw process arguments (`[binary, script, ...userArgs]`). */ readonly argv: readonly string[]; /** Environment variables (values are `undefined` for unset keys). */ readonly env: Readonly>; /** Runtime version strings — used for version-guard checks. */ readonly versions?: { readonly node?: string; readonly bun?: string; }; /** Return the current working directory. */ cwd(): string; /** Platform identifier (e.g. `'linux'`, `'darwin'`, `'win32'`). */ readonly platform: string; /** Standard input stream with TTY detection and async iteration. */ readonly stdin: { readonly isTTY?: boolean; /** Async iterable for reading all of stdin (used by readStdin). */ [Symbol.asyncIterator](): AsyncIterator; }; /** Standard output stream with TTY detection and write. */ readonly stdout: { readonly isTTY?: boolean; readonly columns?: number; readonly rows?: number; getWindowSize?(): readonly [number, number]; on?(event: 'resize', listener: () => void): unknown; off?(event: 'resize', listener: () => void): unknown; removeListener?(event: 'resize', listener: () => void): unknown; write(data: string): unknown; }; /** Standard error stream with write. */ readonly stderr: { write(data: string): unknown; }; /** Terminate the process with the given exit code. */ exit(code: number): never; } /** * Create a runtime adapter backed by Node.js `process` globals. * * Reads `process.argv`, `process.env`, `process.cwd()`, and wraps * `process.stdout.write`/`process.stderr.write` as {@linkcode WriteFn} functions. * * Also works on Bun, which provides a Node-compatible `process` global. * * @param proc - Override the process object (useful for testing the adapter itself). * @returns A {@linkcode RuntimeAdapter} backed by Node.js process state. * * @example * ```ts * import { cli } from '@kjanat/dreamcli'; * import { createNodeAdapter } from '@kjanat/dreamcli/runtime/node'; * * cli('mycli') * .command(deploy) * .run({ adapter: createNodeAdapter() }); * ``` */ declare function createNodeAdapter(proc?: NodeProcess): RuntimeAdapter; //#endregion export { createAdapter as a, Runtime as c, createDenoAdapter as i, detectRuntime as l, createNodeAdapter as n, GlobalForDetect as o, DenoNamespace as r, RUNTIMES as s, NodeProcess as t };