diff --git a/src/loader/types.ts b/src/loader/types.ts index a3d82e4..6ed9ea7 100644 --- a/src/loader/types.ts +++ b/src/loader/types.ts @@ -1,8 +1,10 @@ import { Container } from '@artus/injection'; import { ScanPolicy } from '../constant'; +import { PluginConfigItem } from '../plugin/types'; interface Manifest { items: ManifestItem[]; + pluginConfig?: Record; relative?: boolean; } diff --git a/src/scanner/scan.ts b/src/scanner/scan.ts index e4e6401..a686414 100644 --- a/src/scanner/scan.ts +++ b/src/scanner/scan.ts @@ -129,9 +129,18 @@ export class Scanner { // 4. scan all file in app await this.walk(root, this.formatWalkOptions('app', root, '')); + const relative = this.options.useRelativePath; + if (relative) { + for (const [pluginName, pluginConfigItem] of Object.entries(pluginConfig)) { + if (pluginConfigItem.path) { + pluginConfig[pluginName].path = path.relative(root, pluginConfigItem.path); + } + } + } const result: Manifest = { - items: this.getItemsFromMap(this.options.useRelativePath, root, env), - relative: this.options.useRelativePath, + pluginConfig, + items: this.getItemsFromMap(relative, root, env), + relative, }; return result; } diff --git a/test/scanner.test.ts b/test/scanner.test.ts index 5204fdb..f93c1e0 100644 --- a/test/scanner.test.ts +++ b/test/scanner.test.ts @@ -27,6 +27,11 @@ describe('test/scanner.test.ts', () => { expect(manifest.items.filter(item => item.unitName === 'redis').length).toBe(2); expect(manifest.items.filter(item => item.unitName === 'mysql').length).toBe(0); expect(manifest.items.filter(item => item.source === 'app').length).toBe(8); + expect(manifest.pluginConfig).toStrictEqual({ + redis: { enable: true, path: path.join('src', 'redis_plugin') }, + mysql: { enable: false, path: path.join('src', 'mysql_plugin') }, + testDuplicate: { enable: false, path: path.join('..', '..', '..', 'node_modules', '@artus', 'injection', 'lib') }, + }); const { dev: devManifest } = scanResults; // console.log('devManifest', devManifest); @@ -36,6 +41,11 @@ describe('test/scanner.test.ts', () => { expect(devManifest.items.filter(item => item.loader === 'config').length).toBe(2); expect(devManifest.items.filter(item => item.loader === 'plugin-meta').length).toBe(2); expect(devManifest.items.find(item => item.unitName === 'testDuplicate')).toBeDefined(); + expect(devManifest.pluginConfig).toStrictEqual({ + redis: { enable: true, path: path.join('src', 'redis_plugin') }, + mysql: { enable: false, path: path.join('src', 'mysql_plugin') }, + testDuplicate: { enable: true, path: path.join('src', 'test_duplicate_plugin') }, + }); }); it('should scan module with custom loader', async () => {