@wular/pnext 0.1.5 → 0.1.7

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 (302) hide show
  1. package/bin/pnext +9 -2
  2. package/dist/server/_chunks/aliases-j47a10ce.js +44 -0
  3. package/dist/server/_chunks/analyze-arswqe6s.js +445 -0
  4. package/dist/server/_chunks/boot-af0mv3dy.js +36 -0
  5. package/dist/server/_chunks/build-spy3dxp4.js +84 -0
  6. package/dist/server/_chunks/build-t9h0hec3.js +3550 -0
  7. package/dist/server/_chunks/build-tier-m7yvqz61.js +2472 -0
  8. package/dist/server/_chunks/compile-53j02j27.js +22 -0
  9. package/dist/server/_chunks/config-1yzwexq6.js +27 -0
  10. package/dist/server/_chunks/config-n2z7yxps.js +22 -0
  11. package/dist/server/_chunks/create-meec9hs6.js +134 -0
  12. package/dist/server/_chunks/dev-fjmqg6en.js +220 -0
  13. package/dist/server/_chunks/esbuild-yyktfrtt.js +15 -0
  14. package/dist/server/_chunks/generate-n9sh6hzt.js +21 -0
  15. package/dist/server/_chunks/index-0374j2b9.js +66 -0
  16. package/dist/server/_chunks/index-06nyqntx.js +213 -0
  17. package/dist/server/_chunks/index-1011cscr.js +5263 -0
  18. package/dist/server/_chunks/index-11sfk4hb.js +170 -0
  19. package/dist/server/_chunks/index-20ppawv7.js +297 -0
  20. package/dist/server/_chunks/index-2dv4y4wd.js +1065 -0
  21. package/dist/server/_chunks/index-2vz0wzdn.js +59 -0
  22. package/dist/server/_chunks/index-2wfv4kvx.js +182 -0
  23. package/dist/server/_chunks/index-357na4a8.js +109 -0
  24. package/dist/server/_chunks/index-3b3at80h.js +109 -0
  25. package/dist/server/_chunks/index-3tf1xjsp.js +6166 -0
  26. package/dist/server/_chunks/index-3xbr4eyv.js +105 -0
  27. package/dist/server/_chunks/index-4399bvd2.js +18 -0
  28. package/dist/server/_chunks/index-4hgjrqh7.js +851 -0
  29. package/dist/server/_chunks/index-4q2gbfwk.js +2530 -0
  30. package/dist/server/_chunks/index-4t92hdxd.js +172 -0
  31. package/dist/server/_chunks/index-4zzebszd.js +10 -0
  32. package/dist/server/_chunks/index-5gyr4emz.js +107 -0
  33. package/dist/server/_chunks/index-5hr4062s.js +70 -0
  34. package/dist/server/_chunks/index-68m3mwbd.js +84 -0
  35. package/dist/server/_chunks/index-6b009mt0.js +56 -0
  36. package/dist/server/_chunks/index-6e4fqv30.js +588 -0
  37. package/dist/server/_chunks/index-6gex3pfa.js +15 -0
  38. package/dist/server/_chunks/index-6kp9r0d9.js +11 -0
  39. package/dist/server/_chunks/index-6q7zvrap.js +134 -0
  40. package/dist/server/_chunks/index-73z4esab.js +38 -0
  41. package/dist/server/_chunks/index-79ngvam8.js +60 -0
  42. package/dist/server/_chunks/index-7wc9n8be.js +25 -0
  43. package/dist/server/_chunks/index-8k7pfejn.js +1599 -0
  44. package/dist/server/_chunks/index-8kcxdfya.js +206 -0
  45. package/dist/server/_chunks/index-91x12ykq.js +274 -0
  46. package/dist/server/_chunks/index-9ch50vtq.js +18 -0
  47. package/dist/server/_chunks/index-9hx2641q.js +28 -0
  48. package/dist/server/_chunks/index-9n2914ww.js +535 -0
  49. package/dist/server/_chunks/index-9ych9ma8.js +207 -0
  50. package/dist/server/_chunks/index-b6wtkdp4.js +24 -0
  51. package/dist/server/_chunks/index-bcws5eh2.js +35 -0
  52. package/dist/server/_chunks/index-c0g2wf3z.js +92 -0
  53. package/dist/server/_chunks/index-cf4rvxv6.js +95 -0
  54. package/dist/server/_chunks/index-cjgqs13g.js +65 -0
  55. package/dist/server/_chunks/index-ckkdpht5.js +41 -0
  56. package/dist/server/_chunks/index-cyfednwb.js +87 -0
  57. package/dist/server/_chunks/index-danncfhy.js +311 -0
  58. package/dist/server/_chunks/index-dg0f05zs.js +199 -0
  59. package/dist/server/_chunks/index-e3a6yx84.js +18 -0
  60. package/dist/server/_chunks/index-e88tyv35.js +45 -0
  61. package/dist/server/_chunks/index-eajaspjk.js +1253 -0
  62. package/dist/server/_chunks/index-eeaanp2e.js +483 -0
  63. package/dist/server/_chunks/index-egykcqg3.js +101 -0
  64. package/dist/server/_chunks/index-en7n9f7m.js +22 -0
  65. package/dist/server/_chunks/index-ezgj0tr1.js +88 -0
  66. package/dist/server/_chunks/index-fkp000p1.js +590 -0
  67. package/dist/server/_chunks/index-fn1chkkd.js +214 -0
  68. package/dist/server/_chunks/index-fp8r0sqs.js +64 -0
  69. package/dist/server/_chunks/index-ggk2j965.js +9432 -0
  70. package/dist/server/_chunks/index-grta8ap3.js +238 -0
  71. package/dist/server/_chunks/index-h2a70tg4.js +7 -0
  72. package/dist/server/_chunks/index-h4xy648y.js +51 -0
  73. package/dist/server/_chunks/index-hkdfj58q.js +92 -0
  74. package/dist/server/_chunks/index-j2zrcp1k.js +66 -0
  75. package/dist/server/_chunks/index-jcsjq3d1.js +20 -0
  76. package/dist/server/_chunks/index-jepjvcrf.js +198 -0
  77. package/dist/server/_chunks/index-jks0x0a1.js +14 -0
  78. package/dist/server/_chunks/index-jx7bqvw1.js +57 -0
  79. package/dist/server/_chunks/index-k1g3epw0.js +1299 -0
  80. package/dist/server/_chunks/index-knp0s912.js +7 -0
  81. package/dist/server/_chunks/index-kq8kpzye.js +472 -0
  82. package/dist/server/_chunks/index-kqyy1d4f.js +50 -0
  83. package/dist/server/_chunks/index-kresp2n8.js +445 -0
  84. package/dist/server/_chunks/index-ms9v9tnx.js +31 -0
  85. package/dist/server/_chunks/index-n4hxpng2.js +11 -0
  86. package/dist/server/_chunks/index-ncnes8c6.js +17 -0
  87. package/dist/server/_chunks/index-nqh3xhdc.js +57 -0
  88. package/dist/server/_chunks/index-nyrba2kr.js +4130 -0
  89. package/dist/server/_chunks/index-p77b4kcx.js +296 -0
  90. package/dist/server/_chunks/index-pym1cezq.js +39 -0
  91. package/dist/server/_chunks/index-q738kkhj.js +100 -0
  92. package/dist/server/_chunks/index-qjj6gddn.js +54 -0
  93. package/dist/server/_chunks/index-qm6kmhqs.js +110 -0
  94. package/dist/server/_chunks/index-qn4z5s3c.js +819 -0
  95. package/dist/server/_chunks/index-qpwsgt3a.js +158 -0
  96. package/dist/server/_chunks/index-r97ptz1q.js +97 -0
  97. package/dist/server/_chunks/index-ras0sdab.js +26 -0
  98. package/dist/server/_chunks/index-rcs322t1.js +19 -0
  99. package/dist/server/_chunks/index-rn8dyr1f.js +126 -0
  100. package/dist/server/_chunks/index-rt9qq1va.js +4 -0
  101. package/dist/server/_chunks/index-rthrsed5.js +356 -0
  102. package/dist/server/_chunks/index-sctcgyvv.js +185 -0
  103. package/dist/server/_chunks/index-sjpckxqn.js +213 -0
  104. package/dist/server/_chunks/index-sq3kvz3g.js +200 -0
  105. package/dist/server/_chunks/index-stbk3jhn.js +31 -0
  106. package/dist/server/_chunks/index-sv8m6789.js +266 -0
  107. package/dist/server/_chunks/index-tgcakdxc.js +125 -0
  108. package/dist/server/_chunks/index-tgsfjmep.js +74 -0
  109. package/dist/server/_chunks/index-tq0pc7eg.js +154 -0
  110. package/dist/server/_chunks/index-tq1f96v7.js +51 -0
  111. package/dist/server/_chunks/index-tqn2qnnn.js +241 -0
  112. package/dist/server/_chunks/index-tvqkq6e6.js +128 -0
  113. package/dist/server/_chunks/index-v1ags1na.js +132 -0
  114. package/dist/server/_chunks/index-vvmmknm1.js +1431 -0
  115. package/dist/server/_chunks/index-vvq7rqtn.js +329 -0
  116. package/dist/server/_chunks/index-vz0km5qk.js +33 -0
  117. package/dist/server/_chunks/index-w6h8m6vp.js +138 -0
  118. package/dist/server/_chunks/index-web361b8.js +138 -0
  119. package/dist/server/_chunks/index-wpfhfbs4.js +194 -0
  120. package/dist/server/_chunks/index-x0y005nh.js +283 -0
  121. package/dist/server/_chunks/index-x3yn4ywm.js +22 -0
  122. package/dist/server/_chunks/index-x93hv0sc.js +271 -0
  123. package/dist/server/_chunks/index-xvj80c3a.js +30 -0
  124. package/dist/server/_chunks/index-xywjg2vc.js +100 -0
  125. package/dist/server/_chunks/index-y2jr2n72.js +152 -0
  126. package/dist/server/_chunks/index-y36a0ybw.js +57 -0
  127. package/dist/server/_chunks/index-ye9hmsvf.js +47 -0
  128. package/dist/server/_chunks/index-yhxkxghe.js +56 -0
  129. package/dist/server/_chunks/index-ym67zqxp.js +130 -0
  130. package/dist/server/_chunks/index-ytjvpbm2.js +736 -0
  131. package/dist/server/_chunks/index-yz54pxrh.js +960 -0
  132. package/dist/server/_chunks/index-z4z9zv3b.js +733 -0
  133. package/dist/server/_chunks/index-z84ab1w0.js +1270 -0
  134. package/dist/server/_chunks/index-z88qv16t.js +11 -0
  135. package/dist/server/_chunks/index-zqpqyg8p.js +666 -0
  136. package/dist/server/_chunks/loader-7yw0j98z.js +78 -0
  137. package/dist/server/_chunks/modules-jn8bmbn8.js +74 -0
  138. package/dist/server/_chunks/pipeline-yy9jhydf.js +832 -0
  139. package/dist/server/_chunks/production-jar9ztm3.js +44 -0
  140. package/dist/server/_chunks/proxy-config-j84dgksn.js +21 -0
  141. package/dist/server/_chunks/proxy-w1d0wmsn.js +33 -0
  142. package/dist/server/_chunks/router-k1reahfn.js +498 -0
  143. package/dist/server/_chunks/routes-2s277fc6.js +64 -0
  144. package/dist/server/_chunks/run-pvd8bs1t.js +696 -0
  145. package/dist/server/_chunks/server-mt4a994c.js +1835 -0
  146. package/dist/server/_chunks/tsconfig-defaults-1nb3308g.js +20 -0
  147. package/dist/server/_chunks/typegen-0qr0459b.js +35 -0
  148. package/dist/server/api/client-cache.js +14 -0
  149. package/dist/server/cli/index.js +378 -0
  150. package/dist/server/cli/start.js +137 -0
  151. package/dist/server/client/reference.js +16 -0
  152. package/dist/server/compat/next/cache.js +56 -0
  153. package/dist/server/compat/next/canonical-url.js +13 -0
  154. package/dist/server/compat/next/client-cache.js +57 -0
  155. package/dist/server/compat/next/client-navigation.js +232 -0
  156. package/dist/server/compat/next/client-only.js +1 -0
  157. package/dist/server/compat/next/client-script.js +178 -0
  158. package/dist/server/compat/next/client-server.js +34 -0
  159. package/dist/server/compat/next/config-headers.js +32 -0
  160. package/dist/server/compat/next/config-loader.js +25 -0
  161. package/dist/server/compat/next/config.js +10 -0
  162. package/dist/server/compat/next/constants.js +18 -0
  163. package/dist/server/compat/next/custom-server.js +10 -0
  164. package/dist/server/compat/next/dist/client/components/app-router-headers.js +48 -0
  165. package/dist/server/compat/next/dist/server/web/spec-extension/revalidate.js +27 -0
  166. package/dist/server/compat/next/dist/server/web/spec-extension/unstable-cache.js +25 -0
  167. package/dist/server/compat/next/dist/server/web/spec-extension/unstable-no-store.js +25 -0
  168. package/dist/server/compat/next/dynamic.js +32 -0
  169. package/dist/server/compat/next/error.js +112 -0
  170. package/dist/server/compat/next/font/cache.js +14 -0
  171. package/dist/server/compat/next/font/google.js +3 -0
  172. package/dist/server/compat/next/font/index.js +1 -0
  173. package/dist/server/compat/next/font/local.js +22 -0
  174. package/dist/server/compat/next/font/runtime-client.js +33 -0
  175. package/dist/server/compat/next/font/runtime.js +41 -0
  176. package/dist/server/compat/next/font/shared.js +22 -0
  177. package/dist/server/compat/next/form.js +129 -0
  178. package/dist/server/compat/next/head.js +10 -0
  179. package/dist/server/compat/next/headers.js +30 -0
  180. package/dist/server/compat/next/image/client.js +11 -0
  181. package/dist/server/compat/next/image/config.js +18 -0
  182. package/dist/server/compat/next/image/optimizer.js +25 -0
  183. package/dist/server/compat/next/image/patterns.js +12 -0
  184. package/dist/server/compat/next/image/props.js +16 -0
  185. package/dist/server/compat/next/image/shared.js +86 -0
  186. package/dist/server/compat/next/image/static-metadata.js +32 -0
  187. package/dist/server/compat/next/image/validate.js +8 -0
  188. package/dist/server/compat/next/image.js +59 -0
  189. package/dist/server/compat/next/index.js +1 -0
  190. package/dist/server/compat/next/legacy-image.js +78 -0
  191. package/dist/server/compat/next/legacy-request-apis.js +24 -0
  192. package/dist/server/compat/next/link-transform.js +14 -0
  193. package/dist/server/compat/next/link.js +14 -0
  194. package/dist/server/compat/next/navigation.js +190 -0
  195. package/dist/server/compat/next/offline.js +45 -0
  196. package/dist/server/compat/next/og.js +8 -0
  197. package/dist/server/compat/next/preferred-region.js +8 -0
  198. package/dist/server/compat/next/redirects.js +30 -0
  199. package/dist/server/compat/next/resource-hints.js +30 -0
  200. package/dist/server/compat/next/rewrites.js +41 -0
  201. package/dist/server/compat/next/root-params.js +121 -0
  202. package/dist/server/compat/next/route-state.js +23 -0
  203. package/dist/server/compat/next/router.js +103 -0
  204. package/dist/server/compat/next/script.js +37 -0
  205. package/dist/server/compat/next/server-only.js +1 -0
  206. package/dist/server/compat/next/server.js +131 -0
  207. package/dist/server/compat/next/svgr.js +14 -0
  208. package/dist/server/compat/next/telemetry.js +10 -0
  209. package/dist/server/compat/next/usage.js +13 -0
  210. package/dist/server/compat/next/user-agent.js +12 -0
  211. package/dist/server/compat/next/web-vitals.js +35 -0
  212. package/dist/server/compat/react/action-state.js +11 -0
  213. package/dist/server/compat/react/client-lite.js +83 -0
  214. package/dist/server/compat/react/client.js +131 -0
  215. package/dist/server/compat/react/compiler-runtime.js +42 -0
  216. package/dist/server/compat/react/dom-client.js +106 -0
  217. package/dist/server/compat/react/dom-react-server.js +37 -0
  218. package/dist/server/compat/react/dom-server.js +40 -0
  219. package/dist/server/compat/react/dom.js +52 -0
  220. package/dist/server/compat/react/hooks-extra.js +12 -0
  221. package/dist/server/compat/react/internals.js +14 -0
  222. package/dist/server/compat/react/parity.js +11 -0
  223. package/dist/server/compat/react/preact.js +113 -0
  224. package/dist/server/compat/react/react-server.js +133 -0
  225. package/dist/server/compat/react/router-shim.js +8 -0
  226. package/dist/server/compat/react/server-component-use.js +14 -0
  227. package/dist/server/compat/react/server-inserted-html.js +14 -0
  228. package/dist/server/compat/react/server.js +194 -0
  229. package/dist/server/compat/react/style-values.js +10 -0
  230. package/dist/server/compat/react/use.js +10 -0
  231. package/dist/server/compat/react/view-transition.js +12 -0
  232. package/dist/server/generation.json +1 -0
  233. package/package.json +4 -1
  234. package/src/api/dynamic.tsx +2 -0
  235. package/src/api/server.ts +24 -6
  236. package/src/cli/adapters/vercel-warm.ts +315 -61
  237. package/src/cli/adapters/vercel.ts +348 -71
  238. package/src/cli/build.ts +58 -33
  239. package/src/cli/index.ts +23 -10
  240. package/src/cli/serve/entry.ts +21 -159
  241. package/src/cli/serve/immutable.ts +31 -0
  242. package/src/cli/serve/pipeline.ts +82 -84
  243. package/src/cli/start.ts +3 -1
  244. package/src/client/chunk-fold.ts +19 -6
  245. package/src/client/react-tier.ts +3 -2
  246. package/src/client/reference-stub.ts +21 -2
  247. package/src/compat/actions/client-plugin.ts +4 -2
  248. package/src/compat/actions/config.ts +6 -5
  249. package/src/compat/actions/extensions.ts +2 -3
  250. package/src/compat/aliases.ts +8 -1
  251. package/src/compat/bundler/config.ts +88 -0
  252. package/src/compat/bundler/optimize-package-imports.ts +86 -26
  253. package/src/compat/bundler/relay-transform.ts +15 -3
  254. package/src/compat/cache-control.ts +16 -8
  255. package/src/compat/css/modules.ts +18 -5
  256. package/src/compat/lifecycle/error-funnel.ts +1 -1
  257. package/src/compat/lifecycle/instrumentation.ts +117 -24
  258. package/src/compat/lifecycle/testmode.ts +3 -2
  259. package/src/compat/next/config-loader.ts +137 -13
  260. package/src/compat/next/font/runtime.ts +22 -2
  261. package/src/compat/next/og.ts +3 -3
  262. package/src/compat/next/usage.ts +3 -2
  263. package/src/compat/pages/api.ts +83 -14
  264. package/src/compat/pages/router.ts +30 -14
  265. package/src/compat/register/bundler.ts +3 -1
  266. package/src/compat/register/middleware.ts +1 -1
  267. package/src/compat/register/otel.ts +5 -9
  268. package/src/compat/register/render.ts +3 -1
  269. package/src/compat/register/use-cache.ts +3 -1
  270. package/src/compat/release.ts +46 -0
  271. package/src/compat/segment/serve.ts +1 -1
  272. package/src/compat/validation/validate.ts +10 -7
  273. package/src/config.ts +51 -7
  274. package/src/css/assets.ts +213 -0
  275. package/src/css/build.ts +174 -238
  276. package/src/dev/server.ts +27 -8
  277. package/src/extensions.ts +4 -0
  278. package/src/render/hooks.ts +13 -0
  279. package/src/render/renderer.ts +52 -32
  280. package/src/request/context.ts +9 -0
  281. package/src/resolve/dynamic.ts +3 -1
  282. package/src/resolve/imports.ts +12 -52
  283. package/src/resolve/package-json.ts +56 -0
  284. package/src/resolve/scan-facts.ts +65 -0
  285. package/src/routing/href.ts +10 -3
  286. package/src/routing/match.ts +287 -0
  287. package/src/routing/metadata-files.ts +19 -5
  288. package/src/routing/proxy-config.ts +137 -0
  289. package/src/routing/proxy.ts +35 -134
  290. package/src/routing/routes.ts +22 -281
  291. package/src/runtime/fingerprint.ts +23 -8
  292. package/src/runtime/load.ts +170 -0
  293. package/src/runtime/loader.ts +215 -43
  294. package/src/runtime/module-cache.ts +13 -0
  295. package/src/runtime/modules.ts +370 -81
  296. package/src/runtime/prebundle.ts +81 -0
  297. package/src/runtime/production.ts +391 -0
  298. package/src/runtime/release-graph.ts +334 -0
  299. package/src/runtime/vendor-build.ts +724 -13
  300. package/src/runtime/vendor.ts +16 -3
  301. package/src/types.ts +2 -0
  302. package/src/utils/fs.ts +89 -3
