Skip to content

Commit 4663c73

Browse files
committed
fix: require support paths
1 parent aa3034f commit 4663c73

File tree

7 files changed

+23
-11
lines changed

7 files changed

+23
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
},
3434
"homepage": "https://github.com/eggjs/cluster#readme",
3535
"dependencies": {
36-
"@eggjs/utils": "^4.1.6",
36+
"@eggjs/utils": "^4.2.1",
3737
"@fengmk2/ps-tree": "^2.0.1",
3838
"cfork": "^2.0.0",
3939
"cluster-reload": "^2.0.0",

src/agent_worker.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ async function main() {
1818
// $ node agent_worker.js options
1919
const options = JSON.parse(process.argv[2]) as {
2020
framework: string;
21+
baseDir: string;
2122
require?: string[];
2223
startMode?: 'process' | 'worker_threads';
2324
};
2425
if (options.require) {
2526
// inject
26-
options.require.forEach(mod => {
27-
require(mod);
28-
});
27+
for (const mod of options.require) {
28+
await importModule(mod, {
29+
paths: [ options.baseDir ],
30+
});
31+
}
2932
}
3033

3134
let AgentWorker: typeof BaseAgentWorker;
@@ -36,7 +39,9 @@ async function main() {
3639
}
3740

3841
const consoleLogger = new ConsoleLogger({ level: process.env.EGG_AGENT_WORKER_LOGGER_LEVEL });
39-
const { Agent } = await importModule(options.framework);
42+
const { Agent } = await importModule(options.framework, {
43+
paths: [ options.baseDir ],
44+
});
4045
debug('new Agent with options %j', options);
4146
let agent: any;
4247
try {

src/app_worker.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ async function main() {
1515
// $ node app_worker.js options-json-string
1616
const options = JSON.parse(process.argv[2]) as {
1717
framework: string;
18+
baseDir: string;
1819
require?: string[];
1920
startMode?: 'process' | 'worker_threads';
2021
port: number;
@@ -26,7 +27,9 @@ async function main() {
2627
if (options.require) {
2728
// inject
2829
for (const mod of options.require) {
29-
await importModule(mod);
30+
await importModule(mod, {
31+
paths: [ options.baseDir ],
32+
});
3033
}
3134
}
3235

@@ -40,7 +43,9 @@ async function main() {
4043
const consoleLogger = new ConsoleLogger({
4144
level: process.env.EGG_APP_WORKER_LOGGER_LEVEL,
4245
});
43-
const { Application } = await importModule(options.framework);
46+
const { Application } = await importModule(options.framework, {
47+
paths: [ options.baseDir ],
48+
});
4449
debug('[app_worker:%s] new Application with options %j', process.pid, options);
4550
let app: any;
4651
try {

src/utils/options.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ export async function parseOptions(options?: ClusterOptions) {
106106
framework: options.framework ?? options.customEgg,
107107
});
108108

109-
const egg = await importModule(options.framework);
109+
const egg = await importModule(options.framework, {
110+
paths: [ options.baseDir! ],
111+
});
110112
assert(egg.Application, `should define Application in ${options.framework}`);
111113
assert(egg.Agent, `should define Agent in ${options.framework}`);
112114

test/agent_worker.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ describe('test/agent_worker.test.ts', () => {
1515

1616
it('support config agent debug port', () => {
1717
mm(process.env, 'EGG_AGENT_DEBUG_PORT', '15800');
18-
app = cluster('apps/agent-debug-port', { isDebug: true } as any);
18+
app = cluster('apps/agent-debug-port', { isDebug: true, require: [ './inject1.js' ] } as any);
1919
return app
2020
// .debug()
21+
.expect('stdout', /@@inject1\.js run/)
2122
.expect('stdout', /=15800/)
2223
.end();
2324
});
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
module.exports = () => {
42
console.log('agent argv: ', process.execArgv);
53
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('@@inject1.js run');

0 commit comments

Comments
 (0)