@timber-js/app 0.2.0-alpha.222 → 0.2.0-alpha.224
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/agent-skill.md +21 -5
- package/dist/_chunks/{actions-vBHr2vqd.js → actions-7dTXYJfu.js} +53 -24
- package/dist/_chunks/actions-7dTXYJfu.js.map +1 -0
- package/dist/_chunks/{als-registry-BZqHCtq-.js → als-registry-DpygwCp0.js} +2 -3
- package/dist/_chunks/{als-registry-BZqHCtq-.js.map → als-registry-DpygwCp0.js.map} +1 -1
- package/dist/_chunks/{als-slots-BEEIPKYm.js → als-slots-kbQrHTzm.js} +2 -3
- package/dist/_chunks/{als-slots-BEEIPKYm.js.map → als-slots-kbQrHTzm.js.map} +1 -1
- package/dist/_chunks/{base-path-DaQrzbez.js → base-path-DDIx0FXe.js} +2 -3
- package/dist/_chunks/{base-path-DaQrzbez.js.map → base-path-DDIx0FXe.js.map} +1 -1
- package/dist/_chunks/{build-manifest-DWppEdLB.js → build-manifest-Y4jl7nwU.js} +2 -3
- package/dist/_chunks/{build-manifest-DWppEdLB.js.map → build-manifest-Y4jl7nwU.js.map} +1 -1
- package/dist/_chunks/{build-output-helper-RV_BRcF1.js → build-output-helper-B7wWGTfR.js} +14 -10
- package/dist/_chunks/build-output-helper-B7wWGTfR.js.map +1 -0
- package/dist/_chunks/{cache-api-DdcDLpBj.js → cache-api-TDZ4hlDc.js} +190 -38
- package/dist/_chunks/cache-api-TDZ4hlDc.js.map +1 -0
- package/dist/_chunks/{canonicalize-BAWkWiKK.js → canonicalize-CqK135BN.js} +29 -4
- package/dist/_chunks/{canonicalize-BAWkWiKK.js.map → canonicalize-CqK135BN.js.map} +1 -1
- package/dist/_chunks/chains-CwOr3Myj.js +1 -0
- package/dist/_chunks/{chains-BchW_AtW.js → chains-Dgm3PrMe.js} +3 -4
- package/dist/_chunks/{chains-BchW_AtW.js.map → chains-Dgm3PrMe.js.map} +1 -1
- package/dist/_chunks/{classify-IqzMpxMs.js → classify--_kINHQV.js} +4 -5
- package/dist/_chunks/{classify-IqzMpxMs.js.map → classify--_kINHQV.js.map} +1 -1
- package/dist/_chunks/{cli-check-DQne_YhU.js → cli-check-Dv3f8d2j.js} +5 -6
- package/dist/_chunks/{cli-check-DQne_YhU.js.map → cli-check-Dv3f8d2j.js.map} +1 -1
- package/dist/_chunks/{cli-context-_mPttGGY.js → cli-context-CbZp32SK.js} +3 -4
- package/dist/_chunks/{cli-context-_mPttGGY.js.map → cli-context-CbZp32SK.js.map} +1 -1
- package/dist/_chunks/cli-context-n5hmkdla.js +1 -0
- package/dist/_chunks/cli-dev-status-prPMLU8G.js +138 -0
- package/dist/_chunks/cli-dev-status-prPMLU8G.js.map +1 -0
- package/dist/_chunks/cli-init-BoXOYYil.js +196 -0
- package/dist/_chunks/cli-init-BoXOYYil.js.map +1 -0
- package/dist/_chunks/{cli-schema-sync-BS-RFGE2.js → cli-schema-sync-DIPurq7X.js} +4 -5
- package/dist/_chunks/{cli-schema-sync-BS-RFGE2.js.map → cli-schema-sync-DIPurq7X.js.map} +1 -1
- package/dist/_chunks/{cli-schema-sync-v872sHms.js → cli-schema-sync-uq72EZmD.js} +1 -1
- package/dist/_chunks/{client-dep-entries-BJyP9SIu.js → client-dep-entries-CP7AkMCM.js} +4 -5
- package/dist/_chunks/{client-dep-entries-BJyP9SIu.js.map → client-dep-entries-CP7AkMCM.js.map} +1 -1
- package/dist/_chunks/{cloudflare-Byxl8FWP.js → cloudflare-B75X6u4O.js} +10 -13
- package/dist/_chunks/{cloudflare-Byxl8FWP.js.map → cloudflare-B75X6u4O.js.map} +1 -1
- package/dist/_chunks/{codec-registry-oOUxugz3.js → codec-registry-CPc6bjVl.js} +2 -3
- package/dist/_chunks/{codec-registry-oOUxugz3.js.map → codec-registry-CPc6bjVl.js.map} +1 -1
- package/dist/_chunks/{codegen-Bps1sLKJ.js → codegen-B9oWkWGf.js} +5 -8
- package/dist/_chunks/{codegen-Bps1sLKJ.js.map → codegen-B9oWkWGf.js.map} +1 -1
- package/dist/_chunks/{convention-lint-VwzrtjIt.js → convention-lint-hZwz5wd4.js} +8 -11
- package/dist/_chunks/{convention-lint-VwzrtjIt.js.map → convention-lint-hZwz5wd4.js.map} +1 -1
- package/dist/_chunks/dev-discovery-YnabkCKD.js +238 -0
- package/dist/_chunks/dev-discovery-YnabkCKD.js.map +1 -0
- package/dist/_chunks/{dev-server-BNr5drEO.js → dev-server-B7o4As0l.js} +383 -55
- package/dist/_chunks/dev-server-B7o4As0l.js.map +1 -0
- package/dist/_chunks/dev-server-hZzmbMvK.js +1 -0
- package/dist/_chunks/{dev-store-BOa304m_.js → dev-store-BvdqtHvK.js} +82 -38
- package/dist/_chunks/dev-store-BvdqtHvK.js.map +1 -0
- package/dist/_chunks/{dist-DtrJyBbw.js → dist-C1Rjlo6s.js} +3 -5
- package/dist/_chunks/{dist-DtrJyBbw.js.map → dist-C1Rjlo6s.js.map} +1 -1
- package/dist/_chunks/{error-boundary-Bc8QPZuq.js → error-boundary-DRQXGWCp.js} +20 -27
- package/dist/_chunks/{error-boundary-Bc8QPZuq.js.map → error-boundary-DRQXGWCp.js.map} +1 -1
- package/dist/_chunks/{fast-hash-C-tVYrLb.js → fast-hash-DddxkU5Y.js} +2 -3
- package/dist/_chunks/{fast-hash-C-tVYrLb.js.map → fast-hash-DddxkU5Y.js.map} +1 -1
- package/dist/_chunks/{flight-source-node-BdHUOUqg.js → flight-source-node-0Tp6evlz.js} +6 -8
- package/dist/_chunks/flight-source-node-0Tp6evlz.js.map +1 -0
- package/dist/_chunks/{format-BKclgVbk.js → format-DuPOoXUP.js} +2 -3
- package/dist/_chunks/{format-BKclgVbk.js.map → format-DuPOoXUP.js.map} +1 -1
- package/dist/_chunks/{fs-identity-BRKuL215.js → fs-identity-BmQ_Agg-.js} +3 -5
- package/dist/_chunks/{fs-identity-BRKuL215.js.map → fs-identity-BmQ_Agg-.js.map} +1 -1
- package/dist/_chunks/{global-context-B9PFncvb.js → global-context-DbxNWeBP.js} +2 -3
- package/dist/_chunks/{global-context-B9PFncvb.js.map → global-context-DbxNWeBP.js.map} +1 -1
- package/dist/_chunks/{graph-cache-CYiUS2aS.js → graph-cache-B1LAg4t7.js} +5 -89
- package/dist/_chunks/graph-cache-B1LAg4t7.js.map +1 -0
- package/dist/_chunks/{href-validation-BIrxavIy.js → href-validation-CEZy1V-k.js} +4 -7
- package/dist/_chunks/{href-validation-BIrxavIy.js.map → href-validation-CEZy1V-k.js.map} +1 -1
- package/dist/_chunks/{json-lossy-check-C3Sht92C.js → json-lossy-check-DVkLUlfC.js} +3 -4
- package/dist/_chunks/{json-lossy-check-C3Sht92C.js.map → json-lossy-check-DVkLUlfC.js.map} +1 -1
- package/dist/_chunks/{live-graph-DEu_GWbc.js → live-graph-BcVjQ1Te.js} +6 -7
- package/dist/_chunks/{live-graph-DEu_GWbc.js.map → live-graph-BcVjQ1Te.js.map} +1 -1
- package/dist/_chunks/{logger-CI_hThfy.js → logger-CWk44DLp.js} +89 -47
- package/dist/_chunks/logger-CWk44DLp.js.map +1 -0
- package/dist/_chunks/{metadata-routes-B3XJNyIH.js → metadata-routes-BL26HCDd.js} +2 -3
- package/dist/_chunks/{metadata-routes-B3XJNyIH.js.map → metadata-routes-BL26HCDd.js.map} +1 -1
- package/dist/_chunks/{navigation-root-BQfo1-kG.js → navigation-root-M3B2ZrdO.js} +6 -10
- package/dist/_chunks/{navigation-root-BQfo1-kG.js.map → navigation-root-M3B2ZrdO.js.map} +1 -1
- package/dist/_chunks/{node-response-bF0bKoig.js → node-response-B9aviPDa.js} +43 -9
- package/dist/_chunks/node-response-B9aviPDa.js.map +1 -0
- package/dist/_chunks/{param-value-C8TNYchQ.js → param-value-DqlGfF57.js} +2 -3
- package/dist/_chunks/{param-value-C8TNYchQ.js.map → param-value-DqlGfF57.js.map} +1 -1
- package/dist/_chunks/{plugin-context-uDHFqHHJ.js → plugin-context-BfSRKJfz.js} +1 -1
- package/dist/_chunks/{plugin-context-DxMMvjUt.js → plugin-context-FCkaNLUB.js} +4 -6
- package/dist/_chunks/plugin-context-FCkaNLUB.js.map +1 -0
- package/dist/_chunks/{poison-rules-DoEhbqaY.js → poison-rules-Bmz-lCPi.js} +2 -3
- package/dist/_chunks/{poison-rules-DoEhbqaY.js.map → poison-rules-Bmz-lCPi.js.map} +1 -1
- package/dist/_chunks/{poison-scan-DTWIfNgD.js → poison-scan-DJYxZc_7.js} +4 -5
- package/dist/_chunks/{poison-scan-DTWIfNgD.js.map → poison-scan-DJYxZc_7.js.map} +1 -1
- package/dist/_chunks/{purge-store-WZaxu-3m.js → purge-store-8BqLAYZ1.js} +2 -3
- package/dist/_chunks/{purge-store-WZaxu-3m.js.map → purge-store-8BqLAYZ1.js.map} +1 -1
- package/dist/_chunks/{render-timeout-Ln_u7fX-.js → render-timeout-MrrqD1wd.js} +2 -3
- package/dist/_chunks/{render-timeout-Ln_u7fX-.js.map → render-timeout-MrrqD1wd.js.map} +1 -1
- package/dist/_chunks/{resolve-schema-CkAInout.js → resolve-schema-B-aCuTu3.js} +3 -4
- package/dist/_chunks/{resolve-schema-CkAInout.js.map → resolve-schema-B-aCuTu3.js.map} +1 -1
- package/dist/_chunks/{rsc-cache-key-ClUiXQnK.js → rsc-cache-key-D0cb0Gmc.js} +2 -3
- package/dist/_chunks/{rsc-cache-key-ClUiXQnK.js.map → rsc-cache-key-D0cb0Gmc.js.map} +1 -1
- package/dist/_chunks/{rsc-media-type-DDc7duTD.js → rsc-media-type-m8jz9u6_.js} +2 -3
- package/dist/_chunks/{rsc-media-type-DDc7duTD.js.map → rsc-media-type-m8jz9u6_.js.map} +1 -1
- package/dist/_chunks/{rsc-payload-path-dffcs4jp.js → rsc-payload-path-EphpDB-J.js} +2 -3
- package/dist/_chunks/{rsc-payload-path-dffcs4jp.js.map → rsc-payload-path-EphpDB-J.js.map} +1 -1
- package/dist/_chunks/{scan-BoP17W3w.js → scan-CyizcBiX.js} +2 -3
- package/dist/_chunks/{scan-BoP17W3w.js.map → scan-CyizcBiX.js.map} +1 -1
- package/dist/_chunks/{scanner-C8fdKvKG.js → scanner-CJC-ScJU.js} +15 -23
- package/dist/_chunks/{scanner-C8fdKvKG.js.map → scanner-CJC-ScJU.js.map} +1 -1
- package/dist/_chunks/{schema-bridge-DpOmvZlI.js → schema-bridge-DyRs3cqy.js} +2 -3
- package/dist/_chunks/{schema-bridge-DpOmvZlI.js.map → schema-bridge-DyRs3cqy.js.map} +1 -1
- package/dist/_chunks/{segment-classify-C539Pa2O.js → segment-classify-Ho8jXWeC.js} +3 -5
- package/dist/_chunks/{segment-classify-C539Pa2O.js.map → segment-classify-Ho8jXWeC.js.map} +1 -1
- package/dist/_chunks/{segment-context-D3DNxKFq.js → segment-context-CYiGTi3K.js} +4 -6
- package/dist/_chunks/{segment-context-D3DNxKFq.js.map → segment-context-CYiGTi3K.js.map} +1 -1
- package/dist/_chunks/{segment-keys-D5hu1hz4.js → segment-keys-Y60KNc8C.js} +2 -3
- package/dist/_chunks/{segment-keys-D5hu1hz4.js.map → segment-keys-Y60KNc8C.js.map} +1 -1
- package/dist/_chunks/{singleflight-BeVMMKi0.js → singleflight-BChPMjwH.js} +2 -3
- package/dist/_chunks/{singleflight-BeVMMKi0.js.map → singleflight-BChPMjwH.js.map} +1 -1
- package/dist/_chunks/{sizeof-CO3dk0V1.js → sizeof-DG4W40lv.js} +3 -4
- package/dist/_chunks/{sizeof-CO3dk0V1.js.map → sizeof-DG4W40lv.js.map} +1 -1
- package/dist/_chunks/{ssr-data-nA3I70_n.js → ssr-data-9hPtcNOr.js} +3 -4
- package/dist/_chunks/{ssr-data-nA3I70_n.js.map → ssr-data-9hPtcNOr.js.map} +1 -1
- package/dist/_chunks/{state-BhNGPsdi.js → state-B-EBjeER.js} +2 -3
- package/dist/_chunks/{state-BhNGPsdi.js.map → state-B-EBjeER.js.map} +1 -1
- package/dist/_chunks/{status-page-marker-BRX9Ib-d.js → status-page-marker-XIQXlTOb.js} +8 -13
- package/dist/_chunks/{status-page-marker-BRX9Ib-d.js.map → status-page-marker-XIQXlTOb.js.map} +1 -1
- package/dist/_chunks/{tree-match-6yihorhk.js → tree-match-Bqdr9szG.js} +2 -3
- package/dist/_chunks/{tree-match-6yihorhk.js.map → tree-match-Bqdr9szG.js.map} +1 -1
- package/dist/_chunks/{use-query-states-I3JMng6J.js → use-query-states-pkDV-jSg.js} +4 -7
- package/dist/_chunks/{use-query-states-I3JMng6J.js.map → use-query-states-pkDV-jSg.js.map} +1 -1
- package/dist/_chunks/{walkers-BqzxnwGC.js → walkers-DIE203ir.js} +6 -8
- package/dist/_chunks/{walkers-BqzxnwGC.js.map → walkers-DIE203ir.js.map} +1 -1
- package/dist/_chunks/{write-file-atomic-D1qWqHb4.js → write-file-atomic-DW8m_Atv.js} +2 -3
- package/dist/_chunks/{write-file-atomic-D1qWqHb4.js.map → write-file-atomic-DW8m_Atv.js.map} +1 -1
- package/dist/adapters/build-output-helper.d.ts +10 -1
- package/dist/adapters/build-output-helper.d.ts.map +1 -1
- package/dist/adapters/cloudflare-dev.js +2 -3
- package/dist/adapters/cloudflare-kv-cache.js +3 -4
- package/dist/adapters/cloudflare.d.ts.map +1 -1
- package/dist/adapters/cloudflare.js +1 -1
- package/dist/adapters/nitro-presets.d.ts +6 -0
- package/dist/adapters/nitro-presets.d.ts.map +1 -1
- package/dist/adapters/nitro-preview.d.ts.map +1 -1
- package/dist/adapters/nitro.d.ts.map +1 -1
- package/dist/adapters/nitro.js +94 -57
- package/dist/adapters/nitro.js.map +1 -1
- package/dist/analyze/crawl-entry.js +7 -9
- package/dist/analyze/crawl-entry.js.map +1 -1
- package/dist/analyze/graph-command.d.ts.map +1 -1
- package/dist/analyze/graph-command.js +19 -105
- package/dist/analyze/graph-command.js.map +1 -1
- package/dist/cache/index.js +3 -3
- package/dist/cache/key-discipline.d.ts +61 -0
- package/dist/cache/key-discipline.d.ts.map +1 -0
- package/dist/cache/stores/cloudflare-kv.js +1 -2
- package/dist/cache/stores/memory.js +2 -3
- package/dist/cache/stores/redis.js +1 -2
- package/dist/cache/stores/vercel.js +1 -2
- package/dist/cache/timber-cache.d.ts +5 -1
- package/dist/cache/timber-cache.d.ts.map +1 -1
- package/dist/cdn/cloudflare-purge.js +1 -2
- package/dist/cdn/fastly-purge.js +1 -2
- package/dist/cdn/index.js +2 -3
- package/dist/cdn/workers-cache-purge.js +3 -5
- package/dist/cdn/workers-cache-purge.js.map +1 -1
- package/dist/cli-dev-status.d.ts +75 -0
- package/dist/cli-dev-status.d.ts.map +1 -0
- package/dist/cli-init.d.ts +72 -0
- package/dist/cli-init.d.ts.map +1 -0
- package/dist/cli.d.ts +4 -12
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +27 -54
- package/dist/cli.js.map +1 -1
- package/dist/client/error-boundary.d.ts.map +1 -1
- package/dist/client/error-boundary.js +1 -1
- package/dist/client/index.js +22 -34
- package/dist/client/index.js.map +1 -1
- package/dist/client/internal.js +13 -18
- package/dist/client/internal.js.map +1 -1
- package/dist/client/use-cookie.d.ts +18 -5
- package/dist/client/use-cookie.d.ts.map +1 -1
- package/dist/codec.js +2 -3
- package/dist/config-types.d.ts +40 -5
- package/dist/config-types.d.ts.map +1 -1
- package/dist/config-validation.d.ts.map +1 -1
- package/dist/cookies/define-cookie.d.ts.map +1 -1
- package/dist/cookies/index.js +40 -67
- package/dist/cookies/index.js.map +1 -1
- package/dist/cookies/json-cookie.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +698 -237
- package/dist/index.js.map +1 -1
- package/dist/params/index.js +3 -4
- package/dist/plugin-context.d.ts +7 -0
- package/dist/plugin-context.d.ts.map +1 -1
- package/dist/plugins/dev-discovery.d.ts +69 -5
- package/dist/plugins/dev-discovery.d.ts.map +1 -1
- package/dist/plugins/dev-hostname.d.ts +152 -0
- package/dist/plugins/dev-hostname.d.ts.map +1 -0
- package/dist/plugins/dev-server.d.ts +5 -1
- package/dist/plugins/dev-server.d.ts.map +1 -1
- package/dist/plugins/dev-store-clear.d.ts +59 -4
- package/dist/plugins/dev-store-clear.d.ts.map +1 -1
- package/dist/plugins/graph-endpoint.d.ts +4 -2
- package/dist/plugins/graph-endpoint.d.ts.map +1 -1
- package/dist/plugins/optimize-package-imports-defaults.d.ts +13 -0
- package/dist/plugins/optimize-package-imports-defaults.d.ts.map +1 -0
- package/dist/plugins/optimize-package-imports.d.ts +113 -0
- package/dist/plugins/optimize-package-imports.d.ts.map +1 -0
- package/dist/plugins/prebuilt.d.ts.map +1 -1
- package/dist/routing/index.js +4 -4
- package/dist/rsc-runtime/rsc.d.ts +2 -1
- package/dist/rsc-runtime/rsc.d.ts.map +1 -1
- package/dist/rsc-runtime/server-references.d.ts +8 -0
- package/dist/rsc-runtime/server-references.d.ts.map +1 -0
- package/dist/search-params/index.js +5 -7
- package/dist/search-params/index.js.map +1 -1
- package/dist/server/access-gate.d.ts +12 -0
- package/dist/server/access-gate.d.ts.map +1 -1
- package/dist/server/canonicalize.d.ts +21 -0
- package/dist/server/canonicalize.d.ts.map +1 -1
- package/dist/server/cookie-context.d.ts +8 -1
- package/dist/server/cookie-context.d.ts.map +1 -1
- package/dist/server/flight-source-node.d.ts.map +1 -1
- package/dist/server/flight-source.d.ts.map +1 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +8 -13
- package/dist/server/index.js.map +1 -1
- package/dist/server/interception-gates.d.ts +49 -0
- package/dist/server/interception-gates.d.ts.map +1 -0
- package/dist/server/internal.js +1061 -943
- package/dist/server/internal.js.map +1 -1
- package/dist/server/logger.d.ts +17 -0
- package/dist/server/logger.d.ts.map +1 -1
- package/dist/server/param-coercion.d.ts +8 -0
- package/dist/server/param-coercion.d.ts.map +1 -1
- package/dist/server/pipeline-interception.d.ts +34 -4
- package/dist/server/pipeline-interception.d.ts.map +1 -1
- package/dist/server/pipeline-metadata-route.d.ts +24 -0
- package/dist/server/pipeline-metadata-route.d.ts.map +1 -0
- package/dist/server/pipeline-metadata.d.ts +3 -2
- package/dist/server/pipeline-metadata.d.ts.map +1 -1
- package/dist/server/pipeline-phases.d.ts +9 -3
- package/dist/server/pipeline-phases.d.ts.map +1 -1
- package/dist/server/pipeline.d.ts +18 -0
- package/dist/server/pipeline.d.ts.map +1 -1
- package/dist/server/prebuilt/dev-store.d.ts +68 -22
- package/dist/server/prebuilt/dev-store.d.ts.map +1 -1
- package/dist/server/prebuilt/overlay.d.ts +8 -0
- package/dist/server/prebuilt/overlay.d.ts.map +1 -1
- package/dist/server/prebuilt-runtime.d.ts.map +1 -1
- package/dist/server/primitives.d.ts +13 -0
- package/dist/server/primitives.d.ts.map +1 -1
- package/dist/server/render-utils.d.ts +21 -0
- package/dist/server/render-utils.d.ts.map +1 -1
- package/dist/server/request-context.d.ts +14 -0
- package/dist/server/request-context.d.ts.map +1 -1
- package/dist/server/route-element-builder.d.ts.map +1 -1
- package/dist/server/route-handler.d.ts +7 -0
- package/dist/server/route-handler.d.ts.map +1 -1
- package/dist/server/route-matcher.d.ts +14 -3
- package/dist/server/route-matcher.d.ts.map +1 -1
- package/dist/server/rsc-entry/api-handler.d.ts.map +1 -1
- package/dist/server/rsc-entry/index.d.ts.map +1 -1
- package/dist/server/rsc-entry/rsc-stream.d.ts.map +1 -1
- package/dist/server/signal-identity.d.ts +6 -0
- package/dist/server/signal-identity.d.ts.map +1 -1
- package/dist/server/traced-access.d.ts +18 -0
- package/dist/server/traced-access.d.ts.map +1 -0
- package/dist/server/tracing.d.ts.map +1 -1
- package/dist/server/types.d.ts +5 -4
- package/dist/server/types.d.ts.map +1 -1
- package/dist/shims/font-google.js +1 -2
- package/dist/shims/font-local.js +1 -2
- package/dist/shims/headers.d.ts +11 -4
- package/dist/shims/headers.d.ts.map +1 -1
- package/docs/api/30-api-server.mdx +3 -1
- package/docs/api/32-api-cache.mdx +1 -1
- package/docs/api/34-api-config.mdx +42 -0
- package/docs/api/36-cli.mdx +72 -6
- package/docs/learn/01-quick-start.mdx +1 -1
- package/docs/learn/06-typed-params.mdx +2 -2
- package/docs/learn/10-caching.mdx +26 -5
- package/llms.txt +1 -1
- package/package.json +12 -12
- package/src/adapters/build-output-helper.ts +26 -4
- package/src/adapters/cloudflare.ts +1 -0
- package/src/adapters/nitro-presets.ts +15 -0
- package/src/adapters/nitro-preview.ts +66 -34
- package/src/adapters/nitro.ts +14 -6
- package/src/analyze/graph-command.ts +25 -133
- package/src/cache/key-discipline.ts +218 -0
- package/src/cache/timber-cache.ts +42 -5
- package/src/cli-dev-status.ts +196 -0
- package/src/cli-init.ts +278 -0
- package/src/cli.ts +33 -79
- package/src/client/error-boundary.tsx +19 -2
- package/src/client/use-cookie.ts +33 -21
- package/src/config-types.ts +40 -5
- package/src/config-validation.ts +37 -0
- package/src/cookies/define-cookie.ts +10 -46
- package/src/cookies/json-cookie.ts +4 -4
- package/src/index.ts +2 -0
- package/src/plugin-context.ts +7 -0
- package/src/plugins/dev-discovery.ts +216 -6
- package/src/plugins/dev-hostname.ts +322 -0
- package/src/plugins/dev-server.ts +96 -37
- package/src/plugins/dev-store-clear.ts +105 -7
- package/src/plugins/graph-endpoint.ts +15 -3
- package/src/plugins/optimize-package-imports-defaults.ts +88 -0
- package/src/plugins/optimize-package-imports.ts +439 -0
- package/src/plugins/prebuilt.ts +9 -0
- package/src/rsc-runtime/rsc.ts +7 -3
- package/src/rsc-runtime/server-references.ts +73 -0
- package/src/rsc-runtime/vendor-types.d.ts +9 -0
- package/src/server/access-gate.tsx +32 -20
- package/src/server/action-handler.ts +40 -34
- package/src/server/canonicalize.ts +27 -0
- package/src/server/cookie-context.ts +11 -3
- package/src/server/flight-source-node.ts +5 -2
- package/src/server/flight-source.ts +4 -3
- package/src/server/index.ts +6 -1
- package/src/server/interception-gates.ts +94 -0
- package/src/server/logger.ts +23 -0
- package/src/server/param-coercion.ts +22 -0
- package/src/server/pipeline-interception.ts +64 -4
- package/src/server/pipeline-metadata-route.ts +242 -0
- package/src/server/pipeline-metadata.ts +7 -5
- package/src/server/pipeline-phases.ts +71 -131
- package/src/server/pipeline.ts +20 -2
- package/src/server/prebuilt/dev-store.ts +113 -34
- package/src/server/prebuilt/overlay.ts +18 -0
- package/src/server/prebuilt-runtime.ts +43 -44
- package/src/server/primitives.ts +14 -0
- package/src/server/render-utils.ts +25 -0
- package/src/server/request-context.ts +27 -3
- package/src/server/route-element-builder.ts +15 -2
- package/src/server/route-handler.ts +3 -2
- package/src/server/route-matcher.ts +48 -33
- package/src/server/rsc-entry/api-handler.ts +2 -33
- package/src/server/rsc-entry/index.ts +8 -3
- package/src/server/rsc-entry/rsc-stream.ts +7 -1
- package/src/server/signal-identity.ts +30 -12
- package/src/server/traced-access.ts +50 -0
- package/src/server/tracing.ts +18 -1
- package/src/server/types.ts +5 -4
- package/src/shims/headers.ts +12 -4
- package/dist/_chunks/actions-vBHr2vqd.js.map +0 -1
- package/dist/_chunks/build-output-helper-RV_BRcF1.js.map +0 -1
- package/dist/_chunks/cache-api-DdcDLpBj.js.map +0 -1
- package/dist/_chunks/chains-B8TCLved.js +0 -1
- package/dist/_chunks/cli-context-BJQB6rtF.js +0 -1
- package/dist/_chunks/dev-server-BNr5drEO.js.map +0 -1
- package/dist/_chunks/dev-server-CUg7Mqh_.js +0 -1
- package/dist/_chunks/dev-store-BOa304m_.js.map +0 -1
- package/dist/_chunks/flight-source-node-BdHUOUqg.js.map +0 -1
- package/dist/_chunks/graph-cache-CYiUS2aS.js.map +0 -1
- package/dist/_chunks/logger-CI_hThfy.js.map +0 -1
- package/dist/_chunks/node-response-bF0bKoig.js.map +0 -1
- package/dist/_chunks/plugin-context-DxMMvjUt.js.map +0 -1
- package/dist/server/prebuilt/key-discipline.d.ts +0 -52
- package/dist/server/prebuilt/key-discipline.d.ts.map +0 -1
- package/src/server/prebuilt/key-discipline.ts +0 -122
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Key-discipline diagnostic for both cache tiers (design/45 §Enforcement).
|
|
3
|
+
*
|
|
4
|
+
* A cached value is stored under a key computed from declared inputs only —
|
|
5
|
+
* props and segment params for `cache.component`, the function's arguments
|
|
6
|
+
* for `cache.data`. A request-context read while the value is being computed
|
|
7
|
+
* is the data-leak danger zone (design/06 security note): the result varies
|
|
8
|
+
* by user but the key does not. While the cached work runs, the ALS store is
|
|
9
|
+
* wrapped in a transparent observing proxy; any request-context read
|
|
10
|
+
* produces a structured, rate-limited production diagnostic.
|
|
11
|
+
*
|
|
12
|
+
* The diagnostic fires per offending callsite, rate-limited to once per
|
|
13
|
+
* interval (default 60 s) — not once per process. This ensures the
|
|
14
|
+
* signal stays visible in log aggregators across restarts and deploys.
|
|
15
|
+
*
|
|
16
|
+
* When `strictKeyDiscipline` is enabled (via timber.config.ts
|
|
17
|
+
* `cache.strictKeyDiscipline: true`), the diagnostic is promoted to a
|
|
18
|
+
* thrown error that prevents the tainted value from being cached.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { requestContextAls, type RequestContextStore } from '../server/als-registry.ts';
|
|
22
|
+
import { logKeyDisciplineViolation } from '../server/logger.ts';
|
|
23
|
+
|
|
24
|
+
/** Store fields every tier's key leaves out, by the API that reads them. */
|
|
25
|
+
const REQUEST_FIELDS: ReadonlyMap<PropertyKey, string> = new Map([
|
|
26
|
+
['headers', 'headers()'],
|
|
27
|
+
['parsedCookies', 'cookies()'],
|
|
28
|
+
['searchParams', 'searchParams'],
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The data tier also leaves out segment params: a cache.component key
|
|
33
|
+
* includes them, a cache.data key holds only the function's arguments.
|
|
34
|
+
*/
|
|
35
|
+
const DATA_TIER_FIELDS: ReadonlyMap<PropertyKey, string> = new Map([
|
|
36
|
+
...REQUEST_FIELDS,
|
|
37
|
+
['segmentParams', 'segment params'],
|
|
38
|
+
['slotParams', 'segment params'],
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
/** Which cache tier a callsite belongs to — selects the diagnostic wording. */
|
|
42
|
+
export type KeyDisciplineTier = 'cache.component' | 'cache.data';
|
|
43
|
+
|
|
44
|
+
/** A cached callsite whose work is observed for request-context reads. */
|
|
45
|
+
export interface KeyDisciplineSite {
|
|
46
|
+
tier: KeyDisciplineTier;
|
|
47
|
+
/** Stable id of the callsite — the rate-limit key within its tier. */
|
|
48
|
+
id: string;
|
|
49
|
+
/** Human-readable name for the message; defaults to the id. */
|
|
50
|
+
label?: string;
|
|
51
|
+
/** The cache key this call computed — logged so the entry can be found. */
|
|
52
|
+
cacheKey?: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface TierRules {
|
|
56
|
+
/** Store fields whose read is a violation, mapped to the API name logged. */
|
|
57
|
+
observed: ReadonlyMap<PropertyKey, string>;
|
|
58
|
+
keyedBy: string;
|
|
59
|
+
passAs: string;
|
|
60
|
+
work: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const TIERS: Record<KeyDisciplineTier, TierRules> = {
|
|
64
|
+
'cache.component': {
|
|
65
|
+
observed: REQUEST_FIELDS,
|
|
66
|
+
keyedBy: 'props and segment params',
|
|
67
|
+
passAs: 'as props',
|
|
68
|
+
work: 'a cache capture render',
|
|
69
|
+
},
|
|
70
|
+
'cache.data': {
|
|
71
|
+
observed: DATA_TIER_FIELDS,
|
|
72
|
+
keyedBy: "the function's arguments",
|
|
73
|
+
passAs: 'as an argument',
|
|
74
|
+
work: 'a cached call',
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/** Rate-limit interval: one diagnostic per callsite per 60 seconds. */
|
|
79
|
+
const RATE_LIMIT_MS = 60_000;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Last emission timestamp per `${tier}:${id}`. Past this many entries,
|
|
83
|
+
* ones whose window has elapsed are pruned — an untransformed callsite
|
|
84
|
+
* re-created per request gets a fresh fallback id each time.
|
|
85
|
+
*/
|
|
86
|
+
const lastEmitted = new Map<string, number>();
|
|
87
|
+
const PRUNE_AT = 1_000;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Thrown in strict mode. A distinct class so a caller holding an earlier
|
|
91
|
+
* result computed by the same fn (a stale SWR entry) can drop it.
|
|
92
|
+
*/
|
|
93
|
+
export class KeyDisciplineViolation extends Error {
|
|
94
|
+
override name = 'KeyDisciplineViolation';
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
let strict = false;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Configure strict key-discipline mode. When true, a violation throws
|
|
101
|
+
* instead of logging — the tainted value is never cached.
|
|
102
|
+
* Called at boot from the RSC entry with the resolved config value.
|
|
103
|
+
*/
|
|
104
|
+
export function setKeyDisciplineStrict(enabled: boolean): void {
|
|
105
|
+
strict = enabled;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Run a cached callsite's work under the observing proxy, then report any
|
|
110
|
+
* request-context read it made. The proxy is transparent — it forwards all
|
|
111
|
+
* reads and writes; it only observes.
|
|
112
|
+
*
|
|
113
|
+
* Outside a request context `run` executes as-is: there is nothing to read,
|
|
114
|
+
* and cache.data must keep working there. In default mode a callsite that
|
|
115
|
+
* reported within the rate-limit window is not observed at all. In strict
|
|
116
|
+
* mode a violation rejects after `run` resolves, so the caller never stores
|
|
117
|
+
* the value.
|
|
118
|
+
*/
|
|
119
|
+
export async function observeKeyDiscipline<T>(
|
|
120
|
+
site: KeyDisciplineSite,
|
|
121
|
+
run: () => Promise<T>
|
|
122
|
+
): Promise<T> {
|
|
123
|
+
const store = requestContextAls.getStore();
|
|
124
|
+
if (!store || !shouldCheck(site)) return run();
|
|
125
|
+
|
|
126
|
+
const { proxy, accessedApis } = createObservingProxy(store, TIERS[site.tier].observed);
|
|
127
|
+
const result = await requestContextAls.run(proxy, run);
|
|
128
|
+
if (accessedApis.size > 0) reportViolation(site, accessedApis);
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function rateLimitKey(site: KeyDisciplineSite): string {
|
|
133
|
+
return `${site.tier}:${site.id}`;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Whether to observe this callsite on this call. Always in strict mode;
|
|
138
|
+
* otherwise only once the rate-limit window since its last report elapsed.
|
|
139
|
+
*/
|
|
140
|
+
function shouldCheck(site: KeyDisciplineSite): boolean {
|
|
141
|
+
if (strict) return true;
|
|
142
|
+
const last = lastEmitted.get(rateLimitKey(site));
|
|
143
|
+
if (last === undefined) return true;
|
|
144
|
+
return Date.now() - last >= RATE_LIMIT_MS;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function createObservingProxy(
|
|
148
|
+
store: RequestContextStore,
|
|
149
|
+
observed: ReadonlyMap<PropertyKey, string>
|
|
150
|
+
): {
|
|
151
|
+
proxy: RequestContextStore;
|
|
152
|
+
accessedApis: Set<string>;
|
|
153
|
+
} {
|
|
154
|
+
const accessedApis = new Set<string>();
|
|
155
|
+
const proxy = new Proxy(store, {
|
|
156
|
+
get(target, prop, receiver) {
|
|
157
|
+
// A Map, not an object literal: `constructor` or `toString` read
|
|
158
|
+
// off the store must not count as a request-context read.
|
|
159
|
+
const api = observed.get(prop);
|
|
160
|
+
if (api) accessedApis.add(api);
|
|
161
|
+
return Reflect.get(target, prop, receiver);
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
return { proxy, accessedApis };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Throw in strict mode; otherwise emit a structured error-level diagnostic
|
|
169
|
+
* through the logger (same path as render errors), rate-limited per callsite.
|
|
170
|
+
*/
|
|
171
|
+
function reportViolation(site: KeyDisciplineSite, apis: Set<string>): void {
|
|
172
|
+
const { tier, id } = site;
|
|
173
|
+
const name = site.label ?? id;
|
|
174
|
+
const apiList = Array.from(apis).join(', ');
|
|
175
|
+
const wording = TIERS[tier];
|
|
176
|
+
const remedy =
|
|
177
|
+
`Either pass request-derived values ${wording.passAs} (included in the ` +
|
|
178
|
+
`cache key) or remove the ${apiList} call.`;
|
|
179
|
+
|
|
180
|
+
if (strict) {
|
|
181
|
+
throw new KeyDisciplineViolation(
|
|
182
|
+
`[timber] ${tier} key-discipline violation: "${name}" reads ${apiList} ` +
|
|
183
|
+
`during ${wording.work}. The cache key is computed from ` +
|
|
184
|
+
`${wording.keyedBy} only — caching this result would serve one ` +
|
|
185
|
+
`user's data to another. ${remedy} ` +
|
|
186
|
+
`To downgrade this to a warning, set cache.strictKeyDiscipline: false ` +
|
|
187
|
+
`in timber.config.ts.`
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const now = Date.now();
|
|
192
|
+
const key = rateLimitKey(site);
|
|
193
|
+
const last = lastEmitted.get(key);
|
|
194
|
+
if (last !== undefined && now - last < RATE_LIMIT_MS) return;
|
|
195
|
+
if (lastEmitted.size >= PRUNE_AT) {
|
|
196
|
+
for (const [k, t] of lastEmitted) if (now - t >= RATE_LIMIT_MS) lastEmitted.delete(k);
|
|
197
|
+
}
|
|
198
|
+
lastEmitted.set(key, now);
|
|
199
|
+
|
|
200
|
+
logKeyDisciplineViolation(`${tier} cross-user data leak risk`, {
|
|
201
|
+
...(tier === 'cache.component'
|
|
202
|
+
? { component: name }
|
|
203
|
+
: { fn: name, id, cacheKey: site.cacheKey }),
|
|
204
|
+
accessedApis: Array.from(apis),
|
|
205
|
+
message:
|
|
206
|
+
`${tier} "${name}" reads ${apiList} but the cache key is computed ` +
|
|
207
|
+
`from ${wording.keyedBy} only. If the result varies by ${apiList}, ` +
|
|
208
|
+
`different users may see each other's cached data. ${remedy}`,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Reset all diagnostic state. Exported for tests only.
|
|
214
|
+
*/
|
|
215
|
+
export function resetKeyDisciplineState(): void {
|
|
216
|
+
lastEmitted.clear();
|
|
217
|
+
strict = false;
|
|
218
|
+
}
|
|
@@ -12,6 +12,7 @@ import { guardedRead } from './guarded-read.ts';
|
|
|
12
12
|
import { getWaitUntil } from '../server/waituntil-bridge.ts';
|
|
13
13
|
import { fnv1aHash } from './fast-hash.ts';
|
|
14
14
|
import { devDataCacheKey } from '../server/prebuilt/dev-store.ts';
|
|
15
|
+
import { KeyDisciplineViolation, observeKeyDiscipline } from './key-discipline.ts';
|
|
15
16
|
|
|
16
17
|
let defaultSingleflight = createSingleflight();
|
|
17
18
|
|
|
@@ -123,7 +124,11 @@ function deriveFallbackFnId(fn: (...args: any[]) => any): string {
|
|
|
123
124
|
* configured handler once it arrives (TIM-1029)
|
|
124
125
|
* - No ALS dependency for correctness — cache() works outside a request
|
|
125
126
|
* context. The waitUntil ALS bridge is read optionally so the SWR
|
|
126
|
-
* background refetch survives handler return on Workers/Lambda
|
|
127
|
+
* background refetch survives handler return on Workers/Lambda, and
|
|
128
|
+
* inside one, fn runs under the key-discipline observer (design/45
|
|
129
|
+
* §Enforcement): the key comes from the arguments only, so a
|
|
130
|
+
* request-context read in fn is reported, or rejected in strict mode
|
|
131
|
+
* before the result is stored.
|
|
127
132
|
*
|
|
128
133
|
* Cache hits/misses are recorded as OTEL span events on the enclosing
|
|
129
134
|
* span (not child spans). The DevSpanProcessor reads these for dev log output.
|
|
@@ -138,6 +143,10 @@ export function createCache<Fn extends (...args: any[]) => Promise<any>>(
|
|
|
138
143
|
// With an explicit `key` option the fnId never reaches key generation, so
|
|
139
144
|
// no fallback derivation (or warning) is needed in that case.
|
|
140
145
|
const fnId = stableId ?? (opts.key ? undefined : deriveFallbackFnId(fn));
|
|
146
|
+
// Key-discipline rate-limit id. An explicit-key callsite without a
|
|
147
|
+
// build-time ID has no fnId; its source hash is stable enough for a
|
|
148
|
+
// rate limit and, unlike deriveFallbackFnId, never warns.
|
|
149
|
+
const disciplineId = fnId ?? `key-fn:${fnv1aHash(fn.toString())}`;
|
|
141
150
|
|
|
142
151
|
// Per-call timeoutMs gets a dedicated singleflight instance. Otherwise
|
|
143
152
|
// resolve defaultSingleflight per invocation (not captured at creation
|
|
@@ -175,9 +184,11 @@ export function createCache<Fn extends (...args: any[]) => Promise<any>>(
|
|
|
175
184
|
// key/tags: a caller arriving after an invalidation must not coalesce
|
|
176
185
|
// onto a flight that started before it — it would receive the
|
|
177
186
|
// pre-invalidation result the invalidation was issued to discard.
|
|
178
|
-
// NUL separator: cannot collide with user-provided key strings.
|
|
187
|
+
// NUL separator: cannot collide with user-provided key strings. The
|
|
188
|
+
// store key, not the logical key: in dev it carries the source
|
|
189
|
+
// generation, so a caller after a save never joins a pre-save flight.
|
|
179
190
|
const tags = resolveTags(opts, args);
|
|
180
|
-
const flightKey = `${
|
|
191
|
+
const flightKey = `${storeKey}\u0000${lastInvalidationEpochFor(key, tags)}`;
|
|
181
192
|
|
|
182
193
|
/**
|
|
183
194
|
* Run fn and store the result — exactly once per coalesced execution,
|
|
@@ -192,7 +203,32 @@ export function createCache<Fn extends (...args: any[]) => Promise<any>>(
|
|
|
192
203
|
const executeAndStore = async (signal: AbortSignal): Promise<Awaited<ReturnType<Fn>>> => {
|
|
193
204
|
const startEpoch = currentInvalidationEpoch();
|
|
194
205
|
const generation = nextGeneration(key);
|
|
195
|
-
|
|
206
|
+
// Observed on every execution — the miss path and the SWR refetch,
|
|
207
|
+
// which runs in the triggering request's context. Never on a hit:
|
|
208
|
+
// a hit runs no fn, so it reads nothing.
|
|
209
|
+
let result: Awaited<ReturnType<Fn>>;
|
|
210
|
+
try {
|
|
211
|
+
result = await observeKeyDiscipline(
|
|
212
|
+
{ tier: 'cache.data', id: disciplineId, label: fn.name || undefined, cacheKey: key },
|
|
213
|
+
() => fn(...args)
|
|
214
|
+
);
|
|
215
|
+
} catch (err) {
|
|
216
|
+
// Strict key discipline rejected this fn, so any entry already
|
|
217
|
+
// under the key was computed by the same request-reading fn (stored
|
|
218
|
+
// before strict mode was on). Drop it rather than serve it to
|
|
219
|
+
// everyone as stale — but only under the same guards as a write: a
|
|
220
|
+
// timed-out or superseded flight must not delete a newer result.
|
|
221
|
+
if (
|
|
222
|
+
err instanceof KeyDisciplineViolation &&
|
|
223
|
+
!signal.aborted &&
|
|
224
|
+
writeGenerations.get(key) === generation
|
|
225
|
+
) {
|
|
226
|
+
await getHandler()
|
|
227
|
+
.invalidate({ key: storeKey })
|
|
228
|
+
.catch((e: unknown) => swallow(e, `cache invalidate failed for key "${key}"`));
|
|
229
|
+
}
|
|
230
|
+
throw err;
|
|
231
|
+
}
|
|
196
232
|
if (!signal.aborted && !wasInvalidatedSince(startEpoch, key, tags)) {
|
|
197
233
|
try {
|
|
198
234
|
await getHandler().set(storeKey, result, { ttl: opts.ttl, tags, generation });
|
|
@@ -220,7 +256,8 @@ export function createCache<Fn extends (...args: any[]) => Promise<any>>(
|
|
|
220
256
|
try {
|
|
221
257
|
await executeAndStore(signal);
|
|
222
258
|
} catch (err) {
|
|
223
|
-
// Failed refetch — stale entry continues to be served
|
|
259
|
+
// Failed refetch — stale entry continues to be served (unless
|
|
260
|
+
// executeAndStore dropped it for a key-discipline violation).
|
|
224
261
|
logSwrRefetchFailed({ cacheKey: key, error: err });
|
|
225
262
|
}
|
|
226
263
|
})
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `timber dev status [--json]` — which dev servers are running for this app.
|
|
3
|
+
*
|
|
4
|
+
* The agent-facing answer to "is a dev server already up?" Agents that
|
|
5
|
+
* skip the question start a second server, Vite bumps it to the next
|
|
6
|
+
* port, and the agent then tests a different server than the one the user
|
|
7
|
+
* is watching.
|
|
8
|
+
*
|
|
9
|
+
* Servers are found through their discovery records (plugins/dev-discovery.ts)
|
|
10
|
+
* and listed only after the full validation: pid alive AND the server
|
|
11
|
+
* answers the status probe with that pid. The record format stays private;
|
|
12
|
+
* this command is the public contract.
|
|
13
|
+
*
|
|
14
|
+
* Worktree-aware: `.timber/` is gitignored, so each git worktree has its own
|
|
15
|
+
* records. A server in another worktree serves that worktree's code — never
|
|
16
|
+
* reuse it — but it may be holding the port this checkout would have taken,
|
|
17
|
+
* so it is reported separately.
|
|
18
|
+
*
|
|
19
|
+
* See design/21-dev-server.md §"`timber dev status`".
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { execFile } from 'node:child_process';
|
|
23
|
+
import { realpath } from 'node:fs/promises';
|
|
24
|
+
import { dirname, join, relative, resolve } from 'node:path';
|
|
25
|
+
import { promisify } from 'node:util';
|
|
26
|
+
import { readLiveDevRecords, type DevRecord } from './plugins/dev-discovery.ts';
|
|
27
|
+
|
|
28
|
+
const execFileAsync = promisify(execFile);
|
|
29
|
+
|
|
30
|
+
/** `git` must answer fast or not at all — not being a repo is normal. */
|
|
31
|
+
const GIT_TIMEOUT_MS = 2_000;
|
|
32
|
+
|
|
33
|
+
/** Bumped only on a breaking change to the `--json` shape. */
|
|
34
|
+
export const DEV_STATUS_JSON_VERSION = 1;
|
|
35
|
+
|
|
36
|
+
export interface DevStatusServer {
|
|
37
|
+
/** The URL the server printed — open this in a browser (`http://blog.localhost:3000/`). */
|
|
38
|
+
url: string;
|
|
39
|
+
/**
|
|
40
|
+
* The same server through plain `localhost` (`http://localhost:3000/`), for
|
|
41
|
+
* HTTP clients that resolve through the OS, which may not map `*.localhost`.
|
|
42
|
+
* Equal to `url` when the server has no dev hostname, or when its https
|
|
43
|
+
* certificate does not cover `localhost` (the named URL is then the only
|
|
44
|
+
* one that verifies).
|
|
45
|
+
*/
|
|
46
|
+
loopbackUrl: string;
|
|
47
|
+
port: number;
|
|
48
|
+
pid: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface DevStatusWorktree {
|
|
52
|
+
/** The other worktree's root directory. */
|
|
53
|
+
path: string;
|
|
54
|
+
/** Short branch name, or null for a detached HEAD. */
|
|
55
|
+
branch: string | null;
|
|
56
|
+
/** The same app, inside that worktree. */
|
|
57
|
+
appRoot: string;
|
|
58
|
+
servers: DevStatusServer[];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The `timber dev status --json` contract. */
|
|
62
|
+
export interface DevStatusReport {
|
|
63
|
+
version: typeof DEV_STATUS_JSON_VERSION;
|
|
64
|
+
/** The app this checkout's servers were looked up for. */
|
|
65
|
+
appRoot: string;
|
|
66
|
+
/** Live servers serving this checkout. Reuse one of these. */
|
|
67
|
+
servers: DevStatusServer[];
|
|
68
|
+
/** Live servers in other git worktrees of the same app — different code. */
|
|
69
|
+
otherWorktrees: DevStatusWorktree[];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function toServer(record: DevRecord): DevStatusServer {
|
|
73
|
+
return {
|
|
74
|
+
url: record.url,
|
|
75
|
+
loopbackUrl: record.loopbackUrl,
|
|
76
|
+
port: record.port,
|
|
77
|
+
pid: record.pid,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function liveServers(appRoot: string): Promise<DevStatusServer[]> {
|
|
82
|
+
return (await readLiveDevRecords(appRoot)).map(toServer).sort((a, b) => a.port - b.port);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
interface Worktree {
|
|
86
|
+
path: string;
|
|
87
|
+
branch: string | null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Parse `git worktree list --porcelain`, skipping bare entries. */
|
|
91
|
+
export function parseWorktreeList(porcelain: string): Worktree[] {
|
|
92
|
+
const worktrees: Worktree[] = [];
|
|
93
|
+
for (const stanza of porcelain.split(/\n\s*\n/)) {
|
|
94
|
+
let path: string | null = null;
|
|
95
|
+
let branch: string | null = null;
|
|
96
|
+
let bare = false;
|
|
97
|
+
for (const line of stanza.split('\n')) {
|
|
98
|
+
if (line.startsWith('worktree ')) path = line.slice('worktree '.length);
|
|
99
|
+
else if (line.startsWith('branch ')) branch = line.slice('branch '.length);
|
|
100
|
+
else if (line === 'bare') bare = true;
|
|
101
|
+
}
|
|
102
|
+
if (path && !bare) {
|
|
103
|
+
worktrees.push({ path, branch: branch?.replace(/^refs\/heads\//, '') ?? null });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return worktrees;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async function git(cwd: string, args: string[]): Promise<string> {
|
|
110
|
+
const { stdout } = await execFileAsync('git', args, { cwd, timeout: GIT_TIMEOUT_MS });
|
|
111
|
+
return stdout;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Live servers for this app in every other worktree of its repository.
|
|
116
|
+
* Any git failure (not a repo, no git binary, timeout) means "no other
|
|
117
|
+
* worktrees", silently.
|
|
118
|
+
*/
|
|
119
|
+
async function otherWorktreeServers(appRoot: string): Promise<DevStatusWorktree[]> {
|
|
120
|
+
let toplevel: string;
|
|
121
|
+
let porcelain: string;
|
|
122
|
+
try {
|
|
123
|
+
toplevel = (await git(appRoot, ['rev-parse', '--show-toplevel'])).trim();
|
|
124
|
+
porcelain = await git(appRoot, ['worktree', 'list', '--porcelain']);
|
|
125
|
+
} catch {
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
// git prints resolved paths; resolve the app root too (macOS /tmp is a
|
|
129
|
+
// symlink) so the relative app path is computed in one path space.
|
|
130
|
+
const appPath = relative(await realpath(toplevel), await realpath(appRoot));
|
|
131
|
+
const self = resolve(toplevel);
|
|
132
|
+
|
|
133
|
+
const results = await Promise.all(
|
|
134
|
+
parseWorktreeList(porcelain)
|
|
135
|
+
.filter((worktree) => resolve(worktree.path) !== self)
|
|
136
|
+
.map(async (worktree): Promise<DevStatusWorktree> => {
|
|
137
|
+
const otherApp = join(worktree.path, appPath);
|
|
138
|
+
return { ...worktree, appRoot: otherApp, servers: await liveServers(otherApp) };
|
|
139
|
+
})
|
|
140
|
+
);
|
|
141
|
+
return results.filter((worktree) => worktree.servers.length > 0);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export async function collectDevStatus(appRoot: string): Promise<DevStatusReport> {
|
|
145
|
+
const [servers, otherWorktrees] = await Promise.all([
|
|
146
|
+
liveServers(appRoot),
|
|
147
|
+
otherWorktreeServers(appRoot),
|
|
148
|
+
]);
|
|
149
|
+
return { version: DEV_STATUS_JSON_VERSION, appRoot, servers, otherWorktrees };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** `(pid N)`, plus the plain-localhost URL when it differs from the printed one. */
|
|
153
|
+
function serverNote(server: DevStatusServer): string {
|
|
154
|
+
return server.loopbackUrl === server.url
|
|
155
|
+
? `(pid ${server.pid})`
|
|
156
|
+
: `(pid ${server.pid}; non-browser clients: ${server.loopbackUrl})`;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function formatDevStatus(report: DevStatusReport): string {
|
|
160
|
+
const lines: string[] = [];
|
|
161
|
+
if (report.servers.length === 0) {
|
|
162
|
+
lines.push(`[timber] No dev server is running for this checkout (${report.appRoot}).`);
|
|
163
|
+
} else {
|
|
164
|
+
lines.push(`[timber] Dev server running for this checkout (${report.appRoot}):`);
|
|
165
|
+
for (const server of report.servers) lines.push(` ${server.url} ${serverNote(server)}`);
|
|
166
|
+
}
|
|
167
|
+
if (report.otherWorktrees.length > 0) {
|
|
168
|
+
lines.push('[timber] In other git worktrees (different code — do not test against these):');
|
|
169
|
+
for (const worktree of report.otherWorktrees) {
|
|
170
|
+
const branch = worktree.branch ?? 'detached HEAD';
|
|
171
|
+
for (const server of worktree.servers) {
|
|
172
|
+
lines.push(` ${server.url} ${serverNote(server)} ${worktree.path} [${branch}]`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return lines.join('\n');
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Resolve the app root the way `timber graph` does — the directory of the
|
|
181
|
+
* Vite config, found by walking up from the cwd unless `--config` names it —
|
|
182
|
+
* then print the report. Exits 0 whether or not servers are found ("no server"
|
|
183
|
+
* is an answer); throws only when there is no config to anchor on.
|
|
184
|
+
*/
|
|
185
|
+
export async function runDevStatus(options: { config?: string; json: boolean }): Promise<void> {
|
|
186
|
+
const { findViteConfigUpward } = await import('./analyze/graph-command.ts');
|
|
187
|
+
const configFile = options.config ? resolve(options.config) : findViteConfigUpward(process.cwd());
|
|
188
|
+
if (!configFile) {
|
|
189
|
+
throw new Error(
|
|
190
|
+
'[timber] No Vite config found in this directory or any parent — ' +
|
|
191
|
+
'run `timber dev status` from inside a timber app, or pass --config <path>.'
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
const report = await collectDevStatus(dirname(configFile));
|
|
195
|
+
console.log(options.json ? JSON.stringify(report) : formatDevStatus(report));
|
|
196
|
+
}
|