Skip to content
Myr

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

5 files+13 added−6 removed

modified:test/test.js+9 added-3 removed
10 unmodified lines
11process.env.FOO = 'foo';1213const ENOENT_REGEXP = process.platform === 'win32' ? /failed with exit code 1/ : /spawn.* ENOENT/;1415const identity = value => value;1617test('execa()', async t => {18 const {stdout} = await execa('noop.js', ['foo']);19 t.is(stdout, 'foo');20});
91 unmodified lines
112 const envPaths = stdout.split(path.delimiter);113 t.true(envPaths.some(envPath => envPath.endsWith('.bin')));114});115114test.serial('execPath option', async t => {115 const {path: execPath} = await getNode('16.0.0');116const 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};122123test.serial('execPath option', testExecPath, identity);124test.serial('execPath option can be a file URL', testExecPath, pathToFileURL);125126test('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 lines
modified:index.d.ts+1 added-1 removed
82 unmodified lines
83 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.8485 @default process.execPath86 */87 readonly execPath?: string;87 readonly execPath?: string | URL;8889 /**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 lines
modified:index.test-d.ts+1 added
144 unmodified lines
145execa('unicorns', {localDir: '.'});146execa('unicorns', {localDir: new URL('file:///test')});147expectError(execa('unicorns', {encoding: 'unknownEncoding'}));148execa('unicorns', {execPath: '/path'});149execa('unicorns', {execPath: new URL('file:///test')});150execa('unicorns', {buffer: false});151execa('unicorns', {input: ''});152execa('unicorns', {input: new Uint8Array()});153execa('unicorns', {input: process.stdin});
206 unmodified lines
modified:package.json+1 added-1 removed
modified:readme.md+1 added-1 removed
528 unmodified lines
529Preferred path to find locally installed binaries in (use with `preferLocal`).530531#### execPath532533Type: `string`\533Type: `string | URL`\534Default: `process.execPath` (Current Node.js executable)535536Path to the Node.js executable to use in child processes.537
324 unmodified lines