diff --git a/lib/dev_command.js b/lib/dev_command.js index f7fb7df8..53865b27 100644 --- a/lib/dev_command.js +++ b/lib/dev_command.js @@ -5,23 +5,27 @@ 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) : []; + args.push('--baseDir'); args.push(cwd); args.push('--cluster'); args.push('1'); const eggPath = this.getFrameworkOrEggPath(cwd); + if (eggPath) { args.push(`--eggPath=${eggPath}`); } const options = { env: process.env, + execArgv, }; options.env.NODE_ENV = options.env.NODE_ENV || 'development'; - debug('%s %j %j', this.helper.serverBin, args, options.env.NODE_ENV); + debug('%s %j %j, %j', this.helper.serverBin, args, execArgv, options.env.NODE_ENV); yield this.helper.checkDeps(); yield this.helper.forkNode(this.helper.serverBin, args, options); } diff --git a/lib/start-cluster b/lib/start-cluster index 1536677e..90e57ca9 100755 --- a/lib/start-cluster +++ b/lib/start-cluster @@ -9,6 +9,7 @@ commander .option('--baseDir [baseDir]') .option('--port [port]') .option('--cluster [workers]') + .allowUnknownOption(true) .parse(process.argv); const baseDir = commander.baseDir; diff --git a/package.json b/package.json index f607aae7..7fa51f32 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "common-bin": "^1.0.0", "debug": "^2.2.0", "egg-utils": "^1.0.0", - "glob": "^7.0.5", + "glob": "^7.1.0", "istanbul": "^0.4.0", "mkdirp": "^0.5.1", "mocha": "^3.0.0", @@ -20,8 +20,8 @@ "thunk-mocha": "^1.0.3" }, "devDependencies": { - "autod": "^2.7.0", - "coffee": "^3.2.4", + "autod": "^2.7.1", + "coffee": "^3.2.5", "egg-ci": "1", "eslint": "3", "eslint-config-egg": "3", diff --git a/test/egg-dev.test.js b/test/egg-dev.test.js index 8ec03cfb..e1f51556 100644 --- a/test/egg-dev.test.js +++ b/test/egg-dev.test.js @@ -26,4 +26,26 @@ describe('egg-bin dev', () => { .expect('code', 0) .end(done); }); + + it('should startCluster with execArgv --debug', done => { + coffee.fork(eggBin, [ 'dev', '--debug=7000' ], { + cwd: appdir, + }) + // .debug() + .expect('stdout', `{"baseDir":"${appdir}","workers":1}\n`) + .expect('stderr', /Debugger listening on .*7000/) + .expect('code', 0) + .end(done); + }); + + it.skip('should startCluster with execArgv --inspect', done => { + coffee.fork(eggBin, [ 'dev', '--inspect=7000' ], { + cwd: appdir, + }) + // .debug() + .expect('stdout', `{"baseDir":"${appdir}","workers":1}\n`) + .expect('stderr', /Debugger listening on .*7000/) + .expect('code', 0) + .end(done); + }); });