fix: 修复插件包路径策略DI配置
This commit is contained in:
parent
500f5c69f1
commit
5b22703949
@ -1,4 +1,4 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Inject, Injectable, Optional } from '@nestjs/common';
|
||||||
import { existsSync, statSync } from 'node:fs';
|
import { existsSync, statSync } from 'node:fs';
|
||||||
import { isAbsolute, relative, resolve, sep } from 'node:path';
|
import { isAbsolute, relative, resolve, sep } from 'node:path';
|
||||||
|
|
||||||
@ -9,6 +9,9 @@ const DEFAULT_BUILTIN_PACKAGE_ROOT = resolve(
|
|||||||
'qqbot',
|
'qqbot',
|
||||||
'plugins',
|
'plugins',
|
||||||
);
|
);
|
||||||
|
export const QQBOT_PLUGIN_PACKAGE_CONTROLLED_ROOTS = Symbol(
|
||||||
|
'QQBOT_PLUGIN_PACKAGE_CONTROLLED_ROOTS',
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restricts QQBot plugin package discovery and entry resolution to controlled package roots.
|
* Restricts QQBot plugin package discovery and entry resolution to controlled package roots.
|
||||||
@ -19,10 +22,16 @@ export class QqbotPluginPackagePathPolicyService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a path policy for package roots that the plugin platform may scan.
|
* Creates a path policy for package roots that the plugin platform may scan.
|
||||||
* @param controlledRoots - Directory roots that may contain one-level QQBot plugin package folders.
|
* @param controlledRoots - Optional DI-provided package roots; production omits this token so the platform scans the standard built-in plugin root.
|
||||||
*/
|
*/
|
||||||
constructor(controlledRoots = [DEFAULT_BUILTIN_PACKAGE_ROOT]) {
|
constructor(
|
||||||
this.controlledRoots = controlledRoots.map((root) => resolve(root));
|
@Optional()
|
||||||
|
@Inject(QQBOT_PLUGIN_PACKAGE_CONTROLLED_ROOTS)
|
||||||
|
controlledRoots?: string[],
|
||||||
|
) {
|
||||||
|
this.controlledRoots = (
|
||||||
|
controlledRoots?.length ? controlledRoots : [DEFAULT_BUILTIN_PACKAGE_ROOT]
|
||||||
|
).map((root) => resolve(root));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
import { readFileSync } from 'node:fs';
|
import { readFileSync } from 'node:fs';
|
||||||
import { join } from 'node:path';
|
import { join } from 'node:path';
|
||||||
|
import { Test } from '@nestjs/testing';
|
||||||
import { QqbotPluginPlatformService } from '../../../../src/modules/qqbot/plugin-platform/application/plugin-platform.service';
|
import { QqbotPluginPlatformService } from '../../../../src/modules/qqbot/plugin-platform/application/plugin-platform.service';
|
||||||
|
import { QqbotPluginPackagePathPolicyService } from '../../../../src/modules/qqbot/plugin-platform/infrastructure/integration/package/plugin-package-path-policy.service';
|
||||||
import { QqbotPluginTaskWorkerProcessor } from '../../../../src/modules/qqbot/plugin-platform/application/task/qqbot-plugin-task-worker.processor';
|
import { QqbotPluginTaskWorkerProcessor } from '../../../../src/modules/qqbot/plugin-platform/application/task/qqbot-plugin-task-worker.processor';
|
||||||
|
|
||||||
describe('QQBot plugin platform DI tokens', () => {
|
describe('QQBot plugin platform DI tokens', () => {
|
||||||
@ -27,4 +29,14 @@ describe('QQBot plugin platform DI tokens', () => {
|
|||||||
|
|
||||||
expect(paramTypes[1]).toBe(QqbotPluginPlatformService);
|
expect(paramTypes[1]).toBe(QqbotPluginPlatformService);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('lets Nest instantiate the package path policy without a config-array provider', async () => {
|
||||||
|
const moduleRef = await Test.createTestingModule({
|
||||||
|
providers: [QqbotPluginPackagePathPolicyService],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
expect(moduleRef.get(QqbotPluginPackagePathPolicyService)).toBeInstanceOf(
|
||||||
|
QqbotPluginPackagePathPolicyService,
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user