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 on lines 12 to +14

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exec is now imported alongside execFile.
spawn and exec now only default shell to false when the caller does not specify it (if (opts.shell === undefined) opts.shell = false). Callers that explicitly pass { shell: true } (e.g. build/src/push.js:215 for pipelines) are respected.
When shell: true is requested, exec uses child_process.exec as before. When shell: false (the default), it uses child_process.execFile.


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(' ')}`);

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 = {
});
}
};