Skip to content

Commit

Permalink
fix(market): workaround npmmirror search API missing fields, fix #304
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jan 29, 2024
1 parent 8ad80b9 commit 1d27d5d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
6 changes: 5 additions & 1 deletion packages/registry/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,16 @@ export interface DatedPackage extends BasePackage {
}

export interface SearchPackage extends DatedPackage, Pick<RemotePackage, DependencyMetaKey> {
links: Dict<string>
// `links` is absent in npmmirror
links?: Dict<string>
author?: User
contributors?: User[]
keywords: string[]
publisher: User
maintainers: User[]
// npmmirror only
versions?: string[]
'dist-tags'?: Dict<string>
}

export interface SearchObject {
Expand Down
4 changes: 2 additions & 2 deletions plugins/market/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 镜像地址。'),
}),
}),
})
Expand Down Expand Up @@ -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]
Expand Down
5 changes: 4 additions & 1 deletion plugins/market/src/node/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions plugins/market/src/node/market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 1d27d5d

Please sign in to comment.