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