Skip to content

Commit 306567b

Browse files
committed
fix: handle missing dependencies in generate-technical-writer-prompts
- Add null checks for packageJson.dependencies and devDependencies - Ensure file exists before reading package.json - Add proper error handling for directory read failures - Fixes test failure where projectType was detected as 'unknown'
1 parent 4a70e6d commit 306567b

1 file changed

Lines changed: 27 additions & 19 deletions

File tree

src/tools/generate-technical-writer-prompts.ts

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,18 @@ async function buildProjectContext(
232232

233233
// Analyze package.json if it exists
234234
try {
235-
const packageJson = JSON.parse(
236-
await fs.readFile(packageJsonPath, "utf-8"),
237-
);
235+
// Ensure file exists before reading
236+
if (!(await fileExists(packageJsonPath))) {
237+
throw new Error("package.json not found");
238+
}
239+
240+
const packageJsonContent = await fs.readFile(packageJsonPath, "utf-8");
241+
const packageJson = JSON.parse(packageJsonContent);
238242

239243
// Determine project type from dependencies
240244
const deps = {
241-
...packageJson.dependencies,
242-
...packageJson.devDependencies,
245+
...(packageJson.dependencies || {}),
246+
...(packageJson.devDependencies || {}),
243247
};
244248

245249
if (deps["react"]) frameworks.push("React");
@@ -258,21 +262,25 @@ async function buildProjectContext(
258262
else if (await fileExists(join(projectPath, "pnpm-lock.yaml")))
259263
packageManager = "pnpm";
260264
else packageManager = "npm";
261-
} catch {
265+
} catch (error) {
262266
// Fallback analysis for non-Node.js projects
263-
const files = await fs.readdir(projectPath);
264-
265-
if (files.some((f) => f.endsWith(".py"))) {
266-
languages.push("Python");
267-
projectType = "python_application";
268-
}
269-
if (files.some((f) => f.endsWith(".rs"))) {
270-
languages.push("Rust");
271-
projectType = "rust_application";
272-
}
273-
if (files.some((f) => f.endsWith(".go"))) {
274-
languages.push("Go");
275-
projectType = "go_application";
267+
try {
268+
const files = await fs.readdir(projectPath);
269+
270+
if (files.some((f) => f.endsWith(".py"))) {
271+
languages.push("Python");
272+
projectType = "python_application";
273+
}
274+
if (files.some((f) => f.endsWith(".rs"))) {
275+
languages.push("Rust");
276+
projectType = "rust_application";
277+
}
278+
if (files.some((f) => f.endsWith(".go"))) {
279+
languages.push("Go");
280+
projectType = "go_application";
281+
}
282+
} catch {
283+
// If directory read also fails, keep default "unknown"
276284
}
277285
}
278286

0 commit comments

Comments
 (0)