Skip to content
Closed
Prev Previous commit
Next Next commit
Support sync spawn, too
  • Loading branch information
Timer committed Nov 19, 2017
commit f702accaf6d0e86547a8f422a788b64a5ec9b0d4
15 changes: 13 additions & 2 deletions packages/react-dev-utils/crossSpawn.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

'use strict';

const { spawn } = require('child_process');
const { spawn, spawnSync } = require('child_process');

function crossSpawn(file, args, options) {
function normalizeSpawnArguments(file, args, options) {
if (typeof file !== 'string' || file.length === 0) {
throw new TypeError('"file" argument must be a non-empty string');
}
Expand All @@ -36,7 +36,18 @@ function crossSpawn(file, args, options) {
if (options.shell === undefined && process.platform === 'win32') {
options.shell = true;
}

return { file, args, options };
}

function crossSpawn(file, args, options) {
({ file, args, options } = normalizeSpawnArguments(file, args, options));
return spawn(file, args, options);
}

crossSpawn.sync = function crossSpawnSync(file, args, options) {
({ file, args, options } = normalizeSpawnArguments(file, args, options));
return spawnSync(file, args, options);
};

module.exports = crossSpawn;
2 changes: 1 addition & 1 deletion packages/react-scripts/scripts/eject.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function adjustPackages(cwd, packages, append, dev) {
let status, output;
if (fs.existsSync(paths.yarnLockFile)) {
({ status, output } = spawnSync(
process.platform === 'win32' ? 'yarn.cmd' : 'yarnpkg',
'yarnpkg',
[append ? 'add' : 'remove', ...packages],
{
stdio: 'pipe',
Expand Down