Skip to content

Commit f480922

Browse files
authored
Merge pull request #55 from proofgeist:cursor/fix-webviewer-navigation-file-error-370a
Fix webviewer navigation file error
2 parents 9f4c30b + 00177bf commit f480922

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@proofkit/cli": patch
3+
---
4+
5+
Guard page add/remove against missing `src/app/navigation.tsx` so WebViewer apps don’t error when updating navigation. This safely no-ops when the navigation file isn’t present.

packages/cli/src/cli/remove/page.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ import { abortIfCancel, ensureProofKitProject } from "../utils.js";
1818
const getExistingRoutes = (
1919
project: Project
2020
): { label: string; href: string }[] => {
21-
const sourceFile = project.addSourceFileAtPath(
22-
path.join(state.projectDir, "src/app/navigation.tsx")
23-
);
21+
const navFilePath = path.join(state.projectDir, "src/app/navigation.tsx");
22+
23+
// If navigation file doesn't exist (e.g., webviewer apps), there are no nav routes to remove
24+
if (!fs.existsSync(navFilePath)) return [];
25+
26+
const sourceFile = project.addSourceFileAtPath(navFilePath);
2427

2528
const routes: { label: string; href: string }[] = [];
2629

@@ -88,9 +91,12 @@ const getExistingRoutes = (
8891
};
8992

9093
const removeRouteFromNav = async (project: Project, routeToRemove: string) => {
91-
const sourceFile = project.addSourceFileAtPath(
92-
path.join(state.projectDir, "src/app/navigation.tsx")
93-
);
94+
const navFilePath = path.join(state.projectDir, "src/app/navigation.tsx");
95+
96+
// Skip if there is no navigation file
97+
if (!fs.existsSync(navFilePath)) return;
98+
99+
const sourceFile = project.addSourceFileAtPath(navFilePath);
94100

95101
// Remove from primary routes
96102
const primaryRoutes = sourceFile
@@ -190,7 +196,7 @@ export const runRemovePageAction = async (routeName?: string) => {
190196
return p.cancel(`Page at ${routeName} does not exist`);
191197
}
192198

193-
// Remove from navigation first
199+
// Remove from navigation first (if present)
194200
await removeRouteFromNav(project, routeName);
195201

196202
// Remove the page directory

packages/cli/src/generators/route.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path from "path";
22
import { type RouteLink } from "index.js";
33
import { SyntaxKind } from "ts-morph";
4+
import fs from "fs-extra";
45

56
import { formatAndSaveSourceFiles, getNewProject } from "~/utils/ts-morph.js";
67

@@ -12,10 +13,13 @@ export async function addRouteToNav({
1213
projectDir: string;
1314
navType: "primary" | "secondary";
1415
}) {
16+
const navFilePath = path.join(projectDir, "src/app/navigation.tsx");
17+
18+
// If the navigation file doesn't exist (e.g., WebViewer apps), skip adding to nav
19+
if (!fs.existsSync(navFilePath)) return;
20+
1521
const project = getNewProject(projectDir);
16-
const sourceFile = project.addSourceFileAtPath(
17-
path.join(projectDir, "src/app/navigation.tsx")
18-
);
22+
const sourceFile = project.addSourceFileAtPath(navFilePath);
1923
sourceFile
2024
.getVariableDeclaration(
2125
navType === "primary" ? "primaryRoutes" : "secondaryRoutes"

pnpm-lock.yaml

Lines changed: 2 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)