@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
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* graph-endpoint — `GET /__timber/graph`
|
|
2
|
+
* graph-endpoint — `GET /__timber/graph` (and the `GET /__timber/status`
|
|
3
|
+
* identity probe) on the dev server.
|
|
3
4
|
*
|
|
4
5
|
* The fast path of design/47: when a dev server runs, the env module
|
|
5
6
|
* graphs are already resident and classification is a lookup. Serves
|
|
@@ -38,6 +39,7 @@ import { isAbsolute, join, relative, resolve } from 'node:path';
|
|
|
38
39
|
import type { PluginContext } from '../plugin-context.ts';
|
|
39
40
|
import { buildSourceExtensions, isScannableSourceFile } from '../analyze/scan.ts';
|
|
40
41
|
import { GRAPH_JSON_VERSION } from '../analyze/graph-cache.ts';
|
|
42
|
+
import { STATUS_ENDPOINT_PATH } from './dev-discovery.ts';
|
|
41
43
|
|
|
42
44
|
export const GRAPH_ENDPOINT_PATH = '/__timber/graph';
|
|
43
45
|
|
|
@@ -159,7 +161,8 @@ function reflectCors(res: ServerResponse, origin: string | undefined): void {
|
|
|
159
161
|
}
|
|
160
162
|
|
|
161
163
|
/**
|
|
162
|
-
* Create the Connect middleware handling GET /__timber/graph
|
|
164
|
+
* Create the Connect middleware handling GET /__timber/graph and the
|
|
165
|
+
* GET /__timber/status identity probe.
|
|
163
166
|
*
|
|
164
167
|
* Query surface: `?file=<path>` (absolute or project-root-relative) or
|
|
165
168
|
* `?all=1`. Anything else is a 400 — fail loudly, like the CLI.
|
|
@@ -175,7 +178,8 @@ export function createGraphEndpointMiddleware(server: ViteDevServer, ctx: Plugin
|
|
|
175
178
|
return;
|
|
176
179
|
}
|
|
177
180
|
const url = new URL(rawUrl, 'http://placeholder.invalid');
|
|
178
|
-
|
|
181
|
+
const isStatus = url.pathname === STATUS_ENDPOINT_PATH;
|
|
182
|
+
if (!isStatus && url.pathname !== GRAPH_ENDPOINT_PATH) {
|
|
179
183
|
sendJson(res, 404, { error: `unknown /__timber/ endpoint: ${url.pathname}` });
|
|
180
184
|
return;
|
|
181
185
|
}
|
|
@@ -205,6 +209,14 @@ export function createGraphEndpointMiddleware(server: ViteDevServer, ctx: Plugin
|
|
|
205
209
|
// consumers can actually READ the response.
|
|
206
210
|
reflectCors(res, origin);
|
|
207
211
|
|
|
212
|
+
// Identity probe for `timber dev status` (dev-discovery.ts): the pid
|
|
213
|
+
// lets the CLI confirm this is the server that wrote the record, not
|
|
214
|
+
// a different process that took a crashed server's port.
|
|
215
|
+
if (isStatus) {
|
|
216
|
+
sendJson(res, 200, { pid: process.pid });
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
|
|
208
220
|
try {
|
|
209
221
|
// Lazy import: the analyze pipeline (oxc parse, chains) loads on
|
|
210
222
|
// first query, not on every dev-server boot.
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Import specifiers whose barrel imports timber rewrites by default.
|
|
3
|
+
*
|
|
4
|
+
* Copied from Next.js's built-in `optimizePackageImports` list
|
|
5
|
+
* (packages/next/src/server/config.ts, vercel/next.js@50bf604f2), so an app
|
|
6
|
+
* moving from Next gets the same set without configuring it. Entries are exact
|
|
7
|
+
* import specifiers, not package names: a package with several icon entry
|
|
8
|
+
* points (`react-icons/fa`, `@heroicons/react/24/solid`) lists each one.
|
|
9
|
+
*
|
|
10
|
+
* See design/21-dev-server.md §"Barrel Import Optimization".
|
|
11
|
+
*/
|
|
12
|
+
export const DEFAULT_OPTIMIZE_PACKAGE_IMPORTS: readonly string[] = [
|
|
13
|
+
'lucide-react',
|
|
14
|
+
'date-fns',
|
|
15
|
+
'lodash-es',
|
|
16
|
+
'ramda',
|
|
17
|
+
'antd',
|
|
18
|
+
'react-bootstrap',
|
|
19
|
+
'ahooks',
|
|
20
|
+
'@ant-design/icons',
|
|
21
|
+
'@headlessui/react',
|
|
22
|
+
'@headlessui-float/react',
|
|
23
|
+
'@heroicons/react/20/solid',
|
|
24
|
+
'@heroicons/react/24/solid',
|
|
25
|
+
'@heroicons/react/24/outline',
|
|
26
|
+
'@visx/visx',
|
|
27
|
+
'@tremor/react',
|
|
28
|
+
'rxjs',
|
|
29
|
+
'@mui/material',
|
|
30
|
+
'@mui/icons-material',
|
|
31
|
+
'recharts',
|
|
32
|
+
'react-use',
|
|
33
|
+
'effect',
|
|
34
|
+
'@effect/schema',
|
|
35
|
+
'@effect/platform',
|
|
36
|
+
'@effect/platform-node',
|
|
37
|
+
'@effect/platform-browser',
|
|
38
|
+
'@effect/platform-bun',
|
|
39
|
+
'@effect/sql',
|
|
40
|
+
'@effect/sql-mssql',
|
|
41
|
+
'@effect/sql-mysql2',
|
|
42
|
+
'@effect/sql-pg',
|
|
43
|
+
'@effect/sql-sqlite-node',
|
|
44
|
+
'@effect/sql-sqlite-bun',
|
|
45
|
+
'@effect/sql-sqlite-wasm',
|
|
46
|
+
'@effect/sql-sqlite-react-native',
|
|
47
|
+
'@effect/rpc',
|
|
48
|
+
'@effect/rpc-http',
|
|
49
|
+
'@effect/typeclass',
|
|
50
|
+
'@effect/experimental',
|
|
51
|
+
'@effect/opentelemetry',
|
|
52
|
+
'@material-ui/core',
|
|
53
|
+
'@material-ui/icons',
|
|
54
|
+
'@tabler/icons-react',
|
|
55
|
+
'mui-core',
|
|
56
|
+
'react-icons/ai',
|
|
57
|
+
'react-icons/bi',
|
|
58
|
+
'react-icons/bs',
|
|
59
|
+
'react-icons/cg',
|
|
60
|
+
'react-icons/ci',
|
|
61
|
+
'react-icons/di',
|
|
62
|
+
'react-icons/fa',
|
|
63
|
+
'react-icons/fa6',
|
|
64
|
+
'react-icons/fc',
|
|
65
|
+
'react-icons/fi',
|
|
66
|
+
'react-icons/gi',
|
|
67
|
+
'react-icons/go',
|
|
68
|
+
'react-icons/gr',
|
|
69
|
+
'react-icons/hi',
|
|
70
|
+
'react-icons/hi2',
|
|
71
|
+
'react-icons/im',
|
|
72
|
+
'react-icons/io',
|
|
73
|
+
'react-icons/io5',
|
|
74
|
+
'react-icons/lia',
|
|
75
|
+
'react-icons/lib',
|
|
76
|
+
'react-icons/lu',
|
|
77
|
+
'react-icons/md',
|
|
78
|
+
'react-icons/pi',
|
|
79
|
+
'react-icons/ri',
|
|
80
|
+
'react-icons/rx',
|
|
81
|
+
'react-icons/si',
|
|
82
|
+
'react-icons/sl',
|
|
83
|
+
'react-icons/tb',
|
|
84
|
+
'react-icons/tfi',
|
|
85
|
+
'react-icons/ti',
|
|
86
|
+
'react-icons/vsc',
|
|
87
|
+
'react-icons/wi',
|
|
88
|
+
];
|
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* timber-optimize-package-imports — rewrites named imports from a listed
|
|
3
|
+
* barrel package into imports of only the modules that define those names.
|
|
4
|
+
*
|
|
5
|
+
* In dev, `@vitejs/plugin-rsc` keeps packages with a `react` peer dependency
|
|
6
|
+
* in the rsc and ssr module graphs without pre-bundling them, so on the server
|
|
7
|
+
* `import { Play } from 'lucide-react'` enters lucide's barrel and Vite
|
|
8
|
+
* transforms all ~2,000 icon modules it re-exports, once per environment. A
|
|
9
|
+
* build loads all of them too, before tree-shaking. The
|
|
10
|
+
* rewrite turns that import into one of the icon's own file:
|
|
11
|
+
*
|
|
12
|
+
* import { Play } from 'lucide-react'
|
|
13
|
+
* → import { default as Play } from "/…/lucide-react/dist/esm/icons/play.mjs";
|
|
14
|
+
*
|
|
15
|
+
* Next.js does the same for its `optimizePackageImports` list
|
|
16
|
+
* (next-barrel-loader.ts, optimize_barrel.rs). It applies to every environment
|
|
17
|
+
* in builds; in dev, to the server environments and only for packages Vite
|
|
18
|
+
* compiles itself (the client environment pre-bundles them; the server
|
|
19
|
+
* environments hand most other packages to Node). See design/21-dev-server.md
|
|
20
|
+
* §"Barrel Import Optimization".
|
|
21
|
+
*
|
|
22
|
+
* Every rule here leans toward leaving the import alone. A missed rewrite costs
|
|
23
|
+
* compile time; a wrong one breaks the app. An import is rewritten only when
|
|
24
|
+
* the barrel is a pure barrel (nothing but imports and re-exports) and every
|
|
25
|
+
* imported name is in its export map with a target that resolves to a file.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { readFileSync } from 'node:fs';
|
|
29
|
+
import { isAbsolute } from 'node:path';
|
|
30
|
+
import { MagicString } from 'magic-string';
|
|
31
|
+
import { parseAst, type Plugin } from 'vite';
|
|
32
|
+
import type { PluginContext } from '../plugin-context.ts';
|
|
33
|
+
import { DEFAULT_OPTIMIZE_PACKAGE_IMPORTS } from './optimize-package-imports-defaults.ts';
|
|
34
|
+
|
|
35
|
+
type Program = ReturnType<typeof parseAst>;
|
|
36
|
+
type ModuleItem = Program['body'][number];
|
|
37
|
+
type ImportDeclaration = Extract<ModuleItem, { type: 'ImportDeclaration' }>;
|
|
38
|
+
type ExportNamedDeclaration = Extract<ModuleItem, { type: 'ExportNamedDeclaration' }>;
|
|
39
|
+
type ModuleExportName = ExportNamedDeclaration['specifiers'][number]['local'];
|
|
40
|
+
type Lang = 'js' | 'jsx' | 'ts' | 'tsx';
|
|
41
|
+
|
|
42
|
+
/** Where a barrel's export comes from. */
|
|
43
|
+
export interface BarrelExport {
|
|
44
|
+
/** The specifier as written in the barrel (`'./icons/play.mjs'`). */
|
|
45
|
+
source: string;
|
|
46
|
+
/** The name in `source`: an export name, `'default'`, or `'*'` for a namespace. */
|
|
47
|
+
imported: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Export name → origin, for the names a barrel states explicitly. */
|
|
51
|
+
export type BarrelExportMap = ReadonlyMap<string, BarrelExport>;
|
|
52
|
+
|
|
53
|
+
/** A barrel the rewrite may import past, as seen from one importer. */
|
|
54
|
+
export interface ResolvedBarrel {
|
|
55
|
+
exports: BarrelExportMap;
|
|
56
|
+
/** Resolve a source from `exports` relative to the barrel; null = leave the import alone. */
|
|
57
|
+
resolveTarget(source: string): Promise<string | null>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Merge the user's list with the defaults (Next's semantics: the user list
|
|
62
|
+
* adds, never replaces). Config validation reports invalid entries without
|
|
63
|
+
* stopping the dev server, so only the valid ones (non-empty strings) are used
|
|
64
|
+
* here; a string list is not spread into characters, and an empty entry does
|
|
65
|
+
* not match every quoted empty string.
|
|
66
|
+
*/
|
|
67
|
+
export function resolveOptimizedPackages(user: readonly string[] | undefined): ReadonlySet<string> {
|
|
68
|
+
const extra = Array.isArray(user)
|
|
69
|
+
? user.filter((entry) => typeof entry === 'string' && entry.trim() !== '')
|
|
70
|
+
: [];
|
|
71
|
+
return new Set([...DEFAULT_OPTIMIZE_PACKAGE_IMPORTS, ...extra]);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function nameOf(node: ModuleExportName): string {
|
|
75
|
+
return node.type === 'Literal' ? node.value : node.name;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Read a barrel's export map, or null when the file is not a pure barrel.
|
|
80
|
+
*
|
|
81
|
+
* A pure barrel holds only imports, re-exports, and `export { local }` of an
|
|
82
|
+
* imported binding (`import * as icons from './icons'; export { icons }`, which
|
|
83
|
+
* lucide-react's barrel opens with). Anything that runs code of its own, a
|
|
84
|
+
* declaration, an expression, a bare side-effect import, makes it not a barrel:
|
|
85
|
+
* importing past it would skip that code. So does any directive except
|
|
86
|
+
* `'use strict'`: a `'use client'` or `'use server'` barrel is a boundary
|
|
87
|
+
* plugin-rsc draws around the barrel module itself, and importing past it would
|
|
88
|
+
* load the re-exported files on the wrong side of it.
|
|
89
|
+
*
|
|
90
|
+
* `export default local` is not followed even when `local` is imported: it
|
|
91
|
+
* exports the value `local` held when the barrel ran, not a live binding, so
|
|
92
|
+
* importing `local` directly would see later reassignments the barrel's
|
|
93
|
+
* default never does. `export { local as default }` is live and is followed.
|
|
94
|
+
*
|
|
95
|
+
* A source-phase or deferred import, or import attributes, change what the
|
|
96
|
+
* barrel's binding is, so a barrel using them is not followed. An
|
|
97
|
+
* `export {} from` with no names only runs the module, like a bare import.
|
|
98
|
+
*
|
|
99
|
+
* `export * from` adds no entries. A name it might supply is not in the map, so
|
|
100
|
+
* an import of that name falls back; explicit exports shadow star exports, so
|
|
101
|
+
* every name that is in the map is exact.
|
|
102
|
+
*/
|
|
103
|
+
export function readBarrelExportMap(code: string, lang: Lang): BarrelExportMap | null {
|
|
104
|
+
let program: Program;
|
|
105
|
+
try {
|
|
106
|
+
program = parseAst(code, { lang });
|
|
107
|
+
} catch {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const imported = new Map<string, BarrelExport>();
|
|
112
|
+
for (const item of program.body) {
|
|
113
|
+
if (item.type !== 'ImportDeclaration' || item.importKind === 'type') continue;
|
|
114
|
+
const source = item.source.value;
|
|
115
|
+
for (const spec of item.specifiers) {
|
|
116
|
+
if (spec.type === 'ImportSpecifier') {
|
|
117
|
+
if (spec.importKind === 'type') continue;
|
|
118
|
+
imported.set(spec.local.name, { source, imported: nameOf(spec.imported) });
|
|
119
|
+
} else if (spec.type === 'ImportDefaultSpecifier') {
|
|
120
|
+
imported.set(spec.local.name, { source, imported: 'default' });
|
|
121
|
+
} else {
|
|
122
|
+
imported.set(spec.local.name, { source, imported: '*' });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const exports = new Map<string, BarrelExport>();
|
|
128
|
+
for (const item of program.body) {
|
|
129
|
+
switch (item.type) {
|
|
130
|
+
case 'ExpressionStatement':
|
|
131
|
+
if ('directive' in item && item.directive === 'use strict') continue;
|
|
132
|
+
return null;
|
|
133
|
+
case 'ImportDeclaration':
|
|
134
|
+
if (item.importKind === 'type') continue;
|
|
135
|
+
if (item.specifiers.length === 0 || item.phase !== null || item.attributes.length > 0) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
continue;
|
|
139
|
+
case 'ExportAllDeclaration':
|
|
140
|
+
if (item.exportKind === 'type') continue;
|
|
141
|
+
if (item.attributes.length > 0) return null;
|
|
142
|
+
if (item.exported) {
|
|
143
|
+
exports.set(nameOf(item.exported), { source: item.source.value, imported: '*' });
|
|
144
|
+
}
|
|
145
|
+
continue;
|
|
146
|
+
case 'ExportNamedDeclaration': {
|
|
147
|
+
if (item.exportKind === 'type') continue;
|
|
148
|
+
if (item.declaration || item.attributes.length > 0) return null;
|
|
149
|
+
if (item.source && item.specifiers.length === 0) return null;
|
|
150
|
+
for (const spec of item.specifiers) {
|
|
151
|
+
if (spec.exportKind === 'type') continue;
|
|
152
|
+
const local = nameOf(spec.local);
|
|
153
|
+
const origin = item.source
|
|
154
|
+
? { source: item.source.value, imported: local }
|
|
155
|
+
: imported.get(local);
|
|
156
|
+
if (!origin) return null;
|
|
157
|
+
exports.set(nameOf(spec.exported), origin);
|
|
158
|
+
}
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
// Erased by the TypeScript transform; they run nothing.
|
|
162
|
+
case 'TSInterfaceDeclaration':
|
|
163
|
+
case 'TSTypeAliasDeclaration':
|
|
164
|
+
continue;
|
|
165
|
+
default:
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return exports;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const IDENTIFIER_RE = /^[A-Za-z_$][\w$]*$/;
|
|
173
|
+
|
|
174
|
+
/** An export name as it must be written in an import or export clause. */
|
|
175
|
+
function clauseName(name: string): string {
|
|
176
|
+
return IDENTIFIER_RE.test(name) ? name : JSON.stringify(name);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** One binding the rewritten statement must still provide. */
|
|
180
|
+
interface Binding {
|
|
181
|
+
/** The name the user's statement wanted from the barrel. */
|
|
182
|
+
barrelName: string;
|
|
183
|
+
/** The local name (import) or exported name (re-export) it binds. */
|
|
184
|
+
as: string;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* The bindings a statement takes from `source`, or null when the statement is
|
|
189
|
+
* not a candidate: a namespace import, `import type`, an import attribute, a
|
|
190
|
+
* source phase import, or a statement with no value bindings.
|
|
191
|
+
*/
|
|
192
|
+
function statementBindings(item: ImportDeclaration | ExportNamedDeclaration): Binding[] | null {
|
|
193
|
+
if (item.attributes.length > 0) return null;
|
|
194
|
+
const bindings: Binding[] = [];
|
|
195
|
+
if (item.type === 'ImportDeclaration') {
|
|
196
|
+
if (item.importKind === 'type' || item.phase !== null) return null;
|
|
197
|
+
for (const spec of item.specifiers) {
|
|
198
|
+
if (spec.type === 'ImportNamespaceSpecifier') return null;
|
|
199
|
+
if (spec.type === 'ImportDefaultSpecifier') {
|
|
200
|
+
bindings.push({ barrelName: 'default', as: spec.local.name });
|
|
201
|
+
} else if (spec.importKind !== 'type') {
|
|
202
|
+
bindings.push({ barrelName: nameOf(spec.imported), as: spec.local.name });
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
} else {
|
|
206
|
+
if (item.exportKind === 'type' || item.declaration) return null;
|
|
207
|
+
for (const spec of item.specifiers) {
|
|
208
|
+
if (spec.exportKind === 'type') continue;
|
|
209
|
+
bindings.push({ barrelName: nameOf(spec.local), as: nameOf(spec.exported) });
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return bindings.length > 0 ? bindings : null;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** The replacement statements for one candidate, or null to leave it alone. */
|
|
216
|
+
async function rewriteStatement(
|
|
217
|
+
item: ImportDeclaration | ExportNamedDeclaration,
|
|
218
|
+
barrel: ResolvedBarrel
|
|
219
|
+
): Promise<string | null> {
|
|
220
|
+
const bindings = statementBindings(item);
|
|
221
|
+
if (!bindings) return null;
|
|
222
|
+
const out: string[] = [];
|
|
223
|
+
for (const { barrelName, as } of bindings) {
|
|
224
|
+
const origin = barrel.exports.get(barrelName);
|
|
225
|
+
if (!origin) return null;
|
|
226
|
+
const target = await barrel.resolveTarget(origin.source);
|
|
227
|
+
if (!target) return null;
|
|
228
|
+
const from = JSON.stringify(target);
|
|
229
|
+
if (item.type === 'ImportDeclaration') {
|
|
230
|
+
out.push(
|
|
231
|
+
origin.imported === '*'
|
|
232
|
+
? `import * as ${as} from ${from};`
|
|
233
|
+
: `import { ${clauseName(origin.imported)} as ${as} } from ${from};`
|
|
234
|
+
);
|
|
235
|
+
} else {
|
|
236
|
+
out.push(
|
|
237
|
+
origin.imported === '*'
|
|
238
|
+
? `export * as ${clauseName(as)} from ${from};`
|
|
239
|
+
: `export { ${clauseName(origin.imported)} as ${clauseName(as)} } from ${from};`
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return out.join(' ');
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Rewrite every import and `export { … } from` of a listed specifier whose
|
|
248
|
+
* names the barrel's export map covers. Returns null when nothing changed.
|
|
249
|
+
*
|
|
250
|
+
* Replacements stay on the statement's own lines, so positions after it keep
|
|
251
|
+
* their line numbers even before the source map is applied.
|
|
252
|
+
*/
|
|
253
|
+
export async function rewriteBarrelImports(
|
|
254
|
+
code: string,
|
|
255
|
+
packages: ReadonlySet<string>,
|
|
256
|
+
loadBarrel: (specifier: string) => Promise<ResolvedBarrel | null>
|
|
257
|
+
): Promise<MagicString | null> {
|
|
258
|
+
let program: Program;
|
|
259
|
+
try {
|
|
260
|
+
// Runs after Vite's TypeScript/JSX transform, so the code is JavaScript.
|
|
261
|
+
program = parseAst(code, { lang: 'js' });
|
|
262
|
+
} catch {
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
let s: MagicString | null = null;
|
|
266
|
+
const barrels = new Map<string, ResolvedBarrel | null>();
|
|
267
|
+
for (const item of program.body) {
|
|
268
|
+
if (item.type !== 'ImportDeclaration' && item.type !== 'ExportNamedDeclaration') continue;
|
|
269
|
+
const specifier = item.source?.value;
|
|
270
|
+
if (specifier === undefined || !packages.has(specifier)) continue;
|
|
271
|
+
let barrel = barrels.get(specifier);
|
|
272
|
+
if (barrel === undefined) {
|
|
273
|
+
barrel = await loadBarrel(specifier);
|
|
274
|
+
barrels.set(specifier, barrel);
|
|
275
|
+
}
|
|
276
|
+
if (!barrel) continue;
|
|
277
|
+
const replacement = await rewriteStatement(item, barrel);
|
|
278
|
+
if (replacement === null) continue;
|
|
279
|
+
s ??= new MagicString(code);
|
|
280
|
+
const lineBreaks = code.slice(item.start, item.end).split('\n').length - 1;
|
|
281
|
+
s.overwrite(item.start, item.end, replacement + '\n'.repeat(lineBreaks));
|
|
282
|
+
}
|
|
283
|
+
return s;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/** The npm package a bare specifier names: `@scope/pkg/sub` → `@scope/pkg`. */
|
|
287
|
+
function packageNameOf(specifier: string): string {
|
|
288
|
+
const parts = specifier.split('/');
|
|
289
|
+
return specifier.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0];
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** The resolve options that decide whether a server environment externalizes a package. */
|
|
293
|
+
export interface ExternalizationConfig {
|
|
294
|
+
noExternal: string | RegExp | readonly (string | RegExp)[] | true;
|
|
295
|
+
external: readonly string[] | true;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Whether the environment loads `specifier` through Vite rather than handing
|
|
300
|
+
* it to Node. Only those imports are rewritten.
|
|
301
|
+
*
|
|
302
|
+
* A server environment externalizes most of node_modules in dev: Node loads
|
|
303
|
+
* the package natively, so its barrel costs nothing to compile. Rewriting such
|
|
304
|
+
* an import to a file path would pull that file into Vite's module graph
|
|
305
|
+
* while any other import of the package stayed external, two instances of one
|
|
306
|
+
* module. In dev, plugin-rsc keeps packages with a `react` peer dependency
|
|
307
|
+
* (lucide-react, the icon sets, the component libraries) out of
|
|
308
|
+
* externalization, and timber's production build sets `noExternal: true`.
|
|
309
|
+
*
|
|
310
|
+
* Vite's own check is internal, so this is its conservative subset: the
|
|
311
|
+
* package must match `resolve.noExternal` exactly (a string or a RegExp) and
|
|
312
|
+
* `resolve.external` must not name it. A glob string in `noExternal` does
|
|
313
|
+
* not match here, which only costs the optimization.
|
|
314
|
+
*/
|
|
315
|
+
export function isLoadedThroughVite(specifier: string, config: ExternalizationConfig): boolean {
|
|
316
|
+
const pkg = packageNameOf(specifier);
|
|
317
|
+
const { noExternal, external } = config;
|
|
318
|
+
if (external === true || external.includes(specifier) || external.includes(pkg)) return false;
|
|
319
|
+
if (noExternal === true) return true;
|
|
320
|
+
const patterns = Array.isArray(noExternal) ? noExternal : [noExternal];
|
|
321
|
+
return patterns.some((p) => (typeof p === 'string' ? p === pkg : p.test(pkg)));
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function langForFile(file: string): Lang {
|
|
325
|
+
if (file.endsWith('.tsx')) return 'tsx';
|
|
326
|
+
if (/\.[mc]?ts$/.test(file)) return 'ts';
|
|
327
|
+
if (file.endsWith('.jsx')) return 'jsx';
|
|
328
|
+
return 'js';
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* A resolved id as a plain file import, or null when it is not one (virtual,
|
|
333
|
+
* relative, or carrying a query that changes what the module is).
|
|
334
|
+
*
|
|
335
|
+
* Vite's dev resolver appends `?v=<hash>` to files under node_modules, in the
|
|
336
|
+
* server environments too, and appends the same query again when it resolves
|
|
337
|
+
* the absolute path this rewrite emits. So the query is dropped, never copied:
|
|
338
|
+
* the emitted path resolves to the same id the barrel's own import would, which
|
|
339
|
+
* keeps one module instance per file.
|
|
340
|
+
*/
|
|
341
|
+
function asFilePath(id: string): string | null {
|
|
342
|
+
const path = id.replace(/\?v=[\w.-]+$/, '');
|
|
343
|
+
return isAbsolute(path) && !path.includes('?') && !path.includes('\0') ? path : null;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function escapeRegExp(text: string): string {
|
|
347
|
+
return text.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&');
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export function timberOptimizePackageImports(ctx: PluginContext): Plugin {
|
|
351
|
+
let packages: ReadonlySet<string> = new Set();
|
|
352
|
+
let isDev = false;
|
|
353
|
+
// Cheap pre-filter: a module that never quotes a listed specifier is not parsed.
|
|
354
|
+
let mentionsListed = /(?!)/;
|
|
355
|
+
// Installed packages are assumed not to change while the process runs (Next
|
|
356
|
+
// makes the same assumption); after a reinstall, restart the dev server. A
|
|
357
|
+
// barrel outside node_modules (a linked workspace package) can be edited, so
|
|
358
|
+
// it is read on every transform and never cached. The read and parse are
|
|
359
|
+
// synchronous, so concurrent transforms cannot parse one barrel twice and
|
|
360
|
+
// there is no in-flight promise to time out.
|
|
361
|
+
const exportMaps = new Map<string, BarrelExportMap | null>();
|
|
362
|
+
const targets = new Map<string, string | null>();
|
|
363
|
+
|
|
364
|
+
const isInstalled = (path: string) => path.includes('/node_modules/');
|
|
365
|
+
|
|
366
|
+
function exportMapFor(barrelPath: string): BarrelExportMap | null {
|
|
367
|
+
const cached = exportMaps.get(barrelPath);
|
|
368
|
+
if (cached !== undefined) return cached;
|
|
369
|
+
let code: string;
|
|
370
|
+
try {
|
|
371
|
+
code = readFileSync(barrelPath, 'utf8');
|
|
372
|
+
} catch {
|
|
373
|
+
// Unreadable (deleted, or a transient EMFILE): leave imports alone this
|
|
374
|
+
// time and try again on the next transform.
|
|
375
|
+
return null;
|
|
376
|
+
}
|
|
377
|
+
const map = readBarrelExportMap(code, langForFile(barrelPath));
|
|
378
|
+
if (isInstalled(barrelPath)) exportMaps.set(barrelPath, map);
|
|
379
|
+
return map;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
return {
|
|
383
|
+
name: 'timber-optimize-package-imports',
|
|
384
|
+
|
|
385
|
+
configResolved(config) {
|
|
386
|
+
isDev = config.command === 'serve';
|
|
387
|
+
packages = resolveOptimizedPackages(ctx.config.optimizePackageImports);
|
|
388
|
+
const alternatives = [...packages].map(escapeRegExp).join('|');
|
|
389
|
+
mentionsListed = new RegExp(`(["'])(?:${alternatives})\\1`);
|
|
390
|
+
},
|
|
391
|
+
|
|
392
|
+
// Normal order, after Vite's TypeScript transform: an import that names a
|
|
393
|
+
// type without `type` (`import { Play, LucideIcon }`) has been reduced to
|
|
394
|
+
// its value names, so the type does not fall the whole import back.
|
|
395
|
+
async transform(code, id) {
|
|
396
|
+
// In dev the client environment pre-bundles these packages into one
|
|
397
|
+
// module; importing past that bundle would load a second copy of the
|
|
398
|
+
// package. Builds have no pre-bundle, so every environment is rewritten.
|
|
399
|
+
if (isDev && this.environment.config.consumer !== 'server') return null;
|
|
400
|
+
if (id.startsWith('\0') || !mentionsListed.test(code)) return null;
|
|
401
|
+
const envName = this.environment.name;
|
|
402
|
+
|
|
403
|
+
const { consumer, resolve } = this.environment.config;
|
|
404
|
+
|
|
405
|
+
const s = await rewriteBarrelImports(code, packages, async (specifier) => {
|
|
406
|
+
if (consumer === 'server' && !isLoadedThroughVite(specifier, resolve)) return null;
|
|
407
|
+
const resolved = await this.resolve(specifier, id);
|
|
408
|
+
const barrelPath = resolved && !resolved.external ? asFilePath(resolved.id) : null;
|
|
409
|
+
if (!barrelPath) return null;
|
|
410
|
+
// The rewrite takes the barrel out of this module's import graph, so
|
|
411
|
+
// an edit to an editable barrel would not otherwise re-transform it.
|
|
412
|
+
const installed = isInstalled(barrelPath);
|
|
413
|
+
if (!installed) this.addWatchFile(barrelPath);
|
|
414
|
+
const exports = exportMapFor(barrelPath);
|
|
415
|
+
if (!exports) return null;
|
|
416
|
+
return {
|
|
417
|
+
exports,
|
|
418
|
+
resolveTarget: async (source) => {
|
|
419
|
+
// Only the barrel's own files. A bare source names another
|
|
420
|
+
// package, which the environment may externalize to Node: an
|
|
421
|
+
// absolute path to it would load a second copy beside Node's (or
|
|
422
|
+
// a CJS file Vite's runner cannot run). resolveId does not report
|
|
423
|
+
// that externalization in dev, so it cannot be checked here.
|
|
424
|
+
if (!source.startsWith('./') && !source.startsWith('../')) return null;
|
|
425
|
+
const key = `${envName}\0${barrelPath}\0${source}`;
|
|
426
|
+
const cached = targets.get(key);
|
|
427
|
+
if (cached !== undefined) return cached;
|
|
428
|
+
const target = await this.resolve(source, barrelPath);
|
|
429
|
+
const path = target && !target.external ? asFilePath(target.id) : null;
|
|
430
|
+
if (installed) targets.set(key, path);
|
|
431
|
+
return path;
|
|
432
|
+
},
|
|
433
|
+
};
|
|
434
|
+
});
|
|
435
|
+
if (!s) return null;
|
|
436
|
+
return { code: s.toString(), map: s.generateMap({ hires: 'boundary' }) };
|
|
437
|
+
},
|
|
438
|
+
};
|
|
439
|
+
}
|
package/src/plugins/prebuilt.ts
CHANGED
|
@@ -420,6 +420,14 @@ export function timberPrebuilt(ctx: PluginContext): Plugin & { api: PrebuiltBuil
|
|
|
420
420
|
moduleComponents.delete(id);
|
|
421
421
|
bindingNames.delete(id);
|
|
422
422
|
}
|
|
423
|
+
// Dev: the same, for the dev store's scoped clears. A save reaches the
|
|
424
|
+
// watcher before the module is transformed again, so the clear for a
|
|
425
|
+
// save drops the IDs the module declared before it.
|
|
426
|
+
const devIds =
|
|
427
|
+
ctx.dev && this?.environment?.name === 'rsc'
|
|
428
|
+
? (ctx.devPrebuiltComponentIds ??= new Map())
|
|
429
|
+
: null;
|
|
430
|
+
devIds?.delete(id);
|
|
423
431
|
if (!code.includes('@timber-js/app/cache') && !code.includes('timber/cache')) return;
|
|
424
432
|
// Skip node_modules (don't transform third-party code)
|
|
425
433
|
if (id.includes('node_modules')) return;
|
|
@@ -468,6 +476,7 @@ export function timberPrebuilt(ctx: PluginContext): Plugin & { api: PrebuiltBuil
|
|
|
468
476
|
// Only prerender-capable call sites feed the capture attribution —
|
|
469
477
|
// runtime-tier components (ttl/tags only) must do no build work.
|
|
470
478
|
if (!ctx.dev && mayPrerender(call)) componentIds.push(componentId);
|
|
479
|
+
if (devIds) devIds.set(id, [...(devIds.get(id) ?? []), componentId]);
|
|
471
480
|
|
|
472
481
|
s.overwrite(call.callee.start, call.callee.end, '__prebuilt');
|
|
473
482
|
s.appendLeft(call.arguments[0].start, `${JSON.stringify(componentId)}, `);
|
package/src/rsc-runtime/rsc.ts
CHANGED
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
* touches the RSC runtime.
|
|
11
11
|
*
|
|
12
12
|
* Keep this as thin pass-through re-exports — the value is the single choke
|
|
13
|
-
* point, not abstraction. The
|
|
14
|
-
* render Flight (render-flight.ts)
|
|
13
|
+
* point, not abstraction. The exceptions are `renderFlight`, the only way to
|
|
14
|
+
* render Flight (render-flight.ts), and `loadServerAction`, which tells an
|
|
15
|
+
* unknown reference from a broken module (server-references.ts). Bound-args encryption is plugin-rsc's
|
|
15
16
|
* injected runtime, resolved to encryption-runtime.ts so it renders through
|
|
16
17
|
* `renderFlight` too.
|
|
17
18
|
*/
|
|
@@ -21,8 +22,11 @@ import { scopeReferenceCacheToGeneration } from './dev-reference-cache.ts';
|
|
|
21
22
|
// The only way to render Flight; see render-flight.ts.
|
|
22
23
|
export { renderFlight } from './render-flight.ts';
|
|
23
24
|
|
|
25
|
+
// Resolves an unknown reference to undefined instead of rejecting, so a
|
|
26
|
+
// rejection means a real module failed to load; see server-references.ts.
|
|
27
|
+
export { loadServerAction } from './server-references.ts';
|
|
28
|
+
|
|
24
29
|
export {
|
|
25
|
-
loadServerAction,
|
|
26
30
|
decodeReply,
|
|
27
31
|
decodeAction,
|
|
28
32
|
// No-JS action result → the `useActionState` hook that submitted it
|