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