Skip to content

Latest commit

 

History

History
58 lines (40 loc) · 1.7 KB

environment.md

File metadata and controls

58 lines (40 loc) · 1.7 KB
execa logo

🌐 Environment

const {cwd} = await execa`npm run build`;
console.log(cwd); // Current directory when running the command
await execa({cwd: '/path/to/cwd'})`npm run build`;

Local binaries

await execa('./node_modules/bin/eslint');

The preferLocal option can be used to automatically find binaries installed in local node_modules.

await execa('eslint', {preferLocal: true});

Those are searched in the current or any parent directory. The localDir option can select a different directory.

await execa('eslint', {preferLocal: true, localDir: '/path/to/dir'});

Current package's binary

Execa can be combined with get-bin-path to test the current package's binary. As opposed to hard-coding the path to the binary, this validates that the package.json bin field is correctly set up.

import {execa} from 'execa';
import {getBinPath} from 'get-bin-path';

const binPath = await getBinPath();
await execa(binPath);

Background subprocess

When the detached option is true, the subprocess runs independently from the current process.

Specific behavior depends on the platform. More info..

await execa({detached: true})`npm run start`;