main.d.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { ChildProcess, SpawnOptions } from 'node:child_process';
  2. import { Readable } from 'node:stream';
  3. declare class NonZeroExitError extends Error {
  4. readonly result: Result;
  5. readonly output?: Output;
  6. get exitCode(): number | undefined;
  7. constructor(result: Result, output?: Output);
  8. }
  9. interface Output {
  10. stderr: string;
  11. stdout: string;
  12. exitCode: number | undefined;
  13. }
  14. interface PipeOptions extends Options {
  15. }
  16. type KillSignal = Parameters<ChildProcess['kill']>[0];
  17. interface OutputApi extends AsyncIterable<string> {
  18. pipe(command: string, args?: string[], options?: Partial<PipeOptions>): Result;
  19. process: ChildProcess | undefined;
  20. kill(signal?: KillSignal): boolean;
  21. get pid(): number | undefined;
  22. get aborted(): boolean;
  23. get killed(): boolean;
  24. get exitCode(): number | undefined;
  25. }
  26. type Result = PromiseLike<Output> & OutputApi;
  27. interface Options {
  28. signal: AbortSignal;
  29. nodeOptions: SpawnOptions;
  30. timeout: number;
  31. persist: boolean;
  32. stdin: ExecProcess;
  33. throwOnError: boolean;
  34. }
  35. interface TinyExec {
  36. (command: string, args?: string[], options?: Partial<Options>): Result;
  37. }
  38. declare class ExecProcess implements Result {
  39. protected _process?: ChildProcess;
  40. protected _aborted: boolean;
  41. protected _options: Partial<Options>;
  42. protected _command: string;
  43. protected _args: string[];
  44. protected _resolveClose?: () => void;
  45. protected _processClosed: Promise<void>;
  46. protected _thrownError?: Error;
  47. get process(): ChildProcess | undefined;
  48. get pid(): number | undefined;
  49. get exitCode(): number | undefined;
  50. constructor(command: string, args?: string[], options?: Partial<Options>);
  51. kill(signal?: KillSignal): boolean;
  52. get aborted(): boolean;
  53. get killed(): boolean;
  54. pipe(command: string, args?: string[], options?: Partial<PipeOptions>): Result;
  55. [Symbol.asyncIterator](): AsyncIterator<string>;
  56. protected _waitForOutput(): Promise<Output>;
  57. then<TResult1 = Output, TResult2 = never>(onfulfilled?: ((value: Output) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
  58. protected _streamOut?: Readable;
  59. protected _streamErr?: Readable;
  60. spawn(): void;
  61. protected _resetState(): void;
  62. protected _onError: (err: Error) => void;
  63. protected _onClose: () => void;
  64. }
  65. declare const x: TinyExec;
  66. declare const exec: TinyExec;
  67. export { ExecProcess, type KillSignal, NonZeroExitError, type Options, type Output, type OutputApi, type PipeOptions, type Result, type TinyExec, exec, x };