@timber-js/app 0.2.0-alpha.10 → 0.2.0-alpha.100

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.
Files changed (722) hide show
  1. package/LICENSE +8 -0
  2. package/dist/_chunks/actions-CQ8Z8VGL.js +1061 -0
  3. package/dist/_chunks/actions-CQ8Z8VGL.js.map +1 -0
  4. package/dist/_chunks/build-output-helper-DXnW0qjz.js +61 -0
  5. package/dist/_chunks/build-output-helper-DXnW0qjz.js.map +1 -0
  6. package/dist/_chunks/chunk-BYIpzuS7.js +39 -0
  7. package/dist/_chunks/define-B-Q_UMOD.js +195 -0
  8. package/dist/_chunks/define-B-Q_UMOD.js.map +1 -0
  9. package/dist/_chunks/define-CfBPoJb0.js +123 -0
  10. package/dist/_chunks/define-CfBPoJb0.js.map +1 -0
  11. package/dist/_chunks/define-cookie-BjpIt4UC.js +194 -0
  12. package/dist/_chunks/define-cookie-BjpIt4UC.js.map +1 -0
  13. package/dist/_chunks/format-Bcn-Iv1x.js +14 -0
  14. package/dist/_chunks/format-Bcn-Iv1x.js.map +1 -0
  15. package/dist/_chunks/handler-store-B-lqaGyh.js +54 -0
  16. package/dist/_chunks/handler-store-B-lqaGyh.js.map +1 -0
  17. package/dist/_chunks/logger-0m8MsKdc.js +291 -0
  18. package/dist/_chunks/logger-0m8MsKdc.js.map +1 -0
  19. package/dist/_chunks/merge-search-params-BphMdht_.js +122 -0
  20. package/dist/_chunks/merge-search-params-BphMdht_.js.map +1 -0
  21. package/dist/_chunks/{metadata-routes-Cjmvi3rQ.js → metadata-routes-BU684ls2.js} +1 -1
  22. package/dist/_chunks/{metadata-routes-Cjmvi3rQ.js.map → metadata-routes-BU684ls2.js.map} +1 -1
  23. package/dist/_chunks/navigation-root-BCYczjml.js +96 -0
  24. package/dist/_chunks/navigation-root-BCYczjml.js.map +1 -0
  25. package/dist/_chunks/registry-I2ss-lvy.js +20 -0
  26. package/dist/_chunks/registry-I2ss-lvy.js.map +1 -0
  27. package/dist/_chunks/router-ref-h3-UaCQv.js +28 -0
  28. package/dist/_chunks/router-ref-h3-UaCQv.js.map +1 -0
  29. package/dist/_chunks/schema-bridge-Cxu4l-7p.js +86 -0
  30. package/dist/_chunks/schema-bridge-Cxu4l-7p.js.map +1 -0
  31. package/dist/_chunks/segment-classify-BjfuctV2.js +137 -0
  32. package/dist/_chunks/segment-classify-BjfuctV2.js.map +1 -0
  33. package/dist/_chunks/segment-context-Dx_OizxD.js +34 -0
  34. package/dist/_chunks/segment-context-Dx_OizxD.js.map +1 -0
  35. package/dist/_chunks/{ssr-data-MjmprTmO.js → ssr-data-B4CdH7rE.js} +1 -1
  36. package/dist/_chunks/ssr-data-B4CdH7rE.js.map +1 -0
  37. package/dist/_chunks/stale-reload-Bab885FO.js +64 -0
  38. package/dist/_chunks/stale-reload-Bab885FO.js.map +1 -0
  39. package/dist/_chunks/tracing-C8V-YGsP.js +329 -0
  40. package/dist/_chunks/tracing-C8V-YGsP.js.map +1 -0
  41. package/dist/_chunks/{use-query-states-D5KaffOK.js → use-query-states-B2XTqxDR.js} +7 -20
  42. package/dist/_chunks/use-query-states-B2XTqxDR.js.map +1 -0
  43. package/dist/_chunks/use-segment-params-BkpKAQ7D.js +185 -0
  44. package/dist/_chunks/use-segment-params-BkpKAQ7D.js.map +1 -0
  45. package/dist/_chunks/walkers-Tg0Alwcg.js +850 -0
  46. package/dist/_chunks/walkers-Tg0Alwcg.js.map +1 -0
  47. package/dist/_chunks/{format-DviM89f0.js → warnings-Cg47l5sk.js} +6 -45
  48. package/dist/_chunks/warnings-Cg47l5sk.js.map +1 -0
  49. package/dist/adapters/build-output-helper.d.ts +28 -0
  50. package/dist/adapters/build-output-helper.d.ts.map +1 -0
  51. package/dist/adapters/cloudflare-dev.d.ts +109 -0
  52. package/dist/adapters/cloudflare-dev.d.ts.map +1 -0
  53. package/dist/adapters/cloudflare-dev.js +73 -0
  54. package/dist/adapters/cloudflare-dev.js.map +1 -0
  55. package/dist/adapters/cloudflare-kv-cache.d.ts +64 -0
  56. package/dist/adapters/cloudflare-kv-cache.d.ts.map +1 -0
  57. package/dist/adapters/cloudflare-kv-cache.js +95 -0
  58. package/dist/adapters/cloudflare-kv-cache.js.map +1 -0
  59. package/dist/adapters/cloudflare.d.ts +148 -12
  60. package/dist/adapters/cloudflare.d.ts.map +1 -1
  61. package/dist/adapters/cloudflare.js +142 -38
  62. package/dist/adapters/cloudflare.js.map +1 -1
  63. package/dist/adapters/compress-module.d.ts.map +1 -1
  64. package/dist/adapters/nitro.d.ts +17 -1
  65. package/dist/adapters/nitro.d.ts.map +1 -1
  66. package/dist/adapters/nitro.js +143 -45
  67. package/dist/adapters/nitro.js.map +1 -1
  68. package/dist/adapters/shared.d.ts +16 -0
  69. package/dist/adapters/shared.d.ts.map +1 -0
  70. package/dist/cache/cache-api.d.ts +24 -0
  71. package/dist/cache/cache-api.d.ts.map +1 -0
  72. package/dist/cache/handler-store.d.ts +31 -0
  73. package/dist/cache/handler-store.d.ts.map +1 -0
  74. package/dist/cache/index.d.ts +23 -7
  75. package/dist/cache/index.d.ts.map +1 -1
  76. package/dist/cache/index.js +150 -81
  77. package/dist/cache/index.js.map +1 -1
  78. package/dist/cache/singleflight.d.ts +18 -1
  79. package/dist/cache/singleflight.d.ts.map +1 -1
  80. package/dist/cache/sizeof.d.ts +22 -0
  81. package/dist/cache/sizeof.d.ts.map +1 -0
  82. package/dist/cache/timber-cache.d.ts +1 -1
  83. package/dist/cache/timber-cache.d.ts.map +1 -1
  84. package/dist/cli.d.ts +6 -1
  85. package/dist/cli.d.ts.map +1 -1
  86. package/dist/cli.js +8 -3
  87. package/dist/cli.js.map +1 -1
  88. package/dist/client/browser-dev.d.ts +34 -1
  89. package/dist/client/browser-dev.d.ts.map +1 -1
  90. package/dist/client/browser-entry/action-dispatch.d.ts +17 -0
  91. package/dist/client/browser-entry/action-dispatch.d.ts.map +1 -0
  92. package/dist/client/browser-entry/hmr.d.ts +21 -0
  93. package/dist/client/browser-entry/hmr.d.ts.map +1 -0
  94. package/dist/client/browser-entry/hydrate.d.ts +46 -0
  95. package/dist/client/browser-entry/hydrate.d.ts.map +1 -0
  96. package/dist/client/browser-entry/index.d.ts +30 -0
  97. package/dist/client/browser-entry/index.d.ts.map +1 -0
  98. package/dist/client/browser-entry/post-hydration.d.ts +26 -0
  99. package/dist/client/browser-entry/post-hydration.d.ts.map +1 -0
  100. package/dist/client/browser-entry/router-init.d.ts +23 -0
  101. package/dist/client/browser-entry/router-init.d.ts.map +1 -0
  102. package/dist/client/browser-entry/rsc-stream.d.ts +24 -0
  103. package/dist/client/browser-entry/rsc-stream.d.ts.map +1 -0
  104. package/dist/client/browser-entry/scroll.d.ts +19 -0
  105. package/dist/client/browser-entry/scroll.d.ts.map +1 -0
  106. package/dist/client/error-boundary.d.ts +12 -5
  107. package/dist/client/error-boundary.d.ts.map +1 -1
  108. package/dist/client/error-boundary.js +26 -5
  109. package/dist/client/error-boundary.js.map +1 -1
  110. package/dist/client/error-reconstituter.d.ts +54 -0
  111. package/dist/client/error-reconstituter.d.ts.map +1 -0
  112. package/dist/client/form.d.ts +16 -27
  113. package/dist/client/form.d.ts.map +1 -1
  114. package/dist/client/history.d.ts +19 -4
  115. package/dist/client/history.d.ts.map +1 -1
  116. package/dist/client/index.d.ts +9 -24
  117. package/dist/client/index.d.ts.map +1 -1
  118. package/dist/client/index.js +261 -1100
  119. package/dist/client/index.js.map +1 -1
  120. package/dist/client/internal.d.ts +19 -0
  121. package/dist/client/internal.d.ts.map +1 -0
  122. package/dist/client/internal.js +964 -0
  123. package/dist/client/internal.js.map +1 -0
  124. package/dist/client/link-pending-store.d.ts +63 -0
  125. package/dist/client/link-pending-store.d.ts.map +1 -0
  126. package/dist/client/link.d.ts +62 -55
  127. package/dist/client/link.d.ts.map +1 -1
  128. package/dist/client/nav-link-store.d.ts +36 -0
  129. package/dist/client/nav-link-store.d.ts.map +1 -0
  130. package/dist/client/navigation-api-types.d.ts +90 -0
  131. package/dist/client/navigation-api-types.d.ts.map +1 -0
  132. package/dist/client/navigation-api.d.ts +115 -0
  133. package/dist/client/navigation-api.d.ts.map +1 -0
  134. package/dist/client/navigation-context.d.ts +13 -2
  135. package/dist/client/navigation-context.d.ts.map +1 -1
  136. package/dist/client/{transition-root.d.ts → navigation-root.d.ts} +42 -8
  137. package/dist/client/navigation-root.d.ts.map +1 -0
  138. package/dist/client/nuqs-adapter.d.ts.map +1 -1
  139. package/dist/client/router-ref.d.ts +1 -1
  140. package/dist/client/router.d.ts +70 -4
  141. package/dist/client/router.d.ts.map +1 -1
  142. package/dist/client/rsc-fetch.d.ts +38 -3
  143. package/dist/client/rsc-fetch.d.ts.map +1 -1
  144. package/dist/client/segment-cache.d.ts +1 -1
  145. package/dist/client/segment-cache.d.ts.map +1 -1
  146. package/dist/client/segment-outlet.d.ts +63 -0
  147. package/dist/client/segment-outlet.d.ts.map +1 -0
  148. package/dist/client/ssr-data.d.ts +13 -4
  149. package/dist/client/ssr-data.d.ts.map +1 -1
  150. package/dist/client/stale-reload.d.ts +15 -0
  151. package/dist/client/stale-reload.d.ts.map +1 -1
  152. package/dist/client/state.d.ts +1 -1
  153. package/dist/client/top-loader.d.ts +5 -5
  154. package/dist/client/top-loader.d.ts.map +1 -1
  155. package/dist/client/use-cookie.d.ts +8 -0
  156. package/dist/client/use-cookie.d.ts.map +1 -1
  157. package/dist/client/use-link-status.d.ts +5 -5
  158. package/dist/client/use-link-status.d.ts.map +1 -1
  159. package/dist/client/{use-navigation-pending.d.ts → use-pending-navigation.d.ts} +4 -4
  160. package/dist/client/use-pending-navigation.d.ts.map +1 -0
  161. package/dist/client/use-query-states.d.ts +1 -1
  162. package/dist/client/use-query-states.d.ts.map +1 -1
  163. package/dist/client/use-router.d.ts +1 -1
  164. package/dist/client/{use-params.d.ts → use-segment-params.d.ts} +7 -5
  165. package/dist/client/use-segment-params.d.ts.map +1 -0
  166. package/dist/codec.d.ts +33 -0
  167. package/dist/codec.d.ts.map +1 -0
  168. package/dist/codec.js +2 -0
  169. package/dist/config-types.d.ts +294 -0
  170. package/dist/config-types.d.ts.map +1 -0
  171. package/dist/config-validation.d.ts +51 -0
  172. package/dist/config-validation.d.ts.map +1 -0
  173. package/dist/content/index.d.ts +1 -10
  174. package/dist/content/index.d.ts.map +1 -1
  175. package/dist/content/index.js +0 -2
  176. package/dist/cookies/define-cookie.d.ts +98 -25
  177. package/dist/cookies/define-cookie.d.ts.map +1 -1
  178. package/dist/cookies/index.d.ts +2 -1
  179. package/dist/cookies/index.d.ts.map +1 -1
  180. package/dist/cookies/index.js +36 -72
  181. package/dist/cookies/index.js.map +1 -1
  182. package/dist/cookies/json-cookie.d.ts +64 -0
  183. package/dist/cookies/json-cookie.d.ts.map +1 -0
  184. package/dist/cookies/validation.d.ts +46 -0
  185. package/dist/cookies/validation.d.ts.map +1 -0
  186. package/dist/dev-tools/404-page.d.ts +46 -0
  187. package/dist/dev-tools/404-page.d.ts.map +1 -0
  188. package/dist/dev-tools/browser-logs.d.ts +84 -0
  189. package/dist/dev-tools/browser-logs.d.ts.map +1 -0
  190. package/dist/dev-tools/error-page.d.ts +58 -0
  191. package/dist/dev-tools/error-page.d.ts.map +1 -0
  192. package/dist/dev-tools/holding-server.d.ts +54 -0
  193. package/dist/dev-tools/holding-server.d.ts.map +1 -0
  194. package/dist/dev-tools/index.d.ts +31 -0
  195. package/dist/dev-tools/index.d.ts.map +1 -0
  196. package/dist/{server/dev-span-processor.d.ts → dev-tools/instrumentation.d.ts} +26 -6
  197. package/dist/dev-tools/instrumentation.d.ts.map +1 -0
  198. package/dist/{server/dev-logger.d.ts → dev-tools/logger.d.ts} +1 -1
  199. package/dist/dev-tools/logger.d.ts.map +1 -0
  200. package/dist/{plugins/dev-logs.d.ts → dev-tools/logs.d.ts} +2 -2
  201. package/dist/dev-tools/logs.d.ts.map +1 -0
  202. package/dist/dev-tools/overlay.d.ts +91 -0
  203. package/dist/dev-tools/overlay.d.ts.map +1 -0
  204. package/dist/dev-tools/stack-classifier.d.ts +34 -0
  205. package/dist/dev-tools/stack-classifier.d.ts.map +1 -0
  206. package/dist/dev-tools/terminal.d.ts +28 -0
  207. package/dist/dev-tools/terminal.d.ts.map +1 -0
  208. package/dist/{server/dev-warnings.d.ts → dev-tools/warnings.d.ts} +2 -22
  209. package/dist/dev-tools/warnings.d.ts.map +1 -0
  210. package/dist/fonts/bundle.d.ts +48 -0
  211. package/dist/fonts/bundle.d.ts.map +1 -0
  212. package/dist/fonts/css.d.ts +1 -0
  213. package/dist/fonts/css.d.ts.map +1 -1
  214. package/dist/fonts/dev-middleware.d.ts +22 -0
  215. package/dist/fonts/dev-middleware.d.ts.map +1 -0
  216. package/dist/fonts/pipeline.d.ts +167 -0
  217. package/dist/fonts/pipeline.d.ts.map +1 -0
  218. package/dist/fonts/transform.d.ts +64 -0
  219. package/dist/fonts/transform.d.ts.map +1 -0
  220. package/dist/fonts/types.d.ts +45 -1
  221. package/dist/fonts/types.d.ts.map +1 -1
  222. package/dist/fonts/virtual-modules.d.ts +103 -0
  223. package/dist/fonts/virtual-modules.d.ts.map +1 -0
  224. package/dist/index.d.ts +46 -190
  225. package/dist/index.d.ts.map +1 -1
  226. package/dist/index.js +14569 -12451
  227. package/dist/index.js.map +1 -1
  228. package/dist/plugin-context.d.ts +107 -0
  229. package/dist/plugin-context.d.ts.map +1 -0
  230. package/dist/plugins/adapter-build.d.ts +1 -1
  231. package/dist/plugins/adapter-build.d.ts.map +1 -1
  232. package/dist/plugins/build-manifest.d.ts +2 -2
  233. package/dist/plugins/build-manifest.d.ts.map +1 -1
  234. package/dist/plugins/build-report.d.ts +9 -7
  235. package/dist/plugins/build-report.d.ts.map +1 -1
  236. package/dist/plugins/client-chunks.d.ts +32 -0
  237. package/dist/plugins/client-chunks.d.ts.map +1 -0
  238. package/dist/plugins/content.d.ts +1 -1
  239. package/dist/plugins/content.d.ts.map +1 -1
  240. package/dist/plugins/dev-server.d.ts +1 -1
  241. package/dist/plugins/dev-server.d.ts.map +1 -1
  242. package/dist/plugins/entries.d.ts +1 -1
  243. package/dist/plugins/entries.d.ts.map +1 -1
  244. package/dist/plugins/fonts.d.ts +17 -73
  245. package/dist/plugins/fonts.d.ts.map +1 -1
  246. package/dist/plugins/mdx.d.ts +1 -1
  247. package/dist/plugins/mdx.d.ts.map +1 -1
  248. package/dist/plugins/routing.d.ts +1 -1
  249. package/dist/plugins/routing.d.ts.map +1 -1
  250. package/dist/plugins/server-bundle.d.ts.map +1 -1
  251. package/dist/plugins/shims.d.ts +6 -5
  252. package/dist/plugins/shims.d.ts.map +1 -1
  253. package/dist/plugins/static-build.d.ts +4 -4
  254. package/dist/plugins/static-build.d.ts.map +1 -1
  255. package/dist/routing/codegen-shared.d.ts +55 -0
  256. package/dist/routing/codegen-shared.d.ts.map +1 -0
  257. package/dist/routing/codegen-types.d.ts +52 -0
  258. package/dist/routing/codegen-types.d.ts.map +1 -0
  259. package/dist/routing/codegen.d.ts +2 -2
  260. package/dist/routing/codegen.d.ts.map +1 -1
  261. package/dist/routing/convention-lint.d.ts +41 -0
  262. package/dist/routing/convention-lint.d.ts.map +1 -0
  263. package/dist/routing/index.d.ts +5 -1
  264. package/dist/routing/index.d.ts.map +1 -1
  265. package/dist/routing/index.js +3 -2
  266. package/dist/routing/link-codegen.d.ts +90 -0
  267. package/dist/routing/link-codegen.d.ts.map +1 -0
  268. package/dist/routing/scanner.d.ts +1 -10
  269. package/dist/routing/scanner.d.ts.map +1 -1
  270. package/dist/routing/segment-classify.d.ts +75 -0
  271. package/dist/routing/segment-classify.d.ts.map +1 -0
  272. package/dist/routing/status-file-lint.d.ts +2 -1
  273. package/dist/routing/status-file-lint.d.ts.map +1 -1
  274. package/dist/routing/types.d.ts +77 -25
  275. package/dist/routing/types.d.ts.map +1 -1
  276. package/dist/routing/walkers.d.ts +51 -0
  277. package/dist/routing/walkers.d.ts.map +1 -0
  278. package/dist/rsc-runtime/rsc.d.ts +1 -1
  279. package/dist/rsc-runtime/rsc.d.ts.map +1 -1
  280. package/dist/rsc-runtime/ssr.d.ts +12 -0
  281. package/dist/rsc-runtime/ssr.d.ts.map +1 -1
  282. package/dist/schema-bridge.d.ts +76 -0
  283. package/dist/schema-bridge.d.ts.map +1 -0
  284. package/dist/search-params/define.d.ts +157 -0
  285. package/dist/search-params/define.d.ts.map +1 -0
  286. package/dist/search-params/index.d.ts +4 -7
  287. package/dist/search-params/index.d.ts.map +1 -1
  288. package/dist/search-params/index.js +34 -441
  289. package/dist/search-params/index.js.map +1 -1
  290. package/dist/search-params/registry.d.ts +2 -2
  291. package/dist/search-params/registry.d.ts.map +1 -1
  292. package/dist/search-params/wrappers.d.ts +53 -0
  293. package/dist/search-params/wrappers.d.ts.map +1 -0
  294. package/dist/segment-params/define.d.ts +95 -0
  295. package/dist/segment-params/define.d.ts.map +1 -0
  296. package/dist/segment-params/index.d.ts +3 -0
  297. package/dist/segment-params/index.d.ts.map +1 -0
  298. package/dist/segment-params/index.js +2 -0
  299. package/dist/server/access-gate.d.ts +8 -3
  300. package/dist/server/access-gate.d.ts.map +1 -1
  301. package/dist/server/action-client.d.ts +41 -6
  302. package/dist/server/action-client.d.ts.map +1 -1
  303. package/dist/server/action-encryption.d.ts +76 -0
  304. package/dist/server/action-encryption.d.ts.map +1 -0
  305. package/dist/server/action-handler.d.ts +35 -1
  306. package/dist/server/action-handler.d.ts.map +1 -1
  307. package/dist/server/actions.d.ts +3 -6
  308. package/dist/server/actions.d.ts.map +1 -1
  309. package/dist/server/als-registry.d.ts +33 -5
  310. package/dist/server/als-registry.d.ts.map +1 -1
  311. package/dist/server/asset-headers.d.ts +1 -15
  312. package/dist/server/asset-headers.d.ts.map +1 -1
  313. package/dist/server/build-manifest.d.ts +2 -2
  314. package/dist/server/build-manifest.d.ts.map +1 -1
  315. package/dist/server/cookie-context.d.ts +170 -0
  316. package/dist/server/cookie-context.d.ts.map +1 -0
  317. package/dist/server/cookie-parsing.d.ts +51 -0
  318. package/dist/server/cookie-parsing.d.ts.map +1 -0
  319. package/dist/server/debug.d.ts +1 -1
  320. package/dist/server/default-logger.d.ts +22 -0
  321. package/dist/server/default-logger.d.ts.map +1 -0
  322. package/dist/server/deny-boundary.d.ts +90 -0
  323. package/dist/server/deny-boundary.d.ts.map +1 -0
  324. package/dist/server/deny-renderer.d.ts.map +1 -1
  325. package/dist/server/dev-source-map.d.ts +22 -0
  326. package/dist/server/dev-source-map.d.ts.map +1 -0
  327. package/dist/server/early-hints-sender.d.ts.map +1 -1
  328. package/dist/server/early-hints.d.ts +13 -5
  329. package/dist/server/early-hints.d.ts.map +1 -1
  330. package/dist/server/error-boundary-wrapper.d.ts +7 -1
  331. package/dist/server/error-boundary-wrapper.d.ts.map +1 -1
  332. package/dist/server/fallback-error.d.ts +12 -7
  333. package/dist/server/fallback-error.d.ts.map +1 -1
  334. package/dist/server/flight-injection-state.d.ts +66 -0
  335. package/dist/server/flight-injection-state.d.ts.map +1 -0
  336. package/dist/server/flight-scripts.d.ts +42 -0
  337. package/dist/server/flight-scripts.d.ts.map +1 -0
  338. package/dist/server/flush.d.ts.map +1 -1
  339. package/dist/server/form-data.d.ts +29 -0
  340. package/dist/server/form-data.d.ts.map +1 -1
  341. package/dist/server/html-injector-core.d.ts +212 -0
  342. package/dist/server/html-injector-core.d.ts.map +1 -0
  343. package/dist/server/html-injectors.d.ts +81 -41
  344. package/dist/server/html-injectors.d.ts.map +1 -1
  345. package/dist/server/index.d.ts +9 -46
  346. package/dist/server/index.d.ts.map +1 -1
  347. package/dist/server/index.js +155 -2905
  348. package/dist/server/index.js.map +1 -1
  349. package/dist/server/internal.d.ts +48 -0
  350. package/dist/server/internal.d.ts.map +1 -0
  351. package/dist/server/internal.js +2900 -0
  352. package/dist/server/internal.js.map +1 -0
  353. package/dist/server/logger.d.ts +39 -7
  354. package/dist/server/logger.d.ts.map +1 -1
  355. package/dist/server/middleware-runner.d.ts +36 -4
  356. package/dist/server/middleware-runner.d.ts.map +1 -1
  357. package/dist/server/node-stream-transforms.d.ts +110 -0
  358. package/dist/server/node-stream-transforms.d.ts.map +1 -0
  359. package/dist/server/param-coercion.d.ts +26 -0
  360. package/dist/server/param-coercion.d.ts.map +1 -0
  361. package/dist/server/pipeline-helpers.d.ts +95 -0
  362. package/dist/server/pipeline-helpers.d.ts.map +1 -0
  363. package/dist/server/pipeline-interception.d.ts +1 -1
  364. package/dist/server/pipeline-interception.d.ts.map +1 -1
  365. package/dist/server/pipeline-metadata.d.ts +6 -0
  366. package/dist/server/pipeline-metadata.d.ts.map +1 -1
  367. package/dist/server/pipeline-outcome.d.ts +49 -0
  368. package/dist/server/pipeline-outcome.d.ts.map +1 -0
  369. package/dist/server/pipeline-phases.d.ts +52 -0
  370. package/dist/server/pipeline-phases.d.ts.map +1 -0
  371. package/dist/server/pipeline.d.ts +93 -23
  372. package/dist/server/pipeline.d.ts.map +1 -1
  373. package/dist/server/port-resolution.d.ts +117 -0
  374. package/dist/server/port-resolution.d.ts.map +1 -0
  375. package/dist/server/primitives.d.ts +69 -18
  376. package/dist/server/primitives.d.ts.map +1 -1
  377. package/dist/server/render-timeout.d.ts +51 -0
  378. package/dist/server/render-timeout.d.ts.map +1 -0
  379. package/dist/server/request-context.d.ts +41 -109
  380. package/dist/server/request-context.d.ts.map +1 -1
  381. package/dist/server/route-element-builder.d.ts +27 -1
  382. package/dist/server/route-element-builder.d.ts.map +1 -1
  383. package/dist/server/route-handler.d.ts.map +1 -1
  384. package/dist/server/route-matcher.d.ts +21 -34
  385. package/dist/server/route-matcher.d.ts.map +1 -1
  386. package/dist/server/rsc-entry/action-middleware-runner.d.ts +66 -0
  387. package/dist/server/rsc-entry/action-middleware-runner.d.ts.map +1 -0
  388. package/dist/server/rsc-entry/api-handler.d.ts +2 -2
  389. package/dist/server/rsc-entry/api-handler.d.ts.map +1 -1
  390. package/dist/server/rsc-entry/error-renderer.d.ts +26 -13
  391. package/dist/server/rsc-entry/error-renderer.d.ts.map +1 -1
  392. package/dist/server/rsc-entry/helpers.d.ts +49 -6
  393. package/dist/server/rsc-entry/helpers.d.ts.map +1 -1
  394. package/dist/server/rsc-entry/index.d.ts +20 -3
  395. package/dist/server/rsc-entry/index.d.ts.map +1 -1
  396. package/dist/server/rsc-entry/render-route.d.ts +50 -0
  397. package/dist/server/rsc-entry/render-route.d.ts.map +1 -0
  398. package/dist/server/rsc-entry/rsc-payload.d.ts +3 -3
  399. package/dist/server/rsc-entry/rsc-payload.d.ts.map +1 -1
  400. package/dist/server/rsc-entry/rsc-stream.d.ts +14 -1
  401. package/dist/server/rsc-entry/rsc-stream.d.ts.map +1 -1
  402. package/dist/server/rsc-entry/ssr-bridge.d.ts +1 -1
  403. package/dist/server/rsc-entry/ssr-bridge.d.ts.map +1 -1
  404. package/dist/server/rsc-entry/ssr-renderer.d.ts +19 -4
  405. package/dist/server/rsc-entry/ssr-renderer.d.ts.map +1 -1
  406. package/dist/server/rsc-entry/wrap-action-dispatch.d.ts +119 -0
  407. package/dist/server/rsc-entry/wrap-action-dispatch.d.ts.map +1 -0
  408. package/dist/server/safe-load.d.ts +46 -0
  409. package/dist/server/safe-load.d.ts.map +1 -0
  410. package/dist/server/sensitive-fields.d.ts +74 -0
  411. package/dist/server/sensitive-fields.d.ts.map +1 -0
  412. package/dist/server/sitemap-generator.d.ts +129 -0
  413. package/dist/server/sitemap-generator.d.ts.map +1 -0
  414. package/dist/server/sitemap-handler.d.ts +22 -0
  415. package/dist/server/sitemap-handler.d.ts.map +1 -0
  416. package/dist/server/slot-resolver.d.ts +1 -1
  417. package/dist/server/slot-resolver.d.ts.map +1 -1
  418. package/dist/server/ssr-entry.d.ts +23 -0
  419. package/dist/server/ssr-entry.d.ts.map +1 -1
  420. package/dist/server/ssr-render.d.ts +39 -21
  421. package/dist/server/ssr-render.d.ts.map +1 -1
  422. package/dist/server/ssr-wrappers.d.ts +50 -0
  423. package/dist/server/ssr-wrappers.d.ts.map +1 -0
  424. package/dist/server/state-tree-diff.d.ts.map +1 -1
  425. package/dist/server/status-code-resolver.d.ts +16 -11
  426. package/dist/server/status-code-resolver.d.ts.map +1 -1
  427. package/dist/server/stream-utils.d.ts +36 -0
  428. package/dist/server/stream-utils.d.ts.map +1 -0
  429. package/dist/server/tracing.d.ts +5 -5
  430. package/dist/server/tracing.d.ts.map +1 -1
  431. package/dist/server/tree-builder.d.ts +62 -30
  432. package/dist/server/tree-builder.d.ts.map +1 -1
  433. package/dist/server/types.d.ts +49 -4
  434. package/dist/server/types.d.ts.map +1 -1
  435. package/dist/server/utils/escape-html.d.ts +14 -0
  436. package/dist/server/utils/escape-html.d.ts.map +1 -0
  437. package/dist/server/version-skew.d.ts +61 -0
  438. package/dist/server/version-skew.d.ts.map +1 -0
  439. package/dist/shared/merge-search-params.d.ts +22 -0
  440. package/dist/shared/merge-search-params.d.ts.map +1 -0
  441. package/dist/shims/font-google.d.ts +1 -1
  442. package/dist/shims/font-google.d.ts.map +1 -1
  443. package/dist/shims/font-google.js +42 -0
  444. package/dist/shims/font-google.js.map +1 -0
  445. package/dist/shims/font-local.d.ts +26 -0
  446. package/dist/shims/font-local.d.ts.map +1 -0
  447. package/dist/shims/font-local.js +20 -0
  448. package/dist/shims/font-local.js.map +1 -0
  449. package/dist/shims/headers.d.ts +2 -1
  450. package/dist/shims/headers.d.ts.map +1 -1
  451. package/dist/shims/navigation-client.d.ts +3 -1
  452. package/dist/shims/navigation-client.d.ts.map +1 -1
  453. package/dist/shims/navigation.d.ts +11 -5
  454. package/dist/shims/navigation.d.ts.map +1 -1
  455. package/dist/utils/directive-parser.d.ts +1 -43
  456. package/dist/utils/directive-parser.d.ts.map +1 -1
  457. package/dist/utils/state-machine.d.ts +80 -0
  458. package/dist/utils/state-machine.d.ts.map +1 -0
  459. package/package.json +56 -22
  460. package/src/adapters/build-output-helper.ts +77 -0
  461. package/src/adapters/cloudflare-dev.ts +177 -0
  462. package/src/adapters/cloudflare-kv-cache.ts +142 -0
  463. package/src/adapters/cloudflare.ts +350 -76
  464. package/src/adapters/compress-module.ts +24 -4
  465. package/src/adapters/nitro.ts +142 -59
  466. package/src/adapters/shared.ts +40 -0
  467. package/src/adapters/wrangler.d.ts +7 -0
  468. package/src/cache/cache-api.ts +38 -0
  469. package/src/cache/handler-store.ts +68 -0
  470. package/src/cache/index.ts +81 -18
  471. package/src/cache/singleflight.ts +62 -4
  472. package/src/cache/sizeof.ts +31 -0
  473. package/src/cache/timber-cache.ts +25 -20
  474. package/src/cli.ts +16 -6
  475. package/src/client/browser-dev.ts +153 -1
  476. package/src/client/browser-entry/action-dispatch.ts +116 -0
  477. package/src/client/browser-entry/hmr.ts +81 -0
  478. package/src/client/browser-entry/hydrate.ts +145 -0
  479. package/src/client/browser-entry/index.ts +143 -0
  480. package/src/client/browser-entry/post-hydration.ts +119 -0
  481. package/src/client/browser-entry/router-init.ts +193 -0
  482. package/src/client/browser-entry/rsc-stream.ts +157 -0
  483. package/src/client/browser-entry/scroll.ts +27 -0
  484. package/src/client/error-boundary.tsx +97 -20
  485. package/src/client/error-reconstituter.tsx +65 -0
  486. package/src/client/form.tsx +31 -32
  487. package/src/client/history.ts +26 -4
  488. package/src/client/index.ts +77 -43
  489. package/src/client/internal.ts +58 -0
  490. package/src/client/link-pending-store.ts +111 -0
  491. package/src/client/link.tsx +342 -113
  492. package/src/client/nav-link-store.ts +47 -0
  493. package/src/client/navigation-api-types.ts +112 -0
  494. package/src/client/navigation-api.ts +332 -0
  495. package/src/client/navigation-context.ts +31 -6
  496. package/src/client/navigation-root.tsx +342 -0
  497. package/src/client/nuqs-adapter.tsx +16 -3
  498. package/src/client/router-ref.ts +1 -1
  499. package/src/client/router.ts +300 -73
  500. package/src/client/rsc-fetch.ts +112 -8
  501. package/src/client/segment-cache.ts +1 -1
  502. package/src/client/segment-outlet.tsx +86 -0
  503. package/src/client/ssr-data.ts +13 -5
  504. package/src/client/stale-reload.ts +72 -3
  505. package/src/client/state.ts +2 -2
  506. package/src/client/top-loader.tsx +18 -6
  507. package/src/client/use-cookie.ts +29 -0
  508. package/src/client/use-link-status.ts +7 -7
  509. package/src/client/{use-navigation-pending.ts → use-pending-navigation.ts} +6 -6
  510. package/src/client/use-query-states.ts +9 -3
  511. package/src/client/use-router.ts +1 -1
  512. package/src/client/{use-params.ts → use-segment-params.ts} +7 -5
  513. package/src/codec.ts +45 -0
  514. package/src/config-types.ts +292 -0
  515. package/src/config-validation.ts +303 -0
  516. package/src/content/index.ts +5 -13
  517. package/src/cookies/define-cookie.ts +301 -55
  518. package/src/cookies/index.ts +12 -1
  519. package/src/cookies/json-cookie.ts +105 -0
  520. package/src/cookies/validation.ts +134 -0
  521. package/src/dev-tools/404-page.ts +387 -0
  522. package/src/dev-tools/browser-logs.ts +288 -0
  523. package/src/dev-tools/error-page.ts +509 -0
  524. package/src/dev-tools/holding-server.ts +187 -0
  525. package/src/dev-tools/index.ts +90 -0
  526. package/src/dev-tools/instrumentation.ts +176 -0
  527. package/src/{plugins/dev-logs.ts → dev-tools/logs.ts} +3 -3
  528. package/src/dev-tools/overlay.ts +456 -0
  529. package/src/dev-tools/stack-classifier.ts +75 -0
  530. package/src/dev-tools/terminal.ts +183 -0
  531. package/src/{server/dev-warnings.ts → dev-tools/warnings.ts} +5 -50
  532. package/src/fonts/bundle.ts +142 -0
  533. package/src/fonts/css.ts +2 -1
  534. package/src/fonts/dev-middleware.ts +74 -0
  535. package/src/fonts/pipeline.ts +314 -0
  536. package/src/fonts/transform.ts +406 -0
  537. package/src/fonts/types.ts +50 -1
  538. package/src/fonts/virtual-modules.ts +227 -0
  539. package/src/index.ts +376 -356
  540. package/src/plugin-context.ts +240 -0
  541. package/src/plugins/adapter-build.ts +12 -4
  542. package/src/plugins/build-manifest.ts +13 -2
  543. package/src/plugins/build-report.ts +16 -25
  544. package/src/plugins/client-chunks.ts +65 -0
  545. package/src/plugins/content.ts +1 -1
  546. package/src/plugins/dev-server.ts +154 -21
  547. package/src/plugins/entries.ts +111 -10
  548. package/src/plugins/fonts.ts +155 -654
  549. package/src/plugins/mdx.ts +43 -10
  550. package/src/plugins/routing.ts +225 -41
  551. package/src/plugins/server-action-exports.ts +1 -1
  552. package/src/plugins/server-bundle.ts +32 -1
  553. package/src/plugins/shims.ts +136 -35
  554. package/src/plugins/static-build.ts +17 -11
  555. package/src/routing/codegen-shared.ts +98 -0
  556. package/src/routing/codegen-types.ts +53 -0
  557. package/src/routing/codegen.ts +143 -176
  558. package/src/routing/convention-lint.ts +357 -0
  559. package/src/routing/index.ts +5 -1
  560. package/src/routing/interception.ts +1 -1
  561. package/src/routing/link-codegen.ts +294 -0
  562. package/src/routing/scanner.ts +107 -110
  563. package/src/routing/segment-classify.ts +188 -0
  564. package/src/routing/status-file-lint.ts +10 -7
  565. package/src/routing/types.ts +78 -25
  566. package/src/routing/walkers.ts +90 -0
  567. package/src/rsc-runtime/rsc.ts +2 -0
  568. package/src/rsc-runtime/ssr.ts +50 -0
  569. package/src/rsc-runtime/vendor-types.d.ts +7 -0
  570. package/src/{search-params/codecs.ts → schema-bridge.ts} +57 -20
  571. package/src/search-params/define.ts +538 -0
  572. package/src/search-params/index.ts +14 -20
  573. package/src/search-params/registry.ts +2 -2
  574. package/src/search-params/wrappers.ts +92 -0
  575. package/src/segment-params/define.ts +332 -0
  576. package/src/segment-params/index.ts +9 -0
  577. package/src/server/access-gate.tsx +76 -34
  578. package/src/server/action-client.ts +88 -15
  579. package/src/server/action-encryption.ts +144 -0
  580. package/src/server/action-handler.ts +112 -14
  581. package/src/server/actions.ts +10 -9
  582. package/src/server/als-registry.ts +35 -7
  583. package/src/server/asset-headers.ts +8 -34
  584. package/src/server/build-manifest.ts +10 -4
  585. package/src/server/compress.ts +25 -7
  586. package/src/server/cookie-context.ts +468 -0
  587. package/src/server/cookie-parsing.ts +135 -0
  588. package/src/server/debug.ts +1 -1
  589. package/src/server/default-logger.ts +99 -0
  590. package/src/server/deny-boundary.ts +218 -0
  591. package/src/server/deny-renderer.ts +31 -50
  592. package/src/server/dev-source-map.ts +31 -0
  593. package/src/server/early-hints-sender.ts +3 -2
  594. package/src/server/early-hints.ts +36 -15
  595. package/src/server/error-boundary-wrapper.ts +74 -22
  596. package/src/server/fallback-error.ts +74 -102
  597. package/src/server/flight-injection-state.ts +113 -0
  598. package/src/server/flight-scripts.ts +62 -0
  599. package/src/server/flush.ts +2 -1
  600. package/src/server/form-data.ts +76 -0
  601. package/src/server/html-injector-core.ts +403 -0
  602. package/src/server/html-injectors.ts +244 -223
  603. package/src/server/index.ts +31 -184
  604. package/src/server/internal.ts +176 -0
  605. package/src/server/logger.ts +67 -36
  606. package/src/server/middleware-runner.ts +75 -4
  607. package/src/server/node-stream-transforms.ts +369 -0
  608. package/src/server/param-coercion.ts +76 -0
  609. package/src/server/pipeline-helpers.ts +204 -0
  610. package/src/server/pipeline-interception.ts +17 -16
  611. package/src/server/pipeline-metadata.ts +13 -0
  612. package/src/server/pipeline-outcome.ts +167 -0
  613. package/src/server/pipeline-phases.ts +409 -0
  614. package/src/server/pipeline.ts +128 -394
  615. package/src/server/port-resolution.ts +215 -0
  616. package/src/server/primitives.ts +111 -28
  617. package/src/server/render-timeout.ts +108 -0
  618. package/src/server/request-context.ts +94 -338
  619. package/src/server/route-element-builder.ts +288 -192
  620. package/src/server/route-handler.ts +24 -4
  621. package/src/server/route-matcher.ts +44 -65
  622. package/src/server/rsc-entry/action-middleware-runner.ts +167 -0
  623. package/src/server/rsc-entry/api-handler.ts +16 -17
  624. package/src/server/rsc-entry/error-renderer.ts +305 -89
  625. package/src/server/rsc-entry/helpers.ts +136 -12
  626. package/src/server/rsc-entry/index.ts +312 -341
  627. package/src/server/rsc-entry/render-route.ts +304 -0
  628. package/src/server/rsc-entry/rsc-payload.ts +65 -18
  629. package/src/server/rsc-entry/rsc-stream.ts +81 -13
  630. package/src/server/rsc-entry/ssr-bridge.ts +14 -5
  631. package/src/server/rsc-entry/ssr-renderer.ts +171 -38
  632. package/src/server/rsc-entry/wrap-action-dispatch.ts +449 -0
  633. package/src/server/safe-load.ts +60 -0
  634. package/src/server/sensitive-fields.ts +230 -0
  635. package/src/server/sitemap-generator.ts +338 -0
  636. package/src/server/sitemap-handler.ts +126 -0
  637. package/src/server/slot-resolver.ts +245 -230
  638. package/src/server/ssr-entry.ts +215 -32
  639. package/src/server/ssr-render.ts +289 -67
  640. package/src/server/ssr-wrappers.tsx +139 -0
  641. package/src/server/state-tree-diff.ts +4 -1
  642. package/src/server/status-code-resolver.ts +112 -128
  643. package/src/server/stream-utils.ts +213 -0
  644. package/src/server/tracing.ts +21 -10
  645. package/src/server/tree-builder.ts +202 -90
  646. package/src/server/types.ts +55 -6
  647. package/src/server/utils/escape-html.ts +20 -0
  648. package/src/server/version-skew.ts +104 -0
  649. package/src/shared/merge-search-params.ts +55 -0
  650. package/src/shims/font-google.ts +1 -1
  651. package/src/shims/font-local.ts +34 -0
  652. package/src/shims/headers.ts +5 -1
  653. package/src/shims/navigation-client.ts +4 -3
  654. package/src/shims/navigation.ts +14 -7
  655. package/src/utils/directive-parser.ts +1 -390
  656. package/src/utils/state-machine.ts +111 -0
  657. package/dist/_chunks/als-registry-B7DbZ2hS.js +0 -41
  658. package/dist/_chunks/als-registry-B7DbZ2hS.js.map +0 -1
  659. package/dist/_chunks/debug-gwlJkDuf.js +0 -108
  660. package/dist/_chunks/debug-gwlJkDuf.js.map +0 -1
  661. package/dist/_chunks/format-DviM89f0.js.map +0 -1
  662. package/dist/_chunks/interception-BOoWmLUA.js +0 -676
  663. package/dist/_chunks/interception-BOoWmLUA.js.map +0 -1
  664. package/dist/_chunks/request-context-DIkVh_jG.js +0 -330
  665. package/dist/_chunks/request-context-DIkVh_jG.js.map +0 -1
  666. package/dist/_chunks/ssr-data-MjmprTmO.js.map +0 -1
  667. package/dist/_chunks/tracing-CemImE6h.js +0 -187
  668. package/dist/_chunks/tracing-CemImE6h.js.map +0 -1
  669. package/dist/_chunks/use-cookie-DX-l1_5E.js +0 -91
  670. package/dist/_chunks/use-cookie-DX-l1_5E.js.map +0 -1
  671. package/dist/_chunks/use-query-states-D5KaffOK.js.map +0 -1
  672. package/dist/cache/register-cached-function.d.ts +0 -17
  673. package/dist/cache/register-cached-function.d.ts.map +0 -1
  674. package/dist/client/browser-entry.d.ts +0 -21
  675. package/dist/client/browser-entry.d.ts.map +0 -1
  676. package/dist/client/link-status-provider.d.ts +0 -11
  677. package/dist/client/link-status-provider.d.ts.map +0 -1
  678. package/dist/client/transition-root.d.ts.map +0 -1
  679. package/dist/client/use-navigation-pending.d.ts.map +0 -1
  680. package/dist/client/use-params.d.ts.map +0 -1
  681. package/dist/plugins/cache-transform.d.ts +0 -36
  682. package/dist/plugins/cache-transform.d.ts.map +0 -1
  683. package/dist/plugins/dev-error-overlay.d.ts +0 -60
  684. package/dist/plugins/dev-error-overlay.d.ts.map +0 -1
  685. package/dist/plugins/dev-logs.d.ts.map +0 -1
  686. package/dist/plugins/dynamic-transform.d.ts +0 -72
  687. package/dist/plugins/dynamic-transform.d.ts.map +0 -1
  688. package/dist/search-params/analyze.d.ts +0 -54
  689. package/dist/search-params/analyze.d.ts.map +0 -1
  690. package/dist/search-params/builtin-codecs.d.ts +0 -105
  691. package/dist/search-params/builtin-codecs.d.ts.map +0 -1
  692. package/dist/search-params/codecs.d.ts +0 -53
  693. package/dist/search-params/codecs.d.ts.map +0 -1
  694. package/dist/search-params/create.d.ts +0 -106
  695. package/dist/search-params/create.d.ts.map +0 -1
  696. package/dist/server/dev-fetch-instrumentation.d.ts +0 -22
  697. package/dist/server/dev-fetch-instrumentation.d.ts.map +0 -1
  698. package/dist/server/dev-logger.d.ts.map +0 -1
  699. package/dist/server/dev-span-processor.d.ts.map +0 -1
  700. package/dist/server/dev-warnings.d.ts.map +0 -1
  701. package/dist/server/manifest-status-resolver.d.ts +0 -58
  702. package/dist/server/manifest-status-resolver.d.ts.map +0 -1
  703. package/dist/server/prerender.d.ts +0 -77
  704. package/dist/server/prerender.d.ts.map +0 -1
  705. package/dist/server/response-cache.d.ts +0 -54
  706. package/dist/server/response-cache.d.ts.map +0 -1
  707. package/src/cache/register-cached-function.ts +0 -103
  708. package/src/client/browser-entry.ts +0 -678
  709. package/src/client/link-status-provider.tsx +0 -30
  710. package/src/client/transition-root.tsx +0 -166
  711. package/src/plugins/cache-transform.ts +0 -199
  712. package/src/plugins/dev-error-overlay.ts +0 -230
  713. package/src/plugins/dynamic-transform.ts +0 -161
  714. package/src/search-params/analyze.ts +0 -192
  715. package/src/search-params/builtin-codecs.ts +0 -228
  716. package/src/search-params/create.ts +0 -321
  717. package/src/server/dev-fetch-instrumentation.ts +0 -96
  718. package/src/server/dev-span-processor.ts +0 -78
  719. package/src/server/manifest-status-resolver.ts +0 -215
  720. package/src/server/prerender.ts +0 -139
  721. package/src/server/response-cache.ts +0 -410
  722. /package/src/{server/dev-logger.ts → dev-tools/logger.ts} +0 -0
