mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-23 09:26:51 -05:00
add support for > and >= operators in plugin version ranges
This commit is contained in:
parent
f71d4c0a50
commit
07927162fc
1 changed files with 36 additions and 29 deletions
|
@ -266,6 +266,8 @@ var Common = require('./Common');
|
||||||
* Only the following range types are supported:
|
* Only the following range types are supported:
|
||||||
* - Tilde ranges e.g. `~1.2.3`
|
* - Tilde ranges e.g. `~1.2.3`
|
||||||
* - Caret ranges e.g. `^1.2.3`
|
* - Caret ranges e.g. `^1.2.3`
|
||||||
|
* - Greater than ranges e.g. `>1.2.3`
|
||||||
|
* - Greater than or equal ranges e.g. `>=1.2.3`
|
||||||
* - Exact version e.g. `1.2.3`
|
* - Exact version e.g. `1.2.3`
|
||||||
* - Any version `*`
|
* - Any version `*`
|
||||||
* @method versionParse
|
* @method versionParse
|
||||||
|
@ -273,29 +275,28 @@ var Common = require('./Common');
|
||||||
* @return {object} The version range parsed into its components.
|
* @return {object} The version range parsed into its components.
|
||||||
*/
|
*/
|
||||||
Plugin.versionParse = function(range) {
|
Plugin.versionParse = function(range) {
|
||||||
var pattern = /^\*|[\^~]?\d+\.\d+\.\d+(-[0-9A-Za-z-]+)?$/;
|
var pattern = /^(\*)|(\^|~|>=|>)?\s*((\d+)\.(\d+)\.(\d+))(-[0-9A-Za-z-]+)?$/;
|
||||||
|
|
||||||
if (!pattern.test(range)) {
|
if (!pattern.test(range)) {
|
||||||
Common.warn('Plugin.versionParse:', range, 'is not a valid version or range.');
|
Common.warn('Plugin.versionParse:', range, 'is not a valid version or range.');
|
||||||
}
|
}
|
||||||
|
|
||||||
var identifiers = range.split('-');
|
var parts = pattern.exec(range);
|
||||||
range = identifiers[0];
|
var major = Number(parts[4]);
|
||||||
|
var minor = Number(parts[5]);
|
||||||
var isRange = isNaN(Number(range[0])),
|
var patch = Number(parts[6]);
|
||||||
version = isRange ? range.substr(1) : range,
|
|
||||||
parts = Common.map(version.split('.'), function(part) {
|
|
||||||
return Number(part);
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isRange: isRange,
|
isRange: Boolean(parts[1] || parts[2]),
|
||||||
version: version,
|
version: parts[3],
|
||||||
range: range,
|
range: range,
|
||||||
operator: isRange ? range[0] : '',
|
operator: parts[1] || parts[2] || '',
|
||||||
parts: parts,
|
major: major,
|
||||||
prerelease: identifiers[1],
|
minor: minor,
|
||||||
number: parts[0] * 1e8 + parts[1] * 1e4 + parts[2]
|
patch: patch,
|
||||||
|
parts: [major, minor, patch],
|
||||||
|
prerelease: parts[7],
|
||||||
|
number: major * 1e8 + minor * 1e4 + patch
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -311,30 +312,36 @@ var Common = require('./Common');
|
||||||
Plugin.versionSatisfies = function(version, range) {
|
Plugin.versionSatisfies = function(version, range) {
|
||||||
range = range || '*';
|
range = range || '*';
|
||||||
|
|
||||||
var rangeParsed = Plugin.versionParse(range),
|
var r = Plugin.versionParse(range),
|
||||||
rangeParts = rangeParsed.parts,
|
v = Plugin.versionParse(version);
|
||||||
versionParsed = Plugin.versionParse(version),
|
|
||||||
versionParts = versionParsed.parts;
|
|
||||||
|
|
||||||
if (rangeParsed.isRange) {
|
if (r.isRange) {
|
||||||
if (rangeParsed.operator === '*' || version === '*') {
|
if (r.operator === '*' || version === '*') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rangeParsed.operator === '~') {
|
if (r.operator === '>') {
|
||||||
return versionParts[0] === rangeParts[0] && versionParts[1] === rangeParts[1] && versionParts[2] >= rangeParts[2];
|
return v.number > r.number;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rangeParsed.operator === '^') {
|
if (r.operator === '>=') {
|
||||||
if (rangeParts[0] > 0) {
|
return v.number >= r.number;
|
||||||
return versionParts[0] === rangeParts[0] && versionParsed.number >= rangeParsed.number;
|
}
|
||||||
|
|
||||||
|
if (r.operator === '~') {
|
||||||
|
return v.major === r.major && v.minor === r.minor && v.patch >= r.patch;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (r.operator === '^') {
|
||||||
|
if (r.major > 0) {
|
||||||
|
return v.major === r.major && v.number >= r.number;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rangeParts[1] > 0) {
|
if (r.minor > 0) {
|
||||||
return versionParts[1] === rangeParts[1] && versionParts[2] >= rangeParts[2];
|
return v.minor === r.minor && v.patch >= r.patch;
|
||||||
}
|
}
|
||||||
|
|
||||||
return versionParts[2] === rangeParts[2];
|
return v.patch === r.patch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue