Skip to content

Commit

Permalink
fix: use cross-spawn to support Windows
Browse files Browse the repository at this point in the history
BREAKING CHANGE: run(cmd, args) now needs second param args
  • Loading branch information
3cp committed May 23, 2019
1 parent 4988854 commit 86cd1c7
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ async function makes(supplier, {
prompts,
ansiColors,
sisteransi,
run: cmd => run(cmd, targetDir)
run: (cmd, args) => run(cmd, args, targetDir)
});
}
}
Expand Down
10 changes: 3 additions & 7 deletions lib/run.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
const {spawn} = require('child_process');
const spawn = require('cross-spawn');

module.exports = function(command, dir) {
const [cmd, ...args] = command.split(/\s+/);
module.exports = function(command, args = [], dir = '.') {
return new Promise((resolve, reject) => {
const proc = spawn(cmd, args,
{ stdio: 'inherit', cwd: dir }
);
const proc = spawn(command, args, {stdio: 'inherit', cwd: dir});

proc.on('error', reject);

proc.on('exit', (code, signal) => {
if (code) {
reject(new Error('Process exit code: ' + code + ' signal: ' + signal));
Expand Down
5 changes: 2 additions & 3 deletions lib/skeleton-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ module.exports = async function(dir, {
};

function npmInstall(dir) {
const cmd = 'npm i --only=prod';
info('Skeleton requires additional dependencies. Running ' + cmd);
return run(cmd, dir);
info('Skeleton requires additional dependencies. Running npm i --only=prod');
return run('npm', ['i', '--only=prod'], dir);
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"devDependencies": {
"ansi-colors": "^3.2.4",
"ava": "^1.4.1",
"cross-spawn": "^6.0.5",
"eslint": "^5.16.0",
"gunzip-maybe": "^1.4.1",
"hosted-git-info": "^2.7.1",
Expand Down
6 changes: 3 additions & 3 deletions test/run.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import test from 'ava';
import run from '../lib/run';

test('run a command', async t => {
await run('echo hello');
await run('echo', ['hello']);
t.pass('successfully run a command');
});

test('run a command in a different cwd', async t => {
await run('ls index.js', 'lib');
await run('ls', ['index.js'], 'lib');
t.pass('successfully run a command in a different cwd');
});

test('run a command, catch failure', async t => {
await t.throwsAsync(async () => run('ls no-such-file', 'lib'));
await t.throwsAsync(async () => run('ls', ['no-such-file'], 'lib'));
});

0 comments on commit 86cd1c7

Please sign in to comment.