1 | type CommonOptions = {
|
2 | /**
|
3 | Working directory.
|
4 |
|
5 | @default process.cwd()
|
6 | */
|
7 | readonly cwd?: string | URL;
|
8 |
|
9 | /**
|
10 | The path to the current Node.js executable.
|
11 |
|
12 | This can be either an absolute path or a path relative to the `cwd` option.
|
13 |
|
14 | @default [process.execPath](https://nodejs.org/api/process.html#processexecpath)
|
15 | */
|
16 | readonly execPath?: string | URL;
|
17 |
|
18 | /**
|
19 | Whether to push the current Node.js executable's directory (`execPath` option) to the front of PATH.
|
20 |
|
21 | @default true
|
22 | */
|
23 | readonly addExecPath?: boolean;
|
24 |
|
25 | /**
|
26 | Whether to push the locally installed binaries' directory to the front of PATH.
|
27 |
|
28 | @default true
|
29 | */
|
30 | readonly preferLocal?: boolean;
|
31 | };
|
32 |
|
33 | export type RunPathOptions = CommonOptions & {
|
34 | /**
|
35 | PATH to be appended.
|
36 |
|
37 | Set it to an empty string to exclude the default PATH.
|
38 |
|
39 | @default [`PATH`](https://github.com/sindresorhus/path-key)
|
40 | */
|
41 | readonly path?: string;
|
42 | };
|
43 |
|
44 | export type ProcessEnv = Record<string, string | undefined>;
|
45 |
|
46 | export type EnvOptions = CommonOptions & {
|
47 | /**
|
48 | 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.
|
49 |
|
50 | @default [process.env](https://nodejs.org/api/process.html#processenv)
|
51 | */
|
52 | readonly env?: ProcessEnv;
|
53 | };
|
54 |
|
55 | /**
|
56 | Get your [PATH](https://en.wikipedia.org/wiki/PATH_(variable)) prepended with locally installed binaries.
|
57 |
|
58 | @returns The augmented path string.
|
59 |
|
60 | @example
|
61 | ```
|
62 | import childProcess from 'node:child_process';
|
63 | import {npmRunPath} from 'npm-run-path';
|
64 |
|
65 | console.log(process.env.PATH);
|
66 | //=> '/usr/local/bin'
|
67 |
|
68 | console.log(npmRunPath());
|
69 | //=> '/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'
|
70 | ```
|
71 | */
|
72 | export function npmRunPath(options?: RunPathOptions): string;
|
73 |
|
74 | /**
|
75 | Get your [PATH](https://en.wikipedia.org/wiki/PATH_(variable)) prepended with locally installed binaries.
|
76 |
|
77 | @returns The augmented [`process.env`](https://nodejs.org/api/process.html#process_process_env) object.
|
78 |
|
79 | @example
|
80 | ```
|
81 | import childProcess from 'node:child_process';
|
82 | import {npmRunPathEnv} from 'npm-run-path';
|
83 |
|
84 | // `foo` is a locally installed binary
|
85 | childProcess.execFileSync('foo', {
|
86 | env: npmRunPathEnv()
|
87 | });
|
88 | ```
|
89 | */
|
90 | export function npmRunPathEnv(options?: EnvOptions): ProcessEnv;
|