@visulima/cerebro
Version:
A delightful toolkit for building cross-runtime CLIs for Node.js, Deno, and Bun.
66 lines (65 loc) • 2.41 kB
TypeScript
/**
* Runtime-agnostic process-like APIs that work across Node.js, Deno, and Bun.
*/
/**
* Gets command line arguments compatible with process.argv format.
* For Deno, constructs argv from Deno.args (prepending execPath).
* For Node.js and Bun, uses process.argv directly.
* @returns Array of command line arguments
*/
export declare const getArgv: () => ReadonlyArray<string>;
/**
* Gets the current working directory.
* @returns The current working directory path
*/
export declare const getCwd: () => string;
/**
* Gets environment variables as a mutable object.
* Returns a proxy object that handles mutations across different runtimes.
* @returns Environment variables object (mutable proxy)
*/
export declare const getEnv: () => Record<string, string | undefined>;
/**
* Gets execution arguments (e.g., --inspect, --trace-warnings).
* @returns Array of execution arguments
*/
export declare const getExecArgv: () => ReadonlyArray<string>;
/**
* Gets the absolute pathname of the executable that started the process.
* @returns The executable path
*/
export declare const getExecPath: () => string;
/**
* Gets the operating system platform.
* @returns Platform string (e.g., "darwin", "linux", "win32")
*/
export declare const getPlatform: () => string;
/**
* Gets the CPU architecture.
* @returns Architecture string (e.g., "x64", "arm64")
*/
export declare const getArch: () => string;
/**
* Gets version information about the runtime.
* @returns Object with version strings
*/
export declare const getVersions: () => Record<string, string>;
/**
* Terminates the process with the specified exit code.
* @param exitCode Exit code (default: 0)
*/
export declare const exitProcess: (exitCode?: number) => never;
/**
* Runtime-agnostic event handler registration.
* Note: Deno and Bun don't have equivalent event emitters, so this only works in Node.js.
* In other runtimes, handlers are registered but may not be called for all events.
*/
export type ProcessEventType = "uncaughtException" | "unhandledRejection";
export type ProcessEventHandler = (...args: unknown[]) => void;
/**
* Registers an event handler for process events.
* @param event Event type to listen for
* @param handler Handler function
* @returns Cleanup function to remove the handler
*/
export declare const onProcessEvent: (event: ProcessEventType, handler: ProcessEventHandler) => () => void;