fix(workspace): recursively search for nested object directories in findObjectDir

findObjectDir only searched the workspace root and one level deep, so objects
nested inside category folders (e.g. marketing/influencer/) were not discovered
by the views API. This caused saved views, active_view, and view_settings to
silently return empty for any object beyond depth 1.

Replace the single-level scan with a depth-limited recursive search (max 4
levels), skipping known heavy directories (node_modules, .git, .next, etc.).

The sidebar tree builder (buildTree in tree/route.ts) already walks recursively,
so this brings findObjectDir in line with the rest of the workspace discovery.
This commit is contained in:
kumarabhirup 2026-03-06 00:41:26 -08:00
parent 4578dfa945
commit 7cf895a3c7
No known key found for this signature in database
GPG Key ID: DB7CA2289CAB0167

View File

@ -1016,8 +1016,9 @@ export function writeObjectYaml(objectDir: string, config: ObjectYamlConfig): vo
/**
* Find the filesystem directory for an object by name.
* Walks the workspace tree looking for a directory containing a .object.yaml
* or a directory matching the object name inside the workspace.
* Recursively walks the workspace tree looking for a directory containing a
* .object.yaml matching the given object name. This ensures objects nested
* inside category folders (e.g. marketing/influencer) are discovered correctly.
*/
export function findObjectDir(objectName: string): string | null {
const root = resolveWorkspaceRoot();
@ -1029,21 +1030,31 @@ export function findObjectDir(objectName: string): string | null {
return direct;
}
// Search one level deep for a matching .object.yaml
try {
const entries = readdirSync(root, { withFileTypes: true });
for (const entry of entries) {
if (!entry.isDirectory()) {continue;}
const subDir = join(root, entry.name);
if (entry.name === objectName && existsSync(join(subDir, ".object.yaml"))) {
return subDir;
// Recursively search for a directory named {objectName} containing .object.yaml.
// Depth-limited to avoid traversing heavy subtrees.
const MAX_DEPTH = 4;
const SKIP_DIRS = new Set(["node_modules", ".git", ".next", "tmp", "exports"]);
function search(dir: string, depth: number): string | null {
if (depth > MAX_DEPTH) {return null;}
try {
const entries = readdirSync(dir, { withFileTypes: true });
for (const entry of entries) {
if (!entry.isDirectory() || entry.name.startsWith(".") || SKIP_DIRS.has(entry.name)) {continue;}
const subDir = join(dir, entry.name);
if (entry.name === objectName && existsSync(join(subDir, ".object.yaml"))) {
return subDir;
}
const found = search(subDir, depth + 1);
if (found) {return found;}
}
} catch {
// ignore read errors (permission denied, etc.)
}
} catch {
// ignore read errors
return null;
}
return null;
return search(root, 1);
}
/**