get-latest-version
v6.0.1
Published
Find the latest version of an npm module matching a given semver range
Downloads
1,515,989
Readme
get-latest-version
Find the latest version of an npm module matching a given semver range
Requirements
- Node.js 20 or higher
- This package is now ESM-only and uses named exports. If you need CommonJS support, use version 5.x.
Installing
npm install --save get-latest-versionBasic usage
import {getLatestVersion} from 'get-latest-version'
// Get the latest version
try {
const version = await getLatestVersion('some-module')
console.log(version) // 1.0.0, or whichever is 'latest'
} catch (err) {
console.error(err)
}
// Get highest version matching a semver range
try {
const version = await getLatestVersion('some-other-module', {range: '^1.0.0'})
console.log(version) // highest version matching ^1.0.0 range
} catch (err) {
console.error(err)
}
// Returns both the highest in the given range and the actual `latest` tag
// Note that this differs in that the return value is an object
try {
const versions = await getLatestVersion('@sanity/base', {range: '^1.0.0', includeLatest: true})
console.log(versions) // {inRange: '1.150.8', latest: '2.23.0'}
} catch (err) {
console.error(err)
}Disabling authenticated requests
By default, this module will read the authorization token for whichever registry the module belongs to, based on local npm configuration. To disable this and always send unauthenticated requests to the registry, provide auth: false to the options:
import {getLatestVersion} from 'get-latest-version'
try {
const version = await getLatestVersion('some-module', {auth: false})
console.log(version)
} catch (err) {
console.error(err)
}Using custom registry
By default, module utilizes registry-url to resolve registry URL from NPM configuration files. However, if you need to set up the registry programmatically, you can make use of the registryUrl option:
import {getLatestVersion} from 'get-latest-version'
try {
const version = await getLatestVersion('some-module', {
registryUrl: 'https://some-custom-registry.com'
})
console.log(version)
} catch (err) {
console.error(err)
}Developing
git clone [email protected]:rexxars/get-latest-version.git
cd get-latest-version
npm install
npm testLicense
MIT © Espen Hovlandsdal
