Skip to content

Commit

Permalink
fix(market): fix dep version not synced, close koishijs#189
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jul 9, 2023
1 parent a09454e commit b10bcfb
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 32 deletions.
13 changes: 4 additions & 9 deletions plugins/market/client/components/dependencies.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import { computed } from 'vue'
import { store } from '@koishijs/client'
import { config, refresh } from '../utils'
import { config, refresh, hasUpdate } from '../utils'
import { install } from './utils'
import PackageView from './package.vue'
Expand All @@ -47,21 +47,16 @@ const names = computed(() => {
.sort((a, b) => a > b ? 1 : -1)
})
const updates = computed(() => {
return names.value.filter(name => {
const local = store.dependencies[name]
return local.latest && local.latest !== local.resolved
})
})
const updates = computed(() => names.value.filter(hasUpdate))
const menu = computed(() => [{
icon: 'rocket',
label: '全部更新',
disabled: !updates.value.length,
async action() {
for (const name of updates.value) {
const local = store.dependencies[name]
config.value.override[name] = local.latest
const versions = store.registry[name]
config.value.override[name] = Object.keys(versions)[0]
}
},
}, {
Expand Down
12 changes: 5 additions & 7 deletions plugins/market/client/components/package.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@
<script lang="ts" setup>
import { computed } from 'vue'
import { store } from '@koishijs/client'
import { active, config } from '../utils'
import { store, isNullable } from '@koishijs/client'
import { active, config, hasUpdate } from '../utils'
import { analyzeVersions } from './utils'
import { gt } from 'semver'
const props = defineProps({
name: String,
Expand All @@ -47,10 +46,9 @@ const local = computed(() => store.dependencies[props.name])
const versions = computed(() => store.registry[props.name])
const compare = computed(() => {
if (local.value.invalid) return
try {
return gt(local.value.latest, local.value.resolved) ? '可更新' : '最新'
} catch {}
const result = hasUpdate(props.name)
if (isNullable(result)) return
return result ? '可更新' : '最新'
})
const version = computed({
Expand Down
23 changes: 8 additions & 15 deletions plugins/market/client/extensions/version.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
:href="object.package.links.homepage"
>插件主页</a>
<a class="el-button" target="_blank"
v-if="object.package.links.npm && data.local.version"
:href="object.package.links.npm + '/v/' + data.local.version"
>当前版本:{{ data.local.version }}</a>
v-if="object.package.links.npm && data.local.package.version"
:href="object.package.links.npm + '/v/' + data.local.package.version"
>当前版本:{{ data.local.package.version }}</a>
<a class="el-button" target="_blank"
v-if="object.package.links.repository"
:href="object.package.links.repository"
Expand All @@ -20,7 +20,7 @@
</div>

<!-- latest -->
<k-comment v-if="hasUpdate && !global.static">
<k-comment v-if="hasUpdate(data.name) && !global.static">
<p>当前的插件版本不是最新,<router-link to="/dependencies">点击前往依赖管理</router-link>。</p>
</k-comment>

Expand All @@ -31,31 +31,24 @@

<!-- external -->
<k-comment type="warning" v-if="!data.local.workspace && store.dependencies && !store.dependencies[data.name]">
<p>尚未将当前插件列入依赖,<span class="link" @click="send('market/install', { [data.name]: data.local.version })">点击添加</span>。</p>
<p>尚未将当前插件列入依赖,<span class="link" @click="send('market/install', { [data.name]: data.local.package.version })">点击添加</span>。</p>
</k-comment>
</template>

<script lang="ts" setup>
import { global, send, store } from '@koishijs/client'
import { computed } from 'vue'
import { gt } from 'semver'
import { hasUpdate } from '../utils'
import { SettingsData } from '@koishijs/plugin-config/client'
const props = defineProps<{
data: SettingsData
}>()
const object = computed(() => store.market.data?.[props.data.name])
const dep = computed(() => store.dependencies[props.data.name])
const versions = computed(() => store.registry[props.data.name])
const hasUpdate = computed(() => {
if (!versions.value || props.data.local.workspace) return
try {
return gt(object.value.package.version, props.data.local.version)
} catch {}
})
const dep = computed(() => store.dependencies?.[props.data.name])
const versions = computed(() => store.registry?.[props.data.name])
</script>

Expand Down
10 changes: 10 additions & 0 deletions plugins/market/client/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { computed, ref, watch } from 'vue'
import { Dict, send, store, useStorage } from '@koishijs/client'
import { gt } from 'semver'

interface ManagerConfig {
prefix: string
Expand Down Expand Up @@ -36,3 +37,12 @@ export const refresh = computed(() => ({
type: !store.market || store.market.progress < store.market.total ? 'spin disabled' : '',
action: () => send('market/refresh'),
}))

export function hasUpdate(name: string) {
const versions = store.registry?.[name]
const local = store.dependencies?.[name]
if (!versions || local?.workspace) return
try {
return gt(Object.keys(versions)[0], local.resolved)
} catch {}
}
2 changes: 1 addition & 1 deletion plugins/market/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@koishijs/plugin-market",
"description": "Manage your bots and plugins with console",
"version": "2.2.5",
"version": "2.2.6",
"main": "lib/node/index.js",
"typings": "lib/index.d.ts",
"exports": {
Expand Down

0 comments on commit b10bcfb

Please sign in to comment.