Skip to content

Commit

Permalink
Merge pull request #66 from vivliostyle/fix/issue65
Browse files Browse the repository at this point in the history
fix: Stop using api.npms.io that fails to get the latest package information
  • Loading branch information
akabekobeko committed Aug 12, 2023
2 parents 7a0061a + 56ec193 commit 193ed74
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/themes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import chalk from 'chalk'

export interface SearchResponse {
total: number
results: Result[]
objects: Result[]
}

export interface Result {
Expand Down Expand Up @@ -90,12 +90,14 @@ export type ThemeInfo = {
const KEYWORD = 'vivliostyle-theme'

export async function listThemes(): Promise<Result[]> {
const res = await fetch(`https://api.npms.io/v2/search?q=keywords:${KEYWORD}`)
const res = await fetch(
`https://registry.npmjs.org/-/v1/search?text=keywords:${KEYWORD}`
)
if (res.ok) {
return ((await res.json()) as SearchResponse).results
return ((await res.json()) as SearchResponse).objects
} else {
throw new Error(
`Failed to get the theme information from https://api.npms.io, HTTP status code: "${res.status}"`
`Failed to get the theme information from https://registry.npmjs.org, HTTP status code: "${res.status}"`
)
}
}
Expand Down

0 comments on commit 193ed74

Please sign in to comment.