package/src/index.ts CHANGED
@@ -1,10 +1,19 @@
1
+ /**
2
+ * @timber-js/app — Root entry point (public API).
3
+ *
4
+ * User-facing exports: timber(), defineConfig(), TimberUserConfig, Routes.
5
+ *
6
+ * Internal helpers (PluginContext, resolveAppDir, loadTimberConfigFile,
7
+ * warnConfigConflicts, resolveClientJavascript) live in plugin-context.ts
8
+ * and are NOT re-exported here. Sub-plugins import them via relative paths.
9
+ *
10
+ * Design doc: 18-build-system.md §"Plugin Architecture"
11
+ */
12
+
1
13
  import type { Plugin, PluginOption } from 'vite';
2
- import { existsSync } from 'node:fs';
3
- import { join } from 'node:path';
4
- import { pathToFileURL } from 'node:url';
14
+ import { join, resolve } from 'node:path';
5
15
  import { createRequire } from 'node:module';
6
- import react from '@vitejs/plugin-react';
7
- import { cacheTransformPlugin } from './plugins/cache-transform';
16
+ import react, { reactCompilerPreset } from '@vitejs/plugin-react';
8
17
  import { timberContent } from './plugins/content';
9
18
  import { timberDevServer } from './plugins/dev-server';
10
19
  import { timberEntries } from './plugins/entries';