@@ -0,0 +1,1431 @@
1
+ // @bun
2
+ import { join as __pnextJoin } from "node:path";
3
+ const __PNEXT_PACKAGE_ROOT__ = __pnextJoin(import.meta.dirname, "../../..");
4
+ import {
5
+ rewriteDynamicCallTargets,
6
+ rewriteLiteralDynamicCalls,
7
+ sourceHasDynamicImport
8
+ } from "./index-91x12ykq.js";
9
+ import {
10
+ applyServerHrefConfig,
11
+ isReleaseCompile,
12
+ serverBundleExtraConditions
13
+ } from "./index-3xbr4eyv.js";
14
+ import {
15
+ frameworkFingerprint
16
+ } from "./index-c0g2wf3z.js";
17
+ import {
18
+ build,
19
+ transform
20
+ } from "./index-cjgqs13g.js";
21
+ import {
22
+ writeFileAtomic
23
+ } from "./index-20ppawv7.js";
24
+ import {
25
+ traceEnabled
26
+ } from "./index-vz0km5qk.js";
27
+ import {
28
+ prebundledFile
29
+ } from "./index-y36a0ybw.js";
30
+ import {
31
+ frameworkRuntimeAliasEntries,
32
+ pathToFileHref,
33
+ pnextAliases
34
+ } from "./index-x93hv0sc.js";
35
+ import {
36
+ productionRelease
37
+ } from "./index-tqn2qnnn.js";
38
+ import {
39
+ cachedExistsSync,
40
+ resolveExternalLoadTarget,
41
+ resolveImport,
42
+ workspacePackageRoots
43
+ } from "./index-yz54pxrh.js";
44
+ import {
45
+ applyBundledSourceTransforms,
46
+ applyServerSourcePreTransforms,
47
+ applyServerSourceTransforms,
48
+ extraLoadableExtensions,
49
+ getAssetExtensions,
50
+ getBundlerExtensions,
51
+ getCssExtensions,
52
+ getImportAliasExtensions,
53
+ onLoadableExtensionsChanged,
54
+ serverDefineOptions,
55
+ sourceNeedsServerTransforms
56
+ } from "./index-zqpqyg8p.js";
57
+ import {
58
+ escapeRegex
59
+ } from "./index-qjj6gddn.js";
60
+ import {
61
+ __require
62
+ } from "./index-rt9qq1va.js";
63
+
64
+ // src/runtime/loader.ts
65
+ import { createHash as createHash2 } from "crypto";
66
+ import { createRequire } from "module";
67
+ import { existsSync, readFileSync as readFileSync2, realpathSync, statSync as statSync2, writeFileSync as writeFileSync2 } from "fs";
68
+ import { mkdir as mkdir3, readFile as readFile3, stat as stat3, writeFile } from "fs/promises";
69
+ import path3 from "path";
70
+ import { fileURLToPath as fileURLToPath2 } from "url";
71
+
72
+ // src/runtime/module-cache.ts
73
+ import { mkdirSync, readFileSync, statSync, writeFileSync } from "fs";
74
+ import { mkdir, readFile, stat } from "fs/promises";
75
+ import { createHash, randomUUID } from "crypto";
76
+ import path from "path";
77
+ import { fileURLToPath } from "url";
78
+ function devHeadTrimEnabled() {
79
+ return process.env.PNEXT_HEAD_TRIM !== "0";
80
+ }
81
+ var watcherFreshRoots = new Set;
82
+ function setDevWatcherFreshness(outPath, trusted) {
83
+ if (trusted)
84
+ watcherFreshRoots.add(cacheRoot(outPath));
85
+ else
86
+ watcherFreshRoots.delete(cacheRoot(outPath));
87
+ }
88
+ function watcherFreshnessTrusted(root) {
89
+ return watcherFreshRoots.has(root) && process.env.PNEXT_DEV_WATCH_FRESHNESS !== "0";
90
+ }
91
+ var BINARY_SOURCE = /\.(?:png|jpe?g|gif|webp|avif|ico|bmp|woff2?|ttf|otf|eot|mp[34]|webm|pdf)$/i;
92
+ var MISSING = "missing";
93
+ var frameworkRoot = path.resolve(path.dirname(fileURLToPath(Bun.pathToFileURL(__PNEXT_PACKAGE_ROOT__ + "/src/runtime/module-cache.ts").href)), "..", "..");
94
+ var portablePaths = new Map;
95
+ var memoPortablePaths = process.env.PNEXT_DEV_GRAPH_FAST !== "0";
96
+ function portableSourcePath(file, workspaceRoot) {
97
+ if (!memoPortablePaths)
98
+ return computePortableSourcePath(file, workspaceRoot);
99
+ const memoKey = `${workspaceRoot}\x00${file}`;
100
+ const memoized = portablePaths.get(memoKey);
101
+ if (memoized !== undefined)
102
+ return memoized;
103
+ const computed = computePortableSourcePath(file, workspaceRoot);
104
+ portablePaths.set(memoKey, computed);
105
+ return computed;
106
+ }
107
+ function computePortableSourcePath(file, workspaceRoot) {
108
+ const inWorkspace = path.relative(workspaceRoot, file);
109
+ if (inWorkspace && !inWorkspace.startsWith("..") && !path.isAbsolute(inWorkspace)) {
110
+ return `w:${toPosix(inWorkspace)}`;
111
+ }
112
+ const inFramework = path.relative(frameworkRoot, file);
113
+ if (inFramework && !inFramework.startsWith("..") && !path.isAbsolute(inFramework)) {
114
+ return `f:${toPosix(inFramework)}`;
115
+ }
116
+ return `a:${toPosix(file)}`;
117
+ }
118
+ function absoluteSourcePath(key, workspaceRoot) {
119
+ const value = key.slice(2).split("/").join(path.sep);
120
+ if (key.startsWith("w:"))
121
+ return path.resolve(workspaceRoot, value);
122
+ if (key.startsWith("f:"))
123
+ return path.resolve(frameworkRoot, value);
124
+ return value;
125
+ }
126
+ var toPosix = (file) => path.sep === "/" ? file : file.split(path.sep).join("/");
127
+ function devSourceIdentity(file, workspaceRoot) {
128
+ return portableSourcePath(file, workspaceRoot);
129
+ }
130
+ var DEV_SOURCE_MISSING = MISSING;
131
+ function isBinaryDevSource(file) {
132
+ return BINARY_SOURCE.test(file);
133
+ }
134
+ function devTextSourceHash(source) {
135
+ return Bun.hash(source).toString(36);
136
+ }
137
+ var caches = new Map;
138
+ var persistFlushes = new Set;
139
+ function flushDevModuleCaches() {
140
+ for (const flushNow of persistFlushes)
141
+ flushNow();
142
+ }
143
+ function devModuleCache(config, options) {
144
+ const root = cacheRoot(config.outPath);
145
+ const existing = caches.get(root);
146
+ if (existing)
147
+ return existing;
148
+ const created = createDevModuleCache(root, config.workspaceRoot, options);
149
+ caches.set(root, created);
150
+ return created;
151
+ }
152
+ function cacheRoot(outPath) {
153
+ return path.join(outPath, "cache", "server");
154
+ }
155
+ function createDevModuleCache(root, workspaceRoot, options) {
156
+ const indexFile = path.join(root, "graph.json");
157
+ const outRoot = `${path.dirname(path.dirname(root))}${path.sep}`;
158
+ const generated = (file) => file.startsWith(outRoot) || file.includes(`${path.sep}pnext-pages-compat${path.sep}`);
159
+ const key = createHash("sha256").update(`${options.compileKey}\x00${frameworkFingerprint(root)}`).digest("hex").slice(0, 16);
160
+ establishCacheTrust(root);
161
+ const records = indexRecords(readIndexFile(indexFile), key, workspaceRoot);
162
+ const booted = traceEnabled("server") && records.size > 0 ? new Map([...records].map(([file, record]) => [file, record.srcHash])) : undefined;
163
+ const pending = new Map;
164
+ const graphFast = process.env.PNEXT_DEV_GRAPH_FAST !== "0";
165
+ const settledThisPass = new Map;
166
+ const refreshedThisPass = new Set;
167
+ let passes = 0;
168
+ const closures = new Map;
169
+ const hashes = new Map;
170
+ let dirty = false;
171
+ let flush;
172
+ let retries = 0;
173
+ function persist() {
174
+ if (flush)
175
+ return;
176
+ flush = setTimeout(async () => {
177
+ flush = undefined;
178
+ if (!dirty)
179
+ return;
180
+ const contents = serializeIndex(key, records, workspaceRoot);
181
+ try {
182
+ await mkdir(root, { recursive: true });
183
+ await writeFileAtomic(indexFile, contents);
184
+ dirty = false;
185
+ } catch {
186
+ if (++retries < 3)
187
+ persist();
188
+ }
189
+ }, 50);
190
+ flush.unref?.();
191
+ }
192
+ function flushPersistNow() {
193
+ if (flush) {
194
+ clearTimeout(flush);
195
+ flush = undefined;
196
+ }
197
+ if (!dirty)
198
+ return;
199
+ dirty = false;
200
+ try {
201
+ writeFileSync(indexFile, serializeIndex(key, records, workspaceRoot));
202
+ } catch {}
203
+ }
204
+ persistFlushes.add(flushPersistNow);
205
+ process.on("exit", flushPersistNow);
206
+ async function sourceRecord(file) {
207
+ const inflight = pending.get(file) ?? (graphFast && passes > 0 ? settledThisPass.get(file) : undefined);
208
+ if (inflight)
209
+ return inflight;
210
+ const previous = records.get(file);
211
+ const next = readSourceRecord(file, previous, options.edges).then((record) => {
212
+ pending.delete(file);
213
+ if (record === previous)
214
+ return record;
215
+ records.set(file, record);
216
+ dirty = true;
217
+ persist();
218
+ return record;
219
+ });
220
+ pending.set(file, next);
221
+ if (graphFast && passes > 0)
222
+ settledThisPass.set(file, next);
223
+ return next;
224
+ }
225
+ async function refresh(file) {
226
+ if (watcherFreshnessTrusted(root))
227
+ return;
228
+ const reachable = closures.get(file);
229
+ if (!reachable)
230
+ return;
231
+ if (passes > 0 && refreshedThisPass.has(file))
232
+ return;
233
+ refreshedThisPass.add(file);
234
+ const changed = [];
235
+ await Promise.all([...reachable].map(async (source) => {
236
+ const previous = records.get(source);
237
+ const record = await sourceRecord(source);
238
+ if (previous?.srcHash !== record.srcHash)
239
+ changed.push(source);
240
+ }));
241
+ if (changed.length > 0)
242
+ forget(changed);
243
+ }
244
+ function forget(changed) {
245
+ for (const [source, reachable] of closures) {
246
+ if (!changed.some((target) => reachable.has(target)))
247
+ continue;
248
+ closures.delete(source);
249
+ hashes.delete(source);
250
+ }
251
+ }
252
+ async function serialFrontier(frontier, file) {
253
+ const reached = [];
254
+ for (const current of frontier) {
255
+ const known = current === file ? undefined : closures.get(current);
256
+ reached.push(known ? { expand: false, targets: known } : { expand: true, targets: (await sourceRecord(current)).imports });
257
+ }
258
+ return reached;
259
+ }
260
+ async function serialRecords(reachable) {
261
+ const records2 = [];
262
+ for (const source of reachable)
263
+ records2.push(await sourceRecord(source));
264
+ return records2;
265
+ }
266
+ async function closure(file) {
267
+ const cached = closures.get(file);
268
+ if (cached)
269
+ return cached;
270
+ const seen = new Set([file]);
271
+ let frontier = [file];
272
+ while (frontier.length > 0) {
273
+ const reached = graphFast ? await Promise.all(frontier.map(async (current) => {
274
+ const known = current === file ? undefined : closures.get(current);
275
+ return known ? { expand: false, targets: known } : { expand: true, targets: (await sourceRecord(current)).imports };
276
+ })) : await serialFrontier(frontier, file);
277
+ const next = [];
278
+ for (const { expand, targets } of reached) {
279
+ for (const target of targets) {
280
+ if (seen.has(target))
281
+ continue;
282
+ seen.add(target);
283
+ if (expand)
284
+ next.push(target);
285
+ }
286
+ }
287
+ frontier = next;
288
+ }
289
+ closures.set(file, seen);
290
+ return seen;
291
+ }
292
+ async function computeGraphHash(file) {
293
+ const reachable = [...await closure(file)].sort();
294
+ const records2 = graphFast ? await Promise.all(reachable.map((source) => sourceRecord(source))) : await serialRecords(reachable);
295
+ const hash = createHash("sha256").update(key).update("\x00");
296
+ const moved = [];
297
+ for (const [index, source] of reachable.entries()) {
298
+ const record = records2[index];
299
+ hash.update(generated(source) ? "" : portableSourcePath(source, workspaceRoot));
300
+ hash.update("\x00");
301
+ hash.update(record.srcHash);
302
+ hash.update("\x00");
303
+ if (booted && booted.get(source) !== record.srcHash)
304
+ moved.push(source);
305
+ }
306
+ if (booted && moved.length > 0) {
307
+ console.log(`dev-cache ${path.basename(file)} renamed: ${moved.length} source(s) differ from the persisted graph
308
+ ${moved.slice(0, 10).join(`
309
+ `)}`);
310
+ }
311
+ return hash.digest("hex").slice(0, 16);
312
+ }
313
+ return {
314
+ root,
315
+ graphKey: key,
316
+ async graphSources(files) {
317
+ const reachable = new Set;
318
+ for (const file of files)
319
+ for (const source of await closure(path.resolve(file)))
320
+ reachable.add(source);
321
+ return Promise.all([...reachable].sort().map(async (source) => {
322
+ const record = await sourceRecord(source);
323
+ return [source, record.mtimeMs, record.size, record.srcHash];
324
+ }));
325
+ },
326
+ async graphHash(file) {
327
+ const resolved = path.resolve(file);
328
+ await refresh(resolved);
329
+ const existing = hashes.get(resolved);
330
+ if (existing)
331
+ return existing;
332
+ const next = computeGraphHash(resolved).catch((error) => {
333
+ hashes.delete(resolved);
334
+ throw error;
335
+ });
336
+ hashes.set(resolved, next);
337
+ return next;
338
+ },
339
+ knows(file) {
340
+ return records.has(path.resolve(file));
341
+ },
342
+ async isClientSource(file) {
343
+ return (await sourceRecord(path.resolve(file))).client;
344
+ },
345
+ async packageDemand(file, prune) {
346
+ const resolved = path.resolve(file);
347
+ const demand = new Set;
348
+ if (!prune) {
349
+ for (const source of await closure(resolved)) {
350
+ for (const name of (await sourceRecord(source)).packages)
351
+ demand.add(name);
352
+ }
353
+ return [...demand];
354
+ }
355
+ const seen = new Set([resolved]);
356
+ let frontier = [resolved];
357
+ while (frontier.length > 0) {
358
+ const kept = (await Promise.all(frontier.map(async (source) => await prune(source) ? undefined : source))).filter((source) => source !== undefined);
359
+ const reached = await Promise.all(kept.map((source) => sourceRecord(source)));
360
+ const next = [];
361
+ for (const record of reached) {
362
+ for (const name of record.packages)
363
+ demand.add(name);
364
+ for (const target of record.imports) {
365
+ if (seen.has(target))
366
+ continue;
367
+ seen.add(target);
368
+ next.push(target);
369
+ }
370
+ }
371
+ frontier = next;
372
+ }
373
+ return [...demand];
374
+ },
375
+ hold() {
376
+ if (passes++ === 0) {
377
+ refreshedThisPass.clear();
378
+ settledThisPass.clear();
379
+ }
380
+ let released = false;
381
+ return () => {
382
+ if (released)
383
+ return;
384
+ released = true;
385
+ if (--passes === 0)
386
+ settledThisPass.clear();
387
+ };
388
+ },
389
+ invalidate(files) {
390
+ const changed = new Set([...files].map((file) => path.resolve(file)));
391
+ if (changed.size === 0)
392
+ return;
393
+ for (const file of changed) {
394
+ records.delete(file);
395
+ pending.delete(file);
396
+ settledThisPass.delete(file);
397
+ dirty = true;
398
+ }
399
+ forget([...changed]);
400
+ persist();
401
+ }
402
+ };
403
+ }
404
+ var missingRecord = () => ({
405
+ mtimeMs: 0,
406
+ size: 0,
407
+ srcHash: MISSING,
408
+ imports: [],
409
+ packages: [],
410
+ client: false
411
+ });
412
+ async function readSourceRecord(file, previous, edges) {
413
+ const sync = devHeadTrimEnabled();
414
+ const stats = sync ? (() => {
415
+ try {
416
+ return statSync(file);
417
+ } catch {
418
+ return;
419
+ }
420
+ })() : await stat(file).catch(() => {
421
+ return;
422
+ });
423
+ if (!stats)
424
+ return missingRecord();
425
+ if (previous?.mtimeMs === stats.mtimeMs && previous.size === stats.size) {
426
+ return previous;
427
+ }
428
+ if (isBinaryDevSource(file)) {
429
+ return {
430
+ mtimeMs: stats.mtimeMs,
431
+ size: stats.size,
432
+ srcHash: `b${stats.size.toString(36)}.${Math.round(stats.mtimeMs).toString(36)}`,
433
+ imports: [],
434
+ packages: [],
435
+ client: false
436
+ };
437
+ }
438
+ const source = sync ? (() => {
439
+ try {
440
+ return readFileSync(file, "utf8");
441
+ } catch {
442
+ return;
443
+ }
444
+ })() : await readFile(file, "utf8").catch(() => {
445
+ return;
446
+ });
447
+ if (source === undefined)
448
+ return missingRecord();
449
+ const srcHash = devTextSourceHash(source);
450
+ const scanned = previous?.srcHash === srcHash ? previous : edges(file, source);
451
+ return {
452
+ mtimeMs: stats.mtimeMs,
453
+ size: stats.size,
454
+ srcHash,
455
+ imports: scanned.imports,
456
+ packages: scanned.packages,
457
+ client: scanned.client
458
+ };
459
+ }
460
+ var markers = new Map;
461
+ var wiped = new Set;
462
+ var written = new Set;
463
+ var markerChecks = new Map;
464
+ function markerFile(root) {
465
+ return path.join(root, ".cache-id");
466
+ }
467
+ function establishCacheTrust(root) {
468
+ const current = readMarker(root);
469
+ const generation = `${frameworkFingerprint()}:`;
470
+ const trusted = current?.startsWith(generation) ? current : undefined;
471
+ const value = trusted ?? `${generation}${randomUUID()}`;
472
+ if (!trusted) {
473
+ writeMarker(root, value);
474
+ wiped.add(root);
475
+ }
476
+ markers.set(root, value);
477
+ return value;
478
+ }
479
+ function readMarker(root) {
480
+ try {
481
+ return readFileSync(markerFile(root), "utf8").trim() || undefined;
482
+ } catch {
483
+ return;
484
+ }
485
+ }
486
+ function writeMarker(root, value) {
487
+ try {
488
+ mkdirSync(root, { recursive: true });
489
+ writeFileSync(markerFile(root), value);
490
+ } catch {}
491
+ }
492
+ function cacheMarkerIntact(root) {
493
+ const recorded = markers.get(root);
494
+ if (recorded === undefined || wiped.has(root))
495
+ return false;
496
+ const now = performance.now();
497
+ if (now - (markerChecks.get(root) ?? -Infinity) < 100)
498
+ return true;
499
+ markerChecks.set(root, now);
500
+ const current = readMarker(root);
501
+ if (current === recorded)
502
+ return true;
503
+ if (!current)
504
+ writeMarker(root, recorded);
505
+ else
506
+ markers.set(root, current);
507
+ wiped.add(root);
508
+ return false;
509
+ }
510
+ function noteDevArtifactWritten(file) {
511
+ const root = artifactCacheRoot(file);
512
+ if (root && wiped.has(root))
513
+ written.add(file);
514
+ }
515
+ function devArtifactUsable(file) {
516
+ if (!cachedExistsSync(file))
517
+ return false;
518
+ const root = artifactCacheRoot(file);
519
+ if (!root || !markers.has(root))
520
+ return true;
521
+ return cacheMarkerIntact(root) || written.has(file);
522
+ }
523
+ function artifactCacheRoot(file) {
524
+ const marker = `${path.sep}cache${path.sep}server${path.sep}`;
525
+ const index = file.lastIndexOf(marker);
526
+ return index === -1 ? undefined : file.slice(0, index + marker.length - 1);
527
+ }
528
+ var INDEX_VERSION = 4;
529
+ function compiledSourceGraph(outPath, workspaceRoot) {
530
+ const graph = new Map;
531
+ const parsed = readIndexFile(path.join(cacheRoot(outPath), "graph.json"));
532
+ for (const [source, entry] of Object.entries(parsed?.files ?? {})) {
533
+ graph.set(absoluteSourcePath(source, workspaceRoot), entry[3].map((file) => absoluteSourcePath(file, workspaceRoot)));
534
+ }
535
+ return graph;
536
+ }
537
+ function readIndexFile(file) {
538
+ try {
539
+ return JSON.parse(readFileSync(file, "utf8"));
540
+ } catch {
541
+ return;
542
+ }
543
+ }
544
+ function indexRecords(parsed, key, workspaceRoot) {
545
+ const records = new Map;
546
+ if (parsed?.key !== key || parsed.version !== INDEX_VERSION)
547
+ return records;
548
+ for (const [source, entry] of Object.entries(parsed.files ?? {})) {
549
+ records.set(absoluteSourcePath(source, workspaceRoot), {
550
+ mtimeMs: entry[0],
551
+ size: entry[1],
552
+ srcHash: entry[2],
553
+ imports: entry[3].map((file) => absoluteSourcePath(file, workspaceRoot)),
554
+ packages: entry[4] ?? [],
555
+ client: entry[5] === 1
556
+ });
557
+ }
558
+ return records;
559
+ }
560
+ function serializeIndex(key, records, workspaceRoot) {
561
+ const files = {};
562
+ for (const [source, record] of records) {
563
+ files[portableSourcePath(source, workspaceRoot)] = [
564
+ record.mtimeMs,
565
+ record.size,
566
+ record.srcHash,
567
+ record.imports.map((file) => portableSourcePath(file, workspaceRoot)),
568
+ record.packages,
569
+ record.client ? 1 : 0
570
+ ];
571
+ }
572
+ return JSON.stringify({ version: INDEX_VERSION, key, files });
573
+ }
574
+
575
+ // src/dev/restart/node-modules.ts
576
+ import { mkdir as mkdir2, readFile as readFile2, stat as stat2 } from "fs/promises";
577
+ import path2 from "path";
578
+ async function readNodeModuleBundle(recordFile) {
579
+ const contents = await readFile2(recordFile, "utf8").catch(() => {
580
+ return;
581
+ });
582
+ if (contents === undefined)
583
+ return;
584
+ let record;
585
+ try {
586
+ record = JSON.parse(contents);
587
+ } catch {
588
+ return;
589
+ }
590
+ if (typeof record?.code !== "string" || !Array.isArray(record.inputs))
591
+ return;
592
+ if (record.inputs.length === 0)
593
+ return;
594
+ const held = await Promise.all(record.inputs.map(async ([input, mtimeMs, size]) => {
595
+ const stats = await stat2(input).catch(() => {
596
+ return;
597
+ });
598
+ return stats?.mtimeMs === mtimeMs && stats.size === size;
599
+ }));
600
+ return held.every(Boolean) ? record.code : undefined;
601
+ }
602
+ async function writeNodeModuleBundle(recordFile, inputs, code) {
603
+ const stated = await Promise.all(inputs.map(async (input) => {
604
+ const stats = await stat2(input).catch(() => {
605
+ return;
606
+ });
607
+ return stats ? [input, stats.mtimeMs, stats.size] : undefined;
608
+ }));
609
+ if (stated.length === 0 || stated.some((entry) => entry === undefined))
610
+ return;
611
+ await mkdir2(path2.dirname(recordFile), { recursive: true }).catch(() => {
612
+ return;
613
+ });
614
+ await writeFileAtomic(recordFile, JSON.stringify({ inputs: stated, code })).catch(() => {
615
+ return;
616
+ });
617
+ }
618
+
619
+ // src/runtime/loader.ts
620
+ var require2 = createRequire(Bun.pathToFileURL(__PNEXT_PACKAGE_ROOT__ + "/src/runtime/loader.ts").href);
621
+ function pagesBundleTargetForRuntime(runtime) {
622
+ return runtime === "edge" || runtime === "experimental-edge" ? "pages-edge" : "pages";
623
+ }
624
+ function serverBundleConditions(target) {
625
+ const base = target === "client" ? ["module", "import"] : target === "edge" ? ["react-server", "edge-light", "browser", "module", "import"] : target === "pages-api-edge" ? ["edge-light", "browser", "module", "import"] : target === "pages-api" ? ["node", "require", "import"] : target === "pages-edge" ? ["edge-light", "browser", "module", "import"] : target === "pages" ? ["node", "module", "import"] : ["react-server", "node", "module", "import"];
626
+ return [...new Set([...serverBundleExtraConditions(target), ...base])];
627
+ }
628
+ function serverBundleRequireConditions(target) {
629
+ const base = target === "client" ? ["module", "require"] : target === "edge" ? ["react-server", "edge-light", "browser", "module", "require"] : target === "pages-api-edge" ? ["edge-light", "browser", "module", "require"] : target === "pages-api" ? ["node", "require"] : target === "pages-edge" ? ["edge-light", "browser", "module", "require"] : target === "pages" ? ["node", "module", "require"] : ["react-server", "node", "module", "require"];
630
+ return [...new Set([...serverBundleExtraConditions(target), ...base])];
631
+ }
632
+ var runtimeConfigs = new Map;
633
+ var aliasCache = new WeakMap;
634
+ var packageRootCache = new WeakMap;
635
+ var registeredSignatures = new WeakMap;
636
+ var rootPathCache = new Map;
637
+ var runtimeConfigLookupCache = new Map;
638
+ var firstAliasCache = new Map;
639
+ var transformCache = new Map;
640
+ var pendingTransforms = new Map;
641
+ var nodeModuleTransformCache = new Map;
642
+ var requireSidecarCache = new Map;
643
+ var registeredLoadRoots = new Set;
644
+ var resolveRegistered = false;
645
+ var nodeModulesLoadRegistered = false;
646
+ var pluginsDeferred = false;
647
+ var deferredPluginRoots = new Set;
648
+ var packageJsxLoaders = {
649
+ ".js": "jsx",
650
+ ".mjs": "jsx",
651
+ ".cjs": "jsx"
652
+ };
653
+ function registerServerRuntime(config, sourceFiles = []) {
654
+ applyServerHrefConfig(config);
655
+ if (typeof Bun === "undefined" || productionRelease(config))
656
+ return;
657
+ nativeStoreFor(config);
658
+ const sourceRoots = [...new Set(sourceFiles.map((file) => sourceRootForFile(config, file)))].sort();
659
+ const signature = sourceRoots.join("\x00");
660
+ let registered = registeredSignatures.get(config);
661
+ if (!registered) {
662
+ registered = new Set;
663
+ registeredSignatures.set(config, registered);
664
+ }
665
+ if (registered.has(signature))
666
+ return;
667
+ registered.add(signature);
668
+ const aliases = aliasesForConfig(config);
669
+ const roots = [
670
+ ...rootPaths(config.root),
671
+ ...rootPaths(config.appPath),
672
+ ...isReleaseCompile() ? [] : rootPaths(path3.join(config.outPath, "cache", "server")),
673
+ ...rootPaths(path3.join(__PNEXT_PACKAGE_ROOT__ + "/src/runtime", "..")),
674
+ ...sourceRoots.flatMap(rootPaths)
675
+ ];
676
+ const key = rootPaths(config.appPath).join("\x00");
677
+ const missingImportError = (specifier) => getImportAliasExtensions().missingImportError(config, specifier);
678
+ const existing = runtimeConfigs.get(key);
679
+ if (existing) {
680
+ for (const root of roots)
681
+ existing.roots.add(root);
682
+ for (const [specifier, target] of aliases)
683
+ existing.aliases.set(specifier, target);
684
+ existing.resolved = config;
685
+ existing.missingImportError = missingImportError;
686
+ } else {
687
+ runtimeConfigs.set(key, {
688
+ root: config.root,
689
+ roots: new Set(roots),
690
+ aliases: new Map(aliases),
691
+ resolved: config,
692
+ missingImportError
693
+ });
694
+ }
695
+ runtimeConfigLookupCache.clear();
696
+ firstAliasCache.clear();
697
+ if (pluginsDeferred) {
698
+ for (const root of roots)
699
+ deferredPluginRoots.add(root);
700
+ return;
701
+ }
702
+ registerResolvePlugin();
703
+ registerNodeModulesLoadPlugin();
704
+ for (const root of roots)
705
+ registerLoadPlugin(root, rootPaths(config.root).includes(root));
706
+ }
707
+ function deferServerRuntimePlugins() {
708
+ pluginsDeferred = true;
709
+ }
710
+ function installServerRuntimePlugins() {
711
+ if (!pluginsDeferred)
712
+ return;
713
+ pluginsDeferred = false;
714
+ registerResolvePlugin();
715
+ registerNodeModulesLoadPlugin();
716
+ for (const root of deferredPluginRoots) {
717
+ const projectRoot = [...runtimeConfigs.values()].some((config) => rootPaths(config.root).includes(root));
718
+ registerLoadPlugin(root, projectRoot);
719
+ }
720
+ deferredPluginRoots.clear();
721
+ }
722
+ function resolveRuntimeTarget(target) {
723
+ return path3.isAbsolute(target) ? target : require2.resolve(target);
724
+ }
725
+ function aliasesForConfig(config) {
726
+ let aliases = aliasCache.get(config);
727
+ if (!aliases) {
728
+ aliases = new Map;
729
+ for (const [specifier, target] of Object.entries(coreAliases(config, "server"))) {
730
+ aliases.set(specifier, resolveRuntimeTarget(target));
731
+ }
732
+ aliasCache.set(config, aliases);
733
+ }
734
+ return aliases;
735
+ }
736
+ function coreAliases(config, target) {
737
+ return {
738
+ ...frameworkRuntimeAliasEntries(),
739
+ ...pnextAliases(target),
740
+ ...getImportAliasExtensions().aliases(config, target)
741
+ };
742
+ }
743
+ var aliasSpecifierFilter = /^(?:@wular\/pnext\/cache|preact(?:\/|$)|react(?:-dom)?(?:\/|$)|react-compiler-runtime$|next(?:\/|$)|server-only$|client-only$|@vercel\/og$)/;
744
+ function registerResolvePlugin() {
745
+ if (resolveRegistered)
746
+ return;
747
+ resolveRegistered = true;
748
+ Bun.plugin({
749
+ name: "pnext-server-runtime-resolve",
750
+ setup(plugin) {
751
+ plugin.onResolve({ filter: aliasSpecifierFilter }, (args) => {
752
+ const runtime = runtimeConfigForFile(args.importer);
753
+ const resolved = runtime?.aliases.get(args.path) ?? firstAliasForSpecifier(args.path);
754
+ const target = resolved ? serverRequireAlias(args.path, resolved, args.kind) : undefined;
755
+ if (target)
756
+ return { path: prebundledFile(target) };
757
+ const message = (runtime ?? firstRuntimeConfig())?.missingImportError(args.path);
758
+ if (message)
759
+ throw new Error(message);
760
+ return;
761
+ });
762
+ plugin.onResolve({ filter: /^[^./].*/ }, ({ path: specifier, importer }) => {
763
+ const runtime = runtimeConfigForFile(importer);
764
+ const target = runtime && resolveExternalLoadTarget({
765
+ root: runtime.root,
766
+ fromFile: importer,
767
+ specifier,
768
+ target: "server"
769
+ });
770
+ if (!target)
771
+ return;
772
+ return { path: prebundledFile(target) };
773
+ });
774
+ }
775
+ });
776
+ }
777
+ function registerLoadPlugin(root, projectRoot = false) {
778
+ if (registeredLoadRoots.has(root))
779
+ return;
780
+ registeredLoadRoots.add(root);
781
+ if (traceEnabled("server")) {
782
+ console.error(`[loadplugin] register root=${root} extras=${currentLoadExtras().join(",")}`);
783
+ }
784
+ loadPluginExtras.set(root, currentLoadExtras());
785
+ Bun.plugin({
786
+ name: `pnext-server-runtime-load-${hashRoot(root)}`,
787
+ setup(plugin) {
788
+ plugin.onLoad({ filter: rootFilter(root, projectRoot) }, async ({ path: file }) => ({
789
+ contents: await transformSource(file),
790
+ loader: "js"
791
+ }));
792
+ }
793
+ });
794
+ }
795
+ var loadPluginExtras = new Map;
796
+ function currentLoadExtras() {
797
+ return extraLoadableExtensions().filter((ext) => /^[a-z0-9]+$/i.test(ext));
798
+ }
799
+ onLoadableExtensionsChanged(() => {
800
+ for (const [root, seen] of loadPluginExtras) {
801
+ const fresh = currentLoadExtras().filter((ext) => !seen.includes(ext));
802
+ if (fresh.length === 0)
803
+ continue;
804
+ loadPluginExtras.set(root, [...seen, ...fresh]);
805
+ const exts = fresh.map(escapeRegex).join("|");
806
+ const filter = new RegExp(`^${escapeRegex(root)}(?!.*\\/node_modules\\/)(?:/.*)?\\.(?:${exts})$`);
807
+ Bun.plugin({
808
+ name: `pnext-server-runtime-load-extras-${hashRoot(root)}-${fresh.join("-")}`,
809
+ setup(plugin) {
810
+ plugin.onLoad({ filter }, async ({ path: file }) => ({
811
+ contents: await transformSource(file),
812
+ loader: "js"
813
+ }));
814
+ }
815
+ });
816
+ }
817
+ });
818
+ function registerNodeModulesLoadPlugin() {
819
+ if (nodeModulesLoadRegistered)
820
+ return;
821
+ nodeModulesLoadRegistered = true;
822
+ Bun.plugin({
823
+ name: "pnext-server-node-modules-load",
824
+ setup(plugin) {
825
+ plugin.onLoad({
826
+ filter: /\/node_modules\/.*(?:\.mjs|\.esm\.js|\/(?:es|esm|dist\/esm|build\/modern)\/.*\.js)$/
827
+ }, ({ path: file }) => {
828
+ if (isRecordedNativeFile(file) || nodeModuleGraphLoadsAsIs(file)) {
829
+ return { contents: takeNodeModuleSource(file), loader: "js" };
830
+ }
831
+ return transformNodeModuleSource(file).then((code) => ({ contents: code, loader: "js" }));
832
+ });
833
+ }
834
+ });
835
+ }
836
+ var nodeModuleImportScanner = new Bun.Transpiler({ loader: "js" });
837
+ function nodeModuleSourceLoadsAsIs(source) {
838
+ return nodeModuleRelativeImports(source) !== undefined;
839
+ }
840
+ function nodeModuleRelativeImports(source) {
841
+ if (serverDefineOptions().define || source.includes("use cache"))
842
+ return;
843
+ if (/^\s*(?:(?:\/\/[^\n]*\n|\/\*[\s\S]*?\*\/)\s*)*['"]use (?:client|server)['"]/.test(source)) {
844
+ return;
845
+ }
846
+ try {
847
+ const relative = [];
848
+ for (const { path: specifier } of nodeModuleImportScanner.scanImports(source)) {
849
+ if (specifier.startsWith(".") || specifier.startsWith("/")) {
850
+ if (!/(?:\.[cm]?js|\.json|\/[^./]+)$/.test(specifier))
851
+ return;
852
+ if (specifier.startsWith("."))
853
+ relative.push(specifier);
854
+ } else if (aliasSpecifierFilter.test(specifier) || firstAliasForSpecifier(specifier)) {
855
+ return;
856
+ }
857
+ }
858
+ return relative;
859
+ } catch {
860
+ return;
861
+ }
862
+ }
863
+ var nativeNodeModuleFiles = new Map;
864
+ var nativeNodeModuleStores = new Map;
865
+ var nativeStoreFlushArmed = false;
866
+ var NATIVE_STORE_VERSION = 1;
867
+ var nativeNodeModuleStore = (config) => path3.join(cacheRoot(config.outPath), "native-files.json");
868
+ function statSignature(file) {
869
+ try {
870
+ const { mtimeMs, size } = statSync2(file);
871
+ return `${mtimeMs}:${size}`;
872
+ } catch {
873
+ return;
874
+ }
875
+ }
876
+ function nativeStoreFor(config) {
877
+ let stored = nativeNodeModuleStores.get(config.outPath)?.files;
878
+ if (!stored) {
879
+ stored = new Map;
880
+ nativeNodeModuleStores.set(config.outPath, { config, files: stored });
881
+ for (const [file, signature] of Object.entries(readNativeStore(config))) {
882
+ stored.set(file, signature);
883
+ nativeNodeModuleFiles.set(path3.resolve(config.workspaceRoot, file), signature);
884
+ }
885
+ }
886
+ return stored;
887
+ }
888
+ function readNativeStore(config) {
889
+ try {
890
+ const store = JSON.parse(readFileSync2(nativeNodeModuleStore(config), "utf8"));
891
+ return store.version === NATIVE_STORE_VERSION ? store.files : {};
892
+ } catch {
893
+ return {};
894
+ }
895
+ }
896
+ function isRecordedNativeFile(file) {
897
+ const signature = nativeNodeModuleFiles.get(file);
898
+ return signature !== undefined && signature === statSignature(file);
899
+ }
900
+ function recordNativeNodeModuleFiles(config, files) {
901
+ const stored = nativeStoreFor(config);
902
+ let added = false;
903
+ for (const file of files) {
904
+ if (nativeNodeModuleFiles.has(file))
905
+ continue;
906
+ const signature = statSignature(file);
907
+ if (!signature)
908
+ continue;
909
+ nativeNodeModuleFiles.set(file, signature);
910
+ stored.set(path3.relative(config.workspaceRoot, file), signature);
911
+ added = true;
912
+ }
913
+ if (!added || nativeStoreFlushArmed)
914
+ return;
915
+ nativeStoreFlushArmed = true;
916
+ process.once("exit", () => {
917
+ for (const { config: owner, files: files2 } of nativeNodeModuleStores.values()) {
918
+ try {
919
+ for (const [file, signature] of Object.entries(readNativeStore(owner))) {
920
+ if (!files2.has(file))
921
+ files2.set(file, signature);
922
+ }
923
+ writeFileSync2(nativeNodeModuleStore(owner), JSON.stringify({ version: NATIVE_STORE_VERSION, files: Object.fromEntries(files2) }));
924
+ } catch {}
925
+ }
926
+ });
927
+ }
928
+ var nodeModuleScans = new Map;
929
+ var nodeModuleGraphVerdicts = new Map;
930
+ function nodeModuleScan(file) {
931
+ let scan = nodeModuleScans.get(file);
932
+ if (scan === undefined) {
933
+ try {
934
+ const source = readFileSync2(file, "utf8");
935
+ const relative = nodeModuleRelativeImports(source);
936
+ const dir = path3.dirname(file);
937
+ scan = relative ? {
938
+ source,
939
+ imports: relative.map((specifier) => /\.[cm]?js$/.test(specifier) ? path3.resolve(dir, specifier) : Bun.resolveSync(specifier, dir))
940
+ } : null;
941
+ } catch {
942
+ scan = null;
943
+ }
944
+ nodeModuleScans.set(file, scan);
945
+ }
946
+ return scan;
947
+ }
948
+ function nodeModuleGraphLoadsAsIs(file) {
949
+ const known = nodeModuleGraphVerdicts.get(file);
950
+ if (known !== undefined)
951
+ return known;
952
+ const seen = new Set;
953
+ const stack = [file];
954
+ let verdict = true;
955
+ while (stack.length > 0 && verdict) {
956
+ const next = stack.pop();
957
+ if (seen.has(next) || nodeModuleGraphVerdicts.get(next) === true)
958
+ continue;
959
+ seen.add(next);
960
+ const scan = nodeModuleScan(next);
961
+ if (!scan)
962
+ verdict = false;
963
+ else
964
+ stack.push(...scan.imports);
965
+ }
966
+ if (verdict)
967
+ for (const covered of seen)
968
+ nodeModuleGraphVerdicts.set(covered, true);
969
+ else
970
+ nodeModuleGraphVerdicts.set(file, false);
971
+ return verdict;
972
+ }
973
+ function takeNodeModuleSource(file) {
974
+ const scan = nodeModuleScans.get(file);
975
+ const source = scan?.source ?? readFileSync2(file, "utf8");
976
+ if (scan)
977
+ scan.source = undefined;
978
+ return source;
979
+ }
980
+ function runtimeConfigForFile(file) {
981
+ if (!file)
982
+ return;
983
+ const key = path3.resolve(file);
984
+ if (runtimeConfigLookupCache.has(key)) {
985
+ return runtimeConfigLookupCache.get(key) ?? undefined;
986
+ }
987
+ for (const config of runtimeConfigs.values()) {
988
+ for (const root of config.roots) {
989
+ if (isInside(root, file)) {
990
+ runtimeConfigLookupCache.set(key, config);
991
+ return config;
992
+ }
993
+ }
994
+ }
995
+ runtimeConfigLookupCache.set(key, null);
996
+ return;
997
+ }
998
+ function sourceRootForFile(config, file) {
999
+ const dir = path3.dirname(file);
1000
+ if (isInside(config.appPath, dir))
1001
+ return config.appPath;
1002
+ return packageRootsForConfig(config).find((root) => isInside(root, dir)) ?? dir;
1003
+ }
1004
+ function packageRootsForConfig(config) {
1005
+ let roots = packageRootCache.get(config);
1006
+ if (!roots) {
1007
+ roots = workspacePackageRoots(config.workspaceRoot);
1008
+ packageRootCache.set(config, roots);
1009
+ }
1010
+ return roots;
1011
+ }
1012
+ function firstRuntimeConfig() {
1013
+ for (const config of runtimeConfigs.values())
1014
+ return config;
1015
+ return;
1016
+ }
1017
+ function firstAliasForSpecifier(specifier) {
1018
+ if (firstAliasCache.has(specifier))
1019
+ return firstAliasCache.get(specifier) ?? undefined;
1020
+ for (const config of runtimeConfigs.values()) {
1021
+ const target = config.aliases.get(specifier);
1022
+ if (target) {
1023
+ firstAliasCache.set(specifier, target);
1024
+ return target;
1025
+ }
1026
+ }
1027
+ firstAliasCache.set(specifier, null);
1028
+ return;
1029
+ }
1030
+ async function transformSource(file) {
1031
+ const fileStat = await stat3(file);
1032
+ const cached = transformCache.get(file);
1033
+ if (cached?.mtimeMs === fileStat.mtimeMs && cached.size === fileStat.size) {
1034
+ return cached.code;
1035
+ }
1036
+ const pendingKey = `${file}\x00${fileStat.mtimeMs}\x00${fileStat.size}`;
1037
+ const pending = pendingTransforms.get(pendingKey);
1038
+ if (pending)
1039
+ return pending;
1040
+ const started = transformSourceUncached(file, fileStat);
1041
+ pendingTransforms.set(pendingKey, started);
1042
+ try {
1043
+ return await started;
1044
+ } finally {
1045
+ if (pendingTransforms.get(pendingKey) === started)
1046
+ pendingTransforms.delete(pendingKey);
1047
+ }
1048
+ }
1049
+ async function transformSourceUncached(file, fileStat) {
1050
+ const diskCache = transformCacheFile(file, fileStat);
1051
+ if (diskCache) {
1052
+ const code = await readFile3(diskCache, "utf8").catch(() => {
1053
+ return;
1054
+ });
1055
+ if (code !== undefined) {
1056
+ transformCache.set(file, { mtimeMs: fileStat.mtimeMs, size: fileStat.size, code });
1057
+ return code;
1058
+ }
1059
+ }
1060
+ const runtime = runtimeConfigForFile(file);
1061
+ let raw = await readFile3(file, "utf8");
1062
+ if (/\.mdx?$/.test(file) && !file.includes(`${path3.sep}cache${path3.sep}server${path3.sep}`)) {
1063
+ const { compileMdx } = await import("./compile-53j02j27.js");
1064
+ raw = (await compileMdx(raw, file, runtime?.root ?? path3.dirname(file))).code;
1065
+ }
1066
+ const source = await inlineModuleScopeRequires(rewriteServerSource(raw, file, {
1067
+ root: runtime?.root
1068
+ }), file, runtime?.root);
1069
+ const result = await transform(source, {
1070
+ loader: esbuildLoader(file),
1071
+ jsx: "automatic",
1072
+ jsxImportSource: "preact",
1073
+ sourcefile: file,
1074
+ target: "es2022",
1075
+ ...serverDefineOptions()
1076
+ });
1077
+ transformCache.set(file, {
1078
+ mtimeMs: fileStat.mtimeMs,
1079
+ size: fileStat.size,
1080
+ code: result.code
1081
+ });
1082
+ if (diskCache) {
1083
+ await mkdir3(path3.dirname(diskCache), { recursive: true }).catch(() => {
1084
+ return;
1085
+ });
1086
+ const write = writeFileAtomic(diskCache, result.code).catch(() => {
1087
+ return;
1088
+ });
1089
+ transformWrites.add(write);
1090
+ write.finally(() => transformWrites.delete(write));
1091
+ }
1092
+ return result.code;
1093
+ }
1094
+ var transformWrites = new Set;
1095
+ async function prewarmServerTransforms(root, files) {
1096
+ const loadable = rootFilter(root);
1097
+ await Promise.all([...files].map(async (file) => {
1098
+ if (!loadable.test(file))
1099
+ return;
1100
+ const stats = await stat3(file).catch(() => {
1101
+ return;
1102
+ });
1103
+ if (!stats || !transformCacheFile(file, stats))
1104
+ return;
1105
+ await transformSource(file).catch(() => {
1106
+ return;
1107
+ });
1108
+ }));
1109
+ while (transformWrites.size > 0)
1110
+ await Promise.all([...transformWrites]);
1111
+ }
1112
+ var transformDiskCacheDisabled = process.env.PNEXT_TRANSFORM_DISK_CACHE === "0";
1113
+ var materializedSegment = `${path3.sep}cache${path3.sep}server${path3.sep}`;
1114
+ function transformCacheFile(file, fileStat) {
1115
+ if (transformDiskCacheDisabled)
1116
+ return;
1117
+ const at = file.lastIndexOf(materializedSegment);
1118
+ if (at === -1)
1119
+ return;
1120
+ const cacheRoot2 = file.slice(0, at + materializedSegment.length);
1121
+ const key = `${file}\x00${fileStat.mtimeMs}\x00${fileStat.size}\x00${currentLoadExtras().join(",")}\x00${JSON.stringify(serverDefineOptions())}\x00${frameworkFingerprint()}`;
1122
+ return path3.join(cacheRoot2, "transform", `${hashBundleSpecifier(key)}.js`);
1123
+ }
1124
+ var REQUIRE_CALL = /\b(?:__)?require\(\s*(['"])((?:\.\.?\/|\/|file:\/\/)[^'"]+)\1\s*\)/g;
1125
+ async function inlineModuleScopeRequires(source, file, root) {
1126
+ if (!root || !source.includes("require("))
1127
+ return source;
1128
+ const filter = rootFilter(root);
1129
+ const sidecars = new Map;
1130
+ const pending = [];
1131
+ const seen = new Set;
1132
+ for (const match of source.matchAll(REQUIRE_CALL)) {
1133
+ const specifier = match[2];
1134
+ if (seen.has(specifier))
1135
+ continue;
1136
+ seen.add(specifier);
1137
+ const target = requireCallTarget(root, file, specifier);
1138
+ if (!target || !filter.test(target))
1139
+ continue;
1140
+ pending.push(requireCjsSidecar(target).then((sidecar) => {
1141
+ if (sidecar)
1142
+ sidecars.set(specifier, sidecar);
1143
+ }));
1144
+ }
1145
+ if (pending.length === 0)
1146
+ return source;
1147
+ await Promise.all(pending);
1148
+ if (sidecars.size === 0)
1149
+ return source;
1150
+ return source.replace(REQUIRE_CALL, (whole, quote, specifier) => {
1151
+ const sidecar = sidecars.get(specifier);
1152
+ return sidecar ? `require(${quote}${sidecar}${quote})` : whole;
1153
+ });
1154
+ }
1155
+ function requireCallTarget(root, file, specifier) {
1156
+ if (specifier.startsWith("file://")) {
1157
+ try {
1158
+ return resolveImport(root, file, fileURLToPath2(specifier), runtimeConfigForFile(file)?.resolved.workspaceRoot);
1159
+ } catch {
1160
+ return;
1161
+ }
1162
+ }
1163
+ return resolveImport(root, file, specifier, runtimeConfigForFile(file)?.resolved.workspaceRoot);
1164
+ }
1165
+ async function requireCjsSidecar(target) {
1166
+ try {
1167
+ const sidecar = requireCjsSidecarPath(target);
1168
+ const fileStat = await stat3(target);
1169
+ const cached = requireSidecarCache.get(target);
1170
+ if (cached?.mtimeMs === fileStat.mtimeMs && cached.size === fileStat.size)
1171
+ return sidecar;
1172
+ const runtime = runtimeConfigForFile(target);
1173
+ const source = rewriteServerSource(await readFile3(target, "utf8"), target, {
1174
+ root: runtime?.root
1175
+ });
1176
+ const result = await transform(source, {
1177
+ loader: esbuildLoader(target),
1178
+ jsx: "automatic",
1179
+ jsxImportSource: "preact",
1180
+ sourcefile: target,
1181
+ target: "es2022",
1182
+ format: "cjs",
1183
+ ...serverDefineOptions()
1184
+ });
1185
+ await writeFile(sidecar, result.code);
1186
+ requireSidecarCache.set(target, { mtimeMs: fileStat.mtimeMs, size: fileStat.size });
1187
+ return sidecar;
1188
+ } catch {
1189
+ return;
1190
+ }
1191
+ }
1192
+ function requireCjsSidecarPath(target) {
1193
+ return `${target.replace(/\.[^./\\]+$/, "")}.pnext-require.cjs`;
1194
+ }
1195
+ async function transformNodeModuleSource(file) {
1196
+ const fileStat = await stat3(file);
1197
+ const cached = nodeModuleTransformCache.get(file);
1198
+ if (cached?.mtimeMs === fileStat.mtimeMs && cached.size === fileStat.size) {
1199
+ return cached.code;
1200
+ }
1201
+ const record = nodeModuleBundleRecordFile(file, fileStat);
1202
+ const reused = record ? await readNodeModuleBundle(record) : undefined;
1203
+ if (reused !== undefined) {
1204
+ nodeModuleTransformCache.set(file, {
1205
+ mtimeMs: fileStat.mtimeMs,
1206
+ size: fileStat.size,
1207
+ code: reused
1208
+ });
1209
+ return reused;
1210
+ }
1211
+ const { code, inputs } = await bundleNodeModuleSource(file);
1212
+ nodeModuleTransformCache.set(file, {
1213
+ mtimeMs: fileStat.mtimeMs,
1214
+ size: fileStat.size,
1215
+ code
1216
+ });
1217
+ if (record)
1218
+ writeNodeModuleBundle(record, inputs, code);
1219
+ return code;
1220
+ }
1221
+ function nodeModuleBundleRecordFile(file, fileStat) {
1222
+ if (transformDiskCacheDisabled)
1223
+ return;
1224
+ const outPath = (runtimeConfigForFile(file) ?? firstRuntimeConfig())?.resolved.outPath;
1225
+ if (!outPath)
1226
+ return;
1227
+ const key = `${file}\x00${fileStat.mtimeMs}\x00${fileStat.size}\x00${currentLoadExtras().join(",")}\x00${JSON.stringify(serverDefineOptions())}\x00${frameworkFingerprint()}`;
1228
+ return path3.join(cacheRoot(outPath), "node-module-bundle", `${hashBundleSpecifier(key)}.json`);
1229
+ }
1230
+ async function bundleNodeModuleSource(file) {
1231
+ const resolved = runtimeConfigForFile(file)?.resolved;
1232
+ const extensionPlugins = resolved ? getBundlerExtensions().serverEsbuildPlugins(resolved) : [];
1233
+ const result = await build({
1234
+ entryPoints: [
1235
+ (resolved ? getBundlerExtensions().serverBundleEntry(file, path3.dirname(file), file) : undefined) ?? file
1236
+ ],
1237
+ bundle: true,
1238
+ write: false,
1239
+ format: "esm",
1240
+ platform: "neutral",
1241
+ target: "es2022",
1242
+ loader: packageJsxLoaders,
1243
+ jsx: "automatic",
1244
+ jsxImportSource: "preact",
1245
+ packages: "external",
1246
+ logLevel: "silent",
1247
+ metafile: true,
1248
+ ...serverDefineOptions(),
1249
+ plugins: [
1250
+ serverAssetPlugin(),
1251
+ ...extensionPlugins,
1252
+ runtimeAliasBuildPlugin(undefined, "server", { bundleRequireAliases: true })
1253
+ ]
1254
+ });
1255
+ const output = result.outputFiles[0];
1256
+ if (!output)
1257
+ throw new Error(`Failed to bundle ${file}`);
1258
+ return {
1259
+ code: applyBundledSourceTransforms(output.text, file),
1260
+ inputs: Object.keys(result.metafile.inputs).map((input) => path3.resolve(input))
1261
+ };
1262
+ }
1263
+ function needsServerSourceRewrite(source) {
1264
+ return sourceHasDynamicImport(source) || sourceNeedsServerTransforms(source);
1265
+ }
1266
+ function rewriteServerSource(source, file, options = {}) {
1267
+ const root = options.root ?? path3.dirname(file);
1268
+ const rewritten = sourceHasDynamicImport(source) ? rewriteDynamicCallTargets(rewriteLiteralDynamicCalls(source, file), (specifier) => resolveImport(root, file, specifier, runtimeConfigForFile(file)?.resolved.workspaceRoot), file) : source;
1269
+ if (options.nextFonts === false)
1270
+ return rewritten;
1271
+ if (!sourceNeedsServerTransforms(rewritten))
1272
+ return rewritten;
1273
+ return applyServerSourceTransforms(applyServerSourcePreTransforms(rewritten, file, options.root), file, options.root);
1274
+ }
1275
+ function serverRequireAlias(specifier, target, kind) {
1276
+ if (kind !== "require-call")
1277
+ return target;
1278
+ if (specifier === "next/navigation" && target.endsWith(`${path3.sep}navigation.ts`)) {
1279
+ return path3.join(path3.dirname(target), "navigation.cjs");
1280
+ }
1281
+ if (specifier === "next/router" && target.endsWith(`${path3.sep}router.ts`)) {
1282
+ return path3.join(path3.dirname(target), "router.cjs");
1283
+ }
1284
+ return target;
1285
+ }
1286
+ function runtimeAliasBuildPlugin(config, target = "server", options = {}) {
1287
+ const aliases = config ? coreAliases(config, target) : undefined;
1288
+ const reactServerLayerAliases = config && options.reactServerLayer ? getImportAliasExtensions().reactServerLayerAliases(config) : undefined;
1289
+ return {
1290
+ name: "pnext-runtime-build-alias",
1291
+ setup(build2) {
1292
+ build2.onResolve({ filter: /^\.\/preact$/ }, (args) => {
1293
+ const hasRealSibling = [".ts", ".tsx", ".js", ".mjs", ".jsx"].some((ext) => existsSync(path3.join(args.resolveDir, `preact${ext}`)));
1294
+ const compatPreact = path3.resolve(__PNEXT_PACKAGE_ROOT__ + "/src/runtime", "..", "compat", "react", "preact.ts");
1295
+ if (hasRealSibling && path3.resolve(args.resolveDir, "preact.ts") !== compatPreact)
1296
+ return;
1297
+ return { path: compatPreact };
1298
+ });
1299
+ build2.onResolve({ filter: /^\.\.\/client\/errors\/primitive-throw$/ }, (args) => {
1300
+ const compatPreact = path3.resolve(__PNEXT_PACKAGE_ROOT__ + "/src/runtime", "..", "compat", "react", "preact.ts");
1301
+ if (path3.resolve(args.importer) !== compatPreact)
1302
+ return;
1303
+ return {
1304
+ path: path3.resolve(__PNEXT_PACKAGE_ROOT__ + "/src/runtime", "..", "compat", "client", "errors", "primitive-throw.ts")
1305
+ };
1306
+ });
1307
+ build2.onResolve({ filter: aliasSpecifierFilter }, (args) => {
1308
+ const resolved = aliases?.[args.path] ?? firstAliasForSpecifier(args.path);
1309
+ if (!resolved)
1310
+ return;
1311
+ const requireTarget = serverRequireAlias(args.path, resolved, args.kind);
1312
+ if (requireTarget !== resolved)
1313
+ return { path: requireTarget };
1314
+ if (options.bundleRequireAliases && args.kind === "require-call") {
1315
+ const layerTarget = serverRequireAlias(args.path, reactServerLayerAliases?.[args.path] ?? resolved, args.kind);
1316
+ return { path: path3.isAbsolute(layerTarget) ? layerTarget : require2.resolve(layerTarget) };
1317
+ }
1318
+ return {
1319
+ path: path3.isAbsolute(resolved) ? pathToFileHref(resolved) : resolved,
1320
+ external: true
1321
+ };
1322
+ });
1323
+ }
1324
+ };
1325
+ }
1326
+ function isInside(root, file) {
1327
+ const relative = path3.relative(root, file);
1328
+ return relative === "" || !relative.startsWith("..") && !path3.isAbsolute(relative);
1329
+ }
1330
+ function rootPaths(root) {
1331
+ const key = path3.resolve(root);
1332
+ const cached = rootPathCache.get(key);
1333
+ if (cached)
1334
+ return cached;
1335
+ const paths = new Set([path3.resolve(root)]);
1336
+ try {
1337
+ paths.add(realpathSync.native(root));
1338
+ } catch {}
1339
+ const resolved = [...paths];
1340
+ rootPathCache.set(key, resolved);
1341
+ return resolved;
1342
+ }
1343
+ function rootFilter(root, projectRoot = false) {
1344
+ const extras = currentLoadExtras().map(escapeRegex);
1345
+ const exts = [projectRoot ? "tsx?|jsx" : "[jt]sx?", ...extras].join("|");
1346
+ const vendorGuard = vendorLoadsNatively() ? `${root.endsWith(`${path3.sep}cache${path3.sep}server`) ? "(?!\\/vendor\\/)" : ""}(?!.*\\/cache\\/server\\/vendor\\/)` : "";
1347
+ const serverGuard = [...runtimeConfigs.values()].flatMap((runtime) => rootPaths(path3.join(runtime.resolved.outPath, "server"))).map((serverRoot) => `(?!${escapeRegex(serverRoot)}(?:/|$))`).join("");
1348
+ return new RegExp(`^${serverGuard}${escapeRegex(root)}${vendorGuard}(?!.*\\/node_modules\\/)(?!\\/next\\.config\\.(?:js|cjs|mjs|ts)$)(?:/.*)?\\.(?:${exts})$`);
1349
+ }
1350
+ function esbuildLoader(file) {
1351
+ if (file.endsWith(".tsx"))
1352
+ return "tsx";
1353
+ if (file.endsWith(".ts"))
1354
+ return "ts";
1355
+ return "jsx";
1356
+ }
1357
+ function hashRoot(value) {
1358
+ let hash = 5381;
1359
+ for (const char of value)
1360
+ hash = (hash << 5) + hash ^ char.charCodeAt(0);
1361
+ return (hash >>> 0).toString(36);
1362
+ }
1363
+ function hashBundleSpecifier(value) {
1364
+ return createHash2("sha256").update(value).digest("hex").slice(0, 16);
1365
+ }
1366
+ function vendorLoadsNatively() {
1367
+ return process.env.PNEXT_VENDOR_DIST_NATIVE !== "0";
1368
+ }
1369
+ var serverIgnoredAssetFilter = /\.(?:css|scss|sass|woff2?|ttf|otf|eot|png|jpe?g|gif|webp|avif|svg|ico|bmp)(?:$|[?#])/;
1370
+ function isCssFile(file) {
1371
+ return file.endsWith(".css");
1372
+ }
1373
+ function isStaticImageFile(file) {
1374
+ return /\.(?:png|jpe?g|gif|webp|avif|svg|ico|bmp)(?:$|[?#])/.test(file);
1375
+ }
1376
+ function resolveAssetPath(specifier, resolveDir) {
1377
+ const [sourcePath = "", hash = ""] = specifier.split("#", 2);
1378
+ const resolved = path3.isAbsolute(sourcePath) ? sourcePath : path3.resolve(resolveDir, sourcePath);
1379
+ return hash ? `${resolved}#${hash}` : resolved;
1380
+ }
1381
+ async function staticImageModuleSource(config, file) {
1382
+ const [sourcePath = ""] = file.split("#", 1);
1383
+ const bytes = new Uint8Array(await readFile3(sourcePath));
1384
+ const emitted = [];
1385
+ const emit = (relative, data) => {
1386
+ emitted.push({ relative, bytes: data });
1387
+ return `/${relative}`;
1388
+ };
1389
+ const compat = await getAssetExtensions().staticAssetModule({ sourcePath, bytes, emit });
1390
+ const source = compat ?? coreStaticAssetModule(sourcePath, bytes, emit);
1391
+ if (config) {
1392
+ for (const asset of emitted) {
1393
+ const target = path3.join(config.outPath, "public", ...asset.relative.split("/"));
1394
+ await mkdir3(path3.dirname(target), { recursive: true });
1395
+ if (!existsSync(target))
1396
+ await Bun.write(target, asset.bytes);
1397
+ }
1398
+ }
1399
+ return source;
1400
+ }
1401
+ function coreStaticAssetModule(sourcePath, bytes, emit) {
1402
+ const ext = path3.extname(sourcePath).toLowerCase() || ".bin";
1403
+ const hash = createHash2("sha256").update(bytes).digest("hex").slice(0, 8);
1404
+ const base = path3.basename(sourcePath, path3.extname(sourcePath)).replace(/[^A-Za-z0-9_-]+/g, "-");
1405
+ const relative = getAssetExtensions().staticAssetRelativePath({ sourcePath, hash, base, ext });
1406
+ const src = emit(relative, bytes);
1407
+ return `const src = ${JSON.stringify(src)};
1408
+ export default src;
1409
+ export { src };
1410
+ `;
1411
+ }
1412
+ function serverAssetPlugin(config) {
1413
+ return {
1414
+ name: "pnext-empty-server-assets",
1415
+ setup(build2) {
1416
+ build2.onResolve({ filter: serverIgnoredAssetFilter }, (args) => {
1417
+ const resolved = resolveAssetPath(args.path, args.resolveDir);
1418
+ if (getAssetExtensions().hasLoaderRuleFor(resolved)) {
1419
+ return;
1420
+ }
1421
+ return { path: resolved, namespace: "pnext-empty-server-asset" };
1422
+ });
1423
+ build2.onLoad({ filter: /.*/, namespace: "pnext-empty-server-asset" }, async (args) => ({
1424
+ contents: getCssExtensions().loadCssModuleForClient(args.path) ?? (isCssFile(args.path) ? "" : isStaticImageFile(args.path) ? await staticImageModuleSource(config, args.path) : 'export default "";'),
1425
+ loader: "js"
1426
+ }));
1427
+ }
1428
+ };
1429
+ }
1430
+
1431
+ export { devHeadTrimEnabled, setDevWatcherFreshness, devSourceIdentity, DEV_SOURCE_MISSING, isBinaryDevSource, devTextSourceHash, flushDevModuleCaches, devModuleCache, cacheRoot, noteDevArtifactWritten, devArtifactUsable, compiledSourceGraph, pagesBundleTargetForRuntime, serverBundleConditions, serverBundleRequireConditions, packageJsxLoaders, registerServerRuntime, deferServerRuntimePlugins, installServerRuntimePlugins, coreAliases, aliasSpecifierFilter, nodeModuleSourceLoadsAsIs, statSignature, recordNativeNodeModuleFiles, firstAliasForSpecifier, prewarmServerTransforms, transformCacheFile, needsServerSourceRewrite, rewriteServerSource, serverRequireAlias, runtimeAliasBuildPlugin, hashBundleSpecifier, vendorLoadsNatively, serverIgnoredAssetFilter, serverAssetPlugin };