Permalink
Browse files

refactor: use inherit instead of pipe (#22)

<!--
Thank you for your pull request. Please review below requirements.
Bug fixes and new features should include tests and possibly benchmarks.
Contributors guide: https://github.com/eggjs/egg/blob/master/CONTRIBUTING.md

感谢您贡献代码。请确认下列 checklist 的完成情况。
Bug 修复和新功能必须包含测试,必要时请附上性能测试。
Contributors guide: https://github.com/eggjs/egg/blob/master/CONTRIBUTING.md
-->

##### Checklist
<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->

- [ ] `npm test` passes
- [ ] tests and/or benchmarks are included
- [ ] documentation is changed or added
- [ ] commit message follows commit guidelines

##### Affected core subsystem(s)
<!-- Provide affected core subsystem(s). -->


##### Description of change
<!-- Provide a description of the change below this comment. -->

it can support tty
  • Loading branch information...
popomore committed Jan 5, 2019
1 parent d233b74 commit bf05a99da9661aa731c6938ec7e8443dd381d2eb
Showing with 6 additions and 14 deletions.
  1. +6 −14 lib/dev_server.js
@@ -35,22 +35,15 @@ class DevServer extends Base {
const env = Object.assign({}, process.env, devServer.env);
env.PATH = `${this.app.config.baseDir}/node_modules/.bin:${env.PATH}`;
const opt = {
stdio: 'pipe',
// disable stdout by default
stdio: [ 'inherit', 'ignore', 'inherit' ],
env,
};
if (devServer.cwd) opt.cwd = devServer.cwd;
if (devServer.debug) opt.stdio[1] = 'inherit';
const proc = this.proc = spawn(command, args, opt);
let stderr = '';
proc.stderr.on('data', data => {
stderr += data;
process.stderr.write(data);
});
proc.stdout.on('data', data => {
if (devServer.debug) process.stdout.write(data);
});

proc.once('error', err => this.exit(err, stderr));
proc.once('exit', code => this.exit(code, stderr));
proc.once('error', err => this.exit(err));
proc.once('exit', code => this.exit(code));
}

async checkPortExist() {
@@ -97,7 +90,7 @@ class DevServer extends Base {
this.proc = null;
}

exit(codeOrError, stderr) {
exit(codeOrError) {
const logger = this.app.coreLogger;
this.proc = null;

@@ -113,7 +106,6 @@ class DevServer extends Base {
codeOrError = new Error(message);
}

codeOrError.stderr = stderr;
logger.error(codeOrError);
}
}

0 comments on commit bf05a99

Please sign in to comment.