Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump compare-versions from 4.1.3 to 5.0.1 #1212

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
328 changes: 165 additions & 163 deletions dist/index.js
Expand Up @@ -34643,172 +34643,174 @@ function incrementNodeInspectorPort(args) {

/***/ }),

/***/ 89296:
/***/ (function(module) {

/* global define */
(function (root, factory) {
/* istanbul ignore next */
if (typeof define === 'function' && define.amd) {
define([], factory);
} else if (true) {
module.exports = factory();
} else {}
})(this, function () {
var semver =
/^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i;

function indexOrEnd(str, q) {
return str.indexOf(q) === -1 ? str.length : str.indexOf(q);
}

function split(v) {
var c = v.replace(/^v/, '').replace(/\+.*$/, '');
var patchIndex = indexOrEnd(c, '-');
var arr = c.substring(0, patchIndex).split('.');
arr.push(c.substring(patchIndex + 1));
return arr;
}

function tryParse(v) {
var n = parseInt(v, 10);
return isNaN(n) ? v : n;
}

function validateAndParse(v) {
if (typeof v !== 'string') {
throw new TypeError('Invalid argument expected string');
}
var match = v.match(semver);
if (!match) {
throw new Error(
"Invalid argument not valid semver ('" + v + "' received)"
);
}
match.shift();
return match;
}

function forceType(a, b) {
return typeof a !== typeof b ? [String(a), String(b)] : [a, b];
}

function compareStrings(a, b) {
var [ap, bp] = forceType(tryParse(a), tryParse(b));
if (ap > bp) return 1;
if (ap < bp) return -1;
return 0;
}

function compareSegments(a, b) {
for (var i = 0; i < Math.max(a.length, b.length); i++) {
var r = compareStrings(a[i] || 0, b[i] || 0);
if (r !== 0) return r;
}
return 0;
}

function compareVersions(v1, v2) {
[v1, v2].forEach(validateAndParse);

var s1 = split(v1);
var s2 = split(v2);

for (var i = 0; i < Math.max(s1.length - 1, s2.length - 1); i++) {
var n1 = parseInt(s1[i] || 0, 10);
var n2 = parseInt(s2[i] || 0, 10);

if (n1 > n2) return 1;
if (n2 > n1) return -1;
}

var sp1 = s1[s1.length - 1];
var sp2 = s2[s2.length - 1];

if (sp1 && sp2) {
var p1 = sp1.split('.').map(tryParse);
var p2 = sp2.split('.').map(tryParse);

for (i = 0; i < Math.max(p1.length, p2.length); i++) {
if (
p1[i] === undefined ||
(typeof p2[i] === 'string' && typeof p1[i] === 'number')
)
return -1;
if (
p2[i] === undefined ||
(typeof p1[i] === 'string' && typeof p2[i] === 'number')
)
return 1;

if (p1[i] > p2[i]) return 1;
if (p2[i] > p1[i]) return -1;
}
} else if (sp1 || sp2) {
return sp1 ? -1 : 1;
}

return 0;
}

var allowedOperators = ['>', '>=', '=', '<', '<='];

var operatorResMap = {
'>': [1],
'>=': [0, 1],
'=': [0],
'<=': [-1, 0],
'<': [-1],
};

function validateOperator(op) {
if (typeof op !== 'string') {
throw new TypeError(
'Invalid operator type, expected string but got ' + typeof op
);
}
if (allowedOperators.indexOf(op) === -1) {
throw new TypeError(
'Invalid operator, expected one of ' + allowedOperators.join('|')
);
}
}

compareVersions.validate = function (version) {
return typeof version === 'string' && semver.test(version);
};

compareVersions.compare = function (v1, v2, operator) {
// Validate operator
validateOperator(operator);

// since result of compareVersions can only be -1 or 0 or 1
// a simple map can be used to replace switch
var res = compareVersions(v1, v2);
return operatorResMap[operator].indexOf(res) > -1;
};
/***/ 14773:
/***/ (function(__unused_webpack_module, exports) {

compareVersions.satisfies = function (v, r) {
// if no range operator then "="
var match = r.match(/^([<>=~^]+)/);
var op = match ? match[1] : '=';
(function (global, factory) {
true ? factory(exports) :
0;
})(this, (function (exports) { 'use strict';

/**
* Compare [semver](https://semver.org/) version strings to find greater, equal or lesser.
* This library supports the full semver specification, including comparing versions with different number of digits like `1.0.0`, `1.0`, `1`, and pre-release versions like `1.0.0-alpha`.
* @param v1 - First version to compare
* @param v2 - Second version to compare
* @returns Numeric value compatible with the [Array.sort(fn) interface](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Parameters).
*/
const compareVersions = (v1, v2) => {
// validate input and split into segments
const n1 = validateAndParse(v1);
const n2 = validateAndParse(v2);
// pop off the patch
const p1 = n1.pop();
const p2 = n2.pop();
// validate numbers
const r = compareSegments(n1, n2);
if (r !== 0)
return r;
// validate pre-release
if (p1 && p2) {
return compareSegments(p1.split('.'), p2.split('.'));
}
else if (p1 || p2) {
return p1 ? -1 : 1;
}
return 0;
};
/**
* Validate [semver](https://semver.org/) version strings.
*
* @param version Version number to validate
* @returns `true` if the version number is a valid semver version number, `false` otherwise.
*
* @example
* ```
* validate('1.0.0-rc.1'); // return true
* validate('1.0-rc.1'); // return false
* validate('foo'); // return false
* ```
*/
const validate = (version) => typeof version === 'string' && /^[v\d]/.test(version) && semver.test(version);
/**
* Compare [semver](https://semver.org/) version strings using the specified operator.
*
* @param v1 First version to compare
* @param v2 Second version to compare
* @param operator Allowed arithmetic operator to use
* @returns `true` if the comparison between the firstVersion and the secondVersion satisfies the operator, `false` otherwise.
*
* @example
* ```
* compare('10.1.8', '10.0.4', '>'); // return true
* compare('10.0.1', '10.0.1', '='); // return true
* compare('10.1.1', '10.2.2', '<'); // return true
* compare('10.1.1', '10.2.2', '<='); // return true
* compare('10.1.1', '10.2.2', '>='); // return false
* ```
*/
const compare = (v1, v2, operator) => {
// validate input operator
assertValidOperator(operator);
// since result of compareVersions can only be -1 or 0 or 1
// a simple map can be used to replace switch
const res = compareVersions(v1, v2);
return operatorResMap[operator].includes(res);
};
/**
* Match [npm semver](https://docs.npmjs.com/cli/v6/using-npm/semver) version range.
*
* @param version Version number to match
* @param range Range pattern for version
* @returns `true` if the version number is within the range, `false` otherwise.
*
* @example
* ```
* satisfies('1.1.0', '^1.0.0'); // return true
* satisfies('1.1.0', '~1.0.0'); // return false
* ```
*/
const satisfies = (version, range) => {
// if no range operator then "="
const m = range.match(/^([<>=~^]+)/);
const op = m ? m[1] : '=';
// if gt/lt/eq then operator compare
if (op !== '^' && op !== '~')
return compare(version, range, op);
// else range of either "~" or "^" is assumed
const [v1, v2, v3] = validateAndParse(version);
const [r1, r2, r3] = validateAndParse(range);
if (compareStrings(v1, r1) !== 0)
return false;
if (op === '^') {
return compareSegments([v2, v3], [r2, r3]) >= 0;
}
if (compareStrings(v2, r2) !== 0)
return false;
return compareStrings(v3, r3) >= 0;
};
const semver = /^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i;
const validateAndParse = (version) => {
if (typeof version !== 'string') {
throw new TypeError('Invalid argument expected string');
}
const match = version.match(semver);
if (!match) {
throw new Error(`Invalid argument not valid semver ('${version}' received)`);
}
match.shift();
return match;
};
const isWildcard = (s) => s === '*' || s === 'x' || s === 'X';
const tryParse = (v) => {
const n = parseInt(v, 10);
return isNaN(n) ? v : n;
};
const forceType = (a, b) => typeof a !== typeof b ? [String(a), String(b)] : [a, b];
const compareStrings = (a, b) => {
if (isWildcard(a) || isWildcard(b))
return 0;
const [ap, bp] = forceType(tryParse(a), tryParse(b));
if (ap > bp)
return 1;
if (ap < bp)
return -1;
return 0;
};
const compareSegments = (a, b) => {
for (let i = 0; i < Math.max(a.length, b.length); i++) {
const r = compareStrings(a[i] || '0', b[i] || '0');
if (r !== 0)
return r;
}
return 0;
};
const operatorResMap = {
'>': [1],
'>=': [0, 1],
'=': [0],
'<=': [-1, 0],
'<': [-1],
};
const allowedOperators = Object.keys(operatorResMap);
const assertValidOperator = (op) => {
if (typeof op !== 'string') {
throw new TypeError(`Invalid operator type, expected string but got ${typeof op}`);
}
if (allowedOperators.indexOf(op) === -1) {
throw new Error(`Invalid operator, expected one of ${allowedOperators.join('|')}`);
}
};

// if gt/lt/eq then operator compare
if (op !== '^' && op !== '~') return compareVersions.compare(v, r, op);
exports.compare = compare;
exports.compareVersions = compareVersions;
exports.satisfies = satisfies;
exports.validate = validate;

// else range of either "~" or "^" is assumed
var [v1, v2, v3] = validateAndParse(v);
var [m1, m2, m3] = validateAndParse(r);
if (compareStrings(v1, m1) !== 0) return false;
if (op === '^') {
return compareSegments([v2, v3], [m2, m3]) >= 0;
}
if (compareStrings(v2, m2) !== 0) return false;
return compareStrings(v3, m3) >= 0;
};
Object.defineProperty(exports, '__esModule', { value: true });

return compareVersions;
});
}));
//# sourceMappingURL=index.js.map


/***/ }),
Expand Down Expand Up @@ -141890,7 +141892,7 @@ exports.paginate = paginate
/***/ 96402:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {

const compareVersions = __nccwpck_require__(89296)
const compareVersions = __nccwpck_require__(14773)
const regexEscape = __nccwpck_require__(98691)

const { getVersionInfo } = __nccwpck_require__(49914)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -24,7 +24,7 @@
"@actions/core": "1.9.0",
"@probot/adapter-github-actions": "3.1.1",
"cli-table3": "0.6.2",
"compare-versions": "4.1.3",
"compare-versions": "5.0.1",
"deepmerge": "4.2.2",
"escape-string-regexp": "4.0.0",
"ignore": "5.2.0",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Expand Up @@ -1759,10 +1759,10 @@ commander@^9.3.0:
resolved "https://registry.yarnpkg.com/commander/-/commander-9.3.0.tgz#f619114a5a2d2054e0d9ff1b31d5ccf89255e26b"
integrity sha512-hv95iU5uXPbK83mjrJKuZyFM/LBAoCV/XhVGkS5Je6tl7sxr6A0ITMw5WoRV46/UaJ46Nllm3Xt7IaJhXTIkzw==

compare-versions@4.1.3:
version "4.1.3"
resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-4.1.3.tgz#8f7b8966aef7dc4282b45dfa6be98434fc18a1a4"
integrity sha512-WQfnbDcrYnGr55UwbxKiQKASnTtNnaAWVi8jZyy8NTpVAXWACSne8lMD1iaIo9AiU6mnuLvSVshCzewVuWxHUg==
compare-versions@5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-5.0.1.tgz#14c6008436d994c3787aba38d4087fabe858555e"
integrity sha512-v8Au3l0b+Nwkp4G142JcgJFh1/TUhdxut7wzD1Nq1dyp5oa3tXaqb03EXOAB6jS4gMlalkjAUPZBMiAfKUixHQ==

concat-map@0.0.1:
version "0.0.1"
Expand Down