index.d.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. export interface RunPathOptions {
  2. /**
  3. Working directory.
  4. @default process.cwd()
  5. */
  6. readonly cwd?: string | URL;
  7. /**
  8. PATH to be appended. Default: [`PATH`](https://github.com/sindresorhus/path-key).
  9. Set it to an empty string to exclude the default PATH.
  10. */
  11. readonly path?: string;
  12. /**
  13. Path to the Node.js executable to use in child processes if that is different from the current one. Its directory is pushed to the front of PATH.
  14. This can be either an absolute path or a path relative to the `cwd` option.
  15. @default process.execPath
  16. */
  17. readonly execPath?: string | URL;
  18. }
  19. export type ProcessEnv = Record<string, string | undefined>;
  20. export interface EnvOptions {
  21. /**
  22. The working directory.
  23. @default process.cwd()
  24. */
  25. readonly cwd?: string | URL;
  26. /**
  27. Accepts an object of environment variables, like `process.env`, and modifies the PATH using the correct [PATH key](https://github.com/sindresorhus/path-key). Use this if you're modifying the PATH for use in the `child_process` options.
  28. */
  29. readonly env?: ProcessEnv;
  30. /**
  31. The path to the current Node.js executable. Its directory is pushed to the front of PATH.
  32. This can be either an absolute path or a path relative to the `cwd` option.
  33. @default process.execPath
  34. */
  35. readonly execPath?: string | URL;
  36. }
  37. /**
  38. Get your [PATH](https://en.wikipedia.org/wiki/PATH_(variable)) prepended with locally installed binaries.
  39. @returns The augmented path string.
  40. @example
  41. ```
  42. import childProcess from 'node:child_process';
  43. import {npmRunPath} from 'npm-run-path';
  44. console.log(process.env.PATH);
  45. //=> '/usr/local/bin'
  46. console.log(npmRunPath());
  47. //=> '/Users/sindresorhus/dev/foo/node_modules/.bin:/Users/sindresorhus/dev/node_modules/.bin:/Users/sindresorhus/node_modules/.bin:/Users/node_modules/.bin:/node_modules/.bin:/usr/local/bin'
  48. ```
  49. */
  50. export function npmRunPath(options?: RunPathOptions): string;
  51. /**
  52. @returns The augmented [`process.env`](https://nodejs.org/api/process.html#process_process_env) object.
  53. @example
  54. ```
  55. import childProcess from 'node:child_process';
  56. import {npmRunPathEnv} from 'npm-run-path';
  57. // `foo` is a locally installed binary
  58. childProcess.execFileSync('foo', {
  59. env: npmRunPathEnv()
  60. });
  61. ```
  62. */
  63. export function npmRunPathEnv(options?: EnvOptions): ProcessEnv;