Add: adopt node-semver
This commit is contained in:
parent
f7a43d780f
commit
1f44898475
|
@ -1,5 +1,6 @@
|
|||
/* global getStyles, saveStyle, styleSectionsEqual, chromeLocal */
|
||||
/* global calcStyleDigest, usercss */
|
||||
/* global calcStyleDigest */
|
||||
/* global usercss semverCompare */
|
||||
'use strict';
|
||||
|
||||
// eslint-disable-next-line no-var
|
||||
|
@ -100,10 +101,10 @@ var updater = {
|
|||
return Promise.reject(updater.ERROR_VERSION);
|
||||
}
|
||||
if (style.version) {
|
||||
if (usercss.semverTest(style.version, json.version) === 0) {
|
||||
if (semverCompare(style.version, json.version) === 0) {
|
||||
return Promise.reject(updater.SAME_VERSION);
|
||||
}
|
||||
if (usercss.semverTest(style.version, json.version) > 0) {
|
||||
if (semverCompare(style.version, json.version) > 0) {
|
||||
return Promise.reject(updater.ERROR_VERSION);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* global usercss */
|
||||
/* global semverCompare */
|
||||
|
||||
'use strict';
|
||||
|
||||
|
@ -63,8 +63,8 @@ function getAppliesTo(style) {
|
|||
}
|
||||
|
||||
function initInstallPage({style, dup}) {
|
||||
pendingResource.then(() => {
|
||||
const versionTest = dup && usercss.semverTest(style.version, dup.version);
|
||||
return pendingResource.then(() => {
|
||||
const versionTest = dup && semverCompare(style.version, dup.version);
|
||||
document.body.innerHTML = '';
|
||||
// FIXME: i18n
|
||||
document.body.appendChild(tHTML(`
|
||||
|
@ -113,7 +113,7 @@ function initInstallPage({style, dup}) {
|
|||
}
|
||||
|
||||
function initErrorPage(err, source) {
|
||||
pendingResource.then(() => {
|
||||
return pendingResource.then(() => {
|
||||
document.body.innerHTML = '';
|
||||
// FIXME: i18n
|
||||
document.body.appendChild(tHTML(`
|
||||
|
@ -135,6 +135,7 @@ function initUsercssInstall() {
|
|||
'/js/dom.js',
|
||||
'/js/localization.js',
|
||||
'/js/usercss.js',
|
||||
'/vendor/node-semver/semver.js',
|
||||
'/content/install-user-css.css'
|
||||
]
|
||||
});
|
||||
|
|
|
@ -9,30 +9,6 @@ var usercss = (function () {
|
|||
'namespace', 'noframes', 'preprocessor', 'supportURL', 'var', 'version'
|
||||
];
|
||||
|
||||
// FIXME: use a real semver module
|
||||
function semverTest(a, b) {
|
||||
a = a.split('.').map(Number);
|
||||
b = b.split('.').map(Number);
|
||||
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
if (!(i in b)) {
|
||||
return 1;
|
||||
}
|
||||
if (a[i] < b[i]) {
|
||||
return -1;
|
||||
}
|
||||
if (a[i] > b[i]) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (a.length < b.length) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const BUILDER = {
|
||||
default: {
|
||||
postprocess(sections, vars) {
|
||||
|
@ -243,5 +219,5 @@ var usercss = (function () {
|
|||
// FIXME: validate variable formats
|
||||
}
|
||||
|
||||
return {buildMeta, buildCode, semverTest};
|
||||
return {buildMeta, buildCode};
|
||||
})();
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
"js/prefs.js",
|
||||
"js/script-loader.js",
|
||||
"background/background.js",
|
||||
"vendor/node-semver/semver.js",
|
||||
"background/update.js"
|
||||
]
|
||||
},
|
||||
|
|
1
vendor/node-semver/README.md
vendored
Normal file
1
vendor/node-semver/README.md
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
See https://github.com/eight04/node-semver-bundle.
|
1
vendor/node-semver/semver.js
vendored
Normal file
1
vendor/node-semver/semver.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user