Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions build/src/utils/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const mkdirpCb = require('mkdirp');
const copyFilesCb = require('copyfiles');
const spawnCb = require('child_process').spawn;
const execCb = require('child_process').exec;
const execFileCb = require('child_process').execFile;
Comment thread
Copilot marked this conversation as resolved.
Resolved

module.exports = {

Expand All @@ -25,7 +26,11 @@ module.exports = {
spawn: async (command, args, opts) => {
console.log(`(*) Spawn: ${command}${args.reduce((prev, current) => `${prev} ${current}`, '')}`);

opts = opts || { stdio: 'inherit', shell: true };
opts = Object.assign({}, opts || { stdio: 'inherit' });
if (opts.shell === undefined) {
opts.shell = false;
}

let echo = false;
if (opts.stdio === 'inherit') {
opts.stdio = 'pipe';
Expand Down Expand Up @@ -70,13 +75,27 @@ module.exports = {
});
},

exec: async (command, opts) => {
console.log(`(*) Exec: ${command}`);
exec: async (file, args, opts) => {
console.log(`(*) Exec: ${file} ${args.join(' ')}`);
Comment on lines +78 to +79

opts = Object.assign({}, opts || { stdio: 'inherit' });
if (opts.shell === undefined) {
opts.shell = false;
}

let proc;
if (opts.shell) {
// Explicit shell opt-in: reconstruct command string for exec
const command = [file, ...args].join(' ');
proc = execCb(command, opts);
} else {
// Default safe path: execFile directly (no shell, no string parsing)
proc = execFileCb(file, args, opts);
}

opts = opts || { stdio: 'inherit', shell: true };
return new Promise((resolve, reject) => {
let result = '';
const proc = execCb(command, opts);
// proc already created above
proc.on('close', (code, signal) => {
if (code !== 0) {
console.log(result);
Expand Down Expand Up @@ -211,4 +230,3 @@ module.exports = {
});
}
};

Loading