Skip to content

Commit 47f8e82

Browse files
authored
feat: eggScriptsConfig support node-options (#54)
1 parent 429d3c2 commit 47f8e82

File tree

6 files changed

+64
-4
lines changed

6 files changed

+64
-4
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@ $ eggctl stop [options]
7979

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

82-
```json
82+
```js
8383
{
8484
"eggScriptsConfig": {
8585
"port": 1234,
86-
"ignore-stderr": true
86+
"ignore-stderr": true,
87+
// will pass as `node --max-http-header-size=20000`
88+
"node-options--max-http-header-size": "20000"
8789
}
8890
}
8991
```
@@ -108,4 +110,4 @@ Please open an issue [here](https://github.com/eggjs/egg/issues?q=is%3Aissue+is%
108110

109111
This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Tue Mar 08 2022 09:52:13 GMT+0800`.
110112

111-
<!-- GITCONTRIBUTOR_END -->
113+
<!-- GITCONTRIBUTOR_END -->

lib/command.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,19 @@ class Command extends BaseCommand {
7373
// read argv from eggScriptsConfig in package.json
7474
if (eggScriptsConfig && typeof eggScriptsConfig === 'object') {
7575
for (const key in pkgInfo.eggScriptsConfig) {
76-
if (argv[key] == null) argv[key] = pkgInfo.eggScriptsConfig[key];
76+
const v = pkgInfo.eggScriptsConfig[key];
77+
// like https://github.com/node-modules/common-bin/blob/master/lib/helper.js#L180
78+
if (key.startsWith('node-options--')) {
79+
const newKey = key.replace('node-options--', '');
80+
if (execArgvObj[newKey] == null) {
81+
execArgvObj[newKey] = v;
82+
}
83+
} else {
84+
if (argv[key] == null) {
85+
// only set if key is not pass from command line
86+
argv[key] = v;
87+
}
88+
}
7789
}
7890
}
7991

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
'use strict';
2+
3+
module.exports = () => {
4+
console.log('process.execArgv:', process.execArgv);
5+
console.log('maxHeaderSize:', require('http').maxHeaderSize);
6+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
exports.keys = '123456';
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "example",
3+
"version": "1.0.0",
4+
"dependencies": {
5+
"egg": "^1.0.0"
6+
},
7+
"eggScriptsConfig": {
8+
"workers": 1,
9+
"node-options--max-http-header-size": "20000"
10+
}
11+
}

test/start.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,32 @@ describe('test/start.test.js', () => {
548548
});
549549
});
550550

551+
describe('read eggScriptsConfig', () => {
552+
let app;
553+
let fixturePath;
554+
555+
before(function* () {
556+
fixturePath = path.join(__dirname, 'fixtures/egg-scripts-node-options');
557+
yield utils.cleanup(fixturePath);
558+
});
559+
560+
after(function* () {
561+
app.proc.kill('SIGTERM');
562+
yield utils.cleanup(fixturePath);
563+
});
564+
565+
it('should start', function* () {
566+
app = coffee.fork(eggBin, [ 'start', '--workers=1', fixturePath ]);
567+
app.debug();
568+
app.expect('code', 0);
569+
570+
yield sleep(waitTime);
571+
572+
assert(app.stderr === '');
573+
assert(app.stdout.match(/maxHeaderSize: 20000/));
574+
});
575+
});
576+
551577
describe('subDir as baseDir', () => {
552578
let app;
553579
const rootDir = path.join(__dirname, '..');

0 commit comments

Comments
 (0)