From 515b85f518da47feba6d4cb2b3bbd0f271c731c1 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Mon, 23 Aug 2021 15:32:42 -0600 Subject: [PATCH] fix: fail gracefully when getting npm info --- src/repos.ts | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/repos.ts b/src/repos.ts index 3604baab..7ff8bdab 100644 --- a/src/repos.ts +++ b/src/repos.ts @@ -134,18 +134,22 @@ export class Repos extends ConfigFile { private async addAdditionalInfo(repo: Repository): Promise { const location = repo.location || path.join(this.directory.name, repo.org, repo.name); - const pkgJsonPath = path.join(location, 'package.json'); - const pkgJson = JSON.parse(await readFile(pkgJsonPath, 'utf-8')) as { name: string }; - repo.npm = { name: pkgJson.name }; - - const npmInfoRaw = exec(`npm view ${pkgJson.name} --json`, { silent: true }).stdout; - const npmInfo = JSON.parse(npmInfoRaw) as { - 'dist-tags': Record; - versions: string[]; - }; - repo.npm.version = npmInfo['dist-tags']['latest'] ?? npmInfo.versions.reverse()[0]; - repo.npm.tags = npmInfo['dist-tags']; repo.location = location; + const pkgJsonPath = path.join(location, 'package.json'); + try { + const pkgJson = JSON.parse(await readFile(pkgJsonPath, 'utf-8')) as { name: string }; + repo.npm = { name: pkgJson.name }; + + const npmInfoRaw = exec(`npm view ${pkgJson.name} --json`, { silent: true }).stdout; + const npmInfo = JSON.parse(npmInfoRaw) as { + 'dist-tags': Record; + versions: string[]; + }; + repo.npm.version = npmInfo['dist-tags']['latest'] ?? npmInfo.versions.reverse()[0]; + repo.npm.tags = npmInfo['dist-tags']; + } catch { + // likely not an npm package, which is okay + } return repo; } }