mirror of
https://github.com/certd/certd.git
synced 2026-07-29 16:47:36 +08:00
chore: 完善第三方依赖动态加载
This commit is contained in:
@@ -1,7 +1,22 @@
|
||||
{
|
||||
"extends": "./node_modules/mwts/",
|
||||
"ignorePatterns": ["node_modules", "dist", "test", "jest.config.js", "typings"],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"extends": [
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:prettier/recommended",
|
||||
"prettier"
|
||||
],
|
||||
"env": {
|
||||
"jest": true
|
||||
"mocha": true
|
||||
},
|
||||
"rules": {
|
||||
"@typescript-eslint/no-var-requires": "off",
|
||||
"@typescript-eslint/ban-ts-comment": "off",
|
||||
"@typescript-eslint/ban-ts-ignore": "off",
|
||||
"@typescript-eslint/no-explicit-any": "off",
|
||||
"@typescript-eslint/no-empty-function": "off",
|
||||
"@typescript-eslint/no-unused-vars": "off"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
"test:unit": "cross-env NODE_ENV=unittest mocha --no-config --node-option no-warnings --node-option loader=ts-node/esm \"src/**/*.test.ts\"",
|
||||
"test1": "midway-bin test --ts -V -f test/blank.test.ts -t 'hash-check'",
|
||||
"cov": "midway-bin cov --ts",
|
||||
"lint": "mwts check",
|
||||
"lint:fix": "mwts fix",
|
||||
"prepublish": "npm run build",
|
||||
"pub": "npm publish",
|
||||
"compile": "tsc --skipLibCheck --watch"
|
||||
"compile": "tsc --skipLibCheck --watch",
|
||||
"format": "prettier --write src",
|
||||
"lint": "eslint --fix"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "greper",
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import { IAccessService } from "@certd/pipeline";
|
||||
import { IAccessService, IRuntimeDepsService } from "@certd/pipeline";
|
||||
|
||||
export type AccessRuntimeDepsService = {
|
||||
ensureRuntimeDependencies(pluginKeys: string | string[]): Promise<any>;
|
||||
importRuntime(specifier: string): Promise<any>;
|
||||
};
|
||||
export type AccessRuntimeDepsService = IRuntimeDepsService;
|
||||
|
||||
export class AccessGetter implements IAccessService {
|
||||
userId: number;
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
accessRegistry,
|
||||
FormItemProps,
|
||||
IAccessService,
|
||||
IRuntimeDepsService,
|
||||
IServiceGetter,
|
||||
PluginRequestHandleReq,
|
||||
Registrable
|
||||
@@ -66,26 +67,20 @@ export abstract class BaseAddon implements IAddon {
|
||||
ctx!: AddonContext;
|
||||
http!: HttpClient;
|
||||
logger!: ILogger;
|
||||
runtimeDepsService?: {
|
||||
ensureRuntimeDependencies(pluginKeys: string | string[]): Promise<any>;
|
||||
importRuntime(specifier: string): Promise<any>;
|
||||
};
|
||||
runtimeDepsService?: IRuntimeDepsService;
|
||||
|
||||
async importRuntime(specifier: string) {
|
||||
if (!this.runtimeDepsService) {
|
||||
return await import(specifier);
|
||||
}
|
||||
return await this.runtimeDepsService.importRuntime(specifier);
|
||||
return await this.runtimeDepsService.importRuntime(specifier, this.logger);
|
||||
}
|
||||
|
||||
title!: string;
|
||||
|
||||
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
async onInstance() {}
|
||||
|
||||
|
||||
async getAccess<T = any>(accessId: string | number, isCommon = false) {
|
||||
if (accessId == null) {
|
||||
throw new Error("您还没有配置授权");
|
||||
@@ -119,7 +114,6 @@ export abstract class BaseAddon implements IAddon {
|
||||
return res as T;
|
||||
}
|
||||
|
||||
|
||||
async setCtx(ctx: AddonContext) {
|
||||
this.ctx = ctx;
|
||||
this.http = ctx.http;
|
||||
@@ -128,7 +122,7 @@ export abstract class BaseAddon implements IAddon {
|
||||
this.runtimeDepsService = await this.ctx.serviceGetter.get("runtimeDepsService");
|
||||
}
|
||||
if (this.runtimeDepsService && this.define?.addonType && this.define?.name) {
|
||||
await this.runtimeDepsService.ensureRuntimeDependencies(`addon:${this.define.addonType}:${this.define.name}`);
|
||||
await this.runtimeDepsService.ensureRuntimeDependencies({ pluginKeys: `addon:${this.define.addonType}:${this.define.name}`, logger: this.logger });
|
||||
}
|
||||
}
|
||||
setDefine = (define:AddonDefine) => {
|
||||
|
||||
Reference in New Issue
Block a user