Add: adopt node-semver

This commit is contained in:
eight 2017-09-06 03:08:03 +08:00
parent f7a43d780f
commit 1f44898475
6 changed files with 13 additions and 32 deletions

View File

@ -1,5 +1,6 @@
/* global getStyles, saveStyle, styleSectionsEqual, chromeLocal */ /* global getStyles, saveStyle, styleSectionsEqual, chromeLocal */
/* global calcStyleDigest, usercss */ /* global calcStyleDigest */
/* global usercss semverCompare */
'use strict'; 'use strict';
// eslint-disable-next-line no-var // eslint-disable-next-line no-var
@ -100,10 +101,10 @@ var updater = {
return Promise.reject(updater.ERROR_VERSION); return Promise.reject(updater.ERROR_VERSION);
} }
if (style.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); 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); return Promise.reject(updater.ERROR_VERSION);
} }
} }

View File

@ -1,4 +1,4 @@
/* global usercss */ /* global semverCompare */
'use strict'; 'use strict';
@ -63,8 +63,8 @@ function getAppliesTo(style) {
} }
function initInstallPage({style, dup}) { function initInstallPage({style, dup}) {
pendingResource.then(() => { return pendingResource.then(() => {
const versionTest = dup && usercss.semverTest(style.version, dup.version); const versionTest = dup && semverCompare(style.version, dup.version);
document.body.innerHTML = ''; document.body.innerHTML = '';
// FIXME: i18n // FIXME: i18n
document.body.appendChild(tHTML(` document.body.appendChild(tHTML(`
@ -113,7 +113,7 @@ function initInstallPage({style, dup}) {
} }
function initErrorPage(err, source) { function initErrorPage(err, source) {
pendingResource.then(() => { return pendingResource.then(() => {
document.body.innerHTML = ''; document.body.innerHTML = '';
// FIXME: i18n // FIXME: i18n
document.body.appendChild(tHTML(` document.body.appendChild(tHTML(`
@ -135,6 +135,7 @@ function initUsercssInstall() {
'/js/dom.js', '/js/dom.js',
'/js/localization.js', '/js/localization.js',
'/js/usercss.js', '/js/usercss.js',
'/vendor/node-semver/semver.js',
'/content/install-user-css.css' '/content/install-user-css.css'
] ]
}); });

View File

@ -9,30 +9,6 @@ var usercss = (function () {
'namespace', 'noframes', 'preprocessor', 'supportURL', 'var', 'version' '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 = { const BUILDER = {
default: { default: {
postprocess(sections, vars) { postprocess(sections, vars) {
@ -243,5 +219,5 @@ var usercss = (function () {
// FIXME: validate variable formats // FIXME: validate variable formats
} }
return {buildMeta, buildCode, semverTest}; return {buildMeta, buildCode};
})(); })();

View File

@ -27,6 +27,7 @@
"js/prefs.js", "js/prefs.js",
"js/script-loader.js", "js/script-loader.js",
"background/background.js", "background/background.js",
"vendor/node-semver/semver.js",
"background/update.js" "background/update.js"
] ]
}, },

1
vendor/node-semver/README.md vendored Normal file
View File

@ -0,0 +1 @@
See https://github.com/eight04/node-semver-bundle.

1
vendor/node-semver/semver.js vendored Normal file

File diff suppressed because one or more lines are too long