Skip to content

Commit b5c4a1f

Browse files
authored
fix: detect 404 in getActiveVersion by --json (#70)
1 parent 1b53c2d commit b5c4a1f

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/utils.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,20 @@ export async function getActiveVersion(
159159
npmName: string,
160160
): Promise<string | undefined> {
161161
try {
162-
return (await run("npm", ["info", npmName, "version"], { stdio: "pipe" }))
163-
.stdout;
162+
const { stdout } = await run(
163+
"npm",
164+
["info", npmName, "version", "--json"],
165+
{ stdio: "pipe" },
166+
);
167+
return JSON.parse(stdout);
164168
} catch (e: any) {
165169
// Not published yet
166-
if (e.stderr.startsWith("npm ERR! code E404")) return;
170+
if (e.stdout) {
171+
const stdout = JSON.parse(e.stdout);
172+
if (stdout.error.code === "E404") {
173+
return;
174+
}
175+
}
167176
throw e;
168177
}
169178
}

0 commit comments

Comments
 (0)