@@ -13,357 +22,267 @@ import { timberRouting } from './plugins/routing';
13
22
  import { timberShims } from './plugins/shims';
14
23
  import { timberFonts } from './plugins/fonts';
15
24
  import { timberStaticBuild } from './plugins/static-build';
16
- import { timberDynamicTransform } from './plugins/dynamic-transform';
17
25
  import { timberServerActionExports } from './plugins/server-action-exports';
18
26
  import { timberBuildManifest } from './plugins/build-manifest';
19
- import { timberDevLogs } from './plugins/dev-logs';
27
+ import { timberDevLogs } from './dev-tools/logs';
28
+ import { timberDevBrowserLogs } from './dev-tools/browser-logs';
20
29
  import { timberReactProd } from './plugins/react-prod';
21
30
  import { timberChunks } from './plugins/chunks';
31
+ import { clientChunkGroup } from './plugins/client-chunks';
22
32
  import { timberServerBundle } from './plugins/server-bundle';
23
33
  import { timberAdapterBuild } from './plugins/adapter-build';
24
34
  import { timberBuildReport } from './plugins/build-report';
25
- import type { RouteTree } from './routing/types';
26
- import type { BuildManifest } from './server/build-manifest';
27
- import type { StartupTimer } from './utils/startup-timer';
28
- import { createStartupTimer, createNoopTimer } from './utils/startup-timer';
29
-
30
- /** Configuration for client-side JavaScript output. */
31
- export interface ClientJavascriptConfig {
32
- /** When true, no client JS bundles are emitted or referenced in HTML. */
33
- disabled: boolean;
34
- /**
35
- * When `disabled` is true, still inject the Vite HMR client in dev mode
36
- * so hot reloading works during development. Default: true.
37
- */
38
- enableHMRInDev?: boolean;
39
- }
35
+ import { createNoopTimer } from './utils/startup-timer';
36
+ import { resolveEncryptionKeyExpression, shouldEnableEncryption } from './server/action-encryption';
37
+ import { createHoldingServer } from './dev-tools/holding-server.js';
38
+ import { resolveStartPort, startDevServerPort } from './server/port-resolution.js';
39
+ import type { TimberUserConfig } from './config-types.js';
40
+ import type { PluginContext } from './plugin-context.js';
41
+ import {
42
+ createPluginContext,
43
+ loadTimberConfigFile,
44
+ mergeFileConfig,
45
+ resolveAppDir,
46
+ resolveClientJavascript,
47
+ resolveBuildDir,
48
+ DEFAULT_BUILD_DIR,
49
+ } from './plugin-context.js';
40
50
 
