Skip to content

Commit

Permalink
fix: ignore duplicated module
Browse files Browse the repository at this point in the history
  • Loading branch information
killagu committed Feb 19, 2024
1 parent 57a1adc commit 19c48f1
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 7 deletions.
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;
}
}
33 changes: 33 additions & 0 deletions plugin/config/test/DuplicateOptionalModule.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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 () => {
console.log('app.moduleReferences: ', app.moduleReferences);
assert.equal(app.moduleReferences.length, 3);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { SingletonProto, Inject } from 'core/core-decorator';

Check failure on line 1 in plugin/config/test/fixtures/apps/duplicate-optional-module/app/modules/root/Root.ts

View workflow job for this annotation

GitHub Actions / Runner-ubuntu (20)

Unable to resolve path to module 'core/core-decorator'

Check failure on line 1 in plugin/config/test/fixtures/apps/duplicate-optional-module/app/modules/root/Root.ts

View workflow job for this annotation

GitHub Actions / Runner-ubuntu (18)

Unable to resolve path to module 'core/core-decorator'

Check failure on line 1 in plugin/config/test/fixtures/apps/duplicate-optional-module/app/modules/root/Root.ts

View workflow job for this annotation

GitHub Actions / Runner-ubuntu (16)

Unable to resolve path to module 'core/core-decorator'

Check failure on line 1 in plugin/config/test/fixtures/apps/duplicate-optional-module/app/modules/root/Root.ts

View workflow job for this annotation

GitHub Actions / Runner-windows (16)

Unable to resolve path to module 'core/core-decorator'

Check failure on line 1 in plugin/config/test/fixtures/apps/duplicate-optional-module/app/modules/root/Root.ts

View workflow job for this annotation

GitHub Actions / Runner-ubuntu (14)

Unable to resolve path to module 'core/core-decorator'

Check failure on line 1 in plugin/config/test/fixtures/apps/duplicate-optional-module/app/modules/root/Root.ts

View workflow job for this annotation

GitHub Actions / Runner-windows (20)

Unable to resolve path to module 'core/core-decorator'

Check failure on line 1 in plugin/config/test/fixtures/apps/duplicate-optional-module/app/modules/root/Root.ts

View workflow job for this annotation

GitHub Actions / Runner-windows (14)

Unable to resolve path to module 'core/core-decorator'

Check failure on line 1 in plugin/config/test/fixtures/apps/duplicate-optional-module/app/modules/root/Root.ts

View workflow job for this annotation

GitHub Actions / Runner-windows (18)

Unable to resolve path to module 'core/core-decorator'

Check failure on line 1 in plugin/config/test/fixtures/apps/duplicate-optional-module/app/modules/root/Root.ts

View workflow job for this annotation

GitHub Actions / Runner-macos (16)

Unable to resolve path to module 'core/core-decorator'

Check failure on line 1 in plugin/config/test/fixtures/apps/duplicate-optional-module/app/modules/root/Root.ts

View workflow job for this annotation

GitHub Actions / Runner-macos (14)

Unable to resolve path to module 'core/core-decorator'

Check failure on line 1 in plugin/config/test/fixtures/apps/duplicate-optional-module/app/modules/root/Root.ts

View workflow job for this annotation

GitHub Actions / Runner-macos (20)

Unable to resolve path to module 'core/core-decorator'

Check failure on line 1 in plugin/config/test/fixtures/apps/duplicate-optional-module/app/modules/root/Root.ts

View workflow job for this annotation

GitHub Actions / Runner-macos (18)

Unable to resolve path to module 'core/core-decorator'
import { UsedProto } from 'used/Used';

Check failure on line 2 in plugin/config/test/fixtures/apps/duplicate-optional-module/app/modules/root/Root.ts

View workflow job for this annotation

GitHub Actions / Runner-ubuntu (20)

Unable to resolve path to module 'used/Used'

Check failure on line 2 in plugin/config/test/fixtures/apps/duplicate-optional-module/app/modules/root/Root.ts

View workflow job for this annotation

GitHub Actions / Runner-ubuntu (18)

Unable to resolve path to module 'used/Used'

Check failure on line 2 in plugin/config/test/fixtures/apps/duplicate-optional-module/app/modules/root/Root.ts

View workflow job for this annotation

GitHub Actions / Runner-ubuntu (16)

Unable to resolve path to module 'used/Used'

Check failure on line 2 in plugin/config/test/fixtures/apps/duplicate-optional-module/app/modules/root/Root.ts

View workflow job for this annotation

GitHub Actions / Runner-windows (16)

Unable to resolve path to module 'used/Used'

Check failure on line 2 in plugin/config/test/fixtures/apps/duplicate-optional-module/app/modules/root/Root.ts

View workflow job for this annotation

GitHub Actions / Runner-ubuntu (14)

Unable to resolve path to module 'used/Used'

Check failure on line 2 in plugin/config/test/fixtures/apps/duplicate-optional-module/app/modules/root/Root.ts

View workflow job for this annotation

GitHub Actions / Runner-windows (20)

Unable to resolve path to module 'used/Used'

Check failure on line 2 in plugin/config/test/fixtures/apps/duplicate-optional-module/app/modules/root/Root.ts

View workflow job for this annotation

GitHub Actions / Runner-windows (14)

Unable to resolve path to module 'used/Used'

Check failure on line 2 in plugin/config/test/fixtures/apps/duplicate-optional-module/app/modules/root/Root.ts

View workflow job for this annotation

GitHub Actions / Runner-windows (18)

Unable to resolve path to module 'used/Used'

Check failure on line 2 in plugin/config/test/fixtures/apps/duplicate-optional-module/app/modules/root/Root.ts

View workflow job for this annotation

GitHub Actions / Runner-macos (16)

Unable to resolve path to module 'used/Used'

Check failure on line 2 in plugin/config/test/fixtures/apps/duplicate-optional-module/app/modules/root/Root.ts

View workflow job for this annotation

GitHub Actions / Runner-macos (14)

Unable to resolve path to module 'used/Used'

Check failure on line 2 in plugin/config/test/fixtures/apps/duplicate-optional-module/app/modules/root/Root.ts

View workflow job for this annotation

GitHub Actions / Runner-macos (20)

Unable to resolve path to module 'used/Used'

Check failure on line 2 in plugin/config/test/fixtures/apps/duplicate-optional-module/app/modules/root/Root.ts

View workflow job for this annotation

GitHub Actions / Runner-macos (18)

Unable to resolve path to module 'used/Used'

@SingletonProto()
export class RootProto {
@Inject() usedProto: UsedProto;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "root",
"eggModule": {
"name": "root"
}
}
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;
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 19c48f1

Please sign in to comment.