Add version support for packages.

This commit is contained in:
Al McKinlay 2020-08-21 12:26:35 +01:00
parent 7bf4f68ff8
commit 86e570efb2
3 changed files with 29 additions and 0 deletions

View file

@ -2,6 +2,7 @@
const log = require("../log");
const colors = require("chalk");
const semver = require("semver");
const program = require("commander");
const Helper = require("../helper");
const Utils = require("./utils");
@ -40,6 +41,21 @@ program
process.exit(1);
}
if (
json.thelounge.supports &&
!semver.satisfies(Helper.getVersionNumber(), json.thelounge.supports)
) {
log.error(
`${colors.red(
json.name + " v" + json.version
)} does not support The Lounge v${Helper.getVersionNumber()}. Supported version(s): ${
json.thelounge.supports
}`
);
process.exit(2);
}
log.info(`Installing ${colors.green(json.name + " v" + json.version)}...`);
return Utils.executeYarnCommand("add", "--exact", `${json.name}@${json.version}`)

View file

@ -36,6 +36,7 @@ const Helper = {
setHome,
getVersion,
getVersionCacheBust,
getVersionNumber,
getGitCommit,
ip2hex,
mergeConfig,
@ -60,6 +61,10 @@ function getVersion() {
return gitCommit ? `source (${gitCommit} / ${version})` : version;
}
function getVersionNumber() {
return pkg.version;
}
let _gitCommit;
function getGitCommit() {

View file

@ -4,6 +4,7 @@ const _ = require("lodash");
const log = require("../../log");
const colors = require("chalk");
const path = require("path");
const semver = require("semver");
const Helper = require("../../helper");
const themes = require("./themes");
const packageMap = new Map();
@ -93,6 +94,13 @@ function loadPackage(packageName) {
throw "'thelounge' is not present in package.json";
}
if (
packageInfo.thelounge.supports &&
!semver.satisfies(Helper.getVersionNumber(), packageInfo.thelounge.supports)
) {
throw `v${packageInfo.version} does not support this version of The Lounge. Supports: ${packageInfo.thelounge.supports}`;
}
packageFile = require(packagePath);
} catch (e) {
log.error(`Package ${colors.bold(packageName)} could not be loaded: ${colors.red(e)}`);