41
- /** Fully resolved client JavaScript configuration (no optionals). */
42
- export interface ResolvedClientJavascript {
43
- disabled: boolean;
44
- enableHMRInDev: boolean;
45
- }
46
-
47
- export interface TimberUserConfig {
48
- output?: 'server' | 'static';
49
- /**
50
- * Enable timber debug logging in production builds.
51
- *
52
- * When `true`, timber's own diagnostics (dev warnings, verbose logging)
53
- * are active even in production mode. React stays in production mode —
54
- * only timber's logs are affected.
55
- *
56
- * Can also be enabled at runtime via the `TIMBER_DEBUG` environment variable.
57
- *
58
- * Default: `false`.
59
- */
60
- debug?: boolean;
61
- /**
62
- * Control client-side JavaScript output.
63
- *
64
- * Boolean shorthand:
65
- * `clientJavascript: false` disables all client JS (equivalent to `{ disabled: true }`).
66
- * `clientJavascript: true` enables client JS (the default).
67
- *
68
- * Object form:
69
- * `clientJavascript: { disabled: true, enableHMRInDev: true }` disables client JS
70
- * in production but preserves Vite HMR in dev mode.
71
- *
72
- * When `disabled` is true, `enableHMRInDev` defaults to `true`.
73
- * Server-side JS still runs — this only affects what is sent to the browser.
74
- */
75
- clientJavascript?: boolean | ClientJavascriptConfig;
76
- adapter?: unknown;
77
- cacheHandler?: unknown;
78
- allowedOrigins?: string[];
79
- csrf?: boolean;
80
- limits?: {
81
- actionBodySize?: string;
82
- uploadBodySize?: string;
83
- maxFields?: number;
84
- };
85
- pageExtensions?: string[];
86
- /**
87
- * Slow request threshold in milliseconds. Requests exceeding this emit
88
- * a warning via the logger. Set to 0 to disable. Default: 3000.
89
- *
90
- * See design/17-logging.md §"slowRequestMs".
91
- */
92
- slowRequestMs?: number;
93
- /** Dev-mode options. These have no effect in production builds. */
94
- dev?: {
95
- /** Threshold in ms to highlight slow phases in dev logging output. Default: 200. */
96
- slowPhaseMs?: number;
97
- };
98
- /**
99
- * Cookie signing configuration. See design/29-cookies.md §"Signed Cookies".
100
- *
101
- * Provide `secret` for a single key, or `secrets` (array) for key rotation.
102
- * When `secrets` is used, index 0 is the signing key; all are tried for verification.
103
- */
104
- cookies?: {
105
- /** Single signing secret. Shorthand for `secrets: [secret]`. */
106
- secret?: string;
107
- /** Array of signing secrets for key rotation. Index 0 signs; all verify. */
108
- secrets?: string[];
109
- };
110
- /**
111
- * Override the app directory location. By default, timber auto-detects
112
- * `app/` at the project root, falling back to `src/app/`.
113
- *
114
- * Set this to a relative path from the project root (e.g. `'src/app'`)
115
- * to use a custom location.
116
- */
117
- appDir?: string;
118
- /** MDX compilation options passed to @mdx-js/rollup. See design/20-content-collections.md. */
119
- mdx?: {
120
- remarkPlugins?: unknown[];
121
- rehypePlugins?: unknown[];
122
- recmaPlugins?: unknown[];
123
- remarkRehypeOptions?: Record<string, unknown>;
124
- };
125
- /**
126
- * Built-in top-loader progress bar for client navigations.
127
- * Shows an animated bar at the top of the viewport during RSC navigations.
128
- * Enabled by default — set `enabled: false` to opt out.
129
- *
130
- * Users who want a fully custom progress indicator should disable this
131
- * and use `useNavigationPending()` directly.
132
- *
133
- * See LOCAL-336 for design decisions.
134
- */
135
- topLoader?: {
136
- /** Whether the top-loader is enabled. Default: true. */
137
- enabled?: boolean;
138
- /** Bar color. Default: '#2299DD'. */
139
- color?: string;
140
- /** Bar height in pixels. Default: 3. */
141
- height?: number;
142
- /** Show subtle glow/shadow effect. Default: true. */
143
- shadow?: boolean;
144
- /** Delay in ms before showing the bar (avoids flash on fast navs). Default: 0. */
145
- delay?: number;
146
- /** CSS z-index. Default: 1600. */
147
- zIndex?: number;
148
- };
149
- /**
150
- * Response-level caching and deduplication.
151
- *
152
- * When enabled, concurrent requests to the same URL share a single render
153
- * (singleflight), and recently rendered responses are reused from a short-TTL
154
- * LRU cache without re-executing the RSC-to-SSR pipeline.
155
- *
156
- * Set to `false` to disable entirely. Default: enabled with sensible defaults.
157
- *
158
- * See design/31-benchmarking.md for performance context.
159
- */
160
- responseCache?:
161
- | false
162
- | {
163
- /** Maximum number of entries in the LRU cache. Default: 150. */
164
- maxSize?: number;
165
- /** TTL for cached entries in milliseconds. Default: 5000 (5s). */
166
- ttlMs?: number;
167
- /**
168
- * When true (default), requests with Cookie or Authorization headers
169
- * bypass the cache entirely. This prevents sharing user-specific
170
- * responses across requests.
171
- *
172
- * Set to false to cache all responses regardless of auth state.
173
- * Only do this if your pages are truly public and don't vary by user.
174
- */
175
- publicOnly?: boolean;
176
- };
177
- }
51
+ // ── Public API ────────────────────────────────────────────────────────────
178
52
 
