Skip to content
Myr

Add `execPath` option (#377)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by Sindre Sorhus · parent 88dbeee · Browse files · 6 files+38 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+38 added−2 removed

  • tests:+7 added−0 removed
  • other:+31 added−2 removed

6 files+38 added−2 removed

modified:test/test.js+7 added
1import path from 'path';2import test from 'ava';3import isRunning from 'is-running';4import getNode from 'get-node';5import execa from '..';67process.env.PATH = path.join(__dirname, 'fixtures') + path.delimiter + process.env.PATH;8process.env.FOO = 'foo';
83 unmodified lines
92 const envPaths = stdout.split(path.delimiter);93 t.true(envPaths.some(envPath => envPath.endsWith('.bin')));94});9596test('execPath option', async t => {97 const {path: execPath} = await getNode('6.0.0');98 const {stdout} = await execa('node', ['-p', 'process.env.Path || process.env.PATH'], {preferLocal: true, execPath});99 t.true(stdout.includes('6.0.0'));100});101102test('stdin errors are handled', async t => {103 const child = execa('noop');104 child.stdin.emit('error', new Error('test'));105 await t.throwsAsync(child, /test/);
120 unmodified lines
modified:index.d.ts+13 added
37 unmodified lines
38 */39 readonly localDir?: string;4041 /**42 Path to the Node.js executable to use in child processes.4344 This can be either an absolute path or a path relative to the `cwd` option.4546 Requires `preferLocal` to be `true`.47 48 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.4950 @default process.execPath51 */52 readonly execPath?: string;5354 /**55 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.5657 If the spawned process fails, `error.stdout`, `error.stderr`, and `error.all` will contain the buffered data.58
455 unmodified lines
modified:index.js+3 added-2 removed
12 unmodified lines
13const {joinCommand, parseCommand} = require('./lib/command.js');1415const DEFAULT_MAX_BUFFER = 1000 * 1000 * 100;1617const getEnv = ({env: envOption, extendEnv, preferLocal, localDir}) => {17const getEnv = ({env: envOption, extendEnv, preferLocal, localDir, execPath}) => {18 const env = extendEnv ? {...process.env, ...envOption} : envOption;1920 if (preferLocal) {21 return npmRunPath.env({env, cwd: localDir});21 return npmRunPath.env({env, cwd: localDir, execPath});22 }2324 return env;25};
10 unmodified lines
36 stripFinalNewline: true,37 extendEnv: true,38 preferLocal: false,39 localDir: options.cwd || process.cwd(),40 execPath: process.execPath,41 encoding: 'utf8',42 reject: true,43 cleanup: true,44 all: false,
212 unmodified lines
modified:index.test-d.ts+1 added
modified:package.json+1 added
50 unmodified lines
51 "devDependencies": {52 "@types/node": "^12.0.7",53 "ava": "^2.1.0",54 "coveralls": "^3.0.4",55 "get-node": "^5.0.0",56 "is-running": "^2.1.0",57 "nyc": "^14.1.1",58 "p-event": "^4.1.0",59 "tempfile": "^3.0.0",
11 unmodified lines
modified:readme.md+13 added
306 unmodified lines
307Default: `process.cwd()`308309Preferred path to find locally installed binaries in (use with `preferLocal`).310311#### execPath312313Type: `string`<br>314Default: `process.execPath` (current Node.js executable)315316Path to the Node.js executable to use in child processes.317318This can be either an absolute path or a path relative to the [`cwd` option](#cwd).319320Requires [`preferLocal`](#preferlocal) to be `true`.321322For 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.323324#### buffer325326Type: `boolean`<br>327Default: `true`
240 unmodified lines