diff --git a/.gitignore b/.gitignore index d7987c7e..a9f91933 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ coverage/ !test/fixtures/custom-framework-app/node_modules/ .tmp .vscode +*.log diff --git a/README.md b/README.md index 64c942c6..543433a7 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,17 @@ Add `egg-bin` to `package.json` scripts: ## Command +All the commands support these specific v8 options: + +- `--debug` +- `--inspect` +- `--harmony*` +- `--es_staging` + +```bash +$ egg-bin [command] --debug --es_staging +``` + ### dev Start dev cluster on `local` env, it will start a master, an agent and a worker. diff --git a/lib/cov_command.js b/lib/cov_command.js index f953f9e3..9bdd7007 100644 --- a/lib/cov_command.js +++ b/lib/cov_command.js @@ -34,6 +34,7 @@ class CovCommand extends Command { process.env.istanbul_bin_path = covFile; const opt = { env: process.env, + execArgv: this.helper.formatExecArgv(args), }; const coverageDir = path.join(cwd, 'coverage'); rimraf.sync(coverageDir); diff --git a/lib/debug_command.js b/lib/debug_command.js index d5e32f8d..f5c44862 100644 --- a/lib/debug_command.js +++ b/lib/debug_command.js @@ -16,6 +16,7 @@ class DebugCommand extends Command { const options = { env: Object.assign({}, process.env), + execArgv: this.helper.formatExecArgv(args).concat([ '--inspect' ]), }; options.env.NODE_ENV = options.env.NODE_ENV || 'development'; @@ -26,10 +27,6 @@ class DebugCommand extends Command { debug('%s %s, NODE_ENV:%s, cwd:%s', this.helper.serverBin, args.join(' '), options.env.NODE_ENV, process.cwd()); - options.execArgv = [ - '--inspect', - ]; - this.helper.forkNode(this.helper.serverBin, args, options); } diff --git a/lib/dev_command.js b/lib/dev_command.js index e6aede56..7046a76e 100644 --- a/lib/dev_command.js +++ b/lib/dev_command.js @@ -4,22 +4,20 @@ const debug = require('debug')('egg-bin:dev'); const Command = require('./command'); class DevCommand extends Command { - * run(cwd, args) { - const execArgv = args ? args.filter(str => str.indexOf('--debug') === 0 || str.indexOf('--inspect') === 0) : []; - + * run(cwd, args = []) { const eggPath = this.getFrameworkOrEggPath(cwd); - args = yield this.helper.formatArgs(cwd, args, { eggPath }); + const devArgs = yield this.helper.formatArgs(cwd, args, { eggPath }); const options = { env: Object.assign({}, process.env), - execArgv, + execArgv: this.helper.formatExecArgv(args), }; options.env.NODE_ENV = options.env.NODE_ENV || 'development'; - debug('%s %j %j, %j', this.helper.serverBin, args, execArgv, options.env.NODE_ENV); + debug('%s %j %j, %j', this.helper.serverBin, devArgs, options.execArgv, options.env.NODE_ENV); yield this.helper.checkDeps(); - yield this.helper.forkNode(this.helper.serverBin, args, options); + yield this.helper.forkNode(this.helper.serverBin, devArgs, options); } help() { diff --git a/lib/helper.js b/lib/helper.js index 965e1e55..e59e06b1 100644 --- a/lib/helper.js +++ b/lib/helper.js @@ -83,3 +83,16 @@ exports.formatArgs = function* (cwd, args, options) { } return args; }; + +exports.formatExecArgv = function(args = []) { + return process.execArgv.concat(args.filter(passbyArgv)); +}; + +function passbyArgv(arg) { + if (typeof arg !== 'string') return false; + + return arg.startsWith('--debug') + || arg.startsWith('--inspect') + || arg.startsWith('--es_staging') + || arg.startsWith('--harmony'); +} diff --git a/lib/test_command.js b/lib/test_command.js index 89b226d7..b0b74d41 100644 --- a/lib/test_command.js +++ b/lib/test_command.js @@ -11,6 +11,7 @@ class TestCommand extends Command { env: Object.assign({}, process.env, { NODE_ENV: 'test', }), + execArgv: this.helper.formatExecArgv(args), }; const mochaFile = require.resolve('mocha/bin/_mocha'); yield this.helper.forkNode(mochaFile, newArgs, opt); diff --git a/test/egg-debug.test.js b/test/egg-debug.test.js index f778a542..3b946b8a 100644 --- a/test/egg-debug.test.js +++ b/test/egg-debug.test.js @@ -28,7 +28,7 @@ describe('egg-bin debug', () => { it('should startCluster with port', done => { coffee.fork(eggBin, [ 'debug', '--port', '6001' ], { cwd: appdir }) // .debug() - .expect('stdout', `{"baseDir":"${appdir}","workers":1,"port":"6001","customEgg":"${customEgg}"}\n`) + .expect('stdout', `{"baseDir":"${appdir}","workers":1,"port":"6001","customEgg":"${customEgg}"}\nprocess.execArgv: [ '--inspect' ]\n`) .expect('code', 0) .end(done); }); diff --git a/test/egg-dev.test.js b/test/egg-dev.test.js index 5535b7b2..f8e80c37 100644 --- a/test/egg-dev.test.js +++ b/test/egg-dev.test.js @@ -17,6 +17,14 @@ describe('egg-bin dev', () => { .end(done); }); + it('should startCluster with --harmony success', done => { + coffee.fork(eggBin, [ 'dev', '--harmony' ], { cwd: appdir }) + // .debug() + .expect('stdout', `{"baseDir":"${appdir}","workers":1,"customEgg":"${customEgg}"}\nprocess.execArgv: [ '--harmony' ]\n`) + .expect('code', 0) + .end(done); + }); + it('should startCluster with --port', done => { coffee.fork(eggBin, [ 'dev', '--port', '6001' ], { cwd: appdir }) // .debug() diff --git a/test/fixtures/demo-app/node_modules/aliyun-egg/index.js b/test/fixtures/demo-app/node_modules/aliyun-egg/index.js index b42f805a..81de7666 100644 --- a/test/fixtures/demo-app/node_modules/aliyun-egg/index.js +++ b/test/fixtures/demo-app/node_modules/aliyun-egg/index.js @@ -2,4 +2,7 @@ exports.startCluster = options => { console.log('%j', options); + if (process.execArgv.length) { + console.log('process.execArgv:', process.execArgv); + } };