Add semver compatibility checking

This commit is contained in:
hensm
2018-12-12 20:27:30 +00:00
parent 54150568c2
commit 771233040f
7 changed files with 59 additions and 30 deletions

View File

@@ -24,6 +24,9 @@
, "optionsBridgeFoundStatusText": { , "optionsBridgeFoundStatusText": {
"message": "Bridge found" "message": "Bridge found"
} }
, "optionsBridgeIssueStatusText": {
"message": "Bridge issue"
}
, "optionsBridgeNotFoundStatusText": { , "optionsBridgeNotFoundStatusText": {
"message": "Bridge not found. Try downloading and installing the latest version." "message": "Bridge not found. Try downloading and installing the latest version."
} }
@@ -45,6 +48,9 @@
, "optionsBridgeCompatible": { , "optionsBridgeCompatible": {
"message": "COMPATIBLE" "message": "COMPATIBLE"
} }
, "optionsBridgeMaybeCompatible": {
"message": "MAYBE COMPATIBLE"
}
, "optionsBridgeIncompatible": { , "optionsBridgeIncompatible": {
"message": "INCOMPATIBLE" "message": "INCOMPATIBLE"
} }

View File

@@ -14,24 +14,36 @@ export default async function getBridgeInfo () {
} }
/** /**
* Compare installed bridge version to the version the * If the target version is above 0.x.x range, API is stable
* extension was built alongside and is known to be * and versions with minor or patch level changes should be
* compatible with. * compatible.
*
* TODO: Determine compatibility with semver and enforce/notify
* user.
*/ */
if (applicationVersion !== APPLICATION_VERSION) { const isVersionCompatible =
semver.eq(applicationVersion, APPLICATION_VERSION)
|| semver.diff(applicationVersion, APPLICATION_VERSION) !== "major"
&& semver.major(APPLICATION_VERSION) !== 0;
const isVersionExact = semver.eq(applicationVersion, APPLICATION_VERSION);
const isVersionOlder = semver.lt(applicationVersion, APPLICATION_VERSION);
const isVersionNewer = semver.gt(applicationVersion, APPLICATION_VERSION);
// Print compatibility info to console
if (!isVersionCompatible) {
console.error(`Expecting ${APPLICATION_NAME} v${APPLICATION_VERSION}, found v${applicationVersion}.` console.error(`Expecting ${APPLICATION_NAME} v${APPLICATION_VERSION}, found v${applicationVersion}.`
, semver.lt(applicationVersion, APPLICATION_VERSION) , isVersionOlder
? "Try updating the native app to the latest version." ? "Try updating the native app to the latest version."
: "Try updating the extension to the latest version"); : "Try updating the extension to the latest version");
} }
return { return {
version: applicationVersion name: APPLICATION_NAME
, isVersionCompatible: applicationVersion === APPLICATION_VERSION , version: applicationVersion
, isVersionOlder: semver.lt(applicationVersion, APPLICATION_VERSION) , expectedVersion: APPLICATION_VERSION
, isVersionNewer: semver.gt(applicationVersion, APPLICATION_VERSION)
// Version info
, isVersionExact
, isVersionCompatible
, isVersionOlder
, isVersionNewer
}; };
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@@ -180,18 +180,29 @@ class App extends Component {
? "bridge__info--found" ? "bridge__info--found"
: "bridge__info--not-found"}`; : "bridge__info--not-found"}`;
const [ statusIcon, statusText ] = do {
if (!bridgeInfo) {
[ "assets/icons8-cancel-120.png"
, _("optionsBridgeNotFoundStatusText") ]
} else {
if (bridgeInfo.isVersionExact) {
[ "assets/icons8-ok-120.png"
, _("optionsBridgeFoundStatusText") ]
} else {
[ "assets/icons8-warn-120.png"
, _("optionsBridgeIssueStatusText") ]
}
}
};
<div className={bridgeInfoClasses}> <div className={bridgeInfoClasses}>
<div className="bridge__status"> <div className="bridge__status">
<img className="bridge__status-icon" <img className="bridge__status-icon"
width="60" height="60" width="60" height="60"
src={ bridgeInfo src={ statusIcon } />
? "assets/icons8-ok-120.png"
: "assets/icons8-cancel-120.png" } />
<h2 className="bridge__status-text"> <h2 className="bridge__status-text">
{ bridgeInfo { statusText }
? _("optionsBridgeFoundStatusText")
: _("optionsBridgeNotFoundStatusText") }
</h2> </h2>
</div> </div>
@@ -203,14 +214,22 @@ class App extends Component {
</tr> </tr>
<tr> <tr>
<th>{ _("optionsBridgeStatsExpectedVersion") }</th> <th>{ _("optionsBridgeStatsExpectedVersion") }</th>
<td>{ APPLICATION_VERSION }</td> <td>{ bridgeInfo.expectedVersion }</td>
</tr> </tr>
<tr> <tr>
<th>{ _("optionsBridgeStatsCompatibility") }</th> <th>{ _("optionsBridgeStatsCompatibility") }</th>
<td> <td>
{ bridgeInfo.isVersionCompatible { do {
? _("optionsBridgeCompatible") if (bridgeInfo.isVersionCompatible) {
: _("optionsBridgeIncompatible") } if (bridgeInfo.isVersionExact) {
_("optionsBridgeCompatible")
} else {
_("optionsBridgeMaybeCompatible")
}
} else {
_("optionsBridgeIncompatible")
}
}}
</td> </td>
</tr> </tr>
<tr> <tr>

View File

@@ -50,14 +50,6 @@
width: 100%; width: 100%;
} }
.bridge__missing {
background-color: #d70022;
border-radius: 5px;
color: white;
padding: 5px;
margin-top: 5px;
}
.bridge__info { .bridge__info {
display: flex; display: flex;
} }