@hashicorp/js-releases
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -19,3 +19,3 @@ interface Build { | ||
} | ||
export declare function getRelease(product: string, version?: string, userAgent?: string): Promise<Release>; | ||
export declare function getRelease(product: string, version?: string, userAgent?: string, includePrerelease?: boolean): Promise<Release>; | ||
export {}; |
@@ -156,5 +156,5 @@ "use strict"; | ||
exports.Release = Release; | ||
function getRelease(product, version, userAgent) { | ||
function getRelease(product, version, userAgent, includePrerelease) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const validVersion = semver.validRange(version); // "latest" will return invalid but that's ok because we'll select it by default | ||
const validVersion = semver.validRange(version, { includePrerelease, loose: true }); // "latest" will return invalid but that's ok because we'll select it by default | ||
const indexUrl = `${releasesUrl}/${product}/index.json`; | ||
@@ -165,8 +165,9 @@ const headers = userAgent ? { 'User-Agent': userAgent } : null; | ||
let release; | ||
if (!validVersion) { // pick the latest release | ||
version = Object.keys(response.versions).sort(semver.rcompare)[0]; | ||
if (!validVersion) { // pick the latest release (prereleases will be skipped for safety, set an explicit version instead) | ||
const releaseVersions = Object.keys(response.versions).filter(v => !semver.prerelease(v)); | ||
version = releaseVersions.sort((a, b) => semver.rcompare(a, b))[0]; | ||
release = new Release(response.versions[version]); | ||
} | ||
else { | ||
release = matchVersion(response.versions, validVersion); | ||
release = matchVersion(response.versions, validVersion, includePrerelease); | ||
} | ||
@@ -177,4 +178,6 @@ return release; | ||
exports.getRelease = getRelease; | ||
function matchVersion(versions, range) { | ||
const version = semver.maxSatisfying(Object.keys(versions), range); | ||
function matchVersion(versions, range, includePrerelease) { | ||
// If a prerelease version range is given, it will match in that series (0.14-rc0, 0.14-rc1) | ||
// https://www.npmjs.com/package/semver#prerelease-tags | ||
const version = semver.maxSatisfying(Object.keys(versions), range, { includePrerelease }); | ||
if (version) { | ||
@@ -181,0 +184,0 @@ return new Release(versions[version]); |
{ | ||
"name": "@hashicorp/js-releases", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Download packages from releases.hashicorp.com", | ||
@@ -5,0 +5,0 @@ "main": "./out/index.js", |
@@ -165,4 +165,4 @@ import * as crypto from 'crypto'; | ||
export async function getRelease(product: string, version?: string, userAgent?: string): Promise<Release> { | ||
const validVersion = semver.validRange(version); // "latest" will return invalid but that's ok because we'll select it by default | ||
export async function getRelease(product: string, version?: string, userAgent?: string, includePrerelease?: boolean): Promise<Release> { | ||
const validVersion = semver.validRange(version, { includePrerelease, loose: true }); // "latest" will return invalid but that's ok because we'll select it by default | ||
const indexUrl = `${releasesUrl}/${product}/index.json`; | ||
@@ -173,7 +173,8 @@ const headers = userAgent ? { 'User-Agent': userAgent } : null; | ||
let release: Release; | ||
if (!validVersion) { // pick the latest release | ||
version = Object.keys(response.versions).sort(semver.rcompare)[0]; | ||
if (!validVersion) { // pick the latest release (prereleases will be skipped for safety, set an explicit version instead) | ||
const releaseVersions = Object.keys(response.versions).filter(v => !semver.prerelease(v)); | ||
version = releaseVersions.sort((a, b) => semver.rcompare(a, b))[0]; | ||
release = new Release(response.versions[version]); | ||
} else { | ||
release = matchVersion(response.versions, validVersion); | ||
release = matchVersion(response.versions, validVersion, includePrerelease); | ||
} | ||
@@ -183,4 +184,6 @@ return release; | ||
function matchVersion(versions: Release[], range: string): Release { | ||
const version = semver.maxSatisfying(Object.keys(versions), range); | ||
function matchVersion(versions: Release[], range: string, includePrerelease?: boolean): Release { | ||
// If a prerelease version range is given, it will match in that series (0.14-rc0, 0.14-rc1) | ||
// https://www.npmjs.com/package/semver#prerelease-tags | ||
const version = semver.maxSatisfying(Object.keys(versions), range, { includePrerelease }); | ||
if (version) { | ||
@@ -187,0 +190,0 @@ return new Release(versions[version]); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31235
482