fix(support): Make upgradable versions parsing more permissive
MODIFY
packages/appium/lib/cli/extension-command.js
packages/appium/lib/cli/extension-command.js
@@ -128,10 +128,14 @@ class ExtensionCommand {
// also don't need to check for updates on non-npm exts
continue;
}
+ try {
const updates = await this.checkForExtensionUpdate(ext);
data.updateVersion = updates.safeUpdate;
data.unsafeUpdateVersion = updates.unsafeUpdate;
data.upToDate = updates.safeUpdate === null && updates.unsafeUpdate === null;
+ } catch (e) {
+ data.updateError = e.message;
+ }
}
});
@@ -149,8 +153,15 @@ class ExtensionCommand {
let upToDateTxt = '';
let unsafeUpdateTxt = '';
if (data.installed) {
- const {installType, installSpec, updateVersion, unsafeUpdateVersion, version, upToDate} =
- data;
+ const {
+ installType,
+ installSpec,
+ updateVersion,
+ unsafeUpdateVersion,
+ version,
+ upToDate,
+ updateError,
+ } = data;
let typeTxt;
switch (installType) {
case INSTALL_TYPE_GIT:
@@ -166,6 +177,9 @@ class ExtensionCommand {
installTxt = `@${version.yellow} ${('[installed ' + typeTxt + ']').green}`;
if (showUpdates) {
+ if (updateError) {
+ updateTxt = ` [Cannot check for updates: ${updateError}]`.red;
+ } else {
if (updateVersion) {
updateTxt = ` [${updateVersion} available]`.magenta;
}
@@ -177,6 +191,7 @@ class ExtensionCommand {
}
}
}
+ }
this.log.log(`- ${name.yellow}${installTxt}${updateTxt}${upToDateTxt}${unsafeUpdateTxt}`);
}
@@ -701,6 +716,7 @@ export {ExtensionCommand};
* @property {string?} updateVersion - If the extension is installed, the version it can be updated to
* @property {string?} unsafeUpdateVersion - Same as above, but a major version bump
* @property {boolean} upToDate - If the extension is installed and the latest
+ * @property {string?} updateError - Update check error message (if present)
*/
/**

MODIFY
packages/support/lib/npm.js
packages/support/lib/npm.js
@@ -156,14 +156,14 @@ export class NPM {
*/
getLatestSafeUpgradeFromVersions(curVersion, allVersions) {
let safeUpgradeVer = null;
- const curSemver = semver.parse(curVersion);
+ const curSemver = semver.parse(curVersion) ?? semver.parse(semver.coerce(curVersion));
if (curSemver === null) {
throw new Error(`Could not parse current version '${curVersion}'`);
}
for (const testVer of allVersions) {
- const testSemver = semver.parse(testVer);
+ const testSemver = semver.parse(testVer) ?? semver.parse(semver.coerce(testVer));
if (testSemver === null) {
- throw new Error(`Could not parse version to test against: '${testVer}'`);
+ continue;
}
// if the test version is a prerelease, ignore it
if (testSemver.prerelease.length > 0) {

MODIFY
packages/support/test/unit/npm.spec.js
packages/support/test/unit/npm.spec.js
@@ -25,6 +25,17 @@ describe('npm', function () {
npm.getLatestSafeUpgradeFromVersions('1.0.0', versions1).should.eql('1.2.7');
npm.getLatestSafeUpgradeFromVersions('0.2.0', versions1).should.eql('0.2.5');
});
+ it('should throw if the current version cannot be parsed', function () {
+ should.throw(() => {
+ npm.getLatestSafeUpgradeFromVersions('', versions1);
+ });
+ });
+ it('should ignore an error if one of versions cannot be parsed', function () {
+ npm.getLatestSafeUpgradeFromVersions('0.1.0', ['', '0.2.0']).should.eql('0.2.0');
+ });
+ it('should return null if no newer version is found', function () {
+ (null === npm.getLatestSafeUpgradeFromVersions('10', versions1)).should.be.true;
+ });
});
it('should have many more unit tests');

fix(support): Make upgradable versions parsing more permissive (#17666)