Skip to content

Commit

Permalink
feat: commands support specific execArgv(harmony) (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
dead-horse authored and popomore committed Feb 15, 2017
1 parent bc11a4e commit 0c7108b
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ coverage/
!test/fixtures/custom-framework-app/node_modules/
.tmp
.vscode
*.log
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions lib/cov_command.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 1 addition & 4 deletions lib/debug_command.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
}

Expand Down
12 changes: 5 additions & 7 deletions lib/dev_command.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
13 changes: 13 additions & 0 deletions lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
1 change: 1 addition & 0 deletions lib/test_command.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/egg-debug.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
8 changes: 8 additions & 0 deletions test/egg-dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/demo-app/node_modules/aliyun-egg/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0c7108b

Please sign in to comment.