index.d.ts 2.9 KB

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