Skip to content

Commit

Permalink
Make preferLocal default to true with $ (#529)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Mar 5, 2023
1 parent 2c58762 commit a6d1141
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion index.d.ts
Expand Up @@ -27,7 +27,7 @@ export type CommonOptions<EncodingType> = {
If you `$ npm install foo`, you can then `execa('foo')`.
@default false
@default `true` with `$`/`$.sync`, `false` otherwise
*/
readonly preferLocal?: boolean;

Expand Down
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -242,7 +242,7 @@ function create$(options) {
return $;
}

export const $ = create$();
export const $ = create$({preferLocal: true});

export function execaCommand(command, options) {
const [file, ...args] = parseCommand(command);
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Expand Up @@ -425,7 +425,7 @@ Kill the spawned process when the parent process exits unless either:
#### preferLocal

Type: `boolean`\
Default: `false`
Default: `true` with [`$`](#command)/[`$.sync`](#synccommand), `false` otherwise

Prefer locally installed binaries when looking for a binary to execute.\
If you `$ npm install foo`, you can then `execa('foo')`.
Expand Down
6 changes: 5 additions & 1 deletion test/test.js
Expand Up @@ -4,7 +4,7 @@ import {fileURLToPath, pathToFileURL} from 'node:url';
import test from 'ava';
import isRunning from 'is-running';
import getNode from 'get-node';
import {execa, execaSync} from '../index.js';
import {execa, execaSync, $} from '../index.js';
import {setFixtureDir, PATH_KEY} from './helpers/fixtures-dir.js';

setFixtureDir();
Expand Down Expand Up @@ -96,6 +96,10 @@ test('preferLocal: undefined', async t => {
await t.throwsAsync(execa('ava', ['--version'], {env: getPathWithoutLocalDir()}), {message: ENOENT_REGEXP});
});

test('preferLocal: undefined with $', async t => {
await t.notThrowsAsync($({env: getPathWithoutLocalDir()})`ava --version`);
});

test('localDir option', async t => {
const command = process.platform === 'win32' ? 'echo %PATH%' : 'echo $PATH';
const {stdout} = await execa(command, {shell: true, preferLocal: true, localDir: '/test'});
Expand Down

0 comments on commit a6d1141

Please sign in to comment.