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
Provenance
- Commit
eb22ff7- Tree
db9d15e- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
Sindre Sorhus <sindresorhus@gmail.com>- Parent
4dd258d
4 files changed+16 added−9 removed
modified:test/test.js+13 added-6 removed
10 unmodified lines11 process.env.PATH = path.join(__dirname, 'fixtures') + path.delimiter + process.env.PATH;12 process.env.FOO = 'foo';13 14 const TIMEOUT_REGEXP = /timed out after/;15+const ENOENT_REGEXP = process.platform === 'win32' ? /failed with exit code 1/ : /spawn.* ENOENT/;16 17 test('execa()', async t => {18 const {stdout} = await execa('noop', ['foo']);19 t.is(stdout, 'foo');55 unmodified lines75 76 test('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 });81 82 test('skip throwing when using reject option', async t => {83 const {exitCode} = await execa('fail', {reject: false});97 unmodified lines181 });182 t.is(stderr, 'foo');183 });184 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);195+});196+197 test('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 linesmodified:index.d.ts+1 added-1 removed
25 unmodified lines26 Prefer locally installed binaries when looking for a binary to execute.27 28 If you `$ npm install foo`, you can then `execa('foo')`.29 30- @default true30+ @default false31 */32 readonly preferLocal?: boolean;33 34 /**428 unmodified linesmodified:index.js+1 added-1 removed
26 unmodified lines27 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 linesmodified:readme.md+1 added-1 removed
279 unmodified lines280 281 #### preferLocal282 283 Type: `boolean`<br>284-Default: `true`284+Default: `false`285 286 Prefer locally installed binaries when looking for a binary to execute.<br>287 If you `$ npm install foo`, you can then `execa('foo')`.288 234 unmodified lines