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/bun-plugin/src/serve.tsmodified+13-0
Changes to packages/bun-plugin/src/serve.ts
@@ -537,6 +537,15 @@ export interface ServeOptions {
537537 openPath?: string
538538 componentsDir?: string
539539 layoutsDir?: string
540 /**
541 * Layouts to fall back to when `layoutsDir` does not have the one a page
542 * asks for, so a framework can ship defaults an app overrides by name.
543 *
544 * Stacks has been passing this since the views server was written; until
545 * stx honoured it, it did nothing, and every page extending a framework
546 * layout served a 200 with an empty body.
547 */
548 fallbackLayoutsDir?: string
540549 partialsDir?: string
541550 /**
542551 * Additional source directories that can affect rendered HTML.
@@ -1015,6 +1024,7 @@ export async function serve(options: ServeOptions): Promise<void> {
10151024 // Options passed directly take precedence, then bunfig config, then defaults
10161025 const componentsDir = options.componentsDir ?? stxConfig.componentsDir ?? defaultStxConfig.componentsDir
10171026 const layoutsDir = options.layoutsDir ?? stxConfig.layoutsDir ?? defaultStxConfig.layoutsDir
1027 const fallbackLayoutsDir = options.fallbackLayoutsDir ?? stxConfig.fallbackLayoutsDir
10181028 const partialsDir = options.partialsDir ?? stxConfig.partialsDir ?? defaultStxConfig.partialsDir
10191029 const publicDir = options.publicDir ?? stxConfig.publicDir ?? 'public'
10201030
@@ -2203,6 +2213,7 @@ function __stxOverlay(errs){
22032213 root: process.cwd(),
22042214 ...(componentsDir && { componentsDir }),
22052215 ...(layoutsDir && { layoutsDir }),
2216 ...(fallbackLayoutsDir && { fallbackLayoutsDir }),
22062217 ...(partialsDir && { partialsDir }),
22072218 autoShell: true,
22082219 buildMode: 'serve' as const,
@@ -2576,6 +2587,7 @@ function __stxOverlay(errs){
25762587 root: process.cwd(),
25772588 ...(componentsDir && { componentsDir }),
25782589 ...(layoutsDir && { layoutsDir }),
2590 ...(fallbackLayoutsDir && { fallbackLayoutsDir }),
25792591 ...(partialsDir && { partialsDir }),
25802592 autoShell: true,
25812593 buildMode: 'serve' as const,
@@ -3164,6 +3176,7 @@ function __stxOverlay(errs){
31643176 ...defaultConfig,
31653177 ...(componentsDir && { componentsDir }),
31663178 ...(layoutsDir && { layoutsDir }),
3179 ...(fallbackLayoutsDir && { fallbackLayoutsDir }),
31673180 ...(partialsDir && { partialsDir }),
31683181 autoShell: false,
31693182 }