ReviewOS

also looking at this

stacks/stx

feat(layouts): honour a fallback layouts directory

#1942
Merged chris wants to merge fix/fallback-layouts-dir into main
5 files +174 -10
packages/stx/src/process.tsmodified+19-9
Changes to packages/stx/src/process.ts
@@ -1084,20 +1084,30 @@ async function processDirectivesInternal(
10841084 // compare against, the message was easy to scroll past — which is how a
10851085 // page ends up asserting a layout group with no layout behind it
10861086 // (#1879).
1087 let available: string[] = []
1088 try {
1089 const dir = resolvedOptions.layoutsDir
1090 if (dir) {
1087 //
1088 // Both directories are listed, not just `layoutsDir`. Reporting only
1089 // the app's own layouts made a resolvable-but-unconfigured fallback
1090 // look like the layout did not exist anywhere, which sent the search
1091 // in the wrong direction entirely.
1092 const layoutsIn = (dir: string | undefined): string[] => {
1093 if (!dir)
1094 return []
1095 try {
10911096 const abs = path.isAbsolute(dir) ? dir : path.resolve(process.cwd(), dir)
1092 available = fs.readdirSync(abs)
1097 return fs.readdirSync(abs)
10931098 .filter(f => f.endsWith('.stx'))
10941099 .map(f => f.replace(/\.stx$/, ''))
1095 .sort()
1100 }
1101 catch {
1102 // Unreadable directory — the message is still worth emitting.
1103 return []
10961104 }
10971105 }
1098 catch {
1099 // Unreadable layoutsDir — the message is still worth emitting.
1100 }
1106
1107 const available = [
1108 ...layoutsIn(resolvedOptions.layoutsDir),
1109 ...layoutsIn(resolvedOptions.fallbackLayoutsDir),
1110 ].filter((name, index, all) => all.indexOf(name) === index).sort()
11011111
11021112 const warning = `Layout not found: ${layoutPath} (referenced from ${filePath})`
11031113 + (available.length > 0