Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change default value of the preferLocal option to false #314

Merged
merged 1 commit into from Jun 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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