vinext 0.0.29 → 0.0.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (428) hide show
  1. package/README.md +12 -6
  2. package/dist/build/prerender.d.ts +188 -0
  3. package/dist/build/prerender.js +675 -0
  4. package/dist/build/prerender.js.map +1 -0
  5. package/dist/build/report.d.ts +45 -46
  6. package/dist/build/report.js +247 -276
  7. package/dist/build/report.js.map +1 -1
  8. package/dist/build/run-prerender.d.ts +62 -0
  9. package/dist/build/run-prerender.js +183 -0
  10. package/dist/build/run-prerender.js.map +1 -0
  11. package/dist/build/server-manifest.d.ts +19 -0
  12. package/dist/build/server-manifest.js +29 -0
  13. package/dist/build/server-manifest.js.map +1 -0
  14. package/dist/build/static-export.d.ts +51 -66
  15. package/dist/build/static-export.js +51 -545
  16. package/dist/build/static-export.js.map +1 -1
  17. package/dist/check.d.ts +26 -24
  18. package/dist/check.js +591 -567
  19. package/dist/check.js.map +1 -1
  20. package/dist/cli.d.ts +1 -15
  21. package/dist/cli.js +430 -491
  22. package/dist/cli.js.map +1 -1
  23. package/dist/client/entry.d.ts +1 -2
  24. package/dist/client/entry.js +49 -62
  25. package/dist/client/entry.js.map +1 -1
  26. package/dist/client/validate-module-path.d.ts +4 -1
  27. package/dist/client/validate-module-path.js +23 -28
  28. package/dist/client/validate-module-path.js.map +1 -1
  29. package/dist/client/vinext-next-data.d.ts +15 -20
  30. package/dist/client/vinext-next-data.js +0 -1
  31. package/dist/cloudflare/index.d.ts +3 -8
  32. package/dist/cloudflare/index.js +3 -8
  33. package/dist/cloudflare/kv-cache-handler.d.ts +95 -105
  34. package/dist/cloudflare/kv-cache-handler.js +354 -366
  35. package/dist/cloudflare/kv-cache-handler.js.map +1 -1
  36. package/dist/cloudflare/tpr.d.ts +36 -34
  37. package/dist/cloudflare/tpr.js +460 -603
  38. package/dist/cloudflare/tpr.js.map +1 -1
  39. package/dist/config/config-matchers.d.ts +31 -40
  40. package/dist/config/config-matchers.js +727 -936
  41. package/dist/config/config-matchers.js.map +1 -1
  42. package/dist/config/dotenv.d.ts +18 -11
  43. package/dist/config/dotenv.js +79 -84
  44. package/dist/config/dotenv.js.map +1 -1
  45. package/dist/config/next-config.d.ts +156 -146
  46. package/dist/config/next-config.js +374 -464
  47. package/dist/config/next-config.js.map +1 -1
  48. package/dist/deploy.d.ts +87 -96
  49. package/dist/deploy.js +490 -628
  50. package/dist/deploy.js.map +1 -1
  51. package/dist/entries/app-browser-entry.d.ts +4 -1
  52. package/dist/entries/app-browser-entry.js +12 -8
  53. package/dist/entries/app-browser-entry.js.map +1 -1
  54. package/dist/entries/app-rsc-entry.d.ts +33 -20
  55. package/dist/entries/app-rsc-entry.js +618 -343
  56. package/dist/entries/app-rsc-entry.js.map +1 -1
  57. package/dist/entries/app-ssr-entry.d.ts +9 -1
  58. package/dist/entries/app-ssr-entry.js +61 -28
  59. package/dist/entries/app-ssr-entry.js.map +1 -1
  60. package/dist/entries/pages-client-entry.d.ts +6 -2
  61. package/dist/entries/pages-client-entry.js +30 -33
  62. package/dist/entries/pages-client-entry.js.map +1 -1
  63. package/dist/entries/pages-entry-helpers.d.ts +5 -1
  64. package/dist/entries/pages-entry-helpers.js +17 -14
  65. package/dist/entries/pages-entry-helpers.js.map +1 -1
  66. package/dist/entries/pages-server-entry.d.ts +6 -2
  67. package/dist/entries/pages-server-entry.js +229 -207
  68. package/dist/entries/pages-server-entry.js.map +1 -1
  69. package/dist/index.d.ts +82 -62
  70. package/dist/index.js +2172 -3125
  71. package/dist/index.js.map +1 -1
  72. package/dist/init.d.ts +40 -37
  73. package/dist/init.js +201 -258
  74. package/dist/init.js.map +1 -1
  75. package/dist/plugins/async-hooks-stub.d.ts +7 -3
  76. package/dist/plugins/async-hooks-stub.js +39 -42
  77. package/dist/plugins/async-hooks-stub.js.map +1 -1
  78. package/dist/plugins/client-reference-dedup.d.ts +7 -3
  79. package/dist/plugins/client-reference-dedup.js +63 -88
  80. package/dist/plugins/client-reference-dedup.js.map +1 -1
  81. package/dist/routing/app-router.d.ts +100 -96
  82. package/dist/routing/app-router.js +563 -659
  83. package/dist/routing/app-router.js.map +1 -1
  84. package/dist/routing/file-matcher.d.ts +18 -15
  85. package/dist/routing/file-matcher.js +65 -65
  86. package/dist/routing/file-matcher.js.map +1 -1
  87. package/dist/routing/pages-router.d.ts +23 -24
  88. package/dist/routing/pages-router.js +147 -172
  89. package/dist/routing/pages-router.js.map +1 -1
  90. package/dist/routing/route-trie.d.ts +23 -20
  91. package/dist/routing/route-trie.js +131 -151
  92. package/dist/routing/route-trie.js.map +1 -1
  93. package/dist/routing/route-validation.d.ts +5 -2
  94. package/dist/routing/route-validation.js +98 -130
  95. package/dist/routing/route-validation.js.map +1 -1
  96. package/dist/routing/utils.d.ts +10 -7
  97. package/dist/routing/utils.js +75 -111
  98. package/dist/routing/utils.js.map +1 -1
  99. package/dist/server/api-handler.d.ts +8 -13
  100. package/dist/server/api-handler.js +161 -193
  101. package/dist/server/api-handler.js.map +1 -1
  102. package/dist/server/app-router-entry.d.ts +6 -16
  103. package/dist/server/app-router-entry.js +26 -54
  104. package/dist/server/app-router-entry.js.map +1 -1
  105. package/dist/server/dev-module-runner.d.ts +11 -64
  106. package/dist/server/dev-module-runner.js +89 -101
  107. package/dist/server/dev-module-runner.js.map +1 -1
  108. package/dist/server/dev-origin-check.d.ts +12 -10
  109. package/dist/server/dev-origin-check.js +98 -108
  110. package/dist/server/dev-origin-check.js.map +1 -1
  111. package/dist/server/dev-server.d.ts +17 -13
  112. package/dist/server/dev-server.js +547 -874
  113. package/dist/server/dev-server.js.map +1 -1
  114. package/dist/server/html.d.ts +4 -1
  115. package/dist/server/html.js +25 -26
  116. package/dist/server/html.js.map +1 -1
  117. package/dist/server/image-optimization.d.ts +31 -28
  118. package/dist/server/image-optimization.js +183 -200
  119. package/dist/server/image-optimization.js.map +1 -1
  120. package/dist/server/instrumentation.d.ts +25 -22
  121. package/dist/server/instrumentation.js +110 -122
  122. package/dist/server/instrumentation.js.map +1 -1
  123. package/dist/server/isr-cache.d.ts +16 -26
  124. package/dist/server/isr-cache.js +109 -126
  125. package/dist/server/isr-cache.js.map +1 -1
  126. package/dist/server/metadata-routes.d.ts +85 -88
  127. package/dist/server/metadata-routes.js +277 -286
  128. package/dist/server/metadata-routes.js.map +1 -1
  129. package/dist/server/middleware-codegen.d.ts +7 -4
  130. package/dist/server/middleware-codegen.js +98 -65
  131. package/dist/server/middleware-codegen.js.map +1 -1
  132. package/dist/server/middleware-request-headers.d.ts +8 -6
  133. package/dist/server/middleware-request-headers.js +47 -65
  134. package/dist/server/middleware-request-headers.js.map +1 -1
  135. package/dist/server/middleware.d.ts +31 -47
  136. package/dist/server/middleware.js +276 -363
  137. package/dist/server/middleware.js.map +1 -1
  138. package/dist/server/normalize-path.d.ts +4 -1
  139. package/dist/server/normalize-path.js +33 -47
  140. package/dist/server/normalize-path.js.map +1 -1
  141. package/dist/server/pages-i18n.d.ts +58 -0
  142. package/dist/server/pages-i18n.js +125 -0
  143. package/dist/server/pages-i18n.js.map +1 -0
  144. package/dist/server/prod-server.d.ts +19 -31
  145. package/dist/server/prod-server.js +714 -945
  146. package/dist/server/prod-server.js.map +1 -1
  147. package/dist/server/request-log.d.ts +18 -12
  148. package/dist/server/request-log.js +45 -52
  149. package/dist/server/request-log.js.map +1 -1
  150. package/dist/server/request-pipeline.d.ts +9 -17
  151. package/dist/server/request-pipeline.js +133 -184
  152. package/dist/server/request-pipeline.js.map +1 -1
  153. package/dist/server/worker-utils.d.ts +4 -1
  154. package/dist/server/worker-utils.js +31 -37
  155. package/dist/server/worker-utils.js.map +1 -1
  156. package/dist/shims/amp.d.ts +5 -2
  157. package/dist/shims/amp.js +19 -15
  158. package/dist/shims/amp.js.map +1 -1
  159. package/dist/shims/app.d.ts +8 -10
  160. package/dist/shims/app.js +0 -1
  161. package/dist/shims/cache-runtime.d.ts +21 -43
  162. package/dist/shims/cache-runtime.js +271 -405
  163. package/dist/shims/cache-runtime.js.map +1 -1
  164. package/dist/shims/cache.d.ts +131 -119
  165. package/dist/shims/cache.js +339 -418
  166. package/dist/shims/cache.js.map +1 -1
  167. package/dist/shims/client-only.d.ts +1 -18
  168. package/dist/shims/client-only.js +0 -17
  169. package/dist/shims/compat-router.d.ts +4 -1
  170. package/dist/shims/compat-router.js +23 -19
  171. package/dist/shims/compat-router.js.map +1 -1
  172. package/dist/shims/config.d.ts +7 -5
  173. package/dist/shims/config.js +16 -23
  174. package/dist/shims/config.js.map +1 -1
  175. package/dist/shims/constants.d.ts +119 -118
  176. package/dist/shims/constants.js +159 -165
  177. package/dist/shims/constants.js.map +1 -1
  178. package/dist/shims/document.d.ts +20 -16
  179. package/dist/shims/document.js +41 -22
  180. package/dist/shims/document.js.map +1 -1
  181. package/dist/shims/dynamic.d.ts +13 -22
  182. package/dist/shims/dynamic.js +122 -136
  183. package/dist/shims/dynamic.js.map +1 -1
  184. package/dist/shims/error-boundary.d.ts +22 -15
  185. package/dist/shims/error-boundary.js +81 -79
  186. package/dist/shims/error-boundary.js.map +1 -1
  187. package/dist/shims/error.d.ts +11 -12
  188. package/dist/shims/error.js +35 -39
  189. package/dist/shims/error.js.map +1 -1
  190. package/dist/shims/fetch-cache.d.ts +26 -10
  191. package/dist/shims/fetch-cache.js +443 -586
  192. package/dist/shims/fetch-cache.js.map +1 -1
  193. package/dist/shims/font-google-base.d.ts +28 -26
  194. package/dist/shims/font-google-base.js +238 -325
  195. package/dist/shims/font-google-base.js.map +1 -1
  196. package/dist/shims/font-google.d.ts +3 -3
  197. package/dist/shims/font-google.generated.d.ts +1928 -1924
  198. package/dist/shims/font-google.generated.js +1928 -2133
  199. package/dist/shims/font-google.generated.js.map +1 -1
  200. package/dist/shims/font-google.js +3 -3
  201. package/dist/shims/font-local.d.ts +28 -26
  202. package/dist/shims/font-local.js +204 -260
  203. package/dist/shims/font-local.js.map +1 -1
  204. package/dist/shims/form.d.ts +13 -27
  205. package/dist/shims/form.js +128 -180
  206. package/dist/shims/form.js.map +1 -1
  207. package/dist/shims/head-state.d.ts +9 -10
  208. package/dist/shims/head-state.js +25 -39
  209. package/dist/shims/head-state.js.map +1 -1
  210. package/dist/shims/head.d.ts +16 -18
  211. package/dist/shims/head.js +185 -153
  212. package/dist/shims/head.js.map +1 -1
  213. package/dist/shims/headers.d.ts +84 -71
  214. package/dist/shims/headers.js +447 -583
  215. package/dist/shims/headers.js.map +1 -1
  216. package/dist/shims/i18n-context.d.ts +23 -0
  217. package/dist/shims/i18n-context.js +44 -0
  218. package/dist/shims/i18n-context.js.map +1 -0
  219. package/dist/shims/i18n-state.d.ts +14 -0
  220. package/dist/shims/i18n-state.js +45 -0
  221. package/dist/shims/i18n-state.js.map +1 -0
  222. package/dist/shims/image-config.d.ts +11 -8
  223. package/dist/shims/image-config.js +50 -83
  224. package/dist/shims/image-config.js.map +1 -1
  225. package/dist/shims/image.d.ts +37 -44
  226. package/dist/shims/image.js +284 -301
  227. package/dist/shims/image.js.map +1 -1
  228. package/dist/shims/internal/api-utils.d.ts +7 -4
  229. package/dist/shims/internal/api-utils.js +0 -6
  230. package/dist/shims/internal/app-router-context.d.ts +22 -17
  231. package/dist/shims/internal/app-router-context.js +17 -13
  232. package/dist/shims/internal/app-router-context.js.map +1 -1
  233. package/dist/shims/internal/cookies.d.ts +2 -9
  234. package/dist/shims/internal/cookies.js +2 -9
  235. package/dist/shims/internal/parse-cookie-header.d.ts +4 -1
  236. package/dist/shims/internal/parse-cookie-header.js +29 -29
  237. package/dist/shims/internal/parse-cookie-header.js.map +1 -1
  238. package/dist/shims/internal/router-context.d.ts +6 -1
  239. package/dist/shims/internal/router-context.js +11 -7
  240. package/dist/shims/internal/router-context.js.map +1 -1
  241. package/dist/shims/internal/utils.d.ts +40 -36
  242. package/dist/shims/internal/utils.js +24 -30
  243. package/dist/shims/internal/utils.js.map +1 -1
  244. package/dist/shims/internal/work-unit-async-storage.d.ts +6 -10
  245. package/dist/shims/internal/work-unit-async-storage.js +14 -11
  246. package/dist/shims/internal/work-unit-async-storage.js.map +1 -1
  247. package/dist/shims/layout-segment-context.d.ts +11 -14
  248. package/dist/shims/layout-segment-context.js +24 -23
  249. package/dist/shims/layout-segment-context.js.map +1 -1
  250. package/dist/shims/legacy-image.d.ts +39 -46
  251. package/dist/shims/legacy-image.js +47 -42
  252. package/dist/shims/legacy-image.js.map +1 -1
  253. package/dist/shims/link.d.ts +32 -36
  254. package/dist/shims/link.js +262 -382
  255. package/dist/shims/link.js.map +1 -1
  256. package/dist/shims/metadata.d.ts +210 -202
  257. package/dist/shims/metadata.js +545 -544
  258. package/dist/shims/metadata.js.map +1 -1
  259. package/dist/shims/navigation-state.d.ts +19 -13
  260. package/dist/shims/navigation-state.js +68 -58
  261. package/dist/shims/navigation-state.js.map +1 -1
  262. package/dist/shims/navigation.d.ts +59 -63
  263. package/dist/shims/navigation.js +508 -690
  264. package/dist/shims/navigation.js.map +1 -1
  265. package/dist/shims/og.d.ts +2 -20
  266. package/dist/shims/og.js +2 -19
  267. package/dist/shims/readonly-url-search-params.d.ts +8 -5
  268. package/dist/shims/readonly-url-search-params.js +26 -22
  269. package/dist/shims/readonly-url-search-params.js.map +1 -1
  270. package/dist/shims/request-context.d.ts +8 -5
  271. package/dist/shims/request-context.js +50 -51
  272. package/dist/shims/request-context.js.map +1 -1
  273. package/dist/shims/request-state-types.d.ts +11 -0
  274. package/dist/shims/request-state-types.js +1 -0
  275. package/dist/shims/router-state.d.ts +15 -1
  276. package/dist/shims/router-state.js +34 -41
  277. package/dist/shims/router-state.js.map +1 -1
  278. package/dist/shims/router.d.ts +81 -81
  279. package/dist/shims/router.js +517 -543
  280. package/dist/shims/router.js.map +1 -1
  281. package/dist/shims/script.d.ts +39 -48
  282. package/dist/shims/script.js +107 -160
  283. package/dist/shims/script.js.map +1 -1
  284. package/dist/shims/server-only.d.ts +1 -19
  285. package/dist/shims/server-only.js +0 -18
  286. package/dist/shims/server.d.ts +175 -157
  287. package/dist/shims/server.js +462 -432
  288. package/dist/shims/server.js.map +1 -1
  289. package/dist/shims/unified-request-context.d.ts +66 -0
  290. package/dist/shims/unified-request-context.js +98 -0
  291. package/dist/shims/unified-request-context.js.map +1 -0
  292. package/dist/shims/url-safety.d.ts +4 -1
  293. package/dist/shims/url-safety.js +15 -11
  294. package/dist/shims/url-safety.js.map +1 -1
  295. package/dist/shims/url-utils.d.ts +8 -5
  296. package/dist/shims/url-utils.js +62 -93
  297. package/dist/shims/url-utils.js.map +1 -1
  298. package/dist/shims/web-vitals.d.ts +10 -8
  299. package/dist/shims/web-vitals.js +9 -15
  300. package/dist/shims/web-vitals.js.map +1 -1
  301. package/dist/utils/base-path.d.ts +5 -2
  302. package/dist/utils/base-path.js +21 -19
  303. package/dist/utils/base-path.js.map +1 -1
  304. package/dist/utils/domain-locale.d.ts +26 -0
  305. package/dist/utils/domain-locale.js +44 -0
  306. package/dist/utils/domain-locale.js.map +1 -0
  307. package/dist/utils/hash.d.ts +4 -1
  308. package/dist/utils/hash.js +19 -17
  309. package/dist/utils/hash.js.map +1 -1
  310. package/dist/utils/manifest-paths.d.ts +6 -3
  311. package/dist/utils/manifest-paths.js +15 -16
  312. package/dist/utils/manifest-paths.js.map +1 -1
  313. package/dist/utils/project.d.ts +13 -11
  314. package/dist/utils/project.js +169 -216
  315. package/dist/utils/project.js.map +1 -1
  316. package/dist/utils/query.d.ts +8 -6
  317. package/dist/utils/query.js +57 -67
  318. package/dist/utils/query.js.map +1 -1
  319. package/package.json +11 -10
  320. package/dist/build/report.d.ts.map +0 -1
  321. package/dist/build/static-export.d.ts.map +0 -1
  322. package/dist/check.d.ts.map +0 -1
  323. package/dist/cli.d.ts.map +0 -1
  324. package/dist/client/entry.d.ts.map +0 -1
  325. package/dist/client/validate-module-path.d.ts.map +0 -1
  326. package/dist/client/vinext-next-data.d.ts.map +0 -1
  327. package/dist/client/vinext-next-data.js.map +0 -1
  328. package/dist/cloudflare/index.d.ts.map +0 -1
  329. package/dist/cloudflare/index.js.map +0 -1
  330. package/dist/cloudflare/kv-cache-handler.d.ts.map +0 -1
  331. package/dist/cloudflare/tpr.d.ts.map +0 -1
  332. package/dist/config/config-matchers.d.ts.map +0 -1
  333. package/dist/config/dotenv.d.ts.map +0 -1
  334. package/dist/config/next-config.d.ts.map +0 -1
  335. package/dist/deploy.d.ts.map +0 -1
  336. package/dist/entries/app-browser-entry.d.ts.map +0 -1
  337. package/dist/entries/app-rsc-entry.d.ts.map +0 -1
  338. package/dist/entries/app-ssr-entry.d.ts.map +0 -1
  339. package/dist/entries/pages-client-entry.d.ts.map +0 -1
  340. package/dist/entries/pages-entry-helpers.d.ts.map +0 -1
  341. package/dist/entries/pages-server-entry.d.ts.map +0 -1
  342. package/dist/index.d.ts.map +0 -1
  343. package/dist/init.d.ts.map +0 -1
  344. package/dist/plugins/async-hooks-stub.d.ts.map +0 -1
  345. package/dist/plugins/client-reference-dedup.d.ts.map +0 -1
  346. package/dist/routing/app-router.d.ts.map +0 -1
  347. package/dist/routing/file-matcher.d.ts.map +0 -1
  348. package/dist/routing/pages-router.d.ts.map +0 -1
  349. package/dist/routing/route-trie.d.ts.map +0 -1
  350. package/dist/routing/route-validation.d.ts.map +0 -1
  351. package/dist/routing/utils.d.ts.map +0 -1
  352. package/dist/server/api-handler.d.ts.map +0 -1
  353. package/dist/server/app-router-entry.d.ts.map +0 -1
  354. package/dist/server/dev-module-runner.d.ts.map +0 -1
  355. package/dist/server/dev-origin-check.d.ts.map +0 -1
  356. package/dist/server/dev-server.d.ts.map +0 -1
  357. package/dist/server/html.d.ts.map +0 -1
  358. package/dist/server/image-optimization.d.ts.map +0 -1
  359. package/dist/server/instrumentation.d.ts.map +0 -1
  360. package/dist/server/isr-cache.d.ts.map +0 -1
  361. package/dist/server/metadata-routes.d.ts.map +0 -1
  362. package/dist/server/middleware-codegen.d.ts.map +0 -1
  363. package/dist/server/middleware-request-headers.d.ts.map +0 -1
  364. package/dist/server/middleware.d.ts.map +0 -1
  365. package/dist/server/normalize-path.d.ts.map +0 -1
  366. package/dist/server/prod-server.d.ts.map +0 -1
  367. package/dist/server/request-log.d.ts.map +0 -1
  368. package/dist/server/request-pipeline.d.ts.map +0 -1
  369. package/dist/server/worker-utils.d.ts.map +0 -1
  370. package/dist/shims/amp.d.ts.map +0 -1
  371. package/dist/shims/app.d.ts.map +0 -1
  372. package/dist/shims/app.js.map +0 -1
  373. package/dist/shims/cache-runtime.d.ts.map +0 -1
  374. package/dist/shims/cache.d.ts.map +0 -1
  375. package/dist/shims/client-only.d.ts.map +0 -1
  376. package/dist/shims/client-only.js.map +0 -1
  377. package/dist/shims/compat-router.d.ts.map +0 -1
  378. package/dist/shims/config.d.ts.map +0 -1
  379. package/dist/shims/constants.d.ts.map +0 -1
  380. package/dist/shims/document.d.ts.map +0 -1
  381. package/dist/shims/dynamic.d.ts.map +0 -1
  382. package/dist/shims/error-boundary.d.ts.map +0 -1
  383. package/dist/shims/error.d.ts.map +0 -1
  384. package/dist/shims/fetch-cache.d.ts.map +0 -1
  385. package/dist/shims/font-google-base.d.ts.map +0 -1
  386. package/dist/shims/font-google.d.ts.map +0 -1
  387. package/dist/shims/font-google.generated.d.ts.map +0 -1
  388. package/dist/shims/font-google.js.map +0 -1
  389. package/dist/shims/font-local.d.ts.map +0 -1
  390. package/dist/shims/form.d.ts.map +0 -1
  391. package/dist/shims/head-state.d.ts.map +0 -1
  392. package/dist/shims/head.d.ts.map +0 -1
  393. package/dist/shims/headers.d.ts.map +0 -1
  394. package/dist/shims/image-config.d.ts.map +0 -1
  395. package/dist/shims/image.d.ts.map +0 -1
  396. package/dist/shims/internal/api-utils.d.ts.map +0 -1
  397. package/dist/shims/internal/api-utils.js.map +0 -1
  398. package/dist/shims/internal/app-router-context.d.ts.map +0 -1
  399. package/dist/shims/internal/cookies.d.ts.map +0 -1
  400. package/dist/shims/internal/cookies.js.map +0 -1
  401. package/dist/shims/internal/parse-cookie-header.d.ts.map +0 -1
  402. package/dist/shims/internal/router-context.d.ts.map +0 -1
  403. package/dist/shims/internal/utils.d.ts.map +0 -1
  404. package/dist/shims/internal/work-unit-async-storage.d.ts.map +0 -1
  405. package/dist/shims/layout-segment-context.d.ts.map +0 -1
  406. package/dist/shims/legacy-image.d.ts.map +0 -1
  407. package/dist/shims/link.d.ts.map +0 -1
  408. package/dist/shims/metadata.d.ts.map +0 -1
  409. package/dist/shims/navigation-state.d.ts.map +0 -1
  410. package/dist/shims/navigation.d.ts.map +0 -1
  411. package/dist/shims/og.d.ts.map +0 -1
  412. package/dist/shims/og.js.map +0 -1
  413. package/dist/shims/readonly-url-search-params.d.ts.map +0 -1
  414. package/dist/shims/request-context.d.ts.map +0 -1
  415. package/dist/shims/router-state.d.ts.map +0 -1
  416. package/dist/shims/router.d.ts.map +0 -1
  417. package/dist/shims/script.d.ts.map +0 -1
  418. package/dist/shims/server-only.d.ts.map +0 -1
  419. package/dist/shims/server-only.js.map +0 -1
  420. package/dist/shims/server.d.ts.map +0 -1
  421. package/dist/shims/url-safety.d.ts.map +0 -1
  422. package/dist/shims/url-utils.d.ts.map +0 -1
  423. package/dist/shims/web-vitals.d.ts.map +0 -1
  424. package/dist/utils/base-path.d.ts.map +0 -1
  425. package/dist/utils/hash.d.ts.map +0 -1
  426. package/dist/utils/manifest-paths.d.ts.map +0 -1
  427. package/dist/utils/project.d.ts.map +0 -1
  428. package/dist/utils/query.d.ts.map +0 -1