179
- /**
180
- * Resolve `clientJavascript` into a fully resolved config.
181
- */
182
- export function resolveClientJavascript(config: TimberUserConfig): ResolvedClientJavascript {
183
- if (config.clientJavascript !== undefined) {
184
- if (typeof config.clientJavascript === 'boolean') {
185
- // `clientJavascript: false` → disabled
186
- // `clientJavascript: true` → enabled (default)
187
- return {
188
- disabled: !config.clientJavascript,
189
- enableHMRInDev: !config.clientJavascript, // default true when disabled
190
- };
191
- }
192
- // Object form
193
- return {
194
- disabled: config.clientJavascript.disabled,
195
- enableHMRInDev: config.clientJavascript.enableHMRInDev ?? config.clientJavascript.disabled,
196
- };
197
- }
53
+ export type { TimberUserConfig } from './config-types.js';
198
54
 
199
- // Default: client JS enabled
200
- return { disabled: false, enableHMRInDev: false };
201
- }
55
+ // Metadata route handler types — re-exported so user-authored metadata
56
+ // route files (sitemap.ts, robots.ts, manifest.ts, icon.tsx, etc.) can
57
+ // import them from the package root without reaching into ./server.
58
+ // The canonical location for these types is '@timber-js/app/server'; this
59
+ // root re-export is a convenience for typed metadata route handlers.
60
+ // See design/16-metadata.md §"Metadata Routes".
61
+ export type { Metadata, MetadataRoute, MetadataHandler, MetadataResult } from './server/types.js';
202
62
 
