Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGFIX] Prevent leaked runners/sub processes.
It is not uncommon during developer to end the process unexpectedly. Examples are <ctr-c>, crash, etc. Switching to `execa` gives us * automatic cleanup of child_processes in the above scenarios * Promise API * other nice things: https://github.com/sindresorhus/execa#why
- Loading branch information
1 parent
1950ca9
commit 184de4e
Showing
8 changed files
with
39 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,21 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
|
||
var spawn = require('child_process').spawn; | ||
var execa = require('execa'); | ||
var command = 'npm'; | ||
|
||
function run(command, args, cb) { | ||
|
||
console.log('Running: ' + command + ' ' + args.join(' ')); | ||
|
||
var child = spawn(command, args, { stdio: 'inherit' }); | ||
|
||
child.on('error', function(err) { | ||
cb(err); | ||
}); | ||
|
||
child.on('exit', function(code) { | ||
if (code === 0) { | ||
return cb(); | ||
} | ||
|
||
cb(code); | ||
}); | ||
} | ||
|
||
var testArgs; | ||
var args; | ||
if (process.env.BROWSER_TESTS) { | ||
testArgs = ['run', 'browser-tests']; | ||
args = ['run', 'browser-tests']; | ||
} else { | ||
testArgs = ['run', 'testem-tests']; | ||
args = ['run', 'testem-tests']; | ||
} | ||
|
||
run('npm', testArgs, function(err) { | ||
if (err) { | ||
console.error(err); | ||
process.exit(1); | ||
} | ||
console.log('Running: ' + command + ' ' + args.join(' ')); | ||
|
||
process.exit(0); | ||
execa(command, args, { stdio: 'inherit' }).then(function(result) { | ||
process.exit(result.code); | ||
}).catch(function(err) { | ||
console.error(err); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,31 @@ | ||
'use strict'; | ||
|
||
var fs = require('fs'); | ||
var childProcess = require('child_process'); | ||
var execa = require('execa'); | ||
var Bluebird = require('bluebird'); | ||
var log = require('npmlog'); | ||
|
||
var fsStatAsync = Bluebird.promisify(fs.stat); | ||
|
||
var isWin = require('./utils/is-win')(); | ||
|
||
var fileExists = function(path) { | ||
exports.fileExists = function fileExists(path) { | ||
return fsStatAsync(path).then(function(stats) { | ||
return stats.isFile(); | ||
}).catchReturn(false); | ||
}; | ||
exports.fileExists = fileExists; | ||
|
||
var executableExists = function(exe, options) { | ||
exports.executableExists = function executableExists(exe, options) { | ||
var cmd = isWin ? 'where' : 'which'; | ||
var test = execa(cmd, [exe], options); | ||
|
||
return new Bluebird.Promise(function(resolve) { | ||
var test = childProcess.spawn(cmd, [exe], options); | ||
test.on('error', function(error) { | ||
log.error('Error spawning "' + cmd + exe + '"', error); | ||
}); | ||
test.on('close', function(exitCode) { | ||
return resolve(exitCode === 0); | ||
}); | ||
test.on('error', function(error) { | ||
log.error('Error spawning "' + cmd + exe + '"', error); | ||
}); | ||
}; | ||
|
||
exports.executableExists = executableExists; | ||
return test.then(function(result) { | ||
return result.code === 0; | ||
}, function() { | ||
return false; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters