Skip to content

Commit 19c48f1

Browse files
committed
fix: ignore duplicated module
1 parent 57a1adc commit 19c48f1

7 files changed

Lines changed: 93 additions & 7 deletions

File tree

plugin/config/lib/ModuleScanner.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,17 @@ export class ModuleScanner {
2828
});
2929
const frameworkDir = path.dirname(frameworkPkg);
3030
const optionalModuleReferences = ModuleConfigUtil.readModuleReference(frameworkDir, this.readModuleOptions || {});
31-
return [
31+
const result = [
3232
...moduleReferences,
33-
...optionalModuleReferences.map(t => {
34-
return {
35-
...t,
36-
optional: true,
37-
};
38-
}),
3933
];
34+
for (const optionalModuleReference of optionalModuleReferences) {
35+
if (!result.some(t => t.path === optionalModuleReference.path)) {
36+
result.push({
37+
...optionalModuleReference,
38+
optional: true,
39+
});
40+
}
41+
}
42+
return result;
4043
}
4144
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import mm from 'egg-mock';
2+
import assert from 'assert';
3+
import path from 'path';
4+
5+
describe('test/DuplicateOptionalModule.test.ts', () => {
6+
let app;
7+
const fixturesPath = path.join(__dirname, './fixtures/apps/duplicate-optional-module');
8+
9+
after(async () => {
10+
await app.close();
11+
});
12+
13+
afterEach(() => {
14+
mm.restore();
15+
});
16+
17+
before(async () => {
18+
mm(process.env, 'EGG_TYPESCRIPT', true);
19+
mm(process, 'cwd', () => {
20+
return path.join(__dirname, '..');
21+
});
22+
app = mm.app({
23+
baseDir: fixturesPath,
24+
framework: require.resolve('egg'),
25+
});
26+
await app.ready();
27+
});
28+
29+
it('should work', async () => {
30+
console.log('app.moduleReferences: ', app.moduleReferences);
31+
assert.equal(app.moduleReferences.length, 3);
32+
});
33+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { SingletonProto, Inject } from 'core/core-decorator';
2+
import { UsedProto } from 'used/Used';
3+
4+
@SingletonProto()
5+
export class RootProto {
6+
@Inject() usedProto: UsedProto;
7+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "root",
3+
"eggModule": {
4+
"name": "root"
5+
}
6+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
const path = require('path');
4+
5+
module.exports = function(appInfo) {
6+
const config = {
7+
keys: 'test key',
8+
customLogger: {
9+
xxLogger: {
10+
file: path.join(appInfo.root, 'logs/xx.log'),
11+
},
12+
},
13+
security: {
14+
csrf: {
15+
ignoreJSON: false,
16+
}
17+
},
18+
};
19+
return config;
20+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
exports.tracer = {
4+
package: 'egg-tracer',
5+
enable: true,
6+
};
7+
8+
exports.watcher = false;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "egg-app",
3+
"egg": {
4+
"framework": "foo"
5+
},
6+
"dependencies": {
7+
"used": "*"
8+
}
9+
}

0 commit comments

Comments
 (0)