UNPKG

790 BJavaScriptView Raw
1// Mini wrapper around `child_process` to make it behave a little like `execa`.
2
3import {promisify} from 'node:util';
4import childProcess from 'node:child_process';
5
6const execFile = promisify(childProcess.execFile);
7
8/**
9@param {string} command
10@param {string[]} arguments_
11
12@returns {Promise<import('child_process').ChildProcess>}
13*/
14export async function exec(command, arguments_) {
15 const subprocess = await execFile(command, arguments_, {encoding: 'utf8'});
16 subprocess.stdout = subprocess.stdout.trim();
17 return subprocess;
18}
19
20/**
21@param {string} command
22@param {string[]} arguments_
23
24@returns {string}
25*/
26export function execSync(command, arguments_) {
27 return childProcess.execFileSync(command, arguments_, {
28 encoding: 'utf8',
29 stdio: ['ignore', 'pipe', 'ignore'],
30 }).trim();
31}