@@ -1,136 +1,124 @@
1
- /**
2
- * instrumentation.ts support
3
- *
4
- * Next.js supports an `instrumentation.ts` file at the project root that
5
- * exports a `register()` function. This function is called once when the
6
- * server starts, before any request handling. It's the recommended way to
7
- * set up observability tools (Sentry, Datadog, OpenTelemetry, etc.).
8
- *
9
- * Optionally, it can also export `onRequestError()` which is called when
10
- * an unhandled error occurs during request handling.
11
- *
12
- * References:
13
- * - https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation
14
- *
15
- * ## App Router
16
- *
17
- * For App Router, `register()` is baked directly into the generated RSC entry
18
- * as a top-level `await` at module evaluation time (see `entries/app-rsc-entry.ts`
19
- * `generateRscEntry`). This means it runs inside the Worker process (or RSC
20
- * Vite environment) — the same process that handles requests — before any
21
- * request is served. `runInstrumentation()` is NOT called from `configureServer`
22
- * for App Router.
23
- *
24
- * The `onRequestError` handler is stored on `globalThis` so it is visible across
25
- * the RSC and SSR Vite environments (separate module graphs, same Node.js process).
26
- * With `@cloudflare/vite-plugin` it runs entirely inside the Worker, so
27
- * `globalThis` is the Worker's global — also correct.
28
- *
29
- * ## Pages Router
30
- *
31
- * Pages Router has no RSC entry, so `configureServer()` is the right place to
32
- * call `register()`. `runInstrumentation()` accepts a `ModuleRunner` (created
33
- * via `createDirectRunner()`) rather than `server.ssrLoadModule()` so it is
34
- * safe when `@cloudflare/vite-plugin` is present — that plugin replaces the
35
- * SSR environment's hot channel, causing `ssrLoadModule()` to crash with
36
- * `TypeError: Cannot read properties of undefined (reading 'outsideEmitter')`.
37
- */
1
+ import { getRequestExecutionContext } from "../shims/request-context.js";
38
2
  import fs from "node:fs";
