index.d.ts 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { ChildProcessByStdio, SpawnOptions, ChildProcess } from 'child_process';
  2. /**
  3. * The signature for the cleanup method.
  4. *
  5. * Arguments indicate the exit status of the child process.
  6. *
  7. * If a Promise is returned, then the process is not terminated
  8. * until it resolves, and the resolution value is treated as the
  9. * exit status (if a number) or signal exit (if a signal string).
  10. *
  11. * If `undefined` is returned, then no change is made, and the parent
  12. * exits in the same way that the child exited.
  13. *
  14. * If boolean `false` is returned, then the parent's exit is canceled.
  15. *
  16. * If a number is returned, then the parent process exits with the number
  17. * as its exitCode.
  18. *
  19. * If a signal string is returned, then the parent process is killed with
  20. * the same signal that caused the child to exit.
  21. */
  22. export type Cleanup = (code: number | null, signal: null | NodeJS.Signals, processInfo: {
  23. watchdogPid?: ChildProcess['pid'];
  24. }) => void | undefined | number | NodeJS.Signals | false | Promise<void | undefined | number | NodeJS.Signals | false>;
  25. export type FgArgs = [program: string | [cmd: string, ...args: string[]], cleanup?: Cleanup] | [
  26. program: [cmd: string, ...args: string[]],
  27. opts?: SpawnOptions,
  28. cleanup?: Cleanup
  29. ] | [program: string, cleanup?: Cleanup] | [program: string, opts?: SpawnOptions, cleanup?: Cleanup] | [program: string, args?: string[], cleanup?: Cleanup] | [
  30. program: string,
  31. args?: string[],
  32. opts?: SpawnOptions,
  33. cleanup?: Cleanup
  34. ];
  35. /**
  36. * Normalizes the arguments passed to `foregroundChild`.
  37. *
  38. * Exposed for testing.
  39. *
  40. * @internal
  41. */
  42. export declare const normalizeFgArgs: (fgArgs: FgArgs) => [program: string, args: string[], spawnOpts: SpawnOptions, cleanup: Cleanup];
  43. /**
  44. * Spawn the specified program as a "foreground" process, or at least as
  45. * close as is possible given node's lack of exec-without-fork.
  46. *
  47. * Cleanup method may be used to modify or ignore the result of the child's
  48. * exit code or signal. If cleanup returns undefined (or a Promise that
  49. * resolves to undefined), then the parent will exit in the same way that
  50. * the child did.
  51. *
  52. * Return boolean `false` to prevent the parent's exit entirely.
  53. */
  54. export declare function foregroundChild(cmd: string | [cmd: string, ...args: string[]], cleanup?: Cleanup): ChildProcessByStdio<null, null, null>;
  55. export declare function foregroundChild(program: string, args?: string[], cleanup?: Cleanup): ChildProcessByStdio<null, null, null>;
  56. export declare function foregroundChild(program: string, spawnOpts?: SpawnOptions, cleanup?: Cleanup): ChildProcessByStdio<null, null, null>;
  57. export declare function foregroundChild(program: string, args?: string[], spawnOpts?: SpawnOptions, cleanup?: Cleanup): ChildProcessByStdio<null, null, null>;
  58. //# sourceMappingURL=index.d.ts.map