vinext 1.2.0 → 1.3.0

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 (283) hide show
  1. package/README.md +13 -10
  2. package/dist/build/client-build-config.d.ts +64 -3
  3. package/dist/build/client-build-config.js +131 -4
  4. package/dist/build/client-reference-groups.d.ts +163 -0
  5. package/dist/build/client-reference-groups.js +534 -0
  6. package/dist/build/module-dependency-cache.d.ts +31 -0
  7. package/dist/build/module-dependency-cache.js +51 -1
  8. package/dist/build/next-client-runtime-manifests.d.ts +10 -1
  9. package/dist/build/next-client-runtime-manifests.js +19 -4
  10. package/dist/build/nitro-public-files.d.ts +24 -0
  11. package/dist/build/nitro-public-files.js +60 -0
  12. package/dist/build/output-root-externals.d.ts +21 -0
  13. package/dist/build/output-root-externals.js +40 -0
  14. package/dist/build/pages-client-assets-module.js +1 -1
  15. package/dist/build/prerender-paths.js +6 -3
  16. package/dist/build/prerender.js +1 -1
  17. package/dist/build/server-actions-encryption-key.d.ts +23 -0
  18. package/dist/build/server-actions-encryption-key.js +101 -0
  19. package/dist/build/ssr-manifest.d.ts +3 -0
  20. package/dist/build/ssr-manifest.js +10 -1
  21. package/dist/check.js +5 -6
  22. package/dist/cli-dev-config.js +3 -3
  23. package/dist/cli.js +1 -1
  24. package/dist/client/client-rewrite-params.d.ts +9 -0
  25. package/dist/client/client-rewrite-params.js +20 -0
  26. package/dist/client/dev-error-overlay.js +2 -1
  27. package/dist/client/navigation-runtime.d.ts +25 -2
  28. package/dist/client/navigation-runtime.js +42 -11
  29. package/dist/client/vinext-next-data.d.ts +0 -1
  30. package/dist/config/config-matchers.d.ts +15 -40
  31. package/dist/config/config-matchers.js +195 -262
  32. package/dist/config/config-source.d.ts +34 -0
  33. package/dist/config/config-source.js +141 -0
  34. package/dist/config/header-params.d.ts +29 -0
  35. package/dist/config/header-params.js +106 -0
  36. package/dist/config/next-config.d.ts +7 -5
  37. package/dist/config/next-config.js +120 -7
  38. package/dist/entries/app-browser-entry.d.ts +14 -1
  39. package/dist/entries/app-browser-entry.js +26 -36
  40. package/dist/entries/app-rsc-entry.d.ts +2 -0
  41. package/dist/entries/app-rsc-entry.js +92 -57
  42. package/dist/entries/app-rsc-manifest.d.ts +10 -0
  43. package/dist/entries/app-rsc-manifest.js +20 -1
  44. package/dist/entries/app-ssr-entry.d.ts +4 -1
  45. package/dist/entries/app-ssr-entry.js +9 -2
  46. package/dist/entries/pages-client-entry.d.ts +1 -0
  47. package/dist/entries/pages-client-entry.js +6 -6
  48. package/dist/entries/pages-server-entry.js +17 -14
  49. package/dist/index.d.ts +11 -0
  50. package/dist/index.js +350 -175
  51. package/dist/init.d.ts +1 -1
  52. package/dist/init.js +103 -6
  53. package/dist/plugins/ast-utils.d.ts +53 -2
  54. package/dist/plugins/ast-utils.js +90 -2
  55. package/dist/plugins/cloudflare-dev-module-urls.d.ts +41 -0
  56. package/dist/plugins/cloudflare-dev-module-urls.js +271 -0
  57. package/dist/plugins/commonjs-esm-facade.js +2 -2
  58. package/dist/plugins/css-module-imports.js +13 -20
  59. package/dist/plugins/dynamic-preload-metadata.js +2 -3
  60. package/dist/plugins/extensionless-dynamic-import.js +2 -3
  61. package/dist/plugins/fonts.d.ts +1 -1
  62. package/dist/plugins/fonts.js +3 -3
  63. package/dist/plugins/ignore-dynamic-requests.js +2 -3
  64. package/dist/plugins/import-meta-url.js +3 -4
  65. package/dist/plugins/instrumentation-client.js +3 -2
  66. package/dist/plugins/middleware-export-validation.js +2 -3
  67. package/dist/plugins/og-harfbuzz.js +2 -3
  68. package/dist/plugins/optimize-imports.d.ts +25 -2
  69. package/dist/plugins/optimize-imports.js +109 -24
  70. package/dist/plugins/pages-node-externals.js +2 -3
  71. package/dist/plugins/remove-console.js +2 -18
  72. package/dist/plugins/require-condition-resolution.js +3 -3
  73. package/dist/plugins/require-context.js +2 -3
  74. package/dist/plugins/rsc-client-reference-loaders.d.ts +45 -1
  75. package/dist/plugins/rsc-client-reference-loaders.js +336 -18
  76. package/dist/plugins/strip-server-exports.js +3 -4
  77. package/dist/plugins/styled-jsx.js +2 -3
  78. package/dist/plugins/use-cache-callable.d.ts +26 -2
  79. package/dist/plugins/use-cache-callable.js +101 -36
  80. package/dist/plugins/worker-image-imports.d.ts +1 -0
  81. package/dist/plugins/worker-image-imports.js +31 -34
  82. package/dist/plugins/worker-use-server.js +38 -14
  83. package/dist/routing/app-route-graph.d.ts +1 -1
  84. package/dist/routing/browser-route-manifest.d.ts +43 -0
  85. package/dist/routing/browser-route-manifest.js +195 -0
  86. package/dist/routing/hashed-route-patterns.d.ts +4 -0
  87. package/dist/routing/hashed-route-patterns.js +22 -0
  88. package/dist/routing/optimistic-route-trie.d.ts +27 -0
  89. package/dist/routing/optimistic-route-trie.js +102 -0
  90. package/dist/routing/route-validation.d.ts +6 -1
  91. package/dist/routing/route-validation.js +26 -10
  92. package/dist/server/api-handler.js +1 -1
  93. package/dist/server/app-action-forwarding.d.ts +8 -0
  94. package/dist/server/app-action-forwarding.js +17 -3
  95. package/dist/server/app-browser-entry.js +149 -62
  96. package/dist/server/app-browser-error.d.ts +3 -1
  97. package/dist/server/app-browser-error.js +7 -2
  98. package/dist/server/app-browser-interception-context.d.ts +2 -2
  99. package/dist/server/app-browser-interception-context.js +1 -1
  100. package/dist/server/app-browser-mpa-navigation.d.ts +1 -0
  101. package/dist/server/app-browser-mpa-navigation.js +6 -5
  102. package/dist/server/app-browser-navigation-controller.d.ts +17 -6
  103. package/dist/server/app-browser-navigation-controller.js +88 -26
  104. package/dist/server/app-browser-prefetch-response.js +2 -2
  105. package/dist/server/app-browser-state.d.ts +2 -2
  106. package/dist/server/app-browser-state.js +1 -1
  107. package/dist/server/app-browser-supplemental-refresh.js +1 -1
  108. package/dist/server/app-browser-visible-commit.d.ts +4 -4
  109. package/dist/server/app-client-reference-preloader.d.ts +23 -0
  110. package/dist/server/app-client-reference-preloader.js +30 -7
  111. package/dist/server/app-fallback-renderer.js +2 -1
  112. package/dist/server/app-middleware.d.ts +6 -0
  113. package/dist/server/app-middleware.js +8 -10
  114. package/dist/server/app-optimistic-routing.d.ts +8 -10
  115. package/dist/server/app-optimistic-routing.js +4 -95
  116. package/dist/server/app-page-boundary-render.js +8 -1
  117. package/dist/server/app-page-cache-render.js +1 -0
  118. package/dist/server/app-page-dispatch.js +3 -1
  119. package/dist/server/app-page-render.js +4 -2
  120. package/dist/server/app-page-rsc-render-status.d.ts +1 -0
  121. package/dist/server/app-page-rsc-render-status.js +1 -0
  122. package/dist/server/app-page-search-params-observation.d.ts +1 -4
  123. package/dist/server/app-page-search-params-observation.js +8 -10
  124. package/dist/server/app-page-stream.d.ts +7 -0
  125. package/dist/server/app-page-stream.js +1 -0
  126. package/dist/server/app-pages-bridge.d.ts +2 -1
  127. package/dist/server/app-pages-bridge.js +12 -8
  128. package/dist/server/app-prerender-endpoints.js +1 -1
  129. package/dist/server/app-prerender-static-params.js +3 -2
  130. package/dist/server/app-render-abort-error.d.ts +19 -0
  131. package/dist/server/app-render-abort-error.js +31 -1
  132. package/dist/server/app-render-dependency.js +42 -2
  133. package/dist/server/app-request-stage-independent-entry.js +7 -7
  134. package/dist/server/app-response-stage-entry.js +5 -5
  135. package/dist/server/app-route-handler-dispatch.js +3 -1
  136. package/dist/server/app-route-handler-execution.d.ts +2 -0
  137. package/dist/server/app-route-handler-execution.js +9 -2
  138. package/dist/server/app-route-handler-middleware-context.d.ts +2 -1
  139. package/dist/server/app-route-handler-middleware-context.js +3 -3
  140. package/dist/server/app-route-handler-response.d.ts +2 -1
  141. package/dist/server/app-route-handler-response.js +2 -2
  142. package/dist/server/app-route-handler-runtime.d.ts +2 -0
  143. package/dist/server/app-route-handler-runtime.js +21 -4
  144. package/dist/server/app-route-module-loader.js +7 -6
  145. package/dist/server/app-route-tree.d.ts +20 -0
  146. package/dist/server/app-route-tree.js +18 -0
  147. package/dist/server/app-router-entry.js +7 -7
  148. package/dist/server/app-rsc-cache-busting.d.ts +16 -0
  149. package/dist/server/app-rsc-cache-busting.js +29 -12
  150. package/dist/server/app-rsc-combined-handler.js +8 -1
  151. package/dist/server/app-rsc-errors.d.ts +7 -0
  152. package/dist/server/app-rsc-errors.js +9 -2
  153. package/dist/server/app-rsc-handler.d.ts +4 -1
  154. package/dist/server/app-rsc-handler.js +151 -135
  155. package/dist/server/app-rsc-request-normalization.js +3 -3
  156. package/dist/server/app-rsc-response-finalizer.d.ts +5 -0
  157. package/dist/server/app-rsc-response-finalizer.js +4 -1
  158. package/dist/server/app-rsc-response-stage.js +5 -3
  159. package/dist/server/app-rsc-route-matching.d.ts +1 -0
  160. package/dist/server/app-rsc-route-matching.js +1 -1
  161. package/dist/server/app-server-action-execution.d.ts +23 -6
  162. package/dist/server/app-server-action-execution.js +51 -57
  163. package/dist/server/app-ssr-entry.d.ts +6 -0
  164. package/dist/server/app-ssr-entry.js +21 -11
  165. package/dist/server/app-ssr-stream.d.ts +7 -0
  166. package/dist/server/app-ssr-stream.js +13 -1
  167. package/dist/server/app-visited-response-cache.js +2 -2
  168. package/dist/server/config-headers.js +13 -4
  169. package/dist/server/defer-until-stream-consumed.d.ts +2 -1
  170. package/dist/server/defer-until-stream-consumed.js +3 -1
  171. package/dist/server/dev-server.js +1 -1
  172. package/dist/server/image-optimization.js +1 -0
  173. package/dist/server/isolate-shared-promise.d.ts +10 -0
  174. package/dist/server/isolate-shared-promise.js +33 -0
  175. package/dist/server/isr-cache.js +3 -2
  176. package/dist/server/metadata-route-response.js +2 -2
  177. package/dist/server/middleware-matcher-pattern.d.ts +0 -1
  178. package/dist/server/middleware-matcher-pattern.js +11 -140
  179. package/dist/server/middleware-matcher.js +5 -6
  180. package/dist/server/middleware-response-headers.d.ts +31 -0
  181. package/dist/server/middleware-response-headers.js +57 -1
  182. package/dist/server/middleware-runtime.js +30 -17
  183. package/dist/server/navigation-planner.d.ts +2 -2
  184. package/dist/server/navigation-planner.js +1 -1
  185. package/dist/server/nitro-public-files-plugin.d.ts +38 -0
  186. package/dist/server/nitro-public-files-plugin.js +106 -0
  187. package/dist/server/nitro-public-files.d.ts +21 -0
  188. package/dist/server/nitro-public-files.js +39 -0
  189. package/dist/server/open-redirect.d.ts +11 -4
  190. package/dist/server/open-redirect.js +11 -4
  191. package/dist/server/pages-api-route.js +2 -2
  192. package/dist/server/pages-asset-tags.d.ts +5 -0
  193. package/dist/server/pages-asset-tags.js +9 -2
  194. package/dist/server/pages-client-assets.d.ts +4 -1
  195. package/dist/server/pages-data-route.js +2 -1
  196. package/dist/server/pages-i18n.d.ts +18 -0
  197. package/dist/server/pages-i18n.js +18 -2
  198. package/dist/server/pages-node-compat.d.ts +5 -3
  199. package/dist/server/pages-node-compat.js +35 -16
  200. package/dist/server/pages-page-data.js +1 -1
  201. package/dist/server/pages-page-handler.js +1 -1
  202. package/dist/server/pages-page-response.js +1 -1
  203. package/dist/server/pages-request-pipeline.d.ts +6 -1
  204. package/dist/server/pages-request-pipeline.js +35 -39
  205. package/dist/server/pages-request-stage-entry.js +20 -10
  206. package/dist/server/pages-response-stage-entry.js +1 -1
  207. package/dist/server/pages-revalidate.js +3 -2
  208. package/dist/server/pages-router-entry.js +2 -2
  209. package/dist/server/prod-server.d.ts +2 -2
  210. package/dist/server/prod-server.js +74 -36
  211. package/dist/server/proxy-trust.d.ts +6 -0
  212. package/dist/server/proxy-trust.js +12 -6
  213. package/dist/server/request-pipeline.d.ts +5 -0
  214. package/dist/server/request-pipeline.js +12 -1
  215. package/dist/server/rsc-stream-hints.d.ts +1 -1
  216. package/dist/server/rsc-stream-hints.js +21 -3
  217. package/dist/server/server-reference-loader.js +10 -1
  218. package/dist/server/static-file-cache.js +15 -3
  219. package/dist/server/worker-image-optimization.js +19 -6
  220. package/dist/server/worker-utils.js +1 -1
  221. package/dist/shims/cache-handler.js +3 -2
  222. package/dist/shims/cache-request-state.d.ts +40 -3
  223. package/dist/shims/cache-request-state.js +70 -5
  224. package/dist/shims/cache-runtime.js +47 -19
  225. package/dist/shims/cache.d.ts +2 -2
  226. package/dist/shims/cache.js +17 -8
  227. package/dist/shims/cdn-purge-routes.d.ts +24 -0
  228. package/dist/shims/cdn-purge-routes.js +77 -0
  229. package/dist/shims/dynamic.js +17 -4
  230. package/dist/shims/form.js +8 -3
  231. package/dist/shims/head.js +1 -1
  232. package/dist/shims/headers.js +2 -2
  233. package/dist/shims/image-props.d.ts +93 -0
  234. package/dist/shims/image-props.js +323 -0
  235. package/dist/shims/image.d.ts +4 -18
  236. package/dist/shims/image.js +4 -319
  237. package/dist/shims/internal/headers-state.d.ts +7 -0
  238. package/dist/shims/internal/headers-state.js +14 -2
  239. package/dist/shims/internal/hybrid-client-route-owner-direct.d.ts +4 -1
  240. package/dist/shims/internal/hybrid-client-route-owner-direct.js +32 -15
  241. package/dist/shims/internal/hybrid-client-route-owner.js +9 -8
  242. package/dist/shims/link-prefetch.js +5 -4
  243. package/dist/shims/link.js +7 -5
  244. package/dist/shims/navigation.d.ts +1 -1
  245. package/dist/shims/navigation.js +21 -10
  246. package/dist/shims/og.js +35 -10
  247. package/dist/shims/request-context.d.ts +13 -0
  248. package/dist/shims/router.js +28 -52
  249. package/dist/shims/server.d.ts +42 -8
  250. package/dist/shims/server.js +99 -15
  251. package/dist/shims/thenable-params.d.ts +6 -1
  252. package/dist/shims/thenable-params.js +11 -2
  253. package/dist/shims/unified-request-context.d.ts +5 -0
  254. package/dist/shims/unified-request-context.js +2 -0
  255. package/dist/shims/url-utils.d.ts +7 -0
  256. package/dist/shims/url-utils.js +12 -3
  257. package/dist/utils/asset-prefix.d.ts +7 -0
  258. package/dist/utils/asset-prefix.js +10 -1
  259. package/dist/utils/client-build-manifest.js +12 -5
  260. package/dist/utils/client-runtime-metadata.d.ts +1 -0
  261. package/dist/utils/client-runtime-metadata.js +15 -2
  262. package/dist/utils/domain-locale.js +1 -1
  263. package/dist/utils/lazy-chunks.d.ts +4 -0
  264. package/dist/utils/manifest-paths.d.ts +14 -0
  265. package/dist/utils/manifest-paths.js +22 -1
  266. package/dist/utils/path-to-regexp.d.ts +21 -0
  267. package/dist/{server/middleware-path-to-regexp.js → utils/path-to-regexp.js} +14 -11
  268. package/dist/utils/plugin-react-version.d.ts +15 -0
  269. package/dist/utils/plugin-react-version.js +64 -0
  270. package/dist/utils/plugin-rsc-version.d.ts +2 -0
  271. package/dist/utils/plugin-rsc-version.js +28 -2
  272. package/dist/utils/public-routes.d.ts +2 -0
  273. package/dist/utils/public-routes.js +18 -7
  274. package/dist/utils/react-version.d.ts +7 -0
  275. package/dist/utils/react-version.js +39 -16
  276. package/package.json +6 -6
  277. package/dist/build/nitro-route-rules.d.ts +0 -47
  278. package/dist/build/nitro-route-rules.js +0 -79
  279. package/dist/plugins/cache-flight-codec.d.ts +0 -19
  280. package/dist/plugins/cache-flight-codec.js +0 -68
  281. package/dist/server/middleware-path-to-regexp.d.ts +0 -13
  282. package/dist/utils/regex-safety.d.ts +0 -17
  283. package/dist/utils/regex-safety.js +0 -789
