@timber-js/app 0.2.0-alpha.214 → 0.2.0-alpha.216
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/als-registry-BZqHCtq-.js.map +1 -1
- package/dist/_chunks/{chains-CjK1Eu6a.js → chains-YKZ8WpIW.js} +2 -2
- package/dist/_chunks/{chains-CjK1Eu6a.js.map → chains-YKZ8WpIW.js.map} +1 -1
- package/dist/_chunks/{classify-GAdt6aiA.js → classify-2Yp3xJY1.js} +3 -3
- package/dist/_chunks/{classify-GAdt6aiA.js.map → classify-2Yp3xJY1.js.map} +1 -1
- package/dist/_chunks/{cli-check-DOzjlycg.js → cli-check-D2WtbNqo.js} +3 -3
- package/dist/_chunks/{cli-check-DOzjlycg.js.map → cli-check-D2WtbNqo.js.map} +1 -1
- package/dist/_chunks/{cli-schema-sync-B9wDaQvW.js → cli-schema-sync-CySLKrO3.js} +2 -2
- package/dist/_chunks/{cli-schema-sync-B9wDaQvW.js.map → cli-schema-sync-CySLKrO3.js.map} +1 -1
- package/dist/_chunks/{client-dep-entries-DyDqXOF9.js → client-dep-entries-BOkpKjj1.js} +47 -3
- package/dist/_chunks/client-dep-entries-BOkpKjj1.js.map +1 -0
- package/dist/_chunks/{convention-lint-B3QEGJX7.js → convention-lint-ByKJ6aqD.js} +2 -2
- package/dist/_chunks/{convention-lint-B3QEGJX7.js.map → convention-lint-ByKJ6aqD.js.map} +1 -1
- package/dist/_chunks/{dev-server-_9L4KWC-.js → dev-server-B8zsT-ee.js} +4 -4
- package/dist/_chunks/{dev-server-_9L4KWC-.js.map → dev-server-B8zsT-ee.js.map} +1 -1
- package/dist/_chunks/{live-graph-Cd3YHvrH.js → live-graph-BhtrZpRd.js} +4 -4
- package/dist/_chunks/{live-graph-Cd3YHvrH.js.map → live-graph-BhtrZpRd.js.map} +1 -1
- package/dist/_chunks/{metadata-routes-DSDjM_hJ.js → metadata-routes-B3XJNyIH.js} +1 -2
- package/dist/_chunks/metadata-routes-B3XJNyIH.js.map +1 -0
- package/dist/_chunks/{poison-scan-BnJjBOkn.js → poison-scan-C4FgMxFl.js} +2 -2
- package/dist/_chunks/{poison-scan-BnJjBOkn.js.map → poison-scan-C4FgMxFl.js.map} +1 -1
- package/dist/_chunks/{scanner-CKAT5gRx.js → scanner-Cb3fSjAC.js} +4 -4
- package/dist/_chunks/{scanner-CKAT5gRx.js.map → scanner-Cb3fSjAC.js.map} +1 -1
- package/dist/_chunks/{walkers-DwCXEyRu.js → walkers-Ber9bamD.js} +3 -3
- package/dist/_chunks/{walkers-DwCXEyRu.js.map → walkers-Ber9bamD.js.map} +1 -1
- package/dist/adapters/types.d.ts +3 -1
- package/dist/adapters/types.d.ts.map +1 -1
- package/dist/analyze/crawl-entry.js +3 -3
- package/dist/analyze/graph-command.js +2 -2
- package/dist/cli.d.ts +5 -5
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +15 -14
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -53
- package/dist/index.js.map +1 -1
- package/dist/plugins/client-dep-entries.d.ts +36 -0
- package/dist/plugins/client-dep-entries.d.ts.map +1 -1
- package/dist/routing/index.js +2 -2
- package/dist/server/als-registry.d.ts +2 -0
- package/dist/server/als-registry.d.ts.map +1 -1
- package/dist/server/internal.js +2 -2
- package/dist/server/internal.js.map +1 -1
- package/dist/server/metadata-collector.d.ts +2 -0
- package/dist/server/metadata-collector.d.ts.map +1 -1
- package/dist/server/metadata-route-links.d.ts +70 -0
- package/dist/server/metadata-route-links.d.ts.map +1 -0
- package/dist/server/metadata-routes.d.ts +0 -24
- package/dist/server/metadata-routes.d.ts.map +1 -1
- package/dist/server/port-resolution.d.ts +3 -12
- package/dist/server/port-resolution.d.ts.map +1 -1
- package/dist/server/route-element-builder.d.ts.map +1 -1
- package/dist/server/route-matcher.d.ts +7 -0
- package/dist/server/route-matcher.d.ts.map +1 -1
- package/docs/api/36-cli.mdx +8 -4
- package/docs/learn/13-deploying.mdx +2 -0
- package/package.json +1 -1
- package/src/adapters/types.ts +3 -1
- package/src/cli.ts +18 -16
- package/src/index.ts +48 -71
- package/src/plugins/client-dep-entries.ts +46 -0
- package/src/server/als-registry.ts +2 -0
- package/src/server/metadata-collector.ts +15 -17
- package/src/server/metadata-route-links.ts +200 -0
- package/src/server/metadata-routes.ts +0 -106
- package/src/server/port-resolution.ts +6 -16
- package/src/server/route-element-builder.ts +1 -0
- package/src/server/route-matcher.ts +2 -2
- package/dist/_chunks/client-dep-entries-DyDqXOF9.js.map +0 -1
- package/dist/_chunks/metadata-routes-DSDjM_hJ.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as classifyUrlSegment } from "./segment-classify-C539Pa2O.js";
|
|
2
|
-
import { u as readFileCached } from "./scanner-
|
|
3
|
-
import { n as findSchemaFile, r as parseExistingSchemaKeys } from "./cli-schema-sync-
|
|
2
|
+
import { u as readFileCached } from "./scanner-Cb3fSjAC.js";
|
|
3
|
+
import { n as findSchemaFile, r as parseExistingSchemaKeys } from "./cli-schema-sync-CySLKrO3.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-Ber9bamD.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"walkers-DwCXEyRu.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,QA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AC,GAAG,QAAQ,YAAY;CACnC,OAAO,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-Ber9bamD.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,MAAM;CACxC,IAAI,CAAC,YAAY,OAAO,CAAC;CAEzB,MAAM,UAAU,eAAe,UAAU;CACzC,MAAM,aAAa,wBAAwB,OAAO;CAElD,IAAI,WAAW,WAAW,GAAG,OAAO,CAAC;CAIrC,OAAO,aAAa,YAFO,+BAA+B,IAE1B,CAAkB;AACpD;;;;;AAMA,SAAgB,aACd,YACA,oBACiB;CACjB,MAAM,WAA4B,CAAC;CAGnC,MAAM,+BAAe,IAAI,IAAoB;CAC7C,KAAK,MAAM,SAAS,oBAAoB;EACtC,MAAM,OAAO,iBAAiB,KAAK;EACnC,IAAI,MACF,aAAa,IAAI,MAAM,KAAK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G1E,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"}
|
package/dist/adapters/types.d.ts
CHANGED
|
@@ -137,7 +137,9 @@ export interface TimberPlatformAdapter {
|
|
|
137
137
|
buildOutput(config: TimberConfig, artifacts: BuildArtifacts): Promise<void>;
|
|
138
138
|
/**
|
|
139
139
|
* Start a local preview server for the built output.
|
|
140
|
-
*
|
|
140
|
+
* Without it, `timber preview` fails with an error naming the adapter —
|
|
141
|
+
* there is no fallback to Vite preview, which would serve the build
|
|
142
|
+
* directory (server bundles included) as static files.
|
|
141
143
|
*
|
|
142
144
|
* Runs in a later process than the build (`timber preview`); see
|
|
143
145
|
* {@link PreviewTarget}.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/adapters/types.ts"],"names":[],"mappings":"AAMA;;;;;;;;;GASG;AACH,MAAM,WAAW,YAAY;IAC3B,qDAAqD;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;;;;;;OAUG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACpC;AAED,uCAAuC;AACvC,MAAM,WAAW,iBAAiB;IAChC,2EAA2E;IAC3E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,UAAU,kBAAkB;IAC1B;;;;OAIG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAC;IACnC;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;CAC3C;AAED,qDAAqD;AACrD,MAAM,WAAW,oBAAqB,SAAQ,kBAAkB;I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,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,qBAAqB;IACpC,8DAA8D;IAC9D,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,WAAW,CAAC,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5E;;;;;;;;OAQG;IACH,OAAO,CAAC,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAErE;;;;;;;;;OASG;IACH,cAAc,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;CACxC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { i as scanProjectSourceFiles, n as isScannableSourceFile, t as buildSourceExtensions } from "../_chunks/scan-BoP17W3w.js";
|
|
2
2
|
import { c as resolveAppDir, i as isTimberPluginApi } from "../_chunks/plugin-context-BPBPc3lL.js";
|
|
3
|
-
import { i as detectDirective, r as classifyModules } from "../_chunks/classify-
|
|
4
|
-
import { n as stitchImportChains } from "../_chunks/chains-
|
|
5
|
-
import { n as importSignals, r as poisoningsFor, t as collectImportSpecifiers } from "../_chunks/poison-scan-
|
|
3
|
+
import { i as detectDirective, r as classifyModules } from "../_chunks/classify-2Yp3xJY1.js";
|
|
4
|
+
import { n as stitchImportChains } from "../_chunks/chains-YKZ8WpIW.js";
|
|
5
|
+
import { n as importSignals, r as poisoningsFor, t as collectImportSpecifiers } from "../_chunks/poison-scan-C4FgMxFl.js";
|
|
6
6
|
import { normalizePath } from "vite";
|
|
7
7
|
import { join, resolve } from "node:path";
|
|
8
8
|
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-YKZ8WpIW.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-YKZ8WpIW.js").then((n) => n.t);
|
|
401
401
|
console.log(" import chains:");
|
|
402
402
|
console.log(formatChains(data.chains, configDir));
|
|
403
403
|
}
|
package/dist/cli.d.ts
CHANGED
|
@@ -50,7 +50,6 @@ export declare function parseArgs(args: string[]): ParsedArgs;
|
|
|
50
50
|
export interface ViteDeps {
|
|
51
51
|
createServer?: typeof import('vite').createServer;
|
|
52
52
|
createBuilder?: typeof import('vite').createBuilder;
|
|
53
|
-
preview?: typeof import('vite').preview;
|
|
54
53
|
resolveViteConfig?: ResolveViteConfig;
|
|
55
54
|
}
|
|
56
55
|
/**
|
|
@@ -76,16 +75,17 @@ export declare function runDev(options: CommandOptions, _deps?: ViteDeps): Promi
|
|
|
76
75
|
export declare function runBuild(options: CommandOptions, _deps?: ViteDeps): Promise<void>;
|
|
77
76
|
/**
|
|
78
77
|
* Serve the production build for local testing.
|
|
79
|
-
*
|
|
80
|
-
*
|
|
78
|
+
* The adapter's preview() serves it; without one, preview fails (TIM-1565).
|
|
79
|
+
* There is no fallback to Vite preview: it would serve the build directory
|
|
80
|
+
* itself — the server bundles as static files, with no root `index.html` —
|
|
81
|
+
* which is useless in either output mode.
|
|
81
82
|
*
|
|
82
83
|
* The project is resolved through Vite, as `timber check` resolves it
|
|
83
84
|
* (`cli-context.ts`), so the adapter, the output mode, and the build
|
|
84
85
|
* directory are the ones `timber build` used — including `--config`, inline
|
|
85
86
|
* `timber({ ... })` options, Vite's `root`, and `build.outDir`, none of which
|
|
86
87
|
* a re-read of `timber.config.ts` can see (TIM-1531). A config file that
|
|
87
|
-
* exists but fails to load throws
|
|
88
|
-
* degrading to plain Vite preview (TIM-1066).
|
|
88
|
+
* exists but fails to load throws, naming the file (TIM-1066).
|
|
89
89
|
*/
|
|
90
90
|
export declare function runPreview(options: CommandOptions, _deps?: ViteDeps): Promise<void>;
|
|
91
91
|
/**
|
package/dist/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAgBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE1D,YAAY,EAAE,SAAS,EAAE,CAAC;AAE1B,QAAA,MAAM,QAAQ,YAAI,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAU,CAAC;AAC1F,KAAK,OAAO,GAAG,CAAC,OAAO,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC;AAEzC,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,+DAA+D;IAC/D,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,oEAAoE;IACpE,IAAI,EAAE,OAAO,CAAC;IACd,uDAAuD;IACvD,GAAG,EAAE,OAAO,CAAC;IACb,8EAA8E;IAC9E,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED,MAAM,WAAW,cAAc;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AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,UAAU,CAmEpD;AAID,kDAAkD;AAClD,MAAM,WAAW,QAAQ;IACvB,YAAY,CAAC,EAAE,cAAc,MAAM,EAAE,YAAY,CAAC;IAClD,aAAa,CAAC,EAAE,cAAc,MAAM,EAAE,aAAa,CAAC;IACpD,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;CACvC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,MAAM,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAwDrF;AAED;;;;GAIG;AACH,wBAAsB,QAAQ,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAMvF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAuBzF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,QAAQ,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAMxF;AAID;;;;;GAKG;AACH,wBAAsB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CA6C7D;AAID;;;;;;;GAOG;AACH,wBAAsB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAsD7C"}
|
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-B8zsT-ee.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), {
|
|
@@ -129,30 +129,31 @@ async function runBuild(options, _deps) {
|
|
|
129
129
|
}
|
|
130
130
|
/**
|
|
131
131
|
* Serve the production build for local testing.
|
|
132
|
-
*
|
|
133
|
-
*
|
|
132
|
+
* The adapter's preview() serves it; without one, preview fails (TIM-1565).
|
|
133
|
+
* There is no fallback to Vite preview: it would serve the build directory
|
|
134
|
+
* itself — the server bundles as static files, with no root `index.html` —
|
|
135
|
+
* which is useless in either output mode.
|
|
134
136
|
*
|
|
135
137
|
* The project is resolved through Vite, as `timber check` resolves it
|
|
136
138
|
* (`cli-context.ts`), so the adapter, the output mode, and the build
|
|
137
139
|
* directory are the ones `timber build` used — including `--config`, inline
|
|
138
140
|
* `timber({ ... })` options, Vite's `root`, and `build.outDir`, none of which
|
|
139
141
|
* a re-read of `timber.config.ts` can see (TIM-1531). A config file that
|
|
140
|
-
* exists but fails to load throws
|
|
141
|
-
* degrading to plain Vite preview (TIM-1066).
|
|
142
|
+
* exists but fails to load throws, naming the file (TIM-1066).
|
|
142
143
|
*/
|
|
143
144
|
async function runPreview(options, _deps) {
|
|
144
145
|
const { resolveTimberContext } = await import("./_chunks/cli-context-By7k2xVo.js");
|
|
145
146
|
const { adapterConfig, contextAdapter } = await import("./_chunks/plugin-context-BPBPc3lL.js").then((n) => n.s);
|
|
146
147
|
const ctx = await resolveTimberContext("preview", options.config, _deps?.resolveViteConfig);
|
|
147
148
|
const adapter = contextAdapter(ctx);
|
|
148
|
-
if (typeof adapter?.preview
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
outputDir: ctx.buildDir
|
|
152
|
-
});
|
|
153
|
-
return;
|
|
149
|
+
if (typeof adapter?.preview !== "function") {
|
|
150
|
+
const missing = adapter ? `The adapter '${adapter.name}' has no preview(), so \`timber preview\` cannot serve this build.` : `No adapter is configured, so \`timber preview\` has nothing to serve this build with.`;
|
|
151
|
+
throw new Error(`[timber] ${missing} Use an adapter that implements preview() — cloudflare() from '@timber-js/app/adapters/cloudflare', or nitro() from '@timber-js/app/adapters/nitro' (any preset for a static build; node-server or bun for a server build) — or serve the build with your platform's own tooling.`);
|
|
154
152
|
}
|
|
155
|
-
|
|
153
|
+
await adapter.preview(adapterConfig(ctx), {
|
|
154
|
+
output: ctx.config.output ?? "server",
|
|
155
|
+
outputDir: ctx.buildDir
|
|
156
|
+
});
|
|
156
157
|
}
|
|
157
158
|
/**
|
|
158
159
|
* Validate routes and types without producing build output.
|
|
@@ -169,7 +170,7 @@ async function runPreview(options, _deps) {
|
|
|
169
170
|
* `--project` names the tsconfig handed to tsgo.
|
|
170
171
|
*/
|
|
171
172
|
async function runCheck(options, _deps) {
|
|
172
|
-
const { checkRoutes, runTypeCheck } = await import("./_chunks/cli-check-
|
|
173
|
+
const { checkRoutes, runTypeCheck } = await import("./_chunks/cli-check-D2WtbNqo.js");
|
|
173
174
|
const { root } = await checkRoutes({ viteConfigFile: options.config }, _deps);
|
|
174
175
|
await runTypeCheck({
|
|
175
176
|
root,
|
|
@@ -185,7 +186,7 @@ async function runCheck(options, _deps) {
|
|
|
185
186
|
async function runSchema(args) {
|
|
186
187
|
const subcommand = args[0];
|
|
187
188
|
if (subcommand !== "sync") throw new Error(`Unknown schema subcommand: ${subcommand ?? "(none)"}. Usage: timber schema sync`);
|
|
188
|
-
const { runSchemaSync, defaultCodecForSegment } = await import("./_chunks/cli-schema-sync-
|
|
189
|
+
const { runSchemaSync, defaultCodecForSegment } = await import("./_chunks/cli-schema-sync-CySLKrO3.js").then((n) => n.t);
|
|
189
190
|
const result = runSchemaSync(process.cwd());
|
|
190
191
|
if (result.filesystemSegments.length === 0) {
|
|
191
192
|
console.log("[timber] No dynamic segments found in app/.");
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\n// timber.js CLI\n//\n// Wraps Vite commands with timber-specific behavior.\n// See design/18-build-system.md §\"CLI\".\n//\n// Commands:\n// timber dev — Start Vite dev server with HMR\n// timber build — Run multi-environment build via createBuilder/buildApp\n// timber preview — Serve the production build\n// timber check — Validate types + routes without building\n// timber graph — Classify a file's module environment(s) (design/47)\n\n// Type-only — the implementation is imported dynamically inside runCheck so the\n// CLI's other commands never load the route scanner.\nimport type { CheckDeps } from './cli-check.ts';\nimport type { ResolveViteConfig } from './cli-context.ts';\n\nexport type { CheckDeps };\n\nconst COMMANDS = ['dev', 'build', 'preview', 'check', 'schema', 'init', 'graph'] as const;\ntype Command = (typeof COMMANDS)[number];\n\nexport interface ParsedArgs {\n command: Command;\n config: string | undefined;\n /** `--project`: the tsconfig `timber check` passes to tsgo. */\n project: string | undefined;\n /** `timber graph` only: emit the machine-readable JSON contract. */\n json: boolean;\n /** `timber graph` only: classify the whole project. */\n all: boolean;\n /** Positional arguments after the command (`schema sync`, `graph <file>`). */\n rest: string[];\n}\n\nexport interface CommandOptions {\n /** Path to a Vite config file. Means the same thing for every command. */\n config?: string;\n /** `timber check` only: the tsconfig to type-check. */\n project?: string;\n}\n\n/**\n * Parse CLI arguments into a structured command + options.\n * Accepts: timber <command> [--config|-c <path>] [--project <path>]\n *\n * `--config` names a **Vite** config file for every command, `check` included\n * (TIM-1332): `check` resolves the project through Vite, so a project that\n * builds with `--config ./custom.vite.config.ts` has to be checkable the same\n * way. `--project` names the tsconfig, spelled as tsgo and tsc spell it, and\n * is meaningful only for `check`.\n *\n * Before TIM-1332 `--config` meant the tsconfig for `check` alone — one flag\n * with two meanings, which the docs had to carry a note to explain and which\n * left custom Vite configs unreachable from `check` entirely.\n *\n * Unknown flags are an error, not silently ignored — `timber dev --port 4000`\n * starting on the default port would contradict fail-loudly. The surface stays\n * deliberately small (design/11-platform.md §CLI); port selection goes through\n * the PORT env var or server.port in vite.config.ts.\n *\n * Each subcommand declares its exact flags (the `check --project` precedent,\n * TIM-1332): `graph` additionally accepts a file positional plus `--json` and\n * `--all`, and those two are rejected everywhere else.\n */\nexport function parseArgs(args: string[]): ParsedArgs {\n if (args.length === 0) {\n throw new Error(\n 'No command provided. Usage: timber <dev|build|preview|check|schema|init|graph> [--config <path>]'\n );\n }\n\n const command = args[0];\n if (!COMMANDS.includes(command as Command)) {\n throw new Error(`Unknown command: ${command}. Available commands: ${COMMANDS.join(', ')}`);\n }\n\n let config: string | undefined;\n let project: string | undefined;\n let json = false;\n let all = false;\n const rest: string[] = [];\n for (let i = 1; i < args.length; i++) {\n const arg = args[i];\n if (arg === '--config' || arg === '-c') {\n config = args[++i];\n if (!config) {\n throw new Error('--config requires a path argument');\n }\n } else if (arg === '--json' || arg === '--all') {\n if (command !== 'graph') {\n throw new Error(\n `${arg} is only valid for \\`timber graph\\` (the module-environment query).`\n );\n }\n if (arg === '--json') json = true;\n else all = true;\n } else if (arg === '--project') {\n if (command !== 'check') {\n throw new Error(\n `--project is only valid for \\`timber check\\` (it names the tsconfig to type-check). ` +\n `To point \\`timber ${command}\\` at a different Vite config, use --config <path>.`\n );\n }\n project = args[++i];\n if (!project) {\n throw new Error('--project requires a path argument');\n }\n } else if (arg.startsWith('-')) {\n const portHint =\n arg === '--port' || arg === '-p'\n ? ' To change the port, set the PORT environment variable (PORT=4000 timber dev) ' +\n 'or server.port in vite.config.ts.'\n : '';\n throw new Error(\n `Unknown option: ${arg}. The timber CLI accepts --config <path>` +\n ` (and --project <path> for \\`check\\`).${portHint}`\n );\n } else if (command === 'schema' || command === 'init' || command === 'graph') {\n rest.push(arg);\n } else {\n throw new Error(`Unexpected argument: ${arg}. Usage: timber ${command} [--config <path>]`);\n }\n }\n\n if (command === 'graph' && rest.length > 1) {\n throw new Error(\n `timber graph takes one file. Usage: timber graph <file> [--json], or timber graph --all --json`\n );\n }\n\n return { command: command as Command, config, project, json, all, rest };\n}\n\n// ─── Command Implementations ─────────────────────────────────────────────────\n\n/** @internal Dependency injection for testing. */\nexport interface ViteDeps {\n createServer?: typeof import('vite').createServer;\n createBuilder?: typeof import('vite').createBuilder;\n preview?: typeof import('vite').preview;\n resolveViteConfig?: ResolveViteConfig;\n}\n\n/**\n * Start the Vite dev server with a supervisor that respawns the process\n * when timber.config.ts changes. Node's require cache for ESM modules\n * loaded via require() cannot be evicted, so an in-process restart\n * serves stale config. The supervisor forks a worker; when the worker\n * exits with RESTART_EXIT_CODE (set by timber-dev-server on config file\n * change), the supervisor spawns a fresh worker with a clean cache.\n *\n * The timber plugin binds the port immediately with a holding page\n * (in rootSync's config hook) so browsers see a \"starting...\" page\n * instead of ERR_CONNECTION_REFUSED during initialization.\n *\n * See design/21-dev-server.md, TIM-665, TIM-1444.\n */\nexport async function runDev(options: CommandOptions, _deps?: ViteDeps): Promise<void> {\n // Worker mode: run the dev server directly (forked by supervisor below)\n if (process.env.__TIMBER_DEV_WORKER) {\n const createServer = _deps?.createServer ?? (await import('vite')).createServer;\n const server = await createServer({\n configFile: options.config,\n });\n await server.listen();\n server.printUrls();\n return;\n }\n\n // Supervisor mode: fork a worker and respawn on config changes.\n const { fork } = await import('node:child_process');\n const { RESTART_EXIT_CODE } = await import('./plugins/dev-server.ts');\n\n // eslint-disable-next-line no-constant-condition\n while (true) {\n const result = await new Promise<{ code: number | null; signal: NodeJS.Signals | null }>(\n (resolve) => {\n const child = fork(process.argv[1], process.argv.slice(2), {\n stdio: 'inherit',\n env: { ...process.env, __TIMBER_DEV_WORKER: '1' },\n });\n\n // Forward signals to the child. SIGINT from Ctrl+C is sent to\n // the entire process group, but a targeted SIGTERM (from a\n // process manager or test teardown) only reaches the parent.\n const onSigint = () => child.kill('SIGINT');\n const onSigterm = () => child.kill('SIGTERM');\n process.on('SIGINT', onSigint);\n process.on('SIGTERM', onSigterm);\n\n child.on('exit', (code, signal) => {\n process.off('SIGINT', onSigint);\n process.off('SIGTERM', onSigterm);\n resolve({ code, signal });\n });\n }\n );\n\n if (result.code === RESTART_EXIT_CODE) {\n continue;\n }\n\n // Child was killed by a signal (e.g. SIGTERM) — re-raise on ourselves\n if (result.signal) {\n process.kill(process.pid, result.signal);\n }\n\n if (result.code != null && result.code !== 0) {\n process.exit(result.code);\n }\n\n break;\n }\n}\n\n/**\n * Run the production build using createBuilder + buildApp.\n * Direct build() calls do NOT trigger the RSC plugin's multi-environment\n * pipeline — createBuilder/buildApp is required.\n */\nexport async function runBuild(options: CommandOptions, _deps?: ViteDeps): Promise<void> {\n const createBuilder = _deps?.createBuilder ?? (await import('vite')).createBuilder;\n const builder = await createBuilder({\n configFile: options.config,\n });\n await builder.buildApp();\n}\n\n/**\n * Serve the production build for local testing.\n * If the adapter provides a preview() method, it takes priority.\n * Otherwise falls back to Vite's built-in preview server.\n *\n * The project is resolved through Vite, as `timber check` resolves it\n * (`cli-context.ts`), so the adapter, the output mode, and the build\n * directory are the ones `timber build` used — including `--config`, inline\n * `timber({ ... })` options, Vite's `root`, and `build.outDir`, none of which\n * a re-read of `timber.config.ts` can see (TIM-1531). A config file that\n * exists but fails to load throws (naming the file) instead of silently\n * degrading to plain Vite preview (TIM-1066).\n */\nexport async function runPreview(options: CommandOptions, _deps?: ViteDeps): Promise<void> {\n const { resolveTimberContext } = await import('./cli-context.ts');\n const { adapterConfig, contextAdapter } = await import('./plugin-context.ts');\n\n const ctx = await resolveTimberContext('preview', options.config, _deps?.resolveViteConfig);\n const adapter = contextAdapter(ctx);\n\n if (typeof adapter?.preview === 'function') {\n await adapter.preview(adapterConfig(ctx), {\n output: ctx.config.output ?? 'server',\n outputDir: ctx.buildDir,\n });\n return;\n }\n\n // Fallback: Vite's built-in preview server\n const preview = _deps?.preview ?? (await import('vite')).preview;\n const server = await preview({\n configFile: options.config,\n });\n server.printUrls();\n}\n\n/**\n * Validate routes and types without producing build output.\n *\n * Runs the route pass first — resolve the project through Vite, scan it, fail\n * on proven-fatal convention errors, print warnings, and regenerate the route\n * types — then `tsgo --noEmit`. Codegen has to precede the type pass: the\n * generated `.timber/*.d.ts` files are what type `<Link href>` and\n * `useSegmentParams()`, and a fresh clone has never produced them. See\n * `cli-check.ts` for the full reasoning.\n *\n * `--config` names the **Vite** config, as it does for every other command, so\n * an app that builds with a custom one is checkable the same way.\n * `--project` names the tsconfig handed to tsgo.\n */\nexport async function runCheck(options: CommandOptions, _deps?: CheckDeps): Promise<void> {\n const { checkRoutes, runTypeCheck } = await import('./cli-check.ts');\n const { root } = await checkRoutes({ viteConfigFile: options.config }, _deps);\n // tsgo runs from the root the route pass resolved, not from cwd — that is\n // where it just wrote the declarations tsgo has to read.\n await runTypeCheck({ root, config: options.project }, _deps);\n}\n\n// ─── Schema Subcommand ───────────────────────────────────────────────────────\n\n/**\n * `timber schema sync` — scan filesystem for dynamic segments, diff against\n * app/schema.ts, and append missing entries with type-appropriate codec defaults.\n *\n * See design/41-global-params.md §Auto-Scaffolding\n */\nexport async function runSchema(args: string[]): Promise<void> {\n const subcommand = args[0];\n\n if (subcommand !== 'sync') {\n throw new Error(\n `Unknown schema subcommand: ${subcommand ?? '(none)'}. Usage: timber schema sync`\n );\n }\n\n const { runSchemaSync, defaultCodecForSegment } = await import('./cli-schema-sync.ts');\n const result = runSchemaSync(process.cwd());\n\n if (result.filesystemSegments.length === 0) {\n console.log('[timber] No dynamic segments found in app/.');\n return;\n }\n\n if (result.created) {\n console.log(`[timber] Created app/schema.ts with ${result.addedSegments.length} segment(s):`);\n for (const seg of result.addedSegments) {\n console.log(` + ${seg}: ${defaultCodecForSegment(seg)}`);\n }\n return;\n }\n\n if (result.addedSegments.length === 0 && result.removedSegments.length === 0) {\n console.log('[timber] Schema is up to date — all segments are registered.');\n return;\n }\n\n if (result.addedSegments.length > 0) {\n console.log(`[timber] Added ${result.addedSegments.length} segment(s) to app/schema.ts:`);\n for (const seg of result.addedSegments) {\n console.log(` + ${seg}: ${defaultCodecForSegment(seg)}`);\n }\n }\n\n if (result.removedSegments.length > 0) {\n console.log(\n `[timber] Removed ${result.removedSegments.length} stale segment(s) from app/schema.ts:`\n );\n for (const seg of result.removedSegments) {\n console.log(` - ${seg}`);\n }\n }\n}\n\n// ─── Init Subcommand ─────────────────────────────────────────────────────────\n\n/**\n * `timber init` — write AGENTS.md (and a CLAUDE.md symlink to it) to the\n * project root so AI coding agents can discover timber.js documentation and\n * conventions.\n *\n * The content is read from the installed @timber-js/app package itself, so it\n * stays in sync with the installed version.\n */\nexport async function runInit(): Promise<void> {\n const { readFileSync, writeFileSync, existsSync, symlinkSync } = await import('node:fs');\n const { resolve, dirname } = await import('node:path');\n const { fileURLToPath } = await import('node:url');\n\n const root = process.cwd();\n const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');\n\n const agentSkillPath = resolve(packageRoot, 'agent-skill.md');\n if (!existsSync(agentSkillPath)) {\n throw new Error(\n 'agent-skill.md not found in @timber-js/app package. ' +\n 'This may be a development install — try reinstalling.'\n );\n }\n\n const agentSkill = readFileSync(agentSkillPath, 'utf-8');\n\n const agentsPath = resolve(root, 'AGENTS.md');\n const claudePath = resolve(root, 'CLAUDE.md');\n\n const wrote: string[] = [];\n\n if (existsSync(agentsPath)) {\n console.log('[timber] AGENTS.md already exists — skipping (delete it first to regenerate)');\n } else {\n writeFileSync(agentsPath, agentSkill);\n wrote.push('AGENTS.md');\n }\n\n if (existsSync(claudePath)) {\n console.log('[timber] CLAUDE.md already exists — skipping (delete it first to regenerate)');\n } else {\n try {\n // Relative target so the link survives the project directory moving.\n // The 'file' type argument is required for Windows (ignored elsewhere).\n symlinkSync('AGENTS.md', claudePath, 'file');\n wrote.push('CLAUDE.md (symlink)');\n } catch {\n // Windows without Developer Mode or admin rights can't create symlinks\n // (EPERM) — fall back to a plain pointer file.\n writeFileSync(claudePath, 'Read AGENTS.md for project context and conventions.\\n');\n wrote.push('CLAUDE.md');\n }\n }\n\n if (wrote.length > 0) {\n console.log(\n `[timber] Created ${wrote.join(' and ')} — AI agents can now discover timber.js docs.`\n );\n console.log('[timber] Full documentation: node_modules/@timber-js/app/docs/');\n } else {\n console.log('[timber] Nothing to do — both files already exist.');\n }\n}\n\n// ─── Main Entry Point ────────────────────────────────────────────────────────\n\nasync function main(): Promise<void> {\n const parsed = parseArgs(process.argv.slice(2));\n const options: CommandOptions = { config: parsed.config, project: parsed.project };\n\n switch (parsed.command) {\n case 'dev':\n await runDev(options);\n break;\n case 'build':\n await runBuild(options);\n break;\n case 'preview':\n await runPreview(options);\n break;\n case 'check':\n await runCheck(options);\n break;\n case 'schema':\n await runSchema(parsed.rest);\n break;\n case 'init':\n await runInit();\n break;\n case 'graph': {\n // Lazy import — the graph implementation (and, on a cache miss,\n // Vite + the crawl child) never loads for the other commands.\n const { runGraph } = await import('./analyze/graph-command.ts');\n await runGraph({\n file: parsed.rest[0],\n config: parsed.config,\n json: parsed.json,\n all: parsed.all,\n });\n break;\n }\n }\n}\n\n// Run main when executed as a CLI (not imported in tests).\n// The bin shim (bin/timber.mjs) does `import '../dist/cli.js'`, so\n// process.argv[1] points to the shim, not this file. We check both:\n// direct execution AND being imported by the timber bin shim.\nconst isDirectExecution =\n typeof process !== 'undefined' &&\n process.argv[1] &&\n (import.meta.url.endsWith(process.argv[1]) ||\n process.argv[1].endsWith('bin/timber.mjs') ||\n process.argv[1].endsWith('bin/timber'));\n\nif (isDirectExecution) {\n main().catch((err) => {\n console.error(err.message);\n process.exit(1);\n });\n}\n"],"mappings":";;AAqBA,IAAM,WAAW;CAAC;CAAO;CAAS;CAAW;CAAS;CAAU;CAAQ;AAAO;;;;;;;;;;;;;;;;;;;;;;;;AA8C/E,SAAgB,UAAU,MAA4B;CACpD,IAAI,KAAK,WAAW,GAClB,MAAM,IAAI,MACR,kGACF;CAGF,MAAM,UAAU,KAAK;CACrB,IAAI,CAAC,SAAS,SAAS,OAAkB,GACvC,MAAM,IAAI,MAAM,oBAAoB,QAAQ,wBAAwB,SAAS,KAAK,IAAI,GAAG;CAG3F,IAAI;CACJ,IAAI;CACJ,IAAI,OAAO;CACX,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AAM,CAAC,CAAC;CAC9C,MAAM,UAA0B;EAAE,QAAQ,OAAO;EAAQ,SAAS,OAAO;CAAQ;CAEjF,QAAQ,OAAO,SAAf;EACE,KAAK;GACH,MAAM,OAAO,OAAO;GACpB;EACF,KAAK;GACH,MAAM,SAAS,OAAO;GACtB;EACF,KAAK;GACH,MAAM,WAAW,OAAO;GACxB;EACF,KAAK;GACH,MAAM,SAAS,OAAO;GACtB;EACF,KAAK;GACH,MAAM,UAAU,OAAO,IAAI;GAC3B;EACF,KAAK;GACH,MAAM,QAAQ;GACd;EACF,KAAK,SAAS;GAGZ,MAAM,EAAE,aAAa,MAAM,OAAO;GAClC,MAAM,SAAS;IACb,MAAM,OAAO,KAAK;IAClB,QAAQ,OAAO;IACf,MAAM,OAAO;IACb,KAAK,OAAO;GACd,CAAC;GACD;EACF;CACF;AACF;AAaA,IANE,OAAO,YAAY,eACnB,QAAQ,KAAK,OACZ,YAAY,IAAI,SAAS,QAAQ,KAAK,EAAE,KACvC,QAAQ,KAAK,EAAE,CAAC,SAAS,gBAAgB,KACzC,QAAQ,KAAK,EAAE,CAAC,SAAS,YAAY,IAGvC,KAAK,CAAC,CAAC,OAAO,QAAQ;CACpB,QAAQ,MAAM,IAAI,OAAO;CACzB,QAAQ,KAAK,CAAC;AAChB,CAAC"}
|
|
1
|
+
{"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\n// timber.js CLI\n//\n// Wraps Vite commands with timber-specific behavior.\n// See design/18-build-system.md §\"CLI\".\n//\n// Commands:\n// timber dev — Start Vite dev server with HMR\n// timber build — Run multi-environment build via createBuilder/buildApp\n// timber preview — Serve the production build\n// timber check — Validate types + routes without building\n// timber graph — Classify a file's module environment(s) (design/47)\n\n// Type-only — the implementation is imported dynamically inside runCheck so the\n// CLI's other commands never load the route scanner.\nimport type { CheckDeps } from './cli-check.ts';\nimport type { ResolveViteConfig } from './cli-context.ts';\n\nexport type { CheckDeps };\n\nconst COMMANDS = ['dev', 'build', 'preview', 'check', 'schema', 'init', 'graph'] as const;\ntype Command = (typeof COMMANDS)[number];\n\nexport interface ParsedArgs {\n command: Command;\n config: string | undefined;\n /** `--project`: the tsconfig `timber check` passes to tsgo. */\n project: string | undefined;\n /** `timber graph` only: emit the machine-readable JSON contract. */\n json: boolean;\n /** `timber graph` only: classify the whole project. */\n all: boolean;\n /** Positional arguments after the command (`schema sync`, `graph <file>`). */\n rest: string[];\n}\n\nexport interface CommandOptions {\n /** Path to a Vite config file. Means the same thing for every command. */\n config?: string;\n /** `timber check` only: the tsconfig to type-check. */\n project?: string;\n}\n\n/**\n * Parse CLI arguments into a structured command + options.\n * Accepts: timber <command> [--config|-c <path>] [--project <path>]\n *\n * `--config` names a **Vite** config file for every command, `check` included\n * (TIM-1332): `check` resolves the project through Vite, so a project that\n * builds with `--config ./custom.vite.config.ts` has to be checkable the same\n * way. `--project` names the tsconfig, spelled as tsgo and tsc spell it, and\n * is meaningful only for `check`.\n *\n * Before TIM-1332 `--config` meant the tsconfig for `check` alone — one flag\n * with two meanings, which the docs had to carry a note to explain and which\n * left custom Vite configs unreachable from `check` entirely.\n *\n * Unknown flags are an error, not silently ignored — `timber dev --port 4000`\n * starting on the default port would contradict fail-loudly. The surface stays\n * deliberately small (design/11-platform.md §CLI); port selection goes through\n * the PORT env var or server.port in vite.config.ts.\n *\n * Each subcommand declares its exact flags (the `check --project` precedent,\n * TIM-1332): `graph` additionally accepts a file positional plus `--json` and\n * `--all`, and those two are rejected everywhere else.\n */\nexport function parseArgs(args: string[]): ParsedArgs {\n if (args.length === 0) {\n throw new Error(\n 'No command provided. Usage: timber <dev|build|preview|check|schema|init|graph> [--config <path>]'\n );\n }\n\n const command = args[0];\n if (!COMMANDS.includes(command as Command)) {\n throw new Error(`Unknown command: ${command}. Available commands: ${COMMANDS.join(', ')}`);\n }\n\n let config: string | undefined;\n let project: string | undefined;\n let json = false;\n let all = false;\n const rest: string[] = [];\n for (let i = 1; i < args.length; i++) {\n const arg = args[i];\n if (arg === '--config' || arg === '-c') {\n config = args[++i];\n if (!config) {\n throw new Error('--config requires a path argument');\n }\n } else if (arg === '--json' || arg === '--all') {\n if (command !== 'graph') {\n throw new Error(\n `${arg} is only valid for \\`timber graph\\` (the module-environment query).`\n );\n }\n if (arg === '--json') json = true;\n else all = true;\n } else if (arg === '--project') {\n if (command !== 'check') {\n throw new Error(\n `--project is only valid for \\`timber check\\` (it names the tsconfig to type-check). ` +\n `To point \\`timber ${command}\\` at a different Vite config, use --config <path>.`\n );\n }\n project = args[++i];\n if (!project) {\n throw new Error('--project requires a path argument');\n }\n } else if (arg.startsWith('-')) {\n const portHint =\n arg === '--port' || arg === '-p'\n ? ' To change the port, set the PORT environment variable (PORT=4000 timber dev) ' +\n 'or server.port in vite.config.ts.'\n : '';\n throw new Error(\n `Unknown option: ${arg}. The timber CLI accepts --config <path>` +\n ` (and --project <path> for \\`check\\`).${portHint}`\n );\n } else if (command === 'schema' || command === 'init' || command === 'graph') {\n rest.push(arg);\n } else {\n throw new Error(`Unexpected argument: ${arg}. Usage: timber ${command} [--config <path>]`);\n }\n }\n\n if (command === 'graph' && rest.length > 1) {\n throw new Error(\n `timber graph takes one file. Usage: timber graph <file> [--json], or timber graph --all --json`\n );\n }\n\n return { command: command as Command, config, project, json, all, rest };\n}\n\n// ─── Command Implementations ─────────────────────────────────────────────────\n\n/** @internal Dependency injection for testing. */\nexport interface ViteDeps {\n createServer?: typeof import('vite').createServer;\n createBuilder?: typeof import('vite').createBuilder;\n resolveViteConfig?: ResolveViteConfig;\n}\n\n/**\n * Start the Vite dev server with a supervisor that respawns the process\n * when timber.config.ts changes. Node's require cache for ESM modules\n * loaded via require() cannot be evicted, so an in-process restart\n * serves stale config. The supervisor forks a worker; when the worker\n * exits with RESTART_EXIT_CODE (set by timber-dev-server on config file\n * change), the supervisor spawns a fresh worker with a clean cache.\n *\n * The timber plugin binds the port immediately with a holding page\n * (in rootSync's config hook) so browsers see a \"starting...\" page\n * instead of ERR_CONNECTION_REFUSED during initialization.\n *\n * See design/21-dev-server.md, TIM-665, TIM-1444.\n */\nexport async function runDev(options: CommandOptions, _deps?: ViteDeps): Promise<void> {\n // Worker mode: run the dev server directly (forked by supervisor below)\n if (process.env.__TIMBER_DEV_WORKER) {\n const createServer = _deps?.createServer ?? (await import('vite')).createServer;\n const server = await createServer({\n configFile: options.config,\n });\n await server.listen();\n server.printUrls();\n return;\n }\n\n // Supervisor mode: fork a worker and respawn on config changes.\n const { fork } = await import('node:child_process');\n const { RESTART_EXIT_CODE } = await import('./plugins/dev-server.ts');\n\n // eslint-disable-next-line no-constant-condition\n while (true) {\n const result = await new Promise<{ code: number | null; signal: NodeJS.Signals | null }>(\n (resolve) => {\n const child = fork(process.argv[1], process.argv.slice(2), {\n stdio: 'inherit',\n env: { ...process.env, __TIMBER_DEV_WORKER: '1' },\n });\n\n // Forward signals to the child. SIGINT from Ctrl+C is sent to\n // the entire process group, but a targeted SIGTERM (from a\n // process manager or test teardown) only reaches the parent.\n const onSigint = () => child.kill('SIGINT');\n const onSigterm = () => child.kill('SIGTERM');\n process.on('SIGINT', onSigint);\n process.on('SIGTERM', onSigterm);\n\n child.on('exit', (code, signal) => {\n process.off('SIGINT', onSigint);\n process.off('SIGTERM', onSigterm);\n resolve({ code, signal });\n });\n }\n );\n\n if (result.code === RESTART_EXIT_CODE) {\n continue;\n }\n\n // Child was killed by a signal (e.g. SIGTERM) — re-raise on ourselves\n if (result.signal) {\n process.kill(process.pid, result.signal);\n }\n\n if (result.code != null && result.code !== 0) {\n process.exit(result.code);\n }\n\n break;\n }\n}\n\n/**\n * Run the production build using createBuilder + buildApp.\n * Direct build() calls do NOT trigger the RSC plugin's multi-environment\n * pipeline — createBuilder/buildApp is required.\n */\nexport async function runBuild(options: CommandOptions, _deps?: ViteDeps): Promise<void> {\n const createBuilder = _deps?.createBuilder ?? (await import('vite')).createBuilder;\n const builder = await createBuilder({\n configFile: options.config,\n });\n await builder.buildApp();\n}\n\n/**\n * Serve the production build for local testing.\n * The adapter's preview() serves it; without one, preview fails (TIM-1565).\n * There is no fallback to Vite preview: it would serve the build directory\n * itself — the server bundles as static files, with no root `index.html` —\n * which is useless in either output mode.\n *\n * The project is resolved through Vite, as `timber check` resolves it\n * (`cli-context.ts`), so the adapter, the output mode, and the build\n * directory are the ones `timber build` used — including `--config`, inline\n * `timber({ ... })` options, Vite's `root`, and `build.outDir`, none of which\n * a re-read of `timber.config.ts` can see (TIM-1531). A config file that\n * exists but fails to load throws, naming the file (TIM-1066).\n */\nexport async function runPreview(options: CommandOptions, _deps?: ViteDeps): Promise<void> {\n const { resolveTimberContext } = await import('./cli-context.ts');\n const { adapterConfig, contextAdapter } = await import('./plugin-context.ts');\n\n const ctx = await resolveTimberContext('preview', options.config, _deps?.resolveViteConfig);\n const adapter = contextAdapter(ctx);\n\n if (typeof adapter?.preview !== 'function') {\n const missing = adapter\n ? `The adapter '${adapter.name}' has no preview(), so \\`timber preview\\` cannot serve this build.`\n : `No adapter is configured, so \\`timber preview\\` has nothing to serve this build with.`;\n throw new Error(\n `[timber] ${missing} Use an adapter that implements preview() — ` +\n `cloudflare() from '@timber-js/app/adapters/cloudflare', or nitro() from ` +\n `'@timber-js/app/adapters/nitro' (any preset for a static build; node-server or bun ` +\n `for a server build) — or serve the build with your platform's own tooling.`\n );\n }\n\n await adapter.preview(adapterConfig(ctx), {\n output: ctx.config.output ?? 'server',\n outputDir: ctx.buildDir,\n });\n}\n\n/**\n * Validate routes and types without producing build output.\n *\n * Runs the route pass first — resolve the project through Vite, scan it, fail\n * on proven-fatal convention errors, print warnings, and regenerate the route\n * types — then `tsgo --noEmit`. Codegen has to precede the type pass: the\n * generated `.timber/*.d.ts` files are what type `<Link href>` and\n * `useSegmentParams()`, and a fresh clone has never produced them. See\n * `cli-check.ts` for the full reasoning.\n *\n * `--config` names the **Vite** config, as it does for every other command, so\n * an app that builds with a custom one is checkable the same way.\n * `--project` names the tsconfig handed to tsgo.\n */\nexport async function runCheck(options: CommandOptions, _deps?: CheckDeps): Promise<void> {\n const { checkRoutes, runTypeCheck } = await import('./cli-check.ts');\n const { root } = await checkRoutes({ viteConfigFile: options.config }, _deps);\n // tsgo runs from the root the route pass resolved, not from cwd — that is\n // where it just wrote the declarations tsgo has to read.\n await runTypeCheck({ root, config: options.project }, _deps);\n}\n\n// ─── Schema Subcommand ───────────────────────────────────────────────────────\n\n/**\n * `timber schema sync` — scan filesystem for dynamic segments, diff against\n * app/schema.ts, and append missing entries with type-appropriate codec defaults.\n *\n * See design/41-global-params.md §Auto-Scaffolding\n */\nexport async function runSchema(args: string[]): Promise<void> {\n const subcommand = args[0];\n\n if (subcommand !== 'sync') {\n throw new Error(\n `Unknown schema subcommand: ${subcommand ?? '(none)'}. Usage: timber schema sync`\n );\n }\n\n const { runSchemaSync, defaultCodecForSegment } = await import('./cli-schema-sync.ts');\n const result = runSchemaSync(process.cwd());\n\n if (result.filesystemSegments.length === 0) {\n console.log('[timber] No dynamic segments found in app/.');\n return;\n }\n\n if (result.created) {\n console.log(`[timber] Created app/schema.ts with ${result.addedSegments.length} segment(s):`);\n for (const seg of result.addedSegments) {\n console.log(` + ${seg}: ${defaultCodecForSegment(seg)}`);\n }\n return;\n }\n\n if (result.addedSegments.length === 0 && result.removedSegments.length === 0) {\n console.log('[timber] Schema is up to date — all segments are registered.');\n return;\n }\n\n if (result.addedSegments.length > 0) {\n console.log(`[timber] Added ${result.addedSegments.length} segment(s) to app/schema.ts:`);\n for (const seg of result.addedSegments) {\n console.log(` + ${seg}: ${defaultCodecForSegment(seg)}`);\n }\n }\n\n if (result.removedSegments.length > 0) {\n console.log(\n `[timber] Removed ${result.removedSegments.length} stale segment(s) from app/schema.ts:`\n );\n for (const seg of result.removedSegments) {\n console.log(` - ${seg}`);\n }\n }\n}\n\n// ─── Init Subcommand ─────────────────────────────────────────────────────────\n\n/**\n * `timber init` — write AGENTS.md (and a CLAUDE.md symlink to it) to the\n * project root so AI coding agents can discover timber.js documentation and\n * conventions.\n *\n * The content is read from the installed @timber-js/app package itself, so it\n * stays in sync with the installed version.\n */\nexport async function runInit(): Promise<void> {\n const { readFileSync, writeFileSync, existsSync, symlinkSync } = await import('node:fs');\n const { resolve, dirname } = await import('node:path');\n const { fileURLToPath } = await import('node:url');\n\n const root = process.cwd();\n const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');\n\n const agentSkillPath = resolve(packageRoot, 'agent-skill.md');\n if (!existsSync(agentSkillPath)) {\n throw new Error(\n 'agent-skill.md not found in @timber-js/app package. ' +\n 'This may be a development install — try reinstalling.'\n );\n }\n\n const agentSkill = readFileSync(agentSkillPath, 'utf-8');\n\n const agentsPath = resolve(root, 'AGENTS.md');\n const claudePath = resolve(root, 'CLAUDE.md');\n\n const wrote: string[] = [];\n\n if (existsSync(agentsPath)) {\n console.log('[timber] AGENTS.md already exists — skipping (delete it first to regenerate)');\n } else {\n writeFileSync(agentsPath, agentSkill);\n wrote.push('AGENTS.md');\n }\n\n if (existsSync(claudePath)) {\n console.log('[timber] CLAUDE.md already exists — skipping (delete it first to regenerate)');\n } else {\n try {\n // Relative target so the link survives the project directory moving.\n // The 'file' type argument is required for Windows (ignored elsewhere).\n symlinkSync('AGENTS.md', claudePath, 'file');\n wrote.push('CLAUDE.md (symlink)');\n } catch {\n // Windows without Developer Mode or admin rights can't create symlinks\n // (EPERM) — fall back to a plain pointer file.\n writeFileSync(claudePath, 'Read AGENTS.md for project context and conventions.\\n');\n wrote.push('CLAUDE.md');\n }\n }\n\n if (wrote.length > 0) {\n console.log(\n `[timber] Created ${wrote.join(' and ')} — AI agents can now discover timber.js docs.`\n );\n console.log('[timber] Full documentation: node_modules/@timber-js/app/docs/');\n } else {\n console.log('[timber] Nothing to do — both files already exist.');\n }\n}\n\n// ─── Main Entry Point ────────────────────────────────────────────────────────\n\nasync function main(): Promise<void> {\n const parsed = parseArgs(process.argv.slice(2));\n const options: CommandOptions = { config: parsed.config, project: parsed.project };\n\n switch (parsed.command) {\n case 'dev':\n await runDev(options);\n break;\n case 'build':\n await runBuild(options);\n break;\n case 'preview':\n await runPreview(options);\n break;\n case 'check':\n await runCheck(options);\n break;\n case 'schema':\n await runSchema(parsed.rest);\n break;\n case 'init':\n await runInit();\n break;\n case 'graph': {\n // Lazy import — the graph implementation (and, on a cache miss,\n // Vite + the crawl child) never loads for the other commands.\n const { runGraph } = await import('./analyze/graph-command.ts');\n await runGraph({\n file: parsed.rest[0],\n config: parsed.config,\n json: parsed.json,\n all: parsed.all,\n });\n break;\n }\n }\n}\n\n// Run main when executed as a CLI (not imported in tests).\n// The bin shim (bin/timber.mjs) does `import '../dist/cli.js'`, so\n// process.argv[1] points to the shim, not this file. We check both:\n// direct execution AND being imported by the timber bin shim.\nconst isDirectExecution =\n typeof process !== 'undefined' &&\n process.argv[1] &&\n (import.meta.url.endsWith(process.argv[1]) ||\n process.argv[1].endsWith('bin/timber.mjs') ||\n process.argv[1].endsWith('bin/timber'));\n\nif (isDirectExecution) {\n main().catch((err) => {\n console.error(err.message);\n process.exit(1);\n });\n}\n"],"mappings":";;AAqBA,IAAM,WAAW;CAAC;CAAO;CAAS;CAAW;CAAS;CAAU;CAAQ;AAAO;;;;;;;;;;;;;;;;;;;;;;;;AA8C/E,SAAgB,UAAU,MAA4B;CACpD,IAAI,KAAK,WAAW,GAClB,MAAM,IAAI,MACR,kGACF;CAGF,MAAM,UAAU,KAAK;CACrB,IAAI,CAAC,SAAS,SAAS,OAAkB,GACvC,MAAM,IAAI,MAAM,oBAAoB,QAAQ,wBAAwB,SAAS,KAAK,IAAI,GAAG;CAG3F,IAAI;CACJ,IAAI;CACJ,IAAI,OAAO;CACX,IAAI,MAAM;CACV,MAAM,OAAiB,CAAC;CACxB,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;EACpC,MAAM,MAAM,KAAK;EACjB,IAAI,QAAQ,cAAc,QAAQ,MAAM;GACtC,SAAS,KAAK,EAAE;GAChB,IAAI,CAAC,QACH,MAAM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file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAU,YAAY,EAAE,MAAM,MAAM,CAAC;AA0CjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAa1D,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAQ1D,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAElG;;;;;;;;;;;;GAYG;AAEH,MAAM,WAAW,MAAM;CAAG;AAE1B;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,gBAAgB,GAAG,gBAAgB,CAEvE;AAyGD,wBAAgB,MAAM,CAAC,MAAM,CAAC,EAAE,gBAAgB,GAAG,YAAY,EAAE,CAqXhE;eAEc,MAAM"}
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { a as reportConfigErrors, i as formatMissingPeers, n as timberDevServer, o as validateConfig, r as checkPeerDependencies } from "./_chunks/dev-server-
|
|
1
|
+
import { a as reportConfigErrors, i as formatMissingPeers, n as timberDevServer, o as validateConfig, r as checkPeerDependencies } from "./_chunks/dev-server-B8zsT-ee.js";
|
|
2
2
|
import { i as resolveRenderTimeoutMs } from "./_chunks/render-timeout-DOf_BBcO.js";
|
|
3
3
|
import { t as writeFileAtomic } from "./_chunks/write-file-atomic-D1qWqHb4.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { a as isDynamicMetadataExtension } from "./_chunks/metadata-routes-B3XJNyIH.js";
|
|
5
|
+
import { d as collectInterceptionRewrites, l as getPrerenderExport, n as scanRoutes } from "./_chunks/scanner-Cb3fSjAC.js";
|
|
6
6
|
import { v as swallow } from "./_chunks/logger-CbLdcy-W.js";
|
|
7
|
-
import { c as buildDirToRouteMap, n as formatConventionWarnings, o as flushCodegenWrites, r as lintConventions, s as writeRouteCodegen, t as checkAppDirExists } from "./_chunks/convention-lint-
|
|
7
|
+
import { c as buildDirToRouteMap, n as formatConventionWarnings, o as flushCodegenWrites, r as lintConventions, s as writeRouteCodegen, t as checkAppDirExists } from "./_chunks/convention-lint-ByKJ6aqD.js";
|
|
8
8
|
import { a as loadTimberConfigFile, c as resolveAppDir, d as createNoopTimer, l as resolveBuildDir, n as contextAdapter, o as mergeFileConfig, r as createPluginContext, t as adapterConfig, u as resolveClientJavascript } from "./_chunks/plugin-context-BPBPc3lL.js";
|
|
9
9
|
import { i as withBasePath, n as normalizeBasePath, t as isRelativeBase } from "./_chunks/base-path-DaQrzbez.js";
|
|
10
|
-
import { r as validateSchemaAgainstRoutes, t as collectLeafRoutes } from "./_chunks/walkers-
|
|
10
|
+
import { r as validateSchemaAgainstRoutes, t as collectLeafRoutes } from "./_chunks/walkers-Ber9bamD.js";
|
|
11
11
|
import { i as poisonPillSource, r as markerFor, t as EXPLICIT_MARKERS } from "./_chunks/poison-rules-DoEhbqaY.js";
|
|
12
12
|
import { n as rscPayloadPath, t as RSC_PAYLOAD_DIR } from "./_chunks/rsc-payload-path-dffcs4jp.js";
|
|
13
13
|
import { a as REDIRECTS_FILE, n as detectFsIdentity, o as RESERVED_OUTPUT_PATHS, r as fsKey, t as EXACT_FS_IDENTITY } from "./_chunks/fs-identity-BRKuL215.js";
|
|
@@ -9442,21 +9442,12 @@ function createHoldingServer() {
|
|
|
9442
9442
|
*/
|
|
9443
9443
|
function resolveStartPort(input) {
|
|
9444
9444
|
const defaultPort = input.defaultPort ?? 3e3;
|
|
9445
|
-
if (typeof input.configPort === "number" && Number.isFinite(input.configPort)) return
|
|
9446
|
-
port: input.configPort,
|
|
9447
|
-
explicit: true
|
|
9448
|
-
};
|
|
9445
|
+
if (typeof input.configPort === "number" && Number.isFinite(input.configPort)) return input.configPort;
|
|
9449
9446
|
if (input.envPort != null && input.envPort !== "") {
|
|
9450
9447
|
const parsed = Number(input.envPort);
|
|
9451
|
-
if (Number.isFinite(parsed) && parsed > 0) return
|
|
9452
|
-
port: parsed,
|
|
9453
|
-
explicit: true
|
|
9454
|
-
};
|
|
9448
|
+
if (Number.isFinite(parsed) && parsed > 0) return parsed;
|
|
9455
9449
|
}
|
|
9456
|
-
return
|
|
9457
|
-
port: defaultPort,
|
|
9458
|
-
explicit: false
|
|
9459
|
-
};
|
|
9450
|
+
return defaultPort;
|
|
9460
9451
|
}
|
|
9461
9452
|
//#endregion
|
|
9462
9453
|
//#region src/index.ts
|
|
@@ -9555,6 +9546,7 @@ function timber(config) {
|
|
|
9555
9546
|
name: "timber-root-sync",
|
|
9556
9547
|
api: { getContext: () => ctx },
|
|
9557
9548
|
async config(userConfig, { command, isPreview }) {
|
|
9549
|
+
if (isPreview) throw new Error("[timber] `vite preview` cannot serve a timber build: it would serve the build directory, server bundles included, as static files. Run `timber preview`, which runs your adapter's preview().");
|
|
9558
9550
|
const viteRoot = resolve(userConfig.root ?? process.cwd());
|
|
9559
9551
|
ctx.timer.start("config-load");
|
|
9560
9552
|
const fileConfig = loadTimberConfigFile(viteRoot);
|
|
@@ -9572,29 +9564,19 @@ function timber(config) {
|
|
|
9572
9564
|
if (hasCompilerInReloaded && !hadCompilerInEarly) console.warn("[timber] reactCompiler is set in timber.config.ts but could not be registered because the config file is in a non-cwd root directory. Move reactCompiler to the inline timber() config in vite.config.ts, or run vite from the project root directory.");
|
|
9573
9565
|
}
|
|
9574
9566
|
let resolvedDevPort = null;
|
|
9575
|
-
let resolvedDevPortExplicit = false;
|
|
9576
9567
|
const isMiddlewareMode = Boolean(userConfig.server?.middlewareMode);
|
|
9577
9568
|
const resolvedHost = typeof userConfig.server?.host === "string" ? userConfig.server.host : userConfig.server?.host === true ? void 0 : "localhost";
|
|
9578
|
-
if (command === "serve" && !
|
|
9579
|
-
|
|
9569
|
+
if (command === "serve" && !isMiddlewareMode) {
|
|
9570
|
+
resolvedDevPort = resolveStartPort({
|
|
9580
9571
|
configPort: userConfig.server?.port,
|
|
9581
9572
|
envPort: process.env.PORT
|
|
9582
9573
|
});
|
|
9583
|
-
resolvedDevPort
|
|
9584
|
-
resolvedDevPortExplicit = userConfig.server?.strictPort ?? false;
|
|
9585
|
-
if (start.port !== 0) {
|
|
9574
|
+
if (resolvedDevPort !== 0) {
|
|
9586
9575
|
ctx.holdingServer = createHoldingServer();
|
|
9587
|
-
await ctx.holdingServer.listen(
|
|
9576
|
+
await ctx.holdingServer.listen(resolvedDevPort, resolvedHost).catch(() => {
|
|
9588
9577
|
ctx.holdingServer = null;
|
|
9589
9578
|
});
|
|
9590
9579
|
}
|
|
9591
|
-
} else if (command === "serve" && isPreview) {
|
|
9592
|
-
const start = resolveStartPort({
|
|
9593
|
-
configPort: typeof userConfig.preview?.port === "number" ? userConfig.preview.port : typeof userConfig.server?.port === "number" ? userConfig.server.port : void 0,
|
|
9594
|
-
envPort: process.env.PORT
|
|
9595
|
-
});
|
|
9596
|
-
resolvedDevPort = start.port;
|
|
9597
|
-
resolvedDevPortExplicit = start.explicit;
|
|
9598
9580
|
}
|
|
9599
9581
|
const buildOutDir = relative(resolvedRoot, buildDir);
|
|
9600
9582
|
const envOutDirs = {};
|
|
@@ -9620,41 +9602,34 @@ function timber(config) {
|
|
|
9620
9602
|
oxc: { jsx: { development: false } }
|
|
9621
9603
|
};
|
|
9622
9604
|
const serverConfig = {};
|
|
9623
|
-
const previewConfig = {};
|
|
9624
9605
|
if (resolvedDevPort != null) {
|
|
9625
|
-
|
|
9626
|
-
|
|
9627
|
-
serverConfig.strictPort = resolvedDevPortExplicit;
|
|
9628
|
-
}
|
|
9629
|
-
previewConfig.port = resolvedDevPort;
|
|
9630
|
-
previewConfig.strictPort = resolvedDevPortExplicit;
|
|
9606
|
+
serverConfig.port = resolvedDevPort;
|
|
9607
|
+
serverConfig.strictPort = userConfig.server?.strictPort ?? false;
|
|
9631
9608
|
}
|
|
9632
9609
|
serverConfig.forwardConsole = resolveForwardConsole(ctx.config.devBrowserLogs);
|
|
9633
9610
|
const customLogger = userConfig.customLogger ? wrapLoggerWithOriginalConsole(userConfig.customLogger) : createLogger(userConfig.logLevel ?? "info", {
|
|
9634
9611
|
allowClearScreen: userConfig.clearScreen ?? true,
|
|
9635
9612
|
console: originalConsole
|
|
9636
9613
|
});
|
|
9637
|
-
|
|
9638
|
-
|
|
9639
|
-
|
|
9640
|
-
|
|
9641
|
-
|
|
9642
|
-
|
|
9643
|
-
environments
|
|
9614
|
+
ctx.timer.start("client-deps-scan");
|
|
9615
|
+
const { clientOptimizeDepsEntries, skipUseServerScanPlugin } = await import("./_chunks/client-dep-entries-BOkpKjj1.js");
|
|
9616
|
+
const entries = await clientOptimizeDepsEntries(resolvedRoot, BROWSER_ENTRY_FILE, buildDir);
|
|
9617
|
+
ctx.timer.end("client-deps-scan");
|
|
9618
|
+
return {
|
|
9619
|
+
build: { outDir: buildOutDir },
|
|
9620
|
+
environments: {
|
|
9644
9621
|
...envOutDirs,
|
|
9645
9622
|
client: {
|
|
9646
9623
|
...envOutDirs.client,
|
|
9647
|
-
optimizeDeps: {
|
|
9624
|
+
optimizeDeps: {
|
|
9625
|
+
entries,
|
|
9626
|
+
rolldownOptions: { plugins: [skipUseServerScanPlugin()] }
|
|
9627
|
+
}
|
|
9648
9628
|
}
|
|
9649
|
-
}
|
|
9650
|
-
}
|
|
9651
|
-
return {
|
|
9652
|
-
build: { outDir: buildOutDir },
|
|
9653
|
-
environments,
|
|
9629
|
+
},
|
|
9654
9630
|
optimizeDeps: { exclude: timberOptimizeDepsExclude },
|
|
9655
9631
|
customLogger,
|
|
9656
|
-
server: serverConfig
|
|
9657
|
-
preview: previewConfig
|
|
9632
|
+
server: serverConfig
|
|
9658
9633
|
};
|
|
9659
9634
|
},
|
|
9660
9635
|
configResolved(resolved) {
|