diff --git a/plugins/market/client/components/install.vue b/plugins/market/client/components/install.vue
index 237851d3..8bf63761 100644
--- a/plugins/market/client/components/install.vue
+++ b/plugins/market/client/components/install.vue
@@ -36,11 +36,11 @@
当前版本 |
可用性 |
-
+
{{ name }} |
- {{ request }} |
-
-
+ | {{ peer.request }} |
+
+
{{ getVersion(name) || 'Select' }}
- {{ resolved + (getWorkspaceVersion(name) ? ' (工作区)' : '') }}
+ {{ peer.resolved }}{{ getWorkspaceVersion(name) ? ' (工作区)' : '' }}
|
-
+ |
-
- {{ getResultText(result, name) }}
+
+ {{ getResultText(peer, name) }}
|
@@ -69,7 +69,7 @@
-
+
批量操作模式
批量操作模式下,你可以同时安装、更新或移除多个插件。勾选此选项后,你的所有操作会被暂存,直到你点击右上角的“应用更改”按钮。
@@ -106,7 +106,7 @@
import { computed, ref, watch, reactive } from 'vue'
import { Dict, global, send, store, useContext } from '@koishijs/client'
-import { analyzeVersions, install } from './utils'
+import { analyzeVersions, install, PeerInfo, ResultType } from './utils'
import { active, config } from '../utils'
import { parse } from 'semver'
@@ -117,7 +117,7 @@ function installDep(version: string, checkConfig = false, removeConfig = false)
const target = active.value
if (!target) return
// workspace packages don't need to be installed
- if (config.value.bulk && !workspace.value) {
+ if (config.value.bulkMode && !workspace.value) {
if (dep.value?.resolved === version || !version && !dep.value) {
delete config.value.override[target]
} else {
@@ -162,7 +162,7 @@ const selectVersion = computed({
const versions = reactive>({})
function getOverride() {
- return config.value.bulk ? config.value.override : versions
+ return config.value.bulkMode ? config.value.override : versions
}
function getVersion(name: string) {
@@ -189,7 +189,7 @@ const current = computed(() => store.dependencies?.[active.value]?.resolved)
const local = computed(() => store.packages?.[active.value])
const showRemoveButton = computed(() => {
- return current.value || store.dependencies[active.value] || config.value.bulk && config.value.override[active.value]
+ return current.value || store.dependencies[active.value] || config.value.bulkMode && config.value.override[active.value]
})
const workspace = computed(() => getWorkspaceVersion(active.value))
@@ -205,13 +205,6 @@ function getWorkspaceVersion(name: string) {
}
}
-watch(active, async (name) => {
- if (name && !workspace.value && !store.registry?.[active.value]) {
- const data = await send('market/registry', [name])
- version.value = Object.keys(data)[0]
- }
-}, { immediate: true })
-
const data = computed(() => {
if (!active.value || workspace.value) return
return analyzeVersions(active.value, getVersion)
@@ -245,11 +238,45 @@ const result = computed(() => {
return result
})
-watch(active, (value) => {
- if (!value) return
+function shouldFetchRegistry(name: string) {
+ return !store.registry?.[name] && !getWorkspaceVersion(name)
+}
+
+watch(() => data.value?.[version.value]?.peers, async (peers) => {
+ if (!peers) return
+ const names = Object.keys(peers).filter(shouldFetchRegistry)
+ let registry: typeof store.registry = {}
+ if (names.length) {
+ registry = await send('market/registry', names)
+ }
+ Object.assign(registry, store.registry)
+ if (config.value.bulkMode) return
+
+ // rebuild versions
+ for (const name of Object.keys(versions)) {
+ if (name === active.value) continue
+ if (name in peers) continue
+ delete versions[name]
+ }
+ for (const name in peers) {
+ if (!registry[name]) continue
+ const { result } = peers[name]
+ if (result !== 'warning' && result !== 'danger') continue
+ versions[name] = Object.keys(registry[name])[0]
+ }
+})
+
+watch(active, async (name) => {
+ if (!name) return
+
version.value = config.value.override[active.value]
|| store.dependencies?.[active.value]?.request
- || Object.keys(store.registry?.[value] || {})[0]
+ || Object.keys(store.registry?.[name] || {})[0]
+
+ if (shouldFetchRegistry(name)) {
+ const registry = await send('market/registry', [name])
+ version.value = Object.keys(registry[active.value])[0]
+ }
}, { immediate: true })
function configure() {
@@ -257,7 +284,7 @@ function configure() {
active.value = null
}
-function getResultIcon(type: 'primary' | 'warning' | 'danger' | 'success') {
+function getResultIcon(type: ResultType) {
switch (type) {
case 'primary': return 'info-full'
case 'warning': return 'exclamation-full'
@@ -266,13 +293,12 @@ function getResultIcon(type: 'primary' | 'warning' | 'danger' | 'success') {
}
}
-function getResultText(type: 'primary' | 'warning' | 'danger' | 'success', name: string) {
- const isOverriden = config.value.bulk ? name in config.value.override : name in versions
+function getResultText(peer: PeerInfo, name: string) {
+ const isOverriden = name in getOverride()
const isInstalled = store.packages ? !!store.packages[name] : !!store.dependencies?.[name]
- switch (type) {
- case 'primary': return '可选'
- case 'warning': return isOverriden ? '等待移除' : '未下载'
- case 'danger': return '不兼容'
+ switch (peer.result) {
+ case 'primary': return isOverriden ? '等待移除' : '可选'
+ case 'danger': return peer.resolved ? '不兼容' : isOverriden ? '等待移除' : '未下载'
case 'success': return isOverriden ? isInstalled ? '等待更新' : '等待安装' : '已下载'
}
}
diff --git a/plugins/market/client/components/utils.ts b/plugins/market/client/components/utils.ts
index 1bd60cc5..76c1bdf0 100644
--- a/plugins/market/client/components/utils.ts
+++ b/plugins/market/client/components/utils.ts
@@ -4,14 +4,16 @@ import { compare, satisfies } from 'semver'
import { reactive, ref, watch } from 'vue'
import { active } from '../utils'
-type ResultType = 'success' | 'warning' | 'danger' | 'primary'
+export type ResultType = 'success' | 'warning' | 'danger' | 'primary'
interface AnalyzeResult {
- peers: Dict<{
- request: string
- resolved: string
- result: ResultType
- }>
+ peers: Dict
+ result: ResultType
+}
+
+export interface PeerInfo {
+ request: string
+ resolved: string
result: ResultType
}
@@ -24,9 +26,10 @@ export function analyzeVersions(name: string, getVersion: (name: string) => stri
?? store.dependencies[name]?.resolved
?? store.packages?.[name]?.package.version
const result: ResultType = !resolved
- ? item.peerDependenciesMeta?.[name]?.optional ? 'primary' : 'warning'
+ ? item.peerDependenciesMeta?.[name]?.optional ? 'primary' : 'danger'
: satisfies(resolved, request, { includePrerelease: true }) ? 'success' : 'danger'
- return { request, resolved, result }
+ if (result === 'danger') console.log(name, request, resolved)
+ return { request, resolved, result } as PeerInfo
})
let result: 'success' | 'warning' | 'danger' = 'success'
for (const peer of Object.values(peers)) {
diff --git a/plugins/market/client/utils.ts b/plugins/market/client/utils.ts
index 16c22a56..29dcfe5c 100644
--- a/plugins/market/client/utils.ts
+++ b/plugins/market/client/utils.ts
@@ -4,7 +4,7 @@ import { gt } from 'semver'
interface ManagerConfig {
prefix: string
- bulk?: boolean
+ bulkMode?: boolean
removeConfig?: boolean
override: Dict
hideWorkspace?: boolean
@@ -12,7 +12,7 @@ interface ManagerConfig {
export const config: Ref = useStorage('manager', 2, () => ({
prefix: '^',
- bulk: false,
+ bulkMode: false,
removeConfig: false,
override: {},
hideWorkspace: true,
diff --git a/plugins/market/src/node/index.ts b/plugins/market/src/node/index.ts
index 880f26c5..b8a0ed6e 100644
--- a/plugins/market/src/node/index.ts
+++ b/plugins/market/src/node/index.ts
@@ -26,7 +26,7 @@ declare module '@koishijs/console' {
interface Events {
'market/install'(deps: Dict, forced?: boolean): Promise
- 'market/registry'(names: string[]): Promise>[]>
+ 'market/registry'(names: string[]): Promise>>>
}
}
@@ -165,7 +165,8 @@ export function apply(ctx: Context, config: Config) {
}, { authority: 4 })
ctx.console.addListener('market/registry', async (names) => {
- return Promise.all(names.map(name => ctx.installer.getPackage(name)))
+ const meta = await Promise.all(names.map(name => ctx.installer.getPackage(name)))
+ return Object.fromEntries(meta.map((meta, index) => [names[index], meta]))
}, { authority: 4 })
})
}