fix(support): update checks eat errors from non-existent packages
MODIFY
packages/support/lib/npm.js
packages/support/lib/npm.js
@@ -92,22 +92,34 @@ export class NPM {
/**
* @param {string} cwd
* @param {string} pkg
+ * @returns {Promise<string?>}
*/
async getLatestVersion(cwd, pkg) {
+ try {
return (
+ (
await this.exec('view', [pkg, 'dist-tags'], {
json: true,
cwd,
})
- ).json?.latest;
+ ).json?.latest ?? null
+ );
+ } catch (err) {
+ if (!err?.message.includes('E404')) {
+ throw err;
+ }
+ return null;
+ }
}
/**
* @param {string} cwd
* @param {string} pkg
* @param {string} curVersion
+ * @returns {Promise<string?>}
*/
async getLatestSafeUpgradeVersion(cwd, pkg, curVersion) {
+ try {
const allVersions = (
await this.exec('view', [pkg, 'versions'], {
json: true,
@@ -115,6 +127,12 @@ export class NPM {
})
).json;
return this.getLatestSafeUpgradeFromVersions(curVersion, allVersions);
+ } catch (err) {
+ if (!err?.message.includes('E404')) {
+ throw err;
+ }
+ return null;
+ }
}
/**
@@ -194,7 +212,7 @@ export class NPM {
}
const installOpts = ['--save-dev'];
- if (!await hasAppiumDependency(cwd)) {
+ if (!(await hasAppiumDependency(cwd))) {
if (process.env.APPIUM_OMIT_PEER_DEPS) {
installOpts.push('--omit=peer');
}

ADD
packages/support/test/e2e/npm.e2e.spec.js
+import {npm} from '../../lib/npm';
+
+const {expect} = chai;
+
+describe('npm module', function () {
+ describe('getLatestVersion()', function () {
+ describe('when the package is not published to the public registry', function () {
+ it('should not throw', async function () {
+ await expect(
+ npm.getLatestVersion(
+ process.cwd(),
+ 'crusher-brush-resize-disfigure-props-desktop-blatancy-prologue'
+ )
+ ).not.to.be.rejected;
+ });
+
+ it('should resolve with "null"', async function () {
+ await expect(
+ npm.getLatestVersion(
+ process.cwd(),
+ 'crusher-brush-resize-disfigure-props-desktop-blatancy-prologue'
+ )
+ ).to.eventually.be.null;
+ });
+ });
+ });
+
+ describe('getLatestSafeUpgradeVersion()', function () {
+ describe('when the package is not published to the public registry', function () {
+ it('should not throw', async function () {
+ await expect(
+ npm.getLatestSafeUpgradeVersion(
+ process.cwd(),
+ 'crusher-brush-resize-disfigure-props-desktop-blatancy-prologue',
+ '1.0.0'
+ )
+ ).to.eventually.be.null;
+ });
+
+ it('should resolve with "null"', async function () {
+ await expect(
+ npm.getLatestSafeUpgradeVersion(
+ process.cwd(),
+ 'crusher-brush-resize-disfigure-props-desktop-blatancy-prologue',
+ '1.0.0'
+ )
+ ).to.eventually.be.null;
+ });
+ });
+ });
+});

fix(support): update checks eat errors from non-existent packages