Allow the `execPath` option to be a file URL (#633)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 77e1477 · Browse files · 5 files·+13 added−6 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+13 added−6 removed
- tests:+9 added−3 removed
- other:+4 added−3 removed
Provenance
- Commit
b495146- Tree
18f37a8- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
77e1477
5 files changed+13 added−6 removed
modified:test/test.js+9 added-3 removed
10 unmodified lines11 process.env.FOO = 'foo';12 13 const ENOENT_REGEXP = process.platform === 'win32' ? /failed with exit code 1/ : /spawn.* ENOENT/;14 15+const identity = value => value;16+17 test('execa()', async t => {18 const {stdout} = await execa('noop.js', ['foo']);19 t.is(stdout, 'foo');20 });91 unmodified lines112 const envPaths = stdout.split(path.delimiter);113 t.true(envPaths.some(envPath => envPath.endsWith('.bin')));114 });115 114-test.serial('execPath option', async t => {115- const {path: execPath} = await getNode('16.0.0');116+const testExecPath = async (t, mapPath) => {117+ const {path} = await getNode('16.0.0');118+ const execPath = mapPath(path);119 const {stdout} = await execa('node', ['-p', 'process.env.Path || process.env.PATH'], {preferLocal: true, execPath});120 t.true(stdout.includes('16.0.0'));118-});121+};122 123+test.serial('execPath option', testExecPath, identity);124+test.serial('execPath option can be a file URL', testExecPath, pathToFileURL);125+126 test('stdin errors are handled', async t => {127 const subprocess = execa('noop.js');128 subprocess.stdin.emit('error', new Error('test'));129 await t.throwsAsync(subprocess, {message: /test/});171 unmodified linesmodified:index.d.ts+1 added-1 removed
82 unmodified lines83 For example, this can be used together with [`get-node`](https://github.com/ehmicky/get-node) to run a specific Node.js version in a child process.84 85 @default process.execPath86 */87- readonly execPath?: string;87+ readonly execPath?: string | URL;88 89 /**90 Buffer the output from the spawned process. When set to `false`, you must read the output of `stdout` and `stderr` (or `all` if the `all` option is `true`). Otherwise the returned promise will not be resolved/rejected.91 970 unmodified linesmodified:index.test-d.ts+1 added
144 unmodified lines145 execa('unicorns', {localDir: '.'});146 execa('unicorns', {localDir: new URL('file:///test')});147 expectError(execa('unicorns', {encoding: 'unknownEncoding'}));148 execa('unicorns', {execPath: '/path'});149+execa('unicorns', {execPath: new URL('file:///test')});150 execa('unicorns', {buffer: false});151 execa('unicorns', {input: ''});152 execa('unicorns', {input: new Uint8Array()});153 execa('unicorns', {input: process.stdin});206 unmodified linesmodified:package.json+1 added-1 removed
48 unmodified lines4950515253535455565733 unmodified lines48 unmodified lines "cross-spawn": "^7.0.3", "get-stream": "^8.0.1", "human-signals": "^6.0.0", "is-stream": "^3.0.0", "npm-run-path": "^5.1.0", "npm-run-path": "^5.2.0", "onetime": "^7.0.0", "signal-exit": "^4.1.0", "strip-final-newline": "^4.0.0" },33 unmodified linesmodified:readme.md+1 added-1 removed
528 unmodified lines529 Preferred path to find locally installed binaries in (use with `preferLocal`).530 531 #### execPath532 533-Type: `string`\533+Type: `string | URL`\534 Default: `process.execPath` (Current Node.js executable)535 536 Path to the Node.js executable to use in child processes.537 324 unmodified lines