refactor: 重构

This commit is contained in:
xiaojunnuo
2021-02-08 13:40:28 +08:00
parent 82f86d9556
commit cb8c8186f1
38 changed files with 807 additions and 1895 deletions
+5 -4
View File
@@ -1,5 +1,6 @@
export * from './dns-provider'
export * from './plugin'
export * from './access-provider'
export * from './dns-provider/index.js'
export * from './plugin/index.js'
export * from './access-provider/index.js'
export { Store } from './store/store.js'
export { util } from './utils'
export { util } from './utils/index.js'
// module.createRequireFromPath()
@@ -4,7 +4,11 @@ import dayjs from 'dayjs'
import Sleep from '../utils/util.sleep.js'
export class AbstractPlugin {
constructor ({ accessProviders }) {
constructor (options) {
if (options == null) {
throw new Error('插件安装失败:参数不允许为空')
}
const { accessProviders } = options
this.logger = logger
this.accessProviders = accessProviders
}
+10 -3
View File
@@ -26,11 +26,18 @@ export class Registry {
}
get (name) {
if (name) {
return this.collection[name]
if (!name) {
throw new Error('插件名称不能为空')
}
throw new Error(`${name} cant blank`)
if (!this.collection) {
this.collection = {}
}
const plugin = this.collection[name]
if (!plugin) {
throw new Error(`插件${name}还未注册`)
}
return plugin
}
getCollection () {