From 7eeffe2d19958f718edeaba1e0af360d7602acb6 Mon Sep 17 00:00:00 2001
From: Shigma
Date: Mon, 6 Nov 2023 00:12:46 +0800
Subject: [PATCH] feat(config): use plugin export inject, close #241
---
plugins/config/client/components/plugin.vue | 6 +++---
plugins/config/client/components/utils.ts | 8 ++++----
plugins/config/src/shared/packages.ts | 10 ++++++++++
plugins/config/src/shared/services.ts | 17 +++++++++++------
plugins/market/client/extensions/dependency.vue | 16 ++++++++--------
5 files changed, 36 insertions(+), 21 deletions(-)
diff --git a/plugins/config/client/components/plugin.vue b/plugins/config/client/components/plugin.vue
index f66f58f5..b677cbb1 100644
--- a/plugins/config/client/components/plugin.vue
+++ b/plugins/config/client/components/plugin.vue
@@ -27,9 +27,9 @@
+ :type="name in store.services ? 'success' : required ? 'warning' : 'primary'">
- {{ required ? '必需' : '可选' }}服务:{{ name }} ({{ store.services[name] ? '已加载' : '未加载' }})
+ {{ required ? '必需' : '可选' }}服务:{{ name }} ({{ name in store.services ? '已加载' : '未加载' }})
@@ -38,7 +38,7 @@
-
+
此插件将会提供 {{ name }} 服务,但此服务已被其他插件实现。
diff --git a/plugins/config/client/components/utils.ts b/plugins/config/client/components/utils.ts
index 66ef904f..656507c8 100644
--- a/plugins/config/client/components/utils.ts
+++ b/plugins/config/client/components/utils.ts
@@ -69,11 +69,11 @@ function getEnvInfo(name: string) {
}
// check services
- for (const name of local.manifest.service.required) {
+ for (const name of local.runtime?.required ?? []) {
setService(name, true)
}
- for (const name of local.manifest.service.optional) {
- setService(name, false)
+ for (const name of local.runtime?.optional ?? []) {
+ setService(name, true)
}
// check reusability
@@ -141,7 +141,7 @@ export const type = computed(() => {
if (!env) return
if (env.warning && current.value.disabled) return 'warning'
for (const name in env.using) {
- if (store.services?.[name]) {
+ if (name in store.services || {}) {
if (env.impl.includes(name)) return 'warning'
} else {
if (env.using[name].required) return 'warning'
diff --git a/plugins/config/src/shared/packages.ts b/plugins/config/src/shared/packages.ts
index fb19a472..e3a385ab 100644
--- a/plugins/config/src/shared/packages.ts
+++ b/plugins/config/src/shared/packages.ts
@@ -80,6 +80,14 @@ export abstract class PackageProvider extends DataService> {
async get() {
const services = {} as Dict
- for (const [key, { type }] of Object.entries(this.ctx.root[Context.internal])) {
- if (type !== 'service') continue
- const ctx: Context = this.ctx.get(key)?.[Context.source]
- if (ctx?.scope.uid) {
- const name = key.replace(/^__/, '').replace(/__$/, '')
- services[name] = ctx.scope.uid
+ const attach = (internal: Context[typeof Context.internal]) => {
+ if (!internal) return
+ attach(Object.getPrototypeOf(internal))
+ for (const [key, { type }] of Object.entries(internal)) {
+ if (type !== 'service') continue
+ const ctx: Context = this.ctx.get(key)?.[Context.source]
+ if (ctx) {
+ const name = key.replace(/^__/, '').replace(/__$/, '')
+ services[name] = ctx.scope.uid
+ }
}
}
+ attach(this.ctx.root[Context.internal])
return services
}
}
diff --git a/plugins/market/client/extensions/dependency.vue b/plugins/market/client/extensions/dependency.vue
index b80a7e7a..2e95fb15 100644
--- a/plugins/market/client/extensions/dependency.vue
+++ b/plugins/market/client/extensions/dependency.vue
@@ -7,17 +7,17 @@
+ v-for="({ required }, name) in data.env.using" :key="name"
+ :type="name in store.services ? 'success' : required ? 'warning' : 'primary'">
- {{ required ? '必需' : '可选' }}服务:{{ service }}
- (已加载)
- (未加载,启用下列任一插件可实现此服务)
+ {{ required ? '必需' : '可选' }}服务:{{ name }}
+ (已加载)
+ (未加载,启用下列任一插件可实现此服务)
(未加载)
-