From 86e570efb24de955fefe56ce6f4fe81179d116e6 Mon Sep 17 00:00:00 2001 From: Al McKinlay Date: Fri, 21 Aug 2020 12:26:35 +0100 Subject: [PATCH] Add version support for packages. --- src/command-line/install.js | 16 ++++++++++++++++ src/helper.js | 5 +++++ src/plugins/packages/index.js | 8 ++++++++ 3 files changed, 29 insertions(+) diff --git a/src/command-line/install.js b/src/command-line/install.js index 18ccbb61..53108f57 100644 --- a/src/command-line/install.js +++ b/src/command-line/install.js @@ -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}`) diff --git a/src/helper.js b/src/helper.js index fcfe93ff..c12fde10 100644 --- a/src/helper.js +++ b/src/helper.js @@ -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() { diff --git a/src/plugins/packages/index.js b/src/plugins/packages/index.js index d0ec3943..ea1ed2cd 100644 --- a/src/plugins/packages/index.js +++ b/src/plugins/packages/index.js @@ -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)}`);