webdriver-manager-replacement
Version:
webdriver-manager-replacement
75 lines • 2.83 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const semver = require("semver");
/**
* Encapsulates the getVersionObjs and getVersionObj into a single method.
* @param versionList The version list object.
* @param osMatch The OS name and architecture.
* @param version Optional field for the semver version number or latest.
* @param maxVersion Optional field to find the max version matching a value.
* @returns Either a VersionObj or null.
*/
function getVersion(versionList, osMatch, version, maxVersion) {
const versionObjs = getVersionObjs(versionList, version, maxVersion);
return getVersionObj(versionObjs, osMatch);
}
exports.getVersion = getVersion;
/**
* Get the version obj from the version list.
* @param versionList The version list object.
* @param version Optional field for the semver version number or latest.
* @returns The object with paritial urls associated with the binary size.
*/
function getVersionObjs(versionList, version, maxVersion) {
if (version && version !== 'latest') {
// Exact matches are easy.
return versionList[version];
}
else {
// Either we want the latest or we want to match with the max version.
let retVersion = null;
for (const versionKey of Object.keys(versionList)) {
if (maxVersion) {
// Only find the greatest of the max version.
// An example:
// maxVersion = 0.1 might match 0.13, 0.1, 0.14, result is 0.14.
// if the user wants 0.1., then the maxVersion should be "0.1."
if (versionKey.startsWith(maxVersion)) {
if (!retVersion) {
retVersion = versionKey;
}
else if (semver.gt(versionKey, retVersion)) {
retVersion = versionKey;
}
}
}
else {
// Always find the latest.
if (!retVersion) {
retVersion = versionKey;
}
else if (semver.gt(versionKey, retVersion)) {
retVersion = versionKey;
}
}
}
return versionList[retVersion];
}
}
exports.getVersionObjs = getVersionObjs;
/**
* Get the version obj from the map.
* @param versionObjs A map of partial urls to VersionObj
* @param osMatch The OS name and architecture.
* @returns Either a VersionObj or null.
*/
function getVersionObj(versionObjMap, osMatch) {
for (const name of Object.keys(versionObjMap)) {
if (name.includes(osMatch)) {
return versionObjMap[name];
}
}
return null;
}
exports.getVersionObj = getVersionObj;
//# sourceMappingURL=version_list.js.map