Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ run/
.DS_Store
*.swp
test/fixtures/ts/app/controller/home.js
test/fixtures/ts-pkg/app/controller/home.js
test/fixtures/ts-pkg/app/controller/home.js
!test/fixtures/**/node_modules
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ $ eggctl stop [--title=example]
- **Options**
- `title` - process title description, use for kill grep.

## Options in `package.json`

In addition to the command line specification, options can also be specified in `package.json`. However, the command line designation takes precedence.

```json
{
"eggScriptsConfig": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是否改成 config 节点下比较好?

{
  "config": {
    "eggScripts": { ... }
  }
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现在有 egg, eggPlugin 等一系列配置了,还是先平铺吧?

"port": 1234,
"ignore-stderr": true
}
}
```


## Questions & Suggestions

Please open an issue [here](https://github.com/eggjs/egg/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc).
Expand Down
2 changes: 0 additions & 2 deletions lib/cmd/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ class StartCommand extends Command {

* run(context) {
const { argv, env, cwd, execArgv } = context;

const HOME = homedir();
const logDir = path.join(HOME, 'logs');

Expand Down Expand Up @@ -243,7 +242,6 @@ class StartCommand extends Command {
} catch (err) {
this.logger.error('ignore tail error: %s', err);
}

isSuccess = ignoreStdErr;
this.logger.error('Start got error, see %s', stderr);
this.logger.error('Or use `--ignore-stderr` to ignore stderr at startup.');
Expand Down
7 changes: 7 additions & 0 deletions lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ class Command extends BaseCommand {
if (pkgInfo && pkgInfo.egg && pkgInfo.egg.typescript) {
argv.sourcemap = true;
}

// read argv from eggScriptsConfig in package.json
if (pkgInfo && pkgInfo.eggScriptsConfig && typeof pkgInfo.eggScriptsConfig === 'object') {
for (const key in pkgInfo.eggScriptsConfig) {
if (argv[key] == null) argv[key] = pkgInfo.eggScriptsConfig[key];
Copy link
Member

@atian25 atian25 Apr 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

结合 https://github.com/node-modules/common-bin/blob/master/lib/helper.js#L180

应该可以通过 node-options--max-http-header-size 的方式来注入 Node 启动参数

目前不支持,提了个 PR:#54

}
}
}

// execArgv
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/egg-scripts-config/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

const sleep = require('mz-modules/sleep');

module.exports = app => {
if (process.env.ERROR) {
app.logger.error(new Error(process.env.ERROR));
}

app.beforeStart(function* () {
yield sleep(process.env.WAIT_TIME);
});
};
8 changes: 8 additions & 0 deletions test/fixtures/egg-scripts-config/config/config.default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

exports.keys = '123456';

exports.logger = {
level: 'WARN',
consoleLevel: 'WARN',
};

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

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

15 changes: 15 additions & 0 deletions test/fixtures/egg-scripts-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "example",
"version": "1.0.0",
"dependencies": {
"egg": "^1.0.0"
},
"egg": {
"framework": "custom-framework"
},
"eggScriptsConfig": {
"ignore-stderr": true,
"daemon": true,
"workers": 1
}
}
24 changes: 22 additions & 2 deletions test/start.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,11 +607,14 @@ describe('test/start.test.js', () => {
});

describe('check status', () => {
const cwd = path.join(__dirname, 'fixtures/status');
let cwd;
beforeEach(() => {
cwd = path.join(__dirname, 'fixtures/status');
});

after(function* () {
yield coffee.fork(eggBin, [ 'stop', cwd ])
// .debug()
// .debug()
.end();
yield utils.cleanup(cwd);
});
Expand Down Expand Up @@ -642,6 +645,23 @@ describe('test/start.test.js', () => {
.end();
});

it('should status check fail `--ignore-stderr` in package.json, exit with 0', function* () {
cwd = path.join(__dirname, 'fixtures/egg-scripts-config');
mm(process.env, 'WAIT_TIME', 5000);
mm(process.env, 'ERROR', 'error message');

let stderr = path.join(homePath, 'logs/master-stderr.log');
if (isWin) stderr = stderr.replace(/\\/g, '\\\\');

const app = coffee.fork(eggBin, [ 'start' ], { cwd });
// app.debug();
// TODO: find a windows replacement for tail command
if (!isWin) app.expect('stderr', /nodejs.Error: error message/);
yield app.expect('stderr', new RegExp(`Start got error, see ${stderr}`))
.expect('code', 0)
.end();
});

it('should status check fail, exit with 1', function* () {
mm(process.env, 'WAIT_TIME', 5000);
mm(process.env, 'ERROR', 'error message');
Expand Down