Skip to content
Myr

Change default value of the `preferLocal` option to `false` (#314)

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 4dd258d · Browse files · 4 files+16 added−9 removed
This commit

State

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

Diff stats

4 files+16 added−9 removed

  • tests:+13 added−6 removed
  • other:+3 added−3 removed

4 files+16 added−9 removed

modified:test/test.js+13 added-6 removed
10 unmodified lines
11process.env.PATH = path.join(__dirname, 'fixtures') + path.delimiter + process.env.PATH;12process.env.FOO = 'foo';1314const TIMEOUT_REGEXP = /timed out after/;15const ENOENT_REGEXP = process.platform === 'win32' ? /failed with exit code 1/ : /spawn.* ENOENT/;1617test('execa()', async t => {18 const {stdout} = await execa('noop', ['foo']);19 t.is(stdout, 'foo');
55 unmodified lines
7576test('execa.sync() throws error if written to stderr', t => {77 t.throws(() => {78 execa.sync('foo');78 }, process.platform === 'win32' ? /failed with exit code 1/ : /spawnSync foo ENOENT/);79 }, ENOENT_REGEXP);80});8182test('skip throwing when using reject option', async t => {83 const {exitCode} = await execa('fail', {reject: false});
97 unmodified lines
181 });182 t.is(stderr, 'foo');183});184184test('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);185test('preferLocal: true', async t => {186 await t.notThrowsAsync(execa('ava', ['--version'], {preferLocal: true, env: {PATH: ''}}));187});188189test('preferLocal: false', async t => {190 await t.throwsAsync(execa('ava', ['--version'], {preferLocal: false, env: {PATH: ''}}), ENOENT_REGEXP);191});192193test('preferLocal: undefined', async t => {194 await t.throwsAsync(execa('ava', ['--version'], {env: {PATH: ''}}), ENOENT_REGEXP);195});196197test('localDir option', async t => {198 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'});200 const envPaths = stdout.split(path.delimiter).map(envPath =>201 envPath.replace(/\\/g, '/').replace(/^[^/]+/, '')202 );203 t.true(envPaths.some(envPath => envPath === '/test/node_modules/.bin'));
483 unmodified lines
modified:index.d.ts+1 added-1 removed
25 unmodified lines
26 Prefer locally installed binaries when looking for a binary to execute.2728 If you `$ npm install foo`, you can then `execa('foo')`.2930 @default true30 @default false31 */32 readonly preferLocal?: boolean;3334 /**
428 unmodified lines
modified:index.js+1 added-1 removed
26 unmodified lines
27 options = {28 maxBuffer: DEFAULT_MAX_BUFFER,29 buffer: true,30 stripFinalNewline: true,31 preferLocal: true,31 preferLocal: false,32 localDir: options.cwd || process.cwd(),33 encoding: 'utf8',34 reject: true,35 cleanup: true,
458 unmodified lines
modified:readme.md+1 added-1 removed
279 unmodified lines
280281#### preferLocal282283Type: `boolean`<br>284Default: `true`284Default: `false`285286Prefer locally installed binaries when looking for a binary to execute.<br>287If you `$ npm install foo`, you can then `execa('foo')`.288
234 unmodified lines