diff --git a/.gitignore b/.gitignore index a9a5aec..8ae5692 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ tmp +/node_modules diff --git a/commands/run.js b/commands/run.js index dcd1b16..a3c32c6 100644 --- a/commands/run.js +++ b/commands/run.js @@ -9,15 +9,15 @@ function * run (context) { process.exit(-1) } - process.argv = ['', 'heroku local:run', 'run'] + let execArgv = ['run'] if (context.flags.env) process.argv.push('--env', context.flags.env) if (context.flags.port) process.argv.push('--port', context.flags.port) - process.argv.push('--') // disable node-foreman flag parsing - process.argv.push(...context.args) + execArgv.push('--') // disable node-foreman flag parsing + execArgv.push(...context.args) - require('foreman/nf.js') + yield require('../lib/fork_foreman')(execArgv) } module.exports = { diff --git a/commands/start.js b/commands/start.js index 3f5841e..296611d 100644 --- a/commands/start.js +++ b/commands/start.js @@ -7,21 +7,20 @@ function * run (context) { if (context.flags.restart) throw new Error('--restart is no longer available\nUse forego instead: https://github.com/ddollar/forego') if (context.flags.concurrency) throw new Error('--concurrency is no longer available\nUse forego instead: https://github.com/ddollar/forego') - process.argv = ['', 'heroku local', 'start'] + let execArgv = ['start'] - if (context.flags.procfile) process.argv.push('--procfile', context.flags.procfile) - if (context.flags.env) process.argv.push('--env', context.flags.env) - if (context.flags.port) process.argv.push('--port', context.flags.port) + if (context.flags.procfile) execArgv.push('--procfile', context.flags.procfile) + if (context.flags.env) execArgv.push('--env', context.flags.env) + if (context.flags.port) execArgv.push('--port', context.flags.port) if (context.args.processname) { - process.argv.push(context.args.processname) + execArgv.push(context.args.processname) } else { let procfile = context.flags.procfile || 'Procfile' let procHash = require('foreman/lib/procfile.js').loadProc(procfile) let processes = Object.keys(procHash).filter((x) => x !== 'release') - process.argv.push(processes.join(',')) + execArgv.push(processes.join(',')) } - - require('foreman/nf.js') + yield require('../lib/fork_foreman')(execArgv) } const cmd = { diff --git a/commands/version.js b/commands/version.js index 2b8e6c1..5287198 100644 --- a/commands/version.js +++ b/commands/version.js @@ -4,8 +4,8 @@ const co = require('co') const cli = require('heroku-cli-util') function * run () { - process.argv = ['', 'heroku local', '--version'] - require('foreman/nf.js') + let execArgv = ['--version'] + yield require('../lib/fork_foreman')(execArgv) } module.exports = { diff --git a/lib/fork_foreman.js b/lib/fork_foreman.js new file mode 100644 index 0000000..e22e442 --- /dev/null +++ b/lib/fork_foreman.js @@ -0,0 +1,15 @@ +'use strict' + +const {fork} = require('child_process') +const path = require('path') + +module.exports = function (argv) { + let script = path.join(__dirname, 'run_foreman.js') + let nf = fork(script, argv, {stdio: 'inherit'}) + return new Promise((resolve, reject) => { + nf.on('exit', function (code) { + if (code !== 0) process.exit(code) + resolve() + }) + }) +} diff --git a/lib/run_foreman.js b/lib/run_foreman.js new file mode 100644 index 0000000..f55080d --- /dev/null +++ b/lib/run_foreman.js @@ -0,0 +1 @@ +require('foreman/nf.js') diff --git a/test/run.bats b/test/run.bats new file mode 100755 index 0000000..82563bf --- /dev/null +++ b/test/run.bats @@ -0,0 +1,17 @@ +#!/usr/bin/env bats + +setup() { + run heroku plugins:link . +} + +@test "run" { + run heroku local:run echo 'it works!' + echo $output + [ "$status" -eq 0 ] + [[ "$output" =~ "it works!" ]] +} + +@test "run propagates exit 1" { + run heroku local:run exit 1 + [ "$status" -eq 1 ] +} diff --git a/test/version.bats b/test/version.bats new file mode 100755 index 0000000..6f8d3ea --- /dev/null +++ b/test/version.bats @@ -0,0 +1,12 @@ +#!/usr/bin/env bats + +setup() { + run heroku plugins:link . +} + +@test "version" { + run heroku local:version + echo $output + [ "$status" -eq 0 ] + [[ "$output" =~ "2.0.0" ]] +}