@timber-js/app 0.2.0-alpha.205 → 0.2.0-alpha.206
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_chunks/{chains-BjGKq9Je.js → chains-B4bgOl2g.js} +2 -2
- package/dist/_chunks/{chains-BjGKq9Je.js.map → chains-B4bgOl2g.js.map} +1 -1
- package/dist/_chunks/{cli-check-3WE_GyoL.js → cli-check-BqOylm-3.js} +2 -2
- package/dist/_chunks/{cli-check-3WE_GyoL.js.map → cli-check-BqOylm-3.js.map} +1 -1
- package/dist/_chunks/{cli-schema-sync-D3iIZjku.js → cli-schema-sync--LZKs8Zn.js} +2 -2
- package/dist/_chunks/{cli-schema-sync-D3iIZjku.js.map → cli-schema-sync--LZKs8Zn.js.map} +1 -1
- package/dist/_chunks/{dev-server-Dbdgx2dD.js → dev-server-BzBxgYAV.js} +3 -3
- package/dist/_chunks/{dev-server-Dbdgx2dD.js.map → dev-server-BzBxgYAV.js.map} +1 -1
- package/dist/_chunks/{live-graph-BM2UbbNx.js → live-graph-Bm5WTvcr.js} +3 -3
- package/dist/_chunks/{live-graph-BM2UbbNx.js.map → live-graph-Bm5WTvcr.js.map} +1 -1
- package/dist/_chunks/{poison-scan-g83aAXhs.js → poison-scan-DG5eI2_z.js} +2 -2
- package/dist/_chunks/{poison-scan-g83aAXhs.js.map → poison-scan-DG5eI2_z.js.map} +1 -1
- package/dist/_chunks/{scanner-BhNruzv0.js → scanner-BQ5sPIJ7.js} +2 -2
- package/dist/_chunks/{scanner-BhNruzv0.js.map → scanner-BQ5sPIJ7.js.map} +1 -1
- package/dist/_chunks/{tree-match-CdbvYTBz.js → tree-match-6yihorhk.js} +49 -2
- package/dist/_chunks/tree-match-6yihorhk.js.map +1 -0
- package/dist/_chunks/{walkers-BNsswm-h.js → walkers-CN2N_bA-.js} +2 -2
- package/dist/_chunks/{walkers-BNsswm-h.js.map → walkers-CN2N_bA-.js.map} +1 -1
- package/dist/analyze/crawl-entry.js +2 -2
- package/dist/analyze/graph-command.js +2 -2
- package/dist/cli.js +3 -3
- package/dist/index.js +3 -3
- package/dist/routing/index.js +2 -2
- package/dist/server/tree-match.d.ts +10 -0
- package/dist/server/tree-match.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/server/route-matcher.ts +73 -20
- package/src/server/tree-match.ts +250 -18
- package/dist/_chunks/tree-match-CdbvYTBz.js.map +0 -1
|
@@ -46,6 +46,47 @@ function collectEffectiveChildren(node, groupChain = []) {
|
|
|
46
46
|
function isTerminal(node) {
|
|
47
47
|
return !!(node.page || node.route);
|
|
48
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Specificity tier for a segment. Lower = more specific. Matches the
|
|
51
|
+
* priority order in `matchNode`: static > affixed-dynamic > bare-dynamic >
|
|
52
|
+
* catch-all > optional-catch-all.
|
|
53
|
+
*/
|
|
54
|
+
function segmentTier(node) {
|
|
55
|
+
if (node.segmentType === "static") return 0;
|
|
56
|
+
if (node.segmentType === "dynamic" && (node.paramPrefix || node.paramSuffix)) return 1;
|
|
57
|
+
if (node.segmentType === "dynamic") return 2;
|
|
58
|
+
if (node.segmentType === "catch-all") return 3;
|
|
59
|
+
if (node.segmentType === "optional-catch-all") return 4;
|
|
60
|
+
return 2;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Score a bare-dynamic candidate by running `matchNode` against its subtree
|
|
64
|
+
* with the remaining URL parts, then reading the tier of each segment in
|
|
65
|
+
* the matched chain. Returns a tier array that is compared lexicographically
|
|
66
|
+
* — the candidate whose chain has a lower tier at the first differing
|
|
67
|
+
* position is more specific.
|
|
68
|
+
*
|
|
69
|
+
* Delegates entirely to `matchNode`, so every segment type and priority
|
|
70
|
+
* rule is inherited automatically — no second copy to drift.
|
|
71
|
+
*/
|
|
72
|
+
function subtreeMatchScore(node, parts, index, requireTerminal) {
|
|
73
|
+
const chain = [];
|
|
74
|
+
if (!matchNode(node, parts, index, chain, {}, requireTerminal)) return [];
|
|
75
|
+
return chain.slice(1).map((seg) => segmentTier(seg));
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Compare two tier arrays lexicographically. Negative means `a` is more
|
|
79
|
+
* specific (should be tried first).
|
|
80
|
+
*/
|
|
81
|
+
function compareTierArrays(a, b) {
|
|
82
|
+
const len = Math.max(a.length, b.length);
|
|
83
|
+
for (let i = 0; i < len; i++) {
|
|
84
|
+
const ta = i < a.length ? a[i] : 5;
|
|
85
|
+
const tb = i < b.length ? b[i] : 5;
|
|
86
|
+
if (ta !== tb) return ta - tb;
|
|
87
|
+
}
|
|
88
|
+
return 0;
|
|
89
|
+
}
|
|
49
90
|
/** Combined affix length for specificity ordering. */
|
|
50
91
|
function affixLength(node) {
|
|
51
92
|
return (node.paramPrefix?.length ?? 0) + (node.paramSuffix?.length ?? 0);
|
|
@@ -94,7 +135,13 @@ function matchNode(node, parts, index, chain, params, requireTerminal) {
|
|
|
94
135
|
else delete params[child.paramName];
|
|
95
136
|
}
|
|
96
137
|
}
|
|
97
|
-
|
|
138
|
+
const bareDynamic = effective.filter(({ child }) => child.segmentType === "dynamic" && child.paramName && !child.paramPrefix && !child.paramSuffix);
|
|
139
|
+
if (bareDynamic.length > 1 && index + 1 < parts.length) {
|
|
140
|
+
const scores = /* @__PURE__ */ new Map();
|
|
141
|
+
for (const { child } of bareDynamic) scores.set(child, subtreeMatchScore(child, parts, index + 1, requireTerminal));
|
|
142
|
+
bareDynamic.sort((a, b) => compareTierArrays(scores.get(a.child), scores.get(b.child)));
|
|
143
|
+
}
|
|
144
|
+
for (const { child, groupChain } of bareDynamic) {
|
|
98
145
|
chain.push(...groupChain);
|
|
99
146
|
const prev = params[child.paramName];
|
|
100
147
|
params[child.paramName] = part;
|
|
@@ -119,4 +166,4 @@ function matchNode(node, parts, index, chain, params, requireTerminal) {
|
|
|
119
166
|
//#endregion
|
|
120
167
|
export { matchUrlParts as t };
|
|
121
168
|
|
|
122
|
-
//# sourceMappingURL=tree-match-
|
|
169
|
+
//# sourceMappingURL=tree-match-6yihorhk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree-match-6yihorhk.js","names":[],"sources":["../../src/server/tree-match.ts"],"sourcesContent":["/**\n * Shared URL-matching tree walker for segment trees.\n *\n * Both the main route matcher (`route-matcher.ts`) and slot resolver\n * (`slot-resolver.ts`) need to walk a SegmentNode tree, matching URL\n * parts against children with the same priority semantics:\n *\n * static > dynamic > catch-all > optional-catch-all\n *\n * Before this module, each had its own walker with subtle divergences\n * (different group handling, missing backtracking, incomplete\n * optional-catch-all support). This shared walker is the single\n * source of truth for URL-to-segment matching.\n *\n * See design/07-routing.md §\"Request Lifecycle\" and TIM-940.\n */\n\nimport type { SegmentNode } from '../routing/types.ts';\n\n// ─── Public API ───────────────────────────────────────────────────────────\n\n/** Result of matching URL parts against a segment tree. */\nexport interface TreeMatchResult<TFile> {\n /** Matched segment chain from root to leaf, inclusive. */\n chain: SegmentNode<TFile>[];\n /** Collected params, keyed by param name. Catch-all params are string[]. */\n params: Record<string, string | string[]>;\n}\n\nexport interface TreeMatchOptions {\n /**\n * When true (default), only match if the leaf node has a page or route\n * handler. Set to false for metadata route matching, where we just need\n * to find the owning segment regardless of whether it has a page.\n */\n requireTerminal?: boolean;\n}\n\n/**\n * Match URL path parts against a segment tree.\n *\n * Walks the tree depth-first with backtracking, applying priority\n * ordering globally across group boundaries. Returns the matched\n * segment chain and collected params, or null if no route matches.\n *\n * By default, a match requires a terminal node (one with `page` or\n * `route`) at the leaf. Pass `{ requireTerminal: false }` to match\n * any segment (used by metadata route matching).\n *\n * @param root The root segment node to start matching from.\n * @param parts URL path parts (e.g. ['blog', 'hello-world']).\n * Empty array matches the root itself (if terminal).\n */\nexport function matchUrlParts<TFile>(\n root: SegmentNode<TFile>,\n parts: string[],\n options?: TreeMatchOptions\n): TreeMatchResult<TFile> | null {\n const chain: SegmentNode<TFile>[] = [];\n const params: Record<string, string | string[]> = {};\n const requireTerminal = options?.requireTerminal ?? true;\n\n if (matchNode(root, parts, 0, chain, params, requireTerminal)) {\n return { chain, params };\n }\n return null;\n}\n\n/**\n * Yield every match for the given URL parts, in priority order.\n *\n * Same matching semantics as `matchUrlParts` — static > affixed-dynamic >\n * bare-dynamic > catch-all > optional-catch-all — but instead of returning\n * the first match, it yields all of them. Used by the metadata route matcher,\n * which needs to try alternate owner segments when the first match doesn't\n * own the requested metadata file.\n */\nexport function* matchUrlPartsAll<TFile>(\n root: SegmentNode<TFile>,\n parts: string[],\n options?: TreeMatchOptions\n): Generator<TreeMatchResult<TFile>> {\n const chain: SegmentNode<TFile>[] = [];\n const params: Record<string, string | string[]> = {};\n const requireTerminal = options?.requireTerminal ?? true;\n\n yield* matchNodeAll(root, parts, 0, chain, params, requireTerminal);\n}\n\n// ─── Internal ─────────────────────────────────────────────────────────────\n\n/**\n * A child node flattened through group segments, along with the\n * chain of group nodes that must appear in the segment chain\n * before the child to preserve the tree path.\n */\ninterface EffectiveChild<TFile> {\n child: SegmentNode<TFile>;\n groupChain: SegmentNode<TFile>[];\n}\n\n/**\n * Flatten children through group segments.\n *\n * Groups are transparent for URL matching — their non-group descendants\n * are returned with the chain of group nodes leading to them. This lets\n * the caller apply priority ordering (static > dynamic > catch-all >\n * optional-catch-all) across all groups uniformly instead of per-group.\n */\nfunction collectEffectiveChildren<TFile>(\n node: SegmentNode<TFile>,\n groupChain: SegmentNode<TFile>[] = []\n): EffectiveChild<TFile>[] {\n const result: EffectiveChild<TFile>[] = [];\n for (const child of node.children) {\n if (child.segmentType === 'group') {\n const nested = collectEffectiveChildren(child, [...groupChain, child]);\n result.push(...nested);\n } else {\n result.push({ child, groupChain });\n }\n }\n return result;\n}\n\n/** A node is terminal if it can serve a response (has a page or route handler). */\nfunction isTerminal<TFile>(node: SegmentNode<TFile>): boolean {\n return !!(node.page || node.route);\n}\n\n/**\n * Specificity tier for a segment. Lower = more specific. Matches the\n * priority order in `matchNode`: static > affixed-dynamic > bare-dynamic >\n * catch-all > optional-catch-all.\n */\nfunction segmentTier<TFile>(node: SegmentNode<TFile>): number {\n if (node.segmentType === 'static') return 0;\n if (node.segmentType === 'dynamic' && (node.paramPrefix || node.paramSuffix)) return 1;\n if (node.segmentType === 'dynamic') return 2;\n if (node.segmentType === 'catch-all') return 3;\n if (node.segmentType === 'optional-catch-all') return 4;\n return 2;\n}\n\n/**\n * Score a bare-dynamic candidate by running `matchNode` against its subtree\n * with the remaining URL parts, then reading the tier of each segment in\n * the matched chain. Returns a tier array that is compared lexicographically\n * — the candidate whose chain has a lower tier at the first differing\n * position is more specific.\n *\n * Delegates entirely to `matchNode`, so every segment type and priority\n * rule is inherited automatically — no second copy to drift.\n */\nfunction subtreeMatchScore<TFile>(\n node: SegmentNode<TFile>,\n parts: string[],\n index: number,\n requireTerminal: boolean\n): number[] {\n const chain: SegmentNode<TFile>[] = [];\n const params: Record<string, string | string[]> = {};\n if (!matchNode(node, parts, index, chain, params, requireTerminal)) return [];\n // Skip the first entry (the candidate node itself — it's the bare-dynamic\n // we're scoring, which is the same tier for all candidates).\n return chain.slice(1).map((seg) => segmentTier(seg));\n}\n\n/**\n * Compare two tier arrays lexicographically. Negative means `a` is more\n * specific (should be tried first).\n */\nfunction compareTierArrays(a: number[], b: number[]): number {\n const len = Math.max(a.length, b.length);\n for (let i = 0; i < len; i++) {\n // A shorter match is less specific — missing entries treated as worst tier.\n const ta = i < a.length ? a[i] : 5;\n const tb = i < b.length ? b[i] : 5;\n if (ta !== tb) return ta - tb;\n }\n return 0;\n}\n\n/** Combined affix length for specificity ordering. */\nfunction affixLength<TFile>(node: SegmentNode<TFile>): number {\n return (node.paramPrefix?.length ?? 0) + (node.paramSuffix?.length ?? 0);\n}\n\n/**\n * Recursive depth-first matcher with backtracking.\n *\n * Mutates `chain` and `params` in place for performance; backtracks\n * (restores previous state) when a candidate doesn't lead to a match.\n */\nfunction matchNode<TFile>(\n node: SegmentNode<TFile>,\n parts: string[],\n index: number,\n chain: SegmentNode<TFile>[],\n params: Record<string, string | string[]>,\n requireTerminal: boolean\n): boolean {\n chain.push(node);\n\n // All parts consumed — check if this node is terminal (or any node if !requireTerminal)\n if (index >= parts.length) {\n if (!requireTerminal || isTerminal(node)) return true;\n\n // Groups don't consume URL segments, so a group child's page can\n // match at the same URL depth. Recurse into groups transparently.\n for (const child of node.children) {\n if (child.segmentType === 'group') {\n if (matchNode(child, parts, index, chain, params, requireTerminal)) {\n return true;\n }\n }\n }\n\n // Optional catch-all with zero segments (direct and through groups).\n // The param is NOT set — matching Next.js semantics for [[...slug]]\n // with no path segments.\n const effective = collectEffectiveChildren(node);\n for (const { child, groupChain } of effective) {\n if (child.segmentType === 'optional-catch-all' && (!requireTerminal || isTerminal(child))) {\n chain.push(...groupChain, child);\n return true;\n }\n }\n\n chain.pop();\n return false;\n }\n\n const part = parts[index];\n\n // Flatten children through groups so priority ordering applies globally.\n const effective = collectEffectiveChildren(node);\n\n // 1. Static segments (exact name match)\n for (const { child, groupChain } of effective) {\n if (child.segmentType === 'static' && child.segmentName === part) {\n chain.push(...groupChain);\n if (matchNode(child, parts, index + 1, chain, params, requireTerminal)) {\n return true;\n }\n chain.length -= groupChain.length;\n }\n }\n\n // 2. Affixed dynamic segments (e.g. img-[id].png) — more specific than bare dynamic.\n // Sorted by specificity: longer combined prefix+suffix wins.\n const affixed = effective.filter(\n ({ child }) =>\n child.segmentType === 'dynamic' && child.paramName && (child.paramPrefix || child.paramSuffix)\n );\n affixed.sort((a, b) => affixLength(b.child) - affixLength(a.child));\n for (const { child, groupChain } of affixed) {\n const prefix = child.paramPrefix ?? '';\n const suffix = child.paramSuffix ?? '';\n if (\n part.length > prefix.length + suffix.length &&\n (!prefix || part.startsWith(prefix)) &&\n (!suffix || part.endsWith(suffix))\n ) {\n const value = part.slice(prefix.length, part.length - (suffix.length || 0));\n chain.push(...groupChain);\n const prev = params[child.paramName!];\n params[child.paramName!] = value;\n if (matchNode(child, parts, index + 1, chain, params, requireTerminal)) {\n return true;\n }\n // Backtrack\n chain.length -= groupChain.length;\n if (prev !== undefined) {\n params[child.paramName!] = prev;\n } else {\n delete params[child.paramName!];\n }\n }\n }\n\n // 3. Bare dynamic segments ([param])\n // When multiple bare dynamics compete (common with route groups that\n // flatten into the same parent), sort by subtree specificity so a\n // branch containing a static match for the NEXT URL part is tried\n // first. Without this, the winner depends on children order and\n // renaming a route group can flip it — the exact shape the collision\n // validator exists to reject.\n const bareDynamic = effective.filter(\n ({ child }) =>\n child.segmentType === 'dynamic' && child.paramName && !child.paramPrefix && !child.paramSuffix\n );\n if (bareDynamic.length > 1 && index + 1 < parts.length) {\n const scores = new Map<SegmentNode<TFile>, number[]>();\n for (const { child } of bareDynamic) {\n scores.set(child, subtreeMatchScore(child, parts, index + 1, requireTerminal));\n }\n bareDynamic.sort((a, b) => compareTierArrays(scores.get(a.child)!, scores.get(b.child)!));\n }\n for (const { child, groupChain } of bareDynamic) {\n chain.push(...groupChain);\n const prev = params[child.paramName!];\n params[child.paramName!] = part;\n if (matchNode(child, parts, index + 1, chain, params, requireTerminal)) {\n return true;\n }\n // Backtrack\n chain.length -= groupChain.length;\n if (prev !== undefined) {\n params[child.paramName!] = prev;\n } else {\n delete params[child.paramName!];\n }\n }\n\n // 4. Catch-all segments ([...param]) — must be terminal unless the\n // caller passed requireTerminal:false (metadata route matching needs to\n // find the owning segment even when it has no page).\n for (const { child, groupChain } of effective) {\n if (\n child.segmentType === 'catch-all' &&\n child.paramName &&\n (!requireTerminal || isTerminal(child))\n ) {\n chain.push(...groupChain, child);\n params[child.paramName] = parts.slice(index);\n return true;\n }\n }\n\n // 5. Optional catch-all segments ([[...param]]) — same terminal rule\n for (const { child, groupChain } of effective) {\n if (\n child.segmentType === 'optional-catch-all' &&\n child.paramName &&\n (!requireTerminal || isTerminal(child))\n ) {\n chain.push(...groupChain, child);\n params[child.paramName] = parts.slice(index);\n return true;\n }\n }\n\n chain.pop();\n return false;\n}\n\n/**\n * Generator twin of `matchNode` — yields every match instead of returning\n * the first. Each yield snapshots `chain` and `params` so the caller gets\n * independent results. After yielding, backtracking continues to find the\n * next match.\n */\nfunction* matchNodeAll<TFile>(\n node: SegmentNode<TFile>,\n parts: string[],\n index: number,\n chain: SegmentNode<TFile>[],\n params: Record<string, string | string[]>,\n requireTerminal: boolean\n): Generator<TreeMatchResult<TFile>> {\n chain.push(node);\n\n if (index >= parts.length) {\n if (!requireTerminal || isTerminal(node)) {\n yield { chain: [...chain], params: { ...params } };\n }\n\n for (const child of node.children) {\n if (child.segmentType === 'group') {\n yield* matchNodeAll(child, parts, index, chain, params, requireTerminal);\n }\n }\n\n const effective = collectEffectiveChildren(node);\n for (const { child, groupChain } of effective) {\n if (child.segmentType === 'optional-catch-all' && (!requireTerminal || isTerminal(child))) {\n chain.push(...groupChain, child);\n yield { chain: [...chain], params: { ...params } };\n chain.length -= groupChain.length + 1;\n }\n }\n\n chain.pop();\n return;\n }\n\n const part = parts[index];\n const effective = collectEffectiveChildren(node);\n\n // 1. Static segments\n for (const { child, groupChain } of effective) {\n if (child.segmentType === 'static' && child.segmentName === part) {\n chain.push(...groupChain);\n yield* matchNodeAll(child, parts, index + 1, chain, params, requireTerminal);\n chain.length -= groupChain.length;\n }\n }\n\n // 2. Affixed dynamic segments\n const affixed = effective.filter(\n ({ child }) =>\n child.segmentType === 'dynamic' && child.paramName && (child.paramPrefix || child.paramSuffix)\n );\n affixed.sort((a, b) => affixLength(b.child) - affixLength(a.child));\n for (const { child, groupChain } of affixed) {\n const prefix = child.paramPrefix ?? '';\n const suffix = child.paramSuffix ?? '';\n if (\n part.length > prefix.length + suffix.length &&\n (!prefix || part.startsWith(prefix)) &&\n (!suffix || part.endsWith(suffix))\n ) {\n const value = part.slice(prefix.length, part.length - (suffix.length || 0));\n chain.push(...groupChain);\n const prev = params[child.paramName!];\n params[child.paramName!] = value;\n yield* matchNodeAll(child, parts, index + 1, chain, params, requireTerminal);\n chain.length -= groupChain.length;\n if (prev !== undefined) {\n params[child.paramName!] = prev;\n } else {\n delete params[child.paramName!];\n }\n }\n }\n\n // 3. Bare dynamic segments\n const bareDynamic = effective.filter(\n ({ child }) =>\n child.segmentType === 'dynamic' && child.paramName && !child.paramPrefix && !child.paramSuffix\n );\n if (bareDynamic.length > 1 && index + 1 < parts.length) {\n const scores = new Map<SegmentNode<TFile>, number[]>();\n for (const { child } of bareDynamic) {\n scores.set(child, subtreeMatchScore(child, parts, index + 1, requireTerminal));\n }\n bareDynamic.sort((a, b) => compareTierArrays(scores.get(a.child)!, scores.get(b.child)!));\n }\n for (const { child, groupChain } of bareDynamic) {\n chain.push(...groupChain);\n const prev = params[child.paramName!];\n params[child.paramName!] = part;\n yield* matchNodeAll(child, parts, index + 1, chain, params, requireTerminal);\n chain.length -= groupChain.length;\n if (prev !== undefined) {\n params[child.paramName!] = prev;\n } else {\n delete params[child.paramName!];\n }\n }\n\n // 4. Catch-all segments\n for (const { child, groupChain } of effective) {\n if (\n child.segmentType === 'catch-all' &&\n child.paramName &&\n (!requireTerminal || isTerminal(child))\n ) {\n chain.push(...groupChain, child);\n const prev = params[child.paramName];\n params[child.paramName] = parts.slice(index);\n yield { chain: [...chain], params: { ...params } };\n chain.length -= groupChain.length + 1;\n if (prev !== undefined) {\n params[child.paramName] = prev;\n } else {\n delete params[child.paramName];\n }\n }\n }\n\n // 5. Optional catch-all segments\n for (const { child, groupChain } of effective) {\n if (\n child.segmentType === 'optional-catch-all' &&\n child.paramName &&\n (!requireTerminal || isTerminal(child))\n ) {\n chain.push(...groupChain, child);\n const prev = params[child.paramName];\n params[child.paramName] = parts.slice(index);\n yield { chain: [...chain], params: { ...params } };\n chain.length -= groupChain.length + 1;\n if (prev !== undefined) {\n params[child.paramName] = prev;\n } else {\n delete params[child.paramName];\n }\n }\n }\n\n chain.pop();\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAqDA,SAAgB,cACd,MACA,OACA,SAC+B;CAC/B,MAAM,QAA8B,CAAC;CACrC,MAAM,SAA4C,CAAC;CAGnD,IAAI,UAAU,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E,MAAM,gBAAgB,eACtB,MAAM,cACL,CAAC,mBAAmB,WAAW,KAAK,IACrC;EACA,MAAM,KAAK,GAAG,YAAY,KAAK;EAC/B,OAAO,MAAM,aAAa,MAAM,MAAM,KAAK;EAC3C,OAAO;CACT;CAIF,KAAK,MAAM,EAAE,OAAO,gBAAgB,WAClC,IACE,MAAM,gBAAgB,wBACtB,MAAM,cACL,CAAC,mBAAmB,WAAW,KAAK,IACrC;EACA,MAAM,KAAK,GAAG,YAAY,KAAK;EAC/B,OAAO,MAAM,aAAa,MAAM,MAAM,KAAK;EAC3C,OAAO;CACT;CAGF,MAAM,IAAI;CACV,OAAO;AACT"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as classifyUrlSegment } from "./segment-classify-C539Pa2O.js";
|
|
2
2
|
import { t as readFileCached } from "./file-cache-Dw6BJPG7.js";
|
|
3
|
-
import { n as findSchemaFile, r as parseExistingSchemaKeys } from "./cli-schema-sync
|
|
3
|
+
import { n as findSchemaFile, r as parseExistingSchemaKeys } from "./cli-schema-sync--LZKs8Zn.js";
|
|
4
4
|
//#region src/routing/schema-validation.ts
|
|
5
5
|
/**
|
|
6
6
|
* Schema key/value validation against the filesystem route tree.
|
|
@@ -141,4 +141,4 @@ function walk(node, chain, result, includeSlots) {
|
|
|
141
141
|
//#endregion
|
|
142
142
|
export { collectDynamicSegmentsFromTree as n, validateSchemaAgainstRoutes as r, collectLeafRoutes as t };
|
|
143
143
|
|
|
144
|
-
//# sourceMappingURL=walkers-
|
|
144
|
+
//# sourceMappingURL=walkers-CN2N_bA-.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"walkers-BNsswm-h.js","names":[],"sources":["../../src/routing/schema-validation.ts","../../src/routing/walkers.ts"],"sourcesContent":["/**\n * Schema key/value validation against the filesystem route tree.\n *\n * Runs at codegen time (build + dev) to catch mismatches between\n * app/schema.ts keys and the actual dynamic segments on disk.\n *\n * Design doc: design/41-global-params.md\n */\n\nimport { readFileCached } from './file-cache.ts';\nimport type { RouteTree, SegmentNode } from './types.ts';\nimport { findSchemaFile, parseExistingSchemaKeys } from '../cli-schema-sync.ts';\nimport { classifyUrlSegment } from './segment-classify.ts';\n\nexport interface SchemaWarning {\n type: 'stale-key' | 'missing-key' | 'bracket-mismatch';\n key: string;\n message: string;\n filesystemKey?: string;\n}\n\n/**\n * Collect all unique bracket-keyed dynamic segment names from a route tree.\n * Returns entries like '[artistSlug]', '[...slug]', '[[...topic]]'.\n */\nexport function collectDynamicSegmentsFromTree(tree: RouteTree): Set<string> {\n const segments = new Set<string>();\n walkTree(tree.root, segments);\n return segments;\n}\n\nfunction walkTree(node: SegmentNode, segments: Set<string>): void {\n if (node.paramName && node.segmentName) {\n const classified = classifyUrlSegment(node.segmentName);\n if (classified.kind !== 'static') {\n // Use bare bracket form for schema keys — affixed segments like\n // `img-[id].png` register as `[id]`, matching runtime codec lookup.\n if (classified.kind === 'dynamic' && (classified.prefix || classified.suffix)) {\n segments.add(`[${classified.name}]`);\n } else {\n segments.add(node.segmentName);\n }\n }\n }\n for (const child of node.children) {\n walkTree(child, segments);\n }\n for (const slot of Object.values(node.slots)) {\n walkTree(slot, segments);\n }\n}\n\n/**\n * Extract the param name from a bracket key.\n * '[id]' → 'id', '[...slug]' → 'slug', '[[...topic]]' → 'topic'\n */\nfunction extractParamName(bracketKey: string): string | null {\n const seg = classifyUrlSegment(bracketKey);\n if (seg.kind === 'static') return null;\n return seg.name;\n}\n\n/**\n * Validate schema keys against the filesystem route tree.\n *\n * Returns warnings for:\n * - Stale keys: schema keys that don't match any filesystem segment\n * - Bracket form mismatches: same param name, different bracket form\n * - Missing keys: filesystem segments not registered in schema (informational)\n */\nexport function validateSchemaAgainstRoutes(tree: RouteTree, appDir: string): SchemaWarning[] {\n const schemaPath = findSchemaFile(appDir);\n if (!schemaPath) return [];\n\n const content = readFileCached(schemaPath);\n const schemaKeys = parseExistingSchemaKeys(content);\n\n if (schemaKeys.length === 0) return [];\n\n const filesystemSegments = collectDynamicSegmentsFromTree(tree);\n\n return validateKeys(schemaKeys, filesystemSegments);\n}\n\n/**\n * Core validation: compare schema keys against filesystem segments.\n * Exported separately for testing without filesystem dependencies.\n */\nexport function validateKeys(\n schemaKeys: string[],\n filesystemSegments: Set<string>\n): SchemaWarning[] {\n const warnings: SchemaWarning[] = [];\n\n // Build a map of param name → bracket form for filesystem segments\n const fsParamToKey = new Map<string, string>();\n for (const fsKey of filesystemSegments) {\n const name = extractParamName(fsKey);\n if (name) {\n fsParamToKey.set(name, fsKey);\n }\n }\n\n // Build a set of schema param names for the missing-key check\n const schemaParamNames = new Set<string>();\n\n for (const schemaKey of schemaKeys) {\n const schemaParamName = extractParamName(schemaKey);\n if (!schemaParamName) continue;\n\n schemaParamNames.add(schemaParamName);\n\n if (filesystemSegments.has(schemaKey)) {\n // Exact match — no issue\n continue;\n }\n\n // Check if the param name exists but with a different bracket form\n const fsKey = fsParamToKey.get(schemaParamName);\n if (fsKey) {\n warnings.push({\n type: 'bracket-mismatch',\n key: schemaKey,\n filesystemKey: fsKey,\n message:\n `Schema key '${schemaKey}' does not match filesystem bracket form '${fsKey}'. ` +\n `Update the schema key to '${fsKey}'.`,\n });\n } else {\n warnings.push({\n type: 'stale-key',\n key: schemaKey,\n message:\n `Schema key '${schemaKey}' does not match any dynamic segment in the filesystem. ` +\n `Remove it from app/schema.ts or create the corresponding route segment.`,\n });\n }\n }\n\n // Check for filesystem segments not in schema (informational)\n for (const fsKey of filesystemSegments) {\n const name = extractParamName(fsKey);\n if (name && !schemaParamNames.has(name)) {\n warnings.push({\n type: 'missing-key',\n key: fsKey,\n message:\n `Dynamic segment '${fsKey}' has no codec in app/schema.ts (defaults to string). ` +\n `Run: timber schema sync`,\n });\n }\n }\n\n return warnings;\n}\n","/**\n * Shared route-tree walkers (TIM-848).\n *\n * Tiny helpers that walk a `SegmentNode<TFile>` tree generically. Both the\n * build-time tree (`SegmentNode<RouteFile>`) and the runtime manifest\n * tree (`SegmentNode<ManifestFile>`) flow through these helpers because\n * the walker only reads the structural fields shared by both shapes\n * (`children`, `slots`, `page`, `route`, `urlPath`).\n *\n * Before this module, three near-identical `collectRoutes` functions\n * lived in `plugins/dev-404-page.ts`, `plugins/build-report.ts`, and\n * `routing/codegen.ts`. The codegen one is special-purpose (it\n * accumulates `ParamEntry[]` and resolves codec chains) and stays\n * local; the other two now share `collectLeafRoutes` from this file.\n */\n\nimport type { SegmentNode } from './types.ts';\n\n/** A leaf route discovered while walking the segment tree. */\nexport interface LeafRoute<TFile> {\n /** URL path of the leaf (root is \"/\"). */\n urlPath: string;\n /** Segment chain from root to this leaf, inclusive. */\n segments: SegmentNode<TFile>[];\n /** The page file at this leaf, if any. */\n page?: TFile;\n /** The route handler file at this leaf, if any. */\n route?: TFile;\n}\n\n/** Options for `collectLeafRoutes`. */\nexport interface CollectLeafRoutesOptions {\n /**\n * If true, recurse into parallel slots and emit slot leaves alongside\n * the main route tree. Defaults to `false` because slots render\n * alongside their parent at the same URL and are not separately\n * URL-addressable. The build report excludes slots; route-listing\n * UIs that want to show \"all leaves with a page handler\" can opt in.\n */\n includeSlots?: boolean;\n}\n\n/**\n * Walk a segment tree and collect every leaf with a `page` or `route`\n * handler. Generic over `TFile` so it works on both the build-time\n * scanner output and the runtime manifest tree.\n *\n * - Pages and route handlers at the same URL produce two distinct\n * entries (the build report deduplicates by URL afterward).\n * - Parallel slots are skipped unless `includeSlots: true` (slots\n * share their parent's URL and are not addressable on their own).\n * - Intercepting subtrees are skipped unconditionally. They render only\n * on soft navigation and add no URL depth, so their computed `urlPath`s\n * are not addresses — listing them would advertise routes (`/[year]`)\n * that no request can reach. This matches every other consumer of the\n * tree that produces URLs: the sitemap generator, the static generator,\n * prerendering and the prebuilt-payload builder all skip them too.\n * - Result is sorted by `urlPath` for deterministic output.\n */\nexport function collectLeafRoutes<TFile>(\n root: SegmentNode<TFile>,\n options: CollectLeafRoutesOptions = {}\n): LeafRoute<TFile>[] {\n const { includeSlots = false } = options;\n const result: LeafRoute<TFile>[] = [];\n walk(root, [], result, includeSlots);\n result.sort((a, b) => a.urlPath.localeCompare(b.urlPath));\n return result;\n}\n\nfunction walk<TFile>(\n node: SegmentNode<TFile>,\n chain: SegmentNode<TFile>[],\n result: LeafRoute<TFile>[],\n includeSlots: boolean\n): void {\n if (node.segmentType === 'intercepting') return;\n\n const currentChain = [...chain, node];\n const path = node.urlPath || '/';\n\n if (node.page) {\n result.push({ urlPath: path, segments: currentChain, page: node.page });\n }\n if (node.route) {\n result.push({ urlPath: path, segments: currentChain, route: node.route });\n }\n\n for (const child of node.children) {\n walk(child, currentChain, result, includeSlots);\n }\n\n if (includeSlots) {\n for (const slotNode of Object.values(node.slots)) {\n walk(slotNode, currentChain, result, includeSlots);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAyBA,SAAgB,+BAA+B,MAA8B;CAC3E,MAAM,2BAAW,IAAI,IAAY;CACjC,SAAS,KAAK,MAAM,QAAQ;CAC5B,OAAO;AACT;AAEA,SAAS,SAAS,MAAmB,UAA6B;CAChE,IAAI,KAAK,aAAa,KAAK,aAAa;EACtC,MAAM,aAAa,mBAAmB,KAAK,WAAW;EACtD,IAAI,WAAW,SAAS,UAAU;GAGhC,IAAI,WAAW,SAAS,cAAc,WAAW,UAAU,WAAW,SACpE,SAAS,IAAI,IAAI,WAAW,KAAK,EAAE;QAEnC,SAAS,IAAI,KAAK,WAAW;EAEjC;CACF;CACA,KAAK,MAAM,SAAS,KAAK,UACvB,SAAS,OAAO,QAAQ;CAE1B,KAAK,MAAM,QAAQ,OAAO,OAAO,KAAK,KAAK,GACzC,SAAS,MAAM,QAAQ;AAE3B;;;;;AAMA,SAAS,iBAAiB,YAAmC;CAC3D,MAAM,MAAM,mBAAmB,UAAU;CACzC,IAAI,IAAI,SAAS,UAAU,OAAO;CAClC,OAAO,IAAI;AACb;;;;;;;;;AAUA,SAAgB,4BAA4B,MAAiB,QAAiC;CAC5F,MAAM,aAAa,eAAe,MA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O,MAAM,GAAG,MAAM,EAAE,QAAQ,cAAc,EAAE,OAAO,CAAC;CACxD,OAAO;AACT;AAEA,SAAS,KACP,MACA,OACA,QACA,cACM;CACN,IAAI,KAAK,gBAAgB,gBAAgB;CAEzC,MAAM,eAAe,CAAC,GAAG,OAAO,IAAI;CACpC,MAAM,OAAO,KAAK,WAAW;CAE7B,IAAI,KAAK,MACP,OAAO,KAAK;EAAE,SAAS;EAAM,UAAU;EAAc,MAAM,KAAK;CAAK,CAAC;CAExE,IAAI,KAAK,OACP,OAAO,KAAK;EAAE,SAAS;EAAM,UAAU;EAAc,OAAO,KAAK;CAAM,CAAC;CAG1E,KAAK,MAAM,SAAS,KAAK,UACvB,KAAK,OAAO,cAAc,QAAQ,YAAY;CAGhD,IAAI,cACF,KAAK,MAAM,YAAY,OAAO,OAAO,KAAK,KAAK,GAC7C,KAAK,UAAU,cAAc,QAAQ,YAAY;AAGvD"}
|
|
1
|
+
{"version":3,"file":"walkers-CN2N_bA-.js","names":[],"sources":["../../src/routing/schema-validation.ts","../../src/routing/walkers.ts"],"sourcesContent":["/**\n * Schema key/value validation against the filesystem route tree.\n *\n * Runs at codegen time (build + dev) to catch mismatches between\n * app/schema.ts keys and the actual dynamic segments on disk.\n *\n * Design doc: design/41-global-params.md\n */\n\nimport { readFileCached } from './file-cache.ts';\nimport type { RouteTree, SegmentNode } from './types.ts';\nimport { findSchemaFile, parseExistingSchemaKeys } from '../cli-schema-sync.ts';\nimport { classifyUrlSegment } from './segment-classify.ts';\n\nexport interface SchemaWarning {\n type: 'stale-key' | 'missing-key' | 'bracket-mismatch';\n key: string;\n message: string;\n filesystemKey?: string;\n}\n\n/**\n * Collect all unique bracket-keyed dynamic segment names from a route tree.\n * Returns entries like '[artistSlug]', '[...slug]', '[[...topic]]'.\n */\nexport function collectDynamicSegmentsFromTree(tree: RouteTree): Set<string> {\n const segments = new Set<string>();\n walkTree(tree.root, segments);\n return segments;\n}\n\nfunction walkTree(node: SegmentNode, segments: Set<string>): void {\n if (node.paramName && node.segmentName) {\n const classified = classifyUrlSegment(node.segmentName);\n if (classified.kind !== 'static') {\n // Use bare bracket form for schema keys — affixed segments like\n // `img-[id].png` register as `[id]`, matching runtime codec lookup.\n if (classified.kind === 'dynamic' && (classified.prefix || classified.suffix)) {\n segments.add(`[${classified.name}]`);\n } else {\n segments.add(node.segmentName);\n }\n }\n }\n for (const child of node.children) {\n walkTree(child, segments);\n }\n for (const slot of Object.values(node.slots)) {\n walkTree(slot, segments);\n }\n}\n\n/**\n * Extract the param name from a bracket key.\n * '[id]' → 'id', '[...slug]' → 'slug', '[[...topic]]' → 'topic'\n */\nfunction extractParamName(bracketKey: string): string | null {\n const seg = classifyUrlSegment(bracketKey);\n if (seg.kind === 'static') return null;\n return seg.name;\n}\n\n/**\n * Validate schema keys against the filesystem route tree.\n *\n * Returns warnings for:\n * - Stale keys: schema keys that don't match any filesystem segment\n * - Bracket form mismatches: same param name, different bracket form\n * - Missing keys: filesystem segments not registered in schema (informational)\n */\nexport function validateSchemaAgainstRoutes(tree: RouteTree, appDir: string): SchemaWarning[] {\n const schemaPath = findSchemaFile(appDir);\n if (!schemaPath) return [];\n\n const content = readFileCached(schemaPath);\n const schemaKeys = parseExistingSchemaKeys(content);\n\n if (schemaKeys.length === 0) return [];\n\n const filesystemSegments = collectDynamicSegmentsFromTree(tree);\n\n return validateKeys(schemaKeys, filesystemSegments);\n}\n\n/**\n * Core validation: compare schema keys against filesystem segments.\n * Exported separately for testing without filesystem dependencies.\n */\nexport function validateKeys(\n schemaKeys: string[],\n filesystemSegments: Set<string>\n): SchemaWarning[] {\n const warnings: SchemaWarning[] = [];\n\n // Build a map of param name → bracket form for filesystem segments\n const fsParamToKey = new Map<string, string>();\n for (const fsKey of filesystemSegments) {\n const name = extractParamName(fsKey);\n if (name) {\n fsParamToKey.set(name, fsKey);\n }\n }\n\n // Build a set of schema param names for the missing-key check\n const schemaParamNames = new Set<string>();\n\n for (const schemaKey of schemaKeys) {\n const schemaParamName = extractParamName(schemaKey);\n if (!schemaParamName) continue;\n\n schemaParamNames.add(schemaParamName);\n\n if (filesystemSegments.has(schemaKey)) {\n // Exact match — no issue\n continue;\n }\n\n // Check if the param name exists but with a different bracket form\n const fsKey = fsParamToKey.get(schemaParamName);\n if (fsKey) {\n warnings.push({\n type: 'bracket-mismatch',\n key: schemaKey,\n filesystemKey: fsKey,\n message:\n `Schema key '${schemaKey}' does not match filesystem bracket form '${fsKey}'. ` +\n `Update the schema key to '${fsKey}'.`,\n });\n } else {\n warnings.push({\n type: 'stale-key',\n key: schemaKey,\n message:\n `Schema key '${schemaKey}' does not match any dynamic segment in the filesystem. ` +\n `Remove it from app/schema.ts or create the corresponding route segment.`,\n });\n }\n }\n\n // Check for filesystem segments not in schema (informational)\n for (const fsKey of filesystemSegments) {\n const name = extractParamName(fsKey);\n if (name && !schemaParamNames.has(name)) {\n warnings.push({\n type: 'missing-key',\n key: fsKey,\n message:\n `Dynamic segment '${fsKey}' has no codec in app/schema.ts (defaults to string). ` +\n `Run: timber schema sync`,\n });\n }\n }\n\n return warnings;\n}\n","/**\n * Shared route-tree walkers (TIM-848).\n *\n * Tiny helpers that walk a `SegmentNode<TFile>` tree generically. Both the\n * build-time tree (`SegmentNode<RouteFile>`) and the runtime manifest\n * tree (`SegmentNode<ManifestFile>`) flow through these helpers because\n * the walker only reads the structural fields shared by both shapes\n * (`children`, `slots`, `page`, `route`, `urlPath`).\n *\n * Before this module, three near-identical `collectRoutes` functions\n * lived in `plugins/dev-404-page.ts`, `plugins/build-report.ts`, and\n * `routing/codegen.ts`. The codegen one is special-purpose (it\n * accumulates `ParamEntry[]` and resolves codec chains) and stays\n * local; the other two now share `collectLeafRoutes` from this file.\n */\n\nimport type { SegmentNode } from './types.ts';\n\n/** A leaf route discovered while walking the segment tree. */\nexport interface LeafRoute<TFile> {\n /** URL path of the leaf (root is \"/\"). */\n urlPath: string;\n /** Segment chain from root to this leaf, inclusive. */\n segments: SegmentNode<TFile>[];\n /** The page file at this leaf, if any. */\n page?: TFile;\n /** The route handler file at this leaf, if any. */\n route?: TFile;\n}\n\n/** Options for `collectLeafRoutes`. */\nexport interface CollectLeafRoutesOptions {\n /**\n * If true, recurse into parallel slots and emit slot leaves alongside\n * the main route tree. Defaults to `false` because slots render\n * alongside their parent at the same URL and are not separately\n * URL-addressable. The build report excludes slots; route-listing\n * UIs that want to show \"all leaves with a page handler\" can opt in.\n */\n includeSlots?: boolean;\n}\n\n/**\n * Walk a segment tree and collect every leaf with a `page` or `route`\n * handler. Generic over `TFile` so it works on both the build-time\n * scanner output and the runtime manifest tree.\n *\n * - Pages and route handlers at the same URL produce two distinct\n * entries (the build report deduplicates by URL afterward).\n * - Parallel slots are skipped unless `includeSlots: true` (slots\n * share their parent's URL and are not addressable on their own).\n * - Intercepting subtrees are skipped unconditionally. They render only\n * on soft navigation and add no URL depth, so their computed `urlPath`s\n * are not addresses — listing them would advertise routes (`/[year]`)\n * that no request can reach. This matches every other consumer of the\n * tree that produces URLs: the sitemap generator, the static generator,\n * prerendering and the prebuilt-payload builder all skip them too.\n * - Result is sorted by `urlPath` for deterministic output.\n */\nexport function collectLeafRoutes<TFile>(\n root: SegmentNode<TFile>,\n options: CollectLeafRoutesOptions = {}\n): LeafRoute<TFile>[] {\n const { includeSlots = false } = options;\n const result: LeafRoute<TFile>[] = [];\n walk(root, [], result, includeSlots);\n result.sort((a, b) => a.urlPath.localeCompare(b.urlPath));\n return result;\n}\n\nfunction walk<TFile>(\n node: SegmentNode<TFile>,\n chain: SegmentNode<TFile>[],\n result: LeafRoute<TFile>[],\n includeSlots: boolean\n): void {\n if (node.segmentType === 'intercepting') return;\n\n const currentChain = [...chain, node];\n const path = node.urlPath || '/';\n\n if (node.page) {\n result.push({ urlPath: path, segments: currentChain, page: node.page });\n }\n if (node.route) {\n result.push({ urlPath: path, segments: currentChain, route: node.route });\n }\n\n for (const child of node.children) {\n walk(child, currentChain, result, includeSlots);\n }\n\n if (includeSlots) {\n for (const slotNode of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vB,KAAK,OAAO,cAAc,QAAQ,YAAY;CAGhD,IAAI,cACF,KAAK,MAAM,YAAY,OAAO,OAAO,KAAK,KAAK,GAC7C,KAAK,UAAU,cAAc,QAAQ,YAAY;AAGvD"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { i as scanProjectSourceFiles, n as isScannableSourceFile, t as buildSourceExtensions } from "../_chunks/scan-BoP17W3w.js";
|
|
2
2
|
import { n as isTimberPluginApi, o as resolveAppDir } from "../_chunks/plugin-context-8idfR3UZ.js";
|
|
3
|
-
import { a as detectDirective, i as classifyModules, n as stitchImportChains } from "../_chunks/chains-
|
|
4
|
-
import { n as importSignals, r as poisoningsFor, t as collectImportSpecifiers } from "../_chunks/poison-scan-
|
|
3
|
+
import { a as detectDirective, i as classifyModules, n as stitchImportChains } from "../_chunks/chains-B4bgOl2g.js";
|
|
4
|
+
import { n as importSignals, r as poisoningsFor, t as collectImportSpecifiers } from "../_chunks/poison-scan-DG5eI2_z.js";
|
|
5
5
|
import { normalizePath } from "vite";
|
|
6
6
|
import { join, resolve } from "node:path";
|
|
7
7
|
import { readFile, realpath, writeFile } from "node:fs/promises";
|
|
@@ -378,7 +378,7 @@ async function printSingleFile(input, target, module, answer, json) {
|
|
|
378
378
|
console.log(` environments: ${envs.length > 0 ? envs.join(", ") : "none"}`);
|
|
379
379
|
if (module.subtreeUnknown) console.log(" note: reachable, but its subtree is unknown (never transformed)");
|
|
380
380
|
if (module.chains.length > 0) {
|
|
381
|
-
const { formatChains } = await import("../_chunks/chains-
|
|
381
|
+
const { formatChains } = await import("../_chunks/chains-B4bgOl2g.js").then((n) => n.t);
|
|
382
382
|
console.log(" import chains:");
|
|
383
383
|
console.log(formatChains(module.chains, root));
|
|
384
384
|
}
|
|
@@ -397,7 +397,7 @@ async function printDevServerText(data, configDir) {
|
|
|
397
397
|
console.log(` environments: ${envList.length > 0 ? envList.join(", ") : "none"}`);
|
|
398
398
|
if (data.subtreeUnknown) console.log(" note: reachable, but its subtree is unknown (never transformed)");
|
|
399
399
|
if (data.chains.length > 0) {
|
|
400
|
-
const { formatChains } = await import("../_chunks/chains-
|
|
400
|
+
const { formatChains } = await import("../_chunks/chains-B4bgOl2g.js").then((n) => n.t);
|
|
401
401
|
console.log(" import chains:");
|
|
402
402
|
console.log(formatChains(data.chains, configDir));
|
|
403
403
|
}
|
package/dist/cli.js
CHANGED
|
@@ -90,7 +90,7 @@ async function runDev(options, _deps) {
|
|
|
90
90
|
return;
|
|
91
91
|
}
|
|
92
92
|
const { fork } = await import("node:child_process");
|
|
93
|
-
const { RESTART_EXIT_CODE } = await import("./_chunks/dev-server-
|
|
93
|
+
const { RESTART_EXIT_CODE } = await import("./_chunks/dev-server-BzBxgYAV.js").then((n) => n.t);
|
|
94
94
|
while (true) {
|
|
95
95
|
const result = await new Promise((resolve) => {
|
|
96
96
|
const child = fork(process.argv[1], process.argv.slice(2), {
|
|
@@ -173,7 +173,7 @@ async function runPreview(options, _deps) {
|
|
|
173
173
|
* `--project` names the tsconfig handed to tsgo.
|
|
174
174
|
*/
|
|
175
175
|
async function runCheck(options, _deps) {
|
|
176
|
-
const { checkRoutes, runTypeCheck } = await import("./_chunks/cli-check-
|
|
176
|
+
const { checkRoutes, runTypeCheck } = await import("./_chunks/cli-check-BqOylm-3.js");
|
|
177
177
|
const { root } = await checkRoutes({ viteConfigFile: options.config }, _deps);
|
|
178
178
|
await runTypeCheck({
|
|
179
179
|
root,
|
|
@@ -189,7 +189,7 @@ async function runCheck(options, _deps) {
|
|
|
189
189
|
async function runSchema(args) {
|
|
190
190
|
const subcommand = args[0];
|
|
191
191
|
if (subcommand !== "sync") throw new Error(`Unknown schema subcommand: ${subcommand ?? "(none)"}. Usage: timber schema sync`);
|
|
192
|
-
const { runSchemaSync, defaultCodecForSegment } = await import("./_chunks/cli-schema-sync
|
|
192
|
+
const { runSchemaSync, defaultCodecForSegment } = await import("./_chunks/cli-schema-sync--LZKs8Zn.js").then((n) => n.t);
|
|
193
193
|
const result = runSchemaSync(process.cwd());
|
|
194
194
|
if (result.filesystemSegments.length === 0) {
|
|
195
195
|
console.log("[timber] No dynamic segments found in app/.");
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { a as formatMissingPeers, i as formatConfigErrors, n as timberDevServer, o as validateConfig, r as checkPeerDependencies } from "./_chunks/dev-server-
|
|
1
|
+
import { a as formatMissingPeers, i as formatConfigErrors, n as timberDevServer, o as validateConfig, r as checkPeerDependencies } from "./_chunks/dev-server-BzBxgYAV.js";
|
|
2
2
|
import { a as isDynamicMetadataExtension } from "./_chunks/metadata-routes-DSDjM_hJ.js";
|
|
3
|
-
import { n as scanRoutes, r as collectInterceptionRewrites } from "./_chunks/scanner-
|
|
3
|
+
import { n as scanRoutes, r as collectInterceptionRewrites } from "./_chunks/scanner-BQ5sPIJ7.js";
|
|
4
4
|
import { h as swallow } from "./_chunks/logger-k2DQ4EUf.js";
|
|
5
5
|
import { c as writeRouteCodegen, i as getPrerenderExport, l as buildDirToRouteMap, n as formatConventionWarnings, r as lintConventions, s as flushCodegenWrites, t as checkAppDirExists } from "./_chunks/convention-lint-BnO5TyHD.js";
|
|
6
6
|
import { c as resolveClientJavascript, i as mergeFileConfig, l as createNoopTimer, o as resolveAppDir, r as loadTimberConfigFile, s as resolveBuildDir, t as createPluginContext } from "./_chunks/plugin-context-8idfR3UZ.js";
|
|
7
|
-
import { r as validateSchemaAgainstRoutes, t as collectLeafRoutes } from "./_chunks/walkers-
|
|
7
|
+
import { r as validateSchemaAgainstRoutes, t as collectLeafRoutes } from "./_chunks/walkers-CN2N_bA-.js";
|
|
8
8
|
import { i as poisonPillSource, r as markerFor, t as EXPLICIT_MARKERS } from "./_chunks/poison-rules-DoEhbqaY.js";
|
|
9
9
|
import { i as withBasePath, n as normalizeBasePath, t as isRelativeBase } from "./_chunks/base-path-DaQrzbez.js";
|
|
10
10
|
import { t as EMPTY_BUILD_MANIFEST } from "./_chunks/build-manifest-DTmSGLRz.js";
|
package/dist/routing/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as INTERCEPTION_MARKERS, i as DEFAULT_PAGE_EXTENSIONS, n as classifyUrlSegment, t as classifySegment } from "../_chunks/segment-classify-C539Pa2O.js";
|
|
2
|
-
import { n as scanRoutes, r as collectInterceptionRewrites } from "../_chunks/scanner-
|
|
2
|
+
import { n as scanRoutes, r as collectInterceptionRewrites } from "../_chunks/scanner-BQ5sPIJ7.js";
|
|
3
3
|
import { n as generateRouteMap } from "../_chunks/file-cache-Dw6BJPG7.js";
|
|
4
|
-
import { n as collectDynamicSegmentsFromTree, r as validateSchemaAgainstRoutes, t as collectLeafRoutes } from "../_chunks/walkers-
|
|
4
|
+
import { n as collectDynamicSegmentsFromTree, r as validateSchemaAgainstRoutes, t as collectLeafRoutes } from "../_chunks/walkers-CN2N_bA-.js";
|
|
5
5
|
export { DEFAULT_PAGE_EXTENSIONS, INTERCEPTION_MARKERS, classifySegment, classifyUrlSegment, collectDynamicSegmentsFromTree, collectInterceptionRewrites, collectLeafRoutes, generateRouteMap, scanRoutes, validateSchemaAgainstRoutes };
|
|
@@ -46,4 +46,14 @@ export interface TreeMatchOptions {
|
|
|
46
46
|
* Empty array matches the root itself (if terminal).
|
|
47
47
|
*/
|
|
48
48
|
export declare function matchUrlParts<TFile>(root: SegmentNode<TFile>, parts: string[], options?: TreeMatchOptions): TreeMatchResult<TFile> | null;
|
|
49
|
+
/**
|
|
50
|
+
* Yield every match for the given URL parts, in priority order.
|
|
51
|
+
*
|
|
52
|
+
* Same matching semantics as `matchUrlParts` — static > affixed-dynamic >
|
|
53
|
+
* bare-dynamic > catch-all > optional-catch-all — but instead of returning
|
|
54
|
+
* the first match, it yields all of them. Used by the metadata route matcher,
|
|
55
|
+
* which needs to try alternate owner segments when the first match doesn't
|
|
56
|
+
* own the requested metadata file.
|
|
57
|
+
*/
|
|
58
|
+
export declare function matchUrlPartsAll<TFile>(root: SegmentNode<TFile>, parts: string[], options?: TreeMatchOptions): Generator<TreeMatchResult<TFile>>;
|
|
49
59
|
//# sourceMappingURL=tree-match.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree-match.d.ts","sourceRoot":"","sources":["../../src/server/tree-match.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAIvD,2DAA2D;AAC3D,MAAM,WAAW,eAAe,CAAC,KAAK;IACpC,0DAA0D;IAC1D,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;IAC5B,4EAA4E;IAC5E,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;CAC3C;AAED,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAAC,KAAK,EACjC,IAAI,EAAE,WAAW,CAAC,KAAK,CAAC,EACxB,KAAK,EAAE,MAAM,EAAE,EACf,OAAO,CAAC,EAAE,gBAAgB,GACzB,eAAe,CAAC,KAAK,CAAC,GAAG,IAAI,CAS/B"}
|
|
1
|
+
{"version":3,"file":"tree-match.d.ts","sourceRoot":"","sources":["../../src/server/tree-match.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAIvD,2DAA2D;AAC3D,MAAM,WAAW,eAAe,CAAC,KAAK;IACpC,0DAA0D;IAC1D,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;IAC5B,4EAA4E;IAC5E,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;CAC3C;AAED,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAAC,KAAK,EACjC,IAAI,EAAE,WAAW,CAAC,KAAK,CAAC,EACxB,KAAK,EAAE,MAAM,EAAE,EACf,OAAO,CAAC,EAAE,gBAAgB,GACzB,eAAe,CAAC,KAAK,CAAC,GAAG,IAAI,CAS/B;AAED;;;;;;;;GAQG;AACH,wBAAiB,gBAAgB,CAAC,KAAK,EACrC,IAAI,EAAE,WAAW,CAAC,KAAK,CAAC,EACxB,KAAK,EAAE,MAAM,EAAE,EACf,OAAO,CAAC,EAAE,gBAAgB,GACzB,SAAS,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAMnC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@timber-js/app",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.206",
|
|
4
4
|
"description": "Vite-native React framework built for Servers and Serverless Platforms — correct HTTP semantics, real status codes, pages that work without JavaScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare-workers",
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
resolveServePathForFile,
|
|
19
19
|
type MetadataRouteType,
|
|
20
20
|
} from './metadata-routes.ts';
|
|
21
|
-
import { matchUrlParts } from './tree-match.ts';
|
|
21
|
+
import { matchUrlParts, matchUrlPartsAll } from './tree-match.ts';
|
|
22
22
|
|
|
23
23
|
// ─── Manifest Types ───────────────────────────────────────────────────────
|
|
24
24
|
//
|
|
@@ -190,30 +190,44 @@ function matchMetadataPathname(
|
|
|
190
190
|
|
|
191
191
|
let segment: ManifestSegmentNode;
|
|
192
192
|
let params: Record<string, string | string[]>;
|
|
193
|
+
let file: ManifestFile | null = null;
|
|
193
194
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
195
|
+
// Find the metadata file owner. For prefix matches, iterate all matching
|
|
196
|
+
// segments in priority order — when competing bare-dynamic groups match
|
|
197
|
+
// the same prefix, the first may not own the file. For root-level matches,
|
|
198
|
+
// search all group children since findMetadataRouteInSegment may return
|
|
199
|
+
// a file with the wrong extension when multiple groups own the same
|
|
200
|
+
// convention with different static types.
|
|
201
|
+
segment = root;
|
|
202
|
+
params = {};
|
|
203
|
+
const candidates = [...metadataOwnerCandidates(root, prefixParts)];
|
|
203
204
|
|
|
204
|
-
//
|
|
205
|
-
|
|
205
|
+
// Two passes: direct owners first (node itself + groups), then
|
|
206
|
+
// zero-segment optional-catch-all descent. A direct owner across any
|
|
207
|
+
// candidate must beat a zero-segment catch-all on an earlier candidate.
|
|
208
|
+
for (const allowCatchAll of [false, true]) {
|
|
209
|
+
for (const candidate of candidates) {
|
|
210
|
+
if (!convention.nestable && candidate.segment !== root) continue;
|
|
211
|
+
const found = findMetadataRouteInSegment(
|
|
212
|
+
candidate.segment,
|
|
213
|
+
baseName,
|
|
214
|
+
allowCatchAll && convention.nestable
|
|
215
|
+
);
|
|
216
|
+
if (!found) continue;
|
|
217
|
+
if (convention.serveExtension) {
|
|
218
|
+
const resolvedServePath = resolveServePathForFile(baseName, found.filePath);
|
|
219
|
+
if (lastPart !== resolvedServePath) continue;
|
|
220
|
+
}
|
|
221
|
+
segment = candidate.segment;
|
|
222
|
+
params = candidate.params;
|
|
223
|
+
file = found;
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
if (file) break;
|
|
227
|
+
}
|
|
206
228
|
|
|
207
|
-
const file = findMetadataRouteInSegment(segment, baseName, convention.nestable);
|
|
208
229
|
if (!file) return null;
|
|
209
230
|
|
|
210
|
-
// Validate the requested URL extension matches the file's resolved serve path.
|
|
211
|
-
// Prevents /icon.svg matching when only icon.png exists.
|
|
212
|
-
if (convention.serveExtension) {
|
|
213
|
-
const resolvedServePath = resolveServePathForFile(baseName, file.filePath);
|
|
214
|
-
if (lastPart !== resolvedServePath) return null;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
231
|
const ext = file.filePath.slice(file.filePath.lastIndexOf('.') + 1);
|
|
218
232
|
const isStatic = isStaticMetadataExtension(baseName, ext);
|
|
219
233
|
const contentType = isStatic
|
|
@@ -265,3 +279,42 @@ function findMetadataRouteInSegment(
|
|
|
265
279
|
}
|
|
266
280
|
return null;
|
|
267
281
|
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Yield candidate owner segments for a metadata route.
|
|
285
|
+
*
|
|
286
|
+
* For root-level metadata (empty prefix), yields the root and then each
|
|
287
|
+
* transparent group child — so extension validation can skip a group that
|
|
288
|
+
* owns the wrong static type and find the right one. For prefix matches,
|
|
289
|
+
* delegates to `matchUrlPartsAll` which handles all segment kinds.
|
|
290
|
+
*/
|
|
291
|
+
function* metadataOwnerCandidates(
|
|
292
|
+
root: ManifestSegmentNode,
|
|
293
|
+
prefixParts: string[]
|
|
294
|
+
): Generator<{ segment: ManifestSegmentNode; params: Record<string, string | string[]> }> {
|
|
295
|
+
if (prefixParts.length === 0) {
|
|
296
|
+
yield { segment: root, params: {} };
|
|
297
|
+
// Also yield each group child individually so the caller can validate
|
|
298
|
+
// extensions per-group rather than taking the first file found.
|
|
299
|
+
for (const child of root.children) {
|
|
300
|
+
if (child.segmentType === 'group') {
|
|
301
|
+
yield* groupDescendants(child);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
} else {
|
|
305
|
+
for (const result of matchUrlPartsAll(root, prefixParts, { requireTerminal: false })) {
|
|
306
|
+
yield { segment: result.chain[result.chain.length - 1], params: result.params };
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function* groupDescendants(
|
|
312
|
+
node: ManifestSegmentNode
|
|
313
|
+
): Generator<{ segment: ManifestSegmentNode; params: Record<string, string | string[]> }> {
|
|
314
|
+
yield { segment: node, params: {} };
|
|
315
|
+
for (const child of node.children) {
|
|
316
|
+
if (child.segmentType === 'group') {
|
|
317
|
+
yield* groupDescendants(child);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|