/** * Process interface provides a typed abstraction over common Node.js * process-level operations. * * It covers process lifecycle control, environment variables, * current working directory management, and event handling. */ export interface CBProcess { /** Changes the current working directory */ chdir: (path: string) => void; /** Terminates the Node.js process */ exit: (code?: number) => never; /** Returns the current working directory */ cwd: () => string; /** Access to environment variables */ env: NodeJS.ProcessEnv; /** Registers an event listener */ on: (event: string, listener: (...args: any[]) => void) => void; } /** * ProcessService provides a class-based implementation of the Process interface. * Use this for dependency injection for all the process operations, and for testing we can use custom implemenatation if needed. */ export class ProcessService implements CBProcess { chdir(path: string): void { process.chdir(path); } cwd(): string { return process.cwd(); } exit(code?: number): never { process.exit(code); } on(event: string, listener: (...args: any[]) => void): void { process.on(event, listener); } get env(): NodeJS.ProcessEnv { return process.env; } }