Skip to content

Commit

Permalink
feat: inject moduleConfig read from tegg-config app.moduleConfigs config
Browse files Browse the repository at this point in the history
  • Loading branch information
nightink committed Dec 5, 2023
1 parent 81d3f74 commit 8e1f05a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion plugin/tegg/lib/ModuleConfigLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export class ModuleConfigLoader {
const moduleConfigMap: Record<string, ModuleConfigHolder> = {};
for (const reference of this.app.moduleReferences) {
const moduleName = ModuleConfigUtil.readModuleNameSync(reference.path);
const config = ModuleConfigUtil.loadModuleConfigSync(reference.path, undefined, this.app.config.env) || {};
// first read @eggjs/tegg-config moduleConfigs
const config = this.app.moduleConfigs[moduleName].config || ModuleConfigUtil.loadModuleConfigSync(reference.path, undefined, this.app.config.env) || {};
moduleConfigMap[moduleName] = {
name: moduleName,
reference: {
Expand Down
14 changes: 14 additions & 0 deletions plugin/tegg/test/ModuleConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,18 @@ describe('test/ModuleConfig.test.ts', () => {
});
});
});

it('should work with overwrite', async () => {
mm(app.moduleConfigs.simple.config, 'features', { dynamic: { foo: 'bar', bar: 'overwrite foo' } });

await app.httpRequest()
.get('/config')
.expect(200)
.expect(res => {
assert.deepStrictEqual(res.body, {
moduleConfigs: { features: { dynamic: { foo: 'bar', bar: 'overwrite foo' } } },
moduleConfig: { features: { dynamic: { foo: 'bar', bar: 'overwrite foo' } } },
});
});
});
});

0 comments on commit 8e1f05a

Please sign in to comment.