feat: 通过插件配置懒加载依赖,动态加载第三方依赖包,精简安装镜像大小

This commit is contained in:
xiaojunnuo
2026-06-19 17:44:57 +08:00
parent 0d97ad67c5
commit 01568ca148
50 changed files with 2009 additions and 211 deletions
+23 -1
View File
@@ -3,6 +3,7 @@ import { FormItemProps } from "../dt/index.js";
import { HttpClient, ILogger, utils } from "@certd/basic";
import * as _ from "lodash-es";
import { PluginRequestHandleReq } from "../plugin/index.js";
import { IServiceGetter } from "../service/index.js";
// export type AccessRequestHandleReqInput<T = any> = {
// id?: number;
@@ -20,6 +21,8 @@ export type AccessInputDefine = FormItemProps & {
export type AccessDefine = Registrable & {
icon?: string;
subtype?: string;
dependPlugins?: Record<string, string>;
dependPackages?: Record<string, string>;
input?: {
[key: string]: AccessInputDefine;
};
@@ -39,13 +42,32 @@ export type AccessContext = {
logger: ILogger;
utils: typeof utils;
accessService: IAccessService;
serviceGetter?: IServiceGetter;
define?: AccessDefine;
};
export abstract class BaseAccess implements IAccess {
ctx!: AccessContext;
runtimeDepsService?: {
ensureRuntimeDependencies(pluginKeys: string | string[]): Promise<any>;
importRuntime(specifier: string): Promise<any>;
};
setCtx(ctx: AccessContext) {
async importRuntime(specifier: string) {
if (!this.runtimeDepsService) {
return await import(specifier);
}
return await this.runtimeDepsService.importRuntime(specifier);
}
async setCtx(ctx: AccessContext) {
this.ctx = ctx;
if (!this.runtimeDepsService && this.ctx.serviceGetter) {
this.runtimeDepsService = await this.ctx.serviceGetter.get("runtimeDepsService");
}
if (this.runtimeDepsService && this.ctx.define?.name) {
await this.runtimeDepsService.ensureRuntimeDependencies(`access:${this.ctx.define.name}`);
}
}
async onRequest(req: AccessRequestHandleReq) {
@@ -67,7 +67,9 @@ export async function newAccess(type: string, input: any, accessService: IAccess
accessService,
};
}
access.setCtx(ctx);
ctx.define = ctx.define || register.define;
access.runtimeDepsService = (accessService as any).runtimeDepsService;
await access.setCtx(ctx);
access._type = type;
return access;
}