39
3
  import path from "node:path";
40
- import { getRequestExecutionContext } from "../shims/request-context.js";
4
+ //#region src/server/instrumentation.ts
5
+ /**
6
+ * instrumentation.ts support
7
+ *
8
+ * Next.js supports an `instrumentation.ts` file at the project root that
9
+ * exports a `register()` function. This function is called once when the
10
+ * server starts, before any request handling. It's the recommended way to
11
+ * set up observability tools (Sentry, Datadog, OpenTelemetry, etc.).
12
+ *
13
+ * Optionally, it can also export `onRequestError()` which is called when
14
+ * an unhandled error occurs during request handling.
15
+ *
16
+ * References:
17
+ * - https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation
18
+ *
19
+ * ## App Router
20
+ *
21
+ * For App Router, `register()` is baked directly into the generated RSC entry
22
+ * as a top-level `await` at module evaluation time (see `entries/app-rsc-entry.ts`
23
+ * `generateRscEntry`). This means it runs inside the Worker process (or RSC
24
+ * Vite environment) — the same process that handles requests — before any
25
+ * request is served. `runInstrumentation()` is NOT called from `configureServer`
26
+ * for App Router.
27
+ *
28
+ * The `onRequestError` handler is stored on `globalThis` so it is visible across
29
+ * the RSC and SSR Vite environments (separate module graphs, same Node.js process).
30
+ * With `@cloudflare/vite-plugin` it runs entirely inside the Worker, so
31
+ * `globalThis` is the Worker's global — also correct.
32
+ *
33
+ * ## Pages Router
34
+ *
35
+ * Pages Router has no RSC entry, so `configureServer()` is the right place to
36
+ * call `register()`. `runInstrumentation()` accepts a `ModuleRunner` (created
37
+ * via `createDirectRunner()`) rather than `server.ssrLoadModule()` so it is
38
+ * safe when `@cloudflare/vite-plugin` is present — that plugin replaces the
39
+ * SSR environment's hot channel, causing `ssrLoadModule()` to crash with
40
+ * `TypeError: Cannot read properties of undefined (reading 'outsideEmitter')`.
41
+ */
41
42
  /** Possible instrumentation file names. */
