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

Make preferLocal default to true with $ #529

Merged
merged 1 commit into from Mar 5, 2023
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 @@ 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