diff --git a/plugins/market/client/components/install.vue b/plugins/market/client/components/install.vue
index f2ca6360..d207de0b 100644
--- a/plugins/market/client/components/install.vue
+++ b/plugins/market/client/components/install.vue
@@ -24,6 +24,10 @@
正在加载版本数据……
+
+ 该依赖的安装发生了错误,你可以尝试修复或移除它。
+
+
@@ -63,9 +67,9 @@
添加
- 移除
+ 移除
- {{ current ? '更新' : '安装' }}
+ {{ current ? '更新' : store.dependencies?.[active] ? '修复' : '安装' }}
@@ -114,7 +118,7 @@ const selectVersion = computed({
const unchanged = computed(() => {
return !data.value?.[version.value]
- || version.value === store.dependencies?.[active.value]?.request
+ || version.value === store.dependencies?.[active.value]?.request && !!store.dependencies?.[active.value]?.resolved
})
const current = computed(() => store.dependencies?.[active.value]?.resolved)
diff --git a/plugins/market/client/components/utils.ts b/plugins/market/client/components/utils.ts
index d35c1617..7267c337 100644
--- a/plugins/market/client/components/utils.ts
+++ b/plugins/market/client/components/utils.ts
@@ -43,7 +43,7 @@ export const manualDeps = reactive>>({})
export const showManual = ref(false)
export const showConfirm = ref(false)
-export async function install(override: Dict, callback?: () => Awaitable) {
+export async function install(override: Dict, callback?: () => Awaitable, forced?: boolean) {
const instance = loading({
text: '正在更新依赖……',
})
@@ -54,7 +54,7 @@ export async function install(override: Dict, callback?: () => Awaitable
})
try {
active.value = ''
- const code = await send('market/install', override)
+ const code = await send('market/install', override, forced)
if (code) {
message.error('安装失败!')
} else {
diff --git a/plugins/market/src/node/index.ts b/plugins/market/src/node/index.ts
index ba1d2f85..aca463d8 100644
--- a/plugins/market/src/node/index.ts
+++ b/plugins/market/src/node/index.ts
@@ -25,7 +25,7 @@ declare module '@koishijs/console' {
}
interface Events {
- 'market/install'(deps: Dict): Promise
+ 'market/install'(deps: Dict, forced?: boolean): Promise
'market/registry'(name: string): Promise>>
}
}
@@ -155,8 +155,8 @@ export function apply(ctx: Context, config: Config) {
prod: resolve(__dirname, '../../dist'),
})
- ctx.console.addListener('market/install', async (deps) => {
- const code = await ctx.installer.install(deps)
+ ctx.console.addListener('market/install', async (deps, forced) => {
+ const code = await ctx.installer.install(deps, forced)
ctx.console.dependencies?.refresh()
ctx.console.registry?.refresh()
ctx.console.packages?.refresh()
diff --git a/plugins/market/src/node/installer.ts b/plugins/market/src/node/installer.ts
index 5bc8bdb9..ba210493 100644
--- a/plugins/market/src/node/installer.ts
+++ b/plugins/market/src/node/installer.ts
@@ -201,19 +201,18 @@ class Installer extends Service {
return this.exec(this.agent, args)
}
- async install(deps: Dict) {
+ async install(deps: Dict, forced?: boolean) {
const oldDeps = await this.getDeps()
await this.override(deps)
- let shouldInstall = false
for (const name in deps) {
const { resolved } = oldDeps[name] || {}
if (deps[name] && resolved && satisfies(resolved, deps[name], { includePrerelease: true })) continue
- shouldInstall = true
+ forced = true
break
}
- if (shouldInstall) {
+ if (forced) {
const code = await this._install()
if (code) return code
}
@@ -224,7 +223,12 @@ class Installer extends Service {
const { resolved, workspace } = oldDeps[name]
if (workspace || !newDeps[name]) continue
if (newDeps[name].resolved === resolved) continue
- if (!(require.resolve(name) in require.cache)) continue
+ try {
+ if (!(require.resolve(name) in require.cache)) continue
+ } catch (error) {
+ logger.warn(error)
+ continue
+ }
this.ctx.loader.fullReload()
}