Skip to content
This repository was archived by the owner on Dec 12, 2023. It is now read-only.

Commit b65e9b8

Browse files
committed
Hit new /versions/latest endpoint for latest
1 parent 664e582 commit b65e9b8

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/utils/parse.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ test('parse', t => {
270270
raw: 'registry:dt/node',
271271
type: 'registry',
272272
meta: { name: 'node', source: 'dt', tag: undefined as string, version: undefined as string },
273-
location: 'https://api.typings.org/entries/dt/node/versions/*/latest'
273+
location: 'https://api.typings.org/entries/dt/node/versions/latest'
274274
}
275275

276276
t.deepEqual(actual, expected)
@@ -283,7 +283,7 @@ test('parse', t => {
283283
raw: 'registry:npm/@scoped/npm',
284284
type: 'registry',
285285
meta: { name: '@scoped/npm', source: 'npm', tag: undefined as string, version: undefined as string },
286-
location: 'https://api.typings.org/entries/npm/%40scoped%2Fnpm/versions/*/latest'
286+
location: 'https://api.typings.org/entries/npm/%40scoped%2Fnpm/versions/latest'
287287
}
288288

289289
t.deepEqual(actual, expected)

src/utils/parse.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,16 @@ export function parseDependency (raw: string): Dependency {
167167
throw new TypeError(`Unable to use tag and version together: ${raw}`)
168168
}
169169

170-
const prefix = `/entries/${encodeURIComponent(source)}/${encodeURIComponent(name)}`
171-
const path = tag ?
172-
`${prefix}/tags/${encodeURIComponent(tag)}` :
173-
`${prefix}/versions/${encodeURIComponent(version || '*')}/latest`
170+
let path = `/entries/${encodeURIComponent(source)}/${encodeURIComponent(name)}`
171+
172+
// Select the best API to get the registry version.
173+
if (tag) {
174+
path += `/tags/${encodeURIComponent(tag)}`
175+
} else if (version) {
176+
path += `/versions/${encodeURIComponent(version)}/latest`
177+
} else {
178+
path += '/versions/latest'
179+
}
174180

175181
return {
176182
raw,

0 commit comments

Comments
 (0)