203
63
  /**
204
- * Shared context object passed to all sub-plugins via closure.
64
+ * Route map interface — augmented by the generated timber-routes.d.ts.
205
65
  *
206
- * Sub-plugins communicate through this context — not through Vite's
207
- * plugin API or global state.
208
- * See design/18-build-system.md §"Shared Plugin Context".
66
+ * Each key is a route path pattern. Values have:
67
+ * segmentParams: shape of URL segment params (e.g. { id: string })
68
+ * searchParams: parsed type from search-params.ts, or {} if none
69
+ *
70
+ * This interface is empty by default and populated via codegen.
71
+ * See design/09-typescript.md §"Typed Routes".
209
72
  */
210
- export interface PluginContext {
211
- config: TimberUserConfig;
212
- /** Resolved client JavaScript configuration */
213
- clientJavascript: ResolvedClientJavascript;
214
- /** The scanned route tree (populated by timber-routing, consumed by timber-entries) */
215
- routeTree: RouteTree | null;
216
- /** Absolute path to the app/ directory */
217
- appDir: string;
218
- /** Absolute path to the project root */
219
- root: string;
220
- /** Whether the dev server is running (set by timber-root-sync in configResolved) */
221
- dev: boolean;
222
- /** CSS build manifest (populated by adapter after client build, null in dev) */
223
- buildManifest: BuildManifest | null;
224
- /** Startup timer for profiling cold start phases (active in dev, no-op in prod) */
225
- timer: StartupTimer;
226
-
227
- }
73
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
74
+ export interface Routes {}
228
75
 
229
76
  /**
230
- * Resolve the app directory. Checks (in order):
231
- * 1. Explicit `configAppDir` from timber.config.ts
232
- * 2. `<root>/app`
233
- * 3. `<root>/src/app`
77
+ * Type-safe helper for timber.config.ts files.
78
+ *
79
+ * A pass-through identity function that provides autocomplete and
80
+ * type checking for timber configuration. No runtime validation —
81
+ * purely a DX convenience (same pattern as Vite's defineConfig).
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * // timber.config.ts
86
+ * import { defineConfig } from '@timber-js/app';
234
87
  *
235
- * Throws if none exist.
88
+ * export default defineConfig({
89
+ * output: 'server',
90
+ * pageExtensions: ['tsx', 'ts', 'mdx'],
91
+ * });
92
+ * ```
236
93
  */
