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

Commit

Permalink
Hit new /versions/latest endpoint for latest
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Mar 14, 2016
1 parent 7f5159e commit 44859eb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/utils/parse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ test('parse', t => {
raw: 'registry:dt/node',
type: 'registry',
meta: { name: 'node', source: 'dt', tag: undefined as string, version: undefined as string },
location: 'https://api.typings.org/entries/dt/node/versions/*/latest'
location: 'https://api.typings.org/entries/dt/node/versions/latest'
}

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

t.deepEqual(actual, expected)
Expand Down
14 changes: 10 additions & 4 deletions src/utils/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,16 @@ export function parseDependency (raw: string): Dependency {
throw new TypeError(`Unable to use tag and version together: ${raw}`)
}

const prefix = `/entries/${encodeURIComponent(source)}/${encodeURIComponent(name)}`
const path = tag ?
`${prefix}/tags/${encodeURIComponent(tag)}` :
`${prefix}/versions/${encodeURIComponent(version || '*')}/latest`
let path = `/entries/${encodeURIComponent(source)}/${encodeURIComponent(name)}`

// Select the best API to get the registry version.
if (tag) {
path += `/tags/${encodeURIComponent(tag)}`
} else if (version) {
path += `/versions/${encodeURIComponent(version)}/latest`
} else {
path += '/versions/latest'
}

return {
raw,
Expand Down

0 comments on commit 44859eb

Please sign in to comment.