Skip to content

Commit

Permalink
fix: ignore duplicated module (#191)
Browse files Browse the repository at this point in the history
<!--
Thank you for your pull request. Please review below requirements.
Bug fixes and new features should include tests and possibly benchmarks.
Contributors guide:
https://github.com/eggjs/egg/blob/master/CONTRIBUTING.md

感谢您贡献代码。请确认下列 checklist 的完成情况。
Bug 修复和新功能必须包含测试,必要时请附上性能测试。
Contributors guide:
https://github.com/eggjs/egg/blob/master/CONTRIBUTING.md
-->

##### Checklist
<!-- Remove items that do not apply. For completed items, change [ ] to
[x]. -->

- [ ] `npm test` passes
- [ ] tests and/or benchmarks are included
- [ ] documentation is changed or added
- [ ] commit message follows commit guidelines

##### Affected core subsystem(s)
<!-- Provide affected core subsystem(s). -->


##### Description of change
<!-- Provide a description of the change below this comment. -->

<!--
- any feature?
- close https://github.com/eggjs/egg/ISSUE_URL
-->
  • Loading branch information
killagu authored Feb 19, 2024
1 parent 57a1adc commit 263467f
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ plugin/tegg/test/fixtures/apps/**/*.js
!standalone/standalone/test/fixtures/**/node_modules
!standalone/standalone/test/fixtures/**/node_modules/**/*.js
!plugin/tegg/test/fixtures/**/node_modules
!plugin/config/test/fixtures/**/node_modules
17 changes: 10 additions & 7 deletions plugin/config/lib/ModuleScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ export class ModuleScanner {
});
const frameworkDir = path.dirname(frameworkPkg);
const optionalModuleReferences = ModuleConfigUtil.readModuleReference(frameworkDir, this.readModuleOptions || {});
return [
const result = [
...moduleReferences,
...optionalModuleReferences.map(t => {
return {
...t,
optional: true,
};
}),
];
for (const optionalModuleReference of optionalModuleReferences) {
if (!result.some(t => t.path === optionalModuleReference.path)) {
result.push({
...optionalModuleReference,
optional: true,
});
}
}
return result;
}
}
32 changes: 32 additions & 0 deletions plugin/config/test/DuplicateOptionalModule.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import mm from 'egg-mock';
import assert from 'assert';
import path from 'path';

describe('test/DuplicateOptionalModule.test.ts', () => {
let app;
const fixturesPath = path.join(__dirname, './fixtures/apps/duplicate-optional-module');

after(async () => {
await app.close();
});

afterEach(() => {
mm.restore();
});

before(async () => {
mm(process.env, 'EGG_TYPESCRIPT', true);
mm(process, 'cwd', () => {
return path.join(__dirname, '..');
});
app = mm.app({
baseDir: fixturesPath,
framework: require.resolve('egg'),
});
await app.ready();
});

it('should work', async () => {
assert.equal(app.moduleReferences.length, 2);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

const path = require('path');

module.exports = function(appInfo) {
const config = {
keys: 'test key',
customLogger: {
xxLogger: {
file: path.join(appInfo.root, 'logs/xx.log'),
},
},
security: {
csrf: {
ignoreJSON: false,
}
},
};
return config;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

exports.tracer = {
package: 'egg-tracer',
enable: true,
};

exports.watcher = false;

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.

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.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "egg-app",
"egg": {
"framework": "foo"
},
"dependencies": {
"used": "*"
}
}

0 comments on commit 263467f

Please sign in to comment.