@@ -0,0 +1,271 @@
1
+ import path from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
2
+ import { isCSSRequest } from "vite";
3
+ //#region src/plugins/cloudflare-dev-module-urls.ts
4
+ /**
5
+ * Serve Vite's module URLs before the Cloudflare plugin applies
6
+ * `assets.runWorkerFirst` during development.
7
+ *
8
+ * `vinext init` generates `runWorkerFirst: ["/*", "!/_next/static/*", ...]` so
9
+ * middleware runs for `public/` files. In dev, the Cloudflare plugin sends every
10
+ * request matching those patterns to the Worker before Vite's own middlewares
11
+ * run. That includes Vite's module URLs (`/@vite/client`, `/@id/*`, `/@fs/*`,
12
+ * source files such as `/app/globals.css`), which have no production
13
+ * equivalent, so the Worker answers them with the app's 404 page and nothing
14
+ * hydrates.
15
+ *
16
+ * This plugin registers a pre-middleware ahead of the Cloudflare plugin's and
17
+ * gives Vite's module-serving middlewares the first chance to handle each
18
+ * request. Vite decides what it serves: page navigations, non-GET requests, and
19
+ * unknown paths fall through to the Cloudflare plugin unchanged.
20
+ *
21
+ * The same change was made in the Cloudflare plugin itself in
22
+ * https://github.com/cloudflare/workers-sdk/pull/16281.
23
+ *
24
+ * See https://github.com/cloudflare/vinext/issues/4005.
25
+ */
26
+ /**
27
+ * Vite's internal middlewares that serve module requests (`/@vite/client`,
28
+ * `/@id/*`, JS and CSS source files) and `/@fs/*` paths, preceded by the one
29
+ * that strips a non-root `base` from the URL and the one that answers the HMR
30
+ * client's reconnect ping (`Accept: text/x-vite-ping`) with a 204 instead of
31
+ * the Worker rendering a page for it. If Vite renames them, none are found and
32
+ * every request falls through, which is the behavior without this plugin.
33
+ *
34
+ * `viteServePublicMiddleware` is deliberately excluded so that `public/` files
35
+ * reach the Worker and middleware, as they do in production. Without it, the
36
+ * transform middleware reports a public `.js` or `.css` file as an
37
+ * `ERR_LOAD_PUBLIC_URL` error, which is treated as a fall-through.
38
+ */
39
+ const VITE_MODULE_MIDDLEWARE_NAMES = /* @__PURE__ */ new Set([
40
+ "viteBaseMiddleware",
41
+ "viteHMRPingMiddleware",
42
+ "viteTransformMiddleware",
43
+ "viteServeRawFsMiddleware"
44
+ ]);
45
+ /**
46
+ * Vite's internal middleware that serves files under the project root. Vite
47
+ * gives imported assets root-relative URLs (`import logo from "./logo.svg"`
48
+ * and CSS `url(./bg.png)` both resolve to paths like `/app/logo.svg`), and only
49
+ * this middleware serves them. It also serves every other project file, and a
50
+ * Worker route can share its path with one (e.g. an `api/` directory and an
51
+ * `/api/*` route handler), so it only runs for referenced assets. See
52
+ * `isReferencedAsset`. Navigations to a referenced asset
53
+ * are served too: in production its URL is under `/_next/static/`, which never
54
+ * reaches the Worker.
55
+ */
56
+ const VITE_STATIC_MIDDLEWARE_NAME = "viteServeStaticMiddleware";
57
+ /**
58
+ * The Cloudflare plugin's middleware that sends requests matching
59
+ * `runWorkerFirst` to the Worker. It's only registered when `runWorkerFirst` is
60
+ * set, and without it Vite's middlewares already run in their usual order.
61
+ */
62
+ const CLOUDFLARE_PRE_MIDDLEWARE_NAME = "cloudflarePreMiddleware";
63
+ /**
64
+ * Creates the plugin that lets Vite serve its module URLs before the Cloudflare
65
+ * plugin's `runWorkerFirst` routing in dev.
66
+ *
67
+ * @param options - Plugin options
68
+ * @returns The Vite plugin
69
+ */
70
+ function createCloudflareDevModuleUrlsPlugin(options) {
71
+ return {
72
+ name: "vinext:cloudflare-dev-module-urls",
73
+ apply: "serve",
74
+ enforce: "pre",
75
+ configureServer(server) {
76
+ if (!options.isEnabled()) return;
77
+ server.middlewares.use(function vinextCloudflareDevModuleUrls(req, res, next) {
78
+ runViteModuleMiddlewares(server, req, res, next);
79
+ });
80
+ }
81
+ };
82
+ }
83
+ /**
84
+ * Runs Vite's module-serving middlewares in order, calling `next` once none of
85
+ * them handle the request.
86
+ *
87
+ * @param server - The Vite dev server whose middleware stack is searched
88
+ * @param req - The incoming request
89
+ * @param res - The outgoing response
90
+ * @param next - Called when no middleware handles the request, or with an error
91
+ */
92
+ function runViteModuleMiddlewares(server, req, res, next) {
93
+ const url = req.url;
94
+ if (req.method !== "GET" && req.method !== "HEAD" || !url?.startsWith(server.config.base)) {
95
+ next();
96
+ return;
97
+ }
98
+ const stack = server.middlewares.stack;
99
+ if (!stack.some((layer) => getHandleName(layer.handle) === CLOUDFLARE_PRE_MIDDLEWARE_NAME)) {
100
+ next();
101
+ return;
102
+ }
103
+ const handles = stack.flatMap((layer) => {
104
+ const handle = layer.handle;
105
+ if (typeof handle !== "function") return [];
106
+ if (VITE_MODULE_MIDDLEWARE_NAMES.has(handle.name)) return [handle];
107
+ if (handle.name === "viteServeStaticMiddleware") {
108
+ const serveStatic = handle;
109
+ return [(req, res, next) => isReferencedAsset(server, req.url) ? serveStatic(req, res, next) : next()];
110
+ }
111
+ return [];
112
+ });
113
+ let index = 0;
114
+ const tryNext = (error) => {
115
+ if (isPublicFileLoadError(error)) {
116
+ req.url = url;
117
+ next();
118
+ return;
119
+ }
120
+ if (error) {
121
+ next(error);
122
+ return;
123
+ }
124
+ const handle = handles[index++];
125
+ if (!handle) {
126
+ req.url = url;
127
+ next();
128
+ return;
129
+ }
130
+ try {
131
+ const result = handle(req, res, tryNext);
132
+ if (result instanceof Promise) result.catch(next);
133
+ } catch (e) {
134
+ next(e);
135
+ }
136
+ };
137
+ tryNext();
138
+ }
139
+ function getHandleName(handle) {
140
+ return typeof handle === "function" ? handle.name : void 0;
141
+ }
142
+ /**
143
+ * Whether the transform middleware rejected a request because it is for a
144
+ * `public/` file, which `viteServePublicMiddleware` would normally serve.
145
+ */
146
+ function isPublicFileLoadError(error) {
147
+ return typeof error === "object" && error !== null && "code" in error && error.code === "ERR_LOAD_PUBLIC_URL";
148
+ }
149
+ /**
150
+ * Whether a request URL, with any `base` already stripped, is the URL of an
151
+ * asset that Vite gave to a module.
152
+ *
153
+ * The browser only learns an asset URL from a module Vite has transformed:
154
+ * - The asset's own JS module (`import logo from "./logo.svg"` or `?url`),
155
+ * whose code is `export default "<url>"`, possibly followed by a query or
156
+ * fragment (`?t=` after HMR). Only files Vite treats as assets and `?url`
157
+ * imports count: other modules, such as JSON or `?raw` and `?inline`
158
+ * imports, export the file's contents, which could look like a URL.
159
+ * - A JS module that uses `new URL("./logo.svg", import.meta.url)`, which Vite
160
+ * rewrites to `new URL("<url>", '' + import.meta.url)`.
161
+ * - A stylesheet whose `url()` or `image-set()` Vite resolved.
162
+ *
163
+ * The importers of the asset's file in the module graph cover the last two.
164
+ * Other project files can also be in the graph (Tailwind reports every file it
165
+ * scans as a dependency of the stylesheet), and other imports name the file
166
+ * with a query (`?raw` inlines its contents), but no module's code contains
167
+ * their bare URL in one of these forms, so they keep reaching the Worker.
168
+ *
169
+ * @param server - The Vite dev server whose module graphs are searched
170
+ * @param url - The request URL, with any `base` stripped
171
+ * @returns `true` if a module emitted the URL for the file
172
+ */
173
+ function isReferencedAsset(server, url) {
174
+ if (!url) return false;
175
+ const { pathname } = new URL(url, "http://localhost");
176
+ let decodedPathname;
177
+ try {
178
+ decodedPathname = decodeURI(pathname);
179
+ } catch {
180
+ return false;
181
+ }
182
+ const base = server.config.base;
183
+ let decodedBase = base;
184
+ try {
185
+ decodedBase = decodeURI(base);
186
+ } catch {}
187
+ const origin = server.config.server.origin?.replace(/\/+$/, "");
188
+ const urls = [...new Set([pathname, decodedPathname].flatMap((p) => {
189
+ const underBase = [base, decodedBase].map((b) => b + p.slice(1));
190
+ return [
191
+ p,
192
+ ...underBase,
193
+ ...origin ? underBase.map((u) => origin + u) : []
194
+ ];
195
+ }))];
196
+ const file = resolveStaticFile(server, decodedPathname);
197
+ const isAsset = server.config.assetsInclude(file);
198
+ for (const environment of Object.values(server.environments)) for (const module of environment.moduleGraph.getModulesByFile(file) ?? []) {
199
+ const code = module.transformResult?.code;
200
+ if (code && isAssetUrlModule(module.url, isAsset) && urls.some((u) => containsAssetUrl(code, u))) return true;
201
+ for (const importer of module.importers) {
202
+ const code = importer.transformResult?.code;
203
+ if (!code) continue;
204
+ const css = isCSSRequest(importer.url);
205
+ if (urls.some((u) => css ? containsCssUrl(code, u) : code.includes(`new URL("${u}", '' + import.meta.url)`))) return true;
206
+ }
207
+ }
208
+ return false;
209
+ }
210
+ /**
211
+ * Whether a module for the file exports the file's URL: a `?url` import, or an
212
+ * import of an asset without Vite's `raw` or `inline` queries, which export its
213
+ * contents.
214
+ */
215
+ function isAssetUrlModule(moduleUrl, isAsset) {
216
+ if (/[?&]url(?:&|$)/.test(moduleUrl)) return true;
217
+ return isAsset && !/[?&](?:raw|inline)(?:&|$)/.test(moduleUrl);
218
+ }
219
+ /**
220
+ * Whether an asset module's code exports `url` as a JS string, possibly with a
221
+ * query or fragment, as Vite's asset plugin emits it.
222
+ */
223
+ function containsAssetUrl(code, url) {
224
+ return [
225
+ `"${url}"`,
226
+ `"${url}?`,
227
+ `"${url}#`
228
+ ].some((literal) => code.includes(literal));
229
+ }
230
+ /**
231
+ * The file `viteServeStaticMiddleware` serves for a decoded pathname, applying
232
+ * `resolve.alias` the same way it does, so the file checked is the file served.
233
+ *
234
+ * @param server - The Vite dev server
235
+ * @param pathname - The decoded request pathname, with any `base` stripped
236
+ * @returns The absolute file path
237
+ */
238
+ function resolveStaticFile(server, pathname) {
239
+ const root = server.config.root;
240
+ for (const { find, replacement } of server.config.resolve.alias) if (typeof find === "string" ? pathname.startsWith(find) : find.test(pathname)) {
241
+ const redirected = pathname.replace(find, replacement);
242
+ return path.join(root, redirected.startsWith(root + "/") ? redirected.slice(root.length) : redirected);
243
+ }
244
+ return path.join(root, pathname);
245
+ }
246
+ /**
247
+ * Whether stylesheet code contains `url` as a resolved `url()` or `image-set()`
248
+ * reference, the only places Vite rewrites asset URLs in CSS. The code may be
249
+ * the CSS itself or a JS string of it, and the URL may be quoted and may keep a
250
+ * query or fragment from the source.
251
+ *
252
+ * @param code - Transformed stylesheet code
253
+ * @param url - The URL path to look for
254
+ * @returns `true` if the URL appears as a CSS URL
255
+ */
256
+ function containsCssUrl(code, url) {
257
+ for (let index = code.indexOf(url); index !== -1; index = code.indexOf(url, index + 1)) {
258
+ const after = code[index + url.length];
259
+ if (after === void 0 || !/[)"',?#\\\s]/.test(after)) continue;
260
+ const start = Math.max(0, index - 32);
261
+ const before = code.slice(start, index);
262
+ const urlFunction = /(^|[^\w\-\u0080-\uffff])url\(\s*\\?["']?$/.exec(before);
263
+ if (urlFunction && (urlFunction[1] !== "" || start === 0)) return true;
264
+ if (!/["']$/.test(before)) continue;
265
+ const imageSet = code.lastIndexOf("image-set(", index);
266
+ if (imageSet !== -1 && !/[;{}]/.test(code.slice(imageSet, index))) return true;
267
+ }
268
+ return false;
269
+ }
270
+ //#endregion
271
+ export { VITE_MODULE_MIDDLEWARE_NAMES, VITE_STATIC_MIDDLEWARE_NAME, createCloudflareDevModuleUrlsPlugin };
@@ -1,4 +1,4 @@
1
- import { parseAst } from "vite";
1
+ import { parseProgram } from "./ast-utils.js";
2
2
  import MagicString from "magic-string";
3
3
  //#region src/plugins/commonjs-esm-facade.ts
4
4
  const EXPORT_FACADE_START = "/* [vite-plugin-commonjs] export-statement-S */";
@@ -9,7 +9,7 @@ function hasEsmExports(code) {
9
9
  if (!EXPORT_KEYWORD_RE.test(code)) return false;
10
10
  let ast;
11
11
  try {
12
- ast = parseAst(code);
12
+ ast = parseProgram(code);
13
13
  } catch {
14
14
  return false;
15
15
  }
@@ -1,32 +1,25 @@
1
- import { SCRIPT_MODULE_ID_RE, scriptParserLanguage } from "./ast-utils.js";
1
+ import { LEADING_TRIVIA_RE, SCRIPT_MODULE_ID_RE, hasImportAttributes, parseModuleRecord, scriptParserLanguage } from "./ast-utils.js";
2
2
  import { magicStringTransformResult } from "./transform-result.js";
3
- import { parseAst } from "vite";
4
3
  import MagicString from "magic-string";
5
4
  //#region src/plugins/css-module-imports.ts
6
5
  const CSS_MODULE_RE = /\.module\.(?:css|scss|sass)$/i;
7
6
  const CSS_MODULE_HINT_RE = /\.module\.(?:css|scss|sass)/i;
8
7
  const MDX_RE = /\.mdx$/i;
9
8
  function rewriteCssModuleNamespaceImports(code, lang = "js") {
10
- let ast;
11
- try {
12
- ast = parseAst(code, { lang });
13
- } catch {
14
- return null;
15
- }
9
+ const record = parseModuleRecord(code, lang);
10
+ if (!record) return null;
16
11
  let output = null;
17
- for (const statement of ast.body) {
18
- if (statement.type !== "ImportDeclaration") continue;
19
- if (statement.importKind === "type") continue;
20
- if (typeof statement.source?.value !== "string") continue;
21
- if (!CSS_MODULE_RE.test(statement.source.value)) continue;
22
- if (statement.attributes && statement.attributes.length > 0) continue;
23
- if (statement.specifiers?.length !== 1) continue;
24
- const specifier = statement.specifiers[0];
25
- if (specifier.type !== "ImportNamespaceSpecifier") continue;
26
- if (typeof specifier.start !== "number" || typeof specifier.end !== "number") continue;
27
- if (typeof specifier.local?.name !== "string") continue;
12
+ for (const statement of record.staticImports) {
13
+ if (!CSS_MODULE_RE.test(statement.moduleRequest.value)) continue;
14
+ if (hasImportAttributes(code, statement.moduleRequest.end, statement.end)) continue;
15
+ if (statement.entries.length !== 1) continue;
16
+ const [entry] = statement.entries;
17
+ if (entry.isType || entry.importName.kind !== "NamespaceObject") continue;
18
+ const afterImport = statement.start + 6;
19
+ const starIndex = afterImport + (LEADING_TRIVIA_RE.exec(code.slice(afterImport, entry.localName.start))?.[0].length ?? 0);
20
+ if (code[starIndex] !== "*") continue;
28
21
  output ??= new MagicString(code);
29
- output.overwrite(specifier.start, specifier.end, specifier.local.name);
22
+ output.overwrite(starIndex, entry.localName.end, entry.localName.value);
30
23
  }
31
24
  if (!output) return null;
32
25
  return magicStringTransformResult(output, { hires: true });
@@ -1,11 +1,10 @@
1
1
  import path, { toSlash } from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
2
- import { collectBindingNames, forEachAstChild, stringLiteralValue, walkAst } from "./ast-utils.js";
2
+ import { collectBindingNames, forEachAstChild, parseProgram, stringLiteralValue, walkAst } from "./ast-utils.js";
3
3
  import { hasTrailingComma } from "../utils/has-trailing-comma.js";
4
4
  import { magicStringTransformResult } from "./transform-result.js";
5
5
  import { stripViteModuleQuery } from "../utils/path.js";
6
6
  import { isForeignNodeModule } from "../utils/package-name.js";
7
7
  import { relativeToRoot, relativeWithinRoot, tryRealpathSync } from "../build/ssr-manifest.js";
8
- import { parseAst } from "vite";
9
8
  import MagicString from "magic-string";
10
9
  //#region src/plugins/dynamic-preload-metadata.ts
11
10
  function isNextDynamicSource(source) {
@@ -239,7 +238,7 @@ async function transformNextDynamicPreloadMetadata(code, id, root, resolveDynami
239
238
  if (!code.includes("next/dynamic")) return null;
240
239
  let ast;
241
240
  try {
242
- ast = parseAst(code);
241
+ ast = parseProgram(code);
243
242
  } catch (error) {
244
243
  if (typeof process !== "undefined" && process.env?.DEBUG?.includes("vinext")) console.debug(`[vinext] dynamic-preload-metadata: failed to parse ${id}:`, error);
245
244
  return null;
@@ -1,13 +1,12 @@
1
1
  import path, { toSlash } from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
2
2
  import { escapeRegExp } from "../utils/regex.js";
3
- import { DYNAMIC_IMPORT_PRESCAN, SCRIPT_MODULE_ID_RE, scriptParserLanguage, walkAst } from "./ast-utils.js";
3
+ import { DYNAMIC_IMPORT_PRESCAN, SCRIPT_MODULE_ID_RE, parseProgram, scriptParserLanguage, walkAst } from "./ast-utils.js";
4
4
  import { isUnknownRecord } from "../utils/record.js";
5
5
  import { magicStringTransformResult } from "./transform-result.js";
6
6
  import { NODE_MODULES_PATH_RE } from "../utils/path.js";
7
7
  import { createTransformCache } from "./transform-cache.js";
8
8
  import { createRequire } from "node:module";
9
9
  import fs from "node:fs";
10
- import { parseAst } from "vite";
11
10
  import MagicString from "magic-string";
12
11
  //#region src/plugins/extensionless-dynamic-import.ts
13
12
  const MODULE_EXTENSIONS = [
@@ -63,7 +62,7 @@ function transformExtensionlessImports(code, id, config) {
63
62
  const lang = scriptParserLanguage(id);
64
63
  let ast;
65
64
  try {
66
- ast = parseAst(code, { lang });
65
+ ast = parseProgram(code, { lang });
67
66
  } catch {
68
67
  return null;
69
68
  }
@@ -31,7 +31,7 @@ export declare const RESOLVED_VIRTUAL_GOOGLE_FONTS: string;
31
31
  export declare function _rewriteCachedFontCssToServedUrls(css: string, assetsDir?: string): string;
32
32
  /**
33
33
  * Safely parse a static JS object literal string into a plain object.
34
- * Uses Vite's parseAst (Rollup/acorn) so no code is ever evaluated.
34
+ * Uses Vite's bundled oxc parser so no code is ever evaluated.
35
35
  * Returns null if the expression contains anything dynamic (function calls,
36
36
  * template literals, identifiers, computed properties, etc.).
37
37
  *
@@ -1,5 +1,6 @@
1
1
  import path, { toSlash } from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
2
2
  import { escapeRegExp } from "../utils/regex.js";
3
+ import { parseProgram } from "./ast-utils.js";
3
4
  import { lastSignificantChar } from "../utils/has-trailing-comma.js";
4
5
  import { magicStringTransformResult } from "./transform-result.js";
5
6
  import { buildFallbackFontFace, getFallbackFontOverrideMetrics } from "../build/google-fonts/fallback-metrics.js";
@@ -10,7 +11,6 @@ import { findFontFilesInCss } from "../build/google-fonts/find-font-files-in-css
10
11
  import { ASSET_PREFIX_URL_DIR } from "../utils/asset-prefix.js";
11
12
  import { CONTENT_TYPES } from "../server/static-file-cache.js";
12
13
  import fs from "node:fs";
13
- import { parseAst } from "vite";
14
14
  import MagicString from "magic-string";
15
15
  //#region src/plugins/fonts.ts
16
16
  /**
@@ -127,7 +127,7 @@ function _rewriteCachedFontCssToServedUrls(css, assetsDir = DEFAULT_ASSETS_DIR)
127
127
  const DEFAULT_ASSETS_DIR = ASSET_PREFIX_URL_DIR;
128
128
  /**
129
129
  * Safely parse a static JS object literal string into a plain object.
130
- * Uses Vite's parseAst (Rollup/acorn) so no code is ever evaluated.
130
+ * Uses Vite's bundled oxc parser so no code is ever evaluated.
131
131
  * Returns null if the expression contains anything dynamic (function calls,
132
132
  * template literals, identifiers, computed properties, etc.).
133
133
  *
@@ -137,7 +137,7 @@ const DEFAULT_ASSETS_DIR = ASSET_PREFIX_URL_DIR;
137
137
  function parseStaticObjectLiteral(objectStr) {
138
138
  let ast;
139
139
  try {
140
- ast = parseAst(`(${objectStr})`);
140
+ ast = parseProgram(`(${objectStr})`);
141
141
  } catch {
142
142
  return null;
143
143
  }
@@ -1,12 +1,11 @@
1
1
  import path from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
2
- import { DYNAMIC_IMPORT_PRESCAN, SCRIPT_MODULE_ID_RE, collectBindingNames, forEachAstChild, isIdentifierNamed, mayContainDynamicImport, scriptParserLanguage, stringLiteralValue, unwrapExpression } from "./ast-utils.js";
2
+ import { DYNAMIC_IMPORT_PRESCAN, SCRIPT_MODULE_ID_RE, collectBindingNames, forEachAstChild, isIdentifierNamed, mayContainDynamicImport, parseProgram, scriptParserLanguage, stringLiteralValue, unwrapExpression } from "./ast-utils.js";
3
3
  import { magicStringTransformResult, omitUnusedBuildSourcemap } from "./transform-result.js";
4
4
  import { stripViteModuleQuery } from "../utils/path.js";
5
5
  import { isForeignNodeModule } from "../utils/package-name.js";
6
6
  import { collectDirectScopeBindings, collectLoopScopeBindings, collectSwitchScopeBindings, collectVarScopeBindings, hasAstBinding, isFunctionNode } from "./ast-scope.js";
7
7
  import { createTransformCache } from "./transform-cache.js";
8
8
  import { fileURLToPath } from "node:url";
9
- import { parseAst } from "vite";
10
9
  import MagicString from "magic-string";
11
10
  //#region src/plugins/ignore-dynamic-requests.ts
12
11
  const DYNAMIC_REQUEST_ERROR = "Cannot find module as expression is too dynamic";
@@ -411,7 +410,7 @@ function transformVeryDynamicRequests(code, id) {
411
410
  const lang = scriptParserLanguage(id) ?? "js";
412
411
  let ast;
413
412
  try {
414
- ast = parseAst(code, { lang });
413
+ ast = parseProgram(code, { lang });
415
414
  } catch {
416
415
  return null;
417
416
  }
@@ -1,11 +1,10 @@
1
1
  import path, { toSlash } from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
2
- import { SCRIPT_MODULE_ID_RE, collectBindingNames, forEachAstChild, isIdentifierNamed, scriptParserLanguage } from "./ast-utils.js";
2
+ import { SCRIPT_MODULE_ID_RE, collectBindingNames, forEachAstChild, isIdentifierNamed, parseProgram, scriptParserLanguage } from "./ast-utils.js";
3
3
  import { magicStringTransformResult, omitUnusedBuildSourcemap } from "./transform-result.js";
4
4
  import { canonicalizeFilePath, isPathInsideOrEqual, stripViteModuleQuery } from "../utils/path.js";
5
5
  import { VIRTUAL_MODULE_ID_RE } from "../utils/virtual-module.js";
6
6
  import fs from "node:fs";
7
7
  import { fileURLToPath, pathToFileURL } from "node:url";
8
- import { parseAst } from "vite";
9
8
  import { randomUUID } from "node:crypto";
10
9
  import MagicString from "magic-string";
11
10
  //#region src/plugins/import-meta-url.ts
@@ -254,14 +253,14 @@ function finalizeEmittedModuleIdentity(code, emittedIdentitySentinels, fileName)
254
253
  function rewriteModuleIdentity(code, options) {
255
254
  let ast;
256
255
  try {
257
- ast = parseAst(code, {
256
+ ast = parseProgram(code, {
258
257
  lang: scriptParserLanguage(options.id) ?? "jsx",
259
258
  sourceType: options.cjsGlobalInitializers ? "commonjs" : void 0
260
259
  });
261
260
  } catch {
262
261
  if (!options.cjsGlobalInitializers) return null;
263
262
  try {
264
- ast = parseAst(code, { lang: scriptParserLanguage(options.id) ?? "jsx" });
263
+ ast = parseProgram(code, { lang: scriptParserLanguage(options.id) ?? "jsx" });
265
264
  } catch {
266
265
  return null;
267
266
  }
@@ -1,10 +1,11 @@
1
+ import { parseProgram } from "./ast-utils.js";
1
2
  import { magicStringTransformResult } from "./transform-result.js";
2
3
  import { stripViteModuleQuery } from "../utils/path.js";
3
- import { normalizePath, parseAst } from "vite";
4
+ import { normalizePath } from "vite";
4
5
  import MagicString from "magic-string";
5
6
  //#region src/plugins/instrumentation-client.ts
6
7
  function insertionPositionAfterDirectives(code) {
7
- const ast = parseAst(code);
8
+ const ast = parseProgram(code);
8
9
  let insertPos = 0;
9
10
  for (const node of ast.body) {
10
11
  if (node.type !== "ExpressionStatement" || node.directive === void 0) break;
@@ -1,9 +1,8 @@
1
- import { getAstName, scriptParserLanguage } from "./ast-utils.js";
1
+ import { getAstName, parseProgram, scriptParserLanguage } from "./ast-utils.js";
2
2
  import { createMiddlewareMissingExportError } from "../server/middleware-runtime.js";
3
- import { parseAst } from "vite";
4
3
  //#region src/plugins/middleware-export-validation.ts
5
4
  function hasValidMiddlewareModuleExport(source, id, isProxy) {
6
- const ast = parseAst(source, { lang: scriptParserLanguage(id) ?? "jsx" });
5
+ const ast = parseProgram(source, { lang: scriptParserLanguage(id) ?? "jsx" });
7
6
  const expectedExport = isProxy ? "proxy" : "middleware";
8
7
  for (const statement of ast.body) {
9
8
  if (statement.type === "ExportDefaultDeclaration") return true;
@@ -1,11 +1,10 @@
1
1
  import path, { toSlash } from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
2
- import { forEachAstChild, getAstName, staticStringValue } from "./ast-utils.js";
2
+ import { forEachAstChild, getAstName, parseProgram, staticStringValue } from "./ast-utils.js";
3
3
  import { magicStringTransformResult, omitUnusedBuildSourcemap } from "./transform-result.js";
4
4
  import { isFunctionNode } from "./ast-scope.js";
5
5
  import { createTransformCache } from "./transform-cache.js";
6
6
  import { createRequire } from "node:module";
7
7
  import fs from "node:fs";
8
- import { parseAst } from "vite";
9
8
  import MagicString from "magic-string";
10
9
  //#region src/plugins/og-harfbuzz.ts
11
10
  /**
@@ -220,7 +219,7 @@ function patchHarfbuzzBundle(code, id, isBuild, callbackModuleDir, error) {
220
219
  const ogEntry = toSlash(id.split("?", 1)[0]);
221
220
  const isWorkerd = ogEntry.endsWith("/index.edge.js");
222
221
  const fail = (reason) => error(`[vinext] Unsupported @vercel/og HarfBuzz bundle in ${ogEntry}: ${reason}. vinext must be updated to support this @vercel/og version.`);
223
- const sites = findHarfbuzzPatchSites(parseAst(code, { lang: "js" }));
222
+ const sites = findHarfbuzzPatchSites(parseProgram(code, { lang: "js" }));
224
223
  if (typeof sites === "string") return fail(sites);
225
224
  const output = new MagicString(code);
226
225
  for (const flag of sites.environmentFlags) output.overwrite(flag.start, flag.end, "false");
@@ -5,16 +5,39 @@ type BarrelExportEntry = {
5
5
  source: string;
6
6
  isNamespace: boolean;
7
7
  originalName?: string;
8
+ /**
9
+ * The outermost module on the way to `source` that RSC replaces with
10
+ * references or wrappers because of its directive. RSC must import the name
11
+ * from it instead.
12
+ */
13
+ rscBoundary?: string;
14
+ /**
15
+ * The same for SSR, where only "use server" and "use cache" modules are
16
+ * replaced with references.
17
+ */
18
+ ssrBoundary?: string;
8
19
  };
9
20
  type BarrelExportMap = Map<string, BarrelExportEntry>;
10
21
  /**
11
22
  * Packages whose barrel imports are automatically optimized.
12
23
  * Matches Next.js's built-in optimizePackageImports defaults plus vinext-specific
13
- * compatibility entries for radix-ui and @chakra-ui/react.
24
+ * compatibility entries for radix-ui, @chakra-ui/react, and @heroui/react.
14
25
  * @see https://github.com/vercel/next.js/blob/9c31bbdaa/packages/next/src/server/config.ts#L1301
15
26
  */
16
27
  export declare const DEFAULT_OPTIMIZE_PACKAGES: string[];
17
- export declare function createOptimizedImportSourceMatcher(packages: Iterable<string>): (code: string) => boolean;
28
+ /**
29
+ * Packages whose subpath imports (`pkg/Sub`) are also optimized, in the RSC
30
+ * environment only. Their subpath entries are themselves barrels: heroui's
31
+ * Toast imports `UNSTABLE_ToastQueue` from "react-aria-components/Toast", whose
32
+ * other exports call createContext() at module scope and import "client-only"
33
+ * (https://github.com/cloudflare/vinext/issues/4007). Like Next.js's default
34
+ * Turbopack build, this drops the side-effect-free entry's "client-only"
35
+ * import: server-safe exports work, and client components still fail when
36
+ * their own modules are evaluated. SSR and the client keep the package's own
37
+ * module graph, so context modules are never instantiated twice there.
38
+ */
39
+ export declare const SUBPATH_OPTIMIZE_PACKAGES: string[];
40
+ export declare function createOptimizedImportSourceMatcher(packages: Iterable<string>, subpathPackages?: Iterable<string>): (code: string) => boolean;
18
41
  /**
19
42
  * Build a map of exported names → source sub-module for a barrel package.
20
43
  *