237
- export function resolveAppDir(root: string, configAppDir?: string): string {
238
- if (configAppDir) {
239
- const explicit = join(root, configAppDir);
240
- if (!existsSync(explicit)) {
241
- throw new Error(`[timber] Configured appDir "${configAppDir}" does not exist at ${explicit}`);
242
- }
243
- return explicit;
244
- }
245
-
246
- const rootApp = join(root, 'app');
247
- if (existsSync(rootApp)) return rootApp;
248
-
249
- const srcApp = join(root, 'src', 'app');
250
- if (existsSync(srcApp)) return srcApp;
251
-
252
- throw new Error(
253
- `[timber] Could not find app directory. Expected "app/" or "src/app/" in ${root}. ` +
254
- `You can set appDir in timber.config.ts to specify a custom location.`
255
- );
94
+ export function defineConfig(config: TimberUserConfig): TimberUserConfig {
95
+ return config;
256
96
  }
257
97
 
258
- function createPluginContext(config?: TimberUserConfig, root?: string): PluginContext {
259
- const projectRoot = root ?? process.cwd();
260
- const resolvedConfig: TimberUserConfig = { output: 'server', ...config };
261
- // Timer starts as active — swapped to noop in configResolved for production builds
262
- return {
263
- config: resolvedConfig,
264
- clientJavascript: resolveClientJavascript(resolvedConfig),
265
- routeTree: null,
266
- appDir: join(projectRoot, 'app'),
267
- root: projectRoot,
268
- dev: false,
269
- buildManifest: null,
270
- timer: createStartupTimer(),
271
- };
272
- }
273
-
274
- /**
275
- * Load timber.config.ts (or .js, .mjs) from the project root.
276
- * Returns the config object or null if no config file is found.
277
- */
278
- async function loadTimberConfigFile(root: string): Promise<TimberUserConfig | null> {
279
- const configNames = ['timber.config.ts', 'timber.config.js', 'timber.config.mjs'];
280
-
281
- for (const name of configNames) {
282
- const configPath = join(root, name);
283
- if (existsSync(configPath)) {
284
- const mod = await import(pathToFileURL(configPath).href);
285
- return (mod.default ?? mod) as TimberUserConfig;
286
- }
287
- }
288
- return null;
289
- }
98
+ // ── Private helpers ───────────────────────────────────────────────────────
290
99
 
291
100
  /**
292
- * Detect config keys set in both inline (vite.config.ts) and file (timber.config.ts)
293
- * and warn the user. The `output` key is excluded because it defaults to 'server'
294
- * in createPluginContext and would always appear as an inline key.
101
+ * Resolve the React Compiler plugin via @rolldown/plugin-babel.
295
102
  *
296
- * Returns the list of conflicting key names (for testing).
103
+ * Uses the `reactCompilerPreset` from @vitejs/plugin-react, which:
104
+ * - Uses Babel ONLY for the compiler pass (OXC handles JSX)
105
+ * - Automatically scopes to client environment via applyToEnvironmentHook
106
+ * - Uses react/compiler-runtime built into React 19
107
+ *
108
+ * @rolldown/plugin-babel and babel-plugin-react-compiler are optional peer deps.
109
+ * If either is missing, require() fails with a clear error message.
297
110
  */
298
- export function warnConfigConflicts(
299
- inline: TimberUserConfig,
300
- fileConfig: TimberUserConfig
301
- ): string[] {
302
- const conflicts: string[] = [];
303
- for (const key of Object.keys(fileConfig) as (keyof TimberUserConfig)[]) {
304
- if (key === 'output') continue;
305
- if (key in inline && inline[key] !== undefined) {
306
- conflicts.push(key);
307
- }
308
- }
309
- if (conflicts.length > 0) {
310
- console.warn(
311
- `[timber] Config conflict: ${conflicts.map((k) => `"${k}"`).join(', ')} set in both ` +
312
- `vite.config.ts (inline) and timber.config.ts. ` +
313
- `Move all config to timber.config.ts to avoid confusion. ` +
314
- `The inline value from vite.config.ts will be used.`
111
+ function resolveReactCompilerPlugin(
112
+ config: true | { compilationMode?: string; target?: string },
113
+ req: NodeRequire
114
+ ): PluginOption {
115
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
116
+ let babel: any;
117
+ try {
118
+ babel = req('@rolldown/plugin-babel');
119
+ } catch {
120
+ throw new Error(
121
+ '[timber] reactCompiler requires @rolldown/plugin-babel. ' +
122
+ 'Install it: pnpm add -D @rolldown/plugin-babel babel-plugin-react-compiler'
315
123
  );
316
124
  }
317
- return conflicts;
125
+ const options = typeof config === 'object' ? config : {};
126
+ const babelPlugin = babel.default ?? babel;
127
+ return babelPlugin({
128
+ presets: [reactCompilerPreset(options as Parameters<typeof reactCompilerPreset>[0])],
129
+ }) as PluginOption;
318
130
  }
319
131
 
320
132
  /**
321
- * Merge file-based config into ctx.config. Inline config (already in ctx.config)
322
- * takes precedence — file config only fills in missing fields.
133
+ * Build the options object for @vitejs/plugin-rsc.
134
+ *
135
+ * Uses a getter for `enableActionEncryption` so the RSC plugin reads
136
+ * the value lazily — after ctx.dev is set in configResolved. This lets
137
+ * `actionEncryption.disableInDev` work correctly even though the RSC
138
+ * plugin is created before Vite resolves the command.
323
139
  */
324
- function mergeFileConfig(ctx: PluginContext, fileConfig: TimberUserConfig): void {
325
- const inline = ctx.config;
326
-
327
- // Warn if the same key is set in both places
328
- warnConfigConflicts(inline, fileConfig);
329
-
330
- // For each top-level key, use inline value if present, otherwise file value
331
- ctx.config = {
332
- ...fileConfig,
333
- ...inline,
334
- // Deep merge for nested objects where both exist
335
- ...(fileConfig.limits && inline.limits
336
- ? { limits: { ...fileConfig.limits, ...inline.limits } }
337
- : {}),
338
- ...(fileConfig.dev && inline.dev ? { dev: { ...fileConfig.dev, ...inline.dev } } : {}),
339
- ...(fileConfig.mdx && inline.mdx ? { mdx: { ...fileConfig.mdx, ...inline.mdx } } : {}),
140
+ function createRscOptions(
141
+ ctx: PluginContext,
142
+ encryptionKeyExpr: string | undefined
143
+ ): Record<string, unknown> {
144
+ const options: Record<string, unknown> = {
145
+ serverHandler: false,
146
+ customClientEntry: true,
147
+ entries: {
148
+ rsc: 'virtual:timber-rsc-entry',
149
+ ssr: 'virtual:timber-ssr-entry',
150
+ client: 'virtual:timber-browser-entry',
151
+ },
152
+ // Group client references by layout boundary to balance route-scoped code
153
+ // splitting with HTTP request count. A constant group name ('client-refs')
154
+ // would collapse all routes into one chunk — any page downloads every
155
+ // client component. Per-serverChunk grouping creates many sub-500B files.
156
+ // Layout-boundary grouping is the middle ground: components under the same
157
+ // layout segment share a chunk. See design/27-chunking-strategy.md, TIM-440, TIM-499.
158
+ clientChunks: (meta: { id: string; normalizedId: string; serverChunk: string }) =>
159
+ clientChunkGroup(meta, ctx.appDir),
340
160
  };
341
- }
342
161
 
343
- function timberCache(_ctx: PluginContext): Plugin {
344
- return cacheTransformPlugin();
162
+ // Bound args encryption — AES-256-GCM authenticated encryption for
163
+ // closure variables in 'use server' functions. Always on in production,
164
+ // configurable in dev. See design/08-forms-and-actions.md §"Bound Args Encryption".
165
+ //
166
+ // Uses a getter so the RSC plugin reads the value lazily in its transform
167
+ // hooks, after ctx.dev is set in configResolved. This lets disableInDev
168
+ // work correctly — ctx.dev is false at construction time but true during
169
+ // dev server transforms.
170
+ Object.defineProperty(options, 'enableActionEncryption', {
171
+ get() {
172
+ return shouldEnableEncryption(ctx.dev, ctx.config.actionEncryption);
173
+ },
174
+ enumerable: true,
175
+ });
176
+
177
+ // When TIMBER_ACTIONS_ENCRYPTION_KEY is set, pass it as a runtime expression
178
+ // so the RSC plugin uses it instead of auto-generating a per-build key.
179
+ if (encryptionKeyExpr) {
180
+ options.defineEncryptionKey = encryptionKeyExpr;
181
+ }
182
+
183
+ return options;
345
184
  }
346
185
 
186
+ // NOTE: 'use cache' directive transform removed — future feature pending design doc.
187
+ // The timber.cache() API (createCache) remains available for explicit caching.
188
+ // See design/06-caching.md.
189
+
190
+ // ── Main plugin factory ──────────────────────────────────────────────────
191
+
192
+ /**
193
+ * Create the timber Vite plugin array.
194
+ *
195
+ * Loads timber.config.ts and all dependencies synchronously before
196
+ * constructing the plugin array. This ensures ALL plugins — including
197
+ * the RSC plugin and React Compiler — see the fully merged config
198
+ * (inline + file-based). No async, no deferred config, no stale reads.
199
+ *
200
+ * Requires Node >= 22.12 for synchronous require() of ESM modules
201
+ * (@vitejs/plugin-rsc is ESM-only).
202
+ *
203
+ * Previous versions used async loading and deferred config merging,
204
+ * causing file-based config for reactCompiler, actionEncryption, and
205
+ * output mode to be silently ignored. See TIM-451.
206
+ */
347
207
  export function timber(config?: TimberUserConfig): PluginOption[] {
348
208
  const ctx = createPluginContext(config);
349
- // Sync ctx.root and ctx.appDir with Vite's resolved root, which may
350
- // differ from process.cwd() when --config points to a subdirectory.
351
- // Also loads timber.config.ts and merges it into ctx.config (inline config wins).
209
+
210
+ // Resolve dependencies from the consumer's project (process.cwd()),
211
+ // not from timber's own node_modules. This is critical for pnpm link:
212
+ // when linked, timber's node_modules has a separate vite instance, and
213
+ // the RSC plugin must use the same vite instance as the dev server.
214
+ const consumerRequire = createRequire(join(process.cwd(), 'package.json'));
215
+
216
+ // ── Step 1: Load @vitejs/plugin-rsc ─────────────────────────────────
217
+ // Synchronous require() works for ESM modules on Node 22.12+.
218
+ ctx.timer.start('rsc-plugin-import');
219
+ const rscMod = consumerRequire('@vitejs/plugin-rsc');
220
+ const vitePluginRsc = rscMod.default ?? rscMod;
221
+ ctx.timer.end('rsc-plugin-import');
222
+
223
+ // ── Step 2: Compute config-dependent options ────────────────────────
224
+ // encryptionKeyExpr is env-based and doesn't depend on file config.
225
+ const encryptionKeyExpr = resolveEncryptionKeyExpression();
226
+
227
+ // ── Step 3: Pre-load file config for plugin resolution ──────────────
228
+ // Load timber.config.ts eagerly from process.cwd() so we can resolve
229
+ // plugins (like React Compiler) and add them to the top-level array.
230
+ // Vite's config() hook return type is Omit<UserConfig, 'plugins'> —
231
+ // plugins returned from config() are silently ignored. See TIM-632.
232
+ //
233
+ // The config() hook still loads from the correct Vite root (which may
234
+ // differ from cwd in monorepo setups — see TIM-498), but only for
235
+ // non-plugin config merging.
236
+ const earlyFileConfig = loadTimberConfigFile(process.cwd());
237
+
238
+ // ── Step 4: Build rootSync plugin ───────────────────────────────────
239
+ // rootSync loads timber.config.ts from Vite's resolved root and merges
240
+ // it into ctx.config. Plugin resolution is handled eagerly above — the
241
+ // config() hook must NOT return a `plugins` field (Vite ignores it).
352
242
  const rootSync: Plugin = {
353
243
  name: 'timber-root-sync',
354
- async config(userConfig, { command }) {
355
- // Load timber.config.ts early — before configResolved/buildStart — so
356
- // all plugins (including timber-mdx) see the merged config in their
357
- // buildStart hooks. The config hook runs once and supports async.
358
- const root = userConfig.root ?? process.cwd();
244
+ async config(userConfig, { command, isPreview }) {
245
+ // ── Load timber.config.ts from the correct root ───────────────
246
+ // Vite's `config` hook fires before `configResolved`. The user's
247
+ // `root` option (if set) tells us where the project lives.
248
+ // `resolve()` mirrors Vite's own root resolution logic.
249
+ const viteRoot = resolve(userConfig.root ?? process.cwd());
359
250
  ctx.timer.start('config-load');
360
- const fileConfig = await loadTimberConfigFile(root);
251
+ const fileConfig = loadTimberConfigFile(viteRoot);
361
252
  if (fileConfig) {
362
253
  mergeFileConfig(ctx, fileConfig);
363
254
  ctx.clientJavascript = resolveClientJavascript(ctx.config);
364
255
  }
256
+ // Apply defaults AFTER merge so file-based config isn't overridden
257
+ // by defaults that were baked into the inline config object.
258
+ ctx.config.output ??= 'server';
365
259
  ctx.timer.end('config-load');
366
260
 
261
+ // ── Resolve build output directory ─────────────────────────
262
+ // Priority: timber.config.ts `buildDir` > Vite `build.outDir` > .timber/dist
263
+ // Set Vite's build.outDir so the RSC plugin and all environment
264
+ // builds write to the correct location.
265
+ const viteOutDir = userConfig.build?.outDir;
266
+ const timberBuildDir = ctx.config.buildDir;
267
+ const resolvedRoot = resolve(userConfig.root ?? process.cwd());
268
+ ctx.buildDir = resolveBuildDir(resolvedRoot, timberBuildDir, viteOutDir);
269
+
270
+ // Warn if the Vite root differs from cwd and the re-loaded config
271
+ // has reactCompiler but the early cwd-based load missed it. In this
272
+ // edge case the user must move reactCompiler to inline config.
273
+ if (viteRoot !== process.cwd()) {
274
+ const hasCompilerInReloaded = !config?.reactCompiler && ctx.config.reactCompiler;
275
+ const hadCompilerInEarly = !config?.reactCompiler && earlyFileConfig?.reactCompiler;
276
+ if (hasCompilerInReloaded && !hadCompilerInEarly) {
277
+ console.warn(
278
+ '[timber] reactCompiler is set in timber.config.ts but could not be ' +
279
+ 'registered because the config file is in a non-cwd root directory. ' +
280
+ 'Move reactCompiler to the inline timber() config in vite.config.ts, or ' +
281
+ 'run vite from the project root directory.'
282
+ );
283
+ }
284
+ }
285
+
367
286
  // Force production JSX transform for builds.
368
287
  //
369
288
  // Vite determines dev vs prod JSX via `isProduction`, which checks
@@ -377,8 +296,84 @@ export function timber(config?: TimberUserConfig): PluginOption[] {
377
296
  // We explicitly set `oxc.jsx.development: false` for builds so
378
297
  // the client bundle always uses jsx/jsxs from react/jsx-runtime,
379
298
  // regardless of the ambient NODE_ENV value.
299
+ // ── Resolve dev/preview port (TIM-842) ───────────────────────
300
+ // Default port is 3000 with auto-bump on conflict. Explicit user
301
+ // overrides (`--port`, `PORT` env, `vite.config.ts` server.port)
302
+ // are honored as-is and fail loudly via `strictPort: true`.
303
+ //
304
+ // For dev (`command === 'serve' && !isPreview`) we start the
305
+ // holding server and use its `listen()` as the probe, pairing
306
+ // the probe with the real bind to eliminate TOCTOU races.
307
+ //
308
+ // For `vite preview` (`command === 'serve' && isPreview`) we
309
+ // resolve the config/env port but delegate the actual bind +
310
+ // auto-bump to Vite's own preview server. Starting the holding
311
+ // server in preview mode would self-conflict because the dev
312
+ // plugin's `configureServer` handoff does not run for preview;
313
+ // the holding server would keep the port occupied while Vite's
314
+ // preview tried to bind the same port.
315
+ //
316
+ // See design/21-dev-server.md §"Default Port and Auto-Bump".
317
+ let resolvedDevPort: number | null = null;
318
+ let resolvedDevPortExplicit = false;
319
+ if (command === 'serve' && !isPreview) {
320
+ ctx.holdingServer = createHoldingServer();
321
+ const holdingRef = ctx.holdingServer;
322
+ const result = await startDevServerPort({
323
+ configPort:
324
+ typeof userConfig.server?.port === 'number' ? userConfig.server.port : undefined,
325
+ envPort: process.env.PORT,
326
+ listen: (p) => holdingRef.listen(p),
327
+ });
328
+ resolvedDevPort = result.port;
329
+ resolvedDevPortExplicit = result.explicit;
330
+ if (!result.bound) {
331
+ // Holding server failed to bind. Drop the reference so the
332
+ // dev-server plugin doesn't try to close a server that was
333
+ // never listening, and let Vite surface the conflict.
334
+ ctx.holdingServer = null;
335
+ }
336
+ } else if (command === 'serve' && isPreview) {
337
+ // Preview mode: resolve the starting port from config/env/
338
+ // default but do NOT probe. Vite's preview server handles the
339
+ // bind itself, with `preview.strictPort` controlling whether
340
+ // an in-use port auto-bumps (implicit) or errors (explicit).
341
+ const previewConfigPort =
342
+ typeof userConfig.preview?.port === 'number'
343
+ ? userConfig.preview.port
344
+ : typeof userConfig.server?.port === 'number'
345
+ ? userConfig.server.port
346
+ : undefined;
347
+ const start = resolveStartPort({
348
+ configPort: previewConfigPort,
349
+ envPort: process.env.PORT,
350
+ });
351
+ resolvedDevPort = start.port;
352
+ resolvedDevPortExplicit = start.explicit;
353
+ }
354
+
355
+ // Return the resolved buildDir as Vite's build.outDir so the RSC
356
+ // plugin and all environment builds write to the correct location.
357
+ // This is always set — either from timber config, Vite config, or default.
358
+ const buildOutDir = timberBuildDir
359
+ ? timberBuildDir
360
+ : viteOutDir && viteOutDir !== 'dist'
361
+ ? viteOutDir
362
+ : DEFAULT_BUILD_DIR;
363
+
364
+ // Set per-environment build.outDir so Vite's RSC plugin writes
365
+ // each environment to the correct subdirectory under our buildDir.
366
+ // Without this, the RSC plugin defaults to dist/<envName> instead
367
+ // of <buildOutDir>/<envName>.
368
+ const envOutDirs: Record<string, { build: { outDir: string } }> = {};
369
+ for (const envName of ['rsc', 'ssr', 'client']) {
370
+ envOutDirs[envName] = { build: { outDir: join(buildOutDir, envName) } };
371
+ }
372
+
380
373
  if (command === 'build') {
381
374
  return {
375
+ build: { outDir: buildOutDir },
376
+ environments: envOutDirs,
382
377
  oxc: {
383
378
  jsx: {
384
379
  development: false,
@@ -386,11 +381,45 @@ export function timber(config?: TimberUserConfig): PluginOption[] {
386
381
  },
387
382
  };
388
383
  }
384
+
385
+ // Dev/preview mode: set outDir so dev-time references are
386
+ // consistent, and surface the resolved port to Vite.
387
+ //
388
+ // For dev, we set strictPort: true so Vite uses exactly the port
389
+ // the holding server probed for — without strictPort, Vite would
390
+ // run its own auto-bump starting from `port`, which would skip
391
+ // straight past whatever holding-server-bumped port we picked.
392
+ //
393
+ // For `vite preview`, we set `preview.strictPort` based on
394
+ // whether the user explicitly set the port. Implicit (default)
395
+ // preview uses strictPort: false so Vite's preview server can
396
+ // auto-bump from 3000. Explicit preview uses strictPort: true
397
+ // so conflicts fail loudly, matching the dev behavior and the
398
+ // TIM-842 spec.
399
+ const serverConfig: { port?: number; strictPort?: boolean } = {};
400
+ const previewConfig: { port?: number; strictPort?: boolean } = {};
401
+ if (resolvedDevPort != null) {
402
+ if (!isPreview) {
403
+ serverConfig.port = resolvedDevPort;
404
+ serverConfig.strictPort = true;
405
+ }
406
+ previewConfig.port = resolvedDevPort;
407
+ previewConfig.strictPort = resolvedDevPortExplicit;
408
+ }
409
+ return {
410
+ build: { outDir: buildOutDir },
411
+ environments: envOutDirs,
412
+ server: serverConfig,
413
+ preview: previewConfig,
414
+ };
389
415
  },
390
416
  configResolved(resolved) {
391
417
  ctx.root = resolved.root;
392
418
  ctx.appDir = resolveAppDir(resolved.root, ctx.config.appDir);
393
419
  ctx.dev = resolved.command === 'serve';
420
+ // Sync buildDir from Vite's resolved build.outDir. Vite keeps
421
+ // outDir as-is (may be relative), so resolve against root.
422
+ ctx.buildDir = resolve(resolved.root, resolved.build.outDir);
394
423
  // In production builds, swap to a no-op timer to avoid overhead
395
424
  if (!ctx.dev) {
396
425
  ctx.timer = createNoopTimer();
@@ -398,19 +427,47 @@ export function timber(config?: TimberUserConfig): PluginOption[] {
398
427
  // Start the overall dev server setup timer — ends in timber-dev-server
399
428
  ctx.timer.start('dev-server-setup');
400
429
  }
430
+
431
+ // Validate config and check peer dependencies at startup.
432
+ // Errors are logged to stderr but don't block startup — Vite may
433
+ // still work partially, and the errors guide the user to fix things.
434
+ const { validateConfig, formatConfigErrors, checkPeerDependencies, formatMissingPeers } =
435
+ require('./config-validation.js') as typeof import('./config-validation.js');
436
+
437
+ const configErrors = validateConfig(ctx.config);
438
+ if (configErrors.length > 0) {
439
+ process.stderr.write(`${formatConfigErrors(configErrors)}\n\n`);
440
+ }
441
+
442
+ const peerResults = checkPeerDependencies(ctx.root);
443
+ const peerWarning = formatMissingPeers(peerResults);
444
+ if (peerWarning) {
445
+ process.stderr.write(`${peerWarning}\n\n`);
446
+ }
401
447
  },
402
448
  };
449
+
450
+ // ── Step 5: Resolve optional plugins ────────────────────────────────
451
+ // React Compiler — resolved eagerly from either inline or file config.
452
+ // Vite's config() hook return type is Omit<UserConfig, 'plugins'>, so
453
+ // plugins MUST be in the top-level array — returning them from config()
454
+ // silently drops them. See TIM-632.
455
+ //
456
+ // Inline config takes precedence. File config (from the early cwd-based
457
+ // load) is used when inline config doesn't set reactCompiler.
458
+ const reactCompilerPlugins: PluginOption[] = [];
459
+ const effectiveReactCompiler = config?.reactCompiler ?? earlyFileConfig?.reactCompiler;
460
+ if (effectiveReactCompiler) {
461
+ reactCompilerPlugins.push(resolveReactCompilerPlugin(effectiveReactCompiler, consumerRequire));
462
+ }
463
+
464
+ // ── Step 6: Assemble plugin array ─────────────────────────────────────
403
465
  // @vitejs/plugin-rsc handles:
404
466
  // - RSC/SSR/client environment setup
405
467
  // - "use client" directive → client reference proxy transformation
406
468
  // - "use server" directive → server reference transformation
407
469
  // - Client reference tracking and module map generation
408
470
  //
409
- // Loaded via dynamic import() because @vitejs/plugin-rsc is ESM-only.
410
- // Vite's config loader uses esbuild to transpile to CJS, which breaks
411
- // static imports of ESM-only packages. The dynamic import() is preserved
412
- // by esbuild and runs natively in ESM at runtime.
413
- //
414
471
  // serverHandler: false — timber has its own dev server (timber-dev-server)
415
472
  // entries — tells the RSC plugin about timber's virtual entry modules so
416
473
  // it correctly wires up the browser entry (needed for React Fast Refresh
@@ -423,30 +480,6 @@ export function timber(config?: TimberUserConfig): PluginOption[] {
423
480
  // We do NOT set customBuildApp — the RSC plugin's orchestration is correct
424
481
  // and handles bundle ordering, asset manifest generation, and environment
425
482
  // imports manifest. See @vitejs/plugin-rsc's buildApp implementation.
426
- // Resolve @vitejs/plugin-rsc from the consumer's project (process.cwd()),
427
- // not from timber's own node_modules. This is critical for pnpm link:
428
- // when linked, timber's node_modules has a separate vite instance, and
429
- // the RSC plugin must use the same vite instance as the dev server.
430
- const consumerRequire = createRequire(join(process.cwd(), 'package.json'));
431
- const rscPluginPath = consumerRequire.resolve('@vitejs/plugin-rsc');
432
- ctx.timer.start('rsc-plugin-import');
433
- const rscPluginsPromise = import(pathToFileURL(rscPluginPath).href).then(
434
- ({ default: vitePluginRsc }) => {
435
- ctx.timer.end('rsc-plugin-import');
436
- return vitePluginRsc({
437
- serverHandler: false,
438
- customClientEntry: true,
439
- entries: {
440
- rsc: 'virtual:timber-rsc-entry',
441
- ssr: 'virtual:timber-ssr-entry',
442
- client: 'virtual:timber-browser-entry',
443
- },
444
- // No custom clientChunks — Rolldown handles natural code splitting.
445
- // See design/27-chunking-strategy.md and LOCAL-337.
446
- });
447
- }
448
- );
449
-
450
483
  return [
451
484
  rootSync,
452
485
  timberReactProd(),
@@ -455,15 +488,14 @@ export function timber(config?: TimberUserConfig): PluginOption[] {
455
488
  // following Vinext's convention — the RSC plugin's virtual browser entry
456
489
  // coordinates with plugin-react via __vite_plugin_react_preamble_installed__.
457
490
  react(),
491
+ ...reactCompilerPlugins,
458
492
  timberServerActionExports(),
459
- rscPluginsPromise,
493
+ vitePluginRsc(createRscOptions(ctx, encryptionKeyExpr)),
460
494
  timberShims(ctx),
461
495
  timberRouting(ctx),
462
496
  timberEntries(ctx),
463
497
  timberBuildManifest(ctx),
464
- timberCache(ctx),
465
498
  timberStaticBuild(ctx),
466
- timberDynamicTransform(ctx),
467
499
  timberFonts(ctx),
468
500
  timberMdx(ctx),
469
501
  timberContent(ctx),
@@ -472,21 +504,9 @@ export function timber(config?: TimberUserConfig): PluginOption[] {
472
504
  timberBuildReport(ctx), // Post-build: route table with bundle sizes
473
505
  timberAdapterBuild(ctx), // Post-build: invoke adapter.buildOutput()
474
506
  timberDevLogs(ctx), // Dev-only: forward server console.* to browser console
507
+ timberDevBrowserLogs(ctx), // Dev-only: forward browser console.* to server terminal
475
508
  timberDevServer(ctx), // Must be last — configureServer post-hook runs after all watchers
476
509
  ];
477
510
  }
478
511
 
479
- /**
480
- * Route map interface — augmented by the generated timber-routes.d.ts.
481
- *
482
- * Each key is a route path pattern. Values have:
483
- * params: shape of URL params (e.g. { id: string })
484
- * searchParams: parsed type from search-params.ts, or {} if none
485
- *
486
- * This interface is empty by default and populated via codegen.
487
- * See design/09-typescript.md §"Typed Routes".
488
- */
489
- // eslint-disable-next-line @typescript-eslint/no-empty-object-type
490
- export interface Routes {}
491
-
492
512
  export default timber;