42
43
  const INSTRUMENTATION_FILES = [
43
- "instrumentation.ts",
44
- "instrumentation.tsx",
45
- "instrumentation.js",
46
- "instrumentation.mjs",
47
- "src/instrumentation.ts",
48
- "src/instrumentation.tsx",
49
- "src/instrumentation.js",
50
- "src/instrumentation.mjs",
44
+ "instrumentation.ts",
45
+ "instrumentation.tsx",
46
+ "instrumentation.js",
47
+ "instrumentation.mjs",
48
+ "src/instrumentation.ts",
49
+ "src/instrumentation.tsx",
50
+ "src/instrumentation.js",
51
+ "src/instrumentation.mjs"
51
52
  ];
52
53
  /**
53
- * Find the instrumentation file in the project root.
54
- */
55
- export function findInstrumentationFile(root) {
56
- for (const file of INSTRUMENTATION_FILES) {
57
- const fullPath = path.join(root, file);
58
- if (fs.existsSync(fullPath)) {
59
- return fullPath;
60
- }
61
- }
62
- return null;
54
+ * Find the instrumentation file in the project root.
55
+ */
56
+ function findInstrumentationFile(root) {
57
+ for (const file of INSTRUMENTATION_FILES) {
58
+ const fullPath = path.join(root, file);
59
+ if (fs.existsSync(fullPath)) return fullPath;
60
+ }
61
+ return null;
63
62
  }
64
63
  /**
65
- * Get the registered onRequestError handler (if any).
66
- *
67
- * Reads from globalThis so it works across Vite environment boundaries.
68
- */
69
- export function getOnRequestErrorHandler() {
70
- return globalThis.__VINEXT_onRequestErrorHandler__ ?? null;
64
+ * Get the registered onRequestError handler (if any).
65
+ *
66
+ * Reads from globalThis so it works across Vite environment boundaries.
67
+ */
68
+ function getOnRequestErrorHandler() {
69
+ return globalThis.__VINEXT_onRequestErrorHandler__ ?? null;
71
70
  }
72
71
  /**
73
- * Load and execute the instrumentation file via a ModuleRunner.
74
- *
75
- * Called once during Pages Router server startup (`configureServer`). It:
76
- * 1. Loads the instrumentation module via `runner.import()`.
77
- * 2. Calls the `register()` function if exported.
78
- * 3. Stores the `onRequestError()` handler on `globalThis` so it is visible
79
- * to all Vite environment module graphs (SSR and the host process share
80
- * the same Node.js `globalThis`).
81
- *
82
- * **App Router** does not use this function. For App Router, `register()` is
83
- * emitted as a top-level `await` inside the generated RSC entry module so it
84
- * runs in the same Worker/environment as request handling.
85
- *
86
- * @param runner - A ModuleRunner created via `createDirectRunner()`. Must be
87
- * the same long-lived runner used for middleware and SSR so the module graph
88
- * is shared. Safe with all Vite plugin combinations, including
89
- * `@cloudflare/vite-plugin`, because it never touches the hot channel.
90
- * @param instrumentationPath - Absolute path to the instrumentation file
91
- */
92
- export async function runInstrumentation(runner, instrumentationPath) {
93
- try {
94
- const mod = (await runner.import(instrumentationPath));
95
- // Call register() if exported
96
- if (typeof mod.register === "function") {
97
- await mod.register();
98
- }
99
- // Store onRequestError handler on globalThis so environments can reach the
100
- // same handler.
101
- if (typeof mod.onRequestError === "function") {
102
- globalThis.__VINEXT_onRequestErrorHandler__ = mod.onRequestError;
103
- }
104
- }
105
- catch (err) {
106
- console.error("[vinext] Failed to load instrumentation:", err instanceof Error ? err.message : String(err));
107
- }
72
+ * Load and execute the instrumentation file via a ModuleRunner.
73
+ *
74
+ * Called once during Pages Router server startup (`configureServer`). It:
75
+ * 1. Loads the instrumentation module via `runner.import()`.
76
+ * 2. Calls the `register()` function if exported.
77
+ * 3. Stores the `onRequestError()` handler on `globalThis` so it is visible
78
+ * to all Vite environment module graphs (SSR and the host process share
79
+ * the same Node.js `globalThis`).
80
+ *
81
+ * **App Router** does not use this function. For App Router, `register()` is
82
+ * emitted as a top-level `await` inside the generated RSC entry module so it
83
+ * runs in the same Worker/environment as request handling.
84
+ *
85
+ * @param runner - A ModuleRunner created via `createDirectRunner()`. Must be
86
+ * the same long-lived runner used for middleware and SSR so the module graph
87
+ * is shared. Safe with all Vite plugin combinations, including
88
+ * `@cloudflare/vite-plugin`, because it never touches the hot channel.
89
+ * @param instrumentationPath - Absolute path to the instrumentation file
90
+ */
91
+ async function runInstrumentation(runner, instrumentationPath) {
92
+ try {
93
+ const mod = await runner.import(instrumentationPath);
94
+ if (typeof mod.register === "function") await mod.register();
95
+ if (typeof mod.onRequestError === "function") globalThis.__VINEXT_onRequestErrorHandler__ = mod.onRequestError;
96
+ } catch (err) {
97
+ console.error("[vinext] Failed to load instrumentation:", err instanceof Error ? err.message : String(err));
98
+ }
108
99
  }
109
100
  /**
110
- * Report a request error via the instrumentation handler.
111
- *
112
- * No-op if no onRequestError handler is registered.
113
- *
114
- * Reads the handler from globalThis so this function works correctly regardless
115
- * of which environment it is called from.
116
- */
117
- export function reportRequestError(error, request, context) {
118
- const handler = getOnRequestErrorHandler();
119
- if (!handler)
120
- return Promise.resolve();
121
- const promise = (async () => {
122
- try {
123
- await handler(error, request, context);
124
- }
125
- catch (reportErr) {
126
- console.error("[vinext] onRequestError handler threw:", reportErr instanceof Error ? reportErr.message : String(reportErr));
127
- }
128
- })();
129
- // On Cloudflare Workers, register with ctx.waitUntil() so the isolate
130
- // stays alive until the report completes (e.g. Sentry HTTP request).
131
- // On Node.js (dev or vinext start), getRequestExecutionContext() returns
132
- // null — fire-and-forget is fine because the process doesn't die.
133
- getRequestExecutionContext()?.waitUntil(promise);
134
- return promise;
101
+ * Report a request error via the instrumentation handler.
102
+ *
103
+ * No-op if no onRequestError handler is registered.
104
+ *
105
+ * Reads the handler from globalThis so this function works correctly regardless
106
+ * of which environment it is called from.
107
+ */
108
+ function reportRequestError(error, request, context) {
109
+ const handler = getOnRequestErrorHandler();
110
+ if (!handler) return Promise.resolve();
111
+ const promise = (async () => {
112
+ try {
113
+ await handler(error, request, context);
114
+ } catch (reportErr) {
115
+ console.error("[vinext] onRequestError handler threw:", reportErr instanceof Error ? reportErr.message : String(reportErr));
116
+ }
117
+ })();
118
+ getRequestExecutionContext()?.waitUntil(promise);
119
+ return promise;
135
120
  }
121
+ //#endregion
122
+ export { findInstrumentationFile, getOnRequestErrorHandler, reportRequestError, runInstrumentation };
123
+
136
124
  //# sourceMappingURL=instrumentation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/server/instrumentation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAC;AAUzE,2CAA2C;AAC3C,MAAM,qBAAqB,GAAG;IAC5B,oBAAoB;IACpB,qBAAqB;IACrB,oBAAoB;IACpB,qBAAqB;IACrB,wBAAwB;IACxB,yBAAyB;IACzB,wBAAwB;IACxB,yBAAyB;CAC1B,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAY;IAClD,KAAK,MAAM,IAAI,IAAI,qBAAqB,EAAE,CAAC;QACzC,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACvC,IAAI,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC5B,OAAO,QAAQ,CAAC;QAClB,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAyBD;;;;GAIG;AACH,MAAM,UAAU,wBAAwB;IACtC,OAAO,UAAU,CAAC,gCAAgC,IAAI,IAAI,CAAC;AAC7D,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,MAAsB,EACtB,mBAA2B;IAE3B,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,CAAC,MAAM,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAA4B,CAAC;QAElF,8BAA8B;QAC9B,IAAI,OAAO,GAAG,CAAC,QAAQ,KAAK,UAAU,EAAE,CAAC;YACvC,MAAM,GAAG,CAAC,QAAQ,EAAE,CAAC;QACvB,CAAC;QAED,2EAA2E;QAC3E,gBAAgB;QAChB,IAAI,OAAO,GAAG,CAAC,cAAc,KAAK,UAAU,EAAE,CAAC;YAC7C,UAAU,CAAC,gCAAgC,GAAG,GAAG,CAAC,cAAuC,CAAC;QAC5F,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CACX,0CAA0C,EAC1C,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CACjD,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAChC,KAAY,EACZ,OAA0E,EAC1E,OAA8B;IAE9B,MAAM,OAAO,GAAG,wBAAwB,EAAE,CAAC;IAC3C,IAAI,CAAC,OAAO;QAAE,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAEvC,MAAM,OAAO,GAAG,CAAC,KAAK,IAAI,EAAE;QAC1B,IAAI,CAAC;YACH,MAAM,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QACzC,CAAC;QAAC,OAAO,SAAS,EAAE,CAAC;YACnB,OAAO,CAAC,KAAK,CACX,wCAAwC,EACxC,SAAS,YAAY,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CACnE,CAAC;QACJ,CAAC;IACH,CAAC,CAAC,EAAE,CAAC;IAEL,sEAAsE;IACtE,qEAAqE;IACrE,yEAAyE;IACzE,kEAAkE;IAClE,0BAA0B,EAAE,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IAEjD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["/**\n * instrumentation.ts support\n *\n * Next.js supports an `instrumentation.ts` file at the project root that\n * exports a `register()` function. This function is called once when the\n * server starts, before any request handling. It's the recommended way to\n * set up observability tools (Sentry, Datadog, OpenTelemetry, etc.).\n *\n * Optionally, it can also export `onRequestError()` which is called when\n * an unhandled error occurs during request handling.\n *\n * References:\n * - https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation\n *\n * ## App Router\n *\n * For App Router, `register()` is baked directly into the generated RSC entry\n * as a top-level `await` at module evaluation time (see `entries/app-rsc-entry.ts`\n * `generateRscEntry`). This means it runs inside the Worker process (or RSC\n * Vite environment) — the same process that handles requests — before any\n * request is served. `runInstrumentation()` is NOT called from `configureServer`\n * for App Router.\n *\n * The `onRequestError` handler is stored on `globalThis` so it is visible across\n * the RSC and SSR Vite environments (separate module graphs, same Node.js process).\n * With `@cloudflare/vite-plugin` it runs entirely inside the Worker, so\n * `globalThis` is the Worker's global — also correct.\n *\n * ## Pages Router\n *\n * Pages Router has no RSC entry, so `configureServer()` is the right place to\n * call `register()`. `runInstrumentation()` accepts a `ModuleRunner` (created\n * via `createDirectRunner()`) rather than `server.ssrLoadModule()` so it is\n * safe when `@cloudflare/vite-plugin` is present — that plugin replaces the\n * SSR environment's hot channel, causing `ssrLoadModule()` to crash with\n * `TypeError: Cannot read properties of undefined (reading 'outsideEmitter')`.\n */\n\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { getRequestExecutionContext } from \"../shims/request-context.js\";\n/**\n * Minimal duck-typed interface for the module runner passed to\n * `runInstrumentation`. Only `.import()` is used — this avoids requiring\n * callers (including tests) to provide a full `ModuleRunner` instance.\n */\nexport interface ModuleImporter {\n import(id: string): Promise<unknown>;\n}\n\n/** Possible instrumentation file names. */\nconst INSTRUMENTATION_FILES = [\n \"instrumentation.ts\",\n \"instrumentation.tsx\",\n \"instrumentation.js\",\n \"instrumentation.mjs\",\n \"src/instrumentation.ts\",\n \"src/instrumentation.tsx\",\n \"src/instrumentation.js\",\n \"src/instrumentation.mjs\",\n];\n\n/**\n * Find the instrumentation file in the project root.\n */\nexport function findInstrumentationFile(root: string): string | null {\n for (const file of INSTRUMENTATION_FILES) {\n const fullPath = path.join(root, file);\n if (fs.existsSync(fullPath)) {\n return fullPath;\n }\n }\n return null;\n}\n\n/**\n * The onRequestError handler type from Next.js instrumentation.\n *\n * Called when an unhandled error occurs during request handling.\n * Provides the error, the request info, and an error context.\n */\nexport interface OnRequestErrorContext {\n /** The route path (e.g., '/blog/[slug]') */\n routerKind: \"Pages Router\" | \"App Router\";\n /** The matched route pattern */\n routePath: string;\n /** The route type */\n routeType: \"render\" | \"route\" | \"action\" | \"middleware\";\n /** HTTP status code that will be sent */\n revalidateReason?: \"on-demand\" | \"stale\" | undefined;\n}\n\nexport type OnRequestErrorHandler = (\n error: Error,\n request: { path: string; method: string; headers: Record<string, string> },\n context: OnRequestErrorContext,\n) => void | Promise<void>;\n\n/**\n * Get the registered onRequestError handler (if any).\n *\n * Reads from globalThis so it works across Vite environment boundaries.\n */\nexport function getOnRequestErrorHandler(): OnRequestErrorHandler | null {\n return globalThis.__VINEXT_onRequestErrorHandler__ ?? null;\n}\n\n/**\n * Load and execute the instrumentation file via a ModuleRunner.\n *\n * Called once during Pages Router server startup (`configureServer`). It:\n * 1. Loads the instrumentation module via `runner.import()`.\n * 2. Calls the `register()` function if exported.\n * 3. Stores the `onRequestError()` handler on `globalThis` so it is visible\n * to all Vite environment module graphs (SSR and the host process share\n * the same Node.js `globalThis`).\n *\n * **App Router** does not use this function. For App Router, `register()` is\n * emitted as a top-level `await` inside the generated RSC entry module so it\n * runs in the same Worker/environment as request handling.\n *\n * @param runner - A ModuleRunner created via `createDirectRunner()`. Must be\n * the same long-lived runner used for middleware and SSR so the module graph\n * is shared. Safe with all Vite plugin combinations, including\n * `@cloudflare/vite-plugin`, because it never touches the hot channel.\n * @param instrumentationPath - Absolute path to the instrumentation file\n */\nexport async function runInstrumentation(\n runner: ModuleImporter,\n instrumentationPath: string,\n): Promise<void> {\n try {\n const mod = (await runner.import(instrumentationPath)) as Record<string, unknown>;\n\n // Call register() if exported\n if (typeof mod.register === \"function\") {\n await mod.register();\n }\n\n // Store onRequestError handler on globalThis so environments can reach the\n // same handler.\n if (typeof mod.onRequestError === \"function\") {\n globalThis.__VINEXT_onRequestErrorHandler__ = mod.onRequestError as OnRequestErrorHandler;\n }\n } catch (err) {\n console.error(\n \"[vinext] Failed to load instrumentation:\",\n err instanceof Error ? err.message : String(err),\n );\n }\n}\n\n/**\n * Report a request error via the instrumentation handler.\n *\n * No-op if no onRequestError handler is registered.\n *\n * Reads the handler from globalThis so this function works correctly regardless\n * of which environment it is called from.\n */\nexport function reportRequestError(\n error: Error,\n request: { path: string; method: string; headers: Record<string, string> },\n context: OnRequestErrorContext,\n): Promise<void> {\n const handler = getOnRequestErrorHandler();\n if (!handler) return Promise.resolve();\n\n const promise = (async () => {\n try {\n await handler(error, request, context);\n } catch (reportErr) {\n console.error(\n \"[vinext] onRequestError handler threw:\",\n reportErr instanceof Error ? reportErr.message : String(reportErr),\n );\n }\n })();\n\n // On Cloudflare Workers, register with ctx.waitUntil() so the isolate\n // stays alive until the report completes (e.g. Sentry HTTP request).\n // On Node.js (dev or vinext start), getRequestExecutionContext() returns\n // null — fire-and-forget is fine because the process doesn't die.\n getRequestExecutionContext()?.waitUntil(promise);\n\n return promise;\n}\n"]}
1
+ {"version":3,"file":"instrumentation.js","names":[],"sources":["../../src/server/instrumentation.ts"],"sourcesContent":["/**\n * instrumentation.ts support\n *\n * Next.js supports an `instrumentation.ts` file at the project root that\n * exports a `register()` function. This function is called once when the\n * server starts, before any request handling. It's the recommended way to\n * set up observability tools (Sentry, Datadog, OpenTelemetry, etc.).\n *\n * Optionally, it can also export `onRequestError()` which is called when\n * an unhandled error occurs during request handling.\n *\n * References:\n * - https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation\n *\n * ## App Router\n *\n * For App Router, `register()` is baked directly into the generated RSC entry\n * as a top-level `await` at module evaluation time (see `entries/app-rsc-entry.ts`\n * `generateRscEntry`). This means it runs inside the Worker process (or RSC\n * Vite environment) — the same process that handles requests — before any\n * request is served. `runInstrumentation()` is NOT called from `configureServer`\n * for App Router.\n *\n * The `onRequestError` handler is stored on `globalThis` so it is visible across\n * the RSC and SSR Vite environments (separate module graphs, same Node.js process).\n * With `@cloudflare/vite-plugin` it runs entirely inside the Worker, so\n * `globalThis` is the Worker's global — also correct.\n *\n * ## Pages Router\n *\n * Pages Router has no RSC entry, so `configureServer()` is the right place to\n * call `register()`. `runInstrumentation()` accepts a `ModuleRunner` (created\n * via `createDirectRunner()`) rather than `server.ssrLoadModule()` so it is\n * safe when `@cloudflare/vite-plugin` is present — that plugin replaces the\n * SSR environment's hot channel, causing `ssrLoadModule()` to crash with\n * `TypeError: Cannot read properties of undefined (reading 'outsideEmitter')`.\n */\n\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { getRequestExecutionContext } from \"../shims/request-context.js\";\n/**\n * Minimal duck-typed interface for the module runner passed to\n * `runInstrumentation`. Only `.import()` is used — this avoids requiring\n * callers (including tests) to provide a full `ModuleRunner` instance.\n */\nexport interface ModuleImporter {\n import(id: string): Promise<unknown>;\n}\n\n/** Possible instrumentation file names. */\nconst INSTRUMENTATION_FILES = [\n \"instrumentation.ts\",\n \"instrumentation.tsx\",\n \"instrumentation.js\",\n \"instrumentation.mjs\",\n \"src/instrumentation.ts\",\n \"src/instrumentation.tsx\",\n \"src/instrumentation.js\",\n \"src/instrumentation.mjs\",\n];\n\n/**\n * Find the instrumentation file in the project root.\n */\nexport function findInstrumentationFile(root: string): string | null {\n for (const file of INSTRUMENTATION_FILES) {\n const fullPath = path.join(root, file);\n if (fs.existsSync(fullPath)) {\n return fullPath;\n }\n }\n return null;\n}\n\n/**\n * The onRequestError handler type from Next.js instrumentation.\n *\n * Called when an unhandled error occurs during request handling.\n * Provides the error, the request info, and an error context.\n */\nexport interface OnRequestErrorContext {\n /** The route path (e.g., '/blog/[slug]') */\n routerKind: \"Pages Router\" | \"App Router\";\n /** The matched route pattern */\n routePath: string;\n /** The route type */\n routeType: \"render\" | \"route\" | \"action\" | \"middleware\";\n /** HTTP status code that will be sent */\n revalidateReason?: \"on-demand\" | \"stale\" | undefined;\n}\n\nexport type OnRequestErrorHandler = (\n error: Error,\n request: { path: string; method: string; headers: Record<string, string> },\n context: OnRequestErrorContext,\n) => void | Promise<void>;\n\n/**\n * Get the registered onRequestError handler (if any).\n *\n * Reads from globalThis so it works across Vite environment boundaries.\n */\nexport function getOnRequestErrorHandler(): OnRequestErrorHandler | null {\n return globalThis.__VINEXT_onRequestErrorHandler__ ?? null;\n}\n\n/**\n * Load and execute the instrumentation file via a ModuleRunner.\n *\n * Called once during Pages Router server startup (`configureServer`). It:\n * 1. Loads the instrumentation module via `runner.import()`.\n * 2. Calls the `register()` function if exported.\n * 3. Stores the `onRequestError()` handler on `globalThis` so it is visible\n * to all Vite environment module graphs (SSR and the host process share\n * the same Node.js `globalThis`).\n *\n * **App Router** does not use this function. For App Router, `register()` is\n * emitted as a top-level `await` inside the generated RSC entry module so it\n * runs in the same Worker/environment as request handling.\n *\n * @param runner - A ModuleRunner created via `createDirectRunner()`. Must be\n * the same long-lived runner used for middleware and SSR so the module graph\n * is shared. Safe with all Vite plugin combinations, including\n * `@cloudflare/vite-plugin`, because it never touches the hot channel.\n * @param instrumentationPath - Absolute path to the instrumentation file\n */\nexport async function runInstrumentation(\n runner: ModuleImporter,\n instrumentationPath: string,\n): Promise<void> {\n try {\n const mod = (await runner.import(instrumentationPath)) as Record<string, unknown>;\n\n // Call register() if exported\n if (typeof mod.register === \"function\") {\n await mod.register();\n }\n\n // Store onRequestError handler on globalThis so environments can reach the\n // same handler.\n if (typeof mod.onRequestError === \"function\") {\n globalThis.__VINEXT_onRequestErrorHandler__ = mod.onRequestError as OnRequestErrorHandler;\n }\n } catch (err) {\n console.error(\n \"[vinext] Failed to load instrumentation:\",\n err instanceof Error ? err.message : String(err),\n );\n }\n}\n\n/**\n * Report a request error via the instrumentation handler.\n *\n * No-op if no onRequestError handler is registered.\n *\n * Reads the handler from globalThis so this function works correctly regardless\n * of which environment it is called from.\n */\nexport function reportRequestError(\n error: Error,\n request: { path: string; method: string; headers: Record<string, string> },\n context: OnRequestErrorContext,\n): Promise<void> {\n const handler = getOnRequestErrorHandler();\n if (!handler) return Promise.resolve();\n\n const promise = (async () => {\n try {\n await handler(error, request, context);\n } catch (reportErr) {\n console.error(\n \"[vinext] onRequestError handler threw:\",\n reportErr instanceof Error ? reportErr.message : String(reportErr),\n );\n }\n })();\n\n // On Cloudflare Workers, register with ctx.waitUntil() so the isolate\n // stays alive until the report completes (e.g. Sentry HTTP request).\n // On Node.js (dev or vinext start), getRequestExecutionContext() returns\n // null — fire-and-forget is fine because the process doesn't die.\n getRequestExecutionContext()?.waitUntil(promise);\n\n return promise;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDA,MAAM,wBAAwB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;;;AAKD,SAAgB,wBAAwB,MAA6B;AACnE,MAAK,MAAM,QAAQ,uBAAuB;EACxC,MAAM,WAAW,KAAK,KAAK,MAAM,KAAK;AACtC,MAAI,GAAG,WAAW,SAAS,CACzB,QAAO;;AAGX,QAAO;;;;;;;AA+BT,SAAgB,2BAAyD;AACvE,QAAO,WAAW,oCAAoC;;;;;;;;;;;;;;;;;;;;;;AAuBxD,eAAsB,mBACpB,QACA,qBACe;AACf,KAAI;EACF,MAAM,MAAO,MAAM,OAAO,OAAO,oBAAoB;AAGrD,MAAI,OAAO,IAAI,aAAa,WAC1B,OAAM,IAAI,UAAU;AAKtB,MAAI,OAAO,IAAI,mBAAmB,WAChC,YAAW,mCAAmC,IAAI;UAE7C,KAAK;AACZ,UAAQ,MACN,4CACA,eAAe,QAAQ,IAAI,UAAU,OAAO,IAAI,CACjD;;;;;;;;;;;AAYL,SAAgB,mBACd,OACA,SACA,SACe;CACf,MAAM,UAAU,0BAA0B;AAC1C,KAAI,CAAC,QAAS,QAAO,QAAQ,SAAS;CAEtC,MAAM,WAAW,YAAY;AAC3B,MAAI;AACF,SAAM,QAAQ,OAAO,SAAS,QAAQ;WAC/B,WAAW;AAClB,WAAQ,MACN,0CACA,qBAAqB,QAAQ,UAAU,UAAU,OAAO,UAAU,CACnE;;KAED;AAMJ,6BAA4B,EAAE,UAAU,QAAQ;AAEhD,QAAO"}
@@ -1,21 +1,9 @@
1
- /**
2
- * ISR (Incremental Static Regeneration) cache layer.
3
- *
4
- * Wraps the pluggable CacheHandler with stale-while-revalidate semantics:
5
- * - Fresh hit: serve immediately
6
- * - Stale hit: serve immediately + trigger background regeneration
7
- * - Miss: render synchronously, cache, serve
8
- *
9
- * Background regeneration is deduped — only one regeneration per cache key
10
- * runs at a time, preventing thundering herd on popular pages.
11
- *
12
- * This layer works with any CacheHandler backend (memory, Redis, KV, etc.)
13
- * because it only uses the standard get/set interface.
14
- */
15
- import { type CacheHandlerValue, type IncrementalCacheValue, type CachedPagesValue, type CachedAppPageValue } from "../shims/cache.js";
16
- export interface ISRCacheEntry {
17
- value: CacheHandlerValue;
18
- isStale: boolean;
1
+ import { CacheHandlerValue, CachedAppPageValue, CachedPagesValue, IncrementalCacheValue } from "../shims/cache.js";
2
+
3
+ //#region src/server/isr-cache.d.ts
4
+ interface ISRCacheEntry {
5
+ value: CacheHandlerValue;
6
+ isStale: boolean;
19
7
  }
20
8
  /**
21
9
  * Get a cache entry with staleness information.
@@ -24,11 +12,11 @@ export interface ISRCacheEntry {
24
12
  * { value, isStale: true } for expired-but-usable entries,
25
13
  * or null for cache misses.
26
14
  */
27
- export declare function isrGet(key: string): Promise<ISRCacheEntry | null>;
15
+ declare function isrGet(key: string): Promise<ISRCacheEntry | null>;
28
16
  /**
29
17
  * Store a value in the ISR cache with a revalidation period.
30
18
  */
31
- export declare function isrSet(key: string, data: IncrementalCacheValue, revalidateSeconds: number, tags?: string[]): Promise<void>;
19
+ declare function isrSet(key: string, data: IncrementalCacheValue, revalidateSeconds: number, tags?: string[]): Promise<void>;
32
20
  /**
33
21
  * Trigger a background regeneration for a cache key.
34
22
  *
@@ -39,27 +27,29 @@ export declare function isrSet(key: string, data: IncrementalCacheValue, revalid
39
27
  * `ctx.waitUntil()` via the ALS-backed ExecutionContext, keeping the isolate
40
28
  * alive until the regeneration completes even after the Response is returned.
41
29
  */
42
- export declare function triggerBackgroundRegeneration(key: string, renderFn: () => Promise<void>): void;
30
+ declare function triggerBackgroundRegeneration(key: string, renderFn: () => Promise<void>): void;
43
31
  /**
44
32
  * Build a CachedPagesValue for the Pages Router ISR cache.
45
33
  */
46
- export declare function buildPagesCacheValue(html: string, pageData: object, status?: number): CachedPagesValue;
34
+ declare function buildPagesCacheValue(html: string, pageData: object, status?: number): CachedPagesValue;
47
35
  /**
48
36
  * Build a CachedAppPageValue for the App Router ISR cache.
49
37
  */
50
- export declare function buildAppPageCacheValue(html: string, rscData?: ArrayBuffer, status?: number): CachedAppPageValue;
38
+ declare function buildAppPageCacheValue(html: string, rscData?: ArrayBuffer, status?: number): CachedAppPageValue;
51
39
  /**
52
40
  * Compute an ISR cache key for a given router type and pathname.
53
41
  * Long pathnames are hashed to stay within KV key-length limits (512 bytes).
54
42
  */
55
- export declare function isrCacheKey(router: "pages" | "app", pathname: string, buildId?: string): string;
43
+ declare function isrCacheKey(router: "pages" | "app", pathname: string, buildId?: string): string;
56
44
  /**
57
45
  * Store the revalidate duration for a cache key.
58
46
  * Uses insertion-order LRU eviction to prevent unbounded growth.
59
47
  */
60
- export declare function setRevalidateDuration(key: string, seconds: number): void;
48
+ declare function setRevalidateDuration(key: string, seconds: number): void;
61
49
  /**
62
50
  * Get the revalidate duration for a cache key.
63
51
  */
64
- export declare function getRevalidateDuration(key: string): number | undefined;
52
+ declare function getRevalidateDuration(key: string): number | undefined;
53
+ //#endregion
54
+ export { ISRCacheEntry, buildAppPageCacheValue, buildPagesCacheValue, getRevalidateDuration, isrCacheKey, isrGet, isrSet, setRevalidateDuration, triggerBackgroundRegeneration };
65
55
  //# sourceMappingURL=isr-cache.d.ts.map
@@ -1,144 +1,127 @@
1
- /**
2
- * ISR (Incremental Static Regeneration) cache layer.
3
- *
4
- * Wraps the pluggable CacheHandler with stale-while-revalidate semantics:
5
- * - Fresh hit: serve immediately
6
- * - Stale hit: serve immediately + trigger background regeneration
7
- * - Miss: render synchronously, cache, serve
8
- *
9
- * Background regeneration is deduped — only one regeneration per cache key
10
- * runs at a time, preventing thundering herd on popular pages.
11
- *
12
- * This layer works with any CacheHandler backend (memory, Redis, KV, etc.)
13
- * because it only uses the standard get/set interface.
14
- */
15
- import { getCacheHandler, } from "../shims/cache.js";
16
- import { fnv1a64 } from "../utils/hash.js";
17
1
  import { getRequestExecutionContext } from "../shims/request-context.js";
2
+ import { fnv1a64 } from "../utils/hash.js";
3
+ import { getCacheHandler } from "../shims/cache.js";
4
+ //#region src/server/isr-cache.ts
5
+ /**
6
+ * ISR (Incremental Static Regeneration) cache layer.
7
+ *
8
+ * Wraps the pluggable CacheHandler with stale-while-revalidate semantics:
9
+ * - Fresh hit: serve immediately
10
+ * - Stale hit: serve immediately + trigger background regeneration
11
+ * - Miss: render synchronously, cache, serve
12
+ *
13
+ * Background regeneration is deduped — only one regeneration per cache key
14
+ * runs at a time, preventing thundering herd on popular pages.
15
+ *
16
+ * This layer works with any CacheHandler backend (memory, Redis, KV, etc.)
17
+ * because it only uses the standard get/set interface.
18
+ */
18
19
  /**
19
- * Get a cache entry with staleness information.
20
- *
21
- * Returns { value, isStale: false } for fresh entries,
22
- * { value, isStale: true } for expired-but-usable entries,
23
- * or null for cache misses.
24
- */
25
- export async function isrGet(key) {
26
- const handler = getCacheHandler();
27
- const result = await handler.get(key);
28
- if (!result || !result.value)
29
- return null;
30
- return {
31
- value: result,
32
- isStale: result.cacheState === "stale",
33
- };
20
+ * Get a cache entry with staleness information.
21
+ *
22
+ * Returns { value, isStale: false } for fresh entries,
23
+ * { value, isStale: true } for expired-but-usable entries,
24
+ * or null for cache misses.
25
+ */
26
+ async function isrGet(key) {
27
+ const result = await getCacheHandler().get(key);
28
+ if (!result || !result.value) return null;
29
+ return {
30
+ value: result,
31
+ isStale: result.cacheState === "stale"
32
+ };
34
33
  }
35
34
  /**
36
- * Store a value in the ISR cache with a revalidation period.
37
- */
38
- export async function isrSet(key, data, revalidateSeconds, tags) {
39
- const handler = getCacheHandler();
40
- await handler.set(key, data, {
41
- revalidate: revalidateSeconds,
42
- tags: tags ?? [],
43
- });
35
+ * Store a value in the ISR cache with a revalidation period.
36
+ */
37
+ async function isrSet(key, data, revalidateSeconds, tags) {
38
+ await getCacheHandler().set(key, data, {
39
+ revalidate: revalidateSeconds,
40
+ tags: tags ?? []
41
+ });
44
42
  }
45
- // ---------------------------------------------------------------------------
46
- // Background regeneration dedup
47
- // ---------------------------------------------------------------------------
48
- const pendingRegenerations = new Map();
43
+ const _PENDING_REGEN_KEY = Symbol.for("vinext.isrCache.pendingRegenerations");
44
+ const _g = globalThis;
45
+ const pendingRegenerations = _g[_PENDING_REGEN_KEY] ??= /* @__PURE__ */ new Map();
49
46
  /**
50
- * Trigger a background regeneration for a cache key.
51
- *
52
- * If a regeneration for this key is already in progress, this is a no-op.
53
- * The renderFn should produce the new cache value and call isrSet internally.
54
- *
55
- * On Cloudflare Workers the regeneration promise is registered with
56
- * `ctx.waitUntil()` via the ALS-backed ExecutionContext, keeping the isolate
57
- * alive until the regeneration completes even after the Response is returned.
58
- */
59
- export function triggerBackgroundRegeneration(key, renderFn) {
60
- if (pendingRegenerations.has(key))
61
- return;
62
- const promise = renderFn()
63
- .catch((err) => {
64
- console.error(`[vinext] ISR background regeneration failed for ${key}:`, err);
65
- })
66
- .finally(() => {
67
- pendingRegenerations.delete(key);
68
- });
69
- pendingRegenerations.set(key, promise);
70
- // Register with the Workers ExecutionContext (retrieved from ALS) so the
71
- // runtime keeps the isolate alive until the regeneration completes, even
72
- // after the Response has already been sent to the client.
73
- getRequestExecutionContext()?.waitUntil(promise);
47
+ * Trigger a background regeneration for a cache key.
48
+ *
49
+ * If a regeneration for this key is already in progress, this is a no-op.
50
+ * The renderFn should produce the new cache value and call isrSet internally.
51
+ *
52
+ * On Cloudflare Workers the regeneration promise is registered with
53
+ * `ctx.waitUntil()` via the ALS-backed ExecutionContext, keeping the isolate
54
+ * alive until the regeneration completes even after the Response is returned.
55
+ */
56
+ function triggerBackgroundRegeneration(key, renderFn) {
57
+ if (pendingRegenerations.has(key)) return;
58
+ const promise = renderFn().catch((err) => {
59
+ console.error(`[vinext] ISR background regeneration failed for ${key}:`, err);
60
+ }).finally(() => {
61
+ pendingRegenerations.delete(key);
62
+ });
63
+ pendingRegenerations.set(key, promise);
64
+ getRequestExecutionContext()?.waitUntil(promise);
74
65
  }
75
- // ---------------------------------------------------------------------------
76
- // Helpers for building ISR cache values
77
- // ---------------------------------------------------------------------------
78
66
  /**
79
- * Build a CachedPagesValue for the Pages Router ISR cache.
80
- */
81
- export function buildPagesCacheValue(html, pageData, status) {
82
- return {
83
- kind: "PAGES",
84
- html,
85
- pageData,
86
- headers: undefined,
87
- status,
88
- };
67
+ * Build a CachedPagesValue for the Pages Router ISR cache.
68
+ */
69
+ function buildPagesCacheValue(html, pageData, status) {
70
+ return {
71
+ kind: "PAGES",
72
+ html,
73
+ pageData,
74
+ headers: void 0,
75
+ status
76
+ };
89
77
  }
90
78
  /**
91
- * Build a CachedAppPageValue for the App Router ISR cache.
92
- */
93
- export function buildAppPageCacheValue(html, rscData, status) {
94
- return {
95
- kind: "APP_PAGE",
96
- html,
97
- rscData,
98
- headers: undefined,
99
- postponed: undefined,
100
- status,
101
- };
79
+ * Build a CachedAppPageValue for the App Router ISR cache.
80
+ */
81
+ function buildAppPageCacheValue(html, rscData, status) {
82
+ return {
83
+ kind: "APP_PAGE",
84
+ html,
85
+ rscData,
86
+ headers: void 0,
87
+ postponed: void 0,
88
+ status
89
+ };
102
90
  }
103
91
  /**
104
- * Compute an ISR cache key for a given router type and pathname.
105
- * Long pathnames are hashed to stay within KV key-length limits (512 bytes).
106
- */
107
- export function isrCacheKey(router, pathname, buildId) {
108
- const normalized = pathname === "/" ? "/" : pathname.replace(/\/$/, "");
109
- const prefix = buildId ? `${router}:${buildId}` : router;
110
- const key = `${prefix}:${normalized}`;
111
- if (key.length <= 200)
112
- return key;
113
- return `${prefix}:__hash:${fnv1a64(normalized)}`;
92
+ * Compute an ISR cache key for a given router type and pathname.
93
+ * Long pathnames are hashed to stay within KV key-length limits (512 bytes).
94
+ */
95
+ function isrCacheKey(router, pathname, buildId) {
96
+ const normalized = pathname === "/" ? "/" : pathname.replace(/\/$/, "");
97
+ const prefix = buildId ? `${router}:${buildId}` : router;
98
+ const key = `${prefix}:${normalized}`;
99
+ if (key.length <= 200) return key;
100
+ return `${prefix}:__hash:${fnv1a64(normalized)}`;
114
101
  }
115
- // ---------------------------------------------------------------------------
116
- // Revalidate duration tracking — remembers how long each ISR key's TTL is
117
- // so we can emit correct Cache-Control headers on cache hits.
118
- // ---------------------------------------------------------------------------
119
- const MAX_REVALIDATE_ENTRIES = 10_000;
120
- const revalidateDurations = new Map();
102
+ const MAX_REVALIDATE_ENTRIES = 1e4;
103
+ const _REVALIDATE_KEY = Symbol.for("vinext.isrCache.revalidateDurations");
104
+ const revalidateDurations = _g[_REVALIDATE_KEY] ??= /* @__PURE__ */ new Map();
121
105
  /**
122
- * Store the revalidate duration for a cache key.
123
- * Uses insertion-order LRU eviction to prevent unbounded growth.
124
- */
125
- export function setRevalidateDuration(key, seconds) {
126
- // Simple LRU: delete and re-insert to move to end (most recent)
127
- revalidateDurations.delete(key);
128
- revalidateDurations.set(key, seconds);
129
- // Evict oldest entries if over limit
130
- while (revalidateDurations.size > MAX_REVALIDATE_ENTRIES) {
131
- const first = revalidateDurations.keys().next().value;
132
- if (first !== undefined)
133
- revalidateDurations.delete(first);
134
- else
135
- break;
136
- }
106
+ * Store the revalidate duration for a cache key.
107
+ * Uses insertion-order LRU eviction to prevent unbounded growth.
108
+ */
109
+ function setRevalidateDuration(key, seconds) {
110
+ revalidateDurations.delete(key);
111
+ revalidateDurations.set(key, seconds);
112
+ while (revalidateDurations.size > MAX_REVALIDATE_ENTRIES) {
113
+ const first = revalidateDurations.keys().next().value;
114
+ if (first !== void 0) revalidateDurations.delete(first);
115
+ else break;
116
+ }
137
117
  }
138
118
  /**
139
- * Get the revalidate duration for a cache key.
140
- */
141
- export function getRevalidateDuration(key) {
142
- return revalidateDurations.get(key);
119
+ * Get the revalidate duration for a cache key.
120
+ */
121
+ function getRevalidateDuration(key) {
122
+ return revalidateDurations.get(key);
143
123
  }
124
+ //#endregion
125
+ export { buildAppPageCacheValue, buildPagesCacheValue, getRevalidateDuration, isrCacheKey, isrGet, isrSet, setRevalidateDuration, triggerBackgroundRegeneration };
126
+
144
127
  //# sourceMappingURL=isr-cache.js.map