also looking at this
feat(layouts): honour a fallback layouts directory
#1942
5 files
+174
-10
| @@ -1084,20 +1084,30 @@ async function processDirectivesInternal( | ||
| 1084 | 1084 | // compare against, the message was easy to scroll past — which is how a |
| 1085 | 1085 | // page ends up asserting a layout group with no layout behind it |
| 1086 | 1086 | // (#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 { | |
| 1091 | 1096 | const abs = path.isAbsolute(dir) ? dir : path.resolve(process.cwd(), dir) |
| 1092 | available = fs.readdirSync(abs) | |
| 1097 | return fs.readdirSync(abs) | |
| 1093 | 1098 | .filter(f => f.endsWith('.stx')) |
| 1094 | 1099 | .map(f => f.replace(/\.stx$/, '')) |
| 1095 | .sort() | |
| 1100 | } | |
| 1101 | catch { | |
| 1102 | // Unreadable directory — the message is still worth emitting. | |
| 1103 | return [] | |
| 1096 | 1104 | } |
| 1097 | 1105 | } |
| 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() | |
| 1101 | 1111 | |
| 1102 | 1112 | const warning = `Layout not found: ${layoutPath} (referenced from ${filePath})` |
| 1103 | 1113 | + (available.length > 0 |