Skip to content

Commit eb22ff7

Browse files
ehmickysindresorhus
authored andcommitted
Change default value of the preferLocal option to false (#314)
1 parent 4dd258d commit eb22ff7

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ declare namespace execa {
2727
2828
If you `$ npm install foo`, you can then `execa('foo')`.
2929
30-
@default true
30+
@default false
3131
*/
3232
readonly preferLocal?: boolean;
3333

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const handleArgs = (file, args, options = {}) => {
2828
maxBuffer: DEFAULT_MAX_BUFFER,
2929
buffer: true,
3030
stripFinalNewline: true,
31-
preferLocal: true,
31+
preferLocal: false,
3232
localDir: options.cwd || process.cwd(),
3333
encoding: 'utf8',
3434
reject: true,

readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ Kill the spawned process when the parent process exits unless either:
281281
#### preferLocal
282282

283283
Type: `boolean`<br>
284-
Default: `true`
284+
Default: `false`
285285

286286
Prefer locally installed binaries when looking for a binary to execute.<br>
287287
If you `$ npm install foo`, you can then `execa('foo')`.

test/test.js

+13-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ process.env.PATH = path.join(__dirname, 'fixtures') + path.delimiter + process.e
1212
process.env.FOO = 'foo';
1313

1414
const TIMEOUT_REGEXP = /timed out after/;
15+
const ENOENT_REGEXP = process.platform === 'win32' ? /failed with exit code 1/ : /spawn.* ENOENT/;
1516

1617
test('execa()', async t => {
1718
const {stdout} = await execa('noop', ['foo']);
@@ -75,7 +76,7 @@ test('execa.sync()', t => {
7576
test('execa.sync() throws error if written to stderr', t => {
7677
t.throws(() => {
7778
execa.sync('foo');
78-
}, process.platform === 'win32' ? /failed with exit code 1/ : /spawnSync foo ENOENT/);
79+
}, ENOENT_REGEXP);
7980
});
8081

8182
test('skip throwing when using reject option', async t => {
@@ -181,15 +182,21 @@ test('stripFinalNewline in sync mode on failure', t => {
181182
t.is(stderr, 'foo');
182183
});
183184

184-
test('preferLocal option', async t => {
185-
await execa('ava', ['--version'], {env: {PATH: ''}});
186-
const errorRegExp = process.platform === 'win32' ? /failed with exit code 1/ : /spawn ava ENOENT/;
187-
await t.throwsAsync(execa('ava', ['--version'], {preferLocal: false, env: {PATH: ''}}), errorRegExp);
185+
test('preferLocal: true', async t => {
186+
await t.notThrowsAsync(execa('ava', ['--version'], {preferLocal: true, env: {PATH: ''}}));
187+
});
188+
189+
test('preferLocal: false', async t => {
190+
await t.throwsAsync(execa('ava', ['--version'], {preferLocal: false, env: {PATH: ''}}), ENOENT_REGEXP);
191+
});
192+
193+
test('preferLocal: undefined', async t => {
194+
await t.throwsAsync(execa('ava', ['--version'], {env: {PATH: ''}}), ENOENT_REGEXP);
188195
});
189196

190197
test('localDir option', async t => {
191198
const command = process.platform === 'win32' ? 'echo %PATH%' : 'echo $PATH';
192-
const {stdout} = await execa(command, {shell: true, localDir: '/test'});
199+
const {stdout} = await execa(command, {shell: true, preferLocal: true, localDir: '/test'});
193200
const envPaths = stdout.split(path.delimiter).map(envPath =>
194201
envPath.replace(/\\/g, '/').replace(/^[^/]+/, '')
195202
);

0 commit comments

Comments
 (0)