Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Enhance package.json validation in stack doctor command
  • Loading branch information
aadesh18 committed May 5, 2026
commit c7de4348b4dfb877e6f5c2e26378a42453eb8df6
10 changes: 9 additions & 1 deletion packages/stack-cli/src/commands/doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,20 @@ type PackageJsonRead =
| { kind: "missing" }
| { kind: "invalid", error: string };

function isPackageJson(value: unknown): value is PackageJson {
return value !== null && typeof value === "object" && !Array.isArray(value);
}

function readPackageJson(projectDir: string): PackageJsonRead {
const pkgPath = path.join(projectDir, "package.json");
if (!fs.existsSync(pkgPath)) return { kind: "missing" };
const raw = fs.readFileSync(pkgPath, "utf-8");
try {
return { kind: "ok", value: JSON.parse(raw) as PackageJson };
const parsed: unknown = JSON.parse(raw);
if (!isPackageJson(parsed)) {
return { kind: "invalid", error: "package.json must be a JSON object." };
}
return { kind: "ok", value: parsed };
} catch (error) {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
if (error instanceof SyntaxError) {
return { kind: "invalid", error: error.message };
Expand Down
Loading