Skip to content

Latest commit

 

History

History
75 lines (50 loc) · 2.1 KB

environment.md

File metadata and controls

75 lines (50 loc) · 2.1 KB
execa logo

🌐 Environment

Current directory

The current directory when running the command can be set with the cwd option.

import {execa} from 'execa';

await execa({cwd: '/path/to/cwd'})`npm run build`;

And be retrieved with the result.cwd property.

const {cwd} = await execa`npm run build`;

Local binaries

Package managers like npm install local binaries in ./node_modules/.bin.

$ npm install -D eslint
await execa('./node_modules/.bin/eslint');

The preferLocal option can be used to execute those local binaries.

await execa({preferLocal: true})`eslint`;

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

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

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`;

Next: ❌ Errors
Previous: 🐢 Node.js files
Top: Table of contents