@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,1065 @@
1
+ // @bun
2
+ import { join as __pnextJoin } from "node:path";
3
+ const __PNEXT_PACKAGE_ROOT__ = __pnextJoin(import.meta.dirname, "../../..");
4
+ import {
5
+ createVerboseLogger
6
+ } from "./index-73z4esab.js";
7
+ import {
8
+ cssClassNames,
9
+ cssModuleClassName,
10
+ cssModuleMapping,
11
+ hashedAssetName,
12
+ isCssModuleFile,
13
+ recordEmittedAsset
14
+ } from "./index-y2jr2n72.js";
15
+ import {
16
+ readSourceSync
17
+ } from "./index-fp8r0sqs.js";
18
+ import {
19
+ build
20
+ } from "./index-cjgqs13g.js";
21
+ import {
22
+ ensureDir,
23
+ readText
24
+ } from "./index-20ppawv7.js";
25
+ import {
26
+ productionRelease
27
+ } from "./index-tqn2qnnn.js";
28
+ import {
29
+ resolveImport
30
+ } from "./index-yz54pxrh.js";
31
+ import {
32
+ extraPageExtensions,
33
+ getCssExtensions
34
+ } from "./index-zqpqyg8p.js";
35
+ import {
36
+ __require
37
+ } from "./index-rt9qq1va.js";
38
+
39
+ // src/css/build.ts
40
+ import { existsSync as existsSync2 } from "fs";
41
+ import { readFile, rename, writeFile as writeFile2 } from "fs/promises";
42
+ import path2 from "path";
43
+
44
+ // src/css/postcss.ts
45
+ import { createHash } from "crypto";
46
+ import { createRequire } from "module";
47
+ import {
48
+ existsSync,
49
+ mkdirSync,
50
+ readFileSync,
51
+ realpathSync,
52
+ renameSync,
53
+ statSync,
54
+ writeFileSync
55
+ } from "fs";
56
+ import { writeFile } from "fs/promises";
57
+ import path from "path";
58
+ import { pathToFileURL } from "url";
59
+ var postcssProcessors = new Map;
60
+ var tailwindScannerPatch = Symbol.for("pnext.tailwind-scanner-v1");
61
+ var tailwindCandidateSchema = 1;
62
+ var warnedTailwindScannerVersions = new Set;
63
+ function postcssConfigFile(root) {
64
+ for (const file of ["postcss.config.cjs", "postcss.config.js", "postcss.config.mjs"]) {
65
+ const full = path.join(root, file);
66
+ if (existsSync(full))
67
+ return full;
68
+ }
69
+ return;
70
+ }
71
+ function loadPostcss(root, options) {
72
+ const key = `${root}\x00${options.dev ? "dev" : "build"}\x00${options.outDir ?? ""}`;
73
+ let processor = postcssProcessors.get(key);
74
+ if (!processor) {
75
+ processor = createPostcssProcessor(root, options).catch((error) => {
76
+ postcssProcessors.delete(key);
77
+ throw error;
78
+ });
79
+ postcssProcessors.set(key, processor);
80
+ }
81
+ return processor;
82
+ }
83
+ async function runPostcss(root, cssFile, options, fromSource) {
84
+ const loaded = await loadPostcss(root, options);
85
+ if (!loaded)
86
+ return;
87
+ const from = fromSource ?? cssFile;
88
+ const css = await readText(cssFile);
89
+ const result = await loaded.processor.process(css + keptExclusions(loaded.sources, css, from, loaded.partitionedTailwindScan), { from, to: cssFile });
90
+ await writeFile(cssFile, result.css);
91
+ }
92
+ async function createPostcssProcessor(root, options) {
93
+ const configFile = postcssConfigFile(root);
94
+ if (!configFile)
95
+ return;
96
+ const loaded = await import(pathToFileURL(configFile).href);
97
+ const config = "default" in loaded && loaded.default ? loaded.default : loaded;
98
+ const { plugins, partitionedTailwindScan } = postcssPlugins(root, config, options);
99
+ if (plugins.length === 0)
100
+ return;
101
+ const appRequire = createRequire(path.join(root, "package.json"));
102
+ const postcss = interopDefault(resolvePostcss(appRequire));
103
+ const tailwind = pluginEntries(config).some(([specifier, pluginOptions]) => specifier === "@tailwindcss/postcss" && pluginOptions !== false);
104
+ return {
105
+ processor: postcss(plugins),
106
+ sources: tailwind ? scanExclusions(root, appRequire, options) : "",
107
+ partitionedTailwindScan
108
+ };
109
+ }
110
+ function keptExclusions(exclusions, css, fromFile, partitionedTailwindScan = false) {
111
+ if (!exclusions || partitionedTailwindScan)
112
+ return exclusions;
113
+ const dir = path.dirname(fromFile);
114
+ const globs = [...css.matchAll(/@source\s+(?!not\s)['"]([^'"]+)['"]/g)].map((match) => path.resolve(dir, match[1].replace(/[*{[].*$/, "")));
115
+ if (globs.length === 0)
116
+ return exclusions;
117
+ const kept = exclusions.split(`
118
+ `).filter((line) => {
119
+ const match = /@source not "([^"]+)"/.exec(line);
120
+ return !match || !globs.some((glob) => glob === match[1] || glob.startsWith(match[1] + "/"));
121
+ }).join(`
122
+ `);
123
+ return kept.includes("@source not") ? kept : "";
124
+ }
125
+ function scanExclusions(root, appRequire, options) {
126
+ if (process.env.PNEXT_TAILWIND_SCAN_ALL)
127
+ return "";
128
+ const [major, minor] = packageVersion(appRequire, "@tailwindcss/postcss");
129
+ if (major < 4 || major === 4 && minor < 1)
130
+ return "";
131
+ const dirs = ["node_modules", ".next", options.outDir ?? ".pnext"];
132
+ const excluded = [...new Set(dirs.map((dir) => path.resolve(root, dir)))].filter((dir) => dir.startsWith(root + path.sep));
133
+ if (excluded.length === 0)
134
+ return "";
135
+ return `
136
+ ${excluded.map((dir) => `@source not ${JSON.stringify(dir.split(path.sep).join("/"))};`).join(`
137
+ `)}
138
+ `;
139
+ }
140
+ function packageVersion(req, name) {
141
+ try {
142
+ const pkg = JSON.parse(readFileSync(req.resolve(`${name}/package.json`), "utf8"));
143
+ const [major, minor] = (pkg.version ?? "").split(".");
144
+ return [Number.parseInt(major ?? "", 10) || 0, Number.parseInt(minor ?? "", 10) || 0];
145
+ } catch {
146
+ return [0, 0];
147
+ }
148
+ }
149
+ function pluginEntries(config) {
150
+ return Array.isArray(config.plugins) ? config.plugins.map((entry) => Array.isArray(entry) ? [entry[0], entry[1]] : [entry, undefined]) : Object.entries(config.plugins ?? {});
151
+ }
152
+ function postcssPlugins(root, config, options) {
153
+ const appRequire = createRequire(path.join(root, "package.json"));
154
+ const entries = pluginEntries(config);
155
+ const plugins = [];
156
+ let partitionedTailwindScan = false;
157
+ for (const [specifier, pluginOptions] of entries) {
158
+ if (pluginOptions === false)
159
+ continue;
160
+ if (typeof specifier !== "string") {
161
+ if (specifier)
162
+ plugins.push(specifier);
163
+ continue;
164
+ }
165
+ const patchedScanner = specifier === "@tailwindcss/postcss" ? configureTailwindScanner(appRequire, root, options) : undefined;
166
+ const factory = interopDefault(appRequire(specifier));
167
+ if (patchedScanner) {
168
+ assertTailwindScannerPatch(appRequire, patchedScanner);
169
+ partitionedTailwindScan = true;
170
+ }
171
+ const resolvedOptions = pluginOptionsFor(root, specifier, pluginOptions, options);
172
+ plugins.push(typeof factory === "function" ? factory(resolvedOptions) : factory);
173
+ }
174
+ return { plugins, partitionedTailwindScan };
175
+ }
176
+ function configureTailwindScanner(appRequire, root, options) {
177
+ const pluginPackage = appRequire.resolve("@tailwindcss/postcss/package.json");
178
+ const pluginRequire = createRequire(pluginPackage);
179
+ const oxide = pluginRequire("@tailwindcss/oxide");
180
+ const versions = ["@tailwindcss/postcss", "tailwindcss", "@tailwindcss/oxide"].map((name) => ({
181
+ name,
182
+ version: packageVersionText(pluginRequire, name),
183
+ tuple: packageVersion(pluginRequire, name)
184
+ }));
185
+ if (!versions.every(({ tuple: [major, minor] }) => major === 4 && minor === 3)) {
186
+ const label = versions.map(({ name, version }) => `${name}@${version}`).join(", ");
187
+ if (!warnedTailwindScannerVersions.has(label)) {
188
+ warnedTailwindScannerVersions.add(label);
189
+ console.warn(`PNext: unsupported Tailwind scanner versions (${label}); using native Scanner.`);
190
+ }
191
+ return;
192
+ }
193
+ const registration = {
194
+ root: path.resolve(root),
195
+ cacheDir: path.join(path.resolve(root, options.outDir ?? ".pnext"), "cache/tailwind/candidates/v1"),
196
+ versions: ["@tailwindcss/postcss", "tailwindcss", "@tailwindcss/oxide", "postcss"].map((name) => `${name}@${packageVersionText(pluginRequire, name)}`).join("\x00")
197
+ };
198
+ const installed = oxide[tailwindScannerPatch];
199
+ if (installed) {
200
+ if (oxide.Scanner !== installed.Scanner)
201
+ throw tailwindScannerPatchError();
202
+ const index = installed.registrations.findIndex((item) => item.root === registration.root);
203
+ if (index === -1)
204
+ installed.registrations.push(registration);
205
+ else
206
+ installed.registrations[index] = registration;
207
+ return installed.Scanner;
208
+ }
209
+ const NativeScanner = oxide.Scanner;
210
+ const registrations = [registration];
211
+
212
+ class PnextTailwindScanner {
213
+ scanners;
214
+ registration;
215
+ constructor({ sources = [] }) {
216
+ this.registration = tailwindRegistration(registrations, sources);
217
+ this.scanners = partitionTailwindSources(sources).map((partition) => ({
218
+ scanner: new NativeScanner({ sources: partition }),
219
+ inventory: new NativeScanner({ sources: partition }),
220
+ sources: partition
221
+ }));
222
+ }
223
+ scan() {
224
+ return sortedUnique(this.scanners.flatMap(({ scanner, inventory, sources }) => this.registration ? cachedTailwindCandidates(inventory, sources, this.registration, () => new NativeScanner({ sources }).scan()) : scanner.scan()));
225
+ }
226
+ scanFiles(input) {
227
+ return sortedUnique(this.scanners.flatMap(({ scanner }) => scanner.scanFiles(input)));
228
+ }
229
+ getCandidatesWithPositions(input) {
230
+ return this.scanners.flatMap(({ scanner }) => scanner.getCandidatesWithPositions(input));
231
+ }
232
+ get files() {
233
+ return sortedUnique(this.scanners.flatMap(({ inventory }) => inventory.files));
234
+ }
235
+ get scannedFiles() {
236
+ return sortedUnique(this.scanners.flatMap(({ scanner }) => scanner.scannedFiles));
237
+ }
238
+ get globs() {
239
+ return uniqueTailwindGlobs(this.scanners.flatMap(({ scanner }) => scanner.globs));
240
+ }
241
+ get normalizedSources() {
242
+ return uniqueTailwindGlobs(this.scanners.flatMap(({ scanner }) => scanner.normalizedSources));
243
+ }
244
+ }
245
+ oxide.Scanner = PnextTailwindScanner;
246
+ oxide[tailwindScannerPatch] = { registrations, Scanner: PnextTailwindScanner };
247
+ return PnextTailwindScanner;
248
+ }
249
+ function assertTailwindScannerPatch(appRequire, expected) {
250
+ const pluginPackage = appRequire.resolve("@tailwindcss/postcss/package.json");
251
+ const oxide = createRequire(pluginPackage)("@tailwindcss/oxide");
252
+ if (oxide.Scanner !== expected || oxide[tailwindScannerPatch]?.Scanner !== expected) {
253
+ throw tailwindScannerPatchError();
254
+ }
255
+ }
256
+ function tailwindScannerPatchError() {
257
+ return new Error("PNext could not install its Tailwind Scanner integration. The loaded @tailwindcss/postcss module does not observe the patched @tailwindcss/oxide Scanner; refusing to drop explicit @source utilities.");
258
+ }
259
+ function partitionTailwindSources(sources) {
260
+ const broadExclusions = sources.filter((source) => source.negated && !/[*?{[]/.test(source.pattern));
261
+ const dependencySources = sources.filter((source) => !source.negated && broadExclusions.some((exclusion) => isInside(sourcePrefix(exclusion), sourcePrefix(source))));
262
+ if (dependencySources.length === 0)
263
+ return [sources];
264
+ const dependencySet = new Set(dependencySources);
265
+ const appSources = sources.filter((source) => !dependencySet.has(source));
266
+ return [appSources].concat(dependencySources.map((source) => [
267
+ source,
268
+ ...sources.filter((exclusion) => exclusion.negated && !broadExclusions.includes(exclusion) && pathsOverlap(sourcePrefix(source), sourcePrefix(exclusion)))
269
+ ].map(resolveTailwindSource)));
270
+ }
271
+ function resolveTailwindSource(source) {
272
+ const globAt = source.pattern.search(/[*?{[]/);
273
+ const literal = (globAt === -1 ? source.pattern : source.pattern.slice(0, globAt)).replace(/[\\/]$/, "");
274
+ const absolutePattern = path.resolve(source.base, source.pattern);
275
+ let absolute = path.resolve(source.base, literal || ".");
276
+ while (!existsSync(absolute)) {
277
+ const parent = path.dirname(absolute);
278
+ if (parent === absolute)
279
+ return source;
280
+ absolute = parent;
281
+ }
282
+ try {
283
+ const stat = statSync(absolute);
284
+ if (globAt === -1 && stat.isFile()) {
285
+ return {
286
+ ...source,
287
+ base: realpathSync.native(path.dirname(absolute)),
288
+ pattern: path.basename(absolute)
289
+ };
290
+ }
291
+ return {
292
+ ...source,
293
+ base: realpathSync.native(absolute),
294
+ pattern: globAt === -1 ? "**/*" : path.relative(absolute, absolutePattern).split(path.sep).join("/")
295
+ };
296
+ } catch {
297
+ return source;
298
+ }
299
+ }
300
+ function sourcePrefix(source) {
301
+ const prefix = source.pattern.replace(/[*?{[].*$/, "").replace(/[\\/]$/, "") || ".";
302
+ return path.resolve(source.base, prefix);
303
+ }
304
+ function pathsOverlap(left, right) {
305
+ return isInside(left, right) || isInside(right, left);
306
+ }
307
+ function isInside(parent, child) {
308
+ const relative = path.relative(parent, child);
309
+ return relative === "" || !relative.startsWith(`..${path.sep}`) && relative !== ".." && !path.isAbsolute(relative);
310
+ }
311
+ function tailwindRegistration(registrations, sources) {
312
+ return [...registrations].sort((left, right) => right.root.length - left.root.length).find((item) => sources.some((source) => isInside(item.root, path.resolve(source.base))));
313
+ }
314
+ function cachedTailwindCandidates(inventory, sources, registration, scan) {
315
+ let cache;
316
+ try {
317
+ cache = tailwindCacheIdentity(inventory, sources, registration);
318
+ } catch {
319
+ return scan();
320
+ }
321
+ const stored = readJson(cache.file);
322
+ if (stored?.schema === tailwindCandidateSchema && stored.fingerprint === cache.fingerprint && Array.isArray(stored.candidates) && stored.candidates.every((candidate) => typeof candidate === "string")) {
323
+ return stored.candidates;
324
+ }
325
+ const candidates = scan();
326
+ try {
327
+ mkdirSync(registration.cacheDir, { recursive: true });
328
+ atomicJsonWrite(cache.file, {
329
+ schema: tailwindCandidateSchema,
330
+ fingerprint: cache.fingerprint,
331
+ candidates,
332
+ files: cache.files
333
+ });
334
+ } catch {}
335
+ return candidates;
336
+ }
337
+ function tailwindCacheIdentity(scanner, sources, registration) {
338
+ const identities = sources.map(tailwindSourceIdentity);
339
+ const sourceKey = createHash("sha256").update(String(tailwindCandidateSchema)).update("\x00").update(registration.versions).update("\x00").update(JSON.stringify(identities)).digest("hex");
340
+ const files = scanner.files.map((file) => path.resolve(file)).sort();
341
+ const fingerprint = createHash("sha256").update(sourceKey);
342
+ for (const file of files) {
343
+ fingerprint.update("\x00").update(file).update("\x00").update(readFileSync(file));
344
+ }
345
+ return {
346
+ file: path.join(registration.cacheDir, `${sourceKey}.json`),
347
+ fingerprint: fingerprint.digest("hex"),
348
+ files: files.length
349
+ };
350
+ }
351
+ function tailwindSourceIdentity(source) {
352
+ const prefix = sourcePrefix(source);
353
+ const real = realExistingPath(prefix);
354
+ const packageFile = nearestPackageJson(real);
355
+ let packageIdentity;
356
+ if (packageFile) {
357
+ const pkg = readJson(packageFile);
358
+ if (pkg) {
359
+ packageIdentity = { name: pkg.name, version: pkg.version };
360
+ }
361
+ }
362
+ return { ...source, base: path.resolve(source.base), real, package: packageIdentity };
363
+ }
364
+ function realExistingPath(input) {
365
+ let current = input;
366
+ while (!existsSync(current)) {
367
+ const parent = path.dirname(current);
368
+ if (parent === current)
369
+ return input;
370
+ current = parent;
371
+ }
372
+ try {
373
+ const stat = statSync(current);
374
+ return realpathSync.native(stat.isFile() ? path.dirname(current) : current);
375
+ } catch {
376
+ return current;
377
+ }
378
+ }
379
+ function nearestPackageJson(input) {
380
+ let current = input;
381
+ while (true) {
382
+ const file = path.join(current, "package.json");
383
+ if (existsSync(file))
384
+ return file;
385
+ const parent = path.dirname(current);
386
+ if (parent === current)
387
+ break;
388
+ current = parent;
389
+ }
390
+ return;
391
+ }
392
+ function atomicJsonWrite(file, value) {
393
+ const temporary = `${file}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
394
+ writeFileSync(temporary, JSON.stringify(value));
395
+ renameSync(temporary, file);
396
+ }
397
+ function readJson(file) {
398
+ try {
399
+ return JSON.parse(readFileSync(file, "utf8"));
400
+ } catch {
401
+ return;
402
+ }
403
+ }
404
+ function sortedUnique(values) {
405
+ return [...new Set(values)].sort();
406
+ }
407
+ function uniqueTailwindGlobs(globs) {
408
+ const seen = new Set;
409
+ return globs.filter((glob) => {
410
+ const key = `${glob.base}\x00${glob.pattern}`;
411
+ if (seen.has(key))
412
+ return false;
413
+ seen.add(key);
414
+ return true;
415
+ });
416
+ }
417
+ function packageVersionText(req, name) {
418
+ try {
419
+ return JSON.parse(readFileSync(req.resolve(`${name}/package.json`), "utf8")).version ?? "unknown";
420
+ } catch {
421
+ return "unknown";
422
+ }
423
+ }
424
+ function pluginOptionsFor(root, specifier, userOptions, options) {
425
+ if (specifier !== "@tailwindcss/postcss")
426
+ return userOptions;
427
+ return {
428
+ base: root,
429
+ optimize: options.dev ? false : { minify: true },
430
+ ...typeof userOptions === "object" && userOptions !== null ? userOptions : {}
431
+ };
432
+ }
433
+ function resolvePostcss(appRequire) {
434
+ let appPostcss;
435
+ try {
436
+ appPostcss = appRequire("postcss");
437
+ if (packageVersion(appRequire, "postcss")[0] >= 8)
438
+ return appPostcss;
439
+ } catch {}
440
+ const ownPostcss = resolveOwnPostcss();
441
+ if (ownPostcss)
442
+ return ownPostcss;
443
+ try {
444
+ const pluginPackage = appRequire.resolve("@tailwindcss/postcss/package.json");
445
+ return createRequire(pluginPackage)("postcss");
446
+ } catch {
447
+ if (appPostcss)
448
+ return appPostcss;
449
+ throw new Error("Could not resolve a PostCSS installation for the CSS pipeline.");
450
+ }
451
+ }
452
+ function resolveOwnPostcss() {
453
+ try {
454
+ const ownRequire = createRequire(Bun.pathToFileURL(__PNEXT_PACKAGE_ROOT__ + "/src/css/postcss.ts").href);
455
+ if (packageVersion(ownRequire, "postcss")[0] >= 8)
456
+ return ownRequire("postcss");
457
+ } catch {}
458
+ return;
459
+ }
460
+ function interopDefault(mod) {
461
+ if (typeof mod === "function")
462
+ return mod;
463
+ if (mod && typeof mod === "object" && "default" in mod && mod.default)
464
+ return mod.default;
465
+ return mod;
466
+ }
467
+
468
+ // src/css/build.ts
469
+ var worker;
470
+ var workerFailed = false;
471
+ var nextId = 0;
472
+ var pending = new Map;
473
+ function ensureWorker() {
474
+ if (worker || workerFailed)
475
+ return worker;
476
+ try {
477
+ worker = new Worker(new URL("./worker.ts", Bun.pathToFileURL(__PNEXT_PACKAGE_ROOT__ + "/src/css/build.ts").href).href, {
478
+ type: "module"
479
+ });
480
+ } catch {
481
+ workerFailed = true;
482
+ return;
483
+ }
484
+ worker.unref();
485
+ worker.onmessage = (event) => {
486
+ const { id, error } = event.data;
487
+ const entry = pending.get(id);
488
+ if (!entry)
489
+ return;
490
+ pending.delete(id);
491
+ if (pending.size === 0)
492
+ worker?.unref();
493
+ if (!error)
494
+ return entry.resolve();
495
+ const failure = new Error(error.message);
496
+ failure.name = error.name;
497
+ if (error.stack)
498
+ failure.stack = error.stack;
499
+ entry.reject(failure);
500
+ };
501
+ worker.onerror = () => failWorker(new Error("pnext CSS worker crashed"));
502
+ return worker;
503
+ }
504
+ function failWorker(error) {
505
+ workerFailed = true;
506
+ worker = undefined;
507
+ for (const entry of pending.values())
508
+ entry.reject(error);
509
+ pending.clear();
510
+ }
511
+ function send(request) {
512
+ const active = ensureWorker();
513
+ if (!active)
514
+ return;
515
+ const id = nextId++;
516
+ return new Promise((resolve, reject) => {
517
+ pending.set(id, { resolve, reject });
518
+ active.ref();
519
+ active.postMessage(request(id));
520
+ });
521
+ }
522
+ async function stopCssWorker() {
523
+ const active = worker;
524
+ worker = undefined;
525
+ if (active)
526
+ await Promise.resolve(active.terminate());
527
+ }
528
+ async function runPostcssOffThread(config, cssFile, options, from) {
529
+ const { root, outPath: outDir } = config;
530
+ const dev = options.dev ?? false;
531
+ const sent = send((id) => ({ kind: "process", id, root, dev, outDir, cssFile, from }));
532
+ if (sent)
533
+ return sent;
534
+ return runPostcss(root, cssFile, { dev, outDir }, from);
535
+ }
536
+ function warmCssWorker(config, options = {}) {
537
+ send((id) => ({
538
+ kind: "warm",
539
+ id,
540
+ root: config.root,
541
+ dev: options.dev ?? false,
542
+ outDir: config.outPath
543
+ }))?.catch(() => {});
544
+ }
545
+ function globalCssSource(config) {
546
+ return globalCssSources(config)[0];
547
+ }
548
+ function globalCssSources(config) {
549
+ return productionRelease(config)?.globalCss ?? globalCssSourcesForPaths(config.root, config.appPath, config.workspaceRoot);
550
+ }
551
+ var globalCssSourceCache = new Map;
552
+ var globalCssStore;
553
+ function setGlobalCssSourceStore(store) {
554
+ globalCssStore = store;
555
+ }
556
+ function globalCssSourcesForPaths(root, appPath, workspaceRoot) {
557
+ const key = `${root}\x00${appPath}\x00${workspaceRoot ?? ""}`;
558
+ const cached = globalCssSourceCache.get(key);
559
+ if (cached)
560
+ return cached;
561
+ const stored = globalCssStore?.load(key);
562
+ if (stored) {
563
+ globalCssSourceCache.set(key, stored);
564
+ return stored;
565
+ }
566
+ const sources = new Set;
567
+ const visited = new Set;
568
+ const missing = new Set;
569
+ collectGlobalCssSources(root, rootLayoutFile(appPath, missing), sources, visited, missing, workspaceRoot);
570
+ const resolved = [...sources].map((file) => path2.resolve(file));
571
+ globalCssSourceCache.set(key, resolved);
572
+ globalCssStore?.save(key, resolved, [...visited], [...missing]);
573
+ return resolved;
574
+ }
575
+ function clearGlobalCssSourceCache() {
576
+ globalCssSourceCache.clear();
577
+ }
578
+ function collectGlobalCssSources(root, file, sources, visited, missing, workspaceRoot) {
579
+ const resolvedFile = path2.resolve(file);
580
+ if (visited.has(resolvedFile))
581
+ return;
582
+ if (!existsSync2(resolvedFile)) {
583
+ missing?.add(resolvedFile);
584
+ return;
585
+ }
586
+ visited.add(resolvedFile);
587
+ for (const specifier of moduleSpecifiers(readSourceSync(resolvedFile))) {
588
+ const resolved = resolveImport(root, resolvedFile, specifier, workspaceRoot);
589
+ if (!resolved)
590
+ continue;
591
+ if (isCssFile(resolved)) {
592
+ sources.add(resolved);
593
+ } else {
594
+ collectGlobalCssSources(root, resolved, sources, visited, missing, workspaceRoot);
595
+ }
596
+ }
597
+ }
598
+ function rootLayoutFile(appPath, missing) {
599
+ for (const extension of ["tsx", "ts", "jsx", "js", "mjs", ...extraPageExtensions()]) {
600
+ const file = path2.join(appPath, `layout.${extension}`);
601
+ if (existsSync2(file))
602
+ return file;
603
+ missing?.add(file);
604
+ }
605
+ return path2.join(appPath, "layout.tsx");
606
+ }
607
+ function warmCssPipeline(config, options = {}) {
608
+ if (!hasPostcssConfig(config.root))
609
+ return;
610
+ warmCssWorker(config, options);
611
+ }
612
+ async function buildGlobalCss(config, options = {}) {
613
+ const log = createVerboseLogger(options.verbose ?? false, "css");
614
+ const sources = globalCssSources(config);
615
+ if (sources.length === 0) {
616
+ log.log("global css: no side-effect css imports in root layout, skipping");
617
+ return;
618
+ }
619
+ const outDir = options.dev ? path2.join(config.outPath, "cache", "assets") : path2.join(config.outPath, "public", "assets");
620
+ const outfile = path2.join(outDir, "global.css");
621
+ await ensureDir(outDir);
622
+ log.log(`global css: ${sources.length} source${sources.length === 1 ? "" : "s"} \u2014 ${sources.map((file) => path2.relative(config.root, file)).join(", ")}`);
623
+ const postcss = hasPostcssConfig(config.root);
624
+ await log.step("global css: esbuild bundle", () => build({
625
+ stdin: {
626
+ contents: stdinImports(config.root, sources),
627
+ loader: "css",
628
+ resolveDir: config.root,
629
+ sourcefile: "global.css"
630
+ },
631
+ outfile,
632
+ bundle: true,
633
+ minify: !options.dev,
634
+ conditions: ["style", "browser"],
635
+ assetNames: "files/[name]-[hash]",
636
+ plugins: [
637
+ cssPublicUrlPlugin(),
638
+ ...getCssExtensions().cssChunkPlugins(),
639
+ ...cssDirectiveOrderPlugins(postcss)
640
+ ],
641
+ loader: {
642
+ ".css": "css",
643
+ ".module.css": "css",
644
+ ...cssLoaderEntries(),
645
+ ".woff": "file",
646
+ ".woff2": "file",
647
+ ".ttf": "file",
648
+ ".otf": "file",
649
+ ".eot": "file",
650
+ ".png": "file",
651
+ ".svg": "file",
652
+ ".ico": "file"
653
+ }
654
+ }));
655
+ if (postcss) {
656
+ await rewriteTailwindConfigDirectives(outfile, sources);
657
+ await log.step("global css: postcss", () => runPostcssOffThread(config, outfile, options, sources[0]));
658
+ }
659
+ const emitted = await fingerprintAsset(config, outDir, "global.css", options);
660
+ log.log(`global css \u2192 ${path2.relative(config.root, emitted)}`);
661
+ return emitted;
662
+ }
663
+ async function fingerprintAsset(config, outDir, assetName, options, file = assetName) {
664
+ const outfile = path2.join(outDir, file);
665
+ if (options.dev)
666
+ return outfile;
667
+ const emittedName = hashedAssetName(assetName, await readFile(outfile));
668
+ const emitted = path2.join(outDir, emittedName);
669
+ if (emitted !== outfile)
670
+ await rename(outfile, emitted);
671
+ recordEmittedAsset(config.outPath, assetName, emittedName);
672
+ return emitted;
673
+ }
674
+ function stdinImports(root, files) {
675
+ return files.map((file) => {
676
+ const relative = path2.relative(root, file).split(path2.sep).join("/");
677
+ const specifier = path2.isAbsolute(relative) || relative.startsWith("../") ? relative : `./${relative}`;
678
+ return `@import ${JSON.stringify(specifier)};`;
679
+ }).join(`
680
+ `);
681
+ }
682
+ function moduleSpecifiers(source) {
683
+ const specifiers = [];
684
+ const pattern = /(?:import|export)\s+(?:[^'";]+?\s+from\s+)?['"]([^'"]+)['"]/g;
685
+ let match;
686
+ while (match = pattern.exec(source)) {
687
+ if (match[1])
688
+ specifiers.push(match[1]);
689
+ }
690
+ return specifiers;
691
+ }
692
+ function cssFileExtensions() {
693
+ return [".css", ...getCssExtensions().extraCssExtensions()];
694
+ }
695
+ function isCssFile(file) {
696
+ return cssFileExtensions().some((extension) => file.endsWith(extension));
697
+ }
698
+ function cssLoaderEntries() {
699
+ return Object.fromEntries(getCssExtensions().extraCssExtensions().map((extension) => [extension, "css"]));
700
+ }
701
+ var routeCssPlan = new Map;
702
+ function prepareRouteCssChunks(routes) {
703
+ routeCssPlan.clear();
704
+ const plan = getCssExtensions().planRouteCssChunks(routes.map((route) => ({ id: route.id, cssImports: route.cssImports })));
705
+ for (const [id, segments] of plan)
706
+ routeCssPlan.set(id, segments);
707
+ }
708
+ function routeCssChunks(route) {
709
+ if (route.cssImports.length === 0)
710
+ return;
711
+ const segments = routeCssPlan.get(route.id);
712
+ if (segments && segments.length > 1) {
713
+ const cssAssets = segments.map((_, index) => `${route.id}-${index}.css`);
714
+ const chunks2 = segments.map((imports, index) => ({
715
+ imports,
716
+ name: cssAssets[index],
717
+ label: `route css ${route.route} #${index + 1}`
718
+ }));
719
+ return { cssAssets, chunks: chunks2 };
720
+ }
721
+ const chunks = [
722
+ { imports: route.cssImports, name: `${route.id}.css`, label: `route css ${route.route}` }
723
+ ];
724
+ return { cssAssets: undefined, chunks };
725
+ }
726
+ function clientReferenceCssChunks(reference) {
727
+ if (!reference.cssImports || reference.cssImports.length === 0)
728
+ return [];
729
+ return [
730
+ {
731
+ imports: reference.cssImports,
732
+ name: `${reference.id}.css`,
733
+ label: `island css ${reference.id}`
734
+ }
735
+ ];
736
+ }
737
+ async function buildRouteCss(config, route, options = {}) {
738
+ const css = routeCssChunks(route);
739
+ if (!css)
740
+ return;
741
+ route.cssAssets = css.cssAssets;
742
+ const files = [];
743
+ for (const chunk of css.chunks) {
744
+ files.push(await bundleCssChunk(config, chunk.imports, chunk.name, chunk.label, options));
745
+ }
746
+ return css.cssAssets ? files : files[0];
747
+ }
748
+ var DOCUMENT_CSS = new Set([
749
+ "global.css",
750
+ "not-found.css",
751
+ "global-not-found.css",
752
+ "global-error.css"
753
+ ]);
754
+ function buildRouteStylesheets(config, routes, documentCss, options = {}) {
755
+ const builds = new Map;
756
+ const taken = new Set;
757
+ const publish = new Map;
758
+ for (const route of routes) {
759
+ const css = routeCssChunks(route);
760
+ const chunks = [
761
+ ...css?.chunks ?? [],
762
+ ...route.clientReferences.flatMap(clientReferenceCssChunks)
763
+ ];
764
+ const own = chunks.map((chunk) => {
765
+ const key = `${chunk.name}\x00${chunk.imports.join("\x00")}`;
766
+ let build2 = builds.get(key);
767
+ if (!build2) {
768
+ const file = taken.has(chunk.name) ? `.${builds.size}-${chunk.name}` : chunk.name;
769
+ taken.add(chunk.name);
770
+ const write = () => writeCssChunk(config, chunk.imports, file, chunk.label, options);
771
+ const outDir = DOCUMENT_CSS.has(file) ? documentCss.then(write) : write();
772
+ outDir.catch(() => {
773
+ return;
774
+ });
775
+ build2 = { file, outDir };
776
+ builds.set(key, build2);
777
+ }
778
+ return { name: chunk.name, build: build2 };
779
+ });
780
+ publish.set(route, async () => {
781
+ if (css)
782
+ route.cssAssets = css.cssAssets;
783
+ for (const { name, build: build2 } of own) {
784
+ if (build2.emitted)
785
+ recordEmittedAsset(config.outPath, name, build2.emitted);
786
+ else {
787
+ const emitted = await fingerprintAsset(config, await build2.outDir, name, options, build2.file);
788
+ build2.emitted = path2.basename(emitted);
789
+ }
790
+ }
791
+ });
792
+ }
793
+ return publish;
794
+ }
795
+ async function buildNotFoundCss(config, options = {}) {
796
+ const { collectFileCss } = await import("./routes-2s277fc6.js");
797
+ const targets = [
798
+ {
799
+ id: "not-found",
800
+ files: conventionCandidates(config.appPath, "not-found")
801
+ },
802
+ {
803
+ id: "global-not-found",
804
+ files: conventionCandidates(config.appPath, "global-not-found"),
805
+ includeGlobalCss: true
806
+ },
807
+ {
808
+ id: "global-error",
809
+ files: conventionCandidates(config.appPath, "global-error")
810
+ }
811
+ ];
812
+ for (const target of targets) {
813
+ const cssImports = await collectFileCss(config.appPath, target.files, {
814
+ includeGlobalCss: target.includeGlobalCss ?? false
815
+ });
816
+ if (cssImports.length === 0)
817
+ continue;
818
+ await bundleCssChunk(config, cssImports, `${target.id}.css`, `route css /${target.id}`, options);
819
+ }
820
+ }
821
+ function conventionCandidates(appPath, base) {
822
+ return ["tsx", "ts", "jsx", "js"].map((ext) => path2.join(appPath, `${base}.${ext}`));
823
+ }
824
+ async function buildClientReferenceCss(config, reference, options = {}) {
825
+ const [chunk] = clientReferenceCssChunks(reference);
826
+ if (!chunk)
827
+ return;
828
+ return bundleCssChunk(config, chunk.imports, chunk.name, chunk.label, options);
829
+ }
830
+ async function bundleCssChunk(config, cssImports, assetName, label, options) {
831
+ const outDir = await writeCssChunk(config, cssImports, assetName, label, options);
832
+ return fingerprintAsset(config, outDir, assetName, options);
833
+ }
834
+ async function writeCssChunk(config, cssImports, assetName, label, options) {
835
+ const log = createVerboseLogger(options.verbose ?? false, "css");
836
+ const outDir = options.dev ? path2.join(config.outPath, "cache", "assets") : path2.join(config.outPath, "public", "assets");
837
+ const outfile = path2.join(outDir, assetName);
838
+ await ensureDir(outDir);
839
+ log.log(`${label}: ${cssImports.length} import${cssImports.length === 1 ? "" : "s"}`);
840
+ const postcss = hasPostcssConfig(config.root);
841
+ await build({
842
+ stdin: {
843
+ contents: stdinImports(config.root, cssImports),
844
+ loader: "css",
845
+ resolveDir: config.root,
846
+ sourcefile: assetName
847
+ },
848
+ outfile,
849
+ bundle: true,
850
+ minifyWhitespace: !options.dev,
851
+ minifySyntax: !options.dev,
852
+ minifyIdentifiers: false,
853
+ conditions: ["style", "browser"],
854
+ assetNames: "files/[name]-[hash]",
855
+ plugins: [
856
+ cssPublicUrlPlugin(),
857
+ ...getCssExtensions().cssChunkPlugins(),
858
+ cssModuleBuildPlugin(),
859
+ ...cssDirectiveOrderPlugins(postcss)
860
+ ],
861
+ loader: {
862
+ ".css": "css",
863
+ ".module.css": "css",
864
+ ...cssLoaderEntries(),
865
+ ".woff": "file",
866
+ ".woff2": "file",
867
+ ".ttf": "file",
868
+ ".otf": "file",
869
+ ".eot": "file",
870
+ ".png": "file",
871
+ ".svg": "file",
872
+ ".ico": "file"
873
+ }
874
+ });
875
+ if (postcss) {
876
+ await rewriteTailwindConfigDirectives(outfile, cssImports);
877
+ await log.step(`${label}: postcss`, () => runPostcssOffThread(config, outfile, options));
878
+ }
879
+ return outDir;
880
+ }
881
+ function cssPublicUrlPlugin() {
882
+ return {
883
+ name: "pnext-css-public-url",
884
+ setup(plugin) {
885
+ plugin.onResolve({ filter: /^\// }, (args) => args.kind === "url-token" ? { path: args.path, external: true } : undefined);
886
+ }
887
+ };
888
+ }
889
+ function cssModuleClientPlugin() {
890
+ return {
891
+ name: "pnext-css-modules",
892
+ setup(plugin) {
893
+ plugin.onLoad({ filter: /\.(?:css|scss|sass)$/ }, async ({ path: file }) => ({
894
+ contents: isCssModuleFile(file) ? `export default ${JSON.stringify(await cssModuleMapping(file))};` : "export default undefined;",
895
+ loader: "js"
896
+ }));
897
+ }
898
+ };
899
+ }
900
+ function cssDirectiveOrderPlugins(postcss) {
901
+ return postcss ? [cssDirectiveOrderPlugin()] : [];
902
+ }
903
+ function cssDirectiveOrderPlugin() {
904
+ return {
905
+ name: "pnext-css-directive-order",
906
+ setup(plugin) {
907
+ plugin.onLoad({ filter: /\.css$/ }, async ({ path: file }) => ({
908
+ contents: hoistCssImports(await readText(file)),
909
+ loader: "css",
910
+ resolveDir: path2.dirname(file)
911
+ }));
912
+ }
913
+ };
914
+ }
915
+ var CSS_CONFIG_AT_RULES = new Set(["source", "plugin", "config"]);
916
+ function hoistCssImports(source) {
917
+ if (!/@(?:source|plugin|config)\b/.test(source))
918
+ return source;
919
+ const imports = [];
920
+ const others = [];
921
+ let charset = "";
922
+ let sawDirective = false;
923
+ let hoist = false;
924
+ let index = 0;
925
+ while (index < source.length) {
926
+ const code = source.charCodeAt(index);
927
+ if (code === 32 || code === 9 || code === 10 || code === 13 || code === 12) {
928
+ index += 1;
929
+ continue;
930
+ }
931
+ const char = source[index];
932
+ if (char === "/" && source[index + 1] === "*") {
933
+ const end2 = source.indexOf("*/", index + 2);
934
+ if (end2 === -1)
935
+ break;
936
+ others.push(source.slice(index, end2 + 2));
937
+ index = end2 + 2;
938
+ continue;
939
+ }
940
+ const name = char === "@" ? /^@([\w-]+)/.exec(source.slice(index))?.[1] : undefined;
941
+ if (!name)
942
+ break;
943
+ if (name !== "import" && name !== "charset" && !CSS_CONFIG_AT_RULES.has(name))
944
+ break;
945
+ const end = statementEnd(source, index);
946
+ if (end === -1)
947
+ break;
948
+ const statement = source.slice(index, end);
949
+ if (name === "charset")
950
+ charset ||= statement;
951
+ else if (name === "import") {
952
+ imports.push(statement);
953
+ if (sawDirective)
954
+ hoist = true;
955
+ } else {
956
+ others.push(statement);
957
+ sawDirective = true;
958
+ }
959
+ index = end;
960
+ }
961
+ if (!hoist)
962
+ return source;
963
+ return `${[charset, ...imports, ...others].filter(Boolean).join(`
964
+ `)}
965
+ ${source.slice(index)}`;
966
+ }
967
+ function statementEnd(source, start) {
968
+ for (let index = start;index < source.length; index += 1) {
969
+ const char = source[index];
970
+ if (char === ";")
971
+ return index + 1;
972
+ if (char === "{" || char === "}")
973
+ return -1;
974
+ if (char === '"' || char === "'") {
975
+ index = skipString(source, index);
976
+ if (index === -1)
977
+ return -1;
978
+ }
979
+ }
980
+ return -1;
981
+ }
982
+ function skipString(source, start) {
983
+ const quote = source[start];
984
+ for (let index = start + 1;index < source.length; index += 1) {
985
+ const char = source[index];
986
+ if (char === "\\")
987
+ index += 1;
988
+ else if (char === quote)
989
+ return index;
990
+ }
991
+ return -1;
992
+ }
993
+ function cssModuleBuildPlugin() {
994
+ return {
995
+ name: "pnext-css-module-build",
996
+ setup(plugin) {
997
+ plugin.onLoad({ filter: /\.module\.css$/ }, async ({ path: file }) => ({
998
+ contents: transformCssModule(await readText(file), file),
999
+ loader: "css"
1000
+ }));
1001
+ }
1002
+ };
1003
+ }
1004
+ function transformCssModule(source, file) {
1005
+ let css = source;
1006
+ for (const className of cssClassNames(source)) {
1007
+ css = rewriteClassSelector(css, cssModuleClassName(file, className), className);
1008
+ }
1009
+ css = scopeKeyframes(css, file);
1010
+ return css;
1011
+ }
1012
+ function scopeKeyframes(css, file) {
1013
+ const names = keyframeNames(css);
1014
+ if (names.size === 0)
1015
+ return css;
1016
+ let out = css;
1017
+ for (const name of names) {
1018
+ const scoped = cssModuleClassName(file, name);
1019
+ out = out.replace(new RegExp(`(@(?:-webkit-)?keyframes\\s+)${escapeRegex(name)}(?![-_a-zA-Z0-9])`, "g"), `$1${scoped}`);
1020
+ out = out.replace(new RegExp(`(animation-name\\s*:\\s*)${escapeRegex(name)}(?![-_a-zA-Z0-9])`, "g"), `$1${scoped}`);
1021
+ out = out.replace(new RegExp(`(animation\\s*:[^;{}]*?(?<![-_a-zA-Z0-9]))${escapeRegex(name)}(?![-_a-zA-Z0-9])`, "g"), `$1${scoped}`);
1022
+ }
1023
+ return out;
1024
+ }
1025
+ function keyframeNames(css) {
1026
+ const names = new Set;
1027
+ const pattern = /@(?:-webkit-)?keyframes\s+(-?[_a-zA-Z][\w-]*)/g;
1028
+ let match;
1029
+ while (match = pattern.exec(css)) {
1030
+ if (match[1])
1031
+ names.add(match[1]);
1032
+ }
1033
+ return names;
1034
+ }
1035
+ function rewriteClassSelector(css, scopedClassName, originalClassName) {
1036
+ const esbuildNamePattern = new RegExp(`\\.${escapeRegex(originalClassName)}(?![-_a-zA-Z0-9])`, "g");
1037
+ return css.replace(esbuildNamePattern, `.${scopedClassName}`);
1038
+ }
1039
+ function escapeRegex(value) {
1040
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1041
+ }
1042
+ function hasPostcssConfig(root) {
1043
+ return postcssConfigFile(root) !== undefined;
1044
+ }
1045
+ async function rewriteTailwindConfigDirectives(cssFile, sources) {
1046
+ const candidateDirs = [path2.dirname(cssFile), ...sources.map((file) => path2.dirname(file))];
1047
+ let css = await readText(cssFile);
1048
+ let changed = false;
1049
+ css = css.replace(/@config\s+(['"])([^'"]+)\1\s*;/g, (match, quote, specifier) => {
1050
+ if (!isRelativeSpecifier(specifier))
1051
+ return match;
1052
+ const resolved = candidateDirs.map((dir) => path2.resolve(dir, specifier)).find((file) => existsSync2(file));
1053
+ if (!resolved)
1054
+ return match;
1055
+ changed = true;
1056
+ return `@config ${quote}${resolved.split(path2.sep).join("/")}${quote};`;
1057
+ });
1058
+ if (changed)
1059
+ await writeFile2(cssFile, css);
1060
+ }
1061
+ function isRelativeSpecifier(specifier) {
1062
+ return specifier.startsWith("./") || specifier.startsWith("../");
1063
+ }
1064
+
1065
+ export { stopCssWorker, runPostcssOffThread, warmCssWorker, globalCssSource, globalCssSources, setGlobalCssSourceStore, globalCssSourcesForPaths, clearGlobalCssSourceCache, warmCssPipeline, buildGlobalCss, isCssFile, prepareRouteCssChunks, buildRouteCss, buildRouteStylesheets, buildNotFoundCss, buildClientReferenceCss, cssModuleClientPlugin, hoistCssImports, rewriteTailwindConfigDirectives };