@farm.js/core 0.1.66 → 0.1.68
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{agent-mcp-handler-QLFDDTYN.mjs → agent-mcp-handler-AZ7QW4UP.mjs} +5 -5
- package/dist/{agent-mcp-handler-OXT73ZBY.cjs → agent-mcp-handler-FER4MQDF.cjs} +6 -6
- package/dist/{agent-mcp.d-QD2WZ9BS.d.ts → agent-mcp.d-Uh5xr7aX.d.ts} +1 -1
- package/dist/{agent-mcp.d-CO_ABmNK.d.mts → agent-mcp.d-wkVPK1GA.d.mts} +1 -1
- package/dist/agent-runtime.cjs +6 -5
- package/dist/agent-runtime.d.mts +10 -8
- package/dist/agent-runtime.d.ts +10 -8
- package/dist/agent-runtime.mjs +5 -4
- package/dist/{analyzer-4UFP4HVP.mjs → analyzer-CQDU7E3Y.mjs} +2 -2
- package/dist/analyzer-PPAHM4AW.cjs +16 -0
- package/dist/api/client.cjs +12 -2
- package/dist/api/client.d.mts +4 -4
- package/dist/api/client.d.ts +4 -4
- package/dist/api/client.mjs +12 -2
- package/dist/api/client.native.cjs +12 -2
- package/dist/api/client.native.d.mts +5 -5
- package/dist/api/client.native.d.ts +5 -5
- package/dist/api/client.native.mjs +12 -2
- package/dist/api/node.cjs +223 -0
- package/dist/api/node.d.mts +61 -0
- package/dist/api/node.d.ts +61 -0
- package/dist/api/node.mjs +223 -0
- package/dist/api/route-manager.cjs +11 -11
- package/dist/api/route-manager.d.mts +14 -11
- package/dist/api/route-manager.d.ts +14 -11
- package/dist/api/route-manager.mjs +10 -10
- package/dist/api/runtime.cjs +11 -7
- package/dist/api/runtime.d.mts +11 -9
- package/dist/api/runtime.d.ts +11 -9
- package/dist/api/runtime.mjs +10 -6
- package/dist/{api-client.d-BNLXNCXJ.d.mts → api-client.d-Bp35zMqR.d.mts} +1 -1
- package/dist/{api-client.d-ddQBNGtu.d.ts → api-client.d-CFI_xL0V.d.ts} +1 -1
- package/dist/api.cjs +17 -13
- package/dist/api.d.mts +15 -12
- package/dist/api.d.ts +15 -12
- package/dist/api.mjs +16 -12
- package/dist/{app-manifest.d-DDmNkYQQ.d.ts → app-manifest.d-BT5i2F-o.d.ts} +1 -1
- package/dist/{app-manifest.d-BpKxiU_E.d.mts → app-manifest.d-Dd4q5CFx.d.mts} +1 -1
- package/dist/app-markdown.cjs +5 -5
- package/dist/app-markdown.d.mts +15 -15
- package/dist/app-markdown.d.ts +15 -15
- package/dist/app-markdown.mjs +4 -4
- package/dist/{app.d-x68Cwr0_.d.ts → app.d-BVOpL_f2.d.ts} +52 -11
- package/dist/{app.d-kuoVWhWM.d.mts → app.d-BhiDXex_.d.mts} +52 -11
- package/dist/{chunk-RY4ABNPE.cjs → chunk-225APHKC.cjs} +3 -3
- package/dist/{chunk-JGAE5XPL.cjs → chunk-23VJEGKC.cjs} +4 -2
- package/dist/{chunk-5C7XMKQ4.cjs → chunk-2AFW7673.cjs} +6 -1
- package/dist/{chunk-SYW346ZN.cjs → chunk-2LHZD3OP.cjs} +1 -21
- package/dist/{chunk-ZZI56IUY.mjs → chunk-2ZOYOYEE.mjs} +13 -13
- package/dist/{chunk-7XGWBPQQ.cjs → chunk-3EEINK7G.cjs} +24 -10
- package/dist/{chunk-BRWIVOV4.cjs → chunk-3GNHJ3RN.cjs} +10 -8
- package/dist/{chunk-HCGWDRZO.mjs → chunk-3Y52TWYU.mjs} +18 -7
- package/dist/{chunk-CBOEJ5Z4.cjs → chunk-437QZIC2.cjs} +133 -46
- package/dist/{chunk-O6L3YYPM.cjs → chunk-4E57QHPW.cjs} +8 -16
- package/dist/{chunk-WKPBIT5Q.cjs → chunk-4HGLJOXZ.cjs} +6 -6
- package/dist/{chunk-CJNAUEVC.mjs → chunk-4QENVMG7.mjs} +1 -1
- package/dist/{chunk-EMNKZGF4.mjs → chunk-4UAQB5LB.mjs} +556 -462
- package/dist/{chunk-BQWBHWEW.mjs → chunk-4ZXKYCYK.mjs} +1 -1
- package/dist/{chunk-N35YPV4N.mjs → chunk-57QAQU4F.mjs} +9 -7
- package/dist/{chunk-ZEXE4TGY.mjs → chunk-5FBZJJGA.mjs} +247 -110
- package/dist/{chunk-4OSOLDPL.cjs → chunk-5JKDFRTK.cjs} +2 -2
- package/dist/{chunk-OLIGNTWU.cjs → chunk-5NFQ6AZI.cjs} +7 -7
- package/dist/{chunk-6HRAK7I5.mjs → chunk-5OFNUETM.mjs} +8 -2
- package/dist/{chunk-RD623KW4.cjs → chunk-67MZTLTF.cjs} +21 -3
- package/dist/chunk-6I4BFRE7.cjs +51 -0
- package/dist/{chunk-UBMHQVWN.mjs → chunk-6OFOIMNS.mjs} +1 -1
- package/dist/{chunk-K5EW7GUU.mjs → chunk-7BIW7VCW.mjs} +13 -5
- package/dist/{chunk-CHYTADNK.cjs → chunk-7LK5CTUM.cjs} +70 -53
- package/dist/{chunk-HPP2II4Z.mjs → chunk-7PJARAQQ.mjs} +1 -1
- package/dist/{chunk-LEJDW34D.cjs → chunk-7PPLTD3P.cjs} +3 -3
- package/dist/{chunk-BYRZ5VTH.mjs → chunk-A3T445WK.mjs} +47 -34
- package/dist/{chunk-TGULJSHD.mjs → chunk-AJNBTOVQ.mjs} +20 -9
- package/dist/{chunk-FBEBSAVI.cjs → chunk-AKIQ54FK.cjs} +82 -63
- package/dist/{chunk-2NGZFOKG.mjs → chunk-AOIUYHPH.mjs} +2 -2
- package/dist/{chunk-NKRZLQUK.mjs → chunk-AQIO3RNL.mjs} +1 -1
- package/dist/chunk-AQIRXBBY.cjs +26 -0
- package/dist/{chunk-DQJ2CIH7.cjs → chunk-ASYOWPSR.cjs} +2 -1
- package/dist/chunk-AZ6IW6SF.mjs +28 -0
- package/dist/{chunk-QMDU6QHN.mjs → chunk-B6RBJJ5G.mjs} +1 -1
- package/dist/{chunk-I32V5CZL.cjs → chunk-BDYM2TN3.cjs} +28 -17
- package/dist/{chunk-JLDNXURZ.cjs → chunk-BZWTBELF.cjs} +32 -32
- package/dist/{chunk-ITV4QQL2.cjs → chunk-C6CUUBY5.cjs} +14 -3
- package/dist/{chunk-QGJ4FI2G.mjs → chunk-C6HGUTXB.mjs} +113 -29
- package/dist/{chunk-YN6BHOYY.cjs → chunk-CL52PD6D.cjs} +10 -3
- package/dist/{chunk-VQJHT2ND.mjs → chunk-CRVSYDHV.mjs} +2 -2
- package/dist/{chunk-XURDCXNH.cjs → chunk-CSLHNBPS.cjs} +6 -6
- package/dist/{chunk-XQSYOVCW.cjs → chunk-DBYNZIIQ.cjs} +13 -5
- package/dist/{chunk-AZUUKA66.mjs → chunk-DIXFKAPM.mjs} +1251 -389
- package/dist/{chunk-QTD6EMN2.mjs → chunk-DQ2DI3Y7.mjs} +11 -4
- package/dist/{chunk-NHQM2Q4I.cjs → chunk-DWLNLU55.cjs} +2 -2
- package/dist/chunk-DXZ57EPE.mjs +375 -0
- package/dist/{chunk-SA7MLSP4.mjs → chunk-E3HDJCWF.mjs} +3 -3
- package/dist/{chunk-52Y3C3HG.mjs → chunk-E7VF3LQ5.mjs} +3 -2
- package/dist/{chunk-752XUZIM.cjs → chunk-EGIY4A7V.cjs} +6 -6
- package/dist/chunk-EIVGPQN5.mjs +51 -0
- package/dist/{chunk-KPAJWD3N.mjs → chunk-EYPSKXO4.mjs} +1 -1
- package/dist/{chunk-E4UDLFWR.cjs → chunk-F36LS2C7.cjs} +796 -702
- package/dist/{chunk-MPIGW42F.mjs → chunk-F6CMGWAL.mjs} +1 -1
- package/dist/{chunk-GL7N5UHF.cjs → chunk-FJMC24KG.cjs} +21 -10
- package/dist/{chunk-QISW423S.cjs → chunk-FPBOAG6N.cjs} +2 -2
- package/dist/{chunk-3CCAICF7.cjs → chunk-FSODPZRT.cjs} +5 -5
- package/dist/{chunk-2C5L5RPM.cjs → chunk-FT6KJHS3.cjs} +71 -38
- package/dist/{chunk-WMTBBQHY.cjs → chunk-FVYBEMOD.cjs} +288 -151
- package/dist/{chunk-BM2LH2JM.mjs → chunk-G7NBPP7H.mjs} +14 -13
- package/dist/{chunk-ES2LD2YD.mjs → chunk-GCRT6GJG.mjs} +18 -0
- package/dist/{chunk-5OJVKXFV.cjs → chunk-GDM3ZD2O.cjs} +10 -8
- package/dist/{chunk-25T5VXOE.mjs → chunk-GFPS7MNE.mjs} +106 -19
- package/dist/{chunk-EMDGXYUD.mjs → chunk-GJ7QVFAG.mjs} +16 -7
- package/dist/{chunk-TGSEVBPO.mjs → chunk-GJEC5S4V.mjs} +11 -0
- package/dist/{chunk-HNAISJFD.cjs → chunk-HDPT6OYE.cjs} +9 -3
- package/dist/{chunk-RVGSVQWT.mjs → chunk-HEJM46HQ.mjs} +21 -7
- package/dist/chunk-HHLEYA4B.cjs +17 -0
- package/dist/{chunk-ZNH6NR3H.cjs → chunk-HJZZSBVK.cjs} +2 -2
- package/dist/{chunk-E552H232.cjs → chunk-I7J5RLGO.cjs} +16 -2
- package/dist/chunk-ICFPTHXM.mjs +97 -0
- package/dist/{chunk-K7OZAVOI.mjs → chunk-IFR74W6S.mjs} +46 -13
- package/dist/{chunk-MPJEIHW2.cjs → chunk-IGDYL2IA.cjs} +2 -2
- package/dist/{chunk-5A77OEIG.cjs → chunk-IHTDLCDJ.cjs} +5 -5
- package/dist/{chunk-OYZXVBZP.cjs → chunk-IUKBPBM7.cjs} +2 -1
- package/dist/chunk-J6TZRYCO.cjs +22 -0
- package/dist/{chunk-E4RDMG3K.mjs → chunk-JL2YW5KX.mjs} +5 -4
- package/dist/chunk-JSOCDYER.cjs +375 -0
- package/dist/{chunk-UPYIFH2H.cjs → chunk-JWLRBDDC.cjs} +2 -2
- package/dist/{chunk-OLGQZRW6.mjs → chunk-JZBU7V4D.mjs} +37 -17
- package/dist/{chunk-ONG4RDW3.mjs → chunk-JZGL2PIH.mjs} +13 -3
- package/dist/chunk-K63OWRY2.mjs +22 -0
- package/dist/{chunk-TUPKMMXT.mjs → chunk-K6HIIWUB.mjs} +1 -1
- package/dist/{chunk-MESQF2JC.mjs → chunk-K6SXMVXO.mjs} +2 -2
- package/dist/{chunk-L2JG337G.cjs → chunk-K6VFYFOY.cjs} +33 -31
- package/dist/{chunk-TKK5QHKZ.mjs → chunk-KDO6T6OB.mjs} +3 -3
- package/dist/{chunk-EZ34EHQP.mjs → chunk-KI3MU7B5.mjs} +1 -1
- package/dist/{chunk-GHNW564E.mjs → chunk-KSZK34HU.mjs} +30 -10
- package/dist/{chunk-IT6WRNGB.cjs → chunk-KWCZKJYU.cjs} +1541 -679
- package/dist/{chunk-DVKH2RVN.cjs → chunk-LDEXTX4I.cjs} +70 -57
- package/dist/{chunk-ECKQFEX2.mjs → chunk-LENKRGBV.mjs} +8 -6
- package/dist/{chunk-XBSKPLHF.cjs → chunk-LR4KP3I7.cjs} +2 -2
- package/dist/{chunk-HEPJIKKQ.cjs → chunk-MCSRMEQV.cjs} +2 -2
- package/dist/{chunk-DQF3QLOH.mjs → chunk-ME7RVELR.mjs} +3 -2
- package/dist/{chunk-VFXE6NWR.mjs → chunk-MGKWYPE3.mjs} +2 -1
- package/dist/{chunk-TZVUF5JJ.mjs → chunk-MGZVDX4R.mjs} +5 -5
- package/dist/{chunk-MGKW5XZE.cjs → chunk-MMDKYJ5V.cjs} +7 -7
- package/dist/{chunk-SK7QSNWE.mjs → chunk-MNJDNTGO.mjs} +1 -1
- package/dist/{chunk-5Y2P454O.cjs → chunk-MTBDJ326.cjs} +6 -5
- package/dist/{chunk-FIR62CR3.mjs → chunk-MV7NWU23.mjs} +1 -1
- package/dist/{chunk-7ONGIFYX.cjs → chunk-MZ4CRSY7.cjs} +481 -171
- package/dist/{chunk-O4F3JUST.mjs → chunk-NDDRTFN4.mjs} +4 -0
- package/dist/{chunk-4IHMHFQB.cjs → chunk-NG2EZ6QS.cjs} +28 -1
- package/dist/{chunk-XBSLKXBL.mjs → chunk-NT4W4H52.mjs} +52 -35
- package/dist/{chunk-UAQD67HM.mjs → chunk-NVOMQLI2.mjs} +16 -2
- package/dist/{chunk-R62SF5R4.mjs → chunk-OB45EAQL.mjs} +6 -1
- package/dist/{chunk-V56632LA.cjs → chunk-OCNV4CI2.cjs} +39 -6
- package/dist/{chunk-SYXPWJ7N.cjs → chunk-OFBLGH6V.cjs} +17 -18
- package/dist/{chunk-VQ4NWOWO.mjs → chunk-OGVTUGMU.mjs} +5 -13
- package/dist/{chunk-3UZVPO72.mjs → chunk-OIOPQ25L.mjs} +6 -7
- package/dist/{chunk-2XGBJSDV.cjs → chunk-OO7DYIJD.cjs} +73 -24
- package/dist/{chunk-27FPUFWR.mjs → chunk-P2NBQ5JI.mjs} +1 -1
- package/dist/{chunk-HZPKJRYA.cjs → chunk-PDFFYZAT.cjs} +2 -2
- package/dist/{chunk-GSVJ3IIF.cjs → chunk-PHCJJJZV.cjs} +2 -2
- package/dist/{chunk-EVMXPJCB.mjs → chunk-PKMUQ7LM.mjs} +2 -1
- package/dist/{chunk-OAJOQU5J.mjs → chunk-PLJKJJ2H.mjs} +82 -63
- package/dist/{chunk-72KCTHLV.cjs → chunk-PRL7FXG4.cjs} +113 -29
- package/dist/{chunk-6XQSPIN6.cjs → chunk-PWKAX5MS.cjs} +13 -3
- package/dist/{chunk-4ZJ5C7UJ.cjs → chunk-QIXEU2WV.cjs} +19 -10
- package/dist/{chunk-FJWN7RV4.cjs → chunk-QO43L7Z4.cjs} +38 -8
- package/dist/{chunk-X4K7TYN6.cjs → chunk-QOGIZKSO.cjs} +26 -25
- package/dist/{chunk-CNNBFGL5.cjs → chunk-QSUYB3RH.cjs} +14 -14
- package/dist/chunk-QYNZ3CTI.mjs +17 -0
- package/dist/{chunk-X3XUZWRB.mjs → chunk-R2ZHU37O.mjs} +36 -3
- package/dist/{chunk-ZIHWAN55.cjs → chunk-RE5E2G5S.cjs} +1 -1
- package/dist/{chunk-O75GQVUK.mjs → chunk-RLH5AH2M.mjs} +1 -1
- package/dist/chunk-RWR7SMD7.cjs +50 -0
- package/dist/{chunk-7PTISZSQ.cjs → chunk-S7MWSFFP.cjs} +4 -0
- package/dist/chunk-SD6JGJOM.mjs +50 -0
- package/dist/{chunk-7H4SVNC4.cjs → chunk-SPP3EZTJ.cjs} +46 -26
- package/dist/{chunk-BIF5MLTH.cjs → chunk-SQ6IWJ3H.cjs} +1 -1
- package/dist/{chunk-WVYRLP5E.mjs → chunk-T5XFZQCL.mjs} +1 -1
- package/dist/{chunk-WAY6LOQH.mjs → chunk-TEJ67GD2.mjs} +1 -1
- package/dist/{chunk-OP7LHY4Y.cjs → chunk-TNK2TVRS.cjs} +2005 -800
- package/dist/{chunk-IFTGERT3.mjs → chunk-TTXIITYA.mjs} +49 -0
- package/dist/{chunk-ZFWYCVKS.mjs → chunk-TY5KCYDE.mjs} +22 -4
- package/dist/{chunk-WYAXRIYP.cjs → chunk-UKZ6AWKZ.cjs} +10 -9
- package/dist/{chunk-UJ3R2AH2.cjs → chunk-UPOYKX4S.cjs} +5 -5
- package/dist/{chunk-VBCQ5WOI.cjs → chunk-URN7VFO7.cjs} +105 -16
- package/dist/{chunk-2DLGV2ZG.mjs → chunk-UTUS6JUH.mjs} +1 -21
- package/dist/{chunk-435QJNC2.mjs → chunk-VFNAK6A5.mjs} +4 -4
- package/dist/{chunk-WFWFECDW.mjs → chunk-VRGY3X2I.mjs} +100 -11
- package/dist/{chunk-LQNW3ABP.cjs → chunk-VX2HZGC7.cjs} +14 -14
- package/dist/chunk-W44X6IC2.cjs +97 -0
- package/dist/{chunk-A2MN5PQJ.mjs → chunk-WMLSZAKN.mjs} +9 -9
- package/dist/{chunk-672ISQIG.mjs → chunk-WPB67LE5.mjs} +379 -69
- package/dist/{chunk-3EEET2Q5.cjs → chunk-WUTFJOV7.cjs} +32 -12
- package/dist/chunk-WVQNXXNE.cjs +28 -0
- package/dist/{chunk-Y5TOT5F6.cjs → chunk-X3MHKLCO.cjs} +5 -5
- package/dist/{chunk-W2ZXMMHA.mjs → chunk-XCAQTCGK.mjs} +1 -1
- package/dist/{chunk-Z7P2BTZ3.cjs → chunk-XGTFLG73.cjs} +30 -12
- package/dist/{chunk-XCXHQBMM.mjs → chunk-Y2LU4LE5.mjs} +1 -1
- package/dist/{chunk-5J45H65F.mjs → chunk-Y5LEPEVH.mjs} +1 -1
- package/dist/{chunk-D4MRNBVF.cjs → chunk-Y6KHPJDB.cjs} +2 -2
- package/dist/{chunk-BT4SEFLC.cjs → chunk-YAEN3L2F.cjs} +3 -2
- package/dist/chunk-YFTGIHNC.mjs +26 -0
- package/dist/{chunk-KL7SHLQB.mjs → chunk-YGJ5P3TJ.mjs} +31 -1
- package/dist/{chunk-752IHQTD.cjs → chunk-YTNBCXCW.cjs} +12 -12
- package/dist/{chunk-RFKTJTWZ.mjs → chunk-YVPX5PI5.mjs} +3 -1
- package/dist/{chunk-4TVPYN32.cjs → chunk-Z3PW3DIR.cjs} +7 -7
- package/dist/{chunk-OB7VKCUZ.mjs → chunk-Z6SOXHAD.mjs} +1851 -646
- package/dist/{chunk-72KABRWN.mjs → chunk-ZJGFAW5U.mjs} +5 -3
- package/dist/{chunk-TNBJ4LZG.mjs → chunk-ZPKJPM7K.mjs} +4 -4
- package/dist/{chunk-5FE5YT2N.mjs → chunk-ZZGQD3LL.mjs} +28 -1
- package/dist/client/lifecycle.cjs +2 -2
- package/dist/client/lifecycle.d.mts +1 -1
- package/dist/client/lifecycle.d.ts +1 -1
- package/dist/client/lifecycle.mjs +1 -1
- package/dist/{client-component.d-D74pqdea.d.mts → client-component.d-BvQOxSqh.d.mts} +2 -2
- package/dist/{client-component.d-D8VcypQA.d.ts → client-component.d-DNVSLEPi.d.ts} +2 -2
- package/dist/client-plugins.cjs +2 -2
- package/dist/{client-plugins.d-D4-6hNx7.d.mts → client-plugins.d-CE1lVK2R.d.mts} +116 -373
- package/dist/{client-plugins.d-CXElzotB.d.ts → client-plugins.d-CNDqcAuf.d.ts} +116 -373
- package/dist/client-plugins.d.mts +10 -8
- package/dist/client-plugins.d.ts +10 -8
- package/dist/client-plugins.mjs +1 -1
- package/dist/client.cjs +11 -9
- package/dist/client.d.mts +17 -15
- package/dist/client.d.ts +17 -15
- package/dist/client.mjs +10 -8
- package/dist/{config.d-qt-mE8O5.d.mts → config.d-BKIhJtmr.d.mts} +7 -2
- package/dist/{config.d-qt-mE8O5.d.ts → config.d-BKIhJtmr.d.ts} +7 -2
- package/dist/config.d.mts +10 -8
- package/dist/config.d.ts +10 -8
- package/dist/cron.cjs +2 -2
- package/dist/cron.mjs +1 -1
- package/dist/deferred.cjs +2 -2
- package/dist/deferred.mjs +1 -1
- package/dist/deployment.cjs +4 -2
- package/dist/deployment.d.mts +15 -1
- package/dist/deployment.d.ts +15 -1
- package/dist/deployment.mjs +3 -1
- package/dist/desktop.d.mts +11 -9
- package/dist/desktop.d.ts +11 -9
- package/dist/{devtools-NZUVNUP3.mjs → devtools-2A2GPC7B.mjs} +33 -29
- package/dist/{devtools-N2JQCMXB.cjs → devtools-R27T3BRY.cjs} +38 -34
- package/dist/docs.cjs +28 -27
- package/dist/docs.d.mts +24 -10
- package/dist/docs.d.ts +24 -10
- package/dist/docs.mjs +27 -26
- package/dist/env-types.cjs +3 -3
- package/dist/env-types.mjs +2 -2
- package/dist/environment/vite.cjs +7 -7
- package/dist/environment/vite.d.mts +1 -1
- package/dist/environment/vite.d.ts +1 -1
- package/dist/environment/vite.mjs +6 -6
- package/dist/{generate-route-types.d-BL2pq6xC.d.ts → generate-route-types.d-B76M5R11.d.ts} +1 -1
- package/dist/{generate-route-types.d-BoVDU8qX.d.mts → generate-route-types.d-CaGMIaNI.d.mts} +1 -1
- package/dist/headers.cjs +3 -3
- package/dist/headers.mjs +2 -2
- package/dist/image/server.d.mts +1 -1
- package/dist/image/server.d.ts +1 -1
- package/dist/image/sharp.d.mts +1 -1
- package/dist/image/sharp.d.ts +1 -1
- package/dist/{image-config.d-CeDgNyX4.d.mts → image-config.d-ByhQ0TT7.d.mts} +3 -1
- package/dist/{image-config.d-CeDgNyX4.d.ts → image-config.d-ByhQ0TT7.d.ts} +3 -1
- package/dist/image.cjs +6 -6
- package/dist/image.d.mts +1 -1
- package/dist/image.d.ts +1 -1
- package/dist/image.mjs +1 -1
- package/dist/index.cjs +148 -128
- package/dist/{index.d-SSgYDv4D.d.mts → index.d-Bt3kl19W.d.mts} +1 -1
- package/dist/{index.d-A_x10zGS.d.ts → index.d-Cx_-DaKV.d.ts} +1 -1
- package/dist/index.d.mts +39 -87
- package/dist/index.d.ts +39 -87
- package/dist/index.mjs +224 -204
- package/dist/instrumentation.cjs +3 -3
- package/dist/instrumentation.mjs +2 -2
- package/dist/{integration-orm-52GPGTHO.cjs → integrations/orm.cjs} +5 -5
- package/dist/integrations/orm.d.mts +35 -0
- package/dist/integrations/orm.d.ts +35 -0
- package/dist/{integration-orm-CO23MSFE.mjs → integrations/orm.mjs} +5 -5
- package/dist/integrations.cjs +6 -5
- package/dist/integrations.d.mts +10 -8
- package/dist/integrations.d.ts +10 -8
- package/dist/integrations.mjs +5 -4
- package/dist/internal/app-markdown-runtime.cjs +4 -4
- package/dist/internal/app-markdown-runtime.d.mts +27 -11
- package/dist/internal/app-markdown-runtime.d.ts +27 -11
- package/dist/internal/app-markdown-runtime.mjs +3 -3
- package/dist/internal/build-runtime.cjs +76 -71
- package/dist/internal/build-runtime.d.mts +12 -10
- package/dist/internal/build-runtime.d.ts +12 -10
- package/dist/internal/build-runtime.mjs +75 -70
- package/dist/internal/cli-runtime.cjs +47 -46
- package/dist/internal/cli-runtime.mjs +46 -45
- package/dist/internal/client-error-overlay.cjs +6 -6
- package/dist/internal/client-error-overlay.mjs +2 -2
- package/dist/internal/client-runtime.cjs +85 -36
- package/dist/internal/client-runtime.d.mts +44 -13
- package/dist/internal/client-runtime.d.ts +44 -13
- package/dist/internal/client-runtime.mjs +79 -30
- package/dist/internal/compression-runtime.d.mts +10 -8
- package/dist/internal/compression-runtime.d.ts +10 -8
- package/dist/internal/config-runtime.cjs +27 -26
- package/dist/internal/config-runtime.d.mts +14 -12
- package/dist/internal/config-runtime.d.ts +14 -12
- package/dist/internal/config-runtime.mjs +26 -25
- package/dist/internal/docs-precompiled-runtime.cjs +16 -5
- package/dist/internal/docs-precompiled-runtime.d.mts +7 -0
- package/dist/internal/docs-precompiled-runtime.d.ts +7 -0
- package/dist/internal/docs-precompiled-runtime.mjs +15 -4
- package/dist/internal/form-actions.cjs +7 -2
- package/dist/internal/form-actions.d.mts +10 -3
- package/dist/internal/form-actions.d.ts +10 -3
- package/dist/internal/form-actions.mjs +8 -3
- package/dist/internal/infra-analytics-runtime.cjs +11 -11
- package/dist/internal/infra-analytics-runtime.mjs +9 -9
- package/dist/internal/islands-boot.cjs +6 -1
- package/dist/internal/islands-boot.mjs +6 -1
- package/dist/internal/islands-runtime.cjs +33 -4
- package/dist/internal/islands-runtime.d.mts +1 -1
- package/dist/internal/islands-runtime.d.ts +1 -1
- package/dist/internal/islands-runtime.mjs +31 -2
- package/dist/internal/native-server-fns.cjs +5 -5
- package/dist/internal/native-server-fns.mjs +4 -4
- package/dist/internal/product-telemetry-runtime.cjs +3 -3
- package/dist/internal/product-telemetry-runtime.mjs +2 -2
- package/dist/internal/production-node-env.cjs +4 -2
- package/dist/internal/production-node-env.d.mts +22 -1
- package/dist/internal/production-node-env.d.ts +22 -1
- package/dist/internal/production-node-env.mjs +3 -1
- package/dist/internal/production-runtime.cjs +57 -39
- package/dist/internal/production-runtime.d.mts +27 -21
- package/dist/internal/production-runtime.d.ts +27 -21
- package/dist/internal/production-runtime.mjs +72 -54
- package/dist/internal/react-cache.cjs +3 -3
- package/dist/internal/react-cache.mjs +1 -1
- package/dist/internal/server-tree.cjs +2 -2
- package/dist/internal/server-tree.d.mts +0 -5
- package/dist/internal/server-tree.d.ts +0 -5
- package/dist/internal/server-tree.mjs +1 -1
- package/dist/internal/vercel-edge-middleware.cjs +87 -0
- package/dist/internal/vercel-edge-middleware.d.mts +39 -0
- package/dist/internal/vercel-edge-middleware.d.ts +39 -0
- package/dist/internal/vercel-edge-middleware.mjs +87 -0
- package/dist/layers-7P4RLKVX.cjs +20 -0
- package/dist/{layers-T55SA47E.mjs → layers-XQ7VFMWO.mjs} +4 -2
- package/dist/{layers.d-CcS42OGR.d.mts → layers.d-CH0bC4QL.d.mts} +2 -1
- package/dist/{layers.d-CcS42OGR.d.ts → layers.d-CH0bC4QL.d.ts} +2 -1
- package/dist/{lifecycle.d-C2aLBOwu.d.ts → lifecycle.d-keQs5Swc.d.mts} +7 -1
- package/dist/{lifecycle.d-C2aLBOwu.d.mts → lifecycle.d-keQs5Swc.d.ts} +7 -1
- package/dist/{manager-H5ZM3HAM.mjs → manager-JIA66YJ2.mjs} +4 -3
- package/dist/manager-JOHU6BQI.cjs +15 -0
- package/dist/markdown.cjs +7 -3
- package/dist/markdown.d.mts +10 -8
- package/dist/markdown.d.ts +10 -8
- package/dist/markdown.mjs +6 -2
- package/dist/middleware.cjs +11 -11
- package/dist/middleware.d.mts +13 -10
- package/dist/middleware.d.ts +13 -10
- package/dist/middleware.mjs +13 -13
- package/dist/mobile.d.mts +6 -6
- package/dist/mobile.d.ts +6 -6
- package/dist/mount.d-Bki4pOaJ.d.mts +38 -0
- package/dist/mount.d-DjR5aerM.d.ts +38 -0
- package/dist/{native-server-fn-handler-GLRHAYWV.mjs → native-server-fn-handler-EP5AFJYE.mjs} +5 -5
- package/dist/{native-server-fn-handler-J5MYRXN6.cjs → native-server-fn-handler-QRTXGZA4.cjs} +6 -6
- package/dist/{native-tree-7LPH57Z4.cjs → native-tree-W2SSJB3Y.cjs} +4 -4
- package/dist/{native-tree-VV6WN3GX.mjs → native-tree-Y5YQANW7.mjs} +3 -3
- package/dist/{navigation-delegate.d-GghbHJuK.d.ts → navigation-delegate.d-CtghaSP3.d.ts} +1 -1
- package/dist/{navigation-delegate.d-DQVYKoaZ.d.mts → navigation-delegate.d-VDkziXTK.d.mts} +1 -1
- package/dist/navigation.cjs +8 -7
- package/dist/navigation.d.mts +13 -11
- package/dist/navigation.d.ts +13 -11
- package/dist/navigation.mjs +7 -6
- package/dist/{nitro-DD4QCA66.mjs → nitro-NSTXT7LB.mjs} +11 -11
- package/dist/{nitro-VRDX2H4M.cjs → nitro-Y3LGITW3.cjs} +13 -13
- package/dist/node-module-bundle-LIZ2KMVW.cjs +13 -0
- package/dist/node-module-bundle-VR6NV6AI.mjs +13 -0
- package/dist/{plugin-53SY5YBS.mjs → plugin-SAS22JL7.mjs} +4 -3
- package/dist/{plugin-HZIBL3DW.cjs → plugin-WIU4GDD4.cjs} +5 -4
- package/dist/plugin.cjs +65 -63
- package/dist/plugin.d.mts +12 -10
- package/dist/plugin.d.ts +12 -10
- package/dist/plugin.mjs +64 -62
- package/dist/{production-runtime.d-Bzns3NW9.d.ts → production-runtime.d-BMyyLGBB.d.ts} +3 -57
- package/dist/{production-runtime.d-DiFa5vHW.d.mts → production-runtime.d-DMZY3OgV.d.mts} +3 -57
- package/dist/query/client.cjs +9 -7
- package/dist/query/client.mjs +5 -3
- package/dist/{render-plan.d-CcF0MeCf.d.mts → render-plan.d-BSwV8PE4.d.mts} +1 -1
- package/dist/{render-plan.d-CL_Ikfg_.d.ts → render-plan.d-i9sI4tc9.d.ts} +1 -1
- package/dist/renderer/none/server.cjs +35 -0
- package/dist/renderer/none/server.d.mts +21 -0
- package/dist/renderer/none/server.d.ts +21 -0
- package/dist/renderer/none/server.mjs +35 -0
- package/dist/renderer/react/server.cjs +3 -3
- package/dist/renderer/react/server.mjs +3 -3
- package/dist/renderer-client.cjs +8 -6
- package/dist/renderer-client.d.mts +13 -11
- package/dist/renderer-client.d.ts +13 -11
- package/dist/renderer-client.mjs +5 -3
- package/dist/renderer.cjs +6 -2
- package/dist/renderer.d.mts +25 -2
- package/dist/renderer.d.ts +25 -2
- package/dist/renderer.mjs +5 -1
- package/dist/request.cjs +2 -2
- package/dist/{request.d-DarDOCk9.d.mts → request.d-C24FNQ_7.d.mts} +1 -1
- package/dist/{request.d-B1RnTLri.d.ts → request.d-Dgln8tuI.d.ts} +1 -1
- package/dist/request.d.mts +11 -9
- package/dist/request.d.ts +11 -9
- package/dist/request.mjs +1 -1
- package/dist/{route-rendering.d-BTUYCIj4.d.ts → route-rendering.d-CUylZKJA.d.ts} +1 -1
- package/dist/{route-rendering.d-D_2Ual0-.d.mts → route-rendering.d-Ds0BfwQi.d.mts} +1 -1
- package/dist/{route.d-BaVH3V0w.d.mts → route.d-DrXkpvcg.d.mts} +1 -1
- package/dist/{route.d-DBTEqifW.d.ts → route.d-hs-_cyHn.d.ts} +1 -1
- package/dist/{router.d-CMANF6da.d.ts → router.d-B56rMOFm.d.ts} +1 -1
- package/dist/{router.d-Cuv1jntg.d.mts → router.d-CFPcbqzc.d.mts} +1 -1
- package/dist/routes.cjs +3 -3
- package/dist/{routes.d-B6yFe6jm.d.ts → routes.d-9GFFNioh.d.ts} +2 -2
- package/dist/{routes.d-c2HKfrfL.d.mts → routes.d-CrEy0lJS.d.mts} +2 -2
- package/dist/routes.d.mts +10 -8
- package/dist/routes.d.ts +10 -8
- package/dist/routes.mjs +2 -2
- package/dist/{rsc-pipeline-Z7QBZOIJ.cjs → rsc-pipeline-3T7V6OUT.cjs} +30 -28
- package/dist/{rsc-pipeline-7PNVJSTR.mjs → rsc-pipeline-GA4AQWZI.mjs} +29 -27
- package/dist/{runtime-FKFCUHSK.cjs → runtime-REUTNTI5.cjs} +72 -46
- package/dist/{runtime-QQHX4BP3.mjs → runtime-ZYCKKY7L.mjs} +60 -34
- package/dist/{runtime.d-wvh4ngU0.d.mts → runtime.d-DLRO-ExG.d.mts} +11 -3
- package/dist/{runtime.d-C3RQUj6_.d.ts → runtime.d-H7k9hOQE.d.ts} +11 -3
- package/dist/{schema-dev-notice-JMXEQWIQ.mjs → schema-dev-notice-C2JINRZI.mjs} +3 -2
- package/dist/{schema-dev-notice-PLBFDTOF.cjs → schema-dev-notice-X7GG7QVB.cjs} +5 -4
- package/dist/schema.cjs +6 -2
- package/dist/schema.d-Dny9pnrm.d.mts +298 -0
- package/dist/schema.d-Dny9pnrm.d.ts +298 -0
- package/dist/schema.d.mts +1 -115
- package/dist/schema.d.ts +1 -115
- package/dist/schema.mjs +5 -1
- package/dist/server-fn-client.d.mts +2 -2
- package/dist/server-fn-client.d.ts +2 -2
- package/dist/server-fn.cjs +5 -5
- package/dist/server-fn.mjs +4 -4
- package/dist/server-http.d-rAe7lAQc.d.mts +70 -0
- package/dist/server-http.d-rAe7lAQc.d.ts +70 -0
- package/dist/server-plugins.cjs +7 -7
- package/dist/server-plugins.d.mts +20 -12
- package/dist/server-plugins.d.ts +20 -12
- package/dist/server-plugins.mjs +8 -8
- package/dist/server-query.cjs +6 -6
- package/dist/server-query.mjs +5 -5
- package/dist/server.cjs +168 -126
- package/dist/server.d-C5FFrZAo.d.ts +57 -0
- package/dist/server.d-DgC8xew5.d.mts +57 -0
- package/dist/server.d.mts +24 -16
- package/dist/server.d.ts +24 -16
- package/dist/server.mjs +144 -102
- package/dist/{spa-router.d-m8H_Kl_B.d.ts → spa-router.d-Dr7oanhl.d.ts} +15 -5
- package/dist/{spa-router.d-WU_qS5gJ.d.mts → spa-router.d-g4CzhEH1.d.mts} +15 -5
- package/dist/testing.cjs +17 -17
- package/dist/testing.d.mts +10 -8
- package/dist/testing.d.ts +10 -8
- package/dist/testing.mjs +13 -13
- package/dist/theme/server.cjs +3 -3
- package/dist/theme/server.mjs +2 -2
- package/dist/types.d-xCIhyjOq.d.mts +233 -0
- package/dist/types.d-xCIhyjOq.d.ts +233 -0
- package/dist/{utils.d-C9dQD5Zg.d.ts → utils.d-BxxyDEb8.d.ts} +1 -1
- package/dist/{utils.d-W9IiEqmW.d.mts → utils.d-HIla3pD_.d.mts} +1 -1
- package/dist/version.cjs +2 -2
- package/dist/version.mjs +1 -1
- package/dist/vite.cjs +65 -63
- package/dist/vite.d.mts +36 -14
- package/dist/vite.d.ts +36 -14
- package/dist/vite.mjs +64 -62
- package/dist/workflows.cjs +4 -4
- package/dist/workflows.d.mts +121 -1
- package/dist/workflows.d.ts +121 -1
- package/dist/workflows.mjs +3 -3
- package/package.json +37 -2
- package/dist/analyzer-H7SIX6BJ.cjs +0 -16
- package/dist/chunk-5YPBFMBN.cjs +0 -19
- package/dist/chunk-CLFEQGET.cjs +0 -60
- package/dist/chunk-MK5E44WP.mjs +0 -60
- package/dist/chunk-OM7WILES.mjs +0 -100
- package/dist/chunk-Q5B4LNON.mjs +0 -19
- package/dist/chunk-QPJ4MZTO.mjs +0 -60
- package/dist/chunk-R53QDV6T.cjs +0 -100
- package/dist/chunk-UYTAP4FQ.cjs +0 -60
- package/dist/layers-DMRXRL7F.cjs +0 -18
- package/dist/manager-2LUKNX2N.cjs +0 -14
- package/dist/node-module-bundle-7JHPPF6B.mjs +0 -11
- package/dist/node-module-bundle-YJGYBOGK.cjs +0 -11
- package/dist/workflows.d-CRMzQZ3k.d.mts +0 -188
- package/dist/workflows.d-CRMzQZ3k.d.ts +0 -188
- /package/dist/{chunk-QGOZLGVP.mjs → chunk-I6FIAWNT.mjs} +0 -0
- /package/dist/{chunk-XPIPMWY3.cjs → chunk-K5NI5YQR.cjs} +0 -0
- /package/dist/{chunk-NWUHS6GV.cjs → chunk-QEJWNXRI.cjs} +0 -0
- /package/dist/{chunk-FSXSQQTV.mjs → chunk-TXE4SAMV.mjs} +0 -0
- /package/dist/{chunk-ZXK2EYQW.cjs → chunk-UUQNJDGH.cjs} +0 -0
- /package/dist/{chunk-46P5KNTE.mjs → chunk-VZBAW44S.mjs} +0 -0
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
hasFarmServerRuntimePlugins
|
|
3
|
+
} from "./chunk-QYNZ3CTI.mjs";
|
|
1
4
|
import {
|
|
2
5
|
FARM_MOBILE_CLIENT_ENTRY_NAME,
|
|
3
6
|
FARM_MOBILE_SHELL_CLIENT_PLACEHOLDER,
|
|
@@ -20,25 +23,27 @@ import {
|
|
|
20
23
|
createFarmBunServerEntry,
|
|
21
24
|
createFarmCompileCacheLauncher,
|
|
22
25
|
createFarmNodeServerEntry,
|
|
26
|
+
createReactProductionModePlugin,
|
|
23
27
|
withProductionNodeEnv
|
|
24
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-ZZGQD3LL.mjs";
|
|
29
|
+
import {
|
|
30
|
+
collectFarmNativeServerFns,
|
|
31
|
+
findFarmNativeScreenFiles
|
|
32
|
+
} from "./chunk-MNJDNTGO.mjs";
|
|
25
33
|
import {
|
|
26
34
|
generateNativeMCPPluginSource
|
|
27
35
|
} from "./chunk-KQH2COEJ.mjs";
|
|
28
36
|
import {
|
|
29
37
|
FARM_MOBILE_SESSION_PLUGIN
|
|
30
38
|
} from "./chunk-B4CWYGCG.mjs";
|
|
31
|
-
import {
|
|
32
|
-
collectFarmNativeServerFns,
|
|
33
|
-
findFarmNativeScreenFiles
|
|
34
|
-
} from "./chunk-SK7QSNWE.mjs";
|
|
35
39
|
import {
|
|
36
40
|
assertFarmDocsAdapterServesNoGuardedPages,
|
|
37
41
|
compileFarmDocsAdapterEdgeManifest,
|
|
38
42
|
createFarmDocsAPIHandler,
|
|
43
|
+
farmDocsAdapterServesGuardedPages,
|
|
39
44
|
hasFarmDocsRuntimeAdapter,
|
|
40
45
|
listFarmDocsAdapterPages
|
|
41
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-A3T445WK.mjs";
|
|
42
47
|
import {
|
|
43
48
|
FARM_DOCS_LAST_MODIFIED_MANIFEST,
|
|
44
49
|
createFarmDocsHandler,
|
|
@@ -47,18 +52,22 @@ import {
|
|
|
47
52
|
getFarmDocsMarkdownPath,
|
|
48
53
|
getFarmDocsRoots,
|
|
49
54
|
getFarmDocsRouteTypeEntries,
|
|
55
|
+
listFarmDocsBuiltInPrerenderPages,
|
|
50
56
|
loadFarmDocsPage,
|
|
51
57
|
resolveFarmDocsContentDir,
|
|
52
58
|
toFarmDocsMarkdownPage
|
|
53
|
-
} from "./chunk-
|
|
59
|
+
} from "./chunk-5FBZJJGA.mjs";
|
|
54
60
|
import {
|
|
55
61
|
generateFarmDocsSearchClientRuntime,
|
|
56
62
|
isFarmDocsSearchEnabled,
|
|
57
63
|
resolveFarmDocsSearchClientModule
|
|
58
64
|
} from "./chunk-ALEUMLJN.mjs";
|
|
65
|
+
import {
|
|
66
|
+
CDN_CACHE_CONTROL_HEADERS
|
|
67
|
+
} from "./chunk-JL2YW5KX.mjs";
|
|
59
68
|
import {
|
|
60
69
|
FARM_PRERENDER_ENV
|
|
61
|
-
} from "./chunk-
|
|
70
|
+
} from "./chunk-KDO6T6OB.mjs";
|
|
62
71
|
import {
|
|
63
72
|
loadFarmDocsEngine
|
|
64
73
|
} from "./chunk-VE3FWJBO.mjs";
|
|
@@ -67,17 +76,19 @@ import {
|
|
|
67
76
|
getDeployTargetForPreset,
|
|
68
77
|
hasCustomFarmRouteContext,
|
|
69
78
|
resolveDeployOutputPath
|
|
70
|
-
} from "./chunk-
|
|
79
|
+
} from "./chunk-NT4W4H52.mjs";
|
|
71
80
|
import {
|
|
72
81
|
resolveFarmInstrumentationFile
|
|
73
|
-
} from "./chunk-
|
|
82
|
+
} from "./chunk-57QAQU4F.mjs";
|
|
74
83
|
import {
|
|
75
84
|
resolveFarmInstrumentationRuntime
|
|
76
85
|
} from "./chunk-WNDAISB7.mjs";
|
|
77
86
|
import {
|
|
78
87
|
DEFAULT_NOT_FOUND_STYLES,
|
|
79
88
|
FARM_LAYOUT_ELEMENT_CLIENT_SOURCE,
|
|
89
|
+
FARM_NAVIGATION_SCRIPT_SOURCE,
|
|
80
90
|
FARM_NAVIGATION_STREAM_READER_SOURCE,
|
|
91
|
+
FARM_REFRESH_FIELDS_SOURCE,
|
|
81
92
|
FARM_SERVER_TREE_LAYOUT_CLIENT_SOURCE,
|
|
82
93
|
SHARP_INSTALL_HINT,
|
|
83
94
|
canBootFarmIslandsClient,
|
|
@@ -85,10 +96,11 @@ import {
|
|
|
85
96
|
createFarmApp,
|
|
86
97
|
createFarmSourceAlias,
|
|
87
98
|
createFarmThemeCssPlugin,
|
|
99
|
+
exactIdPattern,
|
|
88
100
|
farmDocsClientConfigPlugin,
|
|
89
101
|
farmFontImportsPlugin,
|
|
102
|
+
fileNamePattern,
|
|
90
103
|
generateClientCachePersistenceCode,
|
|
91
|
-
generateFarmClientPluginEntryCode,
|
|
92
104
|
generateFarmIntegrationProviderClientCode,
|
|
93
105
|
generateFarmIntegrationProviderServerModules,
|
|
94
106
|
mergeFarmFontCss,
|
|
@@ -100,18 +112,19 @@ import {
|
|
|
100
112
|
resolveFarmImageServerRuntime,
|
|
101
113
|
resolveFarmNotFoundComponentPath,
|
|
102
114
|
resolveFarmRouteRootStrategy
|
|
103
|
-
} from "./chunk-
|
|
115
|
+
} from "./chunk-4UAQB5LB.mjs";
|
|
104
116
|
import {
|
|
117
|
+
generateFarmClientPluginEntryCode,
|
|
105
118
|
loadTailwindVitePlugin
|
|
106
|
-
} from "./chunk-
|
|
119
|
+
} from "./chunk-DXZ57EPE.mjs";
|
|
107
120
|
import {
|
|
108
121
|
PluginManager
|
|
109
|
-
} from "./chunk-
|
|
122
|
+
} from "./chunk-KSZK34HU.mjs";
|
|
110
123
|
import {
|
|
111
124
|
generateFarmTypeArtifacts,
|
|
112
125
|
readRouteRenderingDirectiveFromFile,
|
|
113
126
|
resolveRouteRenderingConfigFromFile
|
|
114
|
-
} from "./chunk-
|
|
127
|
+
} from "./chunk-G7NBPP7H.mjs";
|
|
115
128
|
import {
|
|
116
129
|
HOISTED_HEAD_ELEMENT,
|
|
117
130
|
appMiddlewareMayHandlePath,
|
|
@@ -124,7 +137,7 @@ import {
|
|
|
124
137
|
layoutsCanCoverSamePage,
|
|
125
138
|
routeBoundaryCoversDirectory,
|
|
126
139
|
stripRouteGroups
|
|
127
|
-
} from "./chunk-
|
|
140
|
+
} from "./chunk-ZPKJPM7K.mjs";
|
|
128
141
|
import {
|
|
129
142
|
FARM_NATIVE_TREE_CONTENT_TYPE
|
|
130
143
|
} from "./chunk-LLZSYFOM.mjs";
|
|
@@ -138,15 +151,15 @@ import {
|
|
|
138
151
|
listFarmBuiltInRoutePaths,
|
|
139
152
|
resolveFarmApiCatalogInput,
|
|
140
153
|
resolveFarmAppManifestInput
|
|
141
|
-
} from "./chunk-
|
|
154
|
+
} from "./chunk-VFNAK6A5.mjs";
|
|
142
155
|
import {
|
|
143
156
|
FARM_DEFAULT_MCP_PATH,
|
|
144
157
|
createFarmDefaultMCPServer,
|
|
145
158
|
farmConfigMountsMCP
|
|
146
|
-
} from "./chunk-
|
|
159
|
+
} from "./chunk-K6SXMVXO.mjs";
|
|
147
160
|
import {
|
|
148
161
|
isFarmPreviewDeploymentEnvironment
|
|
149
|
-
} from "./chunk-
|
|
162
|
+
} from "./chunk-T5XFZQCL.mjs";
|
|
150
163
|
import {
|
|
151
164
|
FARM_NATIVE_SERVER_FN_PLUGIN
|
|
152
165
|
} from "./chunk-L4RTTTVE.mjs";
|
|
@@ -160,10 +173,11 @@ import {
|
|
|
160
173
|
getClientModuleMetadata,
|
|
161
174
|
getFarmClientHydrationPlanOptions,
|
|
162
175
|
resolveFarmIsolatedClientHydrationMode,
|
|
176
|
+
resolvePackageClientBoundaryCacheFile,
|
|
163
177
|
usePackageClientBoundaryCacheFile,
|
|
164
178
|
usesFarmServerTree,
|
|
165
179
|
withPackageClientBoundaryCache
|
|
166
|
-
} from "./chunk-
|
|
180
|
+
} from "./chunk-WPB67LE5.mjs";
|
|
167
181
|
import {
|
|
168
182
|
generateFarmDocsAdapterClientRuntime,
|
|
169
183
|
getFarmDocsAdapterConfigModule
|
|
@@ -173,63 +187,68 @@ import {
|
|
|
173
187
|
toFarmDocsPublicFontAssets
|
|
174
188
|
} from "./chunk-NRNAHZ57.mjs";
|
|
175
189
|
import {
|
|
190
|
+
nitroRouteRulesBelowBasePath,
|
|
176
191
|
routeRulesToNitroRouteRules
|
|
177
|
-
} from "./chunk-
|
|
192
|
+
} from "./chunk-R2ZHU37O.mjs";
|
|
178
193
|
import {
|
|
179
194
|
applyFarmCspHashesToHtml,
|
|
180
195
|
createFarmCspNonce
|
|
181
196
|
} from "./chunk-22W4FNTG.mjs";
|
|
182
197
|
import {
|
|
183
198
|
resolveFarmServerComponentsMode
|
|
184
|
-
} from "./chunk-
|
|
199
|
+
} from "./chunk-4QENVMG7.mjs";
|
|
185
200
|
import {
|
|
186
201
|
getFarmAppDirectories
|
|
187
|
-
} from "./chunk-
|
|
202
|
+
} from "./chunk-E7VF3LQ5.mjs";
|
|
188
203
|
import {
|
|
189
204
|
REACT_RENDERER,
|
|
190
205
|
getFarmRendererCapabilities,
|
|
191
206
|
getFarmRendererComponentExtensions,
|
|
192
207
|
getFarmRendererStreamingCapabilitiesForRuntime,
|
|
208
|
+
isFarmRendererDisabled,
|
|
193
209
|
isReactRenderer,
|
|
194
210
|
loadFarmRendererVitePlugins,
|
|
195
211
|
resolveFarmRendererAppSetup
|
|
196
|
-
} from "./chunk-
|
|
212
|
+
} from "./chunk-GCRT6GJG.mjs";
|
|
213
|
+
import {
|
|
214
|
+
applyFarmCronVercelCrons,
|
|
215
|
+
createFarmCronCloudflareConfig,
|
|
216
|
+
mergeScheduledTasks,
|
|
217
|
+
prepareFarmCronForNitro
|
|
218
|
+
} from "./chunk-ME7RVELR.mjs";
|
|
219
|
+
import {
|
|
220
|
+
resolveServerActionsConfig
|
|
221
|
+
} from "./chunk-E46NXBNJ.mjs";
|
|
197
222
|
import {
|
|
198
223
|
createBundledEnv
|
|
199
224
|
} from "./chunk-N33DLJBC.mjs";
|
|
200
225
|
import {
|
|
201
226
|
isFarmMarkdownPageFile
|
|
202
|
-
} from "./chunk-
|
|
227
|
+
} from "./chunk-HEJM46HQ.mjs";
|
|
203
228
|
import {
|
|
204
229
|
resolveFarmMdxComponentsModulePath,
|
|
205
230
|
resolveMdxConfig
|
|
206
231
|
} from "./chunk-UIJOLBUL.mjs";
|
|
207
232
|
import {
|
|
208
233
|
getFarmMarkdownAlternatePath
|
|
209
|
-
} from "./chunk-
|
|
234
|
+
} from "./chunk-IFR74W6S.mjs";
|
|
235
|
+
import {
|
|
236
|
+
withPlainDiagnostics
|
|
237
|
+
} from "./chunk-MGKWYPE3.mjs";
|
|
210
238
|
import {
|
|
211
239
|
applyFarmWorkflowVercelCrons,
|
|
212
240
|
prepareFarmWorkflowsForNitro
|
|
213
|
-
} from "./chunk-
|
|
214
|
-
import {
|
|
215
|
-
applyFarmCronVercelCrons,
|
|
216
|
-
createFarmCronCloudflareConfig,
|
|
217
|
-
mergeScheduledTasks,
|
|
218
|
-
prepareFarmCronForNitro
|
|
219
|
-
} from "./chunk-DQF3QLOH.mjs";
|
|
220
|
-
import {
|
|
221
|
-
resolveServerActionsConfig
|
|
222
|
-
} from "./chunk-E46NXBNJ.mjs";
|
|
223
|
-
import {
|
|
224
|
-
_collectFarmStorageModules
|
|
225
|
-
} from "./chunk-TJVUTGED.mjs";
|
|
241
|
+
} from "./chunk-MGZVDX4R.mjs";
|
|
226
242
|
import {
|
|
227
243
|
getFarmIntegrationPluginServerRuntime,
|
|
228
244
|
getIntegrationProviders
|
|
229
|
-
} from "./chunk-
|
|
245
|
+
} from "./chunk-AJNBTOVQ.mjs";
|
|
230
246
|
import {
|
|
231
247
|
FARM_INTEGRATION_API_BASE_PATH_KEY
|
|
232
248
|
} from "./chunk-M53MIIXY.mjs";
|
|
249
|
+
import {
|
|
250
|
+
_collectFarmStorageModules
|
|
251
|
+
} from "./chunk-TJVUTGED.mjs";
|
|
233
252
|
import {
|
|
234
253
|
appendMiddlewareDirectory,
|
|
235
254
|
appendMiddlewareRoutePath,
|
|
@@ -237,7 +256,7 @@ import {
|
|
|
237
256
|
} from "./chunk-MMK4MZUN.mjs";
|
|
238
257
|
import {
|
|
239
258
|
APIRouteManager
|
|
240
|
-
} from "./chunk-
|
|
259
|
+
} from "./chunk-OIOPQ25L.mjs";
|
|
241
260
|
import {
|
|
242
261
|
readFarmI18nCatalogs
|
|
243
262
|
} from "./chunk-DU4VHHPJ.mjs";
|
|
@@ -252,7 +271,7 @@ import {
|
|
|
252
271
|
normalizeFarmRouteRuntimeConfig,
|
|
253
272
|
resolveFarmRouteRuleRuntimeConfig,
|
|
254
273
|
resolveFarmRouteRuntimeConfig
|
|
255
|
-
} from "./chunk-
|
|
274
|
+
} from "./chunk-PKMUQ7LM.mjs";
|
|
256
275
|
import {
|
|
257
276
|
logger,
|
|
258
277
|
toPosixPath,
|
|
@@ -264,19 +283,28 @@ import {
|
|
|
264
283
|
} from "./chunk-2I6PUKWJ.mjs";
|
|
265
284
|
import {
|
|
266
285
|
FARM_VERSION
|
|
267
|
-
} from "./chunk-
|
|
286
|
+
} from "./chunk-F6CMGWAL.mjs";
|
|
268
287
|
import {
|
|
269
|
-
|
|
270
|
-
} from "./chunk-
|
|
288
|
+
normalizeFarmTrailingSlashPathname
|
|
289
|
+
} from "./chunk-YVPX5PI5.mjs";
|
|
290
|
+
import {
|
|
291
|
+
getFarmPresetRuntime,
|
|
292
|
+
resolveCloudflareProcessEnvFlags
|
|
293
|
+
} from "./chunk-NVOMQLI2.mjs";
|
|
271
294
|
import {
|
|
272
295
|
_runWithFarmCspNonce
|
|
273
|
-
} from "./chunk-
|
|
296
|
+
} from "./chunk-5OFNUETM.mjs";
|
|
297
|
+
import {
|
|
298
|
+
applyFarmBasePath,
|
|
299
|
+
normalizeFarmBasePath,
|
|
300
|
+
stripFarmBasePath
|
|
301
|
+
} from "./chunk-SF3JB56B.mjs";
|
|
274
302
|
import {
|
|
275
303
|
compareRoutePatternSpecificity
|
|
276
304
|
} from "./chunk-AYP2YFVN.mjs";
|
|
277
305
|
|
|
278
306
|
// src/build/index.ts
|
|
279
|
-
import
|
|
307
|
+
import path13 from "path";
|
|
280
308
|
import { existsSync as existsSync3 } from "fs";
|
|
281
309
|
|
|
282
310
|
// src/nitro/universal-build.ts
|
|
@@ -341,10 +369,10 @@ async function resolveHashedClientJsSrc(clientOutputDir) {
|
|
|
341
369
|
|
|
342
370
|
// src/nitro/universal-build.ts
|
|
343
371
|
import os from "os";
|
|
344
|
-
import
|
|
372
|
+
import path12 from "path";
|
|
345
373
|
import { constants as fsConstants, existsSync as existsSync2, readFileSync, realpathSync as realpathSync2, statSync } from "fs";
|
|
346
374
|
import { fileURLToPath } from "url";
|
|
347
|
-
import { builtinModules, createRequire } from "module";
|
|
375
|
+
import { builtinModules, createRequire as createRequire2 } from "module";
|
|
348
376
|
import { isDeepStrictEqual } from "util";
|
|
349
377
|
|
|
350
378
|
// src/docs/compiler.ts
|
|
@@ -365,13 +393,23 @@ function sanitizeCompiledValue(value, absolutePaths) {
|
|
|
365
393
|
return sanitized;
|
|
366
394
|
}
|
|
367
395
|
async function compileResponse(response, absolutePaths) {
|
|
396
|
+
const headers = Array.from(response.headers.entries()).map(([key, value]) => [
|
|
397
|
+
key,
|
|
398
|
+
sanitizeCompiledValue(value, absolutePaths)
|
|
399
|
+
]);
|
|
400
|
+
if (/^image\/(?!svg)/i.test(response.headers.get("content-type") || "")) {
|
|
401
|
+
return {
|
|
402
|
+
status: response.status,
|
|
403
|
+
statusText: response.statusText,
|
|
404
|
+
headers,
|
|
405
|
+
body: Buffer.from(await response.arrayBuffer()).toString("base64"),
|
|
406
|
+
bodyEncoding: "base64"
|
|
407
|
+
};
|
|
408
|
+
}
|
|
368
409
|
return {
|
|
369
410
|
status: response.status,
|
|
370
411
|
statusText: response.statusText,
|
|
371
|
-
headers
|
|
372
|
-
key,
|
|
373
|
-
sanitizeCompiledValue(value, absolutePaths)
|
|
374
|
-
]),
|
|
412
|
+
headers,
|
|
375
413
|
body: sanitizeCompiledValue(await response.text(), absolutePaths)
|
|
376
414
|
};
|
|
377
415
|
}
|
|
@@ -381,11 +419,11 @@ function getDocsTitle(docs) {
|
|
|
381
419
|
function loadPages(contentDir, docs) {
|
|
382
420
|
return discoverFarmDocsPages(contentDir, docs).map((page) => loadFarmDocsPage(contentDir, docs, page.slug)).filter((page) => Boolean(page)).sort((a, b) => a.href.localeCompare(b.href));
|
|
383
421
|
}
|
|
384
|
-
function findSocialImagePath(html) {
|
|
422
|
+
function findSocialImagePath(html, basePath) {
|
|
385
423
|
const match = /<meta\s+property=["']og:image["']\s+content=["']([^"']+)["']/i.exec(html) || /<meta\s+content=["']([^"']+)["']\s+property=["']og:image["']/i.exec(html);
|
|
386
424
|
if (!match?.[1]) return null;
|
|
387
425
|
try {
|
|
388
|
-
return new URL(match[1], FARM_DOCS_COMPILED_ORIGIN).pathname;
|
|
426
|
+
return stripFarmBasePath(new URL(match[1], FARM_DOCS_COMPILED_ORIGIN).pathname, basePath);
|
|
389
427
|
} catch {
|
|
390
428
|
return null;
|
|
391
429
|
}
|
|
@@ -399,6 +437,7 @@ async function addHandlerRoute(routes, pathname, handler, absolutePaths) {
|
|
|
399
437
|
async function compileFarmDocsManifest(docs, options) {
|
|
400
438
|
const contentDir = resolveFarmDocsContentDir(docs, options);
|
|
401
439
|
const pages = loadPages(contentDir, docs);
|
|
440
|
+
const basePath = normalizeFarmBasePath(options.basePath);
|
|
402
441
|
const absolutePaths = [
|
|
403
442
|
path2.resolve(options.root),
|
|
404
443
|
path2.resolve(contentDir),
|
|
@@ -411,13 +450,15 @@ async function compileFarmDocsManifest(docs, options) {
|
|
|
411
450
|
fontAssets: options.fontAssets,
|
|
412
451
|
fontStylesheetHref: options.fontStylesheetHref,
|
|
413
452
|
globalStylesheetHref: options.globalStylesheetHref,
|
|
414
|
-
isPathGuarded: options.isPathGuarded
|
|
453
|
+
isPathGuarded: options.isPathGuarded,
|
|
454
|
+
basePath
|
|
415
455
|
});
|
|
416
456
|
const apiHandler = createFarmDocsAPIHandler({
|
|
417
457
|
rootDir: options.root,
|
|
418
458
|
srcDir: options.srcDir,
|
|
419
459
|
docs,
|
|
420
|
-
isPathGuarded: options.isPathGuarded
|
|
460
|
+
isPathGuarded: options.isPathGuarded,
|
|
461
|
+
basePath
|
|
421
462
|
});
|
|
422
463
|
const publicPages = pages.filter((page) => !options.isPathGuarded?.(page.href));
|
|
423
464
|
const routes = {};
|
|
@@ -427,7 +468,7 @@ async function compileFarmDocsManifest(docs, options) {
|
|
|
427
468
|
const markdownPath = getFarmDocsMarkdownPath(page.href);
|
|
428
469
|
await addHandlerRoute(routes, markdownPath, handler, absolutePaths);
|
|
429
470
|
if (htmlResponse) {
|
|
430
|
-
const socialImagePath = findSocialImagePath(await htmlResponse.text());
|
|
471
|
+
const socialImagePath = findSocialImagePath(await htmlResponse.text(), basePath);
|
|
431
472
|
if (socialImagePath && !routes[normalizePathname(socialImagePath)]) {
|
|
432
473
|
await addHandlerRoute(routes, socialImagePath, handler, absolutePaths);
|
|
433
474
|
}
|
|
@@ -500,6 +541,7 @@ async function compileFarmDocsManifest(docs, options) {
|
|
|
500
541
|
protocol: 1,
|
|
501
542
|
originPlaceholder: FARM_DOCS_COMPILED_ORIGIN,
|
|
502
543
|
entry: docs.entry,
|
|
544
|
+
...basePath ? { basePath } : {},
|
|
503
545
|
routes,
|
|
504
546
|
api: {
|
|
505
547
|
static: apiStatic,
|
|
@@ -508,7 +550,7 @@ async function compileFarmDocsManifest(docs, options) {
|
|
|
508
550
|
post: await compileResponse(postResponse, absolutePaths),
|
|
509
551
|
search: {
|
|
510
552
|
pages: publicPages.map((page) => ({
|
|
511
|
-
...toFarmDocsMarkdownPage(page),
|
|
553
|
+
...toFarmDocsMarkdownPage(page, basePath),
|
|
512
554
|
sourcePath: `farm-docs:${page.slug || "index"}`
|
|
513
555
|
})),
|
|
514
556
|
search: searchConfig ?? true,
|
|
@@ -773,7 +815,7 @@ function validateFarmRouteRuntimeDeployment(manifest, preset) {
|
|
|
773
815
|
`Route "${route.pattern}" requires the ${route.runtime} runtime, but preset "${preset}" emits ${runtime} functions. Choose a compatible preset or change the route runtime.`
|
|
774
816
|
);
|
|
775
817
|
}
|
|
776
|
-
if (route.regions?.length && preset !== "vercel"
|
|
818
|
+
if (route.regions?.length && preset !== "vercel") {
|
|
777
819
|
warnings.add(
|
|
778
820
|
`Preset "${preset}" does not map per-route regions; Farm kept them in ${FARM_ROUTE_RUNTIME_MANIFEST} for deployment adapters.`
|
|
779
821
|
);
|
|
@@ -923,12 +965,13 @@ function createFarmVercelImmutableAssetRoute() {
|
|
|
923
965
|
};
|
|
924
966
|
}
|
|
925
967
|
function buildFarmVercelRoutes(options) {
|
|
926
|
-
const { presetRoutes, runtimeRoutes } = options;
|
|
968
|
+
const { presetRoutes, runtimeRoutes, middlewareRoutes = [] } = options;
|
|
927
969
|
const filesystemIndex = presetRoutes.findIndex((route) => route.handle === "filesystem");
|
|
928
970
|
const sourceRoutes = filesystemIndex >= 0 ? presetRoutes.slice(0, filesystemIndex) : [];
|
|
929
971
|
const preservedSourceRoutes = sourceRoutes.filter((route) => route.continue !== true);
|
|
930
972
|
return [
|
|
931
973
|
...preservedSourceRoutes,
|
|
974
|
+
...middlewareRoutes,
|
|
932
975
|
createFarmVercelImmutableAssetRoute(),
|
|
933
976
|
{ handle: "filesystem" },
|
|
934
977
|
...runtimeRoutes,
|
|
@@ -939,12 +982,127 @@ function buildFarmVercelRoutes(options) {
|
|
|
939
982
|
];
|
|
940
983
|
}
|
|
941
984
|
|
|
985
|
+
// src/nitro/ssr-public-assets.ts
|
|
986
|
+
import path7 from "path";
|
|
987
|
+
var SERVER_FILE_URL_RE = /new\s+URL\(\s*(["'`])([^"'`\\]+)\1\s*,\s*import\.meta\.url\s*\)/g;
|
|
988
|
+
function resolveBundleFileName(chunkFileName, relativeUrl) {
|
|
989
|
+
if (relativeUrl.startsWith("/") || /^[a-z][a-z\d+.-]*:/i.test(relativeUrl)) return null;
|
|
990
|
+
let relativePath = relativeUrl.replace(/[?#].*$/, "");
|
|
991
|
+
try {
|
|
992
|
+
relativePath = decodeURI(relativePath);
|
|
993
|
+
} catch {
|
|
994
|
+
}
|
|
995
|
+
const fileName = path7.posix.normalize(
|
|
996
|
+
path7.posix.join(path7.posix.dirname(chunkFileName), relativePath)
|
|
997
|
+
);
|
|
998
|
+
return fileName.startsWith("../") ? null : fileName;
|
|
999
|
+
}
|
|
1000
|
+
function replaceServerFileReferences(bundle, chunkFileName, code, replace) {
|
|
1001
|
+
return code.replace(SERVER_FILE_URL_RE, (reference, _quote, relativeUrl) => {
|
|
1002
|
+
const target = resolveBundleFileName(chunkFileName, relativeUrl);
|
|
1003
|
+
return target && bundle[target]?.type === "asset" ? replace(target) : reference;
|
|
1004
|
+
});
|
|
1005
|
+
}
|
|
1006
|
+
function collectServerReadSSRAssets(bundle) {
|
|
1007
|
+
const assets = /* @__PURE__ */ new Set();
|
|
1008
|
+
for (const [fileName, output] of Object.entries(bundle)) {
|
|
1009
|
+
if (output.type !== "chunk" || !output.code.includes("import.meta.url")) continue;
|
|
1010
|
+
replaceServerFileReferences(bundle, fileName, output.code, (assetFileName) => {
|
|
1011
|
+
assets.add(assetFileName);
|
|
1012
|
+
return "";
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
return assets;
|
|
1016
|
+
}
|
|
1017
|
+
function collectServerOnlySSRAssets(bundle) {
|
|
1018
|
+
const serverOnly = /* @__PURE__ */ new Set();
|
|
1019
|
+
const publicReferenceSources = [];
|
|
1020
|
+
for (const [fileName, output] of Object.entries(bundle)) {
|
|
1021
|
+
if (output.type !== "chunk") continue;
|
|
1022
|
+
if (!output.code.includes("import.meta.url")) {
|
|
1023
|
+
publicReferenceSources.push(output.code);
|
|
1024
|
+
continue;
|
|
1025
|
+
}
|
|
1026
|
+
publicReferenceSources.push(
|
|
1027
|
+
replaceServerFileReferences(bundle, fileName, output.code, (assetFileName) => {
|
|
1028
|
+
serverOnly.add(assetFileName);
|
|
1029
|
+
return "";
|
|
1030
|
+
})
|
|
1031
|
+
);
|
|
1032
|
+
}
|
|
1033
|
+
if (serverOnly.size === 0) return serverOnly;
|
|
1034
|
+
for (const output of Object.values(bundle)) {
|
|
1035
|
+
if (output.type === "asset" && typeof output.source === "string") {
|
|
1036
|
+
publicReferenceSources.push(output.source);
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
for (const fileName of serverOnly) {
|
|
1040
|
+
const name = path7.posix.basename(fileName);
|
|
1041
|
+
if (publicReferenceSources.some((source) => source.includes(name))) {
|
|
1042
|
+
serverOnly.delete(fileName);
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
return serverOnly;
|
|
1046
|
+
}
|
|
1047
|
+
function canReadServerFiles(preset) {
|
|
1048
|
+
return getFarmPresetRuntime(preset) !== "edge" && !preset.startsWith("cloudflare");
|
|
1049
|
+
}
|
|
1050
|
+
function assertServerReadSSRAssetsSupported(bundle, preset, root) {
|
|
1051
|
+
if (canReadServerFiles(preset)) return;
|
|
1052
|
+
const assets = [...collectServerReadSSRAssets(bundle)];
|
|
1053
|
+
if (assets.length === 0) return;
|
|
1054
|
+
const sources = assets.map((fileName) => {
|
|
1055
|
+
const output = bundle[fileName];
|
|
1056
|
+
const original = output?.type === "asset" ? output.originalFileNames?.[0] : void 0;
|
|
1057
|
+
if (!original) return fileName;
|
|
1058
|
+
return path7.relative(root, path7.resolve(root, original)).split(path7.sep).join("/");
|
|
1059
|
+
});
|
|
1060
|
+
throw new Error(
|
|
1061
|
+
`The "${preset}" preset cannot run server code that imports ${sources.join(", ")}. Server code reads such a file from beside the server bundle, and this edge runtime deploys no such file (Cloudflare Workers and Vercel Edge also refuse to compile WebAssembly from bytes). Load it in the browser instead, from client code with the @farm.js/wasm plugin or a "?url" import, or deploy to a Node target such as node-server, bun, vercel or netlify.`
|
|
1062
|
+
);
|
|
1063
|
+
}
|
|
1064
|
+
function createServerReadSSRAssetsPlugin(bundle, ssrOutputDir) {
|
|
1065
|
+
if (collectServerReadSSRAssets(bundle).size === 0) return null;
|
|
1066
|
+
let referenceIds = /* @__PURE__ */ new Map();
|
|
1067
|
+
return {
|
|
1068
|
+
name: "farm-server-read-ssr-assets",
|
|
1069
|
+
buildStart() {
|
|
1070
|
+
referenceIds = /* @__PURE__ */ new Map();
|
|
1071
|
+
},
|
|
1072
|
+
transform(code, id) {
|
|
1073
|
+
if (!code.includes("import.meta.url")) return null;
|
|
1074
|
+
const chunkFileName = path7.relative(ssrOutputDir, id.split("?", 1)[0]).split(path7.sep).join("/");
|
|
1075
|
+
if (bundle[chunkFileName]?.type !== "chunk") return null;
|
|
1076
|
+
let changed = false;
|
|
1077
|
+
const transformed = replaceServerFileReferences(
|
|
1078
|
+
bundle,
|
|
1079
|
+
chunkFileName,
|
|
1080
|
+
code,
|
|
1081
|
+
(assetFileName) => {
|
|
1082
|
+
let referenceId = referenceIds.get(assetFileName);
|
|
1083
|
+
if (!referenceId) {
|
|
1084
|
+
referenceId = this.emitFile({
|
|
1085
|
+
type: "asset",
|
|
1086
|
+
fileName: assetFileName,
|
|
1087
|
+
source: bundle[assetFileName].source
|
|
1088
|
+
});
|
|
1089
|
+
referenceIds.set(assetFileName, referenceId);
|
|
1090
|
+
}
|
|
1091
|
+
changed = true;
|
|
1092
|
+
return `new URL(import.meta.ROLLUP_FILE_URL_${referenceId})`;
|
|
1093
|
+
}
|
|
1094
|
+
);
|
|
1095
|
+
return changed ? { code: transformed, map: null } : null;
|
|
1096
|
+
}
|
|
1097
|
+
};
|
|
1098
|
+
}
|
|
1099
|
+
|
|
942
1100
|
// src/nitro/netlify-entry.ts
|
|
943
1101
|
import { existsSync } from "fs";
|
|
944
|
-
import
|
|
1102
|
+
import path8 from "path";
|
|
945
1103
|
function resolveNitroNetlifyEntry(nitroRuntimeEntry) {
|
|
946
|
-
const entry =
|
|
947
|
-
|
|
1104
|
+
const entry = path8.join(
|
|
1105
|
+
path8.dirname(nitroRuntimeEntry),
|
|
948
1106
|
"..",
|
|
949
1107
|
"presets",
|
|
950
1108
|
"netlify",
|
|
@@ -956,7 +1114,7 @@ function resolveNitroNetlifyEntry(nitroRuntimeEntry) {
|
|
|
956
1114
|
`[Farm.js] Could not find Nitro's Netlify function entry at ${entry}. Farm wraps it so private responses are never cached by Netlify's CDN; reinstall dependencies or report the installed Nitro version.`
|
|
957
1115
|
);
|
|
958
1116
|
}
|
|
959
|
-
return entry.split(
|
|
1117
|
+
return entry.split(path8.sep).join("/");
|
|
960
1118
|
}
|
|
961
1119
|
function createFarmNetlifyEntry(options) {
|
|
962
1120
|
return `
|
|
@@ -997,7 +1155,7 @@ export default async function farmNetlifyHandler(request, context) {
|
|
|
997
1155
|
|
|
998
1156
|
// src/build/strip-platform-config.ts
|
|
999
1157
|
import { realpathSync } from "fs";
|
|
1000
|
-
import
|
|
1158
|
+
import path9 from "path";
|
|
1001
1159
|
var PLATFORM_CONFIG_KEYS = /* @__PURE__ */ new Set(["desktop", "mobile"]);
|
|
1002
1160
|
var CONFIG_FACTORIES = /* @__PURE__ */ new Set(["defineConfig", "defineFarmConfig"]);
|
|
1003
1161
|
function isConfigObject(node) {
|
|
@@ -1071,31 +1229,34 @@ function realPath(file) {
|
|
|
1071
1229
|
try {
|
|
1072
1230
|
return realpathSync(file);
|
|
1073
1231
|
} catch {
|
|
1074
|
-
return
|
|
1232
|
+
return path9.resolve(file);
|
|
1075
1233
|
}
|
|
1076
1234
|
}
|
|
1077
1235
|
function farmStripPlatformConfigPlugin(configFiles) {
|
|
1078
|
-
const files = new Set(configFiles.flatMap((file) => [
|
|
1236
|
+
const files = new Set(configFiles.flatMap((file) => [path9.resolve(file), realPath(file)]));
|
|
1079
1237
|
return {
|
|
1080
1238
|
name: "farm:strip-platform-config",
|
|
1081
1239
|
// Before the TypeScript transform, so its import elision also drops imports only the
|
|
1082
1240
|
// removed block used (`readFileSync` for a version, say).
|
|
1083
1241
|
enforce: "pre",
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1242
|
+
transform: {
|
|
1243
|
+
filter: { id: fileNamePattern(configFiles) },
|
|
1244
|
+
async handler(code, id) {
|
|
1245
|
+
const file = id.split("?", 1)[0];
|
|
1246
|
+
if (!files.has(path9.resolve(file)) && !files.has(realPath(file))) return null;
|
|
1247
|
+
const { parseAst } = await import("rolldown/parseAst");
|
|
1248
|
+
const extension = path9.extname(file).slice(1);
|
|
1249
|
+
const lang = /^[cm]?tsx?$/.test(extension) ? extension.endsWith("x") ? "tsx" : "ts" : extension.endsWith("x") ? "jsx" : "js";
|
|
1250
|
+
const stripped = stripPlatformConfigSource(code, (source) => parseAst(source, { lang }));
|
|
1251
|
+
return stripped === null ? null : { code: stripped, map: null };
|
|
1252
|
+
}
|
|
1092
1253
|
}
|
|
1093
1254
|
};
|
|
1094
1255
|
}
|
|
1095
1256
|
|
|
1096
1257
|
// src/nitro/client-sourcemaps.ts
|
|
1097
1258
|
import fs3 from "fs/promises";
|
|
1098
|
-
import
|
|
1259
|
+
import path10 from "path";
|
|
1099
1260
|
var FARM_CLIENT_SOURCEMAPS_DIR = "client-sourcemaps";
|
|
1100
1261
|
function resolveFarmClientSourcemap(sourcemap) {
|
|
1101
1262
|
return sourcemap ? "hidden" : false;
|
|
@@ -1116,8 +1277,8 @@ function createFarmPrivateClientSourcemapsPlugin(options) {
|
|
|
1116
1277
|
async writeBundle() {
|
|
1117
1278
|
await fs3.rm(options.outDir, { recursive: true, force: true });
|
|
1118
1279
|
for (const [fileName, source] of maps) {
|
|
1119
|
-
const target =
|
|
1120
|
-
await fs3.mkdir(
|
|
1280
|
+
const target = path10.join(options.outDir, fileName);
|
|
1281
|
+
await fs3.mkdir(path10.dirname(target), { recursive: true });
|
|
1121
1282
|
await fs3.writeFile(target, source);
|
|
1122
1283
|
}
|
|
1123
1284
|
}
|
|
@@ -1171,6 +1332,11 @@ function readStaticMiddlewareConfig(program) {
|
|
|
1171
1332
|
for (const property of init.properties) {
|
|
1172
1333
|
if (property.type !== "Property" || property.computed) return "unknown";
|
|
1173
1334
|
const key = property.key?.name ?? property.key?.value;
|
|
1335
|
+
if (key === "runtime") {
|
|
1336
|
+
const runtime = literalMatcher(unwrap(property.value));
|
|
1337
|
+
if (runtime === "edge" || runtime === "nodejs") config.runtime = runtime;
|
|
1338
|
+
continue;
|
|
1339
|
+
}
|
|
1174
1340
|
if (key !== "matcher" && key !== "exclude") continue;
|
|
1175
1341
|
const matchers = literalMatchers(unwrap(property.value));
|
|
1176
1342
|
if (!matchers) return "unknown";
|
|
@@ -1193,6 +1359,164 @@ async function readMiddlewareFileConfig(filePath) {
|
|
|
1193
1359
|
}
|
|
1194
1360
|
}
|
|
1195
1361
|
|
|
1362
|
+
// src/nitro/vercel-edge-middleware.ts
|
|
1363
|
+
import { createRequire, isBuiltin } from "module";
|
|
1364
|
+
import path11 from "path";
|
|
1365
|
+
import { gzipSync } from "zlib";
|
|
1366
|
+
var FARM_VERCEL_EDGE_MIDDLEWARE_FUNCTION = "_farm_middleware";
|
|
1367
|
+
var FARM_VERCEL_EDGE_NOT_FOUND_PATH = "/__farm/not-found";
|
|
1368
|
+
var EDGE_NODE_MODULES = /* @__PURE__ */ new Set(["async_hooks", "events", "buffer", "assert", "util"]);
|
|
1369
|
+
var EDGE_FUNCTION_SIZE_WARNING_BYTES = 1024 * 1024;
|
|
1370
|
+
function farmTargetRunsEdgeMiddleware(preset) {
|
|
1371
|
+
return preset === "vercel";
|
|
1372
|
+
}
|
|
1373
|
+
function isFarmEdgeMiddlewareRoute(route) {
|
|
1374
|
+
return typeof route.config === "object" && route.config?.runtime === "edge";
|
|
1375
|
+
}
|
|
1376
|
+
function escapeRegExp2(value) {
|
|
1377
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1378
|
+
}
|
|
1379
|
+
function toFarmVercelEdgeGuardedUrls(pathnames, basePath) {
|
|
1380
|
+
return [
|
|
1381
|
+
...new Set(pathnames.flatMap((pathname) => [pathname, applyFarmBasePath(pathname, basePath)]))
|
|
1382
|
+
];
|
|
1383
|
+
}
|
|
1384
|
+
function createFarmVercelEdgeMiddlewareRoute(pathnames, basePath = "/") {
|
|
1385
|
+
const publicPaths = toFarmVercelEdgeGuardedUrls(pathnames, basePath);
|
|
1386
|
+
const alternatives = publicPaths.map((pathname) => {
|
|
1387
|
+
const trimmed = pathname.replace(/\/+$/, "");
|
|
1388
|
+
return trimmed ? `${escapeRegExp2(trimmed)}(?:/|/index\\.html|\\.html)?` : "/(?:index\\.html)?";
|
|
1389
|
+
});
|
|
1390
|
+
return {
|
|
1391
|
+
src: `^(?:${alternatives.join("|")})$`,
|
|
1392
|
+
middlewarePath: FARM_VERCEL_EDGE_MIDDLEWARE_FUNCTION,
|
|
1393
|
+
middlewareRawSrc: publicPaths,
|
|
1394
|
+
continue: true
|
|
1395
|
+
};
|
|
1396
|
+
}
|
|
1397
|
+
function generateFarmVercelEdgeMiddlewareEntry(routes, config, guardedPages) {
|
|
1398
|
+
const imports = routes.map(
|
|
1399
|
+
(route, index) => `import * as farmEdgeMiddleware${index} from ${JSON.stringify(route.filePath.replace(/\\/g, "/"))};`
|
|
1400
|
+
);
|
|
1401
|
+
const modules = routes.map(
|
|
1402
|
+
(route, index) => ` { path: ${JSON.stringify(route.path)}, filePath: ${JSON.stringify(route.filePath)}, module: farmEdgeMiddleware${index} },`
|
|
1403
|
+
);
|
|
1404
|
+
return `import { createFarmVercelEdgeMiddleware } from "@farm.js/core/internal/vercel-edge-middleware";
|
|
1405
|
+
${imports.join("\n")}
|
|
1406
|
+
|
|
1407
|
+
export default createFarmVercelEdgeMiddleware({
|
|
1408
|
+
modules: [
|
|
1409
|
+
${modules.join("\n")}
|
|
1410
|
+
],
|
|
1411
|
+
i18n: ${JSON.stringify(config.i18n)},
|
|
1412
|
+
server: ${JSON.stringify({ trustProxy: config.server?.trustProxy === true })},
|
|
1413
|
+
apiBasePath: ${JSON.stringify(resolveFarmAPIServerBasePath(config.api))},
|
|
1414
|
+
notFoundPath: ${JSON.stringify(applyFarmBasePath(FARM_VERCEL_EDGE_NOT_FOUND_PATH, config.basePath))},
|
|
1415
|
+
pages: ${JSON.stringify(toFarmVercelEdgeGuardedUrls(guardedPages, config.basePath))},
|
|
1416
|
+
});
|
|
1417
|
+
`;
|
|
1418
|
+
}
|
|
1419
|
+
async function resolveFarmCoreDir(root, fs4) {
|
|
1420
|
+
const runtimeEntry = createRequire(path11.join(root, "package.json")).resolve(
|
|
1421
|
+
"@farm.js/core/internal/vercel-edge-middleware"
|
|
1422
|
+
);
|
|
1423
|
+
return fs4.realpath(path11.resolve(path11.dirname(runtimeEntry), "..", ".."));
|
|
1424
|
+
}
|
|
1425
|
+
function edgeNodeModulesPlugin(coreDir, unsupported) {
|
|
1426
|
+
const streamStub = "\0farm-edge-node-stream";
|
|
1427
|
+
const corePrefix = coreDir + path11.sep;
|
|
1428
|
+
return {
|
|
1429
|
+
name: "farm-vercel-edge-node-modules",
|
|
1430
|
+
resolveId(source, importer) {
|
|
1431
|
+
if (!isBuiltin(source)) return null;
|
|
1432
|
+
const name = source.replace(/^node:/, "").split("/")[0];
|
|
1433
|
+
if (EDGE_NODE_MODULES.has(name)) return { id: `node:${name}`, external: true };
|
|
1434
|
+
if (name === "stream" && importer && path11.resolve(importer).startsWith(corePrefix)) {
|
|
1435
|
+
return streamStub;
|
|
1436
|
+
}
|
|
1437
|
+
unsupported.add(`${source} (imported by ${importer ?? "the entry"})`);
|
|
1438
|
+
return { id: source, external: true };
|
|
1439
|
+
},
|
|
1440
|
+
load(id) {
|
|
1441
|
+
if (id !== streamStub) return null;
|
|
1442
|
+
return `export const Readable = { toWeb() { throw new Error("[Farm.js] Node streams are not available in Vercel edge middleware."); } };`;
|
|
1443
|
+
}
|
|
1444
|
+
};
|
|
1445
|
+
}
|
|
1446
|
+
async function writeFarmVercelEdgeMiddlewareFunction(options) {
|
|
1447
|
+
const { root, outputDir, buildDir, config, routes, guardedPages, fs: fs4 } = options;
|
|
1448
|
+
const functionDir = path11.join(
|
|
1449
|
+
outputDir,
|
|
1450
|
+
"functions",
|
|
1451
|
+
`${FARM_VERCEL_EDGE_MIDDLEWARE_FUNCTION}.func`
|
|
1452
|
+
);
|
|
1453
|
+
const entryPath = path11.join(buildDir, "vercel-edge-middleware-entry.mjs");
|
|
1454
|
+
await fs4.mkdir(path11.dirname(entryPath), { recursive: true });
|
|
1455
|
+
await fs4.writeFile(
|
|
1456
|
+
entryPath,
|
|
1457
|
+
generateFarmVercelEdgeMiddlewareEntry(routes, config, guardedPages)
|
|
1458
|
+
);
|
|
1459
|
+
const unsupported = /* @__PURE__ */ new Set();
|
|
1460
|
+
const coreDir = await resolveFarmCoreDir(root, fs4);
|
|
1461
|
+
const { rolldown } = await import("rolldown");
|
|
1462
|
+
let code;
|
|
1463
|
+
try {
|
|
1464
|
+
const bundle = await rolldown({
|
|
1465
|
+
cwd: root,
|
|
1466
|
+
input: entryPath,
|
|
1467
|
+
platform: "browser",
|
|
1468
|
+
logLevel: "silent",
|
|
1469
|
+
plugins: [edgeNodeModulesPlugin(coreDir, unsupported)],
|
|
1470
|
+
resolve: {
|
|
1471
|
+
alias: createFarmSourceAlias(root, config.srcDir),
|
|
1472
|
+
conditionNames: ["edge-light", "worker", "browser", "import", "module", "default"]
|
|
1473
|
+
},
|
|
1474
|
+
transform: {
|
|
1475
|
+
target: "es2022",
|
|
1476
|
+
define: { "process.env.NODE_ENV": JSON.stringify("production") }
|
|
1477
|
+
}
|
|
1478
|
+
});
|
|
1479
|
+
try {
|
|
1480
|
+
const { output } = await bundle.generate({
|
|
1481
|
+
format: "esm",
|
|
1482
|
+
codeSplitting: false,
|
|
1483
|
+
minify: true
|
|
1484
|
+
});
|
|
1485
|
+
code = output[0].code;
|
|
1486
|
+
} finally {
|
|
1487
|
+
await bundle.close();
|
|
1488
|
+
}
|
|
1489
|
+
} catch (error) {
|
|
1490
|
+
throw withPlainDiagnostics(error);
|
|
1491
|
+
} finally {
|
|
1492
|
+
await fs4.rm(entryPath, { force: true });
|
|
1493
|
+
}
|
|
1494
|
+
if (unsupported.size > 0) {
|
|
1495
|
+
throw new Error(
|
|
1496
|
+
`[Farm.js] runtime: "edge" middleware runs in Vercel's Edge runtime, which does not provide these Node modules:
|
|
1497
|
+
` + [...unsupported].map((entry) => ` - ${entry}`).join("\n") + `
|
|
1498
|
+
Remove them from the middleware (Edge provides ${[...EDGE_NODE_MODULES].join(", ")}), or remove runtime: "edge" so the middleware runs in the server and its pages render on request.`
|
|
1499
|
+
);
|
|
1500
|
+
}
|
|
1501
|
+
await fs4.rm(functionDir, { recursive: true, force: true });
|
|
1502
|
+
await fs4.mkdir(functionDir, { recursive: true });
|
|
1503
|
+
await fs4.writeFile(path11.join(functionDir, "index.js"), code);
|
|
1504
|
+
await fs4.writeFile(
|
|
1505
|
+
path11.join(functionDir, ".vc-config.json"),
|
|
1506
|
+
`${JSON.stringify({ runtime: "edge", entrypoint: "index.js" }, null, 2)}
|
|
1507
|
+
`
|
|
1508
|
+
);
|
|
1509
|
+
const gzippedBytes = gzipSync(code).length;
|
|
1510
|
+
if (gzippedBytes > EDGE_FUNCTION_SIZE_WARNING_BYTES) {
|
|
1511
|
+
logger.warn(
|
|
1512
|
+
`Vercel edge middleware is ${(gzippedBytes / 1024 / 1024).toFixed(2)} MB gzipped, over the Hobby plan's 1 MB Edge function limit (Pro allows 2 MB, Enterprise 4 MB).`
|
|
1513
|
+
);
|
|
1514
|
+
}
|
|
1515
|
+
logger.info(
|
|
1516
|
+
`\u{1F6E1}\uFE0F Vercel edge middleware: ${routes.length} middleware file(s) guard their prerendered pages before the CDN serves them`
|
|
1517
|
+
);
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1196
1520
|
// src/nitro/universal-build.ts
|
|
1197
1521
|
var FARM_NATIVE_STYLESHEETS_PLACEHOLDER = "__FARM_NATIVE_STYLESHEETS__";
|
|
1198
1522
|
async function readFarmNativeStylesheets(clientOutputDir, clientCssHref) {
|
|
@@ -1200,7 +1524,7 @@ async function readFarmNativeStylesheets(clientOutputDir, clientCssHref) {
|
|
|
1200
1524
|
try {
|
|
1201
1525
|
return {
|
|
1202
1526
|
[clientCssHref]: await fs4.readFile(
|
|
1203
|
-
|
|
1527
|
+
path12.join(clientOutputDir, clientCssHref.slice(1)),
|
|
1204
1528
|
"utf8"
|
|
1205
1529
|
)
|
|
1206
1530
|
};
|
|
@@ -1215,18 +1539,18 @@ function preloadFarmNitroBuilder() {
|
|
|
1215
1539
|
);
|
|
1216
1540
|
}
|
|
1217
1541
|
var _filename = typeof import.meta.url !== "undefined" ? fileURLToPath(import.meta.url) : "";
|
|
1218
|
-
var _dirname =
|
|
1542
|
+
var _dirname = path12.dirname(_filename);
|
|
1219
1543
|
function findFarmCoreRoot(from) {
|
|
1220
|
-
let dir =
|
|
1221
|
-
while (dir !==
|
|
1222
|
-
const manifest =
|
|
1544
|
+
let dir = path12.dirname(from);
|
|
1545
|
+
while (dir !== path12.dirname(dir)) {
|
|
1546
|
+
const manifest = path12.join(dir, "package.json");
|
|
1223
1547
|
if (existsSync2(manifest)) {
|
|
1224
1548
|
try {
|
|
1225
1549
|
if (JSON.parse(readFileSync(manifest, "utf8")).name === "@farm.js/core") return dir;
|
|
1226
1550
|
} catch {
|
|
1227
1551
|
}
|
|
1228
1552
|
}
|
|
1229
|
-
dir =
|
|
1553
|
+
dir = path12.dirname(dir);
|
|
1230
1554
|
}
|
|
1231
1555
|
return null;
|
|
1232
1556
|
}
|
|
@@ -1236,16 +1560,16 @@ function toModulePath(file) {
|
|
|
1236
1560
|
return process.platform === "win32" ? normalized.toLowerCase() : normalized;
|
|
1237
1561
|
}
|
|
1238
1562
|
function findInstalledPackageDir(name, from) {
|
|
1239
|
-
for (let dir = from; ; dir =
|
|
1240
|
-
const candidate =
|
|
1241
|
-
if (existsSync2(
|
|
1563
|
+
for (let dir = from; ; dir = path12.dirname(dir)) {
|
|
1564
|
+
const candidate = path12.join(dir, "node_modules", name);
|
|
1565
|
+
if (existsSync2(path12.join(candidate, "package.json"))) {
|
|
1242
1566
|
try {
|
|
1243
1567
|
return realpathSync2(candidate);
|
|
1244
1568
|
} catch {
|
|
1245
1569
|
return null;
|
|
1246
1570
|
}
|
|
1247
1571
|
}
|
|
1248
|
-
if (dir ===
|
|
1572
|
+
if (dir === path12.dirname(dir)) return null;
|
|
1249
1573
|
}
|
|
1250
1574
|
}
|
|
1251
1575
|
function collectFarmDependencyDirs(root) {
|
|
@@ -1256,7 +1580,7 @@ function collectFarmDependencyDirs(root) {
|
|
|
1256
1580
|
seen.add(dir);
|
|
1257
1581
|
let manifest;
|
|
1258
1582
|
try {
|
|
1259
|
-
manifest = JSON.parse(readFileSync(
|
|
1583
|
+
manifest = JSON.parse(readFileSync(path12.join(dir, "package.json"), "utf8"));
|
|
1260
1584
|
} catch {
|
|
1261
1585
|
return;
|
|
1262
1586
|
}
|
|
@@ -1267,7 +1591,7 @@ function collectFarmDependencyDirs(root) {
|
|
|
1267
1591
|
if (farmCoreRoot) visit(realpathSync2(farmCoreRoot));
|
|
1268
1592
|
queue.push({ name: "@farm.js/core", from: root });
|
|
1269
1593
|
try {
|
|
1270
|
-
const manifest = JSON.parse(readFileSync(
|
|
1594
|
+
const manifest = JSON.parse(readFileSync(path12.join(root, "package.json"), "utf8"));
|
|
1271
1595
|
for (const field of ["dependencies", "devDependencies"]) {
|
|
1272
1596
|
for (const name of Object.keys(manifest[field] ?? {})) {
|
|
1273
1597
|
if (name.startsWith("@farm.js/")) queue.push({ name, from: root });
|
|
@@ -1334,17 +1658,17 @@ var FARM_SSR_PACKAGE_IMPORT = "#farm-ssr-entry";
|
|
|
1334
1658
|
var FARM_SSR_OUTPUT_DIR = "farm-ssr";
|
|
1335
1659
|
var FARM_CLIENT_BUILD_TARGET = ["es2020", "edge88", "firefox78", "chrome87", "safari14"];
|
|
1336
1660
|
function resolveNitroRuntimeDependency(root, specifier) {
|
|
1337
|
-
return
|
|
1661
|
+
return createRequire2(resolveNitroPackageEntry(root)).resolve(specifier).split(path12.sep).join("/");
|
|
1338
1662
|
}
|
|
1339
1663
|
function resolveNitroInternalRuntimeAliases(root) {
|
|
1340
1664
|
const nitroEntry = resolveNitroPackageEntry(root);
|
|
1341
|
-
const runtimeDir =
|
|
1342
|
-
const nitroRequire =
|
|
1665
|
+
const runtimeDir = path12.dirname(nitroEntry);
|
|
1666
|
+
const nitroRequire = createRequire2(nitroEntry);
|
|
1343
1667
|
return {
|
|
1344
1668
|
...Object.fromEntries(
|
|
1345
1669
|
["app", "error/hooks", "runtime-config", "shutdown", "task"].map((moduleName) => [
|
|
1346
1670
|
`#nitro/runtime/${moduleName}`,
|
|
1347
|
-
|
|
1671
|
+
path12.join(runtimeDir, "internal", `${moduleName}.mjs`).split(path12.sep).join("/")
|
|
1348
1672
|
])
|
|
1349
1673
|
),
|
|
1350
1674
|
// Farm's generated workflow and cron wrappers live under `.farm/` and
|
|
@@ -1353,7 +1677,7 @@ function resolveNitroInternalRuntimeAliases(root) {
|
|
|
1353
1677
|
...Object.fromEntries(
|
|
1354
1678
|
["nitro/app", "nitro/h3", "nitro/task"].map((specifier) => [
|
|
1355
1679
|
specifier,
|
|
1356
|
-
nitroRequire.resolve(specifier).split(
|
|
1680
|
+
nitroRequire.resolve(specifier).split(path12.sep).join("/")
|
|
1357
1681
|
])
|
|
1358
1682
|
)
|
|
1359
1683
|
};
|
|
@@ -1364,7 +1688,7 @@ function createPrerenderRuntimeResolverPlugin(root, resolveNitroEntry = resolveN
|
|
|
1364
1688
|
name: "farm-prerender-runtime-resolver",
|
|
1365
1689
|
async resolveId(id, _importer, options) {
|
|
1366
1690
|
if (options.custom?.farmPrerenderRuntimeResolve) return null;
|
|
1367
|
-
if (id.startsWith("\0") || id.startsWith(".") || id.startsWith("#") || id.startsWith("virtual:") ||
|
|
1691
|
+
if (id.startsWith("\0") || id.startsWith(".") || id.startsWith("#") || id.startsWith("virtual:") || path12.isAbsolute(id) || NODE_BUILTIN_MODULES.has(id)) {
|
|
1368
1692
|
return null;
|
|
1369
1693
|
}
|
|
1370
1694
|
if (nitroEntry === void 0) {
|
|
@@ -1387,10 +1711,10 @@ function createFarmStorageModuleRegistration(config) {
|
|
|
1387
1711
|
const modules = _collectFarmStorageModules(config.storage);
|
|
1388
1712
|
if (modules.length === 0) return "";
|
|
1389
1713
|
const root = config.root || process.cwd();
|
|
1390
|
-
const projectRequire =
|
|
1714
|
+
const projectRequire = createRequire2(path12.join(root, "package.json"));
|
|
1391
1715
|
let runtimeRequire = projectRequire;
|
|
1392
1716
|
try {
|
|
1393
|
-
runtimeRequire =
|
|
1717
|
+
runtimeRequire = createRequire2(projectRequire.resolve("@farm.js/core"));
|
|
1394
1718
|
} catch {
|
|
1395
1719
|
}
|
|
1396
1720
|
const loaders = [];
|
|
@@ -1414,10 +1738,10 @@ ${loaders.join("\n")}
|
|
|
1414
1738
|
});` : "";
|
|
1415
1739
|
}
|
|
1416
1740
|
function resolveNitroPackageEntry(root) {
|
|
1417
|
-
const projectRequire =
|
|
1741
|
+
const projectRequire = createRequire2(path12.join(root, "package.json"));
|
|
1418
1742
|
let runtimeRequire = projectRequire;
|
|
1419
1743
|
try {
|
|
1420
|
-
runtimeRequire =
|
|
1744
|
+
runtimeRequire = createRequire2(projectRequire.resolve("@farm.js/core"));
|
|
1421
1745
|
} catch {
|
|
1422
1746
|
}
|
|
1423
1747
|
return runtimeRequire.resolve("nitro");
|
|
@@ -1484,7 +1808,7 @@ function createFarmReactWebServerAlias(hasEdgeBuild) {
|
|
|
1484
1808
|
}
|
|
1485
1809
|
function hasReactDomEdgeServerBuild(root) {
|
|
1486
1810
|
try {
|
|
1487
|
-
|
|
1811
|
+
createRequire2(path12.join(root, "package.json")).resolve("react-dom/server.edge");
|
|
1488
1812
|
return true;
|
|
1489
1813
|
} catch {
|
|
1490
1814
|
return false;
|
|
@@ -1496,31 +1820,28 @@ function shouldAliasReactServerToWebBuild(renderer, preset) {
|
|
|
1496
1820
|
function isCloudflareImagePreset(preset) {
|
|
1497
1821
|
return preset === "cloudflare" || preset === "cloudflare-pages" || preset === "cloudflare-module";
|
|
1498
1822
|
}
|
|
1823
|
+
function getEdgeMetadataImageRuntime(preset) {
|
|
1824
|
+
if (isCloudflareImagePreset(preset)) {
|
|
1825
|
+
return { condition: "workerd", wasm: "module", runtime: "Cloudflare Workers" };
|
|
1826
|
+
}
|
|
1827
|
+
if (preset === "netlify-edge") {
|
|
1828
|
+
return { condition: "edge", wasm: "bytes", runtime: "Netlify Edge Functions" };
|
|
1829
|
+
}
|
|
1830
|
+
return null;
|
|
1831
|
+
}
|
|
1499
1832
|
function shouldUseExternalMetadataImageRuntime(preset, usesImageRuntime) {
|
|
1500
|
-
return usesImageRuntime &&
|
|
1833
|
+
return usesImageRuntime && !getEdgeMetadataImageRuntime(preset);
|
|
1501
1834
|
}
|
|
1502
1835
|
function isNitroRollupExternal(id) {
|
|
1503
1836
|
const normalizedId = id.replace(/\\/g, "/");
|
|
1504
1837
|
return NODE_BUILTIN_MODULES.has(id) || NITRO_EXTERNAL_MODULES.has(id) || normalizedId.startsWith(".prisma/") || normalizedId.includes("/node_modules/@prisma/client/") || normalizedId.includes("/node_modules/.prisma/client/");
|
|
1505
1838
|
}
|
|
1506
1839
|
var FARM_METADATA_IMAGE_WASM_PREFIX = "\0farm-metadata-image-wasm:";
|
|
1507
|
-
function createReactProductionModePlugin() {
|
|
1508
|
-
const nodeEnvExpression = ["process", "env", "NODE_ENV"].join(".");
|
|
1509
|
-
return {
|
|
1510
|
-
name: "farm-react-production-mode",
|
|
1511
|
-
transform(code, id) {
|
|
1512
|
-
const normalizedId = id.replace(/\\/g, "/");
|
|
1513
|
-
const isReactRuntime = normalizedId.includes("/node_modules/react/") || normalizedId.includes("/node_modules/react-dom/");
|
|
1514
|
-
if (!isReactRuntime || !code.includes(nodeEnvExpression)) return null;
|
|
1515
|
-
return { code: code.split(nodeEnvExpression).join('"production"'), map: null };
|
|
1516
|
-
}
|
|
1517
|
-
};
|
|
1518
|
-
}
|
|
1519
1840
|
var FARM_OMITTED_METADATA_IMAGE_RUNTIME_ID = "\0farm-omitted-metadata-image-runtime";
|
|
1520
1841
|
function isFarmCoreModule(file) {
|
|
1521
|
-
let dir =
|
|
1522
|
-
while (dir !==
|
|
1523
|
-
const manifest =
|
|
1842
|
+
let dir = path12.dirname(file.split("?", 1)[0]);
|
|
1843
|
+
while (dir !== path12.dirname(dir)) {
|
|
1844
|
+
const manifest = path12.join(dir, "package.json");
|
|
1524
1845
|
if (existsSync2(manifest)) {
|
|
1525
1846
|
try {
|
|
1526
1847
|
return JSON.parse(readFileSync(manifest, "utf8")).name === "@farm.js/core";
|
|
@@ -1528,28 +1849,94 @@ function isFarmCoreModule(file) {
|
|
|
1528
1849
|
return false;
|
|
1529
1850
|
}
|
|
1530
1851
|
}
|
|
1531
|
-
dir =
|
|
1852
|
+
dir = path12.dirname(dir);
|
|
1532
1853
|
}
|
|
1533
1854
|
return false;
|
|
1534
1855
|
}
|
|
1535
1856
|
function createOmittedMetadataImageRuntimePlugin(externalizeOtherImports) {
|
|
1536
1857
|
return {
|
|
1537
1858
|
name: "farm-omitted-metadata-image-runtime",
|
|
1538
|
-
resolveId
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1859
|
+
resolveId: {
|
|
1860
|
+
filter: { id: exactIdPattern(["@vercel/og"]) },
|
|
1861
|
+
handler(source, importer) {
|
|
1862
|
+
if (source !== "@vercel/og") return null;
|
|
1863
|
+
const fromCoreRuntime = importer !== void 0 && isFarmCoreModule(importer) && !/^og\.[cm]?[jt]sx?$/.test(path12.basename(importer.split("?", 1)[0]));
|
|
1864
|
+
if (fromCoreRuntime) return FARM_OMITTED_METADATA_IMAGE_RUNTIME_ID;
|
|
1865
|
+
return externalizeOtherImports ? { id: source, external: true } : null;
|
|
1866
|
+
}
|
|
1543
1867
|
},
|
|
1544
|
-
load
|
|
1545
|
-
|
|
1546
|
-
|
|
1868
|
+
load: {
|
|
1869
|
+
filter: { id: exactIdPattern([FARM_OMITTED_METADATA_IMAGE_RUNTIME_ID]) },
|
|
1870
|
+
handler(id) {
|
|
1871
|
+
if (id !== FARM_OMITTED_METADATA_IMAGE_RUNTIME_ID) return null;
|
|
1872
|
+
return `
|
|
1547
1873
|
export class ImageResponse {
|
|
1548
1874
|
constructor() {
|
|
1549
1875
|
throw new Error("@vercel/og is not in this server build because the app has no generated metadata image route.");
|
|
1550
1876
|
}
|
|
1551
1877
|
}
|
|
1552
1878
|
`;
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
};
|
|
1882
|
+
}
|
|
1883
|
+
function readVercelOgManifest(file) {
|
|
1884
|
+
let dir = path12.dirname(file.split("?", 1)[0]);
|
|
1885
|
+
while (dir !== path12.dirname(dir)) {
|
|
1886
|
+
const manifestPath = path12.join(dir, "package.json");
|
|
1887
|
+
if (existsSync2(manifestPath)) {
|
|
1888
|
+
const manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
|
|
1889
|
+
return manifest.name === "@vercel/og" ? { dir, manifest } : null;
|
|
1890
|
+
}
|
|
1891
|
+
dir = path12.dirname(dir);
|
|
1892
|
+
}
|
|
1893
|
+
return null;
|
|
1894
|
+
}
|
|
1895
|
+
function resolveVercelOgConditionEntry(resolvedId, condition) {
|
|
1896
|
+
const vercelOg = readVercelOgManifest(resolvedId);
|
|
1897
|
+
const entry = vercelOg?.manifest.exports?.["."]?.[condition];
|
|
1898
|
+
const file = typeof entry === "string" ? entry : entry?.default;
|
|
1899
|
+
return vercelOg && typeof file === "string" ? path12.join(vercelOg.dir, file) : null;
|
|
1900
|
+
}
|
|
1901
|
+
function createEdgeMetadataImageRuntimePlugin({
|
|
1902
|
+
condition,
|
|
1903
|
+
wasm
|
|
1904
|
+
}) {
|
|
1905
|
+
return {
|
|
1906
|
+
name: "farm-edge-metadata-image-runtime",
|
|
1907
|
+
async resolveId(source, importer, options) {
|
|
1908
|
+
if (source === "@vercel/og") {
|
|
1909
|
+
const resolved = await this.resolve(source, importer, { ...options, skipSelf: true });
|
|
1910
|
+
if (!resolved || resolved.external) return resolved;
|
|
1911
|
+
const edgeEntry = resolveVercelOgConditionEntry(resolved.id, condition);
|
|
1912
|
+
return edgeEntry ? { ...resolved, id: edgeEntry } : resolved;
|
|
1913
|
+
}
|
|
1914
|
+
if (wasm !== "module" || !source.endsWith(".wasm?module") || !importer?.replace(/\\/g, "/").includes("/@vercel/og/")) {
|
|
1915
|
+
return null;
|
|
1916
|
+
}
|
|
1917
|
+
const resolvedPath = path12.resolve(path12.dirname(importer.split("?", 1)[0]), source);
|
|
1918
|
+
return { id: toPosixPath(resolvedPath), external: "absolute" };
|
|
1919
|
+
}
|
|
1920
|
+
};
|
|
1921
|
+
}
|
|
1922
|
+
var VERCEL_OG_FONT_FETCH = /fetch\(\s*new URL\(\s*(["'`])(\.\/[^"'`]+\.ttf)\1\s*,\s*import\.meta\.url\s*\)\s*\)/g;
|
|
1923
|
+
function createVercelOgFontInlinePlugin(runtime = "Cloudflare Workers") {
|
|
1924
|
+
return {
|
|
1925
|
+
name: "farm-vercel-og-font-inline",
|
|
1926
|
+
transform(code, id) {
|
|
1927
|
+
const file = id.split("?", 1)[0];
|
|
1928
|
+
if (!/\.[cm]?js$/.test(file) || !file.replace(/\\/g, "/").includes("/@vercel/og/")) {
|
|
1929
|
+
return null;
|
|
1930
|
+
}
|
|
1931
|
+
const inlined = code.replace(VERCEL_OG_FONT_FETCH, (_match, _quote, request) => {
|
|
1932
|
+
const encoded = readFileSync(path12.resolve(path12.dirname(file), request)).toString("base64");
|
|
1933
|
+
return `Promise.resolve({ arrayBuffer: () => Uint8Array.from(atob(${JSON.stringify(encoded)}), (character) => character.charCodeAt(0)).buffer })`;
|
|
1934
|
+
});
|
|
1935
|
+
if (inlined !== code) return { code: inlined, map: null };
|
|
1936
|
+
const version = readVercelOgManifest(file)?.manifest.version ?? "(unknown version)";
|
|
1937
|
+
this.error(
|
|
1938
|
+
`@vercel/og ${version} cannot be bundled for ${runtime}: ${file} does not load its default font with fetch(new URL("./<font>.ttf", import.meta.url)), the pattern Farm inlines because an edge function cannot fetch it. Install a @vercel/og version whose edge build does, such as 1.0.1.`
|
|
1939
|
+
);
|
|
1553
1940
|
}
|
|
1554
1941
|
};
|
|
1555
1942
|
}
|
|
@@ -1561,7 +1948,7 @@ function createMetadataImageWasmPlugin() {
|
|
|
1561
1948
|
return null;
|
|
1562
1949
|
}
|
|
1563
1950
|
const requestPath = source.slice(0, -"?module".length);
|
|
1564
|
-
const resolvedPath =
|
|
1951
|
+
const resolvedPath = path12.isAbsolute(requestPath) ? requestPath : path12.resolve(path12.dirname(importer.split("?", 1)[0]), requestPath);
|
|
1565
1952
|
return `${FARM_METADATA_IMAGE_WASM_PREFIX}${resolvedPath}`;
|
|
1566
1953
|
},
|
|
1567
1954
|
load(id) {
|
|
@@ -1586,11 +1973,11 @@ function collectSSRExternalPackages(ssrBundle) {
|
|
|
1586
1973
|
for (const importId of [...output.imports, ...output.dynamicImports]) {
|
|
1587
1974
|
const normalizedImportId = importId.replace(/\\/g, "/");
|
|
1588
1975
|
const normalizedId = normalizedImportId.replace(/^\.\//, "");
|
|
1589
|
-
const resolvedRelativeId = normalizedImportId.startsWith("./") || normalizedImportId.startsWith("../") ?
|
|
1976
|
+
const resolvedRelativeId = normalizedImportId.startsWith("./") || normalizedImportId.startsWith("../") ? path12.posix.normalize(path12.posix.join(path12.posix.dirname(fileName), normalizedImportId)) : null;
|
|
1590
1977
|
if (emittedFiles.has(normalizedId) || resolvedRelativeId !== null && emittedFiles.has(resolvedRelativeId) || NODE_BUILTIN_MODULES.has(importId) || importId.startsWith("node:")) {
|
|
1591
1978
|
continue;
|
|
1592
1979
|
}
|
|
1593
|
-
if (
|
|
1980
|
+
if (path12.isAbsolute(importId) || /^[A-Za-z]:[\\/]/.test(importId) || importId.startsWith("#") || importId.startsWith("\0")) {
|
|
1594
1981
|
externalPackages.add(importId);
|
|
1595
1982
|
continue;
|
|
1596
1983
|
}
|
|
@@ -1602,15 +1989,15 @@ function collectSSRExternalPackages(ssrBundle) {
|
|
|
1602
1989
|
return externalPackages;
|
|
1603
1990
|
}
|
|
1604
1991
|
function createExternalSSRBundlePlugin(nitroEntryPath, ssrOutputDir, ssrEntryFile) {
|
|
1605
|
-
const resolvedNitroEntry =
|
|
1606
|
-
const resolvedSSREntry =
|
|
1992
|
+
const resolvedNitroEntry = path12.resolve(nitroEntryPath);
|
|
1993
|
+
const resolvedSSREntry = path12.resolve(ssrOutputDir, ssrEntryFile);
|
|
1607
1994
|
return {
|
|
1608
1995
|
name: "farm-externalize-prebuilt-ssr",
|
|
1609
1996
|
resolveId(source, importer) {
|
|
1610
|
-
if (!importer ||
|
|
1997
|
+
if (!importer || path12.resolve(importer) !== resolvedNitroEntry) {
|
|
1611
1998
|
return null;
|
|
1612
1999
|
}
|
|
1613
|
-
const resolvedImport =
|
|
2000
|
+
const resolvedImport = path12.resolve(path12.dirname(importer), source);
|
|
1614
2001
|
if (resolvedImport !== resolvedSSREntry) return null;
|
|
1615
2002
|
return { id: FARM_SSR_PACKAGE_IMPORT, external: true };
|
|
1616
2003
|
}
|
|
@@ -1743,13 +2130,13 @@ function trimSlashes(value) {
|
|
|
1743
2130
|
function resolveBuildDocsContentDir(docs, root, srcDir) {
|
|
1744
2131
|
const configuredContentDir = docs.contentDir || docs.config.contentDir;
|
|
1745
2132
|
if (typeof configuredContentDir === "string" && configuredContentDir.trim()) {
|
|
1746
|
-
const contentDir =
|
|
2133
|
+
const contentDir = path12.isAbsolute(configuredContentDir) ? configuredContentDir : path12.join(root, configuredContentDir);
|
|
1747
2134
|
return existsSync2(contentDir) ? contentDir : null;
|
|
1748
2135
|
}
|
|
1749
2136
|
const entryDir = docs.config.entry || trimSlashes(docs.entry) || "docs";
|
|
1750
|
-
const appDocsDir =
|
|
2137
|
+
const appDocsDir = path12.join(root, srcDir || "src", "app", entryDir);
|
|
1751
2138
|
if (existsSync2(appDocsDir)) return appDocsDir;
|
|
1752
|
-
const rootDocsDir =
|
|
2139
|
+
const rootDocsDir = path12.join(root, entryDir);
|
|
1753
2140
|
return existsSync2(rootDocsDir) ? rootDocsDir : null;
|
|
1754
2141
|
}
|
|
1755
2142
|
function hasProjectPostcssConfig(root) {
|
|
@@ -1766,7 +2153,7 @@ function hasProjectPostcssConfig(root) {
|
|
|
1766
2153
|
".postcssrc.mjs",
|
|
1767
2154
|
".postcssrc.ts"
|
|
1768
2155
|
];
|
|
1769
|
-
const projectRequire =
|
|
2156
|
+
const projectRequire = createRequire2(path12.join(root, "package.json"));
|
|
1770
2157
|
return candidates.some((file) => {
|
|
1771
2158
|
try {
|
|
1772
2159
|
projectRequire.resolve(`./${file}`);
|
|
@@ -1789,7 +2176,7 @@ async function findFarmConfigPath(root) {
|
|
|
1789
2176
|
"config.mjs"
|
|
1790
2177
|
];
|
|
1791
2178
|
for (const candidate of candidates) {
|
|
1792
|
-
const resolvedPath =
|
|
2179
|
+
const resolvedPath = path12.join(root, candidate);
|
|
1793
2180
|
try {
|
|
1794
2181
|
await fs4.access(resolvedPath);
|
|
1795
2182
|
return resolvedPath;
|
|
@@ -1798,14 +2185,6 @@ async function findFarmConfigPath(root) {
|
|
|
1798
2185
|
}
|
|
1799
2186
|
return null;
|
|
1800
2187
|
}
|
|
1801
|
-
function hasFarmServerRuntimePlugins(config) {
|
|
1802
|
-
return (config.plugins || []).some((plugin) => {
|
|
1803
|
-
if (getFarmIntegrationPluginServerRuntime(plugin) === false) return false;
|
|
1804
|
-
return Boolean(
|
|
1805
|
-
plugin.setup || plugin.init || plugin.ready || plugin.shutdown || plugin.runtime || plugin.router || plugin.render || plugin.beforeRouteMatch || plugin.afterRouteMatch || plugin.beforeRender || plugin.afterRender || plugin.onError || plugin.transformHTML
|
|
1806
|
-
);
|
|
1807
|
-
});
|
|
1808
|
-
}
|
|
1809
2188
|
function hasFarmPluginRoutes(config) {
|
|
1810
2189
|
return (config.plugins || []).some((plugin) => Boolean(plugin.routes));
|
|
1811
2190
|
}
|
|
@@ -1834,7 +2213,7 @@ async function discoverMiddlewareRoutes(appDir) {
|
|
|
1834
2213
|
discovered.push({
|
|
1835
2214
|
path: routePath,
|
|
1836
2215
|
directory,
|
|
1837
|
-
filePath:
|
|
2216
|
+
filePath: path12.join(dir, middlewareFile.name)
|
|
1838
2217
|
});
|
|
1839
2218
|
}
|
|
1840
2219
|
for (const entry of entries) {
|
|
@@ -1842,7 +2221,7 @@ async function discoverMiddlewareRoutes(appDir) {
|
|
|
1842
2221
|
continue;
|
|
1843
2222
|
}
|
|
1844
2223
|
await walk(
|
|
1845
|
-
|
|
2224
|
+
path12.join(dir, entry.name),
|
|
1846
2225
|
appendMiddlewareRoutePath(routePath, entry.name),
|
|
1847
2226
|
appendMiddlewareDirectory(directory, entry.name),
|
|
1848
2227
|
discovered
|
|
@@ -1918,7 +2297,7 @@ async function buildUniversal(config, routeManager, apiRouteManager, serverRende
|
|
|
1918
2297
|
logger.info(`\u{1F4CB} Found ${pageRoutes.length} page routes`);
|
|
1919
2298
|
const fs4 = await import("fs/promises");
|
|
1920
2299
|
const layoutRoutes = [];
|
|
1921
|
-
const appDir =
|
|
2300
|
+
const appDir = path12.join(root, srcDir, "app");
|
|
1922
2301
|
async function findLayoutsForClient(dir, routePrefix = "/") {
|
|
1923
2302
|
try {
|
|
1924
2303
|
const entries = await fs4.readdir(dir, { withFileTypes: true });
|
|
@@ -1926,11 +2305,11 @@ async function buildUniversal(config, routeManager, apiRouteManager, serverRende
|
|
|
1926
2305
|
if (entry.isFile() && entry.name.match(/^layout\.(tsx?|jsx?|vue|svelte)$/)) {
|
|
1927
2306
|
layoutRoutes.push({
|
|
1928
2307
|
pattern: routePrefix,
|
|
1929
|
-
modulePath:
|
|
2308
|
+
modulePath: path12.join(dir, entry.name)
|
|
1930
2309
|
});
|
|
1931
2310
|
} else if (entry.isDirectory() && !entry.name.startsWith(".") && !entry.name.startsWith("_")) {
|
|
1932
2311
|
const childPrefix = routePrefix === "/" ? `/${entry.name}` : `${routePrefix}/${entry.name}`;
|
|
1933
|
-
await findLayoutsForClient(
|
|
2312
|
+
await findLayoutsForClient(path12.join(dir, entry.name), childPrefix);
|
|
1934
2313
|
}
|
|
1935
2314
|
}
|
|
1936
2315
|
} catch {
|
|
@@ -1954,7 +2333,7 @@ ${islandsErrors.map((error) => ` - ${error}`).join("\n")}`
|
|
|
1954
2333
|
);
|
|
1955
2334
|
}
|
|
1956
2335
|
const hydrationPlanCache = /* @__PURE__ */ new Map();
|
|
1957
|
-
const clientOutputDir =
|
|
2336
|
+
const clientOutputDir = path12.join(root, distDir, "client");
|
|
1958
2337
|
const [productionViteResult] = await productionViteResultPromise;
|
|
1959
2338
|
if (productionViteResult.status === "rejected") {
|
|
1960
2339
|
await routeRuntimeManifestResultPromise;
|
|
@@ -1963,21 +2342,29 @@ ${islandsErrors.map((error) => ` - ${error}`).join("\n")}`
|
|
|
1963
2342
|
const productionVite = productionViteResult.value;
|
|
1964
2343
|
logger.info("\u26A1 Building application bundles with Vite Rolldown");
|
|
1965
2344
|
const mobileClient = shouldBuildFarmMobileClient(config);
|
|
1966
|
-
const
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
2345
|
+
const rendererDisabled = isFarmRendererDisabled(config.renderer);
|
|
2346
|
+
const buildClientBundle = async () => {
|
|
2347
|
+
if (rendererDisabled) {
|
|
2348
|
+
await fs4.rm(clientOutputDir, { recursive: true, force: true });
|
|
2349
|
+
await fs4.mkdir(clientOutputDir, { recursive: true });
|
|
2350
|
+
return;
|
|
2351
|
+
}
|
|
2352
|
+
return buildClient(
|
|
2353
|
+
productionVite,
|
|
2354
|
+
config,
|
|
2355
|
+
root,
|
|
2356
|
+
srcDir,
|
|
2357
|
+
clientOutputDir,
|
|
2358
|
+
pageRoutes,
|
|
2359
|
+
layoutRoutes,
|
|
2360
|
+
routeSlots,
|
|
2361
|
+
isolatedClientBoundaryModules,
|
|
2362
|
+
hydrationPlanCache,
|
|
2363
|
+
rendererBuildLifetime,
|
|
2364
|
+
routeManager.getProgrammaticClientRoutes(),
|
|
2365
|
+
mobileClient
|
|
2366
|
+
);
|
|
2367
|
+
};
|
|
1981
2368
|
const buildSSRBundle = () => buildSSRInMemory(
|
|
1982
2369
|
productionVite,
|
|
1983
2370
|
config,
|
|
@@ -1995,12 +2382,14 @@ ${islandsErrors.map((error) => ` - ${error}`).join("\n")}`
|
|
|
1995
2382
|
);
|
|
1996
2383
|
let clientBuildResult;
|
|
1997
2384
|
let ssrBuildResult;
|
|
1998
|
-
if (config.renderer.buildConcurrency === "serial") {
|
|
2385
|
+
if (!rendererDisabled && config.renderer.buildConcurrency === "serial") {
|
|
1999
2386
|
logger.info(`\u{1F4E6} Building client and SSR bundles serially for ${config.renderer.name}...`);
|
|
2000
2387
|
[clientBuildResult] = await Promise.allSettled([buildClientBundle()]);
|
|
2001
2388
|
[ssrBuildResult] = await Promise.allSettled([buildSSRBundle()]);
|
|
2002
2389
|
} else {
|
|
2003
|
-
logger.info(
|
|
2390
|
+
logger.info(
|
|
2391
|
+
rendererDisabled ? "\u{1F4E6} Building the server bundle (renderer: false, no client bundle)..." : "\u{1F4E6} Building client and SSR bundles in parallel..."
|
|
2392
|
+
);
|
|
2004
2393
|
[clientBuildResult, ssrBuildResult] = await Promise.allSettled([
|
|
2005
2394
|
buildClientBundle(),
|
|
2006
2395
|
buildSSRBundle()
|
|
@@ -2046,6 +2435,7 @@ ${islandsErrors.map((error) => ` - ${error}`).join("\n")}`
|
|
|
2046
2435
|
logger.warn(warning);
|
|
2047
2436
|
}
|
|
2048
2437
|
const { bundle: ssrBundle, entryFile: ssrEntryFile, configuredHeaderRoutes } = ssrResult;
|
|
2438
|
+
assertServerReadSSRAssetsSupported(ssrBundle, preset, root);
|
|
2049
2439
|
await writeSSRAssetsToClient(ssrBundle, clientOutputDir);
|
|
2050
2440
|
if (config.docs.enabled) {
|
|
2051
2441
|
await copyFarmDocsFontAssetsToClient(root, clientOutputDir);
|
|
@@ -2068,10 +2458,10 @@ ${islandsErrors.map((error) => ` - ${error}`).join("\n")}`
|
|
|
2068
2458
|
lifecyclePluginManager
|
|
2069
2459
|
);
|
|
2070
2460
|
const runtimeManifestPath = await writeFarmRouteRuntimeManifest(
|
|
2071
|
-
|
|
2461
|
+
path12.join(root, distDir),
|
|
2072
2462
|
routeRuntimeManifest
|
|
2073
2463
|
);
|
|
2074
|
-
logger.info(`\u{1F4CB} Route runtime manifest: ${
|
|
2464
|
+
logger.info(`\u{1F4CB} Route runtime manifest: ${path12.relative(root, runtimeManifestPath)}`);
|
|
2075
2465
|
} catch (error) {
|
|
2076
2466
|
if (lifecyclePluginManager) {
|
|
2077
2467
|
await lifecyclePluginManager.runHookParallel("onError", {
|
|
@@ -2105,14 +2495,15 @@ function varyFarmNitroCacheRulesByShell(rules) {
|
|
|
2105
2495
|
}
|
|
2106
2496
|
async function writeSSRAssetsToClient(bundle, outputDir) {
|
|
2107
2497
|
const fs4 = await import("fs/promises");
|
|
2498
|
+
const serverOnlyAssets = collectServerOnlySSRAssets(bundle);
|
|
2108
2499
|
for (const [fileName, output] of Object.entries(bundle)) {
|
|
2109
|
-
if (output.type !== "asset") continue;
|
|
2500
|
+
if (output.type !== "asset" || serverOnlyAssets.has(fileName)) continue;
|
|
2110
2501
|
if (fileName === "farm-fonts.css") {
|
|
2111
2502
|
await mergeBuiltFontCss(outputDir, output.source);
|
|
2112
2503
|
continue;
|
|
2113
2504
|
}
|
|
2114
|
-
const filePath =
|
|
2115
|
-
await fs4.mkdir(
|
|
2505
|
+
const filePath = path12.join(outputDir, fileName);
|
|
2506
|
+
await fs4.mkdir(path12.dirname(filePath), { recursive: true });
|
|
2116
2507
|
await fs4.writeFile(filePath, output.source);
|
|
2117
2508
|
}
|
|
2118
2509
|
}
|
|
@@ -2120,15 +2511,15 @@ async function copyFarmDocsFontAssetsToClient(root, outputDir) {
|
|
|
2120
2511
|
const fs4 = await import("fs/promises");
|
|
2121
2512
|
await Promise.all(
|
|
2122
2513
|
resolveFarmDocsFontAssets(root).map(async ({ sourcePath, url }) => {
|
|
2123
|
-
const targetPath =
|
|
2124
|
-
await fs4.mkdir(
|
|
2514
|
+
const targetPath = path12.join(outputDir, url.replace(/^\/+/, ""));
|
|
2515
|
+
await fs4.mkdir(path12.dirname(targetPath), { recursive: true });
|
|
2125
2516
|
await fs4.copyFile(sourcePath, targetPath);
|
|
2126
2517
|
})
|
|
2127
2518
|
);
|
|
2128
2519
|
}
|
|
2129
2520
|
async function mergeBuiltFontCss(outputDir, fontCssSource) {
|
|
2130
2521
|
const fs4 = await import("fs/promises");
|
|
2131
|
-
const fontCssPath =
|
|
2522
|
+
const fontCssPath = path12.join(outputDir, "farm-fonts.css");
|
|
2132
2523
|
let fontCss = fontCssSource;
|
|
2133
2524
|
if (fontCss === void 0) {
|
|
2134
2525
|
try {
|
|
@@ -2137,7 +2528,7 @@ async function mergeBuiltFontCss(outputDir, fontCssSource) {
|
|
|
2137
2528
|
return;
|
|
2138
2529
|
}
|
|
2139
2530
|
}
|
|
2140
|
-
const clientCssPath =
|
|
2531
|
+
const clientCssPath = path12.join(outputDir, "farm-client.css");
|
|
2141
2532
|
let clientCss = "";
|
|
2142
2533
|
try {
|
|
2143
2534
|
clientCss = await fs4.readFile(clientCssPath, "utf8");
|
|
@@ -2147,6 +2538,13 @@ async function mergeBuiltFontCss(outputDir, fontCssSource) {
|
|
|
2147
2538
|
await fs4.writeFile(fontCssPath, normalizedFontCss);
|
|
2148
2539
|
await fs4.writeFile(clientCssPath, mergeFarmFontCss(clientCss, normalizedFontCss));
|
|
2149
2540
|
}
|
|
2541
|
+
function importsFarmClientBlockedPackage(id, packageName) {
|
|
2542
|
+
return id === packageName || id.startsWith(`${packageName}/`);
|
|
2543
|
+
}
|
|
2544
|
+
function importsFarmApiRouteModule(id) {
|
|
2545
|
+
const specifier = id.replace(/\\/g, "/").split("?", 1)[0];
|
|
2546
|
+
return /(?:^|\/)api\/(?:.*\/)?route(?:\.[cm]?[jt]sx?)?$/.test(specifier);
|
|
2547
|
+
}
|
|
2150
2548
|
var IncompleteClientBuildOutputError = class extends Error {
|
|
2151
2549
|
constructor(detail) {
|
|
2152
2550
|
super(`Farm client build produced incomplete output: ${detail}`);
|
|
@@ -2156,7 +2554,7 @@ var IncompleteClientBuildOutputError = class extends Error {
|
|
|
2156
2554
|
async function validateClientBuildOutput(root, srcDir, outputDir) {
|
|
2157
2555
|
const fs4 = await import("fs/promises");
|
|
2158
2556
|
const fingerprinted = await findFingerprintedClientEntry(outputDir);
|
|
2159
|
-
const clientEntryPath =
|
|
2557
|
+
const clientEntryPath = path12.join(outputDir, fingerprinted ?? "farm-client.js");
|
|
2160
2558
|
let clientEntrySize = 0;
|
|
2161
2559
|
try {
|
|
2162
2560
|
const clientEntry = await fs4.stat(clientEntryPath);
|
|
@@ -2166,8 +2564,8 @@ async function validateClientBuildOutput(root, srcDir, outputDir) {
|
|
|
2166
2564
|
if (clientEntrySize === 0) {
|
|
2167
2565
|
throw new IncompleteClientBuildOutputError("farm-client.js is missing or empty");
|
|
2168
2566
|
}
|
|
2169
|
-
const clientCssPath =
|
|
2170
|
-
const globalsCssPath =
|
|
2567
|
+
const clientCssPath = path12.join(outputDir, "farm-client.css");
|
|
2568
|
+
const globalsCssPath = path12.join(root, srcDir, "app", "globals.css");
|
|
2171
2569
|
let expectsCss = false;
|
|
2172
2570
|
try {
|
|
2173
2571
|
const globalsCss = await fs4.readFile(globalsCssPath, "utf8");
|
|
@@ -2188,7 +2586,7 @@ async function validateClientBuildOutput(root, srcDir, outputDir) {
|
|
|
2188
2586
|
}
|
|
2189
2587
|
}
|
|
2190
2588
|
function getCachedClientModuleHydrationPlan(modulePath, root, mode, cache, options = {}) {
|
|
2191
|
-
const key = `${
|
|
2589
|
+
const key = `${path12.resolve(root)}\0${mode}\0${options.asyncOwnerIslands === true}\0${options.serverOwners === true}\0${options.serverTreeLayouts === true}\0${path12.resolve(modulePath)}`;
|
|
2192
2590
|
let plan = cache.get(key);
|
|
2193
2591
|
if (!plan) {
|
|
2194
2592
|
plan = getClientModuleHydrationPlan(modulePath, root, mode, options);
|
|
@@ -2197,10 +2595,10 @@ function getCachedClientModuleHydrationPlan(modulePath, root, mode, cache, optio
|
|
|
2197
2595
|
return { ...plan, isolatedBoundaries: [...plan.isolatedBoundaries] };
|
|
2198
2596
|
}
|
|
2199
2597
|
async function buildClient(productionVite, config, root, srcDir, outputDir, pageRoutes, layoutRoutes = [], routeSlots = [], isolatedClientBoundaryModules = /* @__PURE__ */ new Set(), hydrationPlanCache = /* @__PURE__ */ new Map(), rendererBuildLifetime, programmaticClientRoutes, mobile = false) {
|
|
2200
|
-
if (!mobile) await removeFarmMobileClientManifest(
|
|
2598
|
+
if (!mobile) await removeFarmMobileClientManifest(path12.dirname(outputDir));
|
|
2201
2599
|
const viteBuild = productionVite.build;
|
|
2202
2600
|
const { farmPlugin, farmServerOnlyEntriesPlugin } = await import("./vite.mjs");
|
|
2203
|
-
const { PluginManager: PluginManager2 } = await import("./plugin-
|
|
2601
|
+
const { PluginManager: PluginManager2 } = await import("./plugin-SAS22JL7.mjs");
|
|
2204
2602
|
const fs4 = await import("fs/promises");
|
|
2205
2603
|
const pluginManager = new PluginManager2({
|
|
2206
2604
|
config,
|
|
@@ -2364,6 +2762,16 @@ async function buildClient(productionVite, config, root, srcDir, outputDir, page
|
|
|
2364
2762
|
);
|
|
2365
2763
|
}
|
|
2366
2764
|
}
|
|
2765
|
+
const serverSlotPlans = islandsMode ? routeSlots.flatMap((slot) => {
|
|
2766
|
+
const plan = getCachedClientModuleHydrationPlan(
|
|
2767
|
+
slot.modulePath,
|
|
2768
|
+
root,
|
|
2769
|
+
isolatedMode,
|
|
2770
|
+
hydrationPlanCache,
|
|
2771
|
+
{ ...pagePlanOptions, serverOwners: true }
|
|
2772
|
+
);
|
|
2773
|
+
return plan.isClientComponent ? [] : [{ slot, plan }];
|
|
2774
|
+
}) : [];
|
|
2367
2775
|
for (const { route, metadata } of routePlans) {
|
|
2368
2776
|
if (isAdapterDocsRoute(route.pattern)) continue;
|
|
2369
2777
|
try {
|
|
@@ -2375,7 +2783,10 @@ async function buildClient(productionVite, config, root, srcDir, outputDir, page
|
|
|
2375
2783
|
`\u26A0\uFE0F ${describeSuppressedAsyncHydration(route.pattern, metadata.fallbackReason)}`
|
|
2376
2784
|
);
|
|
2377
2785
|
}
|
|
2378
|
-
|
|
2786
|
+
const slotBoundaries = serverSlotPlans.filter(
|
|
2787
|
+
({ slot }) => layoutAppliesToRoute(slot.ownerDirectory ?? slot.ownerPattern, routeDirectory(route))
|
|
2788
|
+
).flatMap(({ plan }) => plan.isolatedBoundaries);
|
|
2789
|
+
if (metadata.shouldHydrate || metadata.hasIsolatedClientBoundaries || applicableClientLayouts.length > 0 || slotBoundaries.length > 0) {
|
|
2379
2790
|
const relativePath = route.modulePath.replace(root, "").replace(/^\//, "");
|
|
2380
2791
|
const islandStrategy = resolveFarmRouteRootStrategy(
|
|
2381
2792
|
route,
|
|
@@ -2389,9 +2800,10 @@ async function buildClient(productionVite, config, root, srcDir, outputDir, page
|
|
|
2389
2800
|
relativePath,
|
|
2390
2801
|
pageShouldHydrate: metadata.shouldHydrate,
|
|
2391
2802
|
islandStrategy,
|
|
2392
|
-
hasIsolatedClientBoundaries: metadata.hasIsolatedClientBoundaries || applicableClientLayouts.some((layout) => layout.hasIsolatedClientBoundaries),
|
|
2803
|
+
hasIsolatedClientBoundaries: metadata.hasIsolatedClientBoundaries || applicableClientLayouts.some((layout) => layout.hasIsolatedClientBoundaries) || slotBoundaries.length > 0,
|
|
2393
2804
|
isolatedBoundaries: [
|
|
2394
2805
|
...metadata.hasIsolatedClientBoundaries ? metadata.isolatedBoundaries : [],
|
|
2806
|
+
...slotBoundaries,
|
|
2395
2807
|
...applicableClientLayouts.filter((layout) => layout.hasIsolatedClientBoundaries || layout.serverTreeLayout).flatMap((layout) => layout.isolatedBoundaries)
|
|
2396
2808
|
],
|
|
2397
2809
|
// The server renders a server tree only below a hydrating layout.
|
|
@@ -2417,6 +2829,7 @@ async function buildClient(productionVite, config, root, srcDir, outputDir, page
|
|
|
2417
2829
|
) ? hydrationStrategies[0] ?? "load" : "load";
|
|
2418
2830
|
const docsClientRoutes = syntheticDocsPatterns.map((pattern) => ({
|
|
2419
2831
|
pattern,
|
|
2832
|
+
docs: true,
|
|
2420
2833
|
modulePath: "",
|
|
2421
2834
|
relativePath: "",
|
|
2422
2835
|
pageShouldHydrate: false,
|
|
@@ -2431,7 +2844,8 @@ async function buildClient(productionVite, config, root, srcDir, outputDir, page
|
|
|
2431
2844
|
}
|
|
2432
2845
|
const clientRouteSlots = routeSlots.filter((slot) => {
|
|
2433
2846
|
try {
|
|
2434
|
-
|
|
2847
|
+
const metadata = getClientModuleMetadata(slot.modulePath, root);
|
|
2848
|
+
return metadata.shouldHydrate && (!islandsMode || metadata.isClientComponent);
|
|
2435
2849
|
} catch (error) {
|
|
2436
2850
|
logger.warn(`\u26A0\uFE0F Could not inspect route slot ${slot.modulePath}: ${error}`);
|
|
2437
2851
|
return false;
|
|
@@ -2441,10 +2855,10 @@ async function buildClient(productionVite, config, root, srcDir, outputDir, page
|
|
|
2441
2855
|
`\u{1F4F1} Total hydratable routes detected: ${clientPages.length} pages, ${clientLayouts.filter((layout) => layout.shouldHydrate || layout.hasIsolatedClientBoundaries).length} layouts, and ${clientRouteSlots.length} slots`
|
|
2442
2856
|
);
|
|
2443
2857
|
const buildTarget = async (platform) => {
|
|
2444
|
-
const clientEntryRoot =
|
|
2858
|
+
const clientEntryRoot = path12.join(root, ".farm", "tmp");
|
|
2445
2859
|
await fs4.mkdir(clientEntryRoot, { recursive: true });
|
|
2446
|
-
const clientEntryDir = await fs4.mkdtemp(
|
|
2447
|
-
const clientEntryPath =
|
|
2860
|
+
const clientEntryDir = await fs4.mkdtemp(path12.join(clientEntryRoot, "client-entry-"));
|
|
2861
|
+
const clientEntryPath = path12.join(clientEntryDir, "farm-client-entry.tsx");
|
|
2448
2862
|
const clientHydrationCode = generateClientHydrationEntry(
|
|
2449
2863
|
clientPages,
|
|
2450
2864
|
clientLayouts,
|
|
@@ -2475,10 +2889,14 @@ async function buildClient(productionVite, config, root, srcDir, outputDir, page
|
|
|
2475
2889
|
) : []
|
|
2476
2890
|
);
|
|
2477
2891
|
const entryName = platform === "mobile" ? FARM_MOBILE_CLIENT_ENTRY_NAME : "farm-client";
|
|
2478
|
-
|
|
2892
|
+
const clientEntry = islandsMode && platform === "web" && clientHydrationCode.includes("/*farm-router-stub*/") ? splitFarmClientRouter(clientHydrationCode) : { entry: clientHydrationCode, router: void 0 };
|
|
2893
|
+
await fs4.writeFile(clientEntryPath, clientEntry.entry);
|
|
2894
|
+
if (clientEntry.router !== void 0) {
|
|
2895
|
+
await fs4.writeFile(path12.join(clientEntryDir, "farm-client-router.tsx"), clientEntry.router);
|
|
2896
|
+
}
|
|
2479
2897
|
const clientInput = { [entryName]: clientEntryPath };
|
|
2480
2898
|
if (platform === "web" && canBootFarmIslandsClient(config)) {
|
|
2481
|
-
const clientBootPath =
|
|
2899
|
+
const clientBootPath = path12.join(clientEntryDir, "farm-client-boot.tsx");
|
|
2482
2900
|
await fs4.writeFile(
|
|
2483
2901
|
clientBootPath,
|
|
2484
2902
|
'import { startFarmIslandsBoot } from "@farm.js/core/internal/islands-boot";\nstartFarmIslandsBoot();\n'
|
|
@@ -2495,7 +2913,7 @@ async function buildClient(productionVite, config, root, srcDir, outputDir, page
|
|
|
2495
2913
|
if (hasScopedPostcssConfig) {
|
|
2496
2914
|
logger.info("\u{1F4E6} Using project PostCSS/Tailwind configuration");
|
|
2497
2915
|
} else {
|
|
2498
|
-
const postcssConfigPath =
|
|
2916
|
+
const postcssConfigPath = path12.join(clientEntryDir, "postcss.config.cjs");
|
|
2499
2917
|
await fs4.writeFile(postcssConfigPath, "module.exports = { plugins: [] };\n");
|
|
2500
2918
|
postcssSearchPath = clientEntryDir;
|
|
2501
2919
|
tailwindVitePlugin = await loadTailwindVitePlugin({
|
|
@@ -2541,7 +2959,7 @@ async function buildClient(productionVite, config, root, srcDir, outputDir, page
|
|
|
2541
2959
|
// A browser cannot load a Node builtin: farmServerOnlyEntriesPlugin
|
|
2542
2960
|
// resolves one to Farm's browser module for it instead.
|
|
2543
2961
|
external: (id) => {
|
|
2544
|
-
if (id
|
|
2962
|
+
if (importsFarmClientBlockedPackage(id, "fsevents") || id.endsWith(".node")) {
|
|
2545
2963
|
return true;
|
|
2546
2964
|
}
|
|
2547
2965
|
return false;
|
|
@@ -2551,24 +2969,24 @@ async function buildClient(productionVite, config, root, srcDir, outputDir, page
|
|
|
2551
2969
|
plugins: [
|
|
2552
2970
|
createFarmThemeCssPlugin(config.theme, config.basePath),
|
|
2553
2971
|
createFarmPrivateClientSourcemapsPlugin({
|
|
2554
|
-
outDir:
|
|
2555
|
-
|
|
2972
|
+
outDir: path12.join(
|
|
2973
|
+
path12.dirname(outputDir),
|
|
2556
2974
|
platform === "mobile" ? `${FARM_CLIENT_SOURCEMAPS_DIR}-mobile` : FARM_CLIENT_SOURCEMAPS_DIR
|
|
2557
2975
|
)
|
|
2558
2976
|
}),
|
|
2559
2977
|
// The web client's preload manifests; the mobile client records its files instead.
|
|
2560
2978
|
platform === "mobile" ? createFarmMobileClientManifestPlugin({
|
|
2561
|
-
buildDir:
|
|
2979
|
+
buildDir: path12.dirname(outputDir),
|
|
2562
2980
|
entryName
|
|
2563
2981
|
}) : createFarmClientModulePreloadPlugin({
|
|
2564
2982
|
root,
|
|
2565
|
-
buildDir:
|
|
2983
|
+
buildDir: path12.dirname(outputDir),
|
|
2566
2984
|
entryName: "farm-client"
|
|
2567
2985
|
}),
|
|
2568
2986
|
...adapterOwnsDocsRuntime && platform === "web" ? [
|
|
2569
2987
|
createFarmDocsModulePreloadPlugin({
|
|
2570
2988
|
root,
|
|
2571
|
-
buildDir:
|
|
2989
|
+
buildDir: path12.dirname(outputDir),
|
|
2572
2990
|
importer: clientEntryPath,
|
|
2573
2991
|
entryName: "farm-client",
|
|
2574
2992
|
modules: [
|
|
@@ -2588,47 +3006,63 @@ async function buildClient(productionVite, config, root, srcDir, outputDir, page
|
|
|
2588
3006
|
{
|
|
2589
3007
|
name: "farm-client-only-imports",
|
|
2590
3008
|
enforce: "pre",
|
|
2591
|
-
resolveId
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
3009
|
+
resolveId: {
|
|
3010
|
+
// Every specifier the handler redirects, as a superset of its checks.
|
|
3011
|
+
filter: {
|
|
3012
|
+
id: /@farm\.js\/core|\/api\/|fsevents|\.node$|node-pre-gyp|nf3|^(?:nitro|vite|esbuild|rolldown|rollup)(?:\/|$)/
|
|
3013
|
+
},
|
|
3014
|
+
handler(id) {
|
|
3015
|
+
if (id === "@farm.js/core") {
|
|
3016
|
+
return { id: "\0farm-client-exports", external: false };
|
|
3017
|
+
}
|
|
3018
|
+
if (id === "@farm.js/core/i18n/server") {
|
|
3019
|
+
return { id: "\0farm-i18n-client-bridge", external: false };
|
|
3020
|
+
}
|
|
3021
|
+
if (id === "@farm.js/core/server" || id === "@farm.js/core/api" || id === "@farm.js/core/middleware" || id === "@farm.js/core/headers" || id === "@farm.js/core/config" || id.includes("@farm.js/core/middleware") || id.includes("@farm.js/core/query/server")) {
|
|
3022
|
+
return { id: "\0empty-module", external: false };
|
|
3023
|
+
}
|
|
3024
|
+
if (importsFarmApiRouteModule(id)) {
|
|
3025
|
+
return { id: "\0empty-api-route", external: false };
|
|
3026
|
+
}
|
|
3027
|
+
if (importsFarmClientBlockedPackage(id, "fsevents") || id.endsWith(".node") || id === "nitro" || id === "vite" || id === "esbuild" || id === "rolldown" || id.startsWith("rolldown/") || id === "rollup" || id.startsWith("nitro/") || importsFarmClientBlockedPackage(id, "node-pre-gyp") || importsFarmClientBlockedPackage(id, "@mapbox/node-pre-gyp") || importsFarmClientBlockedPackage(id, "nf3")) {
|
|
3028
|
+
return { id: "\0empty-module", external: false };
|
|
3029
|
+
}
|
|
3030
|
+
return null;
|
|
2606
3031
|
}
|
|
2607
|
-
return null;
|
|
2608
3032
|
},
|
|
2609
|
-
load
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
'export {
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
3033
|
+
load: {
|
|
3034
|
+
filter: {
|
|
3035
|
+
id: exactIdPattern([
|
|
3036
|
+
"\0empty-module",
|
|
3037
|
+
"\0empty-api-route",
|
|
3038
|
+
"\0farm-i18n-client-bridge",
|
|
3039
|
+
"\0farm-client-exports"
|
|
3040
|
+
])
|
|
3041
|
+
},
|
|
3042
|
+
handler(id) {
|
|
3043
|
+
if (id === "\0empty-module") {
|
|
3044
|
+
return "const emptyMiddlewareStore = new Map(); export default {}; export const getMiddlewareContext = () => emptyMiddlewareStore; export const getMiddlewareData = () => emptyMiddlewareStore; export const getMiddlewareValue = () => undefined; export const middleware = () => ({});";
|
|
3045
|
+
}
|
|
3046
|
+
if (id === "\0empty-api-route") {
|
|
3047
|
+
return "export const GET = () => {}; export const HEAD = () => {}; export const QUERY = () => {}; export const POST = () => {}; export const PUT = () => {}; export const DELETE = () => {}; export const PATCH = () => {}; export const OPTIONS = () => {}; export default {};";
|
|
3048
|
+
}
|
|
3049
|
+
if (id === "\0farm-i18n-client-bridge") {
|
|
3050
|
+
return 'export { createTranslator, format, getLocale, getLocaleSource, t } from "@farm.js/core/i18n/client";';
|
|
3051
|
+
}
|
|
3052
|
+
if (id === "\0farm-client-exports") {
|
|
3053
|
+
return [
|
|
3054
|
+
"// Farm.js Client Exports - Safe for browser bundling",
|
|
3055
|
+
'export { Link } from "@farm.js/core/client";',
|
|
3056
|
+
'export { useRouter } from "@farm.js/core/client";',
|
|
3057
|
+
'export { usePathname, useSearchParams } from "@farm.js/core/navigation";',
|
|
3058
|
+
// A page that hydrates ships to the browser with its notFound()/redirect() calls.
|
|
3059
|
+
'export { getFarmRedirectError, isFarmNotFoundError, isFarmRedirectError, notFound, permanentRedirect, redirect } from "@farm.js/core/navigation";',
|
|
3060
|
+
'export { createAPIClient } from "@farm.js/core/client";',
|
|
3061
|
+
'export { localFont, remoteFont } from "@farm.js/core/font";'
|
|
3062
|
+
].join("\n");
|
|
3063
|
+
}
|
|
3064
|
+
return null;
|
|
2630
3065
|
}
|
|
2631
|
-
return null;
|
|
2632
3066
|
}
|
|
2633
3067
|
},
|
|
2634
3068
|
farmPlugin(
|
|
@@ -2658,8 +3092,8 @@ async function buildClient(productionVite, config, root, srcDir, outputDir, page
|
|
|
2658
3092
|
};
|
|
2659
3093
|
await viteBuild(mergeFarmProductionViteConfig(clientViteConfig, config.vite));
|
|
2660
3094
|
if (platform === "mobile") {
|
|
2661
|
-
await fs4.rm(
|
|
2662
|
-
if (!await hasFarmMobileClientEntry(
|
|
3095
|
+
await fs4.rm(path12.join(outputDir, `${entryName}.css`), { force: true });
|
|
3096
|
+
if (!await hasFarmMobileClientEntry(path12.dirname(outputDir), outputDir)) {
|
|
2663
3097
|
throw new IncompleteClientBuildOutputError(
|
|
2664
3098
|
`${FARM_MOBILE_CLIENT_ENTRY_NAME}.js is missing or empty`
|
|
2665
3099
|
);
|
|
@@ -2680,12 +3114,12 @@ async function buildClient(productionVite, config, root, srcDir, outputDir, page
|
|
|
2680
3114
|
}
|
|
2681
3115
|
function toBakedMarkdownSourcePath(root, filePath) {
|
|
2682
3116
|
if (!filePath) return "";
|
|
2683
|
-
if (!
|
|
2684
|
-
const relative =
|
|
2685
|
-
if (!relative || relative.startsWith("..") ||
|
|
2686
|
-
return
|
|
3117
|
+
if (!path12.isAbsolute(filePath)) return filePath.split(path12.sep).join("/");
|
|
3118
|
+
const relative = path12.relative(root, filePath);
|
|
3119
|
+
if (!relative || relative.startsWith("..") || path12.isAbsolute(relative)) {
|
|
3120
|
+
return path12.basename(filePath);
|
|
2687
3121
|
}
|
|
2688
|
-
return relative.split(
|
|
3122
|
+
return relative.split(path12.sep).join("/");
|
|
2689
3123
|
}
|
|
2690
3124
|
function generateUniversalRouterStateRuntime(streamNavigations = false) {
|
|
2691
3125
|
return `
|
|
@@ -2700,6 +3134,7 @@ const IDLE_NAVIGATION_STATE = {
|
|
|
2700
3134
|
startedAt: null,
|
|
2701
3135
|
};
|
|
2702
3136
|
|
|
3137
|
+
/*farm-router-start*/
|
|
2703
3138
|
function createNavigationLocation(url) {
|
|
2704
3139
|
return {
|
|
2705
3140
|
href: url.href,
|
|
@@ -2769,11 +3204,20 @@ function readHistoryIndex(state) {
|
|
|
2769
3204
|
return Number.isSafeInteger(value) ? value : null;
|
|
2770
3205
|
}
|
|
2771
3206
|
|
|
3207
|
+
/*farm-router-end*/
|
|
2772
3208
|
function hasAbsoluteNavigationHref(href) {
|
|
2773
3209
|
return /^[a-zA-Z][a-zA-Z\\d+.-]*:/.test(href) || href.startsWith("//");
|
|
2774
3210
|
}
|
|
2775
3211
|
`.trim();
|
|
2776
3212
|
}
|
|
3213
|
+
function generateClientPageDirectorySource() {
|
|
3214
|
+
return `function getFarmPageDirectory(pathname) {
|
|
3215
|
+
const path = getFarmRoutePathname(pathname);
|
|
3216
|
+
let matched = clientRouteMatcher.match(path);
|
|
3217
|
+
if (matched && matched.route.meta.docs) matched = clientPageRouteMatcher.match(path);
|
|
3218
|
+
return matched ? matched.route.meta.directory || matched.route.meta.pattern : null;
|
|
3219
|
+
}`;
|
|
3220
|
+
}
|
|
2777
3221
|
function generateRuntimePathMatcherSource() {
|
|
2778
3222
|
return `
|
|
2779
3223
|
function normalizeRuntimePath(pathname) {
|
|
@@ -2933,30 +3377,35 @@ function encodeRuntimePathSegment(value) {
|
|
|
2933
3377
|
}
|
|
2934
3378
|
|
|
2935
3379
|
function interpolateRedirectDestination(destination, params) {
|
|
2936
|
-
let result = destination;
|
|
2937
3380
|
const catchAllParamSegments = params[farmCatchAllParamSegments] || {};
|
|
3381
|
+
const encodedParams = new Map();
|
|
2938
3382
|
const orderedCaptures = [];
|
|
2939
3383
|
for (const [key, value] of Object.entries(params)) {
|
|
2940
3384
|
const segments = catchAllParamSegments[key];
|
|
2941
3385
|
const encodedValue = Array.isArray(segments)
|
|
2942
3386
|
? segments.map(encodeRuntimePathSegment).join("/")
|
|
2943
3387
|
: encodeRuntimePathSegment(value);
|
|
3388
|
+
encodedParams.set(key, encodedValue);
|
|
2944
3389
|
orderedCaptures.push(encodedValue);
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
3390
|
+
}
|
|
3391
|
+
// One pass that reads each reference whole, as the development path does: ":id" never
|
|
3392
|
+
// consumes the start of ":idx", an unknown ":name" stays as written, and an injected value is
|
|
3393
|
+
// never read again. An out-of-range "$n" resolves to "", matching the development path.
|
|
3394
|
+
return destination.replace(
|
|
3395
|
+
/\\[\\[\\.\\.\\.(\\w+)\\]\\]|\\[\\.\\.\\.(\\w+)\\]|\\[(\\w+)\\]|:([A-Za-z0-9_]+)(\\*?)|\\$(\\d+)|\\*/g,
|
|
3396
|
+
function(whole, optionalCatchAll, catchAll, bracket, name, star, group) {
|
|
3397
|
+
if (group !== undefined) {
|
|
3398
|
+
const captured = orderedCaptures[Number(group) - 1];
|
|
3399
|
+
return captured === undefined ? "" : captured;
|
|
3400
|
+
}
|
|
3401
|
+
const wildcard = encodedParams.has("wildcard") ? encodedParams.get("wildcard") : "*";
|
|
3402
|
+
const key = optionalCatchAll || catchAll || bracket || name;
|
|
3403
|
+
if (key === undefined) return wildcard;
|
|
3404
|
+
if (encodedParams.has(key)) return encodedParams.get(key);
|
|
3405
|
+
if (name === undefined) return whole;
|
|
3406
|
+
return ":" + name + (star ? wildcard : "");
|
|
3407
|
+
},
|
|
3408
|
+
);
|
|
2960
3409
|
}
|
|
2961
3410
|
`.trim();
|
|
2962
3411
|
}
|
|
@@ -3063,7 +3512,8 @@ ${streamNavigations ? ` // A streamed navigation swaps in the page's shell; its
|
|
|
3063
3512
|
this.activeViewportPrefetches += 1;
|
|
3064
3513
|
let prefetchResult;
|
|
3065
3514
|
try {
|
|
3066
|
-
|
|
3515
|
+
// Through the installed router, so the lazy router's stand-in sees viewport prefetches too.
|
|
3516
|
+
prefetchResult = (window.__FARM_SPA_ROUTER__ || this).prefetch(task.href);
|
|
3067
3517
|
} catch {
|
|
3068
3518
|
prefetchResult = undefined;
|
|
3069
3519
|
}
|
|
@@ -3284,8 +3734,10 @@ ${streamNavigations ? ` // A streamed navigation swaps in the page's shell; its
|
|
|
3284
3734
|
const record = recover ? null : { valid: true, deploymentId, promise: null };
|
|
3285
3735
|
// A navigation (not a prefetch) streams when the router supports it: the page goes in as
|
|
3286
3736
|
// soon as its shell arrives, and its Suspense content follows (takeNavigationStream). A page
|
|
3287
|
-
// whose layouts hydrate, or one rendered in this page's React root, arrives whole.
|
|
3288
|
-
|
|
3737
|
+
// whose layouts hydrate, or one rendered in this page's React root, arrives whole. So does a
|
|
3738
|
+
// refresh, which renders every layout again (no layout chain): like a transition, it keeps
|
|
3739
|
+
// the page on screen until the new one is ready, so the islands it keeps are all in it.
|
|
3740
|
+
const streamShell = ${streamNavigations ? `recover && layoutChain && !interceptFrom && !partialHeaders["F-Render"] &&
|
|
3289
3741
|
!hasHydratableLayout(new URL(url, window.location.href).pathname)` : "false"};
|
|
3290
3742
|
const request = async () => {
|
|
3291
3743
|
const response = await fetchFarmNavigationDocument(url, {
|
|
@@ -3297,7 +3749,7 @@ ${streamNavigations ? ` // A streamed navigation swaps in the page's shell; its
|
|
|
3297
3749
|
...partialHeaders,
|
|
3298
3750
|
...(streamShell ? { "F-Stream": "flush" } : {}),
|
|
3299
3751
|
}, recover, signal);
|
|
3300
|
-
if (!response.ok) throw new Error("Failed to fetch page");
|
|
3752
|
+
if (!response.ok) throw new Error("Failed to fetch page: " + response.status);
|
|
3301
3753
|
const store = (html) => {
|
|
3302
3754
|
if (cacheResult && !signal?.aborted && generation === this.prefetchGeneration &&
|
|
3303
3755
|
deploymentId === window.__FARM_DEPLOYMENT_ID__ && (!record || record.valid)) {
|
|
@@ -3466,6 +3918,188 @@ ${streamNavigations ? ` if (streamShell && response.body) {
|
|
|
3466
3918
|
},
|
|
3467
3919
|
`.trim();
|
|
3468
3920
|
}
|
|
3921
|
+
var FARM_LAZY_ROUTER_STUB = `let farmLoadedRouter = null;
|
|
3922
|
+
let farmRouterLoading = null;
|
|
3923
|
+
const farmRouterReady = [];
|
|
3924
|
+
const farmRouterObserved = new Set();
|
|
3925
|
+
|
|
3926
|
+
function loadFarmRouter() {
|
|
3927
|
+
return farmRouterLoading || (farmRouterLoading = import("./farm-client-router").then(function(module) {
|
|
3928
|
+
farmLoadedRouter = module.spaRouter;
|
|
3929
|
+
// The router module installs itself as the global; this object stays it, so a reference taken
|
|
3930
|
+
// before the router loaded, or a method wrapped on it, keeps working afterwards.
|
|
3931
|
+
window.__FARM_SPA_ROUTER__ = spaRouter;
|
|
3932
|
+
for (const ready of farmRouterReady.splice(0)) ready(farmLoadedRouter);
|
|
3933
|
+
if (farmRouterViewport) farmRouterViewport.disconnect();
|
|
3934
|
+
for (const element of farmRouterObserved) farmLoadedRouter.observeForPrefetch(element);
|
|
3935
|
+
farmRouterObserved.clear();
|
|
3936
|
+
return farmLoadedRouter;
|
|
3937
|
+
}, function(error) {
|
|
3938
|
+
farmRouterLoading = null;
|
|
3939
|
+
throw error;
|
|
3940
|
+
}));
|
|
3941
|
+
}
|
|
3942
|
+
|
|
3943
|
+
let farmRouterViewport = null;
|
|
3944
|
+
function farmRouterViewportObserver() {
|
|
3945
|
+
return farmRouterViewport || (farmRouterViewport = new IntersectionObserver(function(entries) {
|
|
3946
|
+
if (!entries.some(function(entry) { return entry.isIntersecting; })) return;
|
|
3947
|
+
farmRouterViewport.disconnect();
|
|
3948
|
+
void loadFarmRouter().catch(function() {});
|
|
3949
|
+
}, { rootMargin: "50px" }));
|
|
3950
|
+
}
|
|
3951
|
+
|
|
3952
|
+
function farmRouterCall(name, beforeLoad) {
|
|
3953
|
+
return function() {
|
|
3954
|
+
const args = arguments;
|
|
3955
|
+
if (farmLoadedRouter) return farmLoadedRouter[name].apply(farmLoadedRouter, args);
|
|
3956
|
+
if (beforeLoad) return beforeLoad.apply(null, args);
|
|
3957
|
+
return loadFarmRouter().then(function(router) { return router[name].apply(router, args); });
|
|
3958
|
+
};
|
|
3959
|
+
}
|
|
3960
|
+
|
|
3961
|
+
function farmRouterSubscribe(name, loadNow) {
|
|
3962
|
+
return function() {
|
|
3963
|
+
const args = arguments;
|
|
3964
|
+
if (farmLoadedRouter) return farmLoadedRouter[name].apply(farmLoadedRouter, args);
|
|
3965
|
+
let active = true;
|
|
3966
|
+
let cleanup;
|
|
3967
|
+
farmRouterReady.push(function(router) {
|
|
3968
|
+
if (active) cleanup = router[name].apply(router, args);
|
|
3969
|
+
});
|
|
3970
|
+
if (loadNow) void loadFarmRouter().catch(function() {});
|
|
3971
|
+
return function() {
|
|
3972
|
+
active = false;
|
|
3973
|
+
if (cleanup) cleanup();
|
|
3974
|
+
};
|
|
3975
|
+
};
|
|
3976
|
+
}
|
|
3977
|
+
|
|
3978
|
+
const farmRouterStandIn = {
|
|
3979
|
+
get currentPath() {
|
|
3980
|
+
return farmLoadedRouter ? farmLoadedRouter.currentPath : window.location.pathname + window.location.search;
|
|
3981
|
+
},
|
|
3982
|
+
navigate: function(href, options) {
|
|
3983
|
+
if (farmLoadedRouter) return farmLoadedRouter.navigate(href, options);
|
|
3984
|
+
return loadFarmRouter().then(function(router) {
|
|
3985
|
+
return router.navigate(href, options);
|
|
3986
|
+
}, function() {
|
|
3987
|
+
if (options && (options.replace || options.action === "replace")) window.location.replace(href);
|
|
3988
|
+
else window.location.assign(href);
|
|
3989
|
+
});
|
|
3990
|
+
},
|
|
3991
|
+
refresh: farmRouterCall("refresh"),
|
|
3992
|
+
prefetch: farmRouterCall("prefetch"),
|
|
3993
|
+
// A watched link loads the router once it nears the viewport, which then prefetches it.
|
|
3994
|
+
observeForPrefetch: farmRouterCall("observeForPrefetch", function(element) {
|
|
3995
|
+
if (!("IntersectionObserver" in window)) return;
|
|
3996
|
+
farmRouterObserved.add(element);
|
|
3997
|
+
farmRouterViewportObserver().observe(element);
|
|
3998
|
+
}),
|
|
3999
|
+
unobserveForPrefetch: farmRouterCall("unobserveForPrefetch", function(element) {
|
|
4000
|
+
farmRouterObserved.delete(element);
|
|
4001
|
+
if (farmRouterViewport) farmRouterViewport.unobserve(element);
|
|
4002
|
+
}),
|
|
4003
|
+
pushState: farmRouterCall("pushState"),
|
|
4004
|
+
replaceState: farmRouterCall("replaceState"),
|
|
4005
|
+
handlePopState: farmRouterCall("handlePopState"),
|
|
4006
|
+
getNavigationState: farmRouterCall("getNavigationState", function() { return IDLE_NAVIGATION_STATE; }),
|
|
4007
|
+
shouldBlockUnload: farmRouterCall("shouldBlockUnload", function() { return false; }),
|
|
4008
|
+
saveScrollPosition: farmRouterCall("saveScrollPosition", function() {}),
|
|
4009
|
+
subscribeNavigation: farmRouterSubscribe("subscribeNavigation", false),
|
|
4010
|
+
addBlocker: farmRouterSubscribe("addBlocker", true),
|
|
4011
|
+
registerScrollElement: farmRouterSubscribe("registerScrollElement", true),
|
|
4012
|
+
};
|
|
4013
|
+
// Members only the router has, such as its fetch helpers, read and write through to it once loaded.
|
|
4014
|
+
const spaRouter = new Proxy(farmRouterStandIn, {
|
|
4015
|
+
get: function(target, key) {
|
|
4016
|
+
if (key in target || !farmLoadedRouter) return target[key];
|
|
4017
|
+
return farmLoadedRouter[key];
|
|
4018
|
+
},
|
|
4019
|
+
set: function(target, key, value) {
|
|
4020
|
+
if (key in target || !farmLoadedRouter) target[key] = value;
|
|
4021
|
+
else farmLoadedRouter[key] = value;
|
|
4022
|
+
return true;
|
|
4023
|
+
},
|
|
4024
|
+
has: function(target, key) {
|
|
4025
|
+
return key in target || (farmLoadedRouter !== null && key in farmLoadedRouter);
|
|
4026
|
+
},
|
|
4027
|
+
});
|
|
4028
|
+
window.__FARM_SPA_ROUTER__ = spaRouter;
|
|
4029
|
+
|
|
4030
|
+
// Links in server components have no handlers of their own, so intent is read from the document.
|
|
4031
|
+
const farmRouterIntentEvents = ["mouseover", "pointerdown", "focusin"];
|
|
4032
|
+
function farmRouterIntent(event) {
|
|
4033
|
+
const anchor = event.target instanceof Element ? event.target.closest("a[href]") : null;
|
|
4034
|
+
const href = anchor && anchor.getAttribute("href");
|
|
4035
|
+
if (!href || href.startsWith("#") || hasAbsoluteNavigationHref(href)) return;
|
|
4036
|
+
for (const type of farmRouterIntentEvents) document.removeEventListener(type, farmRouterIntent, true);
|
|
4037
|
+
void loadFarmRouter().catch(function() {});
|
|
4038
|
+
}
|
|
4039
|
+
for (const type of farmRouterIntentEvents) document.addEventListener(type, farmRouterIntent, true);
|
|
4040
|
+
`;
|
|
4041
|
+
function bindingPattern(name) {
|
|
4042
|
+
return new RegExp(`(?<![\\w$])(?<![^.]\\.)${name.replace(/\$/g, "\\$")}(?![\\w$])`);
|
|
4043
|
+
}
|
|
4044
|
+
function readFarmEntryDeclarations(source) {
|
|
4045
|
+
const names = /* @__PURE__ */ new Set();
|
|
4046
|
+
const pattern = /^(?:async\s+)?function\*?\s+([\w$]+)|^(?:const|let|var|class)\s+([\w$]+)/gm;
|
|
4047
|
+
for (const match of source.matchAll(pattern)) names.add(match[1] ?? match[2]);
|
|
4048
|
+
return names;
|
|
4049
|
+
}
|
|
4050
|
+
function readFarmEntryImports(source) {
|
|
4051
|
+
const bindings = [];
|
|
4052
|
+
for (const match of source.matchAll(/^import\s+([^"';]+?)\s+from\s+(["'][^"']+["'])/gm)) {
|
|
4053
|
+
const from = match[2];
|
|
4054
|
+
const named = /\{([^}]*)\}/.exec(match[1]);
|
|
4055
|
+
for (const specifier of named?.[1]?.split(",") ?? []) {
|
|
4056
|
+
const [imported, local] = specifier.trim().split(/\s+as\s+/);
|
|
4057
|
+
if (imported)
|
|
4058
|
+
bindings.push({ local: local ?? imported, clause: `{ ${specifier.trim()} }`, from });
|
|
4059
|
+
}
|
|
4060
|
+
const outside = match[1].replace(/\{[^}]*\}/, "").replace(/,/g, " ").trim();
|
|
4061
|
+
const namespace = /\*\s+as\s+([\w$]+)/.exec(outside);
|
|
4062
|
+
if (namespace) bindings.push({ local: namespace[1], clause: `* as ${namespace[1]}`, from });
|
|
4063
|
+
else if (outside) bindings.push({ local: outside, clause: outside, from });
|
|
4064
|
+
}
|
|
4065
|
+
return bindings;
|
|
4066
|
+
}
|
|
4067
|
+
function splitFarmClientRouter(code) {
|
|
4068
|
+
const regions = [];
|
|
4069
|
+
const eager = code.replace(
|
|
4070
|
+
/\/\*farm-router-start\*\/([\s\S]*?)\/\*farm-router-end\*\/\n?/g,
|
|
4071
|
+
(_, body2) => {
|
|
4072
|
+
regions.push(body2);
|
|
4073
|
+
return "";
|
|
4074
|
+
}
|
|
4075
|
+
);
|
|
4076
|
+
const body = regions.join("\n");
|
|
4077
|
+
const moved = readFarmEntryDeclarations(body);
|
|
4078
|
+
const usedByRouter = (name) => !moved.has(name) && bindingPattern(name).test(body);
|
|
4079
|
+
const eagerCode = eager.replace(/^import\s[^;]*;/gm, "");
|
|
4080
|
+
const usedByEntry = (name) => bindingPattern(name).test(eagerCode);
|
|
4081
|
+
const bindings = readFarmEntryImports(eager).filter((binding) => usedByRouter(binding.local));
|
|
4082
|
+
const imports = bindings.filter((binding) => !usedByEntry(binding.local));
|
|
4083
|
+
const reexported = bindings.filter((binding) => usedByEntry(binding.local)).map((binding) => binding.local);
|
|
4084
|
+
const shared = [
|
|
4085
|
+
.../* @__PURE__ */ new Set([
|
|
4086
|
+
...reexported,
|
|
4087
|
+
...[...readFarmEntryDeclarations(eager)].filter((name) => usedByRouter(name))
|
|
4088
|
+
])
|
|
4089
|
+
];
|
|
4090
|
+
return {
|
|
4091
|
+
entry: `${eager.replace("/*farm-router-stub*/", FARM_LAZY_ROUTER_STUB)}
|
|
4092
|
+
export { ${shared.join(", ")} };
|
|
4093
|
+
`,
|
|
4094
|
+
router: [
|
|
4095
|
+
...imports.map((binding) => `import ${binding.clause} from ${binding.from};`),
|
|
4096
|
+
`import { ${shared.join(", ")} } from "./farm-client-entry";`,
|
|
4097
|
+
body,
|
|
4098
|
+
"export { spaRouter };",
|
|
4099
|
+
""
|
|
4100
|
+
].join("\n")
|
|
4101
|
+
};
|
|
4102
|
+
}
|
|
3469
4103
|
var FARM_SEGMENT_NAVIGATION_SERVER_RUNTIME = `
|
|
3470
4104
|
function getFarmLayoutKey(pattern, params) {
|
|
3471
4105
|
return pattern.replace(/\\[\\[?\\.\\.\\.([^\\]]+)\\]?\\]|\\[([^\\]]+)\\]/g, function(match, rest, name) {
|
|
@@ -3530,7 +4164,7 @@ __farmConfigureApp(__farmAppSetup);` : `import React, { createRoot, hydrateRoot
|
|
|
3530
4164
|
root,
|
|
3531
4165
|
renderer.componentExtensions ?? []
|
|
3532
4166
|
);
|
|
3533
|
-
const globalsCssPath =
|
|
4167
|
+
const globalsCssPath = path12.join(root, srcDir, "app", "globals.css");
|
|
3534
4168
|
const serverStyleModules = [];
|
|
3535
4169
|
const cssImport = [
|
|
3536
4170
|
...existsSync2(globalsCssPath) ? [globalsCssPath] : [],
|
|
@@ -3629,7 +4263,7 @@ function isFarmDocsPath() {
|
|
|
3629
4263
|
// Farm.js Client Runtime (no client components)
|
|
3630
4264
|
${cssImport}
|
|
3631
4265
|
${layoutImports}
|
|
3632
|
-
import { createClientCancellation, createClientPluginManager, getFarmIslandValueHeaders, getHashTargetElement, installChunkErrorRecovery, isFarmBlockedNavigationURL, isFarmExternalNavigationURL, reconcileFarmDocumentHead, runFarmNavigationDelegates, setFarmBasePath, setFarmTrailingSlashPreference, stripFarmBasePath } from "@farm.js/core/internal/client-runtime";
|
|
4266
|
+
import { createClientCancellation, createClientPluginManager, createPluginlessClientRuntime, getFarmIslandValueHeaders, getHashTargetElement, installChunkErrorRecovery, isFarmBlockedNavigationURL, isFarmExternalNavigationURL, reconcileFarmDocumentHead, runFarmNavigationDelegates, setFarmBasePath, setFarmTrailingSlashPreference, stripFarmBasePath } from "@farm.js/core/internal/client-runtime";
|
|
3633
4267
|
import { createFarmDeploymentMismatchError, createFarmDeploymentRequestHeaders, isFarmDeploymentMismatchResponse } from "@farm.js/core/deployment";
|
|
3634
4268
|
${clientPluginEntry.imports}
|
|
3635
4269
|
${clientCachePersistence.imports}
|
|
@@ -3646,6 +4280,8 @@ mountFarmDocsSearch();
|
|
|
3646
4280
|
|
|
3647
4281
|
${generateUniversalRouterStateRuntime()}
|
|
3648
4282
|
|
|
4283
|
+
${FARM_NAVIGATION_SCRIPT_SOURCE}
|
|
4284
|
+
|
|
3649
4285
|
// SPA Router for server-rendered pages (HTML swap)
|
|
3650
4286
|
const spaRouter = {
|
|
3651
4287
|
${generateUniversalRouterStateProperties()}
|
|
@@ -3816,12 +4452,7 @@ ${generateUniversalRouterStateProperties()}
|
|
|
3816
4452
|
|
|
3817
4453
|
setTimeout(function() {
|
|
3818
4454
|
Array.from(document.querySelectorAll("script")).forEach(function(script) {
|
|
3819
|
-
|
|
3820
|
-
Array.from(script.attributes).forEach(function(attr) {
|
|
3821
|
-
freshScript.setAttribute(attr.name, attr.value);
|
|
3822
|
-
});
|
|
3823
|
-
freshScript.textContent = script.textContent || "";
|
|
3824
|
-
script.replaceWith(freshScript);
|
|
4455
|
+
script.replaceWith(createFarmNavigationScript(script));
|
|
3825
4456
|
});
|
|
3826
4457
|
}, 0);
|
|
3827
4458
|
|
|
@@ -3860,7 +4491,7 @@ ${generateUniversalRouterStateProperties()}
|
|
|
3860
4491
|
}
|
|
3861
4492
|
};
|
|
3862
4493
|
|
|
3863
|
-
const farmClientRuntime = createClientPluginManager(
|
|
4494
|
+
const farmClientRuntime = ${clientPluginEntry.empty ? "createPluginlessClientRuntime()" : `createClientPluginManager(
|
|
3864
4495
|
${clientPluginEntry.registrations},
|
|
3865
4496
|
{
|
|
3866
4497
|
router: spaRouter,
|
|
@@ -3868,7 +4499,7 @@ const farmClientRuntime = createClientPluginManager(
|
|
|
3868
4499
|
isProd: true,
|
|
3869
4500
|
deploymentId: window.__FARM_DEPLOYMENT_ID__,
|
|
3870
4501
|
},
|
|
3871
|
-
);
|
|
4502
|
+
)`};
|
|
3872
4503
|
window.__FARM_CLIENT_RUNTIME__ = farmClientRuntime;
|
|
3873
4504
|
void farmClientRuntime.start();
|
|
3874
4505
|
|
|
@@ -3928,7 +4559,7 @@ document.addEventListener("click", function(e) {
|
|
|
3928
4559
|
routeEntries.push(` {
|
|
3929
4560
|
pattern: ${JSON.stringify(page.pattern)},${page.directory ? `
|
|
3930
4561
|
directory: ${JSON.stringify(page.directory)},` : ""}
|
|
3931
|
-
pageShouldHydrate: ${JSON.stringify(page.pageShouldHydrate)},
|
|
4562
|
+
pageShouldHydrate: ${JSON.stringify(page.pageShouldHydrate)},${page.docs ? "\n docs: true," : ""}
|
|
3932
4563
|
${page.hasIsolatedClientBoundaries ? "hasIsolatedClientBoundaries: true," : ""}
|
|
3933
4564
|
islandStrategy: ${JSON.stringify(page.islandStrategy)},
|
|
3934
4565
|
navigation: "html-fragment",
|
|
@@ -4003,7 +4634,7 @@ ${layoutImports}
|
|
|
4003
4634
|
${rendererClientImports}
|
|
4004
4635
|
${isolatedHydrationImport}
|
|
4005
4636
|
${providerClientCode.imports}
|
|
4006
|
-
import { createClientCancellation, createClientPluginManager, getFarmIslandValueHeaders, getHashTargetElement, installChunkErrorRecovery, isFarmBlockedNavigationURL, isFarmExternalNavigationURL, reconcileFarmDocumentHead, runFarmNavigationDelegates, scheduleFarmIslandHydration, createFarmSearchParams, searchParamsToObject, setFarmBasePath, setFarmTrailingSlashPreference, stripFarmBasePath } from "@farm.js/core/internal/client-runtime";
|
|
4637
|
+
import { createClientCancellation, createClientPluginManager, createPluginlessClientRuntime, getFarmIslandValueHeaders, getHashTargetElement, installChunkErrorRecovery, isFarmBlockedNavigationURL, isFarmExternalNavigationURL, reconcileFarmDocumentHead, runFarmNavigationDelegates, scheduleFarmIslandHydration, createFarmSearchParams, searchParamsToObject, setFarmBasePath, setFarmTrailingSlashPreference, stripFarmBasePath } from "@farm.js/core/internal/client-runtime";
|
|
4007
4638
|
import { createFarmDeploymentMismatchError, createFarmDeploymentRequestHeaders, isFarmDeploymentMismatchResponse } from "@farm.js/core/deployment";
|
|
4008
4639
|
import { createFarmRouter, isFarmRouteActive, matchFarmRoute } from "@farm.js/core/router";
|
|
4009
4640
|
${clientPluginEntry.imports}
|
|
@@ -4029,6 +4660,12 @@ ${routeEntries.join(",\n")}
|
|
|
4029
4660
|
const clientRouteMatcher = createFarmRouter(clientRoutes.map(function(route) {
|
|
4030
4661
|
return { path: route.pattern, meta: route };
|
|
4031
4662
|
}));
|
|
4663
|
+
${clientPages.some((page) => page.docs) ? `const clientPageRouteMatcher = createFarmRouter(clientRoutes.filter(function(route) {
|
|
4664
|
+
return !route.docs;
|
|
4665
|
+
}).map(function(route) {
|
|
4666
|
+
return { path: route.pattern, meta: route };
|
|
4667
|
+
}));` : "const clientPageRouteMatcher = clientRouteMatcher;"}
|
|
4668
|
+
${generateClientPageDirectorySource()}
|
|
4032
4669
|
|
|
4033
4670
|
${isolatedHydrationRuntime}
|
|
4034
4671
|
${routeClientGraphRuntime}
|
|
@@ -4054,10 +4691,7 @@ function getApplicableLayouts(pathname) {
|
|
|
4054
4691
|
const urlPattern = layout.urlPattern || layout.pattern;
|
|
4055
4692
|
if (urlPattern !== '/' && !isFarmRouteActive(urlPattern, normalizedPath, { exact: false })) continue;
|
|
4056
4693
|
if (layout.groupScope) {
|
|
4057
|
-
if (directory === undefined)
|
|
4058
|
-
const matched = matchRoute(pathname);
|
|
4059
|
-
directory = matched ? matched.route.directory || matched.route.pattern : null;
|
|
4060
|
-
}
|
|
4694
|
+
if (directory === undefined) directory = getFarmPageDirectory(pathname);
|
|
4061
4695
|
if (
|
|
4062
4696
|
typeof directory !== 'string' ||
|
|
4063
4697
|
(directory !== layout.groupScope && !directory.startsWith(layout.groupScope + '/'))
|
|
@@ -4263,6 +4897,7 @@ function renderFarmRoute(root, route) {
|
|
|
4263
4897
|
else root.render(route.element);
|
|
4264
4898
|
}
|
|
4265
4899
|
|
|
4900
|
+
/*farm-router-start*/
|
|
4266
4901
|
function matchesRoutePrefix(pathname, pattern) {
|
|
4267
4902
|
return pattern === "/" ||
|
|
4268
4903
|
isFarmRouteActive(pattern, getFarmRoutePathname(pathname), { exact: false });
|
|
@@ -4277,6 +4912,7 @@ function matchInterceptedRouteSlot(pathname, from) {
|
|
|
4277
4912
|
return null;
|
|
4278
4913
|
}
|
|
4279
4914
|
|
|
4915
|
+
/*farm-router-end*/
|
|
4280
4916
|
function routeSlotKey(slot) {
|
|
4281
4917
|
return slot.ownerPattern + ":" + slot.name;
|
|
4282
4918
|
}
|
|
@@ -4296,6 +4932,7 @@ function findClientRouteSlot(slot) {
|
|
|
4296
4932
|
* client navigation does not execute. The JSON ends at the first statement
|
|
4297
4933
|
* boundary where it parses, so the separator inside a string cannot cut it.
|
|
4298
4934
|
*/
|
|
4935
|
+
/*farm-router-start*/
|
|
4299
4936
|
function readPagePropsPayload(doc) {
|
|
4300
4937
|
const prefix = "window.__FARM_PROPS__=";
|
|
4301
4938
|
const separator = ";window.__FARM_INTEGRATION_API_MANIFEST__=";
|
|
@@ -4328,7 +4965,47 @@ function readRouteSlotPayload(doc) {
|
|
|
4328
4965
|
}
|
|
4329
4966
|
}
|
|
4330
4967
|
|
|
4968
|
+
/**
|
|
4969
|
+
* The settled defer() values a fetched document writes after its body, which a client
|
|
4970
|
+
* navigation does not execute either. Undefined when the document has none.
|
|
4971
|
+
*/
|
|
4972
|
+
function readDeferredDataPayload(doc) {
|
|
4973
|
+
const prefix = "window.__FARM_DEFERRED_DATA__=";
|
|
4974
|
+
for (const script of doc.querySelectorAll("script:not([src])")) {
|
|
4975
|
+
const source = (script.textContent || "").trim();
|
|
4976
|
+
if (!source.startsWith(prefix)) continue;
|
|
4977
|
+
try {
|
|
4978
|
+
return JSON.parse(source.slice(prefix.length).replace(/;$/, ""));
|
|
4979
|
+
} catch {
|
|
4980
|
+
return undefined;
|
|
4981
|
+
}
|
|
4982
|
+
}
|
|
4983
|
+
return undefined;
|
|
4984
|
+
}
|
|
4985
|
+
|
|
4986
|
+
/*farm-router-end*/
|
|
4987
|
+
// defer() values arrive as references, settled by the snapshot the server writes once the
|
|
4988
|
+
// document has rendered, and revived as promises the way development revives them. The page
|
|
4989
|
+
// and its slots share one id space. The server writes references only with a snapshot, so a
|
|
4990
|
+
// document without one has nothing to revive and never loads the reviver.
|
|
4991
|
+
async function reviveFarmDeferredPayload(page, slots, settlements) {
|
|
4992
|
+
if (!settlements) return { page: page, slots: slots };
|
|
4993
|
+
const { reviveDeferredData } = await import("@farm.js/core/deferred");
|
|
4994
|
+
return reviveDeferredData({ page: page, slots: slots }, settlements);
|
|
4995
|
+
}
|
|
4996
|
+
|
|
4997
|
+
/*farm-router-start*/
|
|
4998
|
+
function readFarmDocumentPayload(doc) {
|
|
4999
|
+
return reviveFarmDeferredPayload(
|
|
5000
|
+
readPagePropsPayload(doc),
|
|
5001
|
+
readRouteSlotPayload(doc),
|
|
5002
|
+
readDeferredDataPayload(doc),
|
|
5003
|
+
);
|
|
5004
|
+
}
|
|
5005
|
+
|
|
5006
|
+
/*farm-router-end*/
|
|
4331
5007
|
const routeSlotRoots = new Map();
|
|
5008
|
+
/*farm-router-start*/
|
|
4332
5009
|
let activeRouteInterception = null;
|
|
4333
5010
|
|
|
4334
5011
|
function resetRouteSlotRoots() {
|
|
@@ -4339,6 +5016,7 @@ function resetRouteSlotRoots() {
|
|
|
4339
5016
|
activeRouteInterception = null;
|
|
4340
5017
|
}
|
|
4341
5018
|
|
|
5019
|
+
/*farm-router-end*/
|
|
4342
5020
|
function renderClientRouteSlot(slot, registration, mode) {
|
|
4343
5021
|
const container = document.getElementById(slot.containerId);
|
|
4344
5022
|
if (!container || !registration?.Component) return false;
|
|
@@ -4383,6 +5061,7 @@ function hydrateInitialRouteSlots() {
|
|
|
4383
5061
|
}
|
|
4384
5062
|
}
|
|
4385
5063
|
|
|
5064
|
+
/*farm-router-start*/
|
|
4386
5065
|
function renderRouteInterception(slot, registration, from, nextDocument) {
|
|
4387
5066
|
const container = document.getElementById(slot.containerId);
|
|
4388
5067
|
if (!container || !registration?.Component) return false;
|
|
@@ -4428,13 +5107,22 @@ function clearRouteInterception(destination) {
|
|
|
4428
5107
|
return destination === active.from;
|
|
4429
5108
|
}
|
|
4430
5109
|
|
|
5110
|
+
/*farm-router-end*/
|
|
4431
5111
|
// State
|
|
4432
5112
|
let reactRoot = null;
|
|
4433
5113
|
let reactRootContainer = null;
|
|
4434
|
-
let currentPathname = null;
|
|
4435
5114
|
let isHydrated = false;
|
|
4436
5115
|
let pendingPageHydrationController = null;
|
|
4437
5116
|
|
|
5117
|
+
function setFarmReactRoot(root, container) {
|
|
5118
|
+
reactRoot = root;
|
|
5119
|
+
reactRootContainer = container;
|
|
5120
|
+
}
|
|
5121
|
+
|
|
5122
|
+
function setFarmHydrated() {
|
|
5123
|
+
isHydrated = true;
|
|
5124
|
+
}
|
|
5125
|
+
|
|
4438
5126
|
${generateUniversalRouterStateRuntime(islandValues)}
|
|
4439
5127
|
|
|
4440
5128
|
function cancelPendingPageHydration() {
|
|
@@ -4451,7 +5139,14 @@ function resetReactRoot() {
|
|
|
4451
5139
|
isHydrated = false;
|
|
4452
5140
|
}
|
|
4453
5141
|
|
|
4454
|
-
${islandValues ? FARM_DOCUMENT_PARSED_RUNTIME
|
|
5142
|
+
${islandValues ? `${FARM_DOCUMENT_PARSED_RUNTIME}// A deferred reference in the payload, settled by the snapshot that follows the body.
|
|
5143
|
+
function hasFarmDeferredReference(value) {
|
|
5144
|
+
if (!value || typeof value !== "object") return false;
|
|
5145
|
+
if (typeof value.$farmDeferred === "string") return true;
|
|
5146
|
+
return Object.values(value).some(hasFarmDeferredReference);
|
|
5147
|
+
}
|
|
5148
|
+
|
|
5149
|
+
` : ""}// Hydrate client components
|
|
4455
5150
|
async function hydrate() {
|
|
4456
5151
|
await window.__FARM_PPR_REFRESH_PROMISE__;
|
|
4457
5152
|
// A PPR refresh that is still retrying must not replace DOM once hydration starts.
|
|
@@ -4464,10 +5159,19 @@ async function hydrate() {
|
|
|
4464
5159
|
!matched ||
|
|
4465
5160
|
!matched.route.hasIsolatedClientBoundaries ||
|
|
4466
5161
|
matched.route.pageShouldHydrate ||
|
|
4467
|
-
hasHydratableLayout(pathname)
|
|
5162
|
+
hasHydratableLayout(pathname) ||
|
|
5163
|
+
hasFarmDeferredReference(window.__FARM_ROUTE_SLOTS__)
|
|
4468
5164
|
) {
|
|
4469
5165
|
await farmDocumentParsed();
|
|
4470
5166
|
}` : ""}
|
|
5167
|
+
// The snapshot follows the body: this entry runs after it, or waited for it above.
|
|
5168
|
+
const initialPayload = await reviveFarmDeferredPayload(
|
|
5169
|
+
window.__FARM_PROPS__,
|
|
5170
|
+
window.__FARM_ROUTE_SLOTS__,
|
|
5171
|
+
window.__FARM_DEFERRED_DATA__,
|
|
5172
|
+
);
|
|
5173
|
+
window.__FARM_PROPS__ = initialPayload.page;
|
|
5174
|
+
window.__FARM_ROUTE_SLOTS__ = initialPayload.slots;
|
|
4471
5175
|
|
|
4472
5176
|
if (await hydrateFarmDocsAdapterRuntime()) {
|
|
4473
5177
|
return;
|
|
@@ -4486,7 +5190,13 @@ async function hydrate() {
|
|
|
4486
5190
|
) {
|
|
4487
5191
|
// Not cancelled by a navigation: an island it removes is disposed with its DOM, and one in a
|
|
4488
5192
|
// layout it keeps still waits for its trigger, with any click it already holds.
|
|
5193
|
+
const hydrationSession = await farmClientRuntime.beginHydration({
|
|
5194
|
+
container: document.getElementById("root") || document.body,
|
|
5195
|
+
mode: "hydrate",
|
|
5196
|
+
});
|
|
5197
|
+
// Each island reports and recovers its own failure, so this resolves once they are live.
|
|
4489
5198
|
await hydrateFarmIsolatedClientBoundaries(document);
|
|
5199
|
+
await farmClientRuntime.completeHydration(hydrationSession);
|
|
4490
5200
|
return;
|
|
4491
5201
|
}` : ""}
|
|
4492
5202
|
|
|
@@ -4547,7 +5257,6 @@ async function hydrate() {
|
|
|
4547
5257
|
}
|
|
4548
5258
|
renderFarmRoute(reactRoot, routeState);
|
|
4549
5259
|
}
|
|
4550
|
-
currentPathname = pathname;
|
|
4551
5260
|
await farmClientRuntime.completeHydration(hydrationSession);
|
|
4552
5261
|
} catch (error) {
|
|
4553
5262
|
await farmClientRuntime.failHydration(hydrationSession, error);
|
|
@@ -4555,10 +5264,12 @@ async function hydrate() {
|
|
|
4555
5264
|
}
|
|
4556
5265
|
},
|
|
4557
5266
|
});
|
|
4558
|
-
${isolatedHydrationEnabled ?
|
|
5267
|
+
${isolatedHydrationEnabled ? `// Not cancelled with the page: a navigation disposes the islands it removes, and one in a
|
|
5268
|
+
// layout it keeps still waits for its trigger, as on a page of islands only.
|
|
5269
|
+
const isolatedHydration =
|
|
4559
5270
|
!hasHydratableLayout(pathname) &&
|
|
4560
5271
|
document.querySelector('f-island[src]')
|
|
4561
|
-
? hydrateFarmIsolatedClientBoundaries(document
|
|
5272
|
+
? hydrateFarmIsolatedClientBoundaries(document)
|
|
4562
5273
|
: Promise.resolve();
|
|
4563
5274
|
await Promise.all([pageHydration, isolatedHydration]);` : "await pageHydration;"}
|
|
4564
5275
|
} finally {
|
|
@@ -4568,6 +5279,7 @@ async function hydrate() {
|
|
|
4568
5279
|
}
|
|
4569
5280
|
}
|
|
4570
5281
|
|
|
5282
|
+
/*farm-router-start*/
|
|
4571
5283
|
// A layout boundary is the same layout when its key matches: islands mode keys it by pattern and
|
|
4572
5284
|
// params, so a layout whose params change renders again. Other modes compare patterns.
|
|
4573
5285
|
function getLayoutIdentity(boundary) {
|
|
@@ -4603,14 +5315,11 @@ function fitsSegmentResponse(currentRoot, nextRoot) {
|
|
|
4603
5315
|
return true;
|
|
4604
5316
|
}` : ""}
|
|
4605
5317
|
|
|
5318
|
+
${FARM_NAVIGATION_SCRIPT_SOURCE}
|
|
5319
|
+
|
|
4606
5320
|
function activateNavigationScripts(root) {
|
|
4607
5321
|
for (const script of Array.from(root?.querySelectorAll?.("script") || [])) {
|
|
4608
|
-
|
|
4609
|
-
for (const attribute of Array.from(script.attributes)) {
|
|
4610
|
-
freshScript.setAttribute(attribute.name, attribute.value);
|
|
4611
|
-
}
|
|
4612
|
-
freshScript.textContent = script.textContent || "";
|
|
4613
|
-
script.replaceWith(freshScript);
|
|
5322
|
+
script.replaceWith(createFarmNavigationScript(script));
|
|
4614
5323
|
}
|
|
4615
5324
|
}
|
|
4616
5325
|
|
|
@@ -4663,14 +5372,66 @@ async function streamFarmNavigation(stream, root, isCurrent) {
|
|
|
4663
5372
|
${isolatedHydrationEnabled ? "farmIsolatedHydrationRuntime.endStream?.(root);\n if (!queued) run();" : ""}
|
|
4664
5373
|
}` : ""}
|
|
4665
5374
|
|
|
4666
|
-
|
|
5375
|
+
// Suspense content streams, so a fresh response holds its fallback where the live DOM holds the
|
|
5376
|
+
// result. Compare without it.
|
|
5377
|
+
function removeSuspenseContent(root) {
|
|
5378
|
+
const walker = document.createTreeWalker(root, NodeFilter.SHOW_COMMENT);
|
|
5379
|
+
const comments = [];
|
|
5380
|
+
while (walker.nextNode()) comments.push(walker.currentNode);
|
|
5381
|
+
let depth = 0;
|
|
5382
|
+
let start = null;
|
|
5383
|
+
for (const comment of comments) {
|
|
5384
|
+
if (comment.data === "$" || comment.data === "$?" || comment.data === "$!") {
|
|
5385
|
+
if (depth++ === 0) start = comment;
|
|
5386
|
+
} else if (comment.data === "/$" && depth > 0 && --depth === 0) {
|
|
5387
|
+
const range = document.createRange();
|
|
5388
|
+
range.setStartAfter(start);
|
|
5389
|
+
range.setEndBefore(comment);
|
|
5390
|
+
range.deleteContents();
|
|
5391
|
+
start.data = "$";
|
|
5392
|
+
}
|
|
5393
|
+
}
|
|
5394
|
+
}
|
|
5395
|
+
|
|
5396
|
+
// A layout's own server output, without what it wraps and without its islands' DOM, which live
|
|
5397
|
+
// always differs from fresh HTML. It keeps each island's props, so new props count as a change.
|
|
5398
|
+
function getLayoutShell(root, patterns, index) {
|
|
5399
|
+
const shell = findLayoutBoundary(root, patterns[index])?.cloneNode(true);
|
|
5400
|
+
if (!shell) return null;
|
|
5401
|
+
const inner = index + 1 < patterns.length
|
|
5402
|
+
? findLayoutBoundary(shell, patterns[index + 1])
|
|
5403
|
+
: shell.querySelector("#__farm_page__");
|
|
5404
|
+
inner?.replaceChildren();
|
|
5405
|
+
removeSuspenseContent(shell);
|
|
5406
|
+
shell.querySelectorAll("script").forEach(function(script) {
|
|
5407
|
+
if (script.type !== "f/props") return script.remove();
|
|
5408
|
+
Array.from(script.attributes).forEach(function(attribute) {
|
|
5409
|
+
if (attribute.name !== "type") script.removeAttribute(attribute.name);
|
|
5410
|
+
});
|
|
5411
|
+
});
|
|
5412
|
+
shell.querySelectorAll("f-island").forEach(function(island) {
|
|
5413
|
+
island.replaceChildren();
|
|
5414
|
+
Array.from(island.attributes).forEach(function(attribute) {
|
|
5415
|
+
island.removeAttribute(attribute.name);
|
|
5416
|
+
});
|
|
5417
|
+
});
|
|
5418
|
+
return shell.innerHTML;
|
|
5419
|
+
}
|
|
5420
|
+
|
|
5421
|
+
${islandValues ? FARM_REFRESH_FIELDS_SOURCE : ""}function replaceSharedLayoutBoundary(currentRoot, nextRoot, refresh = false) {
|
|
5422
|
+
// A refresh keeps the islands still on the page: the ones in streamed Suspense content too.
|
|
5423
|
+
if (refresh) revealFarmStreamedContent(nextRoot);
|
|
4667
5424
|
const currentPatterns = getLayoutPatterns(currentRoot);
|
|
4668
5425
|
const nextPatterns = getLayoutPatterns(nextRoot);
|
|
4669
5426
|
let sharedCount = 0;
|
|
4670
5427
|
while (
|
|
4671
5428
|
sharedCount < currentPatterns.length &&
|
|
4672
5429
|
sharedCount < nextPatterns.length &&
|
|
4673
|
-
currentPatterns[sharedCount] === nextPatterns[sharedCount]
|
|
5430
|
+
currentPatterns[sharedCount] === nextPatterns[sharedCount] &&
|
|
5431
|
+
// A refresh renders every layout again: start at the first one whose output changed.
|
|
5432
|
+
(!refresh ||
|
|
5433
|
+
getLayoutShell(currentRoot, currentPatterns, sharedCount) ===
|
|
5434
|
+
getLayoutShell(nextRoot, nextPatterns, sharedCount))
|
|
4674
5435
|
) sharedCount++;
|
|
4675
5436
|
|
|
4676
5437
|
const nextTreeRoot = nextPatterns.length
|
|
@@ -4683,11 +5444,13 @@ function replaceSharedLayoutBoundary(currentRoot, nextRoot, refresh = false) {
|
|
|
4683
5444
|
? findLayoutBoundary(nextRoot, nextPatterns[sharedCount])
|
|
4684
5445
|
: nextRoot.querySelector("#__farm_page__");
|
|
4685
5446
|
|
|
4686
|
-
if (!currentTarget || !nextTarget) return false
|
|
5447
|
+
if (!currentTarget || !nextTarget) return false;${islandValues ? `
|
|
5448
|
+
// A refresh renders the same layouts again: their fields keep what was typed, and the focus.
|
|
5449
|
+
const fields = refresh ? captureFarmServerFields(currentTarget) : null;` : ""}
|
|
4687
5450
|
${isolatedHydrationEnabled ? `${islandValues ? `// A refresh keeps the islands still on the page, with their state and new props.
|
|
4688
5451
|
if (refresh) farmIsolatedHydrationRuntime.carryOver(currentTarget, nextTarget);
|
|
4689
5452
|
` : ""}disposeFarmIsolatedClientBoundaries(currentTarget);` : ""}
|
|
4690
|
-
currentTarget.replaceWith(nextTarget);
|
|
5453
|
+
currentTarget.replaceWith(nextTarget);${islandValues ? "\n if (fields) restoreFarmServerFields(fields, nextTarget);" : ""}
|
|
4691
5454
|
activateNavigationScripts(nextTarget);
|
|
4692
5455
|
if (nextTreeRoot && nextTreeRoot !== nextTarget) nextTreeRoot.remove();
|
|
4693
5456
|
|
|
@@ -4695,7 +5458,17 @@ function replaceSharedLayoutBoundary(currentRoot, nextRoot, refresh = false) {
|
|
|
4695
5458
|
const support = document.createElement("div");
|
|
4696
5459
|
support.hidden = true;
|
|
4697
5460
|
support.dataset.farmFragmentSupport = "true";
|
|
4698
|
-
while (nextRoot.firstChild)
|
|
5461
|
+
while (nextRoot.firstChild) {
|
|
5462
|
+
const node = nextRoot.firstChild;
|
|
5463
|
+
// React's staged Suspense content stays in the root, where a later flush of a streamed
|
|
5464
|
+
// navigation reveals it; React removes it then.
|
|
5465
|
+
if (node.nodeType === 1 && node.matches('div[hidden][id^="S:"]')) {
|
|
5466
|
+
currentRoot.appendChild(node);
|
|
5467
|
+
activateNavigationScripts(node);
|
|
5468
|
+
} else {
|
|
5469
|
+
support.appendChild(node);
|
|
5470
|
+
}
|
|
5471
|
+
}
|
|
4699
5472
|
document.body.appendChild(support);
|
|
4700
5473
|
activateNavigationScripts(support);
|
|
4701
5474
|
setTimeout(function() { support.remove(); }, 0);
|
|
@@ -4819,7 +5592,8 @@ ${islandValues ? ` // Islands mode: navigations name the layouts on screen, and
|
|
|
4819
5592
|
const html = await this.fetchPage(to, from, false, true, navigation.controller.signal);
|
|
4820
5593
|
if (!this.isCurrentNavigation(navigation, clientNavigation)) return;
|
|
4821
5594
|
const doc = new DOMParser().parseFromString(html, "text/html");
|
|
4822
|
-
const slotPayload =
|
|
5595
|
+
const slotPayload = (await readFarmDocumentPayload(doc)).slots;
|
|
5596
|
+
if (!this.isCurrentNavigation(navigation, clientNavigation)) return;
|
|
4823
5597
|
const selectedSlot = slotPayload.find(function(slot) {
|
|
4824
5598
|
return slot.interception &&
|
|
4825
5599
|
slot.name === intercepted.slot.name &&
|
|
@@ -4881,11 +5655,9 @@ ${islandValues ? ` // Islands mode: navigations name the layouts on screen, and
|
|
|
4881
5655
|
if (container) {
|
|
4882
5656
|
if (reactRoot && reactRootContainer !== container) resetReactRoot();
|
|
4883
5657
|
if (!reactRoot) {
|
|
4884
|
-
|
|
4885
|
-
reactRootContainer = container;
|
|
5658
|
+
setFarmReactRoot(createRoot(container), container);
|
|
4886
5659
|
}
|
|
4887
5660
|
renderFarmRoute(reactRoot, routeState);
|
|
4888
|
-
currentPathname = pathname;
|
|
4889
5661
|
}
|
|
4890
5662
|
this.currentPath = to;
|
|
4891
5663
|
});
|
|
@@ -4904,6 +5676,11 @@ ${islandValues ? ` // Islands mode: navigations name the layouts on screen, and
|
|
|
4904
5676
|
if (!this.isCurrentNavigation(navigation, clientNavigation)) return;
|
|
4905
5677
|
await this.runViewTransition(options.viewTransition, async () => {
|
|
4906
5678
|
if (!this.isCurrentNavigation(navigation, clientNavigation)) return;
|
|
5679
|
+
// The history entry comes first, as on the client-render path: swapContent shows the
|
|
5680
|
+
// page and its title, then waits for its islands, and a Back pressed meanwhile must
|
|
5681
|
+
// leave the page on screen, not the one before it. Its islands also hydrate at their URL.
|
|
5682
|
+
this.writeHistoryEntry(action, url.pathname + url.search, options.state, url);
|
|
5683
|
+
this.currentPath = to;
|
|
4907
5684
|
let swappedHtml = html;
|
|
4908
5685
|
let swapped = await this.swapContent(
|
|
4909
5686
|
html,
|
|
@@ -4937,9 +5714,6 @@ ${islandValues ? ` // Islands mode: navigations name the layouts on screen, and
|
|
|
4937
5714
|
throw new Error("Farm could not swap the target document");
|
|
4938
5715
|
}
|
|
4939
5716
|
this.takeNavigationStream(swappedHtml);
|
|
4940
|
-
this.writeHistoryEntry(action, url.pathname + url.search, options.state, url);
|
|
4941
|
-
currentPathname = pathname;
|
|
4942
|
-
this.currentPath = to;
|
|
4943
5717
|
});
|
|
4944
5718
|
}
|
|
4945
5719
|
|
|
@@ -4993,10 +5767,12 @@ ${islandValues ? ` // Islands mode: navigations name the layouts on screen, and
|
|
|
4993
5767
|
const doc = parser.parseFromString(html, "text/html");
|
|
4994
5768
|
if (isFarmLocaleDocumentChange(doc)) return false;
|
|
4995
5769
|
if (doc.getElementById("nd-docs-layout")) return false;
|
|
4996
|
-
const nextRouteSlots = readRouteSlotPayload(doc);
|
|
4997
|
-
const nextPageProps = readPagePropsPayload(doc);
|
|
4998
5770
|
const isNavigationCurrent = () =>
|
|
4999
5771
|
this.isCurrentNavigation(navigation, clientNavigation);
|
|
5772
|
+
const nextPayload = await readFarmDocumentPayload(doc);
|
|
5773
|
+
if (!isNavigationCurrent()) return false;
|
|
5774
|
+
const nextRouteSlots = nextPayload.slots;
|
|
5775
|
+
const nextPageProps = nextPayload.page;
|
|
5000
5776
|
|
|
5001
5777
|
reconcileFarmDocumentHead(doc);
|
|
5002
5778
|
|
|
@@ -5040,7 +5816,7 @@ ${islandValues ? ` // Islands mode: navigations name the layouts on screen, and
|
|
|
5040
5816
|
if (routeState) {
|
|
5041
5817
|
renderFarmRoute(reactRoot, routeState);
|
|
5042
5818
|
window.__FARM_ROUTE_SLOTS__ = nextRouteSlots;
|
|
5043
|
-
|
|
5819
|
+
setFarmHydrated();
|
|
5044
5820
|
return true;
|
|
5045
5821
|
}
|
|
5046
5822
|
}
|
|
@@ -5080,9 +5856,8 @@ ${islandValues ? ` // Islands mode: navigations name the layouts on screen, and
|
|
|
5080
5856
|
);
|
|
5081
5857
|
if (!isNavigationCurrent()) return false;
|
|
5082
5858
|
if (routeState) {
|
|
5083
|
-
|
|
5084
|
-
|
|
5085
|
-
isHydrated = true;
|
|
5859
|
+
setFarmReactRoot(hydrateFarmRoute(pageContainer, routeState), pageContainer);
|
|
5860
|
+
setFarmHydrated();
|
|
5086
5861
|
}
|
|
5087
5862
|
${isolatedHydrationEnabled ? `if (matched.route.hasIsolatedClientBoundaries && !hydrateLayouts) {
|
|
5088
5863
|
await hydrateFarmIsolatedClientBoundaries(
|
|
@@ -5118,12 +5893,7 @@ ${islandValues ? ` // Islands mode: navigations name the layouts on screen, and
|
|
|
5118
5893
|
|
|
5119
5894
|
setTimeout(function() {
|
|
5120
5895
|
Array.from(document.querySelectorAll("script")).forEach(function(script) {
|
|
5121
|
-
|
|
5122
|
-
Array.from(script.attributes).forEach(function(attr) {
|
|
5123
|
-
freshScript.setAttribute(attr.name, attr.value);
|
|
5124
|
-
});
|
|
5125
|
-
freshScript.textContent = script.textContent || "";
|
|
5126
|
-
script.replaceWith(freshScript);
|
|
5896
|
+
script.replaceWith(createFarmNavigationScript(script));
|
|
5127
5897
|
});
|
|
5128
5898
|
}, 0);
|
|
5129
5899
|
|
|
@@ -5166,7 +5936,9 @@ ${islandValues ? ` // Islands mode: navigations name the layouts on screen, and
|
|
|
5166
5936
|
}
|
|
5167
5937
|
};
|
|
5168
5938
|
|
|
5169
|
-
|
|
5939
|
+
/*farm-router-end*/
|
|
5940
|
+
/*farm-router-stub*/
|
|
5941
|
+
const farmClientRuntime = ${clientPluginEntry.empty ? "createPluginlessClientRuntime()" : `createClientPluginManager(
|
|
5170
5942
|
${clientPluginEntry.registrations},
|
|
5171
5943
|
{
|
|
5172
5944
|
router: spaRouter,
|
|
@@ -5174,13 +5946,15 @@ const farmClientRuntime = createClientPluginManager(
|
|
|
5174
5946
|
isProd: true,
|
|
5175
5947
|
deploymentId: window.__FARM_DEPLOYMENT_ID__,
|
|
5176
5948
|
},
|
|
5177
|
-
);
|
|
5949
|
+
)`};
|
|
5178
5950
|
window.__FARM_CLIENT_RUNTIME__ = farmClientRuntime;
|
|
5179
5951
|
void farmClientRuntime.start();
|
|
5180
5952
|
|
|
5181
5953
|
// Expose router globally
|
|
5954
|
+
/*farm-router-start*/
|
|
5182
5955
|
spaRouter.initializeHistory();
|
|
5183
5956
|
window.__FARM_SPA_ROUTER__ = spaRouter;
|
|
5957
|
+
/*farm-router-end*/
|
|
5184
5958
|
|
|
5185
5959
|
window.addEventListener("beforeunload", function(event) {
|
|
5186
5960
|
if (spaRouter.shouldBlockUnload()) {
|
|
@@ -5226,7 +6000,7 @@ void hydrate();
|
|
|
5226
6000
|
async function buildSSRInMemory(productionVite, config, root, routeManager, apiRouteManager, serverRenderer, preset, collectedPageRoutes, collectedLayoutRoutes, collectedRouteSlots, isolatedClientBoundaryModules, hydrationPlanCache, rendererBuildLifetime) {
|
|
5227
6001
|
const viteBuild = productionVite.build;
|
|
5228
6002
|
const { farmPlugin, farmServerOnlyEntriesPlugin } = await import("./vite.mjs");
|
|
5229
|
-
const { PluginManager: PluginManager2 } = await import("./plugin-
|
|
6003
|
+
const { PluginManager: PluginManager2 } = await import("./plugin-SAS22JL7.mjs");
|
|
5230
6004
|
const fs4 = await import("fs/promises");
|
|
5231
6005
|
const pluginManager = new PluginManager2({
|
|
5232
6006
|
config,
|
|
@@ -5242,9 +6016,9 @@ async function buildSSRInMemory(productionVite, config, root, routeManager, apiR
|
|
|
5242
6016
|
buildLifetime: rendererBuildLifetime
|
|
5243
6017
|
});
|
|
5244
6018
|
if (!hasScopedPostcssConfig) {
|
|
5245
|
-
postcssConfigDir = await fs4.mkdtemp(
|
|
6019
|
+
postcssConfigDir = await fs4.mkdtemp(path12.join(os.tmpdir(), "farm-postcss-"));
|
|
5246
6020
|
await fs4.writeFile(
|
|
5247
|
-
|
|
6021
|
+
path12.join(postcssConfigDir, "postcss.config.cjs"),
|
|
5248
6022
|
"module.exports = { plugins: [] };\n"
|
|
5249
6023
|
);
|
|
5250
6024
|
tailwindVitePlugin = await loadTailwindVitePlugin({
|
|
@@ -5329,10 +6103,11 @@ async function buildSSRInMemory(productionVite, config, root, routeManager, apiR
|
|
|
5329
6103
|
const appDirs = getFarmAppDirectories(config);
|
|
5330
6104
|
let openAPIReference = null;
|
|
5331
6105
|
if (config.openapi.enabled && config.openapi.route) {
|
|
5332
|
-
const { OpenAPIManager, renderOpenAPIReferenceHTML } = await import("./manager-
|
|
6106
|
+
const { OpenAPIManager, renderOpenAPIReferenceHTML } = await import("./manager-JIA66YJ2.mjs");
|
|
5333
6107
|
const openAPIManager = new OpenAPIManager(appDirs, config.openapi, {
|
|
5334
6108
|
mode: "production",
|
|
5335
|
-
apiBaseURL: config.api.baseURL
|
|
6109
|
+
apiBaseURL: config.api.baseURL,
|
|
6110
|
+
loadModule: (filePath) => apiRouteManager.loadModule(filePath)
|
|
5336
6111
|
});
|
|
5337
6112
|
const spec = await openAPIManager.generateSpec();
|
|
5338
6113
|
if (!spec) {
|
|
@@ -5345,7 +6120,13 @@ async function buildSSRInMemory(productionVite, config, root, routeManager, apiR
|
|
|
5345
6120
|
specRoute: config.openapi.specRoute || null
|
|
5346
6121
|
};
|
|
5347
6122
|
}
|
|
5348
|
-
const
|
|
6123
|
+
const discoveredMiddlewareRoutes = await discoverMiddlewareRoutes(appDirs);
|
|
6124
|
+
const middlewareRoutes = farmTargetRunsEdgeMiddleware(preset) ? await Promise.all(
|
|
6125
|
+
discoveredMiddlewareRoutes.map(async (route) => ({
|
|
6126
|
+
...route,
|
|
6127
|
+
config: await readMiddlewareFileConfig(route.filePath)
|
|
6128
|
+
}))
|
|
6129
|
+
) : discoveredMiddlewareRoutes;
|
|
5349
6130
|
const instrumentationPath = resolveFarmInstrumentationFile(root, config.srcDir || "src");
|
|
5350
6131
|
const notFoundPath = resolveFarmNotFoundComponentPath(config, appDirs);
|
|
5351
6132
|
if (notFoundPath) logger.info(`\u{1F4CB} Found custom 404 page: ${notFoundPath}`);
|
|
@@ -5371,7 +6152,7 @@ async function buildSSRInMemory(productionVite, config, root, routeManager, apiR
|
|
|
5371
6152
|
const hasMdxComponentConfig = Boolean(config.mdx?.components);
|
|
5372
6153
|
const hasMiddlewareConfig = hasFarmMiddlewareConfig(config.middleware);
|
|
5373
6154
|
const hasRouteContextConfig = hasCustomFarmRouteContext(config);
|
|
5374
|
-
const hasServerRuntimePlugins = hasFarmServerRuntimePlugins(config);
|
|
6155
|
+
const hasServerRuntimePlugins = hasFarmServerRuntimePlugins(config.plugins);
|
|
5375
6156
|
const hasPluginRoutes = hasFarmPluginRoutes(config);
|
|
5376
6157
|
const hasServerCacheConfig = hasFarmServerCacheConfig(config.cache);
|
|
5377
6158
|
const configModulePath = hasServerRuntimeIntegrations || hasObservabilityHandler || hasMdxComponentConfig || hasMiddlewareConfig || hasRouteContextConfig || hasServerRuntimePlugins || hasPluginRoutes || hasServerCacheConfig || hasFarmServerStorageConfig(config.storage) || hasIntegrationProviders ? await findFarmConfigPath(root) : null;
|
|
@@ -5385,7 +6166,8 @@ async function buildSSRInMemory(productionVite, config, root, routeManager, apiR
|
|
|
5385
6166
|
assertFarmDocsAdapterServesNoGuardedPages(
|
|
5386
6167
|
config.docs,
|
|
5387
6168
|
{ root, srcDir: config.srcDir },
|
|
5388
|
-
(pathname) => adapterGuardedPaths.has(pathname)
|
|
6169
|
+
(pathname) => adapterGuardedPaths.has(pathname),
|
|
6170
|
+
getFarmPresetRuntime(preset) === "edge" ? "edge" : "node"
|
|
5389
6171
|
);
|
|
5390
6172
|
}
|
|
5391
6173
|
const farmDocsCspNonceMarker = createFarmCspNonce(config.security);
|
|
@@ -5406,7 +6188,8 @@ async function buildSSRInMemory(productionVite, config, root, routeManager, apiR
|
|
|
5406
6188
|
fontAssets: toFarmDocsPublicFontAssets(resolveFarmDocsFontAssets(root)),
|
|
5407
6189
|
fontStylesheetHref: "/farm-fonts.css",
|
|
5408
6190
|
globalStylesheetHref: FARM_CLIENT_CSS_HREF_PLACEHOLDER,
|
|
5409
|
-
isPathGuarded: (pathname) => guardedPaths.has(pathname)
|
|
6191
|
+
isPathGuarded: (pathname) => guardedPaths.has(pathname),
|
|
6192
|
+
basePath: config.basePath
|
|
5410
6193
|
});
|
|
5411
6194
|
})()
|
|
5412
6195
|
) : null;
|
|
@@ -5443,6 +6226,7 @@ async function buildSSRInMemory(productionVite, config, root, routeManager, apiR
|
|
|
5443
6226
|
);
|
|
5444
6227
|
const virtualEntryId = "\0virtual:farm-ssr-entry";
|
|
5445
6228
|
const useExternalMetadataImageRuntime = shouldUseExternalMetadataImageRuntime(preset, true);
|
|
6229
|
+
const edgeMetadataImageRuntime = getEdgeMetadataImageRuntime(preset);
|
|
5446
6230
|
const omitCoreMetadataImageRuntime = !metadataImageRoutes.some(
|
|
5447
6231
|
(image) => image.sourceType === "module"
|
|
5448
6232
|
);
|
|
@@ -5558,13 +6342,22 @@ async function buildSSRInMemory(productionVite, config, root, routeManager, apiR
|
|
|
5558
6342
|
...tailwindVitePlugin ? [tailwindVitePlugin] : [],
|
|
5559
6343
|
...rendererVitePlugins,
|
|
5560
6344
|
...config.vite.plugins || [],
|
|
5561
|
-
|
|
6345
|
+
// On an edge preset any server module may import @vercel/og.
|
|
6346
|
+
...(edgeMetadataImageRuntime ? edgeMetadataImageRuntime.wasm === "bytes" : !useExternalMetadataImageRuntime && metadataImageRoutes.some((image) => image.sourceType === "module")) ? [{ ...createMetadataImageWasmPlugin(), enforce: "pre" }] : [],
|
|
5562
6347
|
...omitCoreMetadataImageRuntime ? [
|
|
5563
6348
|
{
|
|
5564
6349
|
...createOmittedMetadataImageRuntimePlugin(useExternalMetadataImageRuntime),
|
|
5565
6350
|
enforce: "pre"
|
|
5566
6351
|
}
|
|
5567
6352
|
] : [],
|
|
6353
|
+
// After the stub above, which must take core's own import first.
|
|
6354
|
+
...edgeMetadataImageRuntime ? [
|
|
6355
|
+
{
|
|
6356
|
+
...createEdgeMetadataImageRuntimePlugin(edgeMetadataImageRuntime),
|
|
6357
|
+
enforce: "pre"
|
|
6358
|
+
},
|
|
6359
|
+
createVercelOgFontInlinePlugin(edgeMetadataImageRuntime.runtime)
|
|
6360
|
+
] : [],
|
|
5568
6361
|
{ ...createReactProductionModePlugin(), enforce: "pre" },
|
|
5569
6362
|
farmServerOnlyEntriesPlugin(),
|
|
5570
6363
|
farmPlugin({ ...config, isolatedClientBoundaryModules }, pluginManager),
|
|
@@ -5579,17 +6372,23 @@ async function buildSSRInMemory(productionVite, config, root, routeManager, apiR
|
|
|
5579
6372
|
] : [],
|
|
5580
6373
|
{
|
|
5581
6374
|
name: "farm-virtual-ssr-entry",
|
|
5582
|
-
resolveId
|
|
5583
|
-
|
|
5584
|
-
|
|
6375
|
+
resolveId: {
|
|
6376
|
+
filter: { id: exactIdPattern([virtualEntryId, "\0virtual:farm-ssr-entry"]) },
|
|
6377
|
+
handler(id) {
|
|
6378
|
+
if (id === virtualEntryId || id === "\0virtual:farm-ssr-entry") {
|
|
6379
|
+
return virtualEntryId;
|
|
6380
|
+
}
|
|
6381
|
+
return null;
|
|
5585
6382
|
}
|
|
5586
|
-
return null;
|
|
5587
6383
|
},
|
|
5588
|
-
load
|
|
5589
|
-
|
|
5590
|
-
|
|
6384
|
+
load: {
|
|
6385
|
+
filter: { id: exactIdPattern([virtualEntryId]) },
|
|
6386
|
+
handler(id) {
|
|
6387
|
+
if (id === virtualEntryId) {
|
|
6388
|
+
return virtualEntryCode;
|
|
6389
|
+
}
|
|
6390
|
+
return null;
|
|
5591
6391
|
}
|
|
5592
|
-
return null;
|
|
5593
6392
|
}
|
|
5594
6393
|
},
|
|
5595
6394
|
{
|
|
@@ -5640,7 +6439,7 @@ async function buildSSRInMemory(productionVite, config, root, routeManager, apiR
|
|
|
5640
6439
|
}
|
|
5641
6440
|
function readFarmAppPackageIdentity(root) {
|
|
5642
6441
|
try {
|
|
5643
|
-
return JSON.parse(readFileSync(
|
|
6442
|
+
return JSON.parse(readFileSync(path12.join(root, "package.json"), "utf8"));
|
|
5644
6443
|
} catch {
|
|
5645
6444
|
return {};
|
|
5646
6445
|
}
|
|
@@ -5775,17 +6574,33 @@ function matchLocalIntegrationRequest(request) {
|
|
|
5775
6574
|
});` : "return null;"}
|
|
5776
6575
|
}
|
|
5777
6576
|
|
|
5778
|
-
async function handleIntegrationRequest(request, ranMiddleware, clientAddress) {
|
|
5779
|
-
${options.hasServerRuntimeIntegrations ? `
|
|
5780
|
-
|
|
5781
|
-
|
|
5782
|
-
|
|
5783
|
-
|
|
5784
|
-
|
|
5785
|
-
|
|
5786
|
-
|
|
5787
|
-
|
|
5788
|
-
|
|
6577
|
+
async function handleIntegrationRequest(request, ranMiddleware, clientAddress, reportRuntimeError) {
|
|
6578
|
+
${options.hasServerRuntimeIntegrations ? `try {
|
|
6579
|
+
return await dispatchIntegrationRequests(
|
|
6580
|
+
serverRuntimeIntegrations,
|
|
6581
|
+
{
|
|
6582
|
+
config: integrationRuntimeConfig,
|
|
6583
|
+
isDev: false,
|
|
6584
|
+
isProd: true,
|
|
6585
|
+
},
|
|
6586
|
+
request,
|
|
6587
|
+
{ ranMiddleware, clientAddress },
|
|
6588
|
+
);
|
|
6589
|
+
} catch (error) {
|
|
6590
|
+
// Integration middleware on any other request keeps failing that request.
|
|
6591
|
+
if (!matchLocalIntegrationRequest(request)) throw error;
|
|
6592
|
+
// A throwing integration route answers 500, as an API route does: a plugin's
|
|
6593
|
+
// runtime.error observes the throw, and runtime.after still sees this 500.
|
|
6594
|
+
console.error("[Integration Error] " + new URL(request.url).pathname + ":", error);
|
|
6595
|
+
await reportRuntimeError?.(error);
|
|
6596
|
+
return {
|
|
6597
|
+
response: new Response(JSON.stringify({ error: "Internal Server Error" }), {
|
|
6598
|
+
status: 500,
|
|
6599
|
+
headers: { "Content-Type": "application/json" },
|
|
6600
|
+
}),
|
|
6601
|
+
setCookies: [],
|
|
6602
|
+
};
|
|
6603
|
+
}` : `return { response: null, setCookies: [] };`}
|
|
5789
6604
|
}
|
|
5790
6605
|
|
|
5791
6606
|
// Merge Set-Cookie values forwarded by a passthrough integration middleware
|
|
@@ -6046,6 +6861,7 @@ if (typeof ReactDOMServer.configureApp !== "function") {
|
|
|
6046
6861
|
ReactDOMServer.configureApp(__farmAppSetup);`;
|
|
6047
6862
|
}
|
|
6048
6863
|
function generateVirtualEntryCode(apiRoutes, pageRoutes, layoutRoutes, routeSlots, errorRoutes, metadataImageRoutes, applicationMetadataRoutes, middlewareRoutes, redirectRoutes, configuredRewriteRoutes, configuredHeaderRoutes, openAPIReference, notFoundPath, instrumentationPath, config, farmDocsPrecompiledManifest, configModulePath, hasServerRuntimeIntegrations, hasRuntimeIntegrationConfig, hasConfiguredRuntimePlugins, hasServerRuntimePlugins, preset, i18nCatalogs, isolatedClientBoundaryModules, hydrationPlanCache, mobileShellLoadingRoutes = []) {
|
|
6864
|
+
const farmRendererDisabled = isFarmRendererDisabled(config.renderer);
|
|
6049
6865
|
const farmIslandsMode = resolveFarmServerComponentsMode(config.experimental?.serverComponents) === "islands";
|
|
6050
6866
|
const farmClientBoot = canBootFarmIslandsClient(config);
|
|
6051
6867
|
const farmMobileClient = shouldBuildFarmMobileClient(config);
|
|
@@ -6114,6 +6930,7 @@ function renderFarmServerTreeLayout(Layout, props, outlets) {
|
|
|
6114
6930
|
const hasGeneratedMetadataImages = metadataImageRoutes.some(
|
|
6115
6931
|
(image) => image.sourceType === "module"
|
|
6116
6932
|
);
|
|
6933
|
+
const edgeMiddlewareFilePaths = farmTargetRunsEdgeMiddleware(preset) ? middlewareRoutes.filter(isFarmEdgeMiddlewareRoute).map((route) => route.filePath) : [];
|
|
6117
6934
|
const hasMiddlewareRuntime = middlewareRoutes.length > 0 || hasFarmMiddlewareConfig(config.middleware);
|
|
6118
6935
|
const farmDocsFontAssets = config.docs?.enabled ? toFarmDocsPublicFontAssets(resolveFarmDocsFontAssets(config.root)) : [];
|
|
6119
6936
|
const integrationProviders = getIntegrationProviders(config.integrations);
|
|
@@ -6327,6 +7144,7 @@ function renderFarmServerTreeLayout(Layout, props, outlets) {
|
|
|
6327
7144
|
containerId: ${JSON.stringify(slot.containerId)},
|
|
6328
7145
|
interception: ${JSON.stringify(slot.interception)},
|
|
6329
7146
|
fallback: ${JSON.stringify(slot.fallback)},
|
|
7147
|
+
hydrates: ${!farmIslandsMode || getClientModuleMetadata(slot.modulePath, config.root).isClientComponent},
|
|
6330
7148
|
module: ${varName},
|
|
6331
7149
|
}`);
|
|
6332
7150
|
});
|
|
@@ -6432,6 +7250,9 @@ function renderFarmServerTreeLayout(Layout, props, outlets) {
|
|
|
6432
7250
|
applyFarmCspNonceToResponse,
|
|
6433
7251
|
createFarmCspNonce,
|
|
6434
7252
|
stampFarmCspNonce,
|
|
7253
|
+
isDeferred,
|
|
7254
|
+
prepareDeferredData,
|
|
7255
|
+
snapshotDeferredData,
|
|
6435
7256
|
applyFarmPreviewRobotsTag,
|
|
6436
7257
|
applyFarmThemeDocument,
|
|
6437
7258
|
appendFarmLinkHeader,
|
|
@@ -6454,12 +7275,16 @@ function renderFarmServerTreeLayout(Layout, props, outlets) {
|
|
|
6454
7275
|
createFarmApiCatalogResponse,
|
|
6455
7276
|
createFarmAppManifestResponse,
|
|
6456
7277
|
farmPathGuardCoversEndpoint,
|
|
7278
|
+
farmPathGuardCoversPage,
|
|
6457
7279
|
collectFarmLlmsTxtPages,
|
|
6458
7280
|
createFarmDefaultLlmsTxt,
|
|
6459
7281
|
createFarmLlmsMarkdownReader,
|
|
7282
|
+
isFarmPageNoIndex,
|
|
6460
7283
|
listFarmMCPLlmsTxtLinks,
|
|
7284
|
+
readFarmLlmsMarkdownFrom,
|
|
6461
7285
|
registerFarmMCPServer,
|
|
6462
7286
|
renderFarmLlmsFullTxt,
|
|
7287
|
+
resolveFarmAgentOrigin,
|
|
6463
7288
|
createFarmLlmsFullRenderer,
|
|
6464
7289
|
createFarmThemeDocumentParts,
|
|
6465
7290
|
createFarmLocaleCookie,
|
|
@@ -6561,13 +7386,15 @@ function resolveFarmMobileShellRender(request, route, routePathname) {
|
|
|
6561
7386
|
}
|
|
6562
7387
|
return loading.route.module.default;
|
|
6563
7388
|
}` : ""}${farmIslandsMode ? `
|
|
6564
|
-
import { getSharedLayoutPrefixLength, handleFarmFormActionRequest, ignoreFarmHeldValues, installFarmIslandValues, parseFarmLayoutChainHeader } from "@farm.js/core/internal/production-runtime";
|
|
7389
|
+
import { getFarmFormState as farmFormState, getSharedLayoutPrefixLength, handleFarmFormActionRequest, ignoreFarmHeldValues, installFarmIslandValues, parseFarmLayoutChainHeader, renderFarmFormStateScript as farmFormStateScript } from "@farm.js/core/internal/production-runtime";
|
|
6565
7390
|
import { installFarmIslandsServer } from "@farm.js/core/internal/islands-server";
|
|
6566
7391
|
installFarmIslandsServer();
|
|
6567
7392
|
const farmFormActionsConfig = ${JSON.stringify(resolveServerActionsConfig(config.serverActions))};
|
|
6568
7393
|
installFarmIslandValues();
|
|
6569
7394
|
${islandsActionKeyCode()}
|
|
6570
|
-
${FARM_SEGMENT_NAVIGATION_SERVER_RUNTIME}` :
|
|
7395
|
+
${FARM_SEGMENT_NAVIGATION_SERVER_RUNTIME}` : `
|
|
7396
|
+
function farmFormState() { return undefined; }
|
|
7397
|
+
function farmFormStateScript() { return ""; }`}`;
|
|
6571
7398
|
const productionSiteTelemetryImport = config.telemetry ? `import { createFarmProductionSiteReporter } from "@farm.js/core/internal/product-telemetry-runtime";` : "";
|
|
6572
7399
|
const metadataImageRuntimeImport = hasGeneratedMetadataImages ? `import { createFarmMetadataImageResponse } from "@farm.js/core/internal/metadata-image-runtime";` : "";
|
|
6573
7400
|
const pluginRuntimeImport = hasPluginRuntime ? `import { PluginManager } from "@farm.js/core/plugin";` : "";
|
|
@@ -6592,7 +7419,7 @@ import { fileURLToPath as farmDocsFileURLToPath } from "node:url";` : "";
|
|
|
6592
7419
|
const markdownHandlerImport = config.md?.enabled ? `import { applyMarkdownNegotiationHeaders, createMarkdownMirrorResponse, getFarmMarkdownAlternatePath } from "@farm.js/core/markdown";` : "";
|
|
6593
7420
|
const appMarkdownImport = hasMarkdownPages ? `import { FARM_MARKDOWN_ANONYMOUS_CLIENT_ADDRESS, createFarmMarkdownRouteModule, createFarmMarkdownSourceResponse, isFarmMarkdownPublicSourceResponse } from "@farm.js/core/internal/app-markdown-runtime";` : "const createFarmMarkdownSourceResponse = null;\nconst isFarmMarkdownPublicSourceResponse = null;";
|
|
6594
7421
|
const markdownErrorImport = `import { FARM_MARKDOWN_CONTENT_TYPE, FARM_MARKDOWN_PAGE_CHECK_HEADER, _isFarmMarkdownPageCheck, createFarmMarkdownErrorBody, farmRequestWantsMarkdown } from "@farm.js/core/markdown";`;
|
|
6595
|
-
const mdxComponentsPath = typeof config.mdx?.components === "string" ?
|
|
7422
|
+
const mdxComponentsPath = typeof config.mdx?.components === "string" ? path12.isAbsolute(config.mdx.components) ? config.mdx.components : path12.join(config.root, config.mdx.components) : null;
|
|
6596
7423
|
const mdxComponentsImport = mdxComponentsPath ? `import * as FarmMdxComponentsModule from ${toVirtualEntryImportSpecifier(mdxComponentsPath)};` : "";
|
|
6597
7424
|
const layerConfigPaths = (config.layers || []).map((layer) => layer.configFile).filter((configFile) => Boolean(configFile)).filter((configFile) => configFile !== configModulePath);
|
|
6598
7425
|
const layerConfigImports = layerConfigPaths.map(
|
|
@@ -6644,7 +7471,7 @@ function matchLocalAPIRequest(request) {
|
|
|
6644
7471
|
return matchBuiltAPIRoute(new URL(request.url).pathname);
|
|
6645
7472
|
}
|
|
6646
7473
|
|
|
6647
|
-
async function handleAPIRequest(request) {
|
|
7474
|
+
async function handleAPIRequest(request, reportRuntimeError) {
|
|
6648
7475
|
const url = new URL(request.url);
|
|
6649
7476
|
const method = request.method.toUpperCase();
|
|
6650
7477
|
const match = matchLocalAPIRequest(request);
|
|
@@ -6711,6 +7538,8 @@ async function handleAPIRequest(request) {
|
|
|
6711
7538
|
error,
|
|
6712
7539
|
});
|
|
6713
7540
|
console.error(\`[API Error] \${url.pathname}:\`, error);
|
|
7541
|
+
// A plugin's runtime.error observes the throw; runtime.after still sees this 500.
|
|
7542
|
+
await reportRuntimeError?.(error);
|
|
6714
7543
|
return new Response(
|
|
6715
7544
|
JSON.stringify({ error: "Internal Server Error" }),
|
|
6716
7545
|
{ status: 500, headers: { "Content-Type": "application/json" } }
|
|
@@ -7050,6 +7879,7 @@ globalThis.__FARM_DOCS_RUNTIME_CONFIG__ = {
|
|
|
7050
7879
|
srcDir: ${JSON.stringify(config.srcDir)},
|
|
7051
7880
|
docs: farmDocsResolvedConfig,
|
|
7052
7881
|
guardedPaths: farmDocsGuardedPaths,
|
|
7882
|
+
basePath: ${JSON.stringify(config.basePath)},
|
|
7053
7883
|
};
|
|
7054
7884
|
const farmDocsPrecompiledRuntime = ${hasPrecompiledDocs ? `createFarmDocsPrecompiledRuntime(${JSON.stringify(farmDocsPrecompiledManifest)})` : "null"};
|
|
7055
7885
|
// Filled in from the client build once it has finished (see buildNitroUniversal).
|
|
@@ -7092,6 +7922,19 @@ const farmDocsHandler = ${config.docs?.enabled ? hasPrecompiledDocs ? "farmDocsP
|
|
|
7092
7922
|
loadReactModule: async () => FarmDocsAdapterReact,
|
|
7093
7923
|
// Lists the docs MCP endpoint in /.well-known/ai-catalog.json for the server's lifetime.
|
|
7094
7924
|
registerMCPServer: registerFarmMCPServer,
|
|
7925
|
+
// A page built with this keeps its HTML string, so the preload budget and the response
|
|
7926
|
+
// writer use it instead of reading and re-encoding the body. Older adapters ignore it.
|
|
7927
|
+
createHtmlResponse: farmOwnedHtmlResponse,${farmDocsAdapterServesGuardedPages(config.docs) ? `
|
|
7928
|
+
// The adapter keeps pages a path guard covers off search, llms.txt, the sitemap and MCP. It
|
|
7929
|
+
// asks about any path its own content lists, so the guards decide here, not a page list.
|
|
7930
|
+
isPathGuarded: (pathname) =>
|
|
7931
|
+
farmPathGuardCoversPage(
|
|
7932
|
+
{
|
|
7933
|
+
config: { middleware: farmMiddlewareConfig, integrations: serverRuntimeIntegrations },
|
|
7934
|
+
middlewareRoutes: fileMiddlewareModules,
|
|
7935
|
+
},
|
|
7936
|
+
pathname,
|
|
7937
|
+
),` : ""}
|
|
7095
7938
|
})` : `createFarmDocsHandler(farmDocsResolvedConfig, {
|
|
7096
7939
|
root: farmDocsRuntimeRoot,
|
|
7097
7940
|
srcDir: ${JSON.stringify(config.srcDir)},
|
|
@@ -7105,12 +7948,13 @@ const farmDocsHandler = ${config.docs?.enabled ? hasPrecompiledDocs ? "farmDocsP
|
|
|
7105
7948
|
// The client stylesheet carries globals.css under a content-hashed name.
|
|
7106
7949
|
globalStylesheetHref: ${JSON.stringify(FARM_CLIENT_CSS_HREF_PLACEHOLDER)},
|
|
7107
7950
|
isPathGuarded: isFarmDocsPathGuarded,
|
|
7951
|
+
basePath: ${JSON.stringify(config.basePath)},
|
|
7108
7952
|
})` : "null"};
|
|
7109
|
-
const farmDocsAPIHandler = ${config.docs?.enabled ? hasPrecompiledDocs ? "farmDocsPrecompiledRuntime.handleAPIRequest" : adapterOwnsDocsRuntime ? "null" : `createFarmDocsAPIHandler({ rootDir: farmDocsRuntimeRoot, srcDir: ${JSON.stringify(config.srcDir)}, docs: farmDocsResolvedConfig, isPathGuarded: isFarmDocsPathGuarded })` : "null"};
|
|
7953
|
+
const farmDocsAPIHandler = ${config.docs?.enabled ? hasPrecompiledDocs ? "farmDocsPrecompiledRuntime.handleAPIRequest" : adapterOwnsDocsRuntime ? "null" : `createFarmDocsAPIHandler({ rootDir: farmDocsRuntimeRoot, srcDir: ${JSON.stringify(config.srcDir)}, docs: farmDocsResolvedConfig, isPathGuarded: isFarmDocsPathGuarded, basePath: ${JSON.stringify(config.basePath)} })` : "null"};
|
|
7110
7954
|
|
|
7111
7955
|
// API routes bundled at build time
|
|
7112
7956
|
const apiRoutes = ${apiRoutes.length > 0 ? "mergePluginAPIRoutes(" : ""}[${apiRegistrations.join(",")}
|
|
7113
|
-
]${apiRoutes.length > 0 ? `, configuredPlugins, ${JSON.stringify(apiRoutes.map(({ path:
|
|
7957
|
+
]${apiRoutes.length > 0 ? `, configuredPlugins, ${JSON.stringify(apiRoutes.map(({ path: path14, methods }) => ({ path: path14, methods })))}, { bodySizeLimit: ${JSON.stringify(config.server.bodySizeLimit)}, dispatch: dispatchFarmPluginAPIRequest })` : ""};
|
|
7114
7958
|
// A plugin calling an app endpoint (an MCP tool, say) goes through the whole
|
|
7115
7959
|
// pipeline, so the endpoint's middleware and integration guards run for it.
|
|
7116
7960
|
function dispatchFarmPluginAPIRequest(request) {
|
|
@@ -7130,6 +7974,9 @@ function fetchFarmInnerRequest(request, context) {
|
|
|
7130
7974
|
return fetch(new Request(request, { headers }), context);
|
|
7131
7975
|
}
|
|
7132
7976
|
const farmLocalAPIBasePath = ${JSON.stringify(resolveFarmAPIServerBasePath(config.api))};
|
|
7977
|
+
// Reports a failure Farm answers itself (an API or integration route's 500) to the plugin
|
|
7978
|
+
// runtime request.
|
|
7979
|
+
const farmRuntimeErrorSlot = Symbol("farm.runtime.error.slot");
|
|
7133
7980
|
const farmOpenAPIReference = ${JSON.stringify(openAPIReference)};
|
|
7134
7981
|
${config.agent?.apiCatalog ? `const farmApiCatalogInput = ${JSON.stringify(resolveFarmApiCatalogInput(config))};
|
|
7135
7982
|
` : ""}${config.agent?.manifest !== false ? `const farmAppManifestInput = ${JSON.stringify(
|
|
@@ -7249,7 +8096,18 @@ function renderFarmClientBootstrapScript(canonicalPath, selectedRouteSlots, page
|
|
|
7249
8096
|
}
|
|
7250
8097
|
return '<script id="__farm_route_slots_data__" type="application/json">' +
|
|
7251
8098
|
serializedRouteSlots +
|
|
7252
|
-
'</script>' + stampFarmCspNonce('<script>' + source + '</script>');
|
|
8099
|
+
'</script>' + stampFarmCspNonce('<script>' + source + '</script>') + farmFormStateScript();
|
|
8100
|
+
}
|
|
8101
|
+
|
|
8102
|
+
// The settled defer() values the bootstrap script's props refer to, as development writes them.
|
|
8103
|
+
// It runs once the document has rendered: React has awaited every value a component read.
|
|
8104
|
+
function renderFarmDeferredDataScript(records) {
|
|
8105
|
+
if (!records || records.length === 0) return "";
|
|
8106
|
+
return stampFarmCspNonce(
|
|
8107
|
+
'<script>window.__FARM_DEFERRED_DATA__=' +
|
|
8108
|
+
serializeFarmInlineValue(snapshotDeferredData(records)) +
|
|
8109
|
+
';</script>'
|
|
8110
|
+
);
|
|
7253
8111
|
}
|
|
7254
8112
|
|
|
7255
8113
|
function renderFarmRendererHydrationScript() {
|
|
@@ -7313,6 +8171,27 @@ function createFarmFlushToken() {
|
|
|
7313
8171
|
return token;
|
|
7314
8172
|
}
|
|
7315
8173
|
|
|
8174
|
+
async function farmKeptLayoutsRender(ReactDOMServer, layouts, keptCount, params) {
|
|
8175
|
+
let element = null;
|
|
8176
|
+
for (let index = keptCount - 1; index >= 0; index--) {
|
|
8177
|
+
const Layout = layouts[index].module.default;
|
|
8178
|
+
if (Layout) element = React.createElement(Layout, { children: element, params });
|
|
8179
|
+
}
|
|
8180
|
+
try {
|
|
8181
|
+
const rendered = await renderFarmElement(
|
|
8182
|
+
ReactDOMServer,
|
|
8183
|
+
wrapWithFarmIntegrationProviders(element),
|
|
8184
|
+
);
|
|
8185
|
+
if (rendered.stream) {
|
|
8186
|
+
const reader = rendered.stream.getReader();
|
|
8187
|
+
while (!(await reader.read()).done);
|
|
8188
|
+
}
|
|
8189
|
+
return rendered.streamErrors.length === 0;
|
|
8190
|
+
} catch {
|
|
8191
|
+
return false;
|
|
8192
|
+
}
|
|
8193
|
+
}
|
|
8194
|
+
|
|
7316
8195
|
async function renderFarmElement(ReactDOMServer, element, routeKey, flushToken = "") {
|
|
7317
8196
|
// Written after each React flush in a streamed navigation (flushToken): the browser swaps in
|
|
7318
8197
|
// the shell, then adds each Suspense boundary as soon as the flush that completed it ends.
|
|
@@ -7358,6 +8237,7 @@ async function renderFarmElement(ReactDOMServer, element, routeKey, flushToken =
|
|
|
7358
8237
|
typeof ReactDOMServer.renderToReadableStream === "function") {
|
|
7359
8238
|
const stream = await ReactDOMServer.renderToReadableStream(element, {
|
|
7360
8239
|
nonce: _resolveCurrentCspNonce(),
|
|
8240
|
+
formState: farmFormState(),
|
|
7361
8241
|
onError(error) {
|
|
7362
8242
|
// redirect()/notFound() are control flow, not render failures: the
|
|
7363
8243
|
// request handler must still receive them to map the response status,
|
|
@@ -7520,6 +8400,7 @@ async function renderFarmElement(ReactDOMServer, element, routeKey, flushToken =
|
|
|
7520
8400
|
};
|
|
7521
8401
|
pipeableStream = ReactDOMServer.renderToPipeableStream(element, {
|
|
7522
8402
|
nonce: _resolveCurrentCspNonce(),
|
|
8403
|
+
formState: farmFormState(),
|
|
7523
8404
|
onShellReady() {
|
|
7524
8405
|
try {
|
|
7525
8406
|
pipeableStream.pipe(destination);
|
|
@@ -7635,6 +8516,12 @@ function rememberFarmSyncRender(routeKey, streamedHtml) {
|
|
|
7635
8516
|
|
|
7636
8517
|
function renderFarmElementSync(ReactDOMServer, element, routeKey) {
|
|
7637
8518
|
if (!farmReactSyncRender) return undefined;
|
|
8519
|
+
// renderToString takes no form state: the page a useActionState form posted to streams.
|
|
8520
|
+
if (farmFormState() !== undefined) return undefined;
|
|
8521
|
+
// renderToString takes no nonce, so the scripts React adds itself (the form replay script of a
|
|
8522
|
+
// form with a function action) would go out without one, and a nonce policy blocks them. A
|
|
8523
|
+
// response with a nonce renders with the stream, which gives them the nonce.
|
|
8524
|
+
if (_resolveCurrentCspNonce()) return undefined;
|
|
7638
8525
|
const addsDoctype = routeKey === undefined ? undefined : farmSyncRenderRoutes.get(routeKey);
|
|
7639
8526
|
if (addsDoctype === undefined) return undefined;
|
|
7640
8527
|
if (typeof ReactDOMServer.renderToString !== "function") return undefined;
|
|
@@ -8048,12 +8935,8 @@ function withFarmDocsRequestCache(response, request, farmLocaleResolution, middl
|
|
|
8048
8935
|
) {
|
|
8049
8936
|
return response;
|
|
8050
8937
|
}
|
|
8051
|
-
|
|
8052
|
-
|
|
8053
|
-
return farmOwnedResponse(response.body, {
|
|
8054
|
-
status: response.status,
|
|
8055
|
-
statusText: response.statusText,
|
|
8056
|
-
headers,
|
|
8938
|
+
return farmPreloadHeadersResponse(response, (headers) => {
|
|
8939
|
+
headers.set("Cache-Control", "private, no-store");
|
|
8057
8940
|
});
|
|
8058
8941
|
}
|
|
8059
8942
|
|
|
@@ -8291,7 +9174,8 @@ function createFarmAgentRobotsResponse(request) {
|
|
|
8291
9174
|
// Static pages a path-specific guard covers (non-root middleware.ts, a config or
|
|
8292
9175
|
// integration middleware matcher naming the path), decided at build time.
|
|
8293
9176
|
// sitemap.xml, llms.txt and the default MCP server never list them, nor a page behind
|
|
8294
|
-
// a route guard
|
|
9177
|
+
// a route guard, nor one that renders noindex through its own robots or, without one,
|
|
9178
|
+
// its nearest layout's.
|
|
8295
9179
|
const farmAgentGuardedPages = new Set(${JSON.stringify(
|
|
8296
9180
|
pageRoutes.map((route) => route.pattern).filter(
|
|
8297
9181
|
(pattern) => !pattern.includes("[") && farmPathGuardCoversPage(
|
|
@@ -8306,7 +9190,15 @@ const farmAgentGuardedPages = new Set(${JSON.stringify(
|
|
|
8306
9190
|
function getFarmAgentListedPageRoutes() {
|
|
8307
9191
|
return pageRoutes.filter(
|
|
8308
9192
|
(route) =>
|
|
8309
|
-
!
|
|
9193
|
+
!route.pattern.includes("[") &&
|
|
9194
|
+
!farmAgentGuardedPages.has(route.pattern) &&
|
|
9195
|
+
!(route.module && route.module.__farmRouteGuard) &&
|
|
9196
|
+
!isFarmPageNoIndex(
|
|
9197
|
+
route.module && route.module.metadata,
|
|
9198
|
+
getApplicableLayouts(route.pattern, route.directory || route.pattern).map(
|
|
9199
|
+
(layout) => layout.module && layout.module.metadata,
|
|
9200
|
+
),
|
|
9201
|
+
),
|
|
8310
9202
|
);
|
|
8311
9203
|
}
|
|
8312
9204
|
${servesAgentSitemap ? `// sitemap.xml from agent.sitemap, built the same way as in development. Each page's
|
|
@@ -8373,9 +9265,21 @@ async function handleFarmDefaultMCP(request) {
|
|
|
8373
9265
|
// gets its own request context, as for a direct request.
|
|
8374
9266
|
const farmDefaultMCPReadMarkdown = createFarmLlmsMarkdownReader((page) => fetch(page));
|
|
8375
9267
|
` : ""}
|
|
9268
|
+
// The origin llms.txt and llms-full.txt link to: the root layout's metadataBase, else the
|
|
9269
|
+
// request's origin, as for the sitemap and in development.
|
|
9270
|
+
function getFarmAgentOrigin(request) {
|
|
9271
|
+
const rootLayout = layoutRoutes.find((layout) => layout.pattern === "/");
|
|
9272
|
+
return resolveFarmAgentOrigin(
|
|
9273
|
+
rootLayout && rootLayout.module && rootLayout.module.metadata
|
|
9274
|
+
? rootLayout.module.metadata.metadataBase
|
|
9275
|
+
: undefined,
|
|
9276
|
+
new URL(request.url).origin,
|
|
9277
|
+
);
|
|
9278
|
+
}
|
|
9279
|
+
|
|
8376
9280
|
// Static pages and root metadata for llms.txt, built the same way as in development.
|
|
8377
9281
|
function createFarmLlmsTxtContext(request, full) {
|
|
8378
|
-
const origin =
|
|
9282
|
+
const origin = getFarmAgentOrigin(request);
|
|
8379
9283
|
const pages = collectFarmLlmsTxtPages(
|
|
8380
9284
|
getFarmAgentListedPageRoutes().map((route) => ({ pattern: route.pattern, metadata: route.module && route.module.metadata })),
|
|
8381
9285
|
{
|
|
@@ -8406,7 +9310,11 @@ function createFarmLlmsTxtContext(request, full) {
|
|
|
8406
9310
|
? {
|
|
8407
9311
|
markdown: request.method.toUpperCase() === "HEAD"
|
|
8408
9312
|
? async () => null
|
|
8409
|
-
:
|
|
9313
|
+
: readFarmLlmsMarkdownFrom(
|
|
9314
|
+
new URL(request.url).origin,
|
|
9315
|
+
origin,
|
|
9316
|
+
createFarmLlmsMarkdownReader((page) => fetch(page)),
|
|
9317
|
+
),
|
|
8410
9318
|
}
|
|
8411
9319
|
: {}),
|
|
8412
9320
|
};
|
|
@@ -8441,7 +9349,7 @@ async function handleApplicationMetadataRouteRequest(request, routePathname) {
|
|
|
8441
9349
|
})
|
|
8442
9350
|
: routeModule.default;
|
|
8443
9351
|
const body = isLlmsFull && !(value instanceof Response)
|
|
8444
|
-
? await renderFarmLlmsFullTxt(value, { origin:
|
|
9352
|
+
? await renderFarmLlmsFullTxt(value, { origin: getFarmAgentOrigin(request), readMarkdown: llmsContext.markdown })
|
|
8445
9353
|
: value;
|
|
8446
9354
|
return createFarmMetadataRouteResponse(match.metadata.kind, body, routeModule, { method, request });
|
|
8447
9355
|
} catch (error) {
|
|
@@ -8460,10 +9368,12 @@ function matchRedirectRoute(pathname, locale, search) {
|
|
|
8460
9368
|
const params = matchRuntimePathPattern(redirect.source, pathname);
|
|
8461
9369
|
if (!params) continue;
|
|
8462
9370
|
const destination = interpolateRedirectDestination(redirect.destination, params);
|
|
9371
|
+
// Sources match the app-relative path, so an internal destination is app-relative
|
|
9372
|
+
// too: send the browser to it inside the basePath, as a localized one already is.
|
|
8463
9373
|
const localizedDestination =
|
|
8464
9374
|
locale && destination.startsWith("/") && !destination.startsWith("//")
|
|
8465
9375
|
? localizeFarmHref(destination, locale, farmI18nConfig)
|
|
8466
|
-
: destination;
|
|
9376
|
+
: applyFarmBasePath(destination);
|
|
8467
9377
|
return {
|
|
8468
9378
|
destination: appendFarmRedirectQuery(localizedDestination, search),
|
|
8469
9379
|
statusCode: redirect.statusCode ?? (redirect.permanent ? 308 : 307),
|
|
@@ -8484,13 +9394,18 @@ function matchRewriteRoute(pathname, locale) {
|
|
|
8484
9394
|
return null;
|
|
8485
9395
|
}
|
|
8486
9396
|
|
|
9397
|
+
// The URL the browser asked for, for a request a configured rewrite replaced.
|
|
9398
|
+
const farmRequestedUrls = new WeakMap();
|
|
9399
|
+
|
|
8487
9400
|
function createRewrittenRequest(request, destination) {
|
|
8488
9401
|
const sourceUrl = new URL(request.url);
|
|
8489
9402
|
const destinationUrl = new URL(destination, sourceUrl);
|
|
8490
9403
|
if (!destinationUrl.search && sourceUrl.search) {
|
|
8491
9404
|
destinationUrl.search = sourceUrl.search;
|
|
8492
9405
|
}
|
|
8493
|
-
|
|
9406
|
+
const rewritten = new Request(destinationUrl, request);
|
|
9407
|
+
farmRequestedUrls.set(rewritten, farmRequestedUrls.get(request) || request.url);
|
|
9408
|
+
return rewritten;
|
|
8494
9409
|
}
|
|
8495
9410
|
|
|
8496
9411
|
${generateConfiguredResponseHeadersRuntimeSource()}
|
|
@@ -8498,10 +9413,17 @@ ${generateConfiguredResponseHeadersRuntimeSource()}
|
|
|
8498
9413
|
// App middleware files bundled at build time (sorted by depth, root first)
|
|
8499
9414
|
const fileMiddlewareModules = [${middlewareRegistrations.join(",")}
|
|
8500
9415
|
];
|
|
8501
|
-
|
|
9416
|
+
${edgeMiddlewareFilePaths.length > 0 ? `
|
|
9417
|
+
// \`runtime: "edge"\` middleware runs as Vercel routing middleware in front of the pages the build
|
|
9418
|
+
// prerendered for it, so the build's own requests for those pages skip it. A page any other
|
|
9419
|
+
// middleware guards is never prerendered. Read once: Nitro's prerender worker sets the variable.
|
|
9420
|
+
const farmEdgeMiddlewareFiles = new Set(${JSON.stringify(edgeMiddlewareFilePaths)});
|
|
9421
|
+
const farmPrerendering =
|
|
9422
|
+
typeof process !== "undefined" && process.env?.${FARM_PRERENDER_ENV} === "1";
|
|
9423
|
+
` : ""}
|
|
8502
9424
|
const farmMiddlewareRunner = ${hasMiddlewareRuntime ? `createProductionMiddlewareRunner({
|
|
8503
9425
|
config: farmMiddlewareConfig,
|
|
8504
|
-
modules: fileMiddlewareModules,
|
|
9426
|
+
modules: ${edgeMiddlewareFilePaths.length > 0 ? "farmPrerendering ? fileMiddlewareModules.filter((entry) => !farmEdgeMiddlewareFiles.has(entry.filePath)) : fileMiddlewareModules" : "fileMiddlewareModules"},
|
|
8505
9427
|
i18n: farmI18nConfig,
|
|
8506
9428
|
server: farmServerConfig,
|
|
8507
9429
|
apiBasePath: farmLocalAPIBasePath,
|
|
@@ -8642,11 +9564,13 @@ function hasLocalRequestRoute(request, routePathname) {
|
|
|
8642
9564
|
return true;
|
|
8643
9565
|
}
|
|
8644
9566
|
${config.docs?.enabled ? `const docsPath = normalizeRuntimePath(farmDocsResolvedConfig?.entry || "/docs");
|
|
9567
|
+
// The docs answer below the basePath; their API stays at /api/docs, as API routes do.
|
|
9568
|
+
const docsRoutePathname = stripFarmBasePath(pathname);
|
|
8645
9569
|
if (
|
|
8646
9570
|
isFarmDocsAPIRequest(pathname) ||
|
|
8647
9571
|
docsPath === "/" ||
|
|
8648
|
-
|
|
8649
|
-
|
|
9572
|
+
docsRoutePathname === docsPath ||
|
|
9573
|
+
docsRoutePathname.startsWith(docsPath + "/")
|
|
8650
9574
|
) {
|
|
8651
9575
|
return true;
|
|
8652
9576
|
}` : ""}
|
|
@@ -8990,8 +9914,10 @@ function getPPRHeaders(status, config) {
|
|
|
8990
9914
|
return headers;
|
|
8991
9915
|
}
|
|
8992
9916
|
|
|
9917
|
+
// defer() values reach the browser as references its snapshot settles; other promises do not.
|
|
8993
9918
|
function hasFarmUnserializableRouteData(data) {
|
|
8994
|
-
const isPromise = (value) =>
|
|
9919
|
+
const isPromise = (value) =>
|
|
9920
|
+
Boolean(value) && typeof value.then === "function" && !isDeferred(value);
|
|
8995
9921
|
if (isPromise(data)) return true;
|
|
8996
9922
|
return Boolean(data) && typeof data === "object" && Object.values(data).some(isPromise);
|
|
8997
9923
|
}
|
|
@@ -9064,6 +9990,7 @@ async function handleFarmRequest(request, adapterContext) {
|
|
|
9064
9990
|
return applyMarkdownNegotiationHeaders(response, {
|
|
9065
9991
|
config: farmMarkdownConfig,
|
|
9066
9992
|
pathname: requestUrl.pathname,
|
|
9993
|
+
routePathname: getFarmRoutePathname,
|
|
9067
9994
|
});
|
|
9068
9995
|
}` : ""}
|
|
9069
9996
|
return response;
|
|
@@ -9109,6 +10036,8 @@ async function resolveFarmRequestInContext(
|
|
|
9109
10036
|
let url = requestUrl;
|
|
9110
10037
|
let pathname = url.pathname;
|
|
9111
10038
|
let routePathname = getFarmRoutePathname(pathname);
|
|
10039
|
+
// Before middleware: a ctx.rewrite() replaces the request below.
|
|
10040
|
+
const farmRequestedUrl = farmRequestedUrls.get(request) || request.url;
|
|
9112
10041
|
|
|
9113
10042
|
// Redirects have precedence over local routes. Configured rewrites use
|
|
9114
10043
|
// after-files semantics so emitted page, API, integration, docs, image, and
|
|
@@ -9185,6 +10114,7 @@ async function resolveFarmRequestInContext(
|
|
|
9185
10114
|
cloneFarmRequestWithContext(request),
|
|
9186
10115
|
farmIntegrationRanMiddleware,
|
|
9187
10116
|
adapterContext?.clientAddress,
|
|
10117
|
+
adapterContext?.[farmRuntimeErrorSlot],
|
|
9188
10118
|
);
|
|
9189
10119
|
if (integrationDispatch.response) {
|
|
9190
10120
|
return integrationDispatch.response;
|
|
@@ -9198,9 +10128,27 @@ async function resolveFarmRequestInContext(
|
|
|
9198
10128
|
|
|
9199
10129
|
${hasMiddlewareRuntime ? `
|
|
9200
10130
|
const requestBeforeMiddleware = request;
|
|
9201
|
-
|
|
9202
|
-
|
|
9203
|
-
|
|
10131
|
+
let middlewareResult;
|
|
10132
|
+
try {
|
|
10133
|
+
middlewareResult = await farmMiddlewareRunner(request, {
|
|
10134
|
+
clientAddress: adapterContext?.clientAddress,
|
|
10135
|
+
});
|
|
10136
|
+
} catch (error) {
|
|
10137
|
+
// The runner emitted middleware.error. The request is answered below like any
|
|
10138
|
+
// failed request; a plugin's runtime.error observes the throw, as for an API route.
|
|
10139
|
+
console.error("Middleware error:", error);
|
|
10140
|
+
await adapterContext?.[farmRuntimeErrorSlot]?.(error);
|
|
10141
|
+
middlewareResult = {
|
|
10142
|
+
request,
|
|
10143
|
+
response: null,
|
|
10144
|
+
data: new Map(),
|
|
10145
|
+
context: new Map(),
|
|
10146
|
+
headers: new Headers(),
|
|
10147
|
+
guarded: true,
|
|
10148
|
+
failed: true,
|
|
10149
|
+
error,
|
|
10150
|
+
};
|
|
10151
|
+
}
|
|
9204
10152
|
if (middlewareResult.response) {
|
|
9205
10153
|
return middlewareResult.response;
|
|
9206
10154
|
}
|
|
@@ -9214,6 +10162,7 @@ async function resolveFarmRequestInContext(
|
|
|
9214
10162
|
cloneFarmRequestWithContext(request),
|
|
9215
10163
|
farmIntegrationRanMiddleware,
|
|
9216
10164
|
adapterContext?.clientAddress,
|
|
10165
|
+
adapterContext?.[farmRuntimeErrorSlot],
|
|
9217
10166
|
);
|
|
9218
10167
|
farmIntegrationSetCookies = [...farmIntegrationSetCookies, ...rewrittenDispatch.setCookies];
|
|
9219
10168
|
if (rewrittenDispatch.response) {
|
|
@@ -9242,6 +10191,26 @@ ${hasServerRuntimeIntegrations ? `
|
|
|
9242
10191
|
// request instead of the original outer-handler value.
|
|
9243
10192
|
const runResolvedRequest = async () => {
|
|
9244
10193
|
if (middlewareResult.notFound) return renderFarmNotFoundResponse();
|
|
10194
|
+
if (middlewareResult.failed) {${farmRendererDisabled ? `
|
|
10195
|
+
return renderFarmErrorJSONResponse();` : `
|
|
10196
|
+
if (isFarmLocalAPIPathname(pathname)) return renderFarmErrorJSONResponse();
|
|
10197
|
+
// No page was selected, so only the root error boundary and layouts apply.
|
|
10198
|
+
const errorResponse = await renderFarmErrorResponse(middlewareResult.error, "/", {}, null);${config.md?.enabled ? `
|
|
10199
|
+
// An agent asking for Markdown reads the error document as Markdown, as it
|
|
10200
|
+
// does when a page throws. The helper answers null when Markdown is off.
|
|
10201
|
+
const markdownErrorResponse = await createMarkdownMirrorResponse({
|
|
10202
|
+
request,
|
|
10203
|
+
requestUrl: url,
|
|
10204
|
+
config: farmMarkdownConfig,
|
|
10205
|
+
routePathname: getFarmRoutePathname,
|
|
10206
|
+
routeExists: (targetPathname) =>
|
|
10207
|
+
Boolean(matchPageRoute(getFarmRoutePathname(targetPathname))),
|
|
10208
|
+
renderPage: async () => errorResponse,
|
|
10209
|
+
apiServerBasePath: farmLocalAPIBasePath,
|
|
10210
|
+
});
|
|
10211
|
+
if (markdownErrorResponse) return markdownErrorResponse;` : ""}
|
|
10212
|
+
return errorResponse;`}
|
|
10213
|
+
}
|
|
9245
10214
|
` : `
|
|
9246
10215
|
${hasServerRuntimeIntegrations ? `
|
|
9247
10216
|
// An integration guard (protectedRoutes) that let the request through.
|
|
@@ -9299,13 +10268,11 @@ ${hasServerRuntimeIntegrations ? `
|
|
|
9299
10268
|
middlewareData,
|
|
9300
10269
|
middlewareContext,
|
|
9301
10270
|
);
|
|
9302
|
-
|
|
9303
|
-
|
|
9304
|
-
|
|
9305
|
-
|
|
9306
|
-
|
|
9307
|
-
headers: docsHeaders,
|
|
9308
|
-
}), middlewareHeaders);
|
|
10271
|
+
// In place for a page the adapter built with createHtmlResponse, so its HTML string stays.
|
|
10272
|
+
const bufferedDocsResponse = farmPreloadHeadersResponse(wrappedDocsResponse, (headers) => {
|
|
10273
|
+
headers.set("x-farm-preload-buffered", "1");
|
|
10274
|
+
});
|
|
10275
|
+
return applyProductionMiddlewareHeaders(bufferedDocsResponse, middlewareHeaders);
|
|
9309
10276
|
}
|
|
9310
10277
|
}
|
|
9311
10278
|
` : ""}
|
|
@@ -9317,6 +10284,7 @@ ${hasServerRuntimeIntegrations ? `
|
|
|
9317
10284
|
const markdownSourceResponse = await createFarmMarkdownSourceResponse?.({
|
|
9318
10285
|
request: cloneFarmRequestWithContext(request),
|
|
9319
10286
|
config: farmMdxConfig,
|
|
10287
|
+
routePathname: getFarmRoutePathname,
|
|
9320
10288
|
resolveSource: (targetPathname) => {
|
|
9321
10289
|
const match = matchPageRoute(getFarmRoutePathname(targetPathname));
|
|
9322
10290
|
return match?.route?.markdownSource || null;
|
|
@@ -9368,6 +10336,7 @@ ${hasServerRuntimeIntegrations ? `
|
|
|
9368
10336
|
// Middleware and configured rewrites have already resolved this URL.
|
|
9369
10337
|
requestUrl: url,
|
|
9370
10338
|
config: farmMarkdownConfig,
|
|
10339
|
+
routePathname: getFarmRoutePathname,
|
|
9371
10340
|
routeExists: (targetPathname) =>
|
|
9372
10341
|
Boolean(matchPageRoute(getFarmRoutePathname(targetPathname))),
|
|
9373
10342
|
renderPage: (targetRequest) => fetchFarmInnerRequest(targetRequest, adapterContext),
|
|
@@ -9383,7 +10352,10 @@ ${hasServerRuntimeIntegrations ? `
|
|
|
9383
10352
|
// Clone only for an API request: cloning a Request costs more than the match,
|
|
9384
10353
|
// and handleAPIRequest returns null without one.
|
|
9385
10354
|
if (matchLocalAPIRequest(request)) {
|
|
9386
|
-
const apiResponse = await handleAPIRequest(
|
|
10355
|
+
const apiResponse = await handleAPIRequest(
|
|
10356
|
+
cloneFarmRequestWithContext(request),
|
|
10357
|
+
adapterContext?.[farmRuntimeErrorSlot],
|
|
10358
|
+
);
|
|
9387
10359
|
if (apiResponse) {
|
|
9388
10360
|
return applyProductionMiddlewareHeaders(apiResponse, middlewareHeaders);
|
|
9389
10361
|
}
|
|
@@ -9506,13 +10478,14 @@ ${hasServerRuntimeIntegrations ? `
|
|
|
9506
10478
|
: ${config.agent?.llmsTxt?.full ? `normalizeRuntimePath(routePathname) === "/llms-full.txt" ? "llms-full" : ` : ""}null;
|
|
9507
10479
|
if (farmGeneratedLlmsKind) {
|
|
9508
10480
|
const llmsContext = createFarmLlmsTxtContext(request, farmGeneratedLlmsKind === "llms-full");
|
|
10481
|
+
// Renders are shared per origin the request reached, which is where pages are read.
|
|
9509
10482
|
const llmsOrigin = new URL(request.url).origin;
|
|
9510
10483
|
// A page that times out is left out, the shared render is not reused, and
|
|
9511
10484
|
// the partial response is not cacheable.
|
|
9512
10485
|
let llmsComplete = true;
|
|
9513
10486
|
const renderLlmsFull = (shared) =>
|
|
9514
10487
|
renderFarmLlmsFullTxt(llmsContext.defaults, {
|
|
9515
|
-
origin:
|
|
10488
|
+
origin: getFarmAgentOrigin(request),
|
|
9516
10489
|
readMarkdown: llmsContext.markdown,
|
|
9517
10490
|
onIncomplete: () => {
|
|
9518
10491
|
llmsComplete = false;
|
|
@@ -9561,7 +10534,11 @@ ${hasServerRuntimeIntegrations ? `
|
|
|
9561
10534
|
const matchedRoute = matchPageRoute(routePathname);
|
|
9562
10535
|
${farmIslandsMode ? `// Islands mode: a form or client component posting a server action to this page.
|
|
9563
10536
|
if (matchedRoute && request.method === "POST") {
|
|
9564
|
-
const actionResponse = await
|
|
10537
|
+
const actionResponse = await _runWithMiddlewareData(middlewareData || {}, () =>
|
|
10538
|
+
_runWithMiddlewareContext(middlewareContext || {}, () =>
|
|
10539
|
+
handleFarmFormActionRequest(request, farmFormActionsConfig, farmRequestedUrl)
|
|
10540
|
+
)
|
|
10541
|
+
);
|
|
9565
10542
|
if (actionResponse) return applyProductionMiddlewareHeaders(actionResponse, middlewareHeaders);
|
|
9566
10543
|
}` : ""}
|
|
9567
10544
|
if (matchedRoute) {${farmMobileShells ? `
|
|
@@ -9612,7 +10589,7 @@ ${hasServerRuntimeIntegrations ? `
|
|
|
9612
10589
|
? 0
|
|
9613
10590
|
: countFarmKeptLayouts(request, farmSegmentLayouts, params);
|
|
9614
10591
|
// The root layout always renders, so keeping one layout keeps nothing.
|
|
9615
|
-
|
|
10592
|
+
let farmKeptLayouts = farmKeptLayoutCount > 1 ? farmKeptLayoutCount : 0;` : `let farmKeptLayouts = 0;`}
|
|
9616
10593
|
${farmMobileShells ? "const pprConfig = farmShellLoading ? { enabled: false } : resolvePPRConfig(route);" : "const pprConfig = resolvePPRConfig(route);"}
|
|
9617
10594
|
const pprBypassReason = pprConfig.enabled
|
|
9618
10595
|
? getPPRShellBypassReason(request, middlewareData, middlewareContext)
|
|
@@ -9856,8 +10833,8 @@ ${hasServerRuntimeIntegrations ? `
|
|
|
9856
10833
|
...(pageProps.__farmCanonicalPath
|
|
9857
10834
|
? { __farmCanonicalPath: pageProps.__farmCanonicalPath }
|
|
9858
10835
|
: {}),
|
|
9859
|
-
//
|
|
9860
|
-
// a page from these props
|
|
10836
|
+
// A promise that is not a defer() value does not survive JSON, so
|
|
10837
|
+
// the browser cannot render a page from these props.
|
|
9861
10838
|
...(pageProps.__farmRoutePropsResolved && !hasFarmUnserializableRouteData(pageProps.data)
|
|
9862
10839
|
? { __farmRoutePropsResolved: true }
|
|
9863
10840
|
: {}),
|
|
@@ -9882,6 +10859,17 @@ ${hasServerRuntimeIntegrations ? `
|
|
|
9882
10859
|
},
|
|
9883
10860
|
};
|
|
9884
10861
|
});
|
|
10862
|
+
// defer() values go to the browser as references (one id space for the page and its
|
|
10863
|
+
// slots), settled by renderFarmDeferredDataScript once the document has rendered.
|
|
10864
|
+
const farmDeferredData = prepareDeferredData({
|
|
10865
|
+
page: clientPageProps,
|
|
10866
|
+
slots: routeSlotPayload,
|
|
10867
|
+
});
|
|
10868
|
+
// A page without defer() values sends its props as they are: references, and escaped
|
|
10869
|
+
// look-alikes, only ever come with a snapshot, so the browser has nothing to revive.
|
|
10870
|
+
if (farmDeferredData.records.length === 0) {
|
|
10871
|
+
farmDeferredData.data = { page: clientPageProps, slots: routeSlotPayload };
|
|
10872
|
+
}
|
|
9885
10873
|
|
|
9886
10874
|
${farmIslandsMode ? `// Islands mode: a route a shared cache may store (a PPR shell, a static page) renders
|
|
9887
10875
|
// whole for every request, so a cache hit stays a hit. Other routes leave out what the
|
|
@@ -9900,12 +10888,26 @@ ${hasServerRuntimeIntegrations ? `
|
|
|
9900
10888
|
// A navigation the browser streams marks where each React flush ends, so the browser
|
|
9901
10889
|
// shows the page before its Suspense content arrives (FARM_FLUSH_MARKER). The marker
|
|
9902
10890
|
// carries a random token sent in the F-Flush header: page content cannot forge one.
|
|
9903
|
-
|
|
9904
|
-
|
|
9905
|
-
|
|
10891
|
+
// A page with defer() data arrives whole: the browser revives its props from the
|
|
10892
|
+
// snapshot after the body, which a shell swapped in first would not have yet.
|
|
10893
|
+
const farmFlushToken =
|
|
10894
|
+
request.headers.get("f-stream") === "flush" && farmDeferredData.records.length === 0
|
|
10895
|
+
? createFarmFlushToken()
|
|
10896
|
+
: "";` : `const farmLayoutKeyOf = null;
|
|
9906
10897
|
const farmPayloadOnlyNavigation = false;
|
|
9907
10898
|
const farmFlushToken = "";`}
|
|
9908
10899
|
const renderPageElement = async () => {
|
|
10900
|
+
// The browser chooses which layouts it says it keeps, so a kept layout still runs: a
|
|
10901
|
+
// guard in it decides this request. Only its markup is left out. A layout that fails
|
|
10902
|
+
// here renders whole, so notFound() and redirect() answer as on any other request.
|
|
10903
|
+
if (
|
|
10904
|
+
farmKeptLayouts > 0 &&
|
|
10905
|
+
!(await farmKeptLayoutsRender(ReactDOMServer, applicableLayouts, farmKeptLayouts, params))
|
|
10906
|
+
) {
|
|
10907
|
+
farmKeptLayouts = 0;
|
|
10908
|
+
pprCanCache = false;
|
|
10909
|
+
}
|
|
10910
|
+
|
|
9909
10911
|
// First, render the page content
|
|
9910
10912
|
let pageElement;
|
|
9911
10913
|
|
|
@@ -9986,9 +10988,11 @@ ${hasServerRuntimeIntegrations ? `
|
|
|
9986
10988
|
"data-farm-route-slot": slot.name,
|
|
9987
10989
|
"data-farm-slot-owner": slot.ownerPattern,
|
|
9988
10990
|
},
|
|
9989
|
-
|
|
9990
|
-
|
|
9991
|
-
|
|
10991
|
+
slot.hydrates
|
|
10992
|
+
? wrapFarmRouteClientGraph(
|
|
10993
|
+
React.createElement(slot.module.default, slot.props),
|
|
10994
|
+
)
|
|
10995
|
+
: React.createElement(slot.module.default, slot.props),
|
|
9992
10996
|
);
|
|
9993
10997
|
}
|
|
9994
10998
|
// Islands mode: a layout around a client provider, and the server layouts on its
|
|
@@ -10102,7 +11106,7 @@ ${hasServerRuntimeIntegrations ? `
|
|
|
10102
11106
|
// using the public path the .md request will be resolved against.
|
|
10103
11107
|
mergedMetadata = addMetadataMarkdownAlternate(
|
|
10104
11108
|
mergedMetadata,
|
|
10105
|
-
getFarmMarkdownAlternatePath(farmMarkdownConfig, pathname),
|
|
11109
|
+
getFarmMarkdownAlternatePath(farmMarkdownConfig, pathname, { routePathname: getFarmRoutePathname }),
|
|
10106
11110
|
);` : ""}
|
|
10107
11111
|
|
|
10108
11112
|
// headers(), cookies(), or getCurrentRequest() read during the render,
|
|
@@ -10231,11 +11235,16 @@ ${hasServerRuntimeIntegrations ? `
|
|
|
10231
11235
|
const farmClientScripts = function(early) {
|
|
10232
11236
|
return ' ' + renderFarmClientBootstrapScript(
|
|
10233
11237
|
pageProps.__farmCanonicalPath,
|
|
10234
|
-
|
|
10235
|
-
|
|
11238
|
+
farmDeferredData.data.slots,
|
|
11239
|
+
farmDeferredData.data.page
|
|
10236
11240
|
) + '\\n' +
|
|
10237
11241
|
' ' + renderFarmClientEntryScript(early) + '\\n';
|
|
10238
11242
|
};
|
|
11243
|
+
// Written as the stream ends, when the values the page read have settled.
|
|
11244
|
+
const farmDeferredDataScript = function() {
|
|
11245
|
+
const script = renderFarmDeferredDataScript(farmDeferredData.records);
|
|
11246
|
+
return script ? ' ' + script + '\\n' : '';
|
|
11247
|
+
};
|
|
10239
11248
|
const farmEarlyClientScripts = ${farmIslandsMode ? "farmClientScripts(true)" : '""'};
|
|
10240
11249
|
const streamPrefix = '<!DOCTYPE html>\\n<html lang="en">\\n<head>\\n' +
|
|
10241
11250
|
farmThemeDocument.head + '\\n' +
|
|
@@ -10247,9 +11256,10 @@ ${hasServerRuntimeIntegrations ? `
|
|
|
10247
11256
|
' <link rel="modulepreload" href="/__farm_client_js_src__">' + renderFarmClientModulePreloads(null, route.clientModule) + '\\n' +
|
|
10248
11257
|
renderFarmRendererHydrationScript() + '\\n' +
|
|
10249
11258
|
'</head>\\n<body>\\n' + farmEarlyClientScripts + ' <div id="root">';
|
|
10250
|
-
const
|
|
10251
|
-
|
|
10252
|
-
'</body>\\n</html>';
|
|
11259
|
+
const streamClientScripts = farmEarlyClientScripts ? '' : farmClientScripts();
|
|
11260
|
+
const streamSuffix = function() {
|
|
11261
|
+
return '</div>\\n' + farmDeferredDataScript() + streamClientScripts + '</body>\\n</html>';
|
|
11262
|
+
};
|
|
10253
11263
|
const themedStreamPrefix = streamPrefix.replace(
|
|
10254
11264
|
'<html lang="en">',
|
|
10255
11265
|
() => '<html lang="en"' + farmThemeDocument.attributes + '>'
|
|
@@ -10325,6 +11335,7 @@ ${hasServerRuntimeIntegrations ? `
|
|
|
10325
11335
|
async function(rootOpened) {
|
|
10326
11336
|
return (await lateNavigationRecovery()) +
|
|
10327
11337
|
(rootOpened ? '</div>\\n' : '') +
|
|
11338
|
+
farmDeferredDataScript() +
|
|
10328
11339
|
(farmEarlyClientScripts ? '' : farmClientScripts());
|
|
10329
11340
|
},
|
|
10330
11341
|
onStreamComplete
|
|
@@ -10333,7 +11344,7 @@ ${hasServerRuntimeIntegrations ? `
|
|
|
10333
11344
|
renderedPage.stream,
|
|
10334
11345
|
themedStreamPrefix,
|
|
10335
11346
|
async function() {
|
|
10336
|
-
return (await lateNavigationRecovery()) + streamSuffix;
|
|
11347
|
+
return (await lateNavigationRecovery()) + streamSuffix();
|
|
10337
11348
|
},
|
|
10338
11349
|
onStreamComplete
|
|
10339
11350
|
);
|
|
@@ -10379,9 +11390,9 @@ ${hasServerRuntimeIntegrations ? `
|
|
|
10379
11390
|
/<\\/body>/i,
|
|
10380
11391
|
() => ' ' + renderFarmClientBootstrapScript(
|
|
10381
11392
|
pageProps.__farmCanonicalPath,
|
|
10382
|
-
|
|
10383
|
-
|
|
10384
|
-
) + '\\n' +
|
|
11393
|
+
farmDeferredData.data.slots,
|
|
11394
|
+
farmDeferredData.data.page
|
|
11395
|
+
) + renderFarmDeferredDataScript(farmDeferredData.records) + '\\n' +
|
|
10385
11396
|
' ' + farmEntryScript + '\\n</body>',
|
|
10386
11397
|
);
|
|
10387
11398
|
} else {
|
|
@@ -10398,7 +11409,7 @@ ${hasServerRuntimeIntegrations ? `
|
|
|
10398
11409
|
</head>
|
|
10399
11410
|
<body>
|
|
10400
11411
|
<div id="root">\${html}</div>
|
|
10401
|
-
\${renderFarmClientBootstrapScript(pageProps.__farmCanonicalPath,
|
|
11412
|
+
\${renderFarmClientBootstrapScript(pageProps.__farmCanonicalPath, farmDeferredData.data.slots, farmDeferredData.data.page)}\${renderFarmDeferredDataScript(farmDeferredData.records)}
|
|
10402
11413
|
\${farmEntryScript}
|
|
10403
11414
|
</body>
|
|
10404
11415
|
</html>\`;
|
|
@@ -10504,106 +11515,7 @@ ${hasServerRuntimeIntegrations ? `
|
|
|
10504
11515
|
|
|
10505
11516
|
emitFarmEvent({ type: "render.error", route: pathname, error });
|
|
10506
11517
|
console.error("SSR Error:", error);
|
|
10507
|
-
|
|
10508
|
-
const errorStatusText = getDefaultErrorStatusText(errorStatus);
|
|
10509
|
-
|
|
10510
|
-
const errorBoundaryMatch = getMatchingErrorBoundary(routePathname);
|
|
10511
|
-
if (errorBoundaryMatch?.route.module?.default) {
|
|
10512
|
-
try {
|
|
10513
|
-
const searchParamsObj = searchParamsToObject(url.searchParams);
|
|
10514
|
-
const ErrorComponent = errorBoundaryMatch.route.module.default;
|
|
10515
|
-
let errorElement = React.createElement(ErrorComponent, {
|
|
10516
|
-
error,
|
|
10517
|
-
reset: function() {},
|
|
10518
|
-
params,
|
|
10519
|
-
search: searchParamsObj,
|
|
10520
|
-
searchParams: createFarmSearchParams(searchParamsObj),
|
|
10521
|
-
path: pathname,
|
|
10522
|
-
...(middlewareData?.size ? { middleware: { data: middlewareData } } : {}),
|
|
10523
|
-
});
|
|
10524
|
-
|
|
10525
|
-
const applicableLayouts = getApplicableLayouts(routePathname);
|
|
10526
|
-
for (let i = applicableLayouts.length - 1; i >= 0; i--) {
|
|
10527
|
-
const LayoutComponent = applicableLayouts[i].module.default;
|
|
10528
|
-
if (LayoutComponent) {
|
|
10529
|
-
errorElement = React.createElement(LayoutComponent, {
|
|
10530
|
-
children: errorElement,
|
|
10531
|
-
params,
|
|
10532
|
-
});
|
|
10533
|
-
}
|
|
10534
|
-
}
|
|
10535
|
-
|
|
10536
|
-
errorElement = wrapWithFarmIntegrationProviders(errorElement);
|
|
10537
|
-
|
|
10538
|
-
const renderErrorElement = () =>
|
|
10539
|
-
renderFarmElementToString(ReactDOMServer, errorElement);
|
|
10540
|
-
const errorHtml = ${hasMiddlewareRuntime ? `await _runWithMiddlewareData(middlewareData, () =>
|
|
10541
|
-
_runWithMiddlewareContext(middlewareContext, renderErrorElement)
|
|
10542
|
-
)` : "await renderErrorElement()"};
|
|
10543
|
-
const errorDocument = applyFarmThemeDocument(
|
|
10544
|
-
applyFarmI18nDocument(
|
|
10545
|
-
createFarmErrorDocument(errorHtml, "Application Error"),
|
|
10546
|
-
pathname,
|
|
10547
|
-
getFarmI18nSnapshot(),
|
|
10548
|
-
request
|
|
10549
|
-
),
|
|
10550
|
-
farmThemeConfig,
|
|
10551
|
-
farmResolvedRuntimeConfig.basePath,
|
|
10552
|
-
getFarmTheme(request)
|
|
10553
|
-
);
|
|
10554
|
-
emitFarmEvent({
|
|
10555
|
-
type: "render.complete",
|
|
10556
|
-
route: pathname,
|
|
10557
|
-
pathname,
|
|
10558
|
-
status: errorStatus,
|
|
10559
|
-
durationMs: Date.now() - requestStartTime,
|
|
10560
|
-
});
|
|
10561
|
-
return rememberFarmBufferedHtml(applyProductionMiddlewareHeaders(farmOwnedHtmlResponse(errorDocument, {
|
|
10562
|
-
status: errorStatus,
|
|
10563
|
-
headers: {
|
|
10564
|
-
"Content-Type": "text/html; charset=utf-8",
|
|
10565
|
-
"Cache-Control": "private, no-store",
|
|
10566
|
-
"x-farm-preload-buffered": getFarmBufferedPreloadMarker(errorDocument),
|
|
10567
|
-
},
|
|
10568
|
-
}), middlewareHeaders), errorDocument);
|
|
10569
|
-
} catch (boundaryError) {
|
|
10570
|
-
console.error("Route error boundary failed:", boundaryError);
|
|
10571
|
-
}
|
|
10572
|
-
}
|
|
10573
|
-
|
|
10574
|
-
const fallbackHtml = stampFarmCspNonce(createDefaultErrorMarkup({
|
|
10575
|
-
statusCode: errorStatus,
|
|
10576
|
-
statusText: errorStatusText,
|
|
10577
|
-
requestPath: pathname,
|
|
10578
|
-
method: request.method,
|
|
10579
|
-
development: false,
|
|
10580
|
-
mode: "production",
|
|
10581
|
-
}));
|
|
10582
|
-
const fallbackDocument = applyFarmThemeDocument(
|
|
10583
|
-
applyFarmI18nDocument(
|
|
10584
|
-
createFarmErrorDocument(
|
|
10585
|
-
fallbackHtml,
|
|
10586
|
-
errorStatus + " - " + errorStatusText
|
|
10587
|
-
),
|
|
10588
|
-
pathname,
|
|
10589
|
-
getFarmI18nSnapshot(),
|
|
10590
|
-
request
|
|
10591
|
-
),
|
|
10592
|
-
farmThemeConfig,
|
|
10593
|
-
farmResolvedRuntimeConfig.basePath,
|
|
10594
|
-
getFarmTheme(request)
|
|
10595
|
-
);
|
|
10596
|
-
return rememberFarmBufferedHtml(applyProductionMiddlewareHeaders(farmOwnedHtmlResponse(
|
|
10597
|
-
fallbackDocument,
|
|
10598
|
-
{
|
|
10599
|
-
status: errorStatus,
|
|
10600
|
-
headers: {
|
|
10601
|
-
"Content-Type": "text/html; charset=utf-8",
|
|
10602
|
-
"Cache-Control": "private, no-store",
|
|
10603
|
-
"x-farm-preload-buffered": getFarmBufferedPreloadMarker(fallbackDocument),
|
|
10604
|
-
},
|
|
10605
|
-
}
|
|
10606
|
-
), middlewareHeaders), fallbackDocument);
|
|
11518
|
+
return renderFarmErrorResponse(error, routePathname, params);
|
|
10607
11519
|
}
|
|
10608
11520
|
}
|
|
10609
11521
|
|
|
@@ -10622,10 +11534,136 @@ ${servesDefaultMCP ? `
|
|
|
10622
11534
|
// 404 fallback - render proper HTML page
|
|
10623
11535
|
return renderFarmNotFoundResponse();
|
|
10624
11536
|
|
|
11537
|
+
// Hoisted: a page that throws and a middleware failure answer with the same error
|
|
11538
|
+
// document. The error boundary and layouts are those of errorRoutePathname.
|
|
11539
|
+
async function renderFarmErrorResponse(error, errorRoutePathname, params, errorDirectory) {
|
|
11540
|
+
const errorStatus = resolveDefaultErrorStatus(error);
|
|
11541
|
+
const errorStatusText = getDefaultErrorStatusText(errorStatus);
|
|
11542
|
+
|
|
11543
|
+
const errorBoundaryMatch = getMatchingErrorBoundary(errorRoutePathname);
|
|
11544
|
+
if (errorBoundaryMatch?.route.module?.default) {
|
|
11545
|
+
try {
|
|
11546
|
+
const searchParamsObj = searchParamsToObject(url.searchParams);
|
|
11547
|
+
const ErrorComponent = errorBoundaryMatch.route.module.default;
|
|
11548
|
+
let errorElement = React.createElement(ErrorComponent, {
|
|
11549
|
+
error,
|
|
11550
|
+
reset: function() {},
|
|
11551
|
+
params,
|
|
11552
|
+
search: searchParamsObj,
|
|
11553
|
+
searchParams: createFarmSearchParams(searchParamsObj),
|
|
11554
|
+
path: pathname,
|
|
11555
|
+
...(middlewareData?.size ? { middleware: { data: middlewareData } } : {}),
|
|
11556
|
+
});
|
|
11557
|
+
|
|
11558
|
+
const applicableLayouts = getApplicableLayouts(errorRoutePathname, errorDirectory);
|
|
11559
|
+
for (let i = applicableLayouts.length - 1; i >= 0; i--) {
|
|
11560
|
+
const LayoutComponent = applicableLayouts[i].module.default;
|
|
11561
|
+
if (LayoutComponent) {
|
|
11562
|
+
errorElement = React.createElement(LayoutComponent, {
|
|
11563
|
+
children: errorElement,
|
|
11564
|
+
params,
|
|
11565
|
+
});
|
|
11566
|
+
}
|
|
11567
|
+
}
|
|
11568
|
+
|
|
11569
|
+
errorElement = wrapWithFarmIntegrationProviders(errorElement);
|
|
11570
|
+
|
|
11571
|
+
const renderErrorElement = () =>
|
|
11572
|
+
renderFarmElementToString(ReactDOMServer, errorElement);
|
|
11573
|
+
const errorHtml = ${hasMiddlewareRuntime ? `await _runWithMiddlewareData(middlewareData, () =>
|
|
11574
|
+
_runWithMiddlewareContext(middlewareContext, renderErrorElement)
|
|
11575
|
+
)` : "await renderErrorElement()"};
|
|
11576
|
+
const errorDocument = applyFarmThemeDocument(
|
|
11577
|
+
applyFarmI18nDocument(
|
|
11578
|
+
createFarmErrorDocument(errorHtml, "Application Error"),
|
|
11579
|
+
pathname,
|
|
11580
|
+
getFarmI18nSnapshot(),
|
|
11581
|
+
request
|
|
11582
|
+
),
|
|
11583
|
+
farmThemeConfig,
|
|
11584
|
+
farmResolvedRuntimeConfig.basePath,
|
|
11585
|
+
getFarmTheme(request)
|
|
11586
|
+
);
|
|
11587
|
+
emitFarmEvent({
|
|
11588
|
+
type: "render.complete",
|
|
11589
|
+
route: pathname,
|
|
11590
|
+
pathname,
|
|
11591
|
+
status: errorStatus,
|
|
11592
|
+
durationMs: Date.now() - requestStartTime,
|
|
11593
|
+
});
|
|
11594
|
+
return rememberFarmBufferedHtml(applyProductionMiddlewareHeaders(farmOwnedHtmlResponse(errorDocument, {
|
|
11595
|
+
status: errorStatus,
|
|
11596
|
+
headers: {
|
|
11597
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
11598
|
+
"Cache-Control": "private, no-store",
|
|
11599
|
+
"x-farm-preload-buffered": getFarmBufferedPreloadMarker(errorDocument),
|
|
11600
|
+
},
|
|
11601
|
+
}), middlewareHeaders), errorDocument);
|
|
11602
|
+
} catch (boundaryError) {
|
|
11603
|
+
console.error("Route error boundary failed:", boundaryError);
|
|
11604
|
+
}
|
|
11605
|
+
}
|
|
11606
|
+
|
|
11607
|
+
const fallbackHtml = stampFarmCspNonce(createDefaultErrorMarkup({
|
|
11608
|
+
statusCode: errorStatus,
|
|
11609
|
+
statusText: errorStatusText,
|
|
11610
|
+
requestPath: pathname,
|
|
11611
|
+
method: request.method,
|
|
11612
|
+
development: false,
|
|
11613
|
+
mode: "production",
|
|
11614
|
+
}));
|
|
11615
|
+
const fallbackDocument = applyFarmThemeDocument(
|
|
11616
|
+
applyFarmI18nDocument(
|
|
11617
|
+
createFarmErrorDocument(
|
|
11618
|
+
fallbackHtml,
|
|
11619
|
+
errorStatus + " - " + errorStatusText
|
|
11620
|
+
),
|
|
11621
|
+
pathname,
|
|
11622
|
+
getFarmI18nSnapshot(),
|
|
11623
|
+
request
|
|
11624
|
+
),
|
|
11625
|
+
farmThemeConfig,
|
|
11626
|
+
farmResolvedRuntimeConfig.basePath,
|
|
11627
|
+
getFarmTheme(request)
|
|
11628
|
+
);
|
|
11629
|
+
return rememberFarmBufferedHtml(applyProductionMiddlewareHeaders(farmOwnedHtmlResponse(
|
|
11630
|
+
fallbackDocument,
|
|
11631
|
+
{
|
|
11632
|
+
status: errorStatus,
|
|
11633
|
+
headers: {
|
|
11634
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
11635
|
+
"Cache-Control": "private, no-store",
|
|
11636
|
+
"x-farm-preload-buffered": getFarmBufferedPreloadMarker(fallbackDocument),
|
|
11637
|
+
},
|
|
11638
|
+
}
|
|
11639
|
+
), middlewareHeaders), fallbackDocument);
|
|
11640
|
+
}
|
|
11641
|
+
${hasMiddlewareRuntime ? `
|
|
11642
|
+
// A request no page answers fails with the JSON a throwing API route answers.
|
|
11643
|
+
function renderFarmErrorJSONResponse() {
|
|
11644
|
+
return applyProductionMiddlewareHeaders(farmOwnedResponse(
|
|
11645
|
+
JSON.stringify({ error: "Internal Server Error" }),
|
|
11646
|
+
{ status: 500, headers: { "Content-Type": "application/json" } }
|
|
11647
|
+
), middlewareHeaders);
|
|
11648
|
+
}
|
|
11649
|
+
` : ""}
|
|
10625
11650
|
// Hoisted: page and middleware notFound() answer with the same page.
|
|
10626
11651
|
async function renderFarmNotFoundResponse() {
|
|
10627
11652
|
emitFarmEvent({ type: "route.notFound", pathname });
|
|
10628
|
-
|
|
11653
|
+
${farmRendererDisabled ? `
|
|
11654
|
+
// renderer: false has no pages to render, so a miss answers like an API miss.
|
|
11655
|
+
emitFarmEvent({
|
|
11656
|
+
type: "render.complete",
|
|
11657
|
+
route: pathname,
|
|
11658
|
+
pathname,
|
|
11659
|
+
status: 404,
|
|
11660
|
+
durationMs: Date.now() - requestStartTime,
|
|
11661
|
+
});
|
|
11662
|
+
return applyProductionMiddlewareHeaders(farmOwnedResponse(
|
|
11663
|
+
JSON.stringify({ error: "Not found", pathname }),
|
|
11664
|
+
{ status: 404, headers: { "Content-Type": "application/json" } }
|
|
11665
|
+
), middlewareHeaders);
|
|
11666
|
+
` : ""}
|
|
10629
11667
|
// Agents that navigate in Markdown (a \`.md\` URL or \`Accept: text/markdown\`)
|
|
10630
11668
|
// get a Markdown error body instead of the HTML not-found shell.
|
|
10631
11669
|
if (farmRequestWantsMarkdown(pathname, request.headers.get("accept"))) {
|
|
@@ -10821,7 +11859,23 @@ async function handleFarmPluginRequest(request, runtimeOptions, adapterContext)
|
|
|
10821
11859
|
}
|
|
10822
11860
|
|
|
10823
11861
|
${generatePreloadResponseRuntimeSource()}
|
|
10824
|
-
|
|
11862
|
+
${hasPluginRuntime ? `
|
|
11863
|
+
// The 500 a request answers when a plugin runtime hook throws, as in farm dev: the generic JSON
|
|
11864
|
+
// body on an API path or with renderer: false, plain text for a page.
|
|
11865
|
+
function createFarmRuntimeHookErrorResponse(request, error) {
|
|
11866
|
+
console.error("Plugin runtime error:", error);${farmRendererDisabled ? "" : `
|
|
11867
|
+
if (!isFarmLocalAPIPathname(new URL(request.url).pathname)) {
|
|
11868
|
+
return farmOwnedResponse("Internal Server Error", {
|
|
11869
|
+
status: 500,
|
|
11870
|
+
headers: { "Content-Type": "text/plain; charset=utf-8" },
|
|
11871
|
+
});
|
|
11872
|
+
}`}
|
|
11873
|
+
return farmOwnedResponse(JSON.stringify({ error: "Internal Server Error" }), {
|
|
11874
|
+
status: 500,
|
|
11875
|
+
headers: { "Content-Type": "application/json" },
|
|
11876
|
+
});
|
|
11877
|
+
}
|
|
11878
|
+
` : ""}
|
|
10825
11879
|
// Export as Web Standard fetch API
|
|
10826
11880
|
export async function fetch(request, context) {${imageRuntime === "none" ? "" : `
|
|
10827
11881
|
// The image optimizer's fetch of a local source is not a loopback visitor.
|
|
@@ -10896,11 +11950,14 @@ async function handleFarmFetch(request, context) {
|
|
|
10896
11950
|
const runRequest = () => farmPluginRuntime
|
|
10897
11951
|
? farmPluginRuntime.runRuntimeRequest(
|
|
10898
11952
|
request,
|
|
10899
|
-
(runtimeRequest) =>
|
|
11953
|
+
(runtimeRequest, runtimeScope) =>
|
|
10900
11954
|
_runWithCurrentRequest(runtimeRequest, () =>
|
|
10901
11955
|
prepareResponse(
|
|
10902
11956
|
runtimeRequest,
|
|
10903
|
-
handleFarmPluginRequest(runtimeRequest, runtimeOptions,
|
|
11957
|
+
handleFarmPluginRequest(runtimeRequest, runtimeOptions, {
|
|
11958
|
+
...context,
|
|
11959
|
+
[farmRuntimeErrorSlot]: runtimeScope.reportError,
|
|
11960
|
+
}),
|
|
10904
11961
|
)
|
|
10905
11962
|
),
|
|
10906
11963
|
{
|
|
@@ -10909,6 +11966,11 @@ async function handleFarmFetch(request, context) {
|
|
|
10909
11966
|
? context.waitUntil.bind(context)
|
|
10910
11967
|
: undefined,
|
|
10911
11968
|
},
|
|
11969
|
+
).catch((error) =>
|
|
11970
|
+
// A runtime hook threw, or something it wraps: runtime.error and onError observed
|
|
11971
|
+
// it, and the remaining runtime.after hooks were skipped. Answer the 500 farm dev
|
|
11972
|
+
// answers, with the headers() config, instead of Nitro's own error response.
|
|
11973
|
+
prepareResponse(request, createFarmRuntimeHookErrorResponse(request, error))
|
|
10912
11974
|
)
|
|
10913
11975
|
: ${hasInfraAnalyticsRuntime && !hasPluginRuntime ? `farmAnalyticsOptions
|
|
10914
11976
|
? farmInfraAnalytics.record(
|
|
@@ -11006,6 +12068,16 @@ function getEffectiveRouteRule(config, pathname) {
|
|
|
11006
12068
|
function getManifestPageEntry(manifest, pathname) {
|
|
11007
12069
|
return manifest.routes.filter((entry) => entry.kind === "page" && middlewarePatternMatches(entry.pattern, pathname)).sort((left, right) => compareRoutePatternSpecificity(left.pattern, right.pattern))[0];
|
|
11008
12070
|
}
|
|
12071
|
+
function withFarmEdgeGuardedPrerenderHeaders(headers, edgeGuarded) {
|
|
12072
|
+
if (!edgeGuarded) return headers;
|
|
12073
|
+
const cacheHeaders = /* @__PURE__ */ new Set(["cache-control", ...CDN_CACHE_CONTROL_HEADERS]);
|
|
12074
|
+
return {
|
|
12075
|
+
...Object.fromEntries(
|
|
12076
|
+
Object.entries(headers).filter(([name]) => !cacheHeaders.has(name.toLowerCase()))
|
|
12077
|
+
),
|
|
12078
|
+
"cache-control": "private, no-store"
|
|
12079
|
+
};
|
|
12080
|
+
}
|
|
11009
12081
|
function getPhysicalPrerenderBypassReason(options) {
|
|
11010
12082
|
const {
|
|
11011
12083
|
config,
|
|
@@ -11042,18 +12114,30 @@ function getPhysicalPrerenderBypassReason(options) {
|
|
|
11042
12114
|
}
|
|
11043
12115
|
async function getFarmDocsPrerenderPages(config, root, preset) {
|
|
11044
12116
|
if (!config.docs?.enabled || !config.docs.prerender) return [];
|
|
11045
|
-
if (!isReactRenderer(config.renderer) || !hasFarmDocsRuntimeAdapter(config.docs)) {
|
|
11046
|
-
logger.warn(
|
|
11047
|
-
"docs.prerender needs a docs adapter such as @farming-labs/farmjs; Farm's built-in docs renderer keeps rendering docs pages on request."
|
|
11048
|
-
);
|
|
11049
|
-
return [];
|
|
11050
|
-
}
|
|
11051
12117
|
if (getFarmPresetRuntime(preset) === "edge") {
|
|
11052
12118
|
logger.info(
|
|
11053
12119
|
`\u21AA Keeping docs pages in the edge docs snapshot: docs.prerender writes static files on Node and serverless targets, not "${preset}".`
|
|
11054
12120
|
);
|
|
11055
12121
|
return [];
|
|
11056
12122
|
}
|
|
12123
|
+
if (!hasFarmDocsRuntimeAdapter(config.docs)) {
|
|
12124
|
+
const { pages: pages2, originDependent } = listFarmDocsBuiltInPrerenderPages(config.docs, {
|
|
12125
|
+
root,
|
|
12126
|
+
srcDir: config.srcDir
|
|
12127
|
+
});
|
|
12128
|
+
if (originDependent.length > 0) {
|
|
12129
|
+
logger.info(
|
|
12130
|
+
`\u21AA Keeping ${originDependent.length} docs page(s) rendering on request: their social image metadata is an absolute URL built from the request's origin. Set docs.socialImage.baseUrl to prerender them.`
|
|
12131
|
+
);
|
|
12132
|
+
}
|
|
12133
|
+
return pages2;
|
|
12134
|
+
}
|
|
12135
|
+
if (!isReactRenderer(config.renderer)) {
|
|
12136
|
+
logger.warn(
|
|
12137
|
+
`The docs adapter ${JSON.stringify(config.docs.adapter.id)} renders with React; docs.prerender keeps its pages rendering on request with the "${config.renderer.name}" renderer.`
|
|
12138
|
+
);
|
|
12139
|
+
return [];
|
|
12140
|
+
}
|
|
11057
12141
|
const pages = await listFarmDocsAdapterPages(config.docs, { root, srcDir: config.srcDir });
|
|
11058
12142
|
if (!pages) {
|
|
11059
12143
|
logger.warn(
|
|
@@ -11078,11 +12162,11 @@ async function buildNitroUniversal(config, routeManager, apiRouteManager, server
|
|
|
11078
12162
|
]);
|
|
11079
12163
|
if (nitroBuilderResult.status === "rejected") throw nitroBuilderResult.reason;
|
|
11080
12164
|
const nitroBuilder = nitroBuilderResult.value;
|
|
11081
|
-
const isVercel = preset === "vercel"
|
|
12165
|
+
const isVercel = preset === "vercel";
|
|
11082
12166
|
const isCloudflareWorker = preset === "cloudflare-module";
|
|
11083
12167
|
const outputDir = resolveDeployOutputPath(root, config.deploy.outputDir);
|
|
11084
|
-
const runtimeServerOutputDir = isVercel ?
|
|
11085
|
-
const ssrOutputDir =
|
|
12168
|
+
const runtimeServerOutputDir = isVercel ? path12.join(outputDir, "functions", "__nitro.func") : path12.join(outputDir, "server");
|
|
12169
|
+
const ssrOutputDir = path12.join(root, distDir, "ssr");
|
|
11086
12170
|
const imageRuntime = resolveFarmImageServerRuntime(config.images, preset);
|
|
11087
12171
|
const hasGeneratedMetadataImages = Array.from(routeManager.getMetadataImages().values()).some(
|
|
11088
12172
|
(image) => image.sourceType === "module"
|
|
@@ -11097,7 +12181,10 @@ async function buildNitroUniversal(config, routeManager, apiRouteManager, server
|
|
|
11097
12181
|
...imageRuntime === "node" ? ["sharp"] : [],
|
|
11098
12182
|
...useExternalMetadataImageRuntime ? ["@vercel/og"] : []
|
|
11099
12183
|
]);
|
|
11100
|
-
const
|
|
12184
|
+
const ssrExternalsArePackaged = [...ssrExternalPackages].every(
|
|
12185
|
+
(packageName) => copiedRuntimePackages.has(packageName)
|
|
12186
|
+
);
|
|
12187
|
+
const isPrebuiltSSRCandidate = preset === "node-server" && ssrExternalsArePackaged;
|
|
11101
12188
|
logger.info(`\u{1F4E6} Nitro output directory: ${outputDir}`);
|
|
11102
12189
|
logger.info(`\u{1F4E6} SSR entry file: ${ssrEntryFile}`);
|
|
11103
12190
|
logger.info(`\u{1F4E6} Preset: ${preset}`);
|
|
@@ -11131,12 +12218,21 @@ async function buildNitroUniversal(config, routeManager, apiRouteManager, server
|
|
|
11131
12218
|
config: await readMiddlewareFileConfig(route.filePath)
|
|
11132
12219
|
}))
|
|
11133
12220
|
) : middlewareRoutes;
|
|
12221
|
+
const edgeMiddlewareRoutes = farmTargetRunsEdgeMiddleware(preset) ? middlewareRoutesWithConfig.filter(isFarmEdgeMiddlewareRoute) : [];
|
|
12222
|
+
const serverMiddlewareRoutes = edgeMiddlewareRoutes.length > 0 ? middlewareRoutesWithConfig.filter((route) => !isFarmEdgeMiddlewareRoute(route)) : middlewareRoutesWithConfig;
|
|
12223
|
+
const edgeGuardedPrerenderRoutes = [];
|
|
12224
|
+
const addPrerenderRoute = (pathname) => {
|
|
12225
|
+
prerenderRoutes.push(pathname);
|
|
12226
|
+
if (appMiddlewareMayHandlePath(edgeMiddlewareRoutes, pathname)) {
|
|
12227
|
+
edgeGuardedPrerenderRoutes.push(pathname);
|
|
12228
|
+
}
|
|
12229
|
+
};
|
|
11134
12230
|
for (const page of ssgPages) {
|
|
11135
12231
|
if (page.revalidate !== void 0) continue;
|
|
11136
12232
|
if (prerenderRoutes.includes(page.urlPath)) continue;
|
|
11137
12233
|
const reason = getPhysicalPrerenderBypassReason({
|
|
11138
12234
|
config,
|
|
11139
|
-
middlewareRoutes:
|
|
12235
|
+
middlewareRoutes: serverMiddlewareRoutes,
|
|
11140
12236
|
routeRuntimeManifest,
|
|
11141
12237
|
redirectSources,
|
|
11142
12238
|
rewriteSources,
|
|
@@ -11146,7 +12242,7 @@ async function buildNitroUniversal(config, routeManager, apiRouteManager, server
|
|
|
11146
12242
|
skippedPrerenderRoutes.push({ pathname: page.urlPath, reason });
|
|
11147
12243
|
continue;
|
|
11148
12244
|
}
|
|
11149
|
-
|
|
12245
|
+
addPrerenderRoute(page.urlPath);
|
|
11150
12246
|
}
|
|
11151
12247
|
const docsRouteRuntimeManifest = {
|
|
11152
12248
|
...routeRuntimeManifest,
|
|
@@ -11156,7 +12252,7 @@ async function buildNitroUniversal(config, routeManager, apiRouteManager, server
|
|
|
11156
12252
|
if (prerenderRoutes.includes(pathname)) continue;
|
|
11157
12253
|
const reason = getPhysicalPrerenderBypassReason({
|
|
11158
12254
|
config,
|
|
11159
|
-
middlewareRoutes:
|
|
12255
|
+
middlewareRoutes: serverMiddlewareRoutes,
|
|
11160
12256
|
routeRuntimeManifest: docsRouteRuntimeManifest,
|
|
11161
12257
|
redirectSources,
|
|
11162
12258
|
rewriteSources,
|
|
@@ -11166,7 +12262,7 @@ async function buildNitroUniversal(config, routeManager, apiRouteManager, server
|
|
|
11166
12262
|
skippedPrerenderRoutes.push({ pathname, reason });
|
|
11167
12263
|
continue;
|
|
11168
12264
|
}
|
|
11169
|
-
|
|
12265
|
+
addPrerenderRoute(pathname);
|
|
11170
12266
|
}
|
|
11171
12267
|
for (const skipped of skippedPrerenderRoutes) {
|
|
11172
12268
|
logger.info(`\u21AA Keeping SSG route ${skipped.pathname} server-handled (${skipped.reason})`);
|
|
@@ -11192,15 +12288,15 @@ async function buildNitroUniversal(config, routeManager, apiRouteManager, server
|
|
|
11192
12288
|
resolveHashedClientCssHref(clientOutputDir),
|
|
11193
12289
|
resolveHashedClientJsSrc(clientOutputDir),
|
|
11194
12290
|
resolveClientBootSrc(clientOutputDir),
|
|
11195
|
-
readFarmDocsModulePreloads(
|
|
11196
|
-
readFarmClientModulePreloads(
|
|
12291
|
+
readFarmDocsModulePreloads(path12.join(root, distDir)),
|
|
12292
|
+
readFarmClientModulePreloads(path12.join(root, distDir))
|
|
11197
12293
|
]);
|
|
11198
12294
|
let nativeStylesheets;
|
|
11199
12295
|
const encodedDocsModulePreloads = encodeFarmDocsModulePreloads(docsModulePreloads);
|
|
11200
12296
|
const encodedClientModulePreloads = encodeFarmClientModulePreloads(clientModulePreloads);
|
|
11201
12297
|
const encodedMobileShellClient = shouldBuildFarmMobileClient(config) ? encodeFarmMobileShellClient(
|
|
11202
12298
|
await finalizeFarmMobileClient({
|
|
11203
|
-
buildDir:
|
|
12299
|
+
buildDir: path12.join(root, distDir),
|
|
11204
12300
|
clientOutputDir,
|
|
11205
12301
|
webEntry: clientJsSrc,
|
|
11206
12302
|
webBoot: clientBootSrc,
|
|
@@ -11239,12 +12335,12 @@ async function buildNitroUniversal(config, routeManager, apiRouteManager, server
|
|
|
11239
12335
|
await fs4.mkdir(ssrOutputDir, { recursive: true });
|
|
11240
12336
|
await Promise.all(
|
|
11241
12337
|
Object.entries(ssrBundle).map(async ([fileName, output]) => {
|
|
11242
|
-
const filePath =
|
|
11243
|
-
await fs4.mkdir(
|
|
12338
|
+
const filePath = path12.join(ssrOutputDir, fileName);
|
|
12339
|
+
await fs4.mkdir(path12.dirname(filePath), { recursive: true });
|
|
11244
12340
|
await fs4.writeFile(filePath, output.type === "chunk" ? output.code : output.source);
|
|
11245
12341
|
})
|
|
11246
12342
|
);
|
|
11247
|
-
const nitroEntryPath =
|
|
12343
|
+
const nitroEntryPath = path12.join(ssrOutputDir, "nitro-entry.mjs");
|
|
11248
12344
|
const nodeAdapterModule = preset === "node-server" ? resolveNitroRuntimeDependency(root, "srvx/node") : null;
|
|
11249
12345
|
const hasNitroCacheRouteRules = hasFarmNitroCacheRouteRule(config.routeRules);
|
|
11250
12346
|
const nitroEntryCode = `
|
|
@@ -11452,20 +12548,20 @@ function toFarmNodeResponse(request, response) {
|
|
|
11452
12548
|
);
|
|
11453
12549
|
}
|
|
11454
12550
|
await fs4.writeFile(
|
|
11455
|
-
|
|
12551
|
+
path12.join(ssrOutputDir, FARM_DESKTOP_ENV_MODULE_FILE),
|
|
11456
12552
|
FARM_DESKTOP_ENV_MODULE_SOURCE
|
|
11457
12553
|
);
|
|
11458
12554
|
}
|
|
11459
|
-
const farmNodeServerEntryPath = preset === "node-server" ?
|
|
12555
|
+
const farmNodeServerEntryPath = preset === "node-server" ? path12.join(ssrOutputDir, "farm-node-server-entry.mjs") : null;
|
|
11460
12556
|
if (farmNodeServerEntryPath && nodeAdapterModule) {
|
|
11461
12557
|
await fs4.writeFile(
|
|
11462
|
-
|
|
12558
|
+
path12.join(ssrOutputDir, FARM_NODE_ENV_MODULE_FILE),
|
|
11463
12559
|
FARM_NODE_ENV_MODULE_SOURCE
|
|
11464
12560
|
);
|
|
11465
12561
|
await fs4.writeFile(
|
|
11466
12562
|
farmNodeServerEntryPath,
|
|
11467
12563
|
createFarmNodeServerEntry({
|
|
11468
|
-
nitroEntryFile:
|
|
12564
|
+
nitroEntryFile: path12.basename(nitroEntryPath),
|
|
11469
12565
|
nodeAdapterModule,
|
|
11470
12566
|
server: config.server,
|
|
11471
12567
|
websocketAdapterModule: resolveNitroRuntimeDependency(root, "crossws/adapters/node"),
|
|
@@ -11473,12 +12569,12 @@ function toFarmNodeResponse(request, response) {
|
|
|
11473
12569
|
})
|
|
11474
12570
|
);
|
|
11475
12571
|
}
|
|
11476
|
-
const farmBunServerEntryPath = preset === "bun" ?
|
|
12572
|
+
const farmBunServerEntryPath = preset === "bun" ? path12.join(ssrOutputDir, "farm-bun-server-entry.mjs") : null;
|
|
11477
12573
|
if (farmBunServerEntryPath) {
|
|
11478
12574
|
await fs4.writeFile(
|
|
11479
12575
|
farmBunServerEntryPath,
|
|
11480
12576
|
createFarmBunServerEntry({
|
|
11481
|
-
nitroEntryFile:
|
|
12577
|
+
nitroEntryFile: path12.basename(nitroEntryPath),
|
|
11482
12578
|
bunAdapterModule: resolveNitroRuntimeDependency(root, "srvx/bun"),
|
|
11483
12579
|
server: config.server,
|
|
11484
12580
|
websocketAdapterModule: resolveNitroRuntimeDependency(root, "crossws/adapters/bun"),
|
|
@@ -11486,7 +12582,7 @@ function toFarmNodeResponse(request, response) {
|
|
|
11486
12582
|
})
|
|
11487
12583
|
);
|
|
11488
12584
|
}
|
|
11489
|
-
const farmNetlifyEntryPath = preset === "netlify" ?
|
|
12585
|
+
const farmNetlifyEntryPath = preset === "netlify" ? path12.join(ssrOutputDir, "farm-netlify-entry.mjs") : null;
|
|
11490
12586
|
if (farmNetlifyEntryPath) {
|
|
11491
12587
|
await fs4.writeFile(
|
|
11492
12588
|
farmNetlifyEntryPath,
|
|
@@ -11495,24 +12591,46 @@ function toFarmNodeResponse(request, response) {
|
|
|
11495
12591
|
})
|
|
11496
12592
|
);
|
|
11497
12593
|
}
|
|
12594
|
+
const farmCloudflareEnvPath = preset === "cloudflare-pages" ? path12.join(ssrOutputDir, "farm-cloudflare-env.mjs") : null;
|
|
12595
|
+
if (farmCloudflareEnvPath) {
|
|
12596
|
+
await fs4.writeFile(
|
|
12597
|
+
farmCloudflareEnvPath,
|
|
12598
|
+
`export default function farmCloudflareEnv(event) {
|
|
12599
|
+
const env = event.req.runtime?.cloudflare?.env
|
|
12600
|
+
if (env) globalThis.__env__ = env
|
|
12601
|
+
}
|
|
12602
|
+
`
|
|
12603
|
+
);
|
|
12604
|
+
}
|
|
11498
12605
|
const prebuiltSSRPlugin = createExternalSSRBundlePlugin(
|
|
11499
12606
|
nitroEntryPath,
|
|
11500
12607
|
ssrOutputDir,
|
|
11501
12608
|
ssrEntryFile
|
|
11502
12609
|
);
|
|
11503
|
-
const configuredNitroRouteRules =
|
|
12610
|
+
const configuredNitroRouteRules = nitroRouteRulesBelowBasePath(
|
|
12611
|
+
shouldBuildFarmMobileClient(config) ? varyFarmNitroCacheRulesByShell(routeRulesToNitroRouteRules(config.routeRules)) : routeRulesToNitroRouteRules(config.routeRules),
|
|
12612
|
+
config.basePath,
|
|
12613
|
+
resolveFarmAPIServerBasePath(config.api)
|
|
12614
|
+
);
|
|
12615
|
+
const toPrerenderPublicPath = (route) => normalizeFarmTrailingSlashPathname(
|
|
12616
|
+
applyFarmBasePath(route, config.basePath),
|
|
12617
|
+
config.trailingSlash === true
|
|
12618
|
+
);
|
|
11504
12619
|
const prerenderNitroRouteRules = Object.fromEntries(
|
|
11505
12620
|
prerenderRoutes.map((route) => {
|
|
11506
12621
|
const configuredRule = configuredNitroRouteRules[route] || {};
|
|
11507
12622
|
return [
|
|
11508
|
-
route,
|
|
12623
|
+
toPrerenderPublicPath(route),
|
|
11509
12624
|
{
|
|
11510
12625
|
...configuredRule,
|
|
11511
12626
|
prerender: true,
|
|
11512
|
-
headers:
|
|
11513
|
-
|
|
11514
|
-
|
|
11515
|
-
|
|
12627
|
+
headers: withFarmEdgeGuardedPrerenderHeaders(
|
|
12628
|
+
{
|
|
12629
|
+
...getPrerenderRouteHeaders(route, configuredHeaderRoutes),
|
|
12630
|
+
...configuredRule.headers
|
|
12631
|
+
},
|
|
12632
|
+
edgeGuardedPrerenderRoutes.includes(route)
|
|
12633
|
+
)
|
|
11516
12634
|
}
|
|
11517
12635
|
];
|
|
11518
12636
|
})
|
|
@@ -11531,7 +12649,7 @@ function toFarmNodeResponse(request, response) {
|
|
|
11531
12649
|
// `src` directory), as Nitro handlers outside Farm's aliases.
|
|
11532
12650
|
serverDir: false,
|
|
11533
12651
|
serverEntry: false,
|
|
11534
|
-
buildDir:
|
|
12652
|
+
buildDir: path12.join(root, distDir, ".nitro"),
|
|
11535
12653
|
alias: resolveNitroInternalRuntimeAliases(root),
|
|
11536
12654
|
compatibilityDate: "2024-12-01",
|
|
11537
12655
|
output: resolveFarmNitroOutputConfig(preset, outputDir),
|
|
@@ -11559,7 +12677,7 @@ function toFarmNodeResponse(request, response) {
|
|
|
11559
12677
|
// answered independently, as by the production server, so keeping several
|
|
11560
12678
|
// in flight overlaps the worker's rendering with this thread's per-route work.
|
|
11561
12679
|
concurrency: Math.min(os.availableParallelism(), 8),
|
|
11562
|
-
routes: prerenderRoutes
|
|
12680
|
+
routes: prerenderRoutes.map(toPrerenderPublicPath)
|
|
11563
12681
|
}
|
|
11564
12682
|
} : {},
|
|
11565
12683
|
experimental: {
|
|
@@ -11579,6 +12697,7 @@ function toFarmNodeResponse(request, response) {
|
|
|
11579
12697
|
} : {},
|
|
11580
12698
|
// Use serverHandlers to define our workflow handler first, then the catch-all handler.
|
|
11581
12699
|
handlers: [
|
|
12700
|
+
...farmCloudflareEnvPath ? [{ route: "/**", middleware: true, handler: toPosixPath(farmCloudflareEnvPath) }] : [],
|
|
11582
12701
|
...farmWorkflows.handlerPath ? [
|
|
11583
12702
|
{
|
|
11584
12703
|
route: `${config.workflows.route}/**`,
|
|
@@ -11602,7 +12721,10 @@ function toFarmNodeResponse(request, response) {
|
|
|
11602
12721
|
rollupConfig: {
|
|
11603
12722
|
external: nitroRollupExternal,
|
|
11604
12723
|
plugins: [
|
|
11605
|
-
|
|
12724
|
+
// On Cloudflare, Nitro imports @vercel/og's `?module` wasm files as
|
|
12725
|
+
// precompiled modules, and bundles @vercel/og itself when the SSR
|
|
12726
|
+
// graph kept it external.
|
|
12727
|
+
...isCloudflareImagePreset(preset) ? [createVercelOgFontInlinePlugin()] : hasGeneratedMetadataImages && !useExternalMetadataImageRuntime ? [createMetadataImageWasmPlugin()] : [],
|
|
11606
12728
|
// Workers bundle React here rather than loading it from node_modules.
|
|
11607
12729
|
// Unenv rewrites `process` before Nitro's own replacements run, so
|
|
11608
12730
|
// React's development builds would otherwise ship next to production.
|
|
@@ -11619,7 +12741,7 @@ function toFarmNodeResponse(request, response) {
|
|
|
11619
12741
|
if (pluginManager) {
|
|
11620
12742
|
nitroConfig = await pluginManager.runHookSerial("beforeNitroBuild", nitroConfig);
|
|
11621
12743
|
}
|
|
11622
|
-
const expectedServerDir =
|
|
12744
|
+
const expectedServerDir = path12.join(outputDir, "server");
|
|
11623
12745
|
const customRollupKeys = Object.keys(nitroConfig.rollupConfig || {}).filter(
|
|
11624
12746
|
(key) => key !== "external" && key !== "plugins"
|
|
11625
12747
|
);
|
|
@@ -11632,11 +12754,13 @@ function toFarmNodeResponse(request, response) {
|
|
|
11632
12754
|
snapshotSSRRebundleOptions(nitroConfig)
|
|
11633
12755
|
);
|
|
11634
12756
|
const requestedBuilder = nitroConfig.builder ?? process.env.NITRO_BUILDER;
|
|
11635
|
-
const
|
|
12757
|
+
const nitroBuildIsFarms = (requestedBuilder === void 0 || requestedBuilder === "rollup" || requestedBuilder === "rolldown") && nitroConfig.sourcemap === false && !hasCustomOxcOptions && !hasLateBuildMutationConfig && !hasUnsupportedSSRRebundleOverrides && nitroConfig.rollupConfig?.external === nitroRollupExternal && !hasRollupPlugins(nitroConfig.rollupConfig?.plugins) && customRollupKeys.length === 0 && Boolean(
|
|
11636
12758
|
nitroConfig.handlers?.some(
|
|
11637
|
-
(handler) =>
|
|
12759
|
+
(handler) => path12.resolve(handler?.handler || "") === nitroEntryPath
|
|
11638
12760
|
)
|
|
11639
12761
|
);
|
|
12762
|
+
const canReusePrebuiltSSR = isPrebuiltSSRCandidate && nitroConfig.preset === "node-server" && nitroBuildIsFarms && path12.resolve(nitroConfig.output?.serverDir || "") === path12.resolve(expectedServerDir);
|
|
12763
|
+
const prerenderReusesPrebuiltSSR = prerenderRoutes.length > 0 && ssrExternalsArePackaged && nitroBuildIsFarms;
|
|
11640
12764
|
const selectRolldownBuilder = canReusePrebuiltSSR && requestedBuilder === void 0 && await canUseRolldownBuilder();
|
|
11641
12765
|
if (selectRolldownBuilder) nitroConfig.builder = "rolldown";
|
|
11642
12766
|
const useRolldownBuilder = canReusePrebuiltSSR && (nitroConfig.builder ?? process.env.NITRO_BUILDER) === "rolldown";
|
|
@@ -11644,13 +12768,14 @@ function toFarmNodeResponse(request, response) {
|
|
|
11644
12768
|
const keepServerNames = !(config.docs?.enabled && config.docs.adapter?.server);
|
|
11645
12769
|
const useFarmServerMinifier = shouldMinify && nitroConfig.sourcemap === false && !hasCustomOxcOptions && !hasLateBuildMutationConfig;
|
|
11646
12770
|
const serverChunkMinifier = useFarmServerMinifier ? createServerChunkMinifyPlugin({ keepNames: keepServerNames, target: "esnext" }) : null;
|
|
11647
|
-
|
|
12771
|
+
const ssrRollupPlugin = canReusePrebuiltSSR ? prebuiltSSRPlugin : createServerReadSSRAssetsPlugin(ssrBundle, ssrOutputDir);
|
|
12772
|
+
if (ssrRollupPlugin) {
|
|
11648
12773
|
const configuredRollupPlugins = nitroConfig.rollupConfig?.plugins;
|
|
11649
12774
|
nitroConfig.rollupConfig = {
|
|
11650
12775
|
...nitroConfig.rollupConfig,
|
|
11651
12776
|
plugins: [
|
|
11652
12777
|
...Array.isArray(configuredRollupPlugins) ? configuredRollupPlugins : configuredRollupPlugins ? [configuredRollupPlugins] : [],
|
|
11653
|
-
|
|
12778
|
+
ssrRollupPlugin
|
|
11654
12779
|
]
|
|
11655
12780
|
};
|
|
11656
12781
|
}
|
|
@@ -11675,7 +12800,9 @@ function toFarmNodeResponse(request, response) {
|
|
|
11675
12800
|
if (config.md?.enabled) {
|
|
11676
12801
|
nitroInstance.hooks.hook("prerender:generate", (route) => {
|
|
11677
12802
|
if (!route.contents || !route.contentType?.toLowerCase().includes("html")) return;
|
|
11678
|
-
const alternatePath = getFarmMarkdownAlternatePath(config.md, route.route
|
|
12803
|
+
const alternatePath = getFarmMarkdownAlternatePath(config.md, route.route, {
|
|
12804
|
+
routePathname: (pathname) => routeManager.toRoutePathname(pathname)
|
|
12805
|
+
});
|
|
11679
12806
|
if (!alternatePath) return;
|
|
11680
12807
|
const routeRule = nitroInstance.options.routeRules[route.route] || {};
|
|
11681
12808
|
const alternate = `<${alternatePath}>; rel="alternate"; type="text/markdown"`;
|
|
@@ -11728,7 +12855,24 @@ function toFarmNodeResponse(request, response) {
|
|
|
11728
12855
|
});
|
|
11729
12856
|
await nitroBuilder.prepare(nitroInstance);
|
|
11730
12857
|
await nitroBuilder.copyPublicAssets(nitroInstance);
|
|
11731
|
-
if (
|
|
12858
|
+
if (prerenderReusesPrebuiltSSR && !canReusePrebuiltSSR) {
|
|
12859
|
+
nitroInstance.hooks.hook("prerender:config", (prerendererConfig) => {
|
|
12860
|
+
const configuredPlugins = prerendererConfig.rollupConfig?.plugins;
|
|
12861
|
+
const plugins = Array.isArray(configuredPlugins) ? configuredPlugins : configuredPlugins ? [configuredPlugins] : [];
|
|
12862
|
+
prerendererConfig.rollupConfig = {
|
|
12863
|
+
...prerendererConfig.rollupConfig,
|
|
12864
|
+
plugins: [...plugins.filter((plugin) => plugin !== ssrRollupPlugin), prebuiltSSRPlugin]
|
|
12865
|
+
};
|
|
12866
|
+
prerendererConfig.output = {
|
|
12867
|
+
...prerendererConfig.output,
|
|
12868
|
+
serverDir: path12.join(
|
|
12869
|
+
prerendererConfig.buildDir ?? path12.join(root, distDir, ".nitro"),
|
|
12870
|
+
"prerender"
|
|
12871
|
+
)
|
|
12872
|
+
};
|
|
12873
|
+
});
|
|
12874
|
+
}
|
|
12875
|
+
if (prerenderReusesPrebuiltSSR) {
|
|
11732
12876
|
nitroInstance.hooks.hook("prerender:init", (prerenderer) => {
|
|
11733
12877
|
if (useRolldownBuilder) {
|
|
11734
12878
|
prerenderer.hooks.hook("rollup:before", (_nitro, rollupConfig) => {
|
|
@@ -11738,10 +12882,10 @@ function toFarmNodeResponse(request, response) {
|
|
|
11738
12882
|
});
|
|
11739
12883
|
}
|
|
11740
12884
|
prerenderer.hooks.hook("compiled", async () => {
|
|
11741
|
-
const prerenderServerDir =
|
|
12885
|
+
const prerenderServerDir = prerenderer.options.output.serverDir;
|
|
11742
12886
|
await copyPrebuiltSSRBundle(
|
|
11743
12887
|
ssrBundle,
|
|
11744
|
-
|
|
12888
|
+
path12.join(prerenderServerDir, FARM_SSR_OUTPUT_DIR),
|
|
11745
12889
|
null,
|
|
11746
12890
|
fs4
|
|
11747
12891
|
);
|
|
@@ -11817,7 +12961,7 @@ function toFarmNodeResponse(request, response) {
|
|
|
11817
12961
|
const copyResults = await Promise.allSettled([
|
|
11818
12962
|
prebuiltSSRFilesResult.value ? writeSSRBundleFiles(
|
|
11819
12963
|
prebuiltSSRFilesResult.value,
|
|
11820
|
-
|
|
12964
|
+
path12.join(outputDir, "server", FARM_SSR_OUTPUT_DIR),
|
|
11821
12965
|
fs4
|
|
11822
12966
|
) : Promise.resolve(),
|
|
11823
12967
|
runtimeCopyPromise
|
|
@@ -11827,14 +12971,17 @@ function toFarmNodeResponse(request, response) {
|
|
|
11827
12971
|
);
|
|
11828
12972
|
if (failedCopy) throw failedCopy.reason;
|
|
11829
12973
|
if (canReusePrebuiltSSR) {
|
|
11830
|
-
await registerPrebuiltSSRPackageImport(
|
|
12974
|
+
await registerPrebuiltSSRPackageImport(path12.join(outputDir, "server"), ssrEntryFile, fs4);
|
|
11831
12975
|
logger.info("\u26A1 Reused Farm's prebuilt SSR bundle for the Node output");
|
|
11832
12976
|
}
|
|
11833
12977
|
if (useRolldownBuilder) {
|
|
11834
12978
|
logger.info("\u26A1 Built the Node adapter with Rolldown");
|
|
11835
12979
|
}
|
|
11836
12980
|
if (preset === "node-server" && !desktopServerEntry) {
|
|
11837
|
-
await installFarmCompileCacheLauncher(
|
|
12981
|
+
await installFarmCompileCacheLauncher(path12.join(outputDir, "server"), fs4);
|
|
12982
|
+
}
|
|
12983
|
+
if (preset.startsWith("cloudflare")) {
|
|
12984
|
+
await populateCloudflareProcessEnv(nitroInstance.options.output.serverDir, fs4);
|
|
11838
12985
|
}
|
|
11839
12986
|
if (pluginManager) {
|
|
11840
12987
|
await pluginManager.runHookParallel("afterNitroBuild", {
|
|
@@ -11852,24 +12999,46 @@ function toFarmNodeResponse(request, response) {
|
|
|
11852
12999
|
config,
|
|
11853
13000
|
farmWorkflows,
|
|
11854
13001
|
routeRuntimeManifest,
|
|
11855
|
-
farmCron.provider === "host" ? farmCron.jobs : []
|
|
13002
|
+
farmCron.provider === "host" ? farmCron.jobs : [],
|
|
13003
|
+
{
|
|
13004
|
+
buildDir: path12.join(root, distDir),
|
|
13005
|
+
middlewareRoutes: edgeMiddlewareRoutes,
|
|
13006
|
+
guardedPages: edgeGuardedPrerenderRoutes
|
|
13007
|
+
}
|
|
11856
13008
|
);
|
|
11857
13009
|
}
|
|
11858
13010
|
logger.success(`\u2705 Nitro build completed with preset: ${preset}`);
|
|
11859
13011
|
}
|
|
11860
13012
|
function resolveFarmNitroOutputConfig(preset, outputDir) {
|
|
11861
|
-
const isVercel = preset === "vercel"
|
|
13013
|
+
const isVercel = preset === "vercel";
|
|
11862
13014
|
return {
|
|
11863
13015
|
dir: outputDir,
|
|
11864
13016
|
...preset === "node-server" ? {
|
|
11865
|
-
serverDir:
|
|
11866
|
-
publicDir:
|
|
13017
|
+
serverDir: path12.join(outputDir, "server"),
|
|
13018
|
+
publicDir: path12.join(outputDir, "public")
|
|
11867
13019
|
} : isVercel ? {
|
|
11868
|
-
serverDir:
|
|
11869
|
-
publicDir:
|
|
13020
|
+
serverDir: path12.join(outputDir, "functions", "__nitro.func"),
|
|
13021
|
+
publicDir: path12.join(outputDir, "static")
|
|
11870
13022
|
} : {}
|
|
11871
13023
|
};
|
|
11872
13024
|
}
|
|
13025
|
+
async function populateCloudflareProcessEnv(serverDir, fs4) {
|
|
13026
|
+
const wranglerPath = path12.join(serverDir, "wrangler.json");
|
|
13027
|
+
let source;
|
|
13028
|
+
try {
|
|
13029
|
+
source = await fs4.readFile(wranglerPath, "utf8");
|
|
13030
|
+
} catch (error) {
|
|
13031
|
+
if (error.code === "ENOENT") return;
|
|
13032
|
+
throw error;
|
|
13033
|
+
}
|
|
13034
|
+
const wrangler = JSON.parse(source);
|
|
13035
|
+
const flags = resolveCloudflareProcessEnvFlags(wrangler);
|
|
13036
|
+
if (!flags) return;
|
|
13037
|
+
await fs4.writeFile(
|
|
13038
|
+
wranglerPath,
|
|
13039
|
+
JSON.stringify({ ...wrangler, compatibility_flags: flags }, null, 2)
|
|
13040
|
+
);
|
|
13041
|
+
}
|
|
11873
13042
|
function prepareSSRBundleFiles(ssrBundle, minifyOptions) {
|
|
11874
13043
|
return Promise.all(
|
|
11875
13044
|
Object.entries(ssrBundle).map(async ([fileName, output]) => ({
|
|
@@ -11882,8 +13051,8 @@ async function writeSSRBundleFiles(files, targetDir, fs4) {
|
|
|
11882
13051
|
await fs4.rm(targetDir, { recursive: true, force: true });
|
|
11883
13052
|
await Promise.all(
|
|
11884
13053
|
files.map(async ({ fileName, contents }) => {
|
|
11885
|
-
const targetPath =
|
|
11886
|
-
await fs4.mkdir(
|
|
13054
|
+
const targetPath = path12.join(targetDir, fileName);
|
|
13055
|
+
await fs4.mkdir(path12.dirname(targetPath), { recursive: true });
|
|
11887
13056
|
await fs4.writeFile(targetPath, contents);
|
|
11888
13057
|
})
|
|
11889
13058
|
);
|
|
@@ -11892,8 +13061,8 @@ async function copyPrebuiltSSRBundle(ssrBundle, targetDir, minifyOptions, fs4) {
|
|
|
11892
13061
|
await writeSSRBundleFiles(await prepareSSRBundleFiles(ssrBundle, minifyOptions), targetDir, fs4);
|
|
11893
13062
|
}
|
|
11894
13063
|
async function installFarmCompileCacheLauncher(serverDir, fs4) {
|
|
11895
|
-
const entryPath =
|
|
11896
|
-
const serverPath =
|
|
13064
|
+
const entryPath = path12.join(serverDir, "index.mjs");
|
|
13065
|
+
const serverPath = path12.join(serverDir, FARM_SERVER_MODULE_FILE);
|
|
11897
13066
|
const entry = await fs4.readFile(entryPath, "utf8").catch((error) => {
|
|
11898
13067
|
if (error.code === "ENOENT") return null;
|
|
11899
13068
|
throw error;
|
|
@@ -11902,11 +13071,11 @@ async function installFarmCompileCacheLauncher(serverDir, fs4) {
|
|
|
11902
13071
|
if (entry.includes(`./${FARM_SERVER_MODULE_FILE}`)) return false;
|
|
11903
13072
|
await fs4.rename(entryPath, serverPath);
|
|
11904
13073
|
await fs4.writeFile(entryPath, createFarmCompileCacheLauncher(FARM_SERVER_MODULE_FILE));
|
|
11905
|
-
await fs4.rm(
|
|
13074
|
+
await fs4.rm(path12.join(serverDir, FARM_COMPILE_CACHE_DIR), { recursive: true, force: true });
|
|
11906
13075
|
return true;
|
|
11907
13076
|
}
|
|
11908
13077
|
async function registerPrebuiltSSRPackageImport(serverDir, ssrEntryFile, fs4) {
|
|
11909
|
-
const packagePath =
|
|
13078
|
+
const packagePath = path12.join(serverDir, "package.json");
|
|
11910
13079
|
const packageJSON = await fs4.readFile(packagePath, "utf8").then((contents) => JSON.parse(contents)).catch((error) => {
|
|
11911
13080
|
if (error.code === "ENOENT") return { type: "module" };
|
|
11912
13081
|
throw error;
|
|
@@ -11934,19 +13103,19 @@ async function moveVercelOutputPath(src, dest, fs4) {
|
|
|
11934
13103
|
await fs4.cp(src, dest, { recursive: true, force: true });
|
|
11935
13104
|
await fs4.rm(src, { recursive: true, force: true });
|
|
11936
13105
|
}
|
|
11937
|
-
async function postProcessVercelOutput(root, outputDir, fs4, config, farmWorkflows, routeRuntimeManifest, cronJobs) {
|
|
11938
|
-
const serverDir =
|
|
11939
|
-
const functionsDir =
|
|
11940
|
-
const nitroFuncDir =
|
|
11941
|
-
const staticDir =
|
|
11942
|
-
const publicDir =
|
|
13106
|
+
async function postProcessVercelOutput(root, outputDir, fs4, config, farmWorkflows, routeRuntimeManifest, cronJobs, edgeMiddleware) {
|
|
13107
|
+
const serverDir = path12.join(outputDir, "server");
|
|
13108
|
+
const functionsDir = path12.join(outputDir, "functions");
|
|
13109
|
+
const nitroFuncDir = path12.join(functionsDir, "__nitro.func");
|
|
13110
|
+
const staticDir = path12.join(outputDir, "static");
|
|
13111
|
+
const publicDir = path12.join(outputDir, "public");
|
|
11943
13112
|
await fs4.mkdir(nitroFuncDir, { recursive: true });
|
|
11944
13113
|
const serverContents = await fs4.readdir(serverDir).catch((error) => {
|
|
11945
13114
|
if (error.code === "ENOENT") return [];
|
|
11946
13115
|
throw error;
|
|
11947
13116
|
});
|
|
11948
13117
|
for (const file of serverContents) {
|
|
11949
|
-
await moveVercelOutputPath(
|
|
13118
|
+
await moveVercelOutputPath(path12.join(serverDir, file), path12.join(nitroFuncDir, file), fs4);
|
|
11950
13119
|
}
|
|
11951
13120
|
if (serverContents.length > 0) await fs4.rm(serverDir, { recursive: true, force: true });
|
|
11952
13121
|
try {
|
|
@@ -11956,7 +13125,7 @@ async function postProcessVercelOutput(root, outputDir, fs4, config, farmWorkflo
|
|
|
11956
13125
|
}
|
|
11957
13126
|
await copyFarmDocsContentForVercel(config, root, nitroFuncDir, fs4);
|
|
11958
13127
|
await copyPrismaClientForVercel(root, nitroFuncDir, fs4);
|
|
11959
|
-
const configPath =
|
|
13128
|
+
const configPath = path12.join(outputDir, "config.json");
|
|
11960
13129
|
const configContent = await fs4.readFile(configPath, "utf-8");
|
|
11961
13130
|
const vercelConfig = JSON.parse(configContent);
|
|
11962
13131
|
const runtimeRoutes = await createFarmVercelRouteRuntimeFunctions(
|
|
@@ -11965,9 +13134,24 @@ async function postProcessVercelOutput(root, outputDir, fs4, config, farmWorkflo
|
|
|
11965
13134
|
fs4,
|
|
11966
13135
|
config.basePath
|
|
11967
13136
|
);
|
|
13137
|
+
const edgeMiddlewareRoutes = edgeMiddleware.middlewareRoutes.filter(
|
|
13138
|
+
(route) => edgeMiddleware.guardedPages.some((pathname) => appMiddlewareMayHandlePath([route], pathname))
|
|
13139
|
+
);
|
|
13140
|
+
if (edgeMiddlewareRoutes.length > 0) {
|
|
13141
|
+
await writeFarmVercelEdgeMiddlewareFunction({
|
|
13142
|
+
root,
|
|
13143
|
+
outputDir,
|
|
13144
|
+
buildDir: edgeMiddleware.buildDir,
|
|
13145
|
+
config,
|
|
13146
|
+
routes: edgeMiddlewareRoutes,
|
|
13147
|
+
guardedPages: edgeMiddleware.guardedPages,
|
|
13148
|
+
fs: fs4
|
|
13149
|
+
});
|
|
13150
|
+
}
|
|
11968
13151
|
vercelConfig.routes = buildFarmVercelRoutes({
|
|
11969
13152
|
presetRoutes: Array.isArray(vercelConfig.routes) ? vercelConfig.routes : [],
|
|
11970
|
-
runtimeRoutes
|
|
13153
|
+
runtimeRoutes,
|
|
13154
|
+
middlewareRoutes: edgeMiddlewareRoutes.length > 0 ? [createFarmVercelEdgeMiddlewareRoute(edgeMiddleware.guardedPages, config.basePath)] : []
|
|
11971
13155
|
});
|
|
11972
13156
|
const vercelConfigWithWorkflowCrons = applyFarmWorkflowVercelCrons(
|
|
11973
13157
|
vercelConfig,
|
|
@@ -11984,7 +13168,7 @@ async function copyFarmDocsContentForVercel(config, root, nitroFuncDir, fs4) {
|
|
|
11984
13168
|
mainRoot,
|
|
11985
13169
|
root,
|
|
11986
13170
|
config.srcDir,
|
|
11987
|
-
|
|
13171
|
+
path12.join(nitroFuncDir, "farm-docs-content"),
|
|
11988
13172
|
fs4
|
|
11989
13173
|
);
|
|
11990
13174
|
for (const [index, docsRoot] of extraRoots.entries()) {
|
|
@@ -11992,7 +13176,7 @@ async function copyFarmDocsContentForVercel(config, root, nitroFuncDir, fs4) {
|
|
|
11992
13176
|
docsRoot,
|
|
11993
13177
|
root,
|
|
11994
13178
|
config.srcDir,
|
|
11995
|
-
|
|
13179
|
+
path12.join(nitroFuncDir, "farm-docs-roots", String(index)),
|
|
11996
13180
|
fs4
|
|
11997
13181
|
);
|
|
11998
13182
|
}
|
|
@@ -12003,18 +13187,24 @@ async function copyFarmDocsRootContent(docs, root, srcDir, bundledContentDir, fs
|
|
|
12003
13187
|
const lastModifiedManifest = createFarmDocsLastModifiedManifest(docsContentDir, {
|
|
12004
13188
|
fallback: "now"
|
|
12005
13189
|
});
|
|
13190
|
+
const undatedPages = lastModifiedManifest.unknown?.length ?? 0;
|
|
13191
|
+
if (undatedPages > 0) {
|
|
13192
|
+
logger.warn(
|
|
13193
|
+
`${undatedPages} docs page(s) were last changed before this shallow clone's Git history, so they show no "Last updated" date. Build from a full clone (git fetch --unshallow) or set lastModified in the page's frontmatter.`
|
|
13194
|
+
);
|
|
13195
|
+
}
|
|
12006
13196
|
await fs4.rm(bundledContentDir, { recursive: true, force: true });
|
|
12007
|
-
await fs4.mkdir(
|
|
13197
|
+
await fs4.mkdir(path12.dirname(bundledContentDir), { recursive: true });
|
|
12008
13198
|
await fs4.cp(docsContentDir, bundledContentDir, {
|
|
12009
13199
|
recursive: true,
|
|
12010
13200
|
force: true
|
|
12011
13201
|
});
|
|
12012
13202
|
await fs4.writeFile(
|
|
12013
|
-
|
|
13203
|
+
path12.join(bundledContentDir, FARM_DOCS_LAST_MODIFIED_MANIFEST),
|
|
12014
13204
|
`${JSON.stringify(lastModifiedManifest, null, 2)}
|
|
12015
13205
|
`
|
|
12016
13206
|
);
|
|
12017
|
-
logger.info(`\u{1F4DA} Bundled docs content for Vercel: ${
|
|
13207
|
+
logger.info(`\u{1F4DA} Bundled docs content for Vercel: ${path12.relative(root, docsContentDir)}`);
|
|
12018
13208
|
}
|
|
12019
13209
|
function resolveServerFunctionPlatform(preset) {
|
|
12020
13210
|
return preset === "vercel" || preset === "netlify" ? { os: "linux", cpu: "x64", libc: "glibc" } : null;
|
|
@@ -12031,20 +13221,20 @@ function platformFieldAllows(field, value) {
|
|
|
12031
13221
|
}
|
|
12032
13222
|
async function stageSharpRuntime(config, root, distDir, fs4, preset) {
|
|
12033
13223
|
const functionPlatform = resolveServerFunctionPlatform(preset);
|
|
12034
|
-
const projectRequire =
|
|
13224
|
+
const projectRequire = createRequire2(path12.join(root, "package.json"));
|
|
12035
13225
|
let sharpRequire = projectRequire;
|
|
12036
13226
|
if (!resolvePackageJson(projectRequire, "sharp")) {
|
|
12037
13227
|
try {
|
|
12038
|
-
sharpRequire =
|
|
13228
|
+
sharpRequire = createRequire2(projectRequire.resolve("@farm.js/core"));
|
|
12039
13229
|
} catch {
|
|
12040
13230
|
}
|
|
12041
13231
|
}
|
|
12042
13232
|
const copiedPackages = /* @__PURE__ */ new Map();
|
|
12043
13233
|
const packageCopies = /* @__PURE__ */ new Map();
|
|
12044
|
-
const stageRoot =
|
|
13234
|
+
const stageRoot = path12.join(root, distDir, "tmp");
|
|
12045
13235
|
await fs4.mkdir(stageRoot, { recursive: true });
|
|
12046
|
-
const stageDir = await fs4.mkdtemp(
|
|
12047
|
-
const targetNodeModules =
|
|
13236
|
+
const stageDir = await fs4.mkdtemp(path12.join(stageRoot, "sharp-runtime-"));
|
|
13237
|
+
const targetNodeModules = path12.join(stageDir, "node_modules");
|
|
12048
13238
|
function copyPackage(packageName, parentRequire) {
|
|
12049
13239
|
const activeCopy = packageCopies.get(packageName);
|
|
12050
13240
|
if (activeCopy) return activeCopy;
|
|
@@ -12057,11 +13247,11 @@ async function stageSharpRuntime(config, root, distDir, fs4, preset) {
|
|
|
12057
13247
|
if (!packageJsonPath) return;
|
|
12058
13248
|
const packageJson = JSON.parse(await fs4.readFile(packageJsonPath, "utf8"));
|
|
12059
13249
|
if (functionPlatform && !packageSupportsPlatform(packageJson, functionPlatform)) return;
|
|
12060
|
-
const packageDir =
|
|
12061
|
-
const targetDir =
|
|
13250
|
+
const packageDir = path12.dirname(packageJsonPath);
|
|
13251
|
+
const targetDir = path12.join(targetNodeModules, ...packageName.split("/"));
|
|
12062
13252
|
copiedPackages.set(packageName, String(packageJson.version || "*"));
|
|
12063
|
-
await fs4.mkdir(
|
|
12064
|
-
const packageRequire =
|
|
13253
|
+
await fs4.mkdir(path12.dirname(targetDir), { recursive: true });
|
|
13254
|
+
const packageRequire = createRequire2(packageJsonPath);
|
|
12065
13255
|
const dependencies = {
|
|
12066
13256
|
...packageJson.dependencies,
|
|
12067
13257
|
...packageJson.optionalDependencies
|
|
@@ -12095,8 +13285,8 @@ async function stageSharpRuntime(config, root, distDir, fs4, preset) {
|
|
|
12095
13285
|
};
|
|
12096
13286
|
}
|
|
12097
13287
|
async function installStagedSharpRuntime(staged, nitroFuncDir, fs4) {
|
|
12098
|
-
const stagedNodeModules =
|
|
12099
|
-
const targetNodeModules =
|
|
13288
|
+
const stagedNodeModules = path12.join(staged.stageDir, "node_modules");
|
|
13289
|
+
const targetNodeModules = path12.join(nitroFuncDir, "node_modules");
|
|
12100
13290
|
try {
|
|
12101
13291
|
await mergeStagedDirectory(stagedNodeModules, targetNodeModules, fs4);
|
|
12102
13292
|
const functionPackage = await readNitroOutputPackage(nitroFuncDir, fs4);
|
|
@@ -12124,8 +13314,8 @@ async function mergeStagedDirectory(sourceDir, targetDir, fs4) {
|
|
|
12124
13314
|
const entries = await fs4.readdir(sourceDir, { withFileTypes: true });
|
|
12125
13315
|
await settleAllOrThrow(
|
|
12126
13316
|
entries.map(async (entry) => {
|
|
12127
|
-
const sourcePath =
|
|
12128
|
-
const targetPath =
|
|
13317
|
+
const sourcePath = path12.join(sourceDir, entry.name);
|
|
13318
|
+
const targetPath = path12.join(targetDir, entry.name);
|
|
12129
13319
|
try {
|
|
12130
13320
|
await fs4.rename(sourcePath, targetPath);
|
|
12131
13321
|
return;
|
|
@@ -12152,17 +13342,17 @@ async function mergeStagedDirectory(sourceDir, targetDir, fs4) {
|
|
|
12152
13342
|
function assertMetadataImageRuntimeInstalled(root, metadataImageRoutes) {
|
|
12153
13343
|
const generated = metadataImageRoutes.find((image) => image.sourceType === "module");
|
|
12154
13344
|
if (!generated || resolveMetadataImageRuntimePackageJson(root)) return;
|
|
12155
|
-
const file = generated.modulePath ? toPosixPath(
|
|
13345
|
+
const file = generated.modulePath ? toPosixPath(path12.relative(root, generated.modulePath)) : "";
|
|
12156
13346
|
throw new Error(
|
|
12157
13347
|
`${file || "A generated metadata image"} renders with @vercel/og, which is not installed. ${VERCEL_OG_INSTALL_HINT}`
|
|
12158
13348
|
);
|
|
12159
13349
|
}
|
|
12160
13350
|
function resolveMetadataImageRuntimePackageJson(root) {
|
|
12161
|
-
const projectRequire =
|
|
13351
|
+
const projectRequire = createRequire2(path12.join(root, "package.json"));
|
|
12162
13352
|
const packageJsonPath = resolvePackageJson(projectRequire, "@vercel/og");
|
|
12163
13353
|
if (packageJsonPath) return packageJsonPath;
|
|
12164
13354
|
try {
|
|
12165
|
-
return resolvePackageJson(
|
|
13355
|
+
return resolvePackageJson(createRequire2(projectRequire.resolve("@farm.js/core")), "@vercel/og");
|
|
12166
13356
|
} catch {
|
|
12167
13357
|
return null;
|
|
12168
13358
|
}
|
|
@@ -12171,9 +13361,9 @@ async function copyMetadataImageRuntime(root, nitroFuncDir, fs4) {
|
|
|
12171
13361
|
const packageJsonPath = resolveMetadataImageRuntimePackageJson(root);
|
|
12172
13362
|
if (!packageJsonPath) return;
|
|
12173
13363
|
const packageJson = JSON.parse(await fs4.readFile(packageJsonPath, "utf8"));
|
|
12174
|
-
const packageDir =
|
|
12175
|
-
const targetDir =
|
|
12176
|
-
await fs4.mkdir(
|
|
13364
|
+
const packageDir = path12.dirname(packageJsonPath);
|
|
13365
|
+
const targetDir = path12.join(nitroFuncDir, "node_modules", "@vercel", "og");
|
|
13366
|
+
await fs4.mkdir(path12.dirname(targetDir), { recursive: true });
|
|
12177
13367
|
await fs4.cp(packageDir, targetDir, {
|
|
12178
13368
|
recursive: true,
|
|
12179
13369
|
force: true,
|
|
@@ -12189,7 +13379,7 @@ async function copyMetadataImageRuntime(root, nitroFuncDir, fs4) {
|
|
|
12189
13379
|
logger.info("\u{1F5BC}\uFE0F Bundled generated metadata image runtime");
|
|
12190
13380
|
}
|
|
12191
13381
|
async function readNitroOutputPackage(outputDir, fs4) {
|
|
12192
|
-
const packagePath =
|
|
13382
|
+
const packagePath = path12.join(outputDir, "package.json");
|
|
12193
13383
|
return fs4.readFile(packagePath, "utf8").then((contents) => JSON.parse(contents)).catch((error) => {
|
|
12194
13384
|
if (error.code === "ENOENT") return {};
|
|
12195
13385
|
throw error;
|
|
@@ -12198,7 +13388,7 @@ async function readNitroOutputPackage(outputDir, fs4) {
|
|
|
12198
13388
|
async function writeNitroOutputPackage(outputDir, packageJson, fs4) {
|
|
12199
13389
|
await fs4.mkdir(outputDir, { recursive: true });
|
|
12200
13390
|
await fs4.writeFile(
|
|
12201
|
-
|
|
13391
|
+
path12.join(outputDir, "package.json"),
|
|
12202
13392
|
`${JSON.stringify(packageJson, null, 2)}
|
|
12203
13393
|
`
|
|
12204
13394
|
);
|
|
@@ -12214,9 +13404,9 @@ function resolvePackageJson(parentRequire, packageName) {
|
|
|
12214
13404
|
}
|
|
12215
13405
|
}
|
|
12216
13406
|
try {
|
|
12217
|
-
let directory =
|
|
12218
|
-
while (directory !==
|
|
12219
|
-
const candidate =
|
|
13407
|
+
let directory = path12.dirname(metadataModule ?? parentRequire.resolve(packageName));
|
|
13408
|
+
while (directory !== path12.dirname(directory)) {
|
|
13409
|
+
const candidate = path12.join(directory, "package.json");
|
|
12220
13410
|
if (existsSync2(candidate)) {
|
|
12221
13411
|
try {
|
|
12222
13412
|
const manifest = JSON.parse(readFileSync(candidate, "utf8"));
|
|
@@ -12224,31 +13414,40 @@ function resolvePackageJson(parentRequire, packageName) {
|
|
|
12224
13414
|
} catch {
|
|
12225
13415
|
}
|
|
12226
13416
|
}
|
|
12227
|
-
if (
|
|
12228
|
-
directory =
|
|
13417
|
+
if (path12.basename(directory) === "node_modules") break;
|
|
13418
|
+
directory = path12.dirname(directory);
|
|
12229
13419
|
}
|
|
12230
13420
|
} catch {
|
|
12231
13421
|
}
|
|
12232
13422
|
return null;
|
|
12233
13423
|
}
|
|
12234
|
-
async function
|
|
12235
|
-
|
|
12236
|
-
|
|
12237
|
-
|
|
12238
|
-
|
|
12239
|
-
|
|
12240
|
-
|
|
13424
|
+
async function resolveProjectInstalledPackageDir(root, packageName, fs4) {
|
|
13425
|
+
let directory = path12.resolve(root);
|
|
13426
|
+
while (true) {
|
|
13427
|
+
const candidate = path12.join(directory, "node_modules", ...packageName.split("/"));
|
|
13428
|
+
try {
|
|
13429
|
+
const packageDir = await fs4.realpath(candidate);
|
|
13430
|
+
if ((await fs4.stat(path12.join(packageDir, "package.json"))).isFile()) return packageDir;
|
|
13431
|
+
} catch {
|
|
13432
|
+
}
|
|
13433
|
+
const parent = path12.dirname(directory);
|
|
13434
|
+
if (parent === directory) return null;
|
|
13435
|
+
directory = parent;
|
|
12241
13436
|
}
|
|
12242
|
-
|
|
13437
|
+
}
|
|
13438
|
+
async function copyPrismaClientForVercel(root, nitroFuncDir, fs4) {
|
|
13439
|
+
const prismaClientDir = await resolveProjectInstalledPackageDir(root, "@prisma/client", fs4);
|
|
13440
|
+
if (!prismaClientDir) return;
|
|
13441
|
+
const generatedClientDir = path12.join(prismaClientDir, "..", "..", ".prisma", "client");
|
|
12243
13442
|
try {
|
|
12244
13443
|
await fs4.access(generatedClientDir);
|
|
12245
13444
|
} catch {
|
|
12246
13445
|
return;
|
|
12247
13446
|
}
|
|
12248
|
-
const targetNodeModules =
|
|
12249
|
-
const targetPrismaScopeDir =
|
|
12250
|
-
const targetGeneratedDir =
|
|
12251
|
-
const targetClientDir =
|
|
13447
|
+
const targetNodeModules = path12.join(nitroFuncDir, "node_modules");
|
|
13448
|
+
const targetPrismaScopeDir = path12.join(targetNodeModules, "@prisma");
|
|
13449
|
+
const targetGeneratedDir = path12.join(targetNodeModules, ".prisma", "client");
|
|
13450
|
+
const targetClientDir = path12.join(targetPrismaScopeDir, "client");
|
|
12252
13451
|
await fs4.mkdir(targetPrismaScopeDir, { recursive: true });
|
|
12253
13452
|
await fs4.cp(prismaClientDir, targetClientDir, {
|
|
12254
13453
|
recursive: true,
|
|
@@ -12258,7 +13457,7 @@ async function copyPrismaClientForVercel(root, nitroFuncDir, fs4) {
|
|
|
12258
13457
|
recursive: true,
|
|
12259
13458
|
force: true
|
|
12260
13459
|
});
|
|
12261
|
-
const clientPackagePath =
|
|
13460
|
+
const clientPackagePath = path12.join(prismaClientDir, "package.json");
|
|
12262
13461
|
const [functionPackage, clientPackageContent] = await Promise.all([
|
|
12263
13462
|
readNitroOutputPackage(nitroFuncDir, fs4),
|
|
12264
13463
|
fs4.readFile(clientPackagePath, "utf-8")
|
|
@@ -12376,9 +13575,7 @@ async function buildWithProductionNodeEnv(inputConfig, options) {
|
|
|
12376
13575
|
if (config.docs?.enabled) await loadFarmDocsEngine();
|
|
12377
13576
|
pluginManager.updateContext({ config });
|
|
12378
13577
|
const { root, preset, srcDir, distDir, deployOutputDir } = targets;
|
|
12379
|
-
usePackageClientBoundaryCacheFile(
|
|
12380
|
-
path11.resolve(root, distDir, "cache", "client-boundaries.json")
|
|
12381
|
-
);
|
|
13578
|
+
usePackageClientBoundaryCacheFile(resolvePackageClientBoundaryCacheFile(root, distDir));
|
|
12382
13579
|
logger.info(`\u{1F69C} Building Farm.js application with preset: ${preset}...`);
|
|
12383
13580
|
await pluginManager.setupPlugins();
|
|
12384
13581
|
await pluginManager.runHookParallel("beforeBundle", {
|
|
@@ -12446,9 +13643,9 @@ async function buildWithProductionNodeEnv(inputConfig, options) {
|
|
|
12446
13643
|
} else {
|
|
12447
13644
|
const { build: legacyViteBuild } = await import("vite");
|
|
12448
13645
|
logger.info("\u{1F4E6} Building client bundle...");
|
|
12449
|
-
await buildClient2(legacyViteBuild, config, root, srcDir,
|
|
13646
|
+
await buildClient2(legacyViteBuild, config, root, srcDir, path13.join(root, distDir, "client"));
|
|
12450
13647
|
logger.info("\u{1F4E6} Building SSR bundle...");
|
|
12451
|
-
await buildSSR(legacyViteBuild, config, root, srcDir,
|
|
13648
|
+
await buildSSR(legacyViteBuild, config, root, srcDir, path13.join(root, distDir, "server"));
|
|
12452
13649
|
logger.info(`\u{1F680} Building server with Nitro (preset: ${preset})...`);
|
|
12453
13650
|
await buildNitro(
|
|
12454
13651
|
config,
|
|
@@ -12525,8 +13722,10 @@ async function createProjectModuleServer(createViteServer, config, root, buildLi
|
|
|
12525
13722
|
}),
|
|
12526
13723
|
farmEnvironmentFunctionsPlugin(),
|
|
12527
13724
|
// Route modules load here at build time (rendering config, prerendering): `server-only`
|
|
12528
|
-
// resolves as it does in the server build.
|
|
12529
|
-
|
|
13725
|
+
// resolves as it does in the server build. Module-entry packages load pre-bundled, as in
|
|
13726
|
+
// `farm dev`: unbundled, lucide-react alone is ~1,750 modules through the module runner,
|
|
13727
|
+
// which a docs build waited on after its bundles.
|
|
13728
|
+
farmServerOnlyEntriesPlugin({ prebundleServerPackages: true })
|
|
12530
13729
|
],
|
|
12531
13730
|
server: {
|
|
12532
13731
|
middlewareMode: true,
|
|
@@ -12546,6 +13745,12 @@ async function createProjectModuleServer(createViteServer, config, root, buildLi
|
|
|
12546
13745
|
return createViteServer({
|
|
12547
13746
|
...viteConfig,
|
|
12548
13747
|
root,
|
|
13748
|
+
// Vite keys its pre-bundled dependencies on the config, mode included, so this server and
|
|
13749
|
+
// `farm dev` sharing one cache would each rebuild it after the other ran.
|
|
13750
|
+
cacheDir: path13.join(
|
|
13751
|
+
path13.resolve(root, viteConfig.cacheDir ?? path13.join("node_modules", ".vite")),
|
|
13752
|
+
"farm-build"
|
|
13753
|
+
),
|
|
12549
13754
|
configFile: false,
|
|
12550
13755
|
appType: "custom",
|
|
12551
13756
|
mode: "production",
|
|
@@ -12577,7 +13782,7 @@ async function createProjectModuleServer(createViteServer, config, root, buildLi
|
|
|
12577
13782
|
}
|
|
12578
13783
|
async function buildClient2(viteBuild, config, root, srcDir, outputDir) {
|
|
12579
13784
|
const { farmI18nClientBridgePlugin, farmPlugin, farmServerOnlyEntriesPlugin } = await import("./vite.mjs");
|
|
12580
|
-
const { PluginManager: PluginManager2 } = await import("./plugin-
|
|
13785
|
+
const { PluginManager: PluginManager2 } = await import("./plugin-SAS22JL7.mjs");
|
|
12581
13786
|
const pluginManager = new PluginManager2({
|
|
12582
13787
|
config,
|
|
12583
13788
|
isDev: false,
|
|
@@ -12604,7 +13809,7 @@ async function buildClient2(viteBuild, config, root, srcDir, outputDir) {
|
|
|
12604
13809
|
}
|
|
12605
13810
|
async function buildSSR(viteBuild, config, root, srcDir, outputDir) {
|
|
12606
13811
|
const { farmI18nClientBridgePlugin, farmPlugin } = await import("./vite.mjs");
|
|
12607
|
-
const { PluginManager: PluginManager2 } = await import("./plugin-
|
|
13812
|
+
const { PluginManager: PluginManager2 } = await import("./plugin-SAS22JL7.mjs");
|
|
12608
13813
|
const pluginManager = new PluginManager2({
|
|
12609
13814
|
config,
|
|
12610
13815
|
isDev: false,
|
|
@@ -12636,16 +13841,16 @@ async function buildSSR(viteBuild, config, root, srcDir, outputDir) {
|
|
|
12636
13841
|
});
|
|
12637
13842
|
}
|
|
12638
13843
|
function resolveLegacyPageEntry(config, root, srcDir) {
|
|
12639
|
-
const appDir =
|
|
13844
|
+
const appDir = path13.join(root, srcDir, "app");
|
|
12640
13845
|
for (const extension of getFarmRendererComponentExtensions(config.renderer)) {
|
|
12641
|
-
const candidate =
|
|
13846
|
+
const candidate = path13.join(appDir, `page${extension}`);
|
|
12642
13847
|
if (existsSync3(candidate)) return candidate;
|
|
12643
13848
|
}
|
|
12644
|
-
return
|
|
13849
|
+
return path13.join(appDir, "page.tsx");
|
|
12645
13850
|
}
|
|
12646
13851
|
async function buildNitro(config, routeManager, apiRouteManager, serverRenderer, preset, root, distDir, pluginManager) {
|
|
12647
13852
|
const [{ createNitroConfig }, { createNitro, build: nitroBuild }] = await Promise.all([
|
|
12648
|
-
import("./nitro-
|
|
13853
|
+
import("./nitro-NSTXT7LB.mjs"),
|
|
12649
13854
|
import("nitro/builder")
|
|
12650
13855
|
]);
|
|
12651
13856
|
let nitroConfig = await createNitroConfig(
|
|
@@ -12659,18 +13864,18 @@ async function buildNitro(config, routeManager, apiRouteManager, serverRenderer,
|
|
|
12659
13864
|
nitroConfig = await pluginManager.runHookSerial("beforeNitroBuild", nitroConfig);
|
|
12660
13865
|
}
|
|
12661
13866
|
const outputDir = resolveDeployOutputPath(root, config.deploy.outputDir);
|
|
12662
|
-
const serverOutputDir =
|
|
12663
|
-
const publicOutputDir =
|
|
13867
|
+
const serverOutputDir = path13.join(outputDir, "server");
|
|
13868
|
+
const publicOutputDir = path13.join(outputDir, "public");
|
|
12664
13869
|
const { mkdir, cp } = await import("fs/promises");
|
|
12665
13870
|
await mkdir(serverOutputDir, { recursive: true });
|
|
12666
13871
|
await mkdir(publicOutputDir, { recursive: true });
|
|
12667
|
-
const clientDir =
|
|
13872
|
+
const clientDir = path13.join(root, distDir, "client");
|
|
12668
13873
|
try {
|
|
12669
13874
|
await mkdir(publicOutputDir, { recursive: true });
|
|
12670
13875
|
await cp(clientDir, publicOutputDir, { recursive: true });
|
|
12671
13876
|
logger.info("\u{1F4E6} Copied client assets to public directory");
|
|
12672
|
-
const manifestPath =
|
|
12673
|
-
const assetsDir =
|
|
13877
|
+
const manifestPath = path13.join(publicOutputDir, "farm-client-manifest.json");
|
|
13878
|
+
const assetsDir = path13.join(publicOutputDir, "assets");
|
|
12674
13879
|
const manifestExists = await import("fs/promises").then(
|
|
12675
13880
|
(fs4) => fs4.access(manifestPath).then(() => true).catch(() => false)
|
|
12676
13881
|
);
|
|
@@ -12686,8 +13891,8 @@ async function buildNitro(config, routeManager, apiRouteManager, serverRenderer,
|
|
|
12686
13891
|
logger.error(`\u274C Failed to copy client assets: ${error}`);
|
|
12687
13892
|
throw error;
|
|
12688
13893
|
}
|
|
12689
|
-
const serverDir =
|
|
12690
|
-
const nitroServerDir =
|
|
13894
|
+
const serverDir = path13.join(root, distDir, "server");
|
|
13895
|
+
const nitroServerDir = path13.join(root, distDir, ".nitro", "server", "farm");
|
|
12691
13896
|
try {
|
|
12692
13897
|
await mkdir(nitroServerDir, { recursive: true });
|
|
12693
13898
|
await cp(serverDir, nitroServerDir, { recursive: true });
|
|
@@ -12696,7 +13901,7 @@ async function buildNitro(config, routeManager, apiRouteManager, serverRenderer,
|
|
|
12696
13901
|
logger.warn(`Could not copy SSR bundles: ${error}`);
|
|
12697
13902
|
}
|
|
12698
13903
|
const nitro = await createNitro(nitroConfig);
|
|
12699
|
-
const registryPath =
|
|
13904
|
+
const registryPath = path13.join(root, distDir, ".nitro", "server", "farm-registry.ts");
|
|
12700
13905
|
try {
|
|
12701
13906
|
const { farmRegistry } = await import(
|
|
12702
13907
|
/* @vite-ignore */
|
|
@@ -12713,7 +13918,7 @@ async function buildNitro(config, routeManager, apiRouteManager, serverRenderer,
|
|
|
12713
13918
|
}
|
|
12714
13919
|
farmRegistry.routePaths = routePaths;
|
|
12715
13920
|
try {
|
|
12716
|
-
const clientManifestPath =
|
|
13921
|
+
const clientManifestPath = path13.join(root, distDir, "client", "farm-client-manifest.json");
|
|
12717
13922
|
const { readFile } = await import("fs/promises");
|
|
12718
13923
|
const manifestContent = await readFile(clientManifestPath, "utf-8");
|
|
12719
13924
|
farmRegistry.clientManifest = JSON.parse(manifestContent);
|