Skip to content

Commit e660351

Browse files
angeloashmoreclaude
andcommitted
fix: validate npm registry response in getNpmPackageVersion
Use `request` with a Zod schema to ensure the response is OK and contains a valid version string. Previously, a failed fetch could write a bad state file that blocked retries for 24 hours. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent eb53960 commit e660351

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/lib/packageJson.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { x } from "tinyexec";
55
import { z } from "zod/mini";
66

77
import { exists, findUpward, readJsonFile } from "./file";
8+
import { request } from "./request";
89

910
const PackageJsonSchema = z.object({
1011
dependencies: z.optional(z.record(z.string(), z.string())),
@@ -48,8 +49,9 @@ export async function addDependencies(dependencies: Record<string, string>): Pro
4849

4950
export async function getNpmPackageVersion(name: string, tag = "latest"): Promise<string> {
5051
const url = new URL(`${name}/${tag}`, "https://registry.npmjs.org/");
51-
const res = await fetch(url);
52-
const { version } = await res.json();
52+
const { version } = await request(url, {
53+
schema: z.object({ version: z.string() }),
54+
});
5355
return version;
5456
}
5557

0 commit comments

Comments
 (0)