Handle case when npm would return an error code (#3340)

This commit is contained in:
Alexandru Dima 2022-09-29 14:53:09 +02:00 committed by GitHub
parent 35eb0efbc0
commit 9d4574b10b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View file

@ -90,10 +90,14 @@ function npmGetLatestVersion(packageName) {
* @returns {boolean}
*/
function npmExists(packageName, version) {
const output = cp.execSync(`npm show ${packageName}@${version} version`).toString();
const result = output.split(/\r\n|\r|\n/g)[0];
if (result.trim().length === 0) {
try {
const output = cp.execSync(`npm show ${packageName}@${version} version`).toString();
const result = output.split(/\r\n|\r|\n/g)[0];
if (result.trim().length === 0) {
return false;
}
return true;
} catch (err) {
return false;
}
return true;
}