From d58786f40586f8c520d3ae3a0088f2e56798f894 Mon Sep 17 00:00:00 2001 From: Shane McLaughlin Date: Wed, 29 May 2024 11:39:54 -0500 Subject: [PATCH] feat: handle non-json from npm view (#1099) * feat: handle non-json responses from npm view * docs: npm bug link * docs: correct bug link --- src/commands/cli/artifacts/compare.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/commands/cli/artifacts/compare.ts b/src/commands/cli/artifacts/compare.ts index b927c1ee..df80d4d3 100644 --- a/src/commands/cli/artifacts/compare.ts +++ b/src/commands/cli/artifacts/compare.ts @@ -30,7 +30,13 @@ const messages = Messages.loadMessages('@salesforce/plugin-release-management', async function getOwnerAndRepo(plugin: string): Promise<{ owner: string; repo: string }> { const result = await exec(`npm view ${plugin} repository.url --json`); try { - const [owner, repo] = (JSON.parse(result.stdout) as string) + const [owner, repo] = ( + result.stdout.startsWith('"') + ? // it returned json (a string in quotes ex: "git+https://github.com/salesforcecli/plugin-org.git") + (JSON.parse(result.stdout) as string) + : // it returned non-json (just the string) https://github.com/npm/cli/issues/7537 + result.stdout + ) .replace('git+https://github.com/', '') .replace('.git', '') .split('/');