Skip to content

Commit

Permalink
Change default value of the preferLocal option to false (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky authored and sindresorhus committed Jun 24, 2019
1 parent 4dd258d commit eb22ff7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion index.d.ts
Expand Up @@ -27,7 +27,7 @@ declare namespace execa {
If you `$ npm install foo`, you can then `execa('foo')`.
@default true
@default false
*/
readonly preferLocal?: boolean;

Expand Down
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -28,7 +28,7 @@ const handleArgs = (file, args, options = {}) => {
maxBuffer: DEFAULT_MAX_BUFFER,
buffer: true,
stripFinalNewline: true,
preferLocal: true,
preferLocal: false,
localDir: options.cwd || process.cwd(),
encoding: 'utf8',
reject: true,
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Expand Up @@ -281,7 +281,7 @@ Kill the spawned process when the parent process exits unless either:
#### preferLocal

Type: `boolean`<br>
Default: `true`
Default: `false`

Prefer locally installed binaries when looking for a binary to execute.<br>
If you `$ npm install foo`, you can then `execa('foo')`.
Expand Down
19 changes: 13 additions & 6 deletions test/test.js
Expand Up @@ -12,6 +12,7 @@ process.env.PATH = path.join(__dirname, 'fixtures') + path.delimiter + process.e
process.env.FOO = 'foo';

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

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

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

test('preferLocal option', async t => {
await execa('ava', ['--version'], {env: {PATH: ''}});
const errorRegExp = process.platform === 'win32' ? /failed with exit code 1/ : /spawn ava ENOENT/;
await t.throwsAsync(execa('ava', ['--version'], {preferLocal: false, env: {PATH: ''}}), errorRegExp);
test('preferLocal: true', async t => {
await t.notThrowsAsync(execa('ava', ['--version'], {preferLocal: true, env: {PATH: ''}}));
});

test('preferLocal: false', async t => {
await t.throwsAsync(execa('ava', ['--version'], {preferLocal: false, env: {PATH: ''}}), ENOENT_REGEXP);
});

test('preferLocal: undefined', async t => {
await t.throwsAsync(execa('ava', ['--version'], {env: {PATH: ''}}), ENOENT_REGEXP);
});

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

0 comments on commit eb22ff7

Please sign in to comment.