From 1d27d5df2c5ada68a0991e8d94700cde4a6ee19e Mon Sep 17 00:00:00 2001 From: Shigma Date: Tue, 30 Jan 2024 01:01:19 +0800 Subject: [PATCH] fix(market): workaround npmmirror search API missing fields, fix #304 --- packages/registry/src/types.ts | 6 +++++- plugins/market/client/index.ts | 4 ++-- plugins/market/src/node/installer.ts | 5 ++++- plugins/market/src/node/market.ts | 4 ++++ 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/registry/src/types.ts b/packages/registry/src/types.ts index e0be061c..be864dae 100644 --- a/packages/registry/src/types.ts +++ b/packages/registry/src/types.ts @@ -101,12 +101,16 @@ export interface DatedPackage extends BasePackage { } export interface SearchPackage extends DatedPackage, Pick { - links: Dict + // `links` is absent in npmmirror + links?: Dict author?: User contributors?: User[] keywords: string[] publisher: User maintainers: User[] + // npmmirror only + versions?: string[] + 'dist-tags'?: Dict } export interface SearchObject { diff --git a/plugins/market/client/index.ts b/plugins/market/client/index.ts index ba98a9b5..f59507df 100644 --- a/plugins/market/client/index.ts +++ b/plugins/market/client/index.ts @@ -88,7 +88,7 @@ export default (ctx: Context) => { Schema.const(false).description('从不'), ]).description('移除插件时是否移除其已经存在的配置。'), override: Schema.dict(String).hidden(), - gravatar: Schema.string().description('Gravatar 头像地址。'), + gravatar: Schema.string().description('Gravatar 镜像地址。'), }), }), }) @@ -163,7 +163,7 @@ export default (ctx: Context) => { ctx.effect(() => { return watch(() => store.dependencies, (value) => { - if (!value) return + if (!value || !config.value.market) return for (const key in config.value.market.override) { if (value[key]?.workspace) { delete config.value.market.override[key] diff --git a/plugins/market/src/node/installer.ts b/plugins/market/src/node/installer.ts index caa89eaa..0083bd19 100644 --- a/plugins/market/src/node/installer.ts +++ b/plugins/market/src/node/installer.ts @@ -79,7 +79,10 @@ class Installer extends Service { async start() { const { endpoint, timeout } = this.config this.endpoint = endpoint || await getRegistry() - this.http = this.ctx.http.extend({ endpoint: this.endpoint, timeout }) + this.http = this.ctx.http.extend({ + endpoint: this.endpoint, + timeout, + }) } resolveName(name: string) { diff --git a/plugins/market/src/node/market.ts b/plugins/market/src/node/market.ts index d46b0d33..b655c2c7 100644 --- a/plugins/market/src/node/market.ts +++ b/plugins/market/src/node/market.ts @@ -63,6 +63,10 @@ class MarketProvider extends BaseMarketProvider { this.ctx.installer.setPackage(registry.name, versions) }, onSuccess: (object, versions) => { + // npmmirror lacks `links` field + object.package.links ||= { + npm: `${registry.config.endpoint.replace('registry.', 'www.')}/package/${object.package.name}`, + } this.fullCache[object.package.name] = this.tempCache[object.package.name] = object }, after: () => this.flushData(),