vinext 1.0.0-beta.8 → 1.0.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.
- package/README.md +158 -84
- package/THIRD_PARTY_LICENSES.md +25 -0
- package/dist/_virtual/_rolldown/runtime.js +25 -0
- package/dist/build/action-owner-manifest.d.ts +8 -9
- package/dist/build/action-owner-manifest.js +23 -5
- package/dist/build/assets-ignore.d.ts +3 -4
- package/dist/build/clean-output.d.ts +2 -3
- package/dist/build/client-build-config.d.ts +40 -12
- package/dist/build/client-build-config.js +76 -6
- package/dist/build/css-url-assets.d.ts +4 -5
- package/dist/build/css-url-assets.js +5 -2
- package/dist/build/google-fonts/build-url.d.ts +3 -4
- package/dist/build/google-fonts/fallback-metrics.d.ts +3 -4
- package/dist/build/google-fonts/find-font-files-in-css.d.ts +2 -3
- package/dist/build/google-fonts/font-metadata.d.ts +2 -3
- package/dist/build/google-fonts/get-axes.d.ts +2 -3
- package/dist/build/google-fonts/sort-variants.d.ts +2 -3
- package/dist/build/google-fonts/validate.d.ts +2 -3
- package/dist/build/google-fonts/validate.js +8 -4
- package/dist/build/inject-pregenerated-paths.d.ts +2 -3
- package/dist/build/inject-pregenerated-paths.js +16 -14
- package/dist/build/inline-css.d.ts +3 -4
- package/dist/build/layout-classification-types.d.ts +4 -5
- package/dist/build/layout-classification.d.ts +7 -8
- package/dist/build/lifecycle.d.ts +42 -0
- package/dist/build/lifecycle.js +253 -0
- package/dist/build/module-dependency-cache.d.ts +2 -3
- package/dist/build/next-client-runtime-manifests.d.ts +4 -5
- package/dist/build/nitro-route-rules.d.ts +6 -7
- package/dist/build/nitro-route-rules.js +1 -1
- package/dist/build/pages-client-assets-module.d.ts +4 -8
- package/dist/build/pages-client-assets-module.js +1 -13
- package/dist/build/precompress.d.ts +2 -3
- package/dist/build/prerender-cloudflare-loader.d.ts +4 -0
- package/dist/build/prerender-cloudflare-loader.js +49 -0
- package/dist/build/prerender-paths.d.ts +82 -8
- package/dist/build/prerender-paths.js +814 -99
- package/dist/build/prerender-phase.d.ts +2 -3
- package/dist/build/prerender-server-entry.js +11 -3
- package/dist/build/prerender-server-pool.d.ts +9 -6
- package/dist/build/prerender-server-pool.js +8 -5
- package/dist/build/prerender.d.ts +67 -15
- package/dist/build/prerender.js +177 -64
- package/dist/build/preview-credentials.d.ts +5 -6
- package/dist/build/preview-credentials.js +2 -2
- package/dist/build/public-dir-conflict.d.ts +5 -6
- package/dist/build/public-dir-conflict.js +2 -1
- package/dist/build/report.d.ts +38 -19
- package/dist/build/report.js +73 -4
- package/dist/build/route-classification-injector.d.ts +2 -3
- package/dist/build/route-classification-manifest.d.ts +5 -6
- package/dist/build/run-prerender.d.ts +11 -9
- package/dist/build/run-prerender.js +25 -16
- package/dist/build/server-entry.d.ts +4 -0
- package/dist/build/server-entry.js +28 -0
- package/dist/build/server-manifest.d.ts +8 -3
- package/dist/build/server-manifest.js +14 -2
- package/dist/build/ssr-manifest.d.ts +5 -6
- package/dist/build/standalone.d.ts +2 -3
- package/dist/build/standalone.js +2 -2
- package/dist/build/static-export.d.ts +7 -8
- package/dist/cache/cache-adapters-virtual.d.ts +95 -9
- package/dist/cache/cache-adapters-virtual.js +58 -6
- package/dist/check.d.ts +11 -10
- package/dist/check.js +467 -176
- package/dist/cli-args.d.ts +7 -16
- package/dist/cli-args.js +2 -45
- package/dist/cli-dev-config.d.ts +10 -7
- package/dist/cli-dev-config.js +160 -3
- package/dist/cli.js +124 -435
- package/dist/client/app-nav-failure-handler.d.ts +6 -7
- package/dist/client/client-rewrite-matcher.d.ts +2 -3
- package/dist/client/client-rewrites.d.ts +4 -5
- package/dist/client/dev-error-overlay-store.d.ts +13 -14
- package/dist/client/dev-error-overlay.d.ts +15 -15
- package/dist/client/dev-error-overlay.js +8 -5
- package/dist/client/instrumentation-client-inject.d.ts +3 -4
- package/dist/client/instrumentation-client-state.d.ts +5 -6
- package/dist/client/instrumentation-client.d.ts +3 -4
- package/dist/client/navigation-runtime.d.ts +21 -17
- package/dist/client/navigation-runtime.js +2 -1
- package/dist/client/pages-router-link-navigation.d.ts +4 -5
- package/dist/client/react-instance.d.ts +2 -3
- package/dist/client/validate-module-path.d.ts +2 -3
- package/dist/client/vinext-next-data.d.ts +7 -8
- package/dist/client/window-next.d.ts +4 -5
- package/dist/config/config-matchers.d.ts +16 -16
- package/dist/config/config-matchers.js +10 -7
- package/dist/config/dotenv.d.ts +3 -4
- package/dist/config/dotenv.js +2 -1
- package/dist/config/next-config.d.ts +31 -27
- package/dist/config/next-config.js +163 -16
- package/dist/config/prerender.d.ts +20 -16
- package/dist/config/prerender.js +10 -4
- package/dist/config/request-context.d.ts +5 -6
- package/dist/config/server-external-packages.d.ts +14 -3
- package/dist/config/server-external-packages.js +37 -3
- package/dist/config/tsconfig-paths.d.ts +3 -4
- package/dist/deps/.pnpm/ignore@5.3.2/deps/ignore/index.js +189 -0
- package/dist/deps/.pnpm/ua-parser-js@1.0.35/deps/ua-parser-js/src/ua-parser.js +1057 -0
- package/dist/entries/app-browser-entry.d.ts +5 -6
- package/dist/entries/app-browser-entry.js +3 -2
- package/dist/entries/app-rsc-entry.d.ts +12 -3
- package/dist/entries/app-rsc-entry.js +530 -55
- package/dist/entries/app-rsc-manifest.d.ts +4 -3
- package/dist/entries/app-rsc-manifest.js +27 -8
- package/dist/entries/app-ssr-entry.d.ts +2 -3
- package/dist/entries/app-ssr-entry.js +8 -1
- package/dist/entries/pages-client-entry.d.ts +3 -3
- package/dist/entries/pages-client-entry.js +17 -2
- package/dist/entries/pages-server-entry.d.ts +13 -3
- package/dist/entries/pages-server-entry.js +237 -33
- package/dist/entries/runtime-entry-module.d.ts +4 -5
- package/dist/image/image-adapters-virtual.d.ts +4 -5
- package/dist/index.d.ts +10 -11
- package/dist/index.js +832 -199
- package/dist/init-cloudflare.d.ts +27 -16
- package/dist/init-cloudflare.js +754 -113
- package/dist/init-platform.d.ts +26 -22
- package/dist/init-platform.js +85 -29
- package/dist/init.d.ts +19 -13
- package/dist/init.js +123 -41
- package/dist/plugins/action-owner-manifest.d.ts +3 -4
- package/dist/plugins/action-owner-manifest.js +10 -3
- package/dist/plugins/ast-scope.d.ts +10 -11
- package/dist/plugins/ast-scope.js +10 -22
- package/dist/plugins/ast-utils.d.ts +16 -29
- package/dist/plugins/ast-utils.js +27 -71
- package/dist/plugins/async-hooks-stub.d.ts +2 -3
- package/dist/plugins/client-reference-dedup.d.ts +4 -5
- package/dist/plugins/css-data-url.d.ts +2 -3
- package/dist/plugins/css-module-imports.d.ts +3 -4
- package/dist/plugins/css-module-imports.js +1 -1
- package/dist/plugins/dynamic-preload-metadata.d.ts +3 -4
- package/dist/plugins/dynamic-preload-metadata.js +55 -154
- package/dist/plugins/environment.d.ts +2 -3
- package/dist/plugins/extensionless-dynamic-import.d.ts +2 -3
- package/dist/plugins/extensionless-dynamic-import.js +6 -10
- package/dist/plugins/fonts.d.ts +10 -11
- package/dist/plugins/fonts.js +4 -3
- package/dist/plugins/ignore-dynamic-requests.d.ts +3 -4
- package/dist/plugins/ignore-dynamic-requests.js +60 -89
- package/dist/plugins/import-meta-url.d.ts +6 -7
- package/dist/plugins/import-meta-url.js +31 -43
- package/dist/plugins/instrumentation-client.d.ts +3 -3
- package/dist/plugins/instrumentation-client.js +46 -10
- package/dist/plugins/middleware-export-validation.d.ts +3 -4
- package/dist/plugins/middleware-export-validation.js +3 -3
- package/dist/plugins/middleware-server-only.d.ts +2 -3
- package/dist/plugins/og-asset-ownership.d.ts +3 -4
- package/dist/plugins/og-assets.d.ts +4 -5
- package/dist/plugins/og-assets.js +32 -13
- package/dist/plugins/og-harfbuzz.d.ts +24 -0
- package/dist/plugins/og-harfbuzz.js +260 -0
- package/dist/plugins/optimize-imports.d.ts +7 -7
- package/dist/plugins/optimize-imports.js +32 -44
- package/dist/plugins/pages-node-externals.d.ts +2 -3
- package/dist/plugins/pages-node-externals.js +6 -11
- package/dist/plugins/postcss.d.ts +8 -4
- package/dist/plugins/postcss.js +1 -1
- package/dist/plugins/remove-console.d.ts +2 -3
- package/dist/plugins/remove-console.js +0 -1
- package/dist/plugins/require-condition-resolution.d.ts +3 -4
- package/dist/plugins/require-condition-resolution.js +17 -18
- package/dist/plugins/require-context.d.ts +2 -3
- package/dist/plugins/require-context.js +13 -21
- package/dist/plugins/rsc-client-reference-loaders.d.ts +2 -3
- package/dist/plugins/rsc-client-shim-excludes.d.ts +4 -5
- package/dist/plugins/rsc-client-shim-excludes.js +1 -0
- package/dist/plugins/rsc-reference-validation-normalizer.d.ts +2 -3
- package/dist/plugins/sass.d.ts +7 -8
- package/dist/plugins/sass.js +7 -4
- package/dist/plugins/server-externals-manifest.d.ts +2 -3
- package/dist/plugins/strip-server-exports.d.ts +5 -6
- package/dist/plugins/strip-server-exports.js +1 -1
- package/dist/plugins/styled-jsx.d.ts +2 -3
- package/dist/plugins/styled-jsx.js +7 -7
- package/dist/plugins/transform-cache.d.ts +2 -3
- package/dist/plugins/transform-result.d.ts +3 -4
- package/dist/plugins/transitive-externals.d.ts +2 -3
- package/dist/plugins/typeof-window.d.ts +6 -7
- package/dist/plugins/typeof-window.js +30 -31
- package/dist/plugins/use-cache-callable.d.ts +2 -5
- package/dist/plugins/use-cache-callable.js +43 -22
- package/dist/plugins/wasm-module-import.d.ts +2 -3
- package/dist/plugins/worker-image-imports.d.ts +2 -3
- package/dist/plugins/worker-image-imports.js +6 -8
- package/dist/routing/app-route-graph.d.ts +19 -19
- package/dist/routing/app-route-graph.js +3 -2
- package/dist/routing/app-router.d.ts +20 -5
- package/dist/routing/app-router.js +28 -2
- package/dist/routing/file-matcher.d.ts +9 -10
- package/dist/routing/pages-router.d.ts +6 -6
- package/dist/routing/pages-router.js +1 -1
- package/dist/routing/route-matching.d.ts +4 -5
- package/dist/routing/route-matching.js +4 -2
- package/dist/routing/route-pattern.d.ts +13 -14
- package/dist/routing/route-trie.d.ts +5 -6
- package/dist/routing/route-validation.d.ts +3 -4
- package/dist/routing/route-validation.js +12 -11
- package/dist/routing/utils.d.ts +13 -14
- package/dist/server/accept-encoding.d.ts +9 -10
- package/dist/server/api-handler.d.ts +2 -3
- package/dist/server/api-handler.js +9 -6
- package/dist/server/app-action-forwarding.d.ts +3 -4
- package/dist/server/app-action-forwarding.js +1 -1
- package/dist/server/app-action-request.d.ts +2 -3
- package/dist/server/app-bfcache-id.d.ts +3 -4
- package/dist/server/app-bfcache-identity.d.ts +8 -9
- package/dist/server/app-browser-action-result.d.ts +15 -16
- package/dist/server/app-browser-client-reuse-manifest.d.ts +2 -3
- package/dist/server/app-browser-entry.js +121 -40
- package/dist/server/app-browser-error.d.ts +5 -6
- package/dist/server/app-browser-error.js +9 -3
- package/dist/server/app-browser-history-controller.d.ts +4 -5
- package/dist/server/app-browser-hydration.d.ts +16 -6
- package/dist/server/app-browser-hydration.js +14 -1
- package/dist/server/app-browser-interception-context.d.ts +3 -4
- package/dist/server/app-browser-mpa-navigation.d.ts +4 -5
- package/dist/server/app-browser-navigation-abort.d.ts +3 -4
- package/dist/server/app-browser-navigation-controller.d.ts +8 -8
- package/dist/server/app-browser-navigation-controller.js +9 -5
- package/dist/server/app-browser-navigation-response.d.ts +2 -3
- package/dist/server/app-browser-popstate.d.ts +4 -5
- package/dist/server/app-browser-prefetch-response.d.ts +5 -6
- package/dist/server/app-browser-rsc-redirect.d.ts +4 -5
- package/dist/server/app-browser-server-action-client.d.ts +7 -6
- package/dist/server/app-browser-server-action-client.js +9 -5
- package/dist/server/app-browser-server-action-navigation.d.ts +2 -3
- package/dist/server/app-browser-state.d.ts +17 -17
- package/dist/server/app-browser-state.js +7 -3
- package/dist/server/app-browser-stream.d.ts +4 -5
- package/dist/server/app-browser-stream.js +8 -6
- package/dist/server/app-browser-supplemental-refresh.d.ts +11 -12
- package/dist/server/app-browser-visible-commit.d.ts +6 -7
- package/dist/server/app-browser-visible-commit.js +1 -1
- package/dist/server/app-client-reference-preloader.d.ts +2 -3
- package/dist/server/app-elements-wire-key.d.ts +25 -0
- package/dist/server/app-elements-wire-key.js +69 -0
- package/dist/server/app-elements-wire.d.ts +34 -53
- package/dist/server/app-elements-wire.js +4 -75
- package/dist/server/app-elements.d.ts +5 -5
- package/dist/server/app-elements.js +1 -1
- package/dist/server/app-fallback-renderer.d.ts +4 -4
- package/dist/server/app-fallback-renderer.js +6 -6
- package/dist/server/app-fetch-tracing.d.ts +15 -0
- package/dist/server/app-fetch-tracing.js +38 -0
- package/dist/server/app-history-state.d.ts +26 -27
- package/dist/server/app-history-state.js +19 -11
- package/dist/server/app-hook-warning-suppression.d.ts +2 -3
- package/dist/server/app-hydration-cache-publication.d.ts +3 -4
- package/dist/server/app-inline-css-client.d.ts +3 -4
- package/dist/server/app-interception-context-header.d.ts +2 -3
- package/dist/server/app-layout-param-observation.d.ts +7 -8
- package/dist/server/app-metadata-tracing.d.ts +12 -0
- package/dist/server/app-metadata-tracing.js +17 -0
- package/dist/server/app-middleware.d.ts +15 -7
- package/dist/server/app-middleware.js +30 -5
- package/dist/server/app-mounted-slots-header.d.ts +2 -3
- package/dist/server/app-mounted-slots-header.js +2 -2
- package/dist/server/app-optimistic-routing.d.ts +14 -10
- package/dist/server/app-optimistic-routing.js +16 -3
- package/dist/server/app-page-boundary-render.d.ts +6 -6
- package/dist/server/app-page-boundary-render.js +10 -4
- package/dist/server/app-page-boundary.d.ts +9 -10
- package/dist/server/app-page-boundary.js +2 -1
- package/dist/server/app-page-cache-finalizer.d.ts +32 -8
- package/dist/server/app-page-cache-finalizer.js +118 -14
- package/dist/server/app-page-cache-render.d.ts +8 -5
- package/dist/server/app-page-cache-render.js +22 -5
- package/dist/server/app-page-cache.d.ts +28 -9
- package/dist/server/app-page-cache.js +96 -25
- package/dist/server/app-page-dispatch.d.ts +36 -12
- package/dist/server/app-page-dispatch.js +188 -63
- package/dist/server/app-page-element-builder.d.ts +13 -11
- package/dist/server/app-page-element-builder.js +104 -61
- package/dist/server/app-page-execution.d.ts +14 -14
- package/dist/server/app-page-execution.js +12 -8
- package/dist/server/app-page-head.d.ts +19 -16
- package/dist/server/app-page-head.js +25 -25
- package/dist/server/app-page-http-access-fallback-metadata.d.ts +6 -5
- package/dist/server/app-page-http-access-fallback-metadata.js +9 -2
- package/dist/server/app-page-method.d.ts +5 -11
- package/dist/server/app-page-method.js +2 -9
- package/dist/server/app-page-params.d.ts +5 -6
- package/dist/server/app-page-ppr-runtime.d.ts +2 -2
- package/dist/server/app-page-probe.d.ts +5 -6
- package/dist/server/app-page-probe.js +5 -4
- package/dist/server/app-page-render-identity.d.ts +4 -5
- package/dist/server/app-page-render-observation.d.ts +8 -9
- package/dist/server/app-page-render-observation.js +1 -1
- package/dist/server/app-page-render.d.ts +42 -6
- package/dist/server/app-page-render.js +192 -28
- package/dist/server/app-page-request.d.ts +10 -9
- package/dist/server/app-page-request.js +16 -12
- package/dist/server/app-page-response.d.ts +20 -9
- package/dist/server/app-page-response.js +31 -13
- package/dist/server/app-page-route-wiring.d.ts +15 -15
- package/dist/server/app-page-route-wiring.js +31 -24
- package/dist/server/app-page-search-params-observation.d.ts +26 -5
- package/dist/server/app-page-search-params-observation.js +42 -6
- package/dist/server/app-page-segment-plan.d.ts +2 -3
- package/dist/server/app-page-segment-state.d.ts +11 -12
- package/dist/server/app-page-stream.d.ts +27 -11
- package/dist/server/app-page-stream.js +35 -6
- package/dist/server/app-page-tracing.d.ts +33 -0
- package/dist/server/app-page-tracing.js +49 -0
- package/dist/server/app-pages-bridge.d.ts +6 -6
- package/dist/server/app-pages-bridge.js +19 -4
- package/dist/server/app-post-middleware-context.d.ts +2 -3
- package/dist/server/app-ppr-fallback-shell-render.d.ts +3 -4
- package/dist/server/app-ppr-fallback-shell-render.js +3 -2
- package/dist/server/app-ppr-fallback-shell.d.ts +6 -7
- package/dist/server/app-prerender-endpoints.d.ts +5 -5
- package/dist/server/app-prerender-endpoints.js +26 -12
- package/dist/server/app-prerender-static-params.d.ts +15 -7
- package/dist/server/app-prerender-static-params.js +33 -11
- package/dist/server/app-render-dependency.d.ts +14 -13
- package/dist/server/app-render-dependency.js +5 -1
- package/dist/server/app-request-context.d.ts +3 -4
- package/dist/server/app-request-stage-context.d.ts +5 -0
- package/dist/server/app-request-stage-context.js +11 -0
- package/dist/server/app-request-stage-dispatch.d.ts +25 -0
- package/dist/server/app-request-stage-dispatch.js +54 -0
- package/dist/server/app-request-stage-independent-entry.d.ts +8 -0
- package/dist/server/app-request-stage-independent-entry.js +115 -0
- package/dist/server/app-response-header-provenance.d.ts +13 -7
- package/dist/server/app-response-header-provenance.js +34 -1
- package/dist/server/app-response-stage-entry.d.ts +9 -0
- package/dist/server/app-response-stage-entry.js +87 -0
- package/dist/server/app-route-handler-cache.d.ts +2 -3
- package/dist/server/app-route-handler-cache.js +46 -34
- package/dist/server/app-route-handler-dispatch.d.ts +3 -3
- package/dist/server/app-route-handler-dispatch.js +75 -57
- package/dist/server/app-route-handler-execution.d.ts +18 -13
- package/dist/server/app-route-handler-execution.js +189 -25
- package/dist/server/app-route-handler-middleware-context.d.ts +8 -0
- package/dist/server/app-route-handler-middleware-context.js +15 -0
- package/dist/server/app-route-handler-policy.d.ts +22 -10
- package/dist/server/app-route-handler-policy.js +19 -4
- package/dist/server/app-route-handler-response.d.ts +9 -10
- package/dist/server/app-route-handler-response.js +2 -0
- package/dist/server/app-route-handler-runtime.d.ts +9 -10
- package/dist/server/app-route-handler-runtime.js +20 -16
- package/dist/server/app-route-module-loader.d.ts +6 -7
- package/dist/server/app-route-request-built-ins.d.ts +3 -4
- package/dist/server/app-route-tree-prefetch.d.ts +6 -7
- package/dist/server/app-route-tree-prefetch.js +2 -1
- package/dist/server/app-router-entry.d.ts +2 -0
- package/dist/server/app-router-entry.js +76 -12
- package/dist/server/app-rsc-cache-busting.d.ts +47 -22
- package/dist/server/app-rsc-cache-busting.js +80 -18
- package/dist/server/app-rsc-combined-handler.d.ts +9 -0
- package/dist/server/app-rsc-combined-handler.js +11 -0
- package/dist/server/app-rsc-embedded-chunks.d.ts +6 -7
- package/dist/server/app-rsc-error-handler.d.ts +12 -6
- package/dist/server/app-rsc-error-handler.js +15 -6
- package/dist/server/app-rsc-errors.d.ts +12 -9
- package/dist/server/app-rsc-errors.js +15 -13
- package/dist/server/app-rsc-handler.d.ts +33 -6
- package/dist/server/app-rsc-handler.js +498 -83
- package/dist/server/app-rsc-redirect-flight.d.ts +4 -5
- package/dist/server/app-rsc-render-mode.d.ts +8 -9
- package/dist/server/app-rsc-request-normalization.d.ts +3 -3
- package/dist/server/app-rsc-request-normalization.js +2 -1
- package/dist/server/app-rsc-response-finalizer.d.ts +8 -5
- package/dist/server/app-rsc-response-finalizer.js +24 -7
- package/dist/server/app-rsc-response-stage.d.ts +6 -0
- package/dist/server/app-rsc-response-stage.js +251 -0
- package/dist/server/app-rsc-route-matching.d.ts +4 -4
- package/dist/server/app-rsc-route-matching.js +4 -2
- package/dist/server/app-rsc-state-fingerprint.d.ts +3 -4
- package/dist/server/app-rsc-vary.d.ts +16 -0
- package/dist/server/app-rsc-vary.js +31 -0
- package/dist/server/app-segment-config.d.ts +120 -6
- package/dist/server/app-segment-config.js +264 -12
- package/dist/server/app-server-action-execution.d.ts +16 -12
- package/dist/server/app-server-action-execution.js +88 -35
- package/dist/server/app-ssr-entry.d.ts +14 -4
- package/dist/server/app-ssr-entry.js +64 -17
- package/dist/server/app-ssr-error-meta.d.ts +3 -4
- package/dist/server/app-ssr-error-meta.js +2 -1
- package/dist/server/app-ssr-router-instance.d.ts +2 -3
- package/dist/server/app-ssr-search-params-gate.d.ts +20 -0
- package/dist/server/app-ssr-search-params-gate.js +54 -0
- package/dist/server/app-ssr-stream.d.ts +13 -9
- package/dist/server/app-ssr-stream.js +33 -7
- package/dist/server/app-static-generation.d.ts +4 -5
- package/dist/server/app-visited-response-cache.d.ts +11 -12
- package/dist/server/app-visited-response-cache.js +2 -2
- package/dist/server/app-worker-stages.d.ts +112 -0
- package/dist/server/app-worker-stages.js +105 -0
- package/dist/server/artifact-compatibility.d.ts +11 -12
- package/dist/server/before-interactive-head.d.ts +2 -3
- package/dist/server/bfcache-identity.d.ts +7 -8
- package/dist/server/cache-control.d.ts +39 -11
- package/dist/server/cache-control.js +104 -7
- package/dist/server/cache-headers.d.ts +3 -4
- package/dist/server/cache-proof.d.ts +75 -70
- package/dist/server/cache-proof.js +9 -1
- package/dist/server/cacheability-limits.d.ts +8 -0
- package/dist/server/cacheability-limits.js +9 -0
- package/dist/server/cacheability-manifest.d.ts +68 -0
- package/dist/server/cacheability-manifest.js +241 -0
- package/dist/server/cacheability-request.d.ts +49 -0
- package/dist/server/cacheability-request.js +559 -0
- package/dist/server/client-reuse-manifest.d.ts +17 -18
- package/dist/server/client-reuse-manifest.js +2 -2
- package/dist/server/client-trace-metadata.d.ts +9 -6
- package/dist/server/client-trace-metadata.js +27 -15
- package/dist/server/cloudflare-workers-tracing.d.ts +1 -0
- package/dist/server/cloudflare-workers-tracing.js +8 -0
- package/dist/server/config-headers.d.ts +19 -5
- package/dist/server/config-headers.js +39 -5
- package/dist/server/cookie-utils.d.ts +2 -3
- package/dist/server/csp.d.ts +5 -6
- package/dist/server/default-global-error-module.d.ts +2 -3
- package/dist/server/default-global-not-found-module.d.ts +2 -3
- package/dist/server/default-not-found-module.d.ts +2 -3
- package/dist/server/defer-until-stream-consumed.d.ts +2 -3
- package/dist/server/defer-until-stream-consumed.js +2 -1
- package/dist/server/dev-initial-server-error.d.ts +3 -4
- package/dist/server/dev-initial-server-error.js +2 -1
- package/dist/server/dev-lockfile.d.ts +7 -8
- package/dist/server/dev-lockfile.js +4 -1
- package/dist/server/dev-module-runner.d.ts +2 -3
- package/dist/server/dev-origin-check.d.ts +5 -6
- package/dist/server/dev-route-files.d.ts +2 -3
- package/dist/server/dev-server.d.ts +4 -5
- package/dist/server/dev-server.js +130 -61
- package/dist/server/dev-stack-sourcemap.d.ts +7 -7
- package/dist/server/dev-stack-sourcemap.js +1 -1
- package/dist/server/document-initial-head.d.ts +3 -4
- package/dist/server/edge-api-runtime.d.ts +4 -5
- package/dist/server/fetch-handler.d.ts +3 -2
- package/dist/server/fetch-handler.js +3 -18
- package/dist/server/file-based-metadata.d.ts +2 -3
- package/dist/server/framework-tracer.d.ts +46 -0
- package/dist/server/framework-tracer.js +125 -0
- package/dist/server/fully-buffered-response.d.ts +11 -0
- package/dist/server/fully-buffered-response.js +19 -0
- package/dist/server/headers.d.ts +62 -56
- package/dist/server/headers.js +33 -20
- package/dist/server/html.d.ts +6 -27
- package/dist/server/html.js +16 -1
- package/dist/server/http-conditional.d.ts +5 -6
- package/dist/server/http-date.d.ts +2 -3
- package/dist/server/http-error-responses.d.ts +9 -10
- package/dist/server/http-range.d.ts +4 -5
- package/dist/server/hybrid-route-priority.d.ts +4 -5
- package/dist/server/image-optimization.d.ts +20 -21
- package/dist/server/implicit-tags.d.ts +3 -4
- package/dist/server/instrumentation-runtime.d.ts +17 -21
- package/dist/server/instrumentation-runtime.js +26 -8
- package/dist/server/instrumentation.d.ts +26 -30
- package/dist/server/instrumentation.js +18 -23
- package/dist/server/isr-cache.d.ts +28 -27
- package/dist/server/isr-cache.js +18 -70
- package/dist/server/isr-decision.d.ts +4 -4
- package/dist/server/metadata-route-build-data.d.ts +4 -5
- package/dist/server/metadata-route-cache-policy.d.ts +2 -3
- package/dist/server/metadata-route-response.d.ts +7 -7
- package/dist/server/metadata-route-response.js +68 -2
- package/dist/server/metadata-routes.d.ts +18 -19
- package/dist/server/middleware-matcher-pattern.d.ts +6 -7
- package/dist/server/middleware-matcher.d.ts +13 -6
- package/dist/server/middleware-matcher.js +22 -1
- package/dist/server/middleware-path-to-regexp.d.ts +6 -7
- package/dist/server/middleware-path-to-regexp.js +11 -9
- package/dist/server/middleware-response-headers.d.ts +3 -4
- package/dist/server/middleware-runtime.d.ts +13 -8
- package/dist/server/middleware-runtime.js +54 -10
- package/dist/server/middleware.d.ts +5 -5
- package/dist/server/multi-stage.d.ts +141 -0
- package/dist/server/multi-stage.js +8 -0
- package/dist/server/navigation-planner.d.ts +26 -26
- package/dist/server/navigation-trace.d.ts +11 -12
- package/dist/server/next-error-digest.d.ts +4 -5
- package/dist/server/normalize-path.d.ts +5 -6
- package/dist/server/normalize-path.js +1 -1
- package/dist/server/open-redirect.d.ts +2 -3
- package/dist/server/opentelemetry-api.d.ts +59 -0
- package/dist/server/opentelemetry-api.js +53 -0
- package/dist/server/opentelemetry-tracing.d.ts +5 -0
- package/dist/server/opentelemetry-tracing.js +83 -0
- package/dist/server/operation-token.d.ts +11 -12
- package/dist/server/otel-tracer-extension.d.ts +7 -9
- package/dist/server/otel-tracer-extension.js +37 -36
- package/dist/server/pages-api-route.d.ts +5 -4
- package/dist/server/pages-api-route.js +21 -8
- package/dist/server/pages-asset-tags.d.ts +6 -6
- package/dist/server/pages-asset-tags.js +37 -2
- package/dist/server/pages-body-parser-config.d.ts +4 -5
- package/dist/server/pages-body-parser-config.js +4 -4
- package/dist/server/pages-client-assets.d.ts +11 -5
- package/dist/server/pages-data-route.d.ts +11 -12
- package/dist/server/pages-data-route.js +1 -1
- package/dist/server/pages-default-404.d.ts +3 -4
- package/dist/server/pages-dev-hydration.d.ts +9 -4
- package/dist/server/pages-dev-hydration.js +19 -7
- package/dist/server/pages-dev-module-url.d.ts +3 -4
- package/dist/server/pages-dev-stylesheets.d.ts +5 -6
- package/dist/server/pages-document-asset-props.d.ts +6 -7
- package/dist/server/pages-document-initial-props.d.ts +5 -5
- package/dist/server/pages-document-initial-props.js +4 -2
- package/dist/server/pages-execution-tracing.d.ts +40 -0
- package/dist/server/pages-execution-tracing.js +80 -0
- package/dist/server/pages-get-initial-props.d.ts +9 -10
- package/dist/server/pages-i18n.d.ts +8 -8
- package/dist/server/pages-i18n.js +3 -2
- package/dist/server/pages-media-type.d.ts +4 -5
- package/dist/server/pages-node-compat.d.ts +11 -10
- package/dist/server/pages-node-compat.js +12 -4
- package/dist/server/pages-page-data.d.ts +18 -19
- package/dist/server/pages-page-data.js +11 -10
- package/dist/server/pages-page-handler.d.ts +7 -6
- package/dist/server/pages-page-handler.js +98 -47
- package/dist/server/pages-page-method.d.ts +2 -3
- package/dist/server/pages-page-response.d.ts +14 -10
- package/dist/server/pages-page-response.js +49 -31
- package/dist/server/pages-preview.d.ts +10 -11
- package/dist/server/pages-readiness.d.ts +2 -3
- package/dist/server/pages-request-pipeline.d.ts +16 -12
- package/dist/server/pages-request-pipeline.js +69 -28
- package/dist/server/pages-request-stage-entry.d.ts +23 -0
- package/dist/server/pages-request-stage-entry.js +314 -0
- package/dist/server/pages-response-stage-entry.d.ts +11 -0
- package/dist/server/pages-response-stage-entry.js +106 -0
- package/dist/server/pages-response-stage.d.ts +31 -0
- package/dist/server/pages-response-stage.js +49 -0
- package/dist/server/pages-revalidate.d.ts +3 -4
- package/dist/server/pages-revalidate.js +9 -4
- package/dist/server/pages-route-data-kind.d.ts +18 -0
- package/dist/server/pages-route-data-kind.js +11 -0
- package/dist/server/pages-router-entry.d.ts +1 -25
- package/dist/server/pages-router-entry.js +48 -114
- package/dist/server/pages-serializable-props.d.ts +3 -4
- package/dist/server/pregenerated-concrete-paths.d.ts +9 -7
- package/dist/server/pregenerated-concrete-paths.js +12 -6
- package/dist/server/prerender-cache-life-header.d.ts +3 -4
- package/dist/server/prerender-manifest.d.ts +11 -11
- package/dist/server/prerender-manifest.js +6 -3
- package/dist/server/prerender-route-params.d.ts +16 -9
- package/dist/server/prerender-route-params.js +18 -2
- package/dist/server/prerender-work-unit-setup.d.ts +4 -4
- package/dist/server/prerender-work-unit-setup.js +37 -14
- package/dist/server/prod-server.d.ts +12 -9
- package/dist/server/prod-server.js +129 -36
- package/dist/server/proxy-trust.d.ts +5 -6
- package/dist/server/request-log.d.ts +3 -4
- package/dist/server/request-pipeline.d.ts +17 -21
- package/dist/server/request-pipeline.js +8 -10
- package/dist/server/request-stage.d.ts +5 -0
- package/dist/server/request-stage.js +7 -0
- package/dist/server/request-tracing.d.ts +22 -0
- package/dist/server/request-tracing.js +180 -0
- package/dist/server/response-stage-cacheability.d.ts +37 -0
- package/dist/server/response-stage-cacheability.js +55 -0
- package/dist/server/response-stage-policy.d.ts +23 -0
- package/dist/server/response-stage-policy.js +89 -0
- package/dist/server/response-stage.d.ts +5 -0
- package/dist/server/response-stage.js +7 -0
- package/dist/server/response-start-tracing.d.ts +14 -0
- package/dist/server/response-start-tracing.js +80 -0
- package/dist/server/revalidation-host.d.ts +2 -3
- package/dist/server/revalidation-host.js +2 -1
- package/dist/server/revalidation-request.d.ts +8 -0
- package/dist/server/revalidation-request.js +37 -0
- package/dist/server/rsc-completion-metadata.d.ts +6 -7
- package/dist/server/rsc-stream-hints.d.ts +18 -7
- package/dist/server/rsc-stream-hints.js +70 -35
- package/dist/server/seed-cache.d.ts +2 -3
- package/dist/server/seed-cache.js +8 -7
- package/dist/server/server-action-not-found.d.ts +5 -6
- package/dist/server/server-globals.d.ts +2 -3
- package/dist/server/server-globals.js +13 -0
- package/dist/server/skip-cache-proof.d.ts +4 -4
- package/dist/server/socket-error-backstop.d.ts +5 -6
- package/dist/server/socket-error-backstop.js +1 -1
- package/dist/server/static-file-cache.d.ts +5 -6
- package/dist/server/static-file-cache.js +9 -7
- package/dist/server/static-file-signal.d.ts +16 -0
- package/dist/server/static-file-signal.js +82 -0
- package/dist/server/static-layout-client-reuse-proof.d.ts +4 -5
- package/dist/server/streaming-metadata.d.ts +2 -3
- package/dist/server/tracer.d.ts +5 -0
- package/dist/server/tracer.js +13 -0
- package/dist/server/worker-prerender-discovery.d.ts +18 -0
- package/dist/server/worker-prerender-discovery.js +55 -0
- package/dist/server/worker-revalidation-context.d.ts +2 -3
- package/dist/server/worker-revalidation-context.js +5 -5
- package/dist/server/worker-stages.d.ts +43 -0
- package/dist/server/worker-stages.js +25 -0
- package/dist/server/worker-utils.d.ts +5 -6
- package/dist/server/worker-utils.js +4 -4
- package/dist/server/workers-tracing.d.ts +17 -0
- package/dist/server/workers-tracing.js +27 -0
- package/dist/shims/amp.d.ts +3 -4
- package/dist/shims/app-router-scroll-state.d.ts +9 -10
- package/dist/shims/app-router-scroll.d.ts +4 -5
- package/dist/shims/app-router-scroll.js +2 -1
- package/dist/shims/app.d.ts +5 -6
- package/dist/shims/before-interactive-context.d.ts +5 -6
- package/dist/shims/cache-callable-runtime.d.ts +44 -4
- package/dist/shims/cache-callable-runtime.js +168 -8
- package/dist/shims/cache-for-request.d.ts +2 -3
- package/dist/shims/cache-handler.d.ts +33 -20
- package/dist/shims/cache-handler.js +61 -2
- package/dist/shims/cache-request-state.d.ts +28 -29
- package/dist/shims/cache-runtime.d.ts +23 -21
- package/dist/shims/cache-runtime.js +239 -121
- package/dist/shims/cache.d.ts +15 -15
- package/dist/shims/cache.js +25 -13
- package/dist/shims/cacheability-classification.d.ts +106 -0
- package/dist/shims/cacheability-classification.js +161 -0
- package/dist/shims/cdn-cache-state.d.ts +13 -0
- package/dist/shims/cdn-cache-state.js +23 -0
- package/dist/shims/cdn-cache.d.ts +76 -18
- package/dist/shims/cdn-cache.js +40 -39
- package/dist/shims/client-hook-error.d.ts +3 -4
- package/dist/shims/client-locale.d.ts +2 -3
- package/dist/shims/client-page-root.d.ts +24 -0
- package/dist/shims/client-page-root.js +121 -0
- package/dist/shims/compat-router.d.ts +2 -3
- package/dist/shims/config.d.ts +3 -4
- package/dist/shims/constants.d.ts +73 -74
- package/dist/shims/constants.js +1 -1
- package/dist/shims/default-not-found.d.ts +2 -3
- package/dist/shims/document.d.ts +9 -9
- package/dist/shims/dynamic-preload-chunks.d.ts +2 -3
- package/dist/shims/dynamic-preload-chunks.js +17 -13
- package/dist/shims/dynamic.d.ts +3 -3
- package/dist/shims/error-boundary-navigation.d.ts +3 -4
- package/dist/shims/error-boundary.d.ts +17 -18
- package/dist/shims/error-boundary.js +17 -11
- package/dist/shims/error.d.ts +4 -4
- package/dist/shims/error.js +1 -1
- package/dist/shims/error.react-server.d.ts +3 -4
- package/dist/shims/fetch-cache.d.ts +22 -22
- package/dist/shims/fetch-cache.js +50 -20
- package/dist/shims/font-google-base.d.ts +9 -9
- package/dist/shims/font-google-base.js +2 -1
- package/dist/shims/font-local.d.ts +3 -3
- package/dist/shims/font-local.js +1 -1
- package/dist/shims/font-utils.d.ts +14 -15
- package/dist/shims/form.d.ts +2 -2
- package/dist/shims/form.js +10 -7
- package/dist/shims/hash-scroll.d.ts +5 -6
- package/dist/shims/head-state.d.ts +4 -5
- package/dist/shims/head.d.ts +16 -16
- package/dist/shims/head.js +5 -4
- package/dist/shims/headers.d.ts +68 -32
- package/dist/shims/headers.js +101 -10
- package/dist/shims/i18n-context.d.ts +5 -6
- package/dist/shims/i18n-state.d.ts +4 -5
- package/dist/shims/image-config.d.ts +5 -6
- package/dist/shims/image-config.js +2 -0
- package/dist/shims/image.d.ts +5 -5
- package/dist/shims/image.js +12 -8
- package/dist/shims/internal/als-registry.d.ts +4 -5
- package/dist/shims/internal/api-utils.d.ts +3 -4
- package/dist/shims/internal/app-page-props-cache-key.d.ts +32 -4
- package/dist/shims/internal/app-page-props-cache-key.js +53 -1
- package/dist/shims/internal/app-prefetch-fetch-queue.d.ts +5 -6
- package/dist/shims/internal/app-prefetch-rsc-request.d.ts +13 -0
- package/dist/shims/internal/app-prefetch-rsc-request.js +12 -0
- package/dist/shims/internal/app-route-detection.d.ts +2 -2
- package/dist/shims/internal/app-route-prefetch-policy.d.ts +5 -6
- package/dist/shims/internal/app-route-prefetch-policy.js +1 -0
- package/dist/shims/internal/app-router-context.d.ts +9 -10
- package/dist/shims/internal/cookie-serialize.d.ts +4 -5
- package/dist/shims/internal/format-url-object.d.ts +7 -0
- package/dist/shims/internal/format-url-object.js +53 -0
- package/dist/shims/internal/hybrid-client-route-owner-direct.d.ts +6 -7
- package/dist/shims/internal/hybrid-client-route-owner-direct.js +29 -11
- package/dist/shims/internal/hybrid-client-route-owner.d.ts +3 -3
- package/dist/shims/internal/hybrid-client-route-owner.js +5 -4
- package/dist/shims/internal/interpolate-as.d.ts +5 -6
- package/dist/shims/internal/interpolate-as.js +4 -2
- package/dist/shims/internal/link-status-registry.d.ts +5 -6
- package/dist/shims/internal/make-hanging-promise.d.ts +8 -3
- package/dist/shims/internal/make-hanging-promise.js +13 -2
- package/dist/shims/internal/navigation-untracked.d.ts +2 -3
- package/dist/shims/internal/normalize-router-href.d.ts +15 -0
- package/dist/shims/internal/normalize-router-href.js +41 -0
- package/dist/shims/internal/pages-data-fetch-dedup.d.ts +8 -9
- package/dist/shims/internal/pages-data-target.d.ts +8 -6
- package/dist/shims/internal/pages-data-target.js +32 -36
- package/dist/shims/internal/pages-data-url.d.ts +4 -5
- package/dist/shims/internal/pages-data-url.js +2 -1
- package/dist/shims/internal/pages-router-accessor.d.ts +3 -4
- package/dist/shims/internal/pages-router-components.d.ts +3 -4
- package/dist/shims/internal/route-pattern-for-warning.d.ts +5 -6
- package/dist/shims/internal/route-pattern-for-warning.js +3 -3
- package/dist/shims/internal/router-context.d.ts +2 -3
- package/dist/shims/internal/thenable-well-known-properties.d.ts +10 -0
- package/dist/shims/internal/thenable-well-known-properties.js +33 -0
- package/dist/shims/internal/utils.d.ts +7 -8
- package/dist/shims/internal/work-unit-async-storage.d.ts +12 -11
- package/dist/shims/layout-segment-context.d.ts +3 -4
- package/dist/shims/link-prefetch.d.ts +9 -10
- package/dist/shims/link.d.ts +4 -4
- package/dist/shims/link.js +67 -116
- package/dist/shims/metadata.d.ts +15 -16
- package/dist/shims/metadata.js +40 -36
- package/dist/shims/navigation-context-accessors.d.ts +9 -0
- package/dist/shims/navigation-context-accessors.js +19 -0
- package/dist/shims/navigation-context-state.d.ts +27 -18
- package/dist/shims/navigation-errors.d.ts +18 -19
- package/dist/shims/navigation-state.d.ts +6 -7
- package/dist/shims/navigation.d.ts +80 -68
- package/dist/shims/navigation.js +45 -17
- package/dist/shims/navigation.react-server.d.ts +9 -9
- package/dist/shims/navigation.react-server.js +1 -1
- package/dist/shims/offline.d.ts +2 -3
- package/dist/shims/og.d.ts +2 -2
- package/dist/shims/pages-router-runtime.d.ts +4 -5
- package/dist/shims/ppr-fallback-shell.d.ts +13 -14
- package/dist/shims/readonly-url-search-params.d.ts +2 -3
- package/dist/shims/request-context.d.ts +7 -6
- package/dist/shims/root-params.d.ts +14 -15
- package/dist/shims/router-state.d.ts +5 -6
- package/dist/shims/router-state.js +1 -1
- package/dist/shims/router.d.ts +22 -21
- package/dist/shims/router.js +339 -164
- package/dist/shims/script-nonce-context.d.ts +8 -6
- package/dist/shims/script-nonce-context.js +15 -6
- package/dist/shims/script.d.ts +4 -4
- package/dist/shims/script.js +9 -7
- package/dist/shims/search-params-gate.d.ts +35 -0
- package/dist/shims/search-params-gate.js +32 -0
- package/dist/shims/server.d.ts +19 -51
- package/dist/shims/server.js +14 -28
- package/dist/shims/slot.d.ts +33 -15
- package/dist/shims/slot.js +41 -9
- package/dist/shims/streamed-icons.d.ts +3 -4
- package/dist/shims/thenable-params.d.ts +5 -7
- package/dist/shims/thenable-params.js +3 -24
- package/dist/shims/unified-request-context.d.ts +34 -31
- package/dist/shims/unified-request-context.js +34 -24
- package/dist/shims/unrecognized-action-error.d.ts +3 -4
- package/dist/shims/url-safety.d.ts +5 -6
- package/dist/shims/url-utils.d.ts +18 -12
- package/dist/shims/url-utils.js +10 -1
- package/dist/shims/use-merged-ref.d.ts +2 -3
- package/dist/shims/user-agent.d.ts +31 -0
- package/dist/shims/user-agent.js +16 -0
- package/dist/shims/web-vitals.d.ts +2 -2
- package/dist/typegen.d.ts +3 -4
- package/dist/utils/asset-prefix.d.ts +7 -8
- package/dist/utils/base-path.d.ts +5 -6
- package/dist/utils/built-asset-url.d.ts +2 -3
- package/dist/utils/built-asset-url.js +1 -1
- package/dist/utils/cache-control-metadata.d.ts +4 -5
- package/dist/utils/client-build-manifest.d.ts +6 -7
- package/dist/utils/client-build-manifest.js +2 -1
- package/dist/utils/client-entry-manifest.d.ts +6 -7
- package/dist/utils/client-runtime-metadata.d.ts +8 -3
- package/dist/utils/client-runtime-metadata.js +18 -1
- package/dist/utils/commonjs-loader.d.ts +4 -5
- package/dist/utils/compare.d.ts +2 -3
- package/dist/utils/deployment-id.d.ts +6 -7
- package/dist/utils/dev-error-recovery-event.d.ts +2 -3
- package/dist/utils/dev-stack-sourcemap-endpoint.d.ts +2 -3
- package/dist/utils/domain-locale.d.ts +7 -8
- package/dist/utils/encode-cache-tag.d.ts +3 -4
- package/dist/utils/error-cause.d.ts +2 -3
- package/dist/utils/external-url.d.ts +2 -3
- package/dist/utils/has-trailing-comma.d.ts +3 -4
- package/dist/utils/hash.d.ts +3 -4
- package/dist/utils/html-limited-bots.d.ts +3 -4
- package/dist/utils/lazy-chunks.d.ts +8 -9
- package/dist/utils/lazy-chunks.js +4 -4
- package/dist/utils/manifest-paths.d.ts +5 -6
- package/dist/utils/mdx-scan.d.ts +11 -4
- package/dist/utils/mdx-scan.js +27 -1
- package/dist/utils/middleware-request-headers.d.ts +7 -6
- package/dist/utils/middleware-request-headers.js +6 -1
- package/dist/utils/navigation-signal.d.ts +3 -3
- package/dist/utils/navigation-signal.js +16 -1
- package/dist/utils/number.d.ts +2 -3
- package/dist/utils/package-name.d.ts +3 -4
- package/dist/utils/parse-cookie.d.ts +4 -5
- package/dist/utils/path.d.ts +8 -9
- package/dist/utils/plugin-options.d.ts +2 -3
- package/dist/utils/precompressed-variant.d.ts +3 -4
- package/dist/utils/prerender-output-paths.d.ts +9 -10
- package/dist/utils/prerender-output-paths.js +16 -9
- package/dist/utils/project.d.ts +19 -30
- package/dist/utils/project.js +20 -29
- package/dist/utils/promise.d.ts +2 -3
- package/dist/utils/protocol-headers.d.ts +14 -15
- package/dist/utils/public-file-path.d.ts +2 -3
- package/dist/utils/public-routes.d.ts +2 -3
- package/dist/utils/query.d.ts +14 -9
- package/dist/utils/query.js +22 -1
- package/dist/utils/react-compiler-support.d.ts +6 -7
- package/dist/utils/react-version.d.ts +4 -3
- package/dist/utils/react-version.js +19 -1
- package/dist/utils/record.d.ts +2 -3
- package/dist/utils/redirect-digest.d.ts +3 -4
- package/dist/utils/regex-safety.d.ts +4 -5
- package/dist/utils/regex.d.ts +2 -3
- package/dist/utils/safe-json-file.d.ts +2 -3
- package/dist/utils/sorted-array.d.ts +2 -3
- package/dist/utils/text-stream.d.ts +3 -4
- package/dist/utils/vinext-root.d.ts +2 -3
- package/dist/utils/virtual-module.d.ts +3 -4
- package/dist/utils/vite-cli-invocation.d.ts +21 -0
- package/dist/utils/vite-cli-invocation.js +144 -0
- package/dist/utils/vite-version.d.ts +5 -6
- package/next-package.json +4 -0
- package/package.json +55 -6
package/dist/init-cloudflare.js
CHANGED
|
@@ -1,53 +1,113 @@
|
|
|
1
1
|
import path from "./deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
2
2
|
import { detectProject } from "./utils/project.js";
|
|
3
|
+
import { isUnknownRecord } from "./utils/record.js";
|
|
3
4
|
import { createRequire } from "node:module";
|
|
4
5
|
import fs from "node:fs";
|
|
6
|
+
import { createHash } from "node:crypto";
|
|
5
7
|
import MagicString from "magic-string";
|
|
6
8
|
//#region src/init-cloudflare.ts
|
|
7
9
|
const require = createRequire(import.meta.url);
|
|
8
10
|
const DEFAULT_CLOUDFLARE_INIT_OPTIONS = {
|
|
9
|
-
dataCache: "
|
|
10
|
-
cdnCache: "
|
|
11
|
+
dataCache: "none",
|
|
12
|
+
cdnCache: "none",
|
|
11
13
|
imageOptimization: "cloudflare-images"
|
|
12
14
|
};
|
|
15
|
+
const DEFAULT_VERSION_METADATA_BINDING = "CF_VERSION_METADATA";
|
|
16
|
+
const RESPONSE_STORE_WRANGLER_CONFIG = "wrangler.response-store.jsonc";
|
|
17
|
+
const RESPONSE_STORE_BINDING = "RESPONSE_STORE";
|
|
18
|
+
const RESPONSE_STORE_ENTRYPOINT = "ResponseStoreService";
|
|
19
|
+
const RESPONSE_STORE_MAIN = "./node_modules/@cloudflare/workers-response-store/dist/service.js";
|
|
20
|
+
const CACHE_BODIES_BINDING = "CACHE_BODIES";
|
|
21
|
+
const CACHE_METADATA_BINDING = "CACHE_METADATA";
|
|
22
|
+
const CACHE_METADATA_CLASS = "CacheMetadata";
|
|
23
|
+
const CACHE_METADATA_EXPORT = {
|
|
24
|
+
type: "durable-object",
|
|
25
|
+
storage: "sqlite"
|
|
26
|
+
};
|
|
27
|
+
const CTX_EXPORTS_DEFAULT_DATE = "2025-11-17";
|
|
13
28
|
function validateCloudflarePlatformSetup(context, cloudflare) {
|
|
29
|
+
if (cloudflare.cdnCache === "static-assets" && !context.isAppRouter) throw new Error("The Static Assets cache currently requires an App Router project.");
|
|
30
|
+
if (!cloudflare.legacyWrangler) {
|
|
31
|
+
const existingWrangler = [
|
|
32
|
+
"wrangler.toml",
|
|
33
|
+
"wrangler.json",
|
|
34
|
+
"wrangler.jsonc",
|
|
35
|
+
RESPONSE_STORE_WRANGLER_CONFIG
|
|
36
|
+
].find((name) => fs.existsSync(path.join(context.root, name)));
|
|
37
|
+
if (existingWrangler) throw new Error(`Cloudflare init cannot replace an existing Wrangler config (${existingWrangler}). Migrate its bindings to cloudflare.config.ts first, or use --legacy-wrangler-cloudflare-init to keep the Wrangler setup.`);
|
|
38
|
+
const typedConfigPath = path.join(context.root, "cloudflare.config.ts");
|
|
39
|
+
if (cloudflare.cdnCache === "static-assets" && fs.existsSync(typedConfigPath)) throw new Error("Static Assets cache setup for an existing cloudflare.config.ts must be configured manually. Keep its assets binding aligned with staticAssetsAdapter({ binding }) and include \"/_vinext/static-cache/*\" in assets.runWorkerFirst to protect private cache files.");
|
|
40
|
+
if (cloudflare.cdnCache === "response-store" && (cloudflare.responseStoreMode ?? "service-binding") === "service-binding" && fs.existsSync(typedConfigPath) && !fs.readFileSync(typedConfigPath, "utf-8").includes("export const responseStoreServiceBinding")) throw new Error("The existing cloudflare.config.ts must export responseStoreServiceBinding for the Response Store auxiliary Worker. Configure it before rerunning init.");
|
|
41
|
+
if (context.existingViteConfigPath && cloudflare.cdnCache === "response-store" && (cloudflare.responseStoreMode ?? "service-binding") === "service-binding" && !fs.readFileSync(context.existingViteConfigPath, "utf-8").includes("auxiliaryWorkers: [{ config: responseStoreServiceBinding }]")) throw new Error("Cloudflare init with Response Store service-binding requires a fresh Vite config so the auxiliary Worker is connected. Remove the existing Vite config or configure it manually.");
|
|
42
|
+
if (context.existingViteConfigPath) {
|
|
43
|
+
const updatedConfig = updateViteConfigForCloudflare(context.existingViteConfigPath, fs.readFileSync(context.existingViteConfigPath, "utf-8"), {
|
|
44
|
+
isAppRouter: context.isAppRouter,
|
|
45
|
+
nativeModulesToStub: detectProject(context.root).nativeModulesToStub,
|
|
46
|
+
cache: cloudflare
|
|
47
|
+
});
|
|
48
|
+
if (context.hasCssModules) updateViteConfigForCssModules(context.existingViteConfigPath, updatedConfig);
|
|
49
|
+
}
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
14
52
|
const tomlPath = path.join(context.root, "wrangler.toml");
|
|
15
53
|
if (fs.existsSync(tomlPath)) throw new Error("wrangler.toml is not supported by vinext init. Convert it to wrangler.jsonc and rerun.");
|
|
16
54
|
const projectInfo = detectProject(context.root);
|
|
17
55
|
const wranglerPath = ["wrangler.jsonc", "wrangler.json"].map((fileName) => path.join(context.root, fileName)).find((candidate) => fs.existsSync(candidate));
|
|
18
56
|
const wranglerCode = wranglerPath ? fs.readFileSync(wranglerPath, "utf-8") : void 0;
|
|
57
|
+
if (!wranglerCode && cloudflare.cdnCache === "response-store" && (cloudflare.responseStoreMode ?? "service-binding") === "service-binding" && fs.existsSync(path.join(context.root, RESPONSE_STORE_WRANGLER_CONFIG))) readResponseStoreServiceName(context.root, {});
|
|
19
58
|
const updatedWranglerCode = wranglerCode ? updateWranglerConfigForCloudflare(wranglerCode, cloudflare, { root: context.root }) : void 0;
|
|
20
59
|
const imagesBinding = updatedWranglerCode ? getWranglerImagesBinding(updatedWranglerCode) : "IMAGES";
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
60
|
+
const assetsBinding = updatedWranglerCode ? getWranglerAssetsBinding(updatedWranglerCode) : "ASSETS";
|
|
61
|
+
const assetsDirectory = updatedWranglerCode ? getWranglerAssetsDirectory(updatedWranglerCode) : "dist/client";
|
|
62
|
+
const versionMetadataBinding = updatedWranglerCode ? getWranglerVersionMetadataBinding(updatedWranglerCode) : DEFAULT_VERSION_METADATA_BINDING;
|
|
63
|
+
if (context.existingViteConfigPath) {
|
|
64
|
+
const updatedConfig = updateViteConfigForCloudflare(context.existingViteConfigPath, fs.readFileSync(context.existingViteConfigPath, "utf-8"), {
|
|
65
|
+
isAppRouter: context.isAppRouter,
|
|
66
|
+
nativeModulesToStub: projectInfo.nativeModulesToStub,
|
|
67
|
+
cache: cloudflare,
|
|
68
|
+
assetsBinding,
|
|
69
|
+
assetsDirectory,
|
|
70
|
+
imagesBinding,
|
|
71
|
+
versionMetadataBinding
|
|
72
|
+
});
|
|
73
|
+
if (context.hasCssModules) updateViteConfigForCssModules(context.existingViteConfigPath, updatedConfig);
|
|
74
|
+
}
|
|
28
75
|
}
|
|
29
76
|
function setupCloudflarePlatform(context, cloudflare) {
|
|
77
|
+
if (!cloudflare.legacyWrangler) return setupCfPlatform(context, cloudflare);
|
|
30
78
|
const projectInfo = detectProject(context.root);
|
|
31
79
|
const wranglerPath = ["wrangler.jsonc", "wrangler.json"].map((fileName) => path.join(context.root, fileName)).find((candidate) => fs.existsSync(candidate));
|
|
32
80
|
const wranglerCode = wranglerPath ? fs.readFileSync(wranglerPath, "utf-8") : void 0;
|
|
33
|
-
const
|
|
81
|
+
const updatedWranglerCode = wranglerCode ? updateWranglerConfigForCloudflare(wranglerCode, cloudflare, { root: context.root }) : void 0;
|
|
82
|
+
const imagesBinding = updatedWranglerCode ? getWranglerImagesBinding(updatedWranglerCode) : "IMAGES";
|
|
83
|
+
const assetsBinding = updatedWranglerCode ? getWranglerAssetsBinding(updatedWranglerCode) : "ASSETS";
|
|
84
|
+
const assetsDirectory = updatedWranglerCode ? getWranglerAssetsDirectory(updatedWranglerCode) : "dist/client";
|
|
85
|
+
const versionMetadataBinding = updatedWranglerCode ? getWranglerVersionMetadataBinding(updatedWranglerCode) : DEFAULT_VERSION_METADATA_BINDING;
|
|
34
86
|
let generatedViteConfig = false;
|
|
35
87
|
let skippedViteConfig = false;
|
|
88
|
+
let preservedExistingGenerateScopedName = false;
|
|
36
89
|
if (context.existingViteConfigPath) {
|
|
37
90
|
const currentConfig = fs.readFileSync(context.existingViteConfigPath, "utf-8");
|
|
38
|
-
|
|
91
|
+
let updatedConfig = updateViteConfigForCloudflare(context.existingViteConfigPath, currentConfig, {
|
|
39
92
|
isAppRouter: context.isAppRouter,
|
|
40
93
|
nativeModulesToStub: projectInfo.nativeModulesToStub,
|
|
41
94
|
cache: cloudflare,
|
|
95
|
+
assetsBinding,
|
|
96
|
+
assetsDirectory,
|
|
42
97
|
imagesBinding,
|
|
43
|
-
|
|
98
|
+
versionMetadataBinding
|
|
44
99
|
});
|
|
100
|
+
if (context.hasCssModules) {
|
|
101
|
+
const cssUpdate = updateViteConfigForCssModules(context.existingViteConfigPath, updatedConfig);
|
|
102
|
+
updatedConfig = cssUpdate.code;
|
|
103
|
+
preservedExistingGenerateScopedName = cssUpdate.preservedExistingGenerateScopedName;
|
|
104
|
+
}
|
|
45
105
|
if (updatedConfig !== currentConfig) {
|
|
46
106
|
fs.writeFileSync(context.existingViteConfigPath, updatedConfig, "utf-8");
|
|
47
107
|
generatedViteConfig = true;
|
|
48
108
|
} else skippedViteConfig = true;
|
|
49
109
|
} else {
|
|
50
|
-
const configContent = context.isAppRouter ? generateAppRouterViteConfig(projectInfo, cloudflare, imagesBinding, context.
|
|
110
|
+
const configContent = context.isAppRouter ? generateAppRouterViteConfig(projectInfo, cloudflare, imagesBinding, versionMetadataBinding, false, assetsBinding, assetsDirectory, context.hasCssModules) : generatePagesRouterViteConfig(projectInfo, cloudflare, imagesBinding, versionMetadataBinding, false, context.hasCssModules);
|
|
51
111
|
fs.writeFileSync(path.join(context.root, "vite.config.ts"), configContent, "utf-8");
|
|
52
112
|
generatedViteConfig = true;
|
|
53
113
|
}
|
|
@@ -55,30 +115,123 @@ function setupCloudflarePlatform(context, cloudflare) {
|
|
|
55
115
|
if (!wranglerPath) {
|
|
56
116
|
fs.writeFileSync(path.join(context.root, "wrangler.jsonc"), generateWranglerConfig(projectInfo, cloudflare, context.today), "utf-8");
|
|
57
117
|
generatedPlatformFiles.push("wrangler.jsonc");
|
|
58
|
-
} else if (wranglerCode) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
fs.writeFileSync(wranglerPath, updatedConfig, "utf-8");
|
|
118
|
+
} else if (wranglerCode && updatedWranglerCode) {
|
|
119
|
+
if (updatedWranglerCode !== wranglerCode) {
|
|
120
|
+
fs.writeFileSync(wranglerPath, updatedWranglerCode, "utf-8");
|
|
62
121
|
generatedPlatformFiles.push(path.basename(wranglerPath));
|
|
63
122
|
}
|
|
64
123
|
}
|
|
65
124
|
const finalWranglerPath = wranglerPath ?? path.join(context.root, "wrangler.jsonc");
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
125
|
+
if (cloudflare.cdnCache === "response-store" && (cloudflare.responseStoreMode ?? "service-binding") === "service-binding") {
|
|
126
|
+
const responseStorePath = path.join(path.dirname(finalWranglerPath), RESPONSE_STORE_WRANGLER_CONFIG);
|
|
127
|
+
if (!fs.existsSync(responseStorePath)) {
|
|
128
|
+
fs.writeFileSync(responseStorePath, generateResponseStoreWranglerConfig(fs.readFileSync(finalWranglerPath, "utf-8"), context.root), "utf-8");
|
|
129
|
+
generatedPlatformFiles.push(path.relative(context.root, responseStorePath) || RESPONSE_STORE_WRANGLER_CONFIG);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const nextSteps = [];
|
|
133
|
+
if (cloudflare.cdnCache === "response-store" && (cloudflare.responseStoreMode ?? "service-binding") === "service-binding") nextSteps.push("Deploy Workers Response Store before deploying the application:", ` ${context.packageManager ?? "npm"} run deploy:response-store`);
|
|
134
|
+
if (cloudflare.prerender && cloudflare.cdnCache !== "static-assets") nextSteps.push("Pre-rendered routes are built, but Cloudflare deploys do not serve them.", " Use the Static Assets cache to serve them, or cache warming to fill another cache.");
|
|
69
135
|
return {
|
|
70
136
|
generatedViteConfig,
|
|
71
137
|
skippedViteConfig,
|
|
72
138
|
generatedPlatformFiles,
|
|
73
|
-
nextSteps
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
139
|
+
nextSteps,
|
|
140
|
+
preservedExistingGenerateScopedName
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function setupCfPlatform(context, cloudflare) {
|
|
144
|
+
const projectInfo = detectProject(context.root);
|
|
145
|
+
const serviceBinding = cloudflare.cdnCache === "response-store" && (cloudflare.responseStoreMode ?? "service-binding") === "service-binding";
|
|
146
|
+
let generatedViteConfig = false;
|
|
147
|
+
let preservedExistingGenerateScopedName = false;
|
|
148
|
+
if (context.existingViteConfigPath) {
|
|
149
|
+
const current = fs.readFileSync(context.existingViteConfigPath, "utf-8");
|
|
150
|
+
let updated = updateViteConfigForCloudflare(context.existingViteConfigPath, current, {
|
|
151
|
+
isAppRouter: context.isAppRouter,
|
|
152
|
+
nativeModulesToStub: projectInfo.nativeModulesToStub,
|
|
153
|
+
cache: cloudflare
|
|
154
|
+
});
|
|
155
|
+
if (context.hasCssModules) {
|
|
156
|
+
const cssUpdate = updateViteConfigForCssModules(context.existingViteConfigPath, updated);
|
|
157
|
+
updated = cssUpdate.code;
|
|
158
|
+
preservedExistingGenerateScopedName = cssUpdate.preservedExistingGenerateScopedName;
|
|
159
|
+
}
|
|
160
|
+
if (updated !== current) {
|
|
161
|
+
fs.writeFileSync(context.existingViteConfigPath, updated, "utf-8");
|
|
162
|
+
generatedViteConfig = true;
|
|
163
|
+
}
|
|
164
|
+
} else {
|
|
165
|
+
const viteConfig = context.isAppRouter ? generateAppRouterViteConfig(projectInfo, cloudflare, "IMAGES", DEFAULT_VERSION_METADATA_BINDING, serviceBinding, "ASSETS", "dist/client", context.hasCssModules) : generatePagesRouterViteConfig(projectInfo, cloudflare, "IMAGES", DEFAULT_VERSION_METADATA_BINDING, serviceBinding, context.hasCssModules);
|
|
166
|
+
fs.writeFileSync(path.join(context.root, "vite.config.ts"), viteConfig, "utf-8");
|
|
167
|
+
generatedViteConfig = true;
|
|
168
|
+
}
|
|
169
|
+
const configPath = path.join(context.root, "cloudflare.config.ts");
|
|
170
|
+
const generatedPlatformFiles = [];
|
|
171
|
+
if (!fs.existsSync(configPath)) {
|
|
172
|
+
fs.writeFileSync(configPath, generateTypedCloudflareConfig(projectInfo, cloudflare, context.today));
|
|
173
|
+
generatedPlatformFiles.push("cloudflare.config.ts");
|
|
174
|
+
}
|
|
175
|
+
const nextSteps = [];
|
|
176
|
+
if (serviceBinding) nextSteps.push("After `vinext build`, deploy the Response Store Worker explicitly (and repeat when its code/config changes):", ` ${context.packageManager ?? "npm"} run deploy:response-store`, "vinext-cloudflare deploy only deploys the application Worker.");
|
|
177
|
+
if (cloudflare.prerender && cloudflare.cdnCache !== "static-assets") nextSteps.push("Pre-rendered routes are built, but Cloudflare deploys do not serve them.", " Use the Static Assets cache to serve them, or cache warming to fill another cache.");
|
|
178
|
+
nextSteps.push("For TypeScript, add \".cloudflare/types\" to the include list in tsconfig.json.", "Worker types are generated during dev/build; run `cf workers types` before standalone type-checks.");
|
|
179
|
+
return {
|
|
180
|
+
generatedViteConfig,
|
|
181
|
+
skippedViteConfig: !generatedViteConfig,
|
|
182
|
+
generatedPlatformFiles,
|
|
183
|
+
nextSteps,
|
|
184
|
+
preservedExistingGenerateScopedName
|
|
80
185
|
};
|
|
81
186
|
}
|
|
187
|
+
function generateTypedCloudflareConfig(info, options, today = (/* @__PURE__ */ new Date()).toISOString().split("T")[0]) {
|
|
188
|
+
const serviceBinding = options.cdnCache === "response-store" && (options.responseStoreMode ?? "service-binding") === "service-binding";
|
|
189
|
+
const selfContained = options.cdnCache === "response-store" && !serviceBinding;
|
|
190
|
+
const workersCache = options.cdnCache === "workers-cache";
|
|
191
|
+
const helper = serviceBinding ? "createWorkersResponseStoreServiceBindingConfig" : selfContained ? "createWorkersResponseStoreSelfContainedConfig" : workersCache ? "createWorkersCacheConfig" : void 0;
|
|
192
|
+
const imports = [`import { bindings, defineConfig, defineWorker } from "cf/config";`, ...helper ? [`import { ${helper} } from "@vinext/cloudflare/cache/config";`] : []];
|
|
193
|
+
const responseStoreName = compactResourceName(info.projectName, "-response-store", 63);
|
|
194
|
+
const bucket = serviceBinding ? compactResourceName(responseStoreName, "-cache-bodies", 63) : compactResourceName(info.projectName, "-response-store-cache-bodies", 63);
|
|
195
|
+
const shared = serviceBinding ? `const responseStore = await ${helper}({
|
|
196
|
+
worker: {
|
|
197
|
+
name: ${JSON.stringify(responseStoreName)},
|
|
198
|
+
compatibilityDate: ${JSON.stringify(today)},
|
|
199
|
+
compatibilityFlags: ["nodejs_compat"],
|
|
200
|
+
},
|
|
201
|
+
bucket: ${JSON.stringify(bucket)},
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
export const responseStoreServiceBinding = responseStore.serviceBindingWorker;
|
|
205
|
+
|
|
206
|
+
` : selfContained ? `const cache = await ${helper}({
|
|
207
|
+
worker: ${JSON.stringify(info.projectName)},
|
|
208
|
+
bucket: ${JSON.stringify(bucket)},
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
` : workersCache ? `const cache = await ${helper}();\n\n` : "";
|
|
212
|
+
const cacheSpread = serviceBinding ? "responseStore.applicationWorker" : helper ? "cache" : void 0;
|
|
213
|
+
const envBindings = [
|
|
214
|
+
...cacheSpread ? [`...${cacheSpread}.env`] : [],
|
|
215
|
+
"ASSETS: bindings.assets()",
|
|
216
|
+
...options.imageOptimization === "cloudflare-images" ? ["IMAGES: bindings.images()"] : [],
|
|
217
|
+
...options.dataCache === "kv" ? ["VINEXT_KV_CACHE: bindings.kv()"] : []
|
|
218
|
+
];
|
|
219
|
+
return `${imports.join("\n")}
|
|
220
|
+
|
|
221
|
+
${shared}export default defineConfig({
|
|
222
|
+
worker: defineWorker({
|
|
223
|
+
${cacheSpread ? `...${cacheSpread},\n ` : ""}name: ${JSON.stringify(info.projectName)},
|
|
224
|
+
entrypoint: ${JSON.stringify(resolveWorkerEntry(info.root))},
|
|
225
|
+
compatibilityDate: ${JSON.stringify(today)},
|
|
226
|
+
compatibilityFlags: ["nodejs_compat"],
|
|
227
|
+
assets: { notFoundHandling: "none"${options.cdnCache === "static-assets" ? ", runWorkerFirst: [\"/_vinext/static-cache/*\"]" : ""} },
|
|
228
|
+
env: {
|
|
229
|
+
${envBindings.join(",\n ")},
|
|
230
|
+
},
|
|
231
|
+
}),
|
|
232
|
+
});
|
|
233
|
+
`;
|
|
234
|
+
}
|
|
82
235
|
/**
|
|
83
236
|
* `main` is what makes a Wrangler config a Worker rather than a static-assets
|
|
84
237
|
* project. A custom `worker/index.*` wins when present; otherwise the
|
|
@@ -101,16 +254,20 @@ function generateWranglerConfig(info, options = DEFAULT_CLOUDFLARE_INIT_OPTIONS,
|
|
|
101
254
|
assets: {
|
|
102
255
|
directory: "dist/client",
|
|
103
256
|
not_found_handling: "none",
|
|
104
|
-
binding: "ASSETS"
|
|
257
|
+
binding: "ASSETS",
|
|
258
|
+
...options.cdnCache === "static-assets" ? { run_worker_first: ["/_vinext/static-cache/*"] } : {}
|
|
105
259
|
}
|
|
106
260
|
};
|
|
107
|
-
if (options.cdnCache === "workers-cache")
|
|
261
|
+
if (options.cdnCache === "workers-cache") {
|
|
262
|
+
config.cache = { enabled: true };
|
|
263
|
+
config.version_metadata = { binding: DEFAULT_VERSION_METADATA_BINDING };
|
|
264
|
+
}
|
|
108
265
|
if (options.imageOptimization === "cloudflare-images") config.images = { binding: "IMAGES" };
|
|
109
|
-
if (options.dataCache === "kv") config.kv_namespaces = [{
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return JSON.stringify(
|
|
266
|
+
if (options.dataCache === "kv") config.kv_namespaces = [{ binding: "VINEXT_KV_CACHE" }];
|
|
267
|
+
const code = `${JSON.stringify(config, null, 2)}\n`;
|
|
268
|
+
if (options.cdnCache !== "response-store") return code;
|
|
269
|
+
const configured = configureResponseStoreWrangler(code, config, options.responseStoreMode ?? "service-binding", info.root);
|
|
270
|
+
return `${JSON.stringify(JSON.parse(configured), null, 2)}\n`;
|
|
114
271
|
}
|
|
115
272
|
function stripJsonComments(code) {
|
|
116
273
|
let output = "";
|
|
@@ -269,6 +426,197 @@ function appendTopLevelJsonProperty(code, property) {
|
|
|
269
426
|
const structuralBefore = stripJsonComments(before);
|
|
270
427
|
return `${before}${!/,\s*$/.test(structuralBefore) && !/{\s*$/.test(structuralBefore) ? "," : ""}\n${property}\n${code.slice(closing)}`;
|
|
271
428
|
}
|
|
429
|
+
function setTopLevelJsonProperty(code, name, value) {
|
|
430
|
+
const property = findTopLevelJsonProperty(code, name);
|
|
431
|
+
const serialized = JSON.stringify(value);
|
|
432
|
+
if (!property) return appendTopLevelJsonProperty(code, ` ${JSON.stringify(name)}: ${serialized}`);
|
|
433
|
+
return `${code.slice(0, property.valueStart)}${serialized}${code.slice(property.valueEnd)}`;
|
|
434
|
+
}
|
|
435
|
+
function compactResourceName(name, suffix, maxLength) {
|
|
436
|
+
const fullName = `${name}${suffix}`;
|
|
437
|
+
if (fullName.length <= maxLength) return fullName;
|
|
438
|
+
const hash = createHash("sha256").update(name).digest("hex").slice(0, 8);
|
|
439
|
+
return `${name.slice(0, maxLength - suffix.length - hash.length - 1)}-${hash}${suffix}`;
|
|
440
|
+
}
|
|
441
|
+
function isCacheMetadataExport(value) {
|
|
442
|
+
return isUnknownRecord(value) && value.type === CACHE_METADATA_EXPORT.type && value.storage === CACHE_METADATA_EXPORT.storage;
|
|
443
|
+
}
|
|
444
|
+
function readResponseStoreServiceName(root, appConfig) {
|
|
445
|
+
const responseStorePath = path.join(root, RESPONSE_STORE_WRANGLER_CONFIG);
|
|
446
|
+
if (fs.existsSync(responseStorePath)) {
|
|
447
|
+
let responseStoreConfig;
|
|
448
|
+
try {
|
|
449
|
+
responseStoreConfig = JSON.parse(stripJsonComments(fs.readFileSync(responseStorePath, "utf8")));
|
|
450
|
+
} catch (cause) {
|
|
451
|
+
throw new Error(`Could not parse ${RESPONSE_STORE_WRANGLER_CONFIG}.`, { cause });
|
|
452
|
+
}
|
|
453
|
+
if (!isUnknownRecord(responseStoreConfig) || typeof responseStoreConfig.name !== "string" || responseStoreConfig.name.length === 0) throw new Error(`${RESPONSE_STORE_WRANGLER_CONFIG} must contain a Worker name.`);
|
|
454
|
+
if (responseStoreConfig.main !== RESPONSE_STORE_MAIN) throw new Error(`${RESPONSE_STORE_WRANGLER_CONFIG} already exists but does not use @cloudflare/workers-response-store.`);
|
|
455
|
+
const responseStoreExport = isUnknownRecord(responseStoreConfig.exports) ? responseStoreConfig.exports.ResponseStoreBinding : void 0;
|
|
456
|
+
const cacheMetadataExport = isUnknownRecord(responseStoreConfig.exports) ? responseStoreConfig.exports[CACHE_METADATA_CLASS] : void 0;
|
|
457
|
+
const hasCacheBodies = Array.isArray(responseStoreConfig.r2_buckets) && responseStoreConfig.r2_buckets.some((binding) => isUnknownRecord(binding) && binding.binding === CACHE_BODIES_BINDING);
|
|
458
|
+
const durableBindings = isUnknownRecord(responseStoreConfig.durable_objects) ? responseStoreConfig.durable_objects.bindings : void 0;
|
|
459
|
+
const hasCacheMetadata = Array.isArray(durableBindings) && durableBindings.some((binding) => isUnknownRecord(binding) && binding.name === CACHE_METADATA_BINDING && binding.class_name === CACHE_METADATA_CLASS && binding.script_name === void 0);
|
|
460
|
+
const hasNoMigrations = responseStoreConfig.migrations === void 0 || Array.isArray(responseStoreConfig.migrations) && responseStoreConfig.migrations.length === 0;
|
|
461
|
+
if (!isUnknownRecord(responseStoreConfig.cache) || responseStoreConfig.cache.enabled !== true || !isUnknownRecord(responseStoreExport) || !isUnknownRecord(responseStoreExport.cache) || responseStoreExport.cache.enabled !== true || !hasCacheBodies || !hasCacheMetadata || !isCacheMetadataExport(cacheMetadataExport) || !hasNoMigrations) throw new Error(`${RESPONSE_STORE_WRANGLER_CONFIG} is missing required Response Store bindings.`);
|
|
462
|
+
const compatibilityFlags = responseStoreConfig.compatibility_flags;
|
|
463
|
+
if (compatibilityFlags !== void 0 && (!Array.isArray(compatibilityFlags) || compatibilityFlags.some((flag) => typeof flag !== "string"))) throw new Error(`${RESPONSE_STORE_WRANGLER_CONFIG} has invalid compatibility flags.`);
|
|
464
|
+
const flags = compatibilityFlags ?? [];
|
|
465
|
+
if (flags.includes("disable_ctx_exports") || (typeof responseStoreConfig.compatibility_date !== "string" || responseStoreConfig.compatibility_date < CTX_EXPORTS_DEFAULT_DATE) && !flags.includes("enable_ctx_exports")) throw new Error(`${RESPONSE_STORE_WRANGLER_CONFIG} must enable ctx.exports with a compatibility date on or after ${CTX_EXPORTS_DEFAULT_DATE}, or the enable_ctx_exports compatibility flag.`);
|
|
466
|
+
return responseStoreConfig.name;
|
|
467
|
+
}
|
|
468
|
+
if (Array.isArray(appConfig.services)) {
|
|
469
|
+
const binding = appConfig.services.find((service) => isUnknownRecord(service) && service.binding === RESPONSE_STORE_BINDING);
|
|
470
|
+
if (isUnknownRecord(binding) && typeof binding.service === "string" && binding.service.length > 0) return binding.service;
|
|
471
|
+
}
|
|
472
|
+
return compactResourceName(typeof appConfig.name === "string" && appConfig.name.length > 0 ? appConfig.name : detectProject(root).projectName, "-response-store", 63);
|
|
473
|
+
}
|
|
474
|
+
function configureResponseStoreWrangler(code, config, mode, root) {
|
|
475
|
+
const flags = Array.isArray(config.compatibility_flags) ? config.compatibility_flags.filter((flag) => typeof flag === "string") : [];
|
|
476
|
+
if (flags.includes("disable_ctx_exports")) throw new Error("Workers Response Store requires ctx.exports to be enabled.");
|
|
477
|
+
if ((typeof config.compatibility_date !== "string" || config.compatibility_date < CTX_EXPORTS_DEFAULT_DATE) && !flags.includes("enable_ctx_exports")) code = setTopLevelJsonProperty(code, "compatibility_flags", [...flags, "enable_ctx_exports"]);
|
|
478
|
+
const versionMetadata = config.version_metadata;
|
|
479
|
+
if (versionMetadata !== void 0 && (!isUnknownRecord(versionMetadata) || versionMetadata.binding !== DEFAULT_VERSION_METADATA_BINDING)) throw new Error(`Workers Response Store requires version_metadata.binding to be ${JSON.stringify(DEFAULT_VERSION_METADATA_BINDING)}.`);
|
|
480
|
+
code = setTopLevelJsonProperty(code, "version_metadata", { binding: DEFAULT_VERSION_METADATA_BINDING });
|
|
481
|
+
const cache = config.cache;
|
|
482
|
+
if (cache !== void 0 && !isUnknownRecord(cache)) throw new Error("The existing Wrangler config has an invalid cache value.");
|
|
483
|
+
code = setTopLevelJsonProperty(code, "cache", {
|
|
484
|
+
...cache,
|
|
485
|
+
enabled: mode === "self-contained"
|
|
486
|
+
});
|
|
487
|
+
const exportsConfig = config.exports;
|
|
488
|
+
if (exportsConfig !== void 0 && !isUnknownRecord(exportsConfig)) throw new Error("The existing Wrangler config has an invalid exports value.");
|
|
489
|
+
const workerExports = { ...exportsConfig };
|
|
490
|
+
const cacheMetadataExport = workerExports[CACHE_METADATA_CLASS];
|
|
491
|
+
const hasCacheMetadataExport = isCacheMetadataExport(cacheMetadataExport);
|
|
492
|
+
let updateWorkerExports = mode === "self-contained";
|
|
493
|
+
const services = config.services;
|
|
494
|
+
if (services !== void 0 && !Array.isArray(services)) throw new Error("The existing Wrangler config has an invalid services value.");
|
|
495
|
+
const existingServices = services ?? [];
|
|
496
|
+
if (existingServices.some((service) => !isUnknownRecord(service))) throw new Error("The existing Wrangler config has an invalid service binding.");
|
|
497
|
+
const responseStoreService = existingServices.find((service) => service.binding === RESPONSE_STORE_BINDING);
|
|
498
|
+
if (responseStoreService && responseStoreService.entrypoint !== RESPONSE_STORE_ENTRYPOINT) throw new Error(`The ${RESPONSE_STORE_BINDING} service binding uses a different entrypoint.`);
|
|
499
|
+
if (mode === "service-binding") {
|
|
500
|
+
const responseStoreExport = workerExports.ResponseStoreBinding;
|
|
501
|
+
const hasSelfContainedResponseStore = isUnknownRecord(responseStoreExport) && responseStoreExport.type === "worker" && isUnknownRecord(responseStoreExport.cache) && responseStoreExport.cache.enabled === true;
|
|
502
|
+
if (responseStoreExport !== void 0 && !hasSelfContainedResponseStore) throw new Error("The existing ResponseStoreBinding export conflicts with Workers Response Store.");
|
|
503
|
+
if (hasSelfContainedResponseStore && cacheMetadataExport !== void 0 && !hasCacheMetadataExport) throw new Error(`The existing ${CACHE_METADATA_CLASS} export conflicts with Workers Response Store.`);
|
|
504
|
+
const hasCacheBodies = Array.isArray(config.r2_buckets) && config.r2_buckets.some((bucket) => isUnknownRecord(bucket) && bucket.binding === CACHE_BODIES_BINDING);
|
|
505
|
+
const durableBindings = isUnknownRecord(config.durable_objects) ? config.durable_objects.bindings : void 0;
|
|
506
|
+
const hasCacheMetadata = Array.isArray(durableBindings) && durableBindings.some((binding) => isUnknownRecord(binding) && binding.name === CACHE_METADATA_BINDING);
|
|
507
|
+
if (!hasSelfContainedResponseStore && hasCacheBodies) throw new Error(`${CACHE_BODIES_BINDING} is already used by an application-owned R2 binding.`);
|
|
508
|
+
if (!hasSelfContainedResponseStore && hasCacheMetadata) throw new Error(`${CACHE_METADATA_BINDING} is already used by an application-owned Durable Object binding.`);
|
|
509
|
+
const serviceName = readResponseStoreServiceName(root, config);
|
|
510
|
+
code = setTopLevelJsonProperty(code, "services", [...existingServices.filter((service) => service.binding !== RESPONSE_STORE_BINDING), {
|
|
511
|
+
...responseStoreService,
|
|
512
|
+
binding: RESPONSE_STORE_BINDING,
|
|
513
|
+
service: serviceName,
|
|
514
|
+
entrypoint: RESPONSE_STORE_ENTRYPOINT
|
|
515
|
+
}]);
|
|
516
|
+
updateWorkerExports = hasSelfContainedResponseStore;
|
|
517
|
+
delete workerExports.ResponseStoreBinding;
|
|
518
|
+
if (hasSelfContainedResponseStore) delete workerExports[CACHE_METADATA_CLASS];
|
|
519
|
+
if (Array.isArray(config.r2_buckets)) code = setTopLevelJsonProperty(code, "r2_buckets", config.r2_buckets.filter((bucket) => !isUnknownRecord(bucket) || bucket.binding !== CACHE_BODIES_BINDING));
|
|
520
|
+
if (isUnknownRecord(config.durable_objects) && Array.isArray(config.durable_objects.bindings)) code = setTopLevelJsonProperty(code, "durable_objects", {
|
|
521
|
+
...config.durable_objects,
|
|
522
|
+
bindings: config.durable_objects.bindings.filter((binding) => !isUnknownRecord(binding) || binding.name !== CACHE_METADATA_BINDING)
|
|
523
|
+
});
|
|
524
|
+
} else {
|
|
525
|
+
const defaultExport = workerExports.default;
|
|
526
|
+
if (defaultExport !== void 0 && !isUnknownRecord(defaultExport)) throw new Error("The existing Wrangler config has an invalid default export.");
|
|
527
|
+
workerExports.default = {
|
|
528
|
+
...defaultExport,
|
|
529
|
+
type: "worker",
|
|
530
|
+
cache: { enabled: false }
|
|
531
|
+
};
|
|
532
|
+
if (responseStoreService) code = setTopLevelJsonProperty(code, "services", existingServices.filter((service) => service.binding !== RESPONSE_STORE_BINDING));
|
|
533
|
+
for (const [name, value] of Object.entries(workerExports)) {
|
|
534
|
+
if (!isUnknownRecord(value)) throw new Error(`The existing Wrangler config has an invalid ${name} export.`);
|
|
535
|
+
if (value.type === "worker" && value.cache === void 0) workerExports[name] = {
|
|
536
|
+
...value,
|
|
537
|
+
cache: { enabled: false }
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
const responseStoreExport = workerExports.ResponseStoreBinding;
|
|
541
|
+
if (responseStoreExport !== void 0 && !isUnknownRecord(responseStoreExport)) throw new Error("The existing Wrangler config has an invalid ResponseStoreBinding export.");
|
|
542
|
+
workerExports.ResponseStoreBinding = {
|
|
543
|
+
...responseStoreExport,
|
|
544
|
+
type: "worker",
|
|
545
|
+
cache: { enabled: true }
|
|
546
|
+
};
|
|
547
|
+
if (cacheMetadataExport !== void 0 && !hasCacheMetadataExport) throw new Error(`The existing ${CACHE_METADATA_CLASS} export conflicts with Workers Response Store.`);
|
|
548
|
+
workerExports[CACHE_METADATA_CLASS] = CACHE_METADATA_EXPORT;
|
|
549
|
+
const r2Buckets = config.r2_buckets;
|
|
550
|
+
if (r2Buckets !== void 0 && !Array.isArray(r2Buckets)) throw new Error("The existing Wrangler config has an invalid r2_buckets value.");
|
|
551
|
+
const existingBuckets = r2Buckets ?? [];
|
|
552
|
+
if (existingBuckets.some((bucket) => !isUnknownRecord(bucket))) throw new Error("The existing Wrangler config has an invalid R2 binding.");
|
|
553
|
+
if (!existingBuckets.some((bucket) => bucket.binding === CACHE_BODIES_BINDING)) {
|
|
554
|
+
const appName = typeof config.name === "string" && config.name.length > 0 ? config.name : detectProject(root).projectName;
|
|
555
|
+
code = setTopLevelJsonProperty(code, "r2_buckets", [...existingBuckets, {
|
|
556
|
+
binding: CACHE_BODIES_BINDING,
|
|
557
|
+
bucket_name: compactResourceName(appName, "-response-store-cache-bodies", 63)
|
|
558
|
+
}]);
|
|
559
|
+
}
|
|
560
|
+
const durableObjects = config.durable_objects;
|
|
561
|
+
if (durableObjects !== void 0 && !isUnknownRecord(durableObjects)) throw new Error("The existing Wrangler config has an invalid durable_objects value.");
|
|
562
|
+
const durableBindings = durableObjects?.bindings;
|
|
563
|
+
if (durableBindings !== void 0 && !Array.isArray(durableBindings)) throw new Error("The existing Wrangler config has invalid Durable Object bindings.");
|
|
564
|
+
const existingDurableBindings = durableBindings ?? [];
|
|
565
|
+
if (existingDurableBindings.some((binding) => !isUnknownRecord(binding))) throw new Error("The existing Wrangler config has an invalid Durable Object binding.");
|
|
566
|
+
const existingMetadataBinding = existingDurableBindings.find((binding) => binding.name === CACHE_METADATA_BINDING);
|
|
567
|
+
if (existingMetadataBinding && (existingMetadataBinding.class_name !== CACHE_METADATA_CLASS || existingMetadataBinding.script_name !== void 0)) throw new Error(`The ${CACHE_METADATA_BINDING} Durable Object binding is incompatible.`);
|
|
568
|
+
code = setTopLevelJsonProperty(code, "durable_objects", {
|
|
569
|
+
...durableObjects,
|
|
570
|
+
bindings: existingMetadataBinding ? existingDurableBindings : [...existingDurableBindings, {
|
|
571
|
+
name: CACHE_METADATA_BINDING,
|
|
572
|
+
class_name: CACHE_METADATA_CLASS
|
|
573
|
+
}]
|
|
574
|
+
});
|
|
575
|
+
const migrations = config.migrations;
|
|
576
|
+
if (migrations !== void 0 && !Array.isArray(migrations)) throw new Error("The existing Wrangler config has an invalid migrations value.");
|
|
577
|
+
const existingMigrations = migrations ?? [];
|
|
578
|
+
if (existingMigrations.some((migration) => !isUnknownRecord(migration))) throw new Error("The existing Wrangler config has an invalid Durable Object migration.");
|
|
579
|
+
if (existingMigrations.length > 0) throw new Error("Self-contained Workers Response Store cannot be combined with migration-based Durable Objects. Convert the existing Durable Objects to declarative exports or use service-binding mode.");
|
|
580
|
+
}
|
|
581
|
+
return updateWorkerExports ? setTopLevelJsonProperty(code, "exports", workerExports) : code;
|
|
582
|
+
}
|
|
583
|
+
function generateResponseStoreWranglerConfig(appWranglerCode, root) {
|
|
584
|
+
const appConfig = JSON.parse(stripJsonComments(appWranglerCode));
|
|
585
|
+
const serviceName = readResponseStoreServiceName(root, appConfig);
|
|
586
|
+
const compatibilityDate = typeof appConfig.compatibility_date === "string" ? appConfig.compatibility_date : (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
587
|
+
const compatibilityFlags = ["nodejs_compat"];
|
|
588
|
+
if (compatibilityDate < CTX_EXPORTS_DEFAULT_DATE) compatibilityFlags.push("enable_ctx_exports");
|
|
589
|
+
return `${JSON.stringify({
|
|
590
|
+
$schema: "node_modules/wrangler/config-schema.json",
|
|
591
|
+
name: serviceName,
|
|
592
|
+
main: RESPONSE_STORE_MAIN,
|
|
593
|
+
compatibility_date: compatibilityDate,
|
|
594
|
+
compatibility_flags: compatibilityFlags,
|
|
595
|
+
workers_dev: false,
|
|
596
|
+
preview_urls: false,
|
|
597
|
+
cache: { enabled: true },
|
|
598
|
+
exports: {
|
|
599
|
+
default: {
|
|
600
|
+
type: "worker",
|
|
601
|
+
cache: { enabled: false }
|
|
602
|
+
},
|
|
603
|
+
ResponseStoreBinding: {
|
|
604
|
+
type: "worker",
|
|
605
|
+
cache: { enabled: true }
|
|
606
|
+
},
|
|
607
|
+
[CACHE_METADATA_CLASS]: CACHE_METADATA_EXPORT
|
|
608
|
+
},
|
|
609
|
+
r2_buckets: [{
|
|
610
|
+
binding: CACHE_BODIES_BINDING,
|
|
611
|
+
bucket_name: compactResourceName(serviceName, "-cache-bodies", 63)
|
|
612
|
+
}],
|
|
613
|
+
durable_objects: { bindings: [{
|
|
614
|
+
name: CACHE_METADATA_BINDING,
|
|
615
|
+
class_name: CACHE_METADATA_CLASS
|
|
616
|
+
}] },
|
|
617
|
+
...typeof appConfig.account_id === "string" ? { account_id: appConfig.account_id } : {}
|
|
618
|
+
}, null, 2)}\n`;
|
|
619
|
+
}
|
|
272
620
|
function updateWranglerConfigForCloudflare(code, options, context = {}) {
|
|
273
621
|
let config;
|
|
274
622
|
try {
|
|
@@ -283,6 +631,24 @@ function updateWranglerConfigForCloudflare(code, options, context = {}) {
|
|
|
283
631
|
output = appendTopLevelJsonProperty(output, ` "main": ${JSON.stringify(workerEntry)}`);
|
|
284
632
|
}
|
|
285
633
|
if (!findTopLevelJsonProperty(output, "assets")) output = appendTopLevelJsonProperty(output, " \"assets\": { \"directory\": \"dist/client\", \"not_found_handling\": \"none\", \"binding\": \"ASSETS\" }");
|
|
634
|
+
if (options.cdnCache === "static-assets") {
|
|
635
|
+
const assetsProperty = findTopLevelJsonProperty(output, "assets");
|
|
636
|
+
const assets = JSON.parse(stripJsonComments(output.slice(assetsProperty.valueStart, assetsProperty.valueEnd)));
|
|
637
|
+
if (!assets || typeof assets !== "object" || Array.isArray(assets)) throw new Error("The existing Wrangler config has an invalid assets value.");
|
|
638
|
+
const workerFirst = assets.run_worker_first;
|
|
639
|
+
if (workerFirst !== void 0 && typeof workerFirst !== "boolean" && !Array.isArray(workerFirst)) throw new Error("The existing Wrangler config has an invalid assets.run_worker_first value.");
|
|
640
|
+
if (Array.isArray(workerFirst) && workerFirst.some((pattern) => typeof pattern !== "string" || pattern.startsWith("!"))) throw new Error("Static Assets cache requires run_worker_first without exclusion patterns. Use true or an array of positive path patterns.");
|
|
641
|
+
const protectedRouting = workerFirst === true ? true : [.../* @__PURE__ */ new Set([...Array.isArray(workerFirst) ? workerFirst : [], "/_vinext/static-cache/*"])];
|
|
642
|
+
if (typeof assets.directory !== "string" || assets.directory.length === 0 || typeof assets.binding !== "string" || assets.binding.length === 0 || JSON.stringify(workerFirst) !== JSON.stringify(protectedRouting)) {
|
|
643
|
+
const updatedAssets = JSON.stringify({
|
|
644
|
+
...assets,
|
|
645
|
+
...typeof assets.directory === "string" && assets.directory.length > 0 ? {} : { directory: "dist/client" },
|
|
646
|
+
...typeof assets.binding === "string" && assets.binding.length > 0 ? {} : { binding: "ASSETS" },
|
|
647
|
+
run_worker_first: protectedRouting
|
|
648
|
+
});
|
|
649
|
+
output = `${output.slice(0, assetsProperty.valueStart)}${updatedAssets}${output.slice(assetsProperty.valueEnd)}`;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
286
652
|
if (options.cdnCache === "workers-cache") {
|
|
287
653
|
const cacheProperty = findTopLevelJsonProperty(output, "cache");
|
|
288
654
|
if (!cacheProperty) output = appendTopLevelJsonProperty(output, " \"cache\": { \"enabled\": true }");
|
|
@@ -296,6 +662,12 @@ function updateWranglerConfigForCloudflare(code, options, context = {}) {
|
|
|
296
662
|
output = `${output.slice(0, cacheProperty.valueStart)}${updatedCache}${output.slice(cacheProperty.valueEnd)}`;
|
|
297
663
|
}
|
|
298
664
|
}
|
|
665
|
+
const versionMetadataProperty = findTopLevelJsonProperty(output, "version_metadata");
|
|
666
|
+
if (!versionMetadataProperty) output = appendTopLevelJsonProperty(output, ` "version_metadata": { "binding": "${DEFAULT_VERSION_METADATA_BINDING}" }`);
|
|
667
|
+
else {
|
|
668
|
+
const versionMetadata = JSON.parse(stripJsonComments(output.slice(versionMetadataProperty.valueStart, versionMetadataProperty.valueEnd)));
|
|
669
|
+
if (!versionMetadata || typeof versionMetadata.binding !== "string" || versionMetadata.binding.length === 0) output = `${output.slice(0, versionMetadataProperty.valueStart)}{ "binding": "${DEFAULT_VERSION_METADATA_BINDING}" }${output.slice(versionMetadataProperty.valueEnd)}`;
|
|
670
|
+
}
|
|
299
671
|
}
|
|
300
672
|
if (options.imageOptimization === "cloudflare-images") {
|
|
301
673
|
const imagesProperty = findTopLevelJsonProperty(output, "images");
|
|
@@ -307,17 +679,18 @@ function updateWranglerConfigForCloudflare(code, options, context = {}) {
|
|
|
307
679
|
}
|
|
308
680
|
if (options.dataCache === "kv") {
|
|
309
681
|
const kvProperty = findTopLevelJsonProperty(output, "kv_namespaces");
|
|
310
|
-
if (!kvProperty) output = appendTopLevelJsonProperty(output, " \"kv_namespaces\": [{ \"binding\": \"VINEXT_KV_CACHE\"
|
|
682
|
+
if (!kvProperty) output = appendTopLevelJsonProperty(output, " \"kv_namespaces\": [{ \"binding\": \"VINEXT_KV_CACHE\" }]");
|
|
311
683
|
else {
|
|
312
684
|
const rawValue = output.slice(kvProperty.valueStart, kvProperty.valueEnd);
|
|
313
685
|
if (!JSON.parse(stripJsonComments(rawValue)).some((namespace) => namespace.binding === "VINEXT_KV_CACHE")) {
|
|
314
686
|
const closing = kvProperty.valueEnd - 1;
|
|
315
687
|
const content = output.slice(kvProperty.valueStart + 1, closing);
|
|
316
688
|
const separator = content.trim() ? `${/,\s*$/.test(content) ? "" : ","}\n ` : "";
|
|
317
|
-
output = `${output.slice(0, closing)}${separator}{ "binding": "VINEXT_KV_CACHE"
|
|
689
|
+
output = `${output.slice(0, closing)}${separator}{ "binding": "VINEXT_KV_CACHE" }${output.slice(closing)}`;
|
|
318
690
|
}
|
|
319
691
|
}
|
|
320
692
|
}
|
|
693
|
+
if (options.cdnCache === "response-store") output = configureResponseStoreWrangler(output, config, options.responseStoreMode ?? "service-binding", context.root ?? process.cwd());
|
|
321
694
|
return output;
|
|
322
695
|
}
|
|
323
696
|
function getWranglerImagesBinding(code) {
|
|
@@ -326,40 +699,88 @@ function getWranglerImagesBinding(code) {
|
|
|
326
699
|
const images = JSON.parse(stripJsonComments(code.slice(property.valueStart, property.valueEnd)));
|
|
327
700
|
return images && typeof images.binding === "string" && images.binding.length > 0 ? images.binding : "IMAGES";
|
|
328
701
|
}
|
|
702
|
+
function getWranglerAssetsBinding(code) {
|
|
703
|
+
const property = findTopLevelJsonProperty(code, "assets");
|
|
704
|
+
if (!property) return "ASSETS";
|
|
705
|
+
const assets = JSON.parse(stripJsonComments(code.slice(property.valueStart, property.valueEnd)));
|
|
706
|
+
return assets && typeof assets.binding === "string" && assets.binding.length > 0 ? assets.binding : "ASSETS";
|
|
707
|
+
}
|
|
708
|
+
function getWranglerAssetsDirectory(code) {
|
|
709
|
+
const property = findTopLevelJsonProperty(code, "assets");
|
|
710
|
+
if (!property) return "dist/client";
|
|
711
|
+
const assets = JSON.parse(stripJsonComments(code.slice(property.valueStart, property.valueEnd)));
|
|
712
|
+
return assets && typeof assets.directory === "string" && assets.directory.length > 0 ? assets.directory : "dist/client";
|
|
713
|
+
}
|
|
714
|
+
function getWranglerVersionMetadataBinding(code) {
|
|
715
|
+
const property = findTopLevelJsonProperty(code, "version_metadata");
|
|
716
|
+
if (!property) return DEFAULT_VERSION_METADATA_BINDING;
|
|
717
|
+
const versionMetadata = JSON.parse(stripJsonComments(code.slice(property.valueStart, property.valueEnd)));
|
|
718
|
+
return versionMetadata && typeof versionMetadata.binding === "string" && versionMetadata.binding.length > 0 ? versionMetadata.binding : DEFAULT_VERSION_METADATA_BINDING;
|
|
719
|
+
}
|
|
329
720
|
function cacheImports(options) {
|
|
330
721
|
const imports = [];
|
|
331
722
|
if (options.dataCache === "kv") imports.push("import { kvDataAdapter } from \"@vinext/cloudflare/cache/kv-data-adapter\";");
|
|
332
|
-
if (options.cdnCache === "workers-cache") imports.push("import {
|
|
723
|
+
if (options.cdnCache === "workers-cache") imports.push("import { workersCacheCdnAdapter } from \"@vinext/cloudflare/cache/workers-cache-cdn-adapter\";");
|
|
724
|
+
if (options.cdnCache === "static-assets") imports.push("import { staticAssetsAdapter } from \"@vinext/cloudflare/cache/static-assets-adapter\";");
|
|
725
|
+
if (options.cdnCache === "response-store") imports.push("import { responseStoreAdapter } from \"@vinext/cloudflare/cache/response-store-adapter\";");
|
|
333
726
|
if (options.imageOptimization === "cloudflare-images") imports.push("import { imagesOptimizer } from \"@vinext/cloudflare/images/images-optimizer\";");
|
|
334
727
|
return imports;
|
|
335
728
|
}
|
|
336
|
-
function vinextExpression(options, binding = "vinext", imageBinding = "imagesOptimizer", imagesBinding = "IMAGES",
|
|
729
|
+
function vinextExpression(options, binding = "vinext", imageBinding = "imagesOptimizer", imagesBinding = "IMAGES", versionMetadataBinding = DEFAULT_VERSION_METADATA_BINDING, responseStoreBinding = "responseStoreAdapter", assetsBinding = "ASSETS", assetsDirectory = "dist/client") {
|
|
730
|
+
const responseStore = options.cdnCache === "response-store";
|
|
337
731
|
const cacheEntries = [];
|
|
338
732
|
if (options.dataCache === "kv") cacheEntries.push("data: kvDataAdapter()");
|
|
339
|
-
if (options.cdnCache === "workers-cache")
|
|
733
|
+
if (options.cdnCache === "workers-cache") {
|
|
734
|
+
const adapterOptions = versionMetadataBinding === DEFAULT_VERSION_METADATA_BINDING ? "" : `{ versionMetadataBinding: ${JSON.stringify(versionMetadataBinding)} }`;
|
|
735
|
+
cacheEntries.push(`cdn: workersCacheCdnAdapter(${adapterOptions})`);
|
|
736
|
+
}
|
|
737
|
+
if (options.cdnCache === "static-assets") {
|
|
738
|
+
const adapterOptions = assetsBinding === "ASSETS" ? "" : `{ binding: ${JSON.stringify(assetsBinding)} }`;
|
|
739
|
+
cacheEntries.push(`cdn: staticAssetsAdapter(${adapterOptions})`);
|
|
740
|
+
}
|
|
340
741
|
const optionEntries = [];
|
|
341
|
-
if (
|
|
742
|
+
if (responseStore) optionEntries.push(`cache: ${responseStoreBinding}(${options.responseStoreMode === "self-contained" ? "{ mode: \"self-contained\" }" : ""})`);
|
|
743
|
+
else if (cacheEntries.length > 0) optionEntries.push(`cache: { ${cacheEntries.join(", ")} }`);
|
|
744
|
+
if (options.cdnCache === "static-assets" || options.prerender) optionEntries.push("prerender: { routes: \"*\" }");
|
|
745
|
+
if (options.cdnCache === "static-assets") {
|
|
746
|
+
if (path.normalize(assetsDirectory) !== path.normalize("dist/client")) optionEntries.push(`clientOutDir: ${JSON.stringify(assetsDirectory)}`);
|
|
747
|
+
}
|
|
342
748
|
if (options.imageOptimization === "cloudflare-images") {
|
|
343
749
|
const adapterOptions = imagesBinding === "IMAGES" ? "" : `{ binding: ${JSON.stringify(imagesBinding)} }`;
|
|
344
750
|
optionEntries.push(`images: { optimizer: ${imageBinding}(${adapterOptions}) }`);
|
|
345
751
|
}
|
|
346
|
-
if (prerender) optionEntries.push(`prerender: { routes: "*" }`);
|
|
347
752
|
return optionEntries.length === 0 ? `${binding}()` : `${binding}({\n ${optionEntries.join(",\n ")},\n})`;
|
|
348
753
|
}
|
|
754
|
+
function scopedNameSource(indent, pathBinding = "path", hashBinding = "createHash", typescript = true) {
|
|
755
|
+
return `${indent}generateScopedName(${typescript ? "name: string, filename: string" : "name, filename"}) {
|
|
756
|
+
${indent} const relativePath = ${pathBinding}.relative(import.meta.dirname, filename.replace(/\\?.*$/, "")).replaceAll("\\\\", "/");
|
|
757
|
+
${indent} return \`_\${name}_\${${hashBinding}("sha256").update(relativePath).digest("hex").slice(0, 7)}\`;
|
|
758
|
+
${indent}}`;
|
|
759
|
+
}
|
|
760
|
+
function cssModulesConfigSource(indent = " ") {
|
|
761
|
+
return `\n${indent}css: {
|
|
762
|
+
${indent} modules: {
|
|
763
|
+
${scopedNameSource(`${indent} `)},
|
|
764
|
+
${indent} },
|
|
765
|
+
${indent}},`;
|
|
766
|
+
}
|
|
349
767
|
/** Generate vite.config.ts for App Router */
|
|
350
|
-
function generateAppRouterViteConfig(info, options = DEFAULT_CLOUDFLARE_INIT_OPTIONS, imagesBinding = "IMAGES",
|
|
768
|
+
function generateAppRouterViteConfig(info, options = DEFAULT_CLOUDFLARE_INIT_OPTIONS, imagesBinding = "IMAGES", versionMetadataBinding = DEFAULT_VERSION_METADATA_BINDING, serviceBinding = false, assetsBinding = "ASSETS", assetsDirectory = "dist/client", hasCssModules = false) {
|
|
351
769
|
const imports = [
|
|
352
770
|
`import { defineConfig } from "vite";`,
|
|
353
771
|
`import vinext from "vinext";`,
|
|
354
772
|
`import { cloudflare } from "@cloudflare/vite-plugin";`,
|
|
355
|
-
...
|
|
773
|
+
...serviceBinding ? ["import { responseStoreServiceBinding } from \"./cloudflare.config\";"] : [],
|
|
774
|
+
...cacheImports(options),
|
|
775
|
+
...hasCssModules ? ["import { createHash } from \"node:crypto\";", "import { patchCssModules } from \"vite-css-modules\";"] : []
|
|
356
776
|
];
|
|
357
|
-
if (info?.nativeModulesToStub && info.nativeModulesToStub.length > 0) imports.push(`import path from "node:path";`);
|
|
777
|
+
if (hasCssModules || info?.nativeModulesToStub && info.nativeModulesToStub.length > 0) imports.push(`import path from "node:path";`);
|
|
358
778
|
const plugins = [];
|
|
779
|
+
if (hasCssModules) plugins.push(" patchCssModules({ exportMode: \"default\" }),");
|
|
359
780
|
if (info?.hasMDX) plugins.push(` // vinext auto-injects @mdx-js/rollup with plugins from next.config`);
|
|
360
|
-
plugins.push(` ${vinextExpression(options, "vinext", "imagesOptimizer", imagesBinding,
|
|
781
|
+
plugins.push(` ${vinextExpression(options, "vinext", "imagesOptimizer", imagesBinding, versionMetadataBinding, "responseStoreAdapter", assetsBinding, assetsDirectory).replace(/\n/g, "\n ")},`);
|
|
361
782
|
plugins.push(` cloudflare({
|
|
362
|
-
viteEnvironment: {
|
|
783
|
+
${serviceBinding ? "auxiliaryWorkers: [{ config: responseStoreServiceBinding }],\n " : ""}viteEnvironment: {
|
|
363
784
|
name: "rsc",
|
|
364
785
|
childEnvironments: ["ssr"],
|
|
365
786
|
},
|
|
@@ -373,19 +794,21 @@ function generateAppRouterViteConfig(info, options = DEFAULT_CLOUDFLARE_INIT_OPT
|
|
|
373
794
|
export default defineConfig({
|
|
374
795
|
plugins: [
|
|
375
796
|
${plugins.join("\n")}
|
|
376
|
-
],${resolveBlock}
|
|
797
|
+
],${resolveBlock}${hasCssModules ? cssModulesConfigSource() : ""}
|
|
377
798
|
});
|
|
378
799
|
`;
|
|
379
800
|
}
|
|
380
801
|
/** Generate vite.config.ts for Pages Router */
|
|
381
|
-
function generatePagesRouterViteConfig(info, options = DEFAULT_CLOUDFLARE_INIT_OPTIONS, imagesBinding = "IMAGES",
|
|
802
|
+
function generatePagesRouterViteConfig(info, options = DEFAULT_CLOUDFLARE_INIT_OPTIONS, imagesBinding = "IMAGES", versionMetadataBinding = DEFAULT_VERSION_METADATA_BINDING, serviceBinding = false, hasCssModules = false) {
|
|
382
803
|
const imports = [
|
|
383
804
|
`import { defineConfig } from "vite";`,
|
|
384
805
|
`import vinext from "vinext";`,
|
|
385
806
|
`import { cloudflare } from "@cloudflare/vite-plugin";`,
|
|
386
|
-
...
|
|
807
|
+
...serviceBinding ? ["import { responseStoreServiceBinding } from \"./cloudflare.config\";"] : [],
|
|
808
|
+
...cacheImports(options),
|
|
809
|
+
...hasCssModules ? ["import { createHash } from \"node:crypto\";", "import { patchCssModules } from \"vite-css-modules\";"] : []
|
|
387
810
|
];
|
|
388
|
-
if (info?.nativeModulesToStub && info.nativeModulesToStub.length > 0) imports.push(`import path from "node:path";`);
|
|
811
|
+
if (hasCssModules || info?.nativeModulesToStub && info.nativeModulesToStub.length > 0) imports.push(`import path from "node:path";`);
|
|
389
812
|
let resolveBlock = "";
|
|
390
813
|
const aliases = [];
|
|
391
814
|
if (info?.nativeModulesToStub && info.nativeModulesToStub.length > 0) for (const mod of info.nativeModulesToStub) aliases.push(` "${mod}": path.resolve(__dirname, "empty-stub.js"),`);
|
|
@@ -394,9 +817,9 @@ function generatePagesRouterViteConfig(info, options = DEFAULT_CLOUDFLARE_INIT_O
|
|
|
394
817
|
|
|
395
818
|
export default defineConfig({
|
|
396
819
|
plugins: [
|
|
397
|
-
${vinextExpression(options, "vinext", "imagesOptimizer", imagesBinding,
|
|
398
|
-
cloudflare(),
|
|
399
|
-
],${resolveBlock}
|
|
820
|
+
${hasCssModules ? " patchCssModules({ exportMode: \"default\" }),\n" : ""} ${vinextExpression(options, "vinext", "imagesOptimizer", imagesBinding, versionMetadataBinding).replace(/\n/g, "\n ")},
|
|
821
|
+
cloudflare(${serviceBinding ? "{ auxiliaryWorkers: [{ config: responseStoreServiceBinding }] }" : ""}),
|
|
822
|
+
],${resolveBlock}${hasCssModules ? cssModulesConfigSource() : ""}
|
|
400
823
|
});
|
|
401
824
|
`;
|
|
402
825
|
}
|
|
@@ -532,14 +955,17 @@ function allocateBinding(bindings, preferred) {
|
|
|
532
955
|
}
|
|
533
956
|
function findImportedBinding(program, source, imported) {
|
|
534
957
|
for (const statement of program.body) {
|
|
535
|
-
if (statement.type !== "ImportDeclaration" || statement.source.value !== source) continue;
|
|
536
|
-
for (const specifier of statement.specifiers) if (specifier.type === "ImportSpecifier" && specifier.imported.type === "Identifier" && specifier.imported.name === imported) return specifier.local.name;
|
|
958
|
+
if (statement.type !== "ImportDeclaration" || statement.importKind === "type" || statement.source.value !== source) continue;
|
|
959
|
+
for (const specifier of statement.specifiers) if (specifier.type === "ImportSpecifier" && specifier.importKind !== "type" && specifier.imported.type === "Identifier" && specifier.imported.name === imported) return specifier.local.name;
|
|
537
960
|
}
|
|
538
961
|
}
|
|
962
|
+
function quoteImportSource(program, source) {
|
|
963
|
+
return program.body.find((statement) => statement.type === "ImportDeclaration")?.source.raw?.startsWith("'") ? `'${source.replaceAll("\\", "\\\\").replaceAll("'", "\\'")}'` : JSON.stringify(source);
|
|
964
|
+
}
|
|
539
965
|
function ensureNamedImport(program, output, source, imported, binding) {
|
|
540
966
|
const existing = findImportedBinding(program, source, imported);
|
|
541
967
|
if (existing) return existing;
|
|
542
|
-
const declaration = program.body.find((statement) => statement.type === "ImportDeclaration" && statement.source.value === source);
|
|
968
|
+
const declaration = program.body.find((statement) => statement.type === "ImportDeclaration" && statement.importKind !== "type" && statement.source.value === source);
|
|
543
969
|
if (declaration) {
|
|
544
970
|
const named = declaration.specifiers.filter((specifier) => specifier.type === "ImportSpecifier");
|
|
545
971
|
if (named.length > 0) {
|
|
@@ -549,15 +975,15 @@ function ensureNamedImport(program, output, source, imported, binding) {
|
|
|
549
975
|
}
|
|
550
976
|
}
|
|
551
977
|
const offset = importInsertionOffset(program);
|
|
552
|
-
const sourceText = `import { ${binding === imported ? imported : `${imported} as ${binding}`} } from ${
|
|
978
|
+
const sourceText = `import { ${binding === imported ? imported : `${imported} as ${binding}`} } from ${quoteImportSource(program, source)};`;
|
|
553
979
|
output.appendLeft(offset, offset === 0 ? `${sourceText}\n` : `\n${sourceText}`);
|
|
554
980
|
return binding;
|
|
555
981
|
}
|
|
556
982
|
function ensureDefaultImport(program, output, source, binding) {
|
|
557
|
-
const existing = program.body.find((statement) => statement.type === "ImportDeclaration" && statement.source.value === source)?.specifiers.find((specifier) => specifier.type === "ImportDefaultSpecifier");
|
|
983
|
+
const existing = program.body.find((statement) => statement.type === "ImportDeclaration" && statement.importKind !== "type" && statement.source.value === source)?.specifiers.find((specifier) => specifier.type === "ImportDefaultSpecifier");
|
|
558
984
|
if (existing) return existing.local.name;
|
|
559
985
|
const offset = importInsertionOffset(program);
|
|
560
|
-
const sourceText = `import ${binding} from ${
|
|
986
|
+
const sourceText = `import ${binding} from ${quoteImportSource(program, source)};`;
|
|
561
987
|
output.appendLeft(offset, offset === 0 ? `${sourceText}\n` : `\n${sourceText}`);
|
|
562
988
|
return binding;
|
|
563
989
|
}
|
|
@@ -596,11 +1022,50 @@ function ensureDefaultRequire(program, output, source, binding) {
|
|
|
596
1022
|
output.appendLeft(offset, offset === 0 ? `${sourceText}\n` : `\n${sourceText}`);
|
|
597
1023
|
return binding;
|
|
598
1024
|
}
|
|
1025
|
+
const insertedCommas = /* @__PURE__ */ new WeakMap();
|
|
599
1026
|
function insertObjectProperty(output, object, source, code) {
|
|
600
1027
|
const offset = object.end - 1;
|
|
601
|
-
const
|
|
602
|
-
|
|
603
|
-
|
|
1028
|
+
const lastProperty = object.properties.at(-1);
|
|
1029
|
+
if (lastProperty) {
|
|
1030
|
+
const gap = code.slice(lastProperty.end, offset);
|
|
1031
|
+
if (!endsWithCommaIgnoringWhitespaceAndComments(gap) && !insertedCommas.get(output)?.has(lastProperty.end)) {
|
|
1032
|
+
if (/^[ \t]+$/.test(gap)) output.update(lastProperty.end, offset, ",");
|
|
1033
|
+
else output.appendLeft(lastProperty.end, ",");
|
|
1034
|
+
const offsets = insertedCommas.get(output) ?? /* @__PURE__ */ new Set();
|
|
1035
|
+
offsets.add(lastProperty.end);
|
|
1036
|
+
insertedCommas.set(output, offsets);
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
output.appendLeft(offset, `\n${source}\n`);
|
|
1040
|
+
}
|
|
1041
|
+
function formatInlineConfig(filePath, code, originalCode) {
|
|
1042
|
+
if (code === originalCode) return code;
|
|
1043
|
+
const config = findConfigObject(parseViteConfig(filePath, code));
|
|
1044
|
+
if (!config || config.properties.length === 0) return code;
|
|
1045
|
+
const output = new MagicString(code);
|
|
1046
|
+
const lineStart = code.lastIndexOf("\n", config.start) + 1;
|
|
1047
|
+
const indent = code.slice(lineStart, config.start).match(/^[ \t]*/)?.[0] ?? "";
|
|
1048
|
+
const properties = config.properties;
|
|
1049
|
+
const first = properties[0];
|
|
1050
|
+
const opening = code.slice(config.start + 1, first.start);
|
|
1051
|
+
if (/^[ \t]*$/.test(opening)) {
|
|
1052
|
+
if (opening) output.update(config.start + 1, first.start, `\n${indent} `);
|
|
1053
|
+
else output.appendLeft(first.start, `\n${indent} `);
|
|
1054
|
+
}
|
|
1055
|
+
for (let index = 1; index < properties.length; index++) {
|
|
1056
|
+
const previous = properties[index - 1];
|
|
1057
|
+
const current = properties[index];
|
|
1058
|
+
const gap = code.slice(previous.end, current.start);
|
|
1059
|
+
if (/^,[ \t]*$/.test(gap)) output.update(previous.end, current.start, `,\n${indent} `);
|
|
1060
|
+
}
|
|
1061
|
+
const last = properties.at(-1);
|
|
1062
|
+
const closing = code.slice(last.end, config.end - 1);
|
|
1063
|
+
if (/^,?[ \t]*$/.test(closing)) {
|
|
1064
|
+
const replacement = `${closing.includes(",") ? "," : ""}\n${indent}`;
|
|
1065
|
+
if (closing) output.update(last.end, config.end - 1, replacement);
|
|
1066
|
+
else output.appendLeft(last.end, replacement);
|
|
1067
|
+
}
|
|
1068
|
+
return output.toString();
|
|
604
1069
|
}
|
|
605
1070
|
function endsWithCommaIgnoringWhitespaceAndComments(code) {
|
|
606
1071
|
let index = 0;
|
|
@@ -671,11 +1136,20 @@ function findPluginCall(config, binding) {
|
|
|
671
1136
|
if (!plugins || plugins.value.type !== "ArrayExpression") return void 0;
|
|
672
1137
|
return plugins.value.elements.find((element) => element?.type === "CallExpression" && element.callee.type === "Identifier" && element.callee.name === binding);
|
|
673
1138
|
}
|
|
674
|
-
function
|
|
1139
|
+
function getVinextCacheSlot(call, name) {
|
|
675
1140
|
const firstArgument = call?.arguments[0];
|
|
676
|
-
if (!firstArgument || firstArgument.type === "SpreadElement" || firstArgument.type !== "ObjectExpression") return
|
|
1141
|
+
if (!firstArgument || firstArgument.type === "SpreadElement" || firstArgument.type !== "ObjectExpression") return;
|
|
677
1142
|
const cache = findProperty(firstArgument, "cache");
|
|
678
|
-
|
|
1143
|
+
if (cache?.value.type !== "ObjectExpression") return void 0;
|
|
1144
|
+
return findProperty(cache.value, name);
|
|
1145
|
+
}
|
|
1146
|
+
function getVinextCacheOption(call) {
|
|
1147
|
+
const firstArgument = call?.arguments[0];
|
|
1148
|
+
if (!firstArgument || firstArgument.type === "SpreadElement" || firstArgument.type !== "ObjectExpression") return;
|
|
1149
|
+
return findProperty(firstArgument, "cache");
|
|
1150
|
+
}
|
|
1151
|
+
function hasVinextCacheSlot(call, name) {
|
|
1152
|
+
return Boolean(getVinextCacheSlot(call, name));
|
|
679
1153
|
}
|
|
680
1154
|
function getVinextImageOptimizer(call) {
|
|
681
1155
|
const firstArgument = call?.arguments[0];
|
|
@@ -684,11 +1158,6 @@ function getVinextImageOptimizer(call) {
|
|
|
684
1158
|
if (images?.value.type !== "ObjectExpression") return void 0;
|
|
685
1159
|
return findProperty(images.value, "optimizer");
|
|
686
1160
|
}
|
|
687
|
-
function hasVinextPrerender(call) {
|
|
688
|
-
const firstArgument = call?.arguments[0];
|
|
689
|
-
if (!firstArgument || firstArgument.type === "SpreadElement" || firstArgument.type !== "ObjectExpression") return false;
|
|
690
|
-
return Boolean(findProperty(firstArgument, "prerender"));
|
|
691
|
-
}
|
|
692
1161
|
function isUsableImageOptimizer(property) {
|
|
693
1162
|
if (!property) return false;
|
|
694
1163
|
const value = property.value;
|
|
@@ -718,6 +1187,17 @@ function ensureVinextCache(output, config, vinextBinding, additions, code) {
|
|
|
718
1187
|
const missing = additions.filter(({ name }) => !findProperty(cacheObject, name));
|
|
719
1188
|
if (missing.length > 0) insertObjectProperty(output, cacheObject, missing.map(({ name, expression }) => ` ${name}: ${expression},`).join("\n"), code);
|
|
720
1189
|
}
|
|
1190
|
+
function ensureVinextResponseStore(output, config, vinextBinding, expression, code) {
|
|
1191
|
+
if (!expression) return;
|
|
1192
|
+
const call = findPluginCall(config, vinextBinding);
|
|
1193
|
+
const firstArgument = call?.arguments[0];
|
|
1194
|
+
if (!call || !firstArgument || firstArgument.type === "SpreadElement") return;
|
|
1195
|
+
if (firstArgument.type !== "ObjectExpression") throw new Error("The vinext() plugin options must be a static object for vinext init to configure Workers Response Store.");
|
|
1196
|
+
const optionsObject = firstArgument;
|
|
1197
|
+
const cache = findProperty(optionsObject, "cache");
|
|
1198
|
+
if (!cache) insertObjectProperty(output, optionsObject, ` cache: ${expression},`, code);
|
|
1199
|
+
else if (cache.value.type === "ObjectExpression" && cache.value.properties.length === 0) output.overwrite(cache.value.start, cache.value.end, expression);
|
|
1200
|
+
}
|
|
721
1201
|
function ensureVinextImageOptimizer(output, config, vinextBinding, expression, code) {
|
|
722
1202
|
if (!expression) return;
|
|
723
1203
|
const call = findPluginCall(config, vinextBinding);
|
|
@@ -740,17 +1220,28 @@ function ensureVinextImageOptimizer(output, config, vinextBinding, expression, c
|
|
|
740
1220
|
if (!optimizer) insertObjectProperty(output, imagesObject, ` optimizer: ${expression},`, code);
|
|
741
1221
|
else output.overwrite(optimizer.value.start, optimizer.value.end, expression);
|
|
742
1222
|
}
|
|
743
|
-
function
|
|
744
|
-
if (!prerender) return;
|
|
1223
|
+
function ensureVinextPrerenderOptions(output, config, vinextBinding, assetsDirectory, code) {
|
|
745
1224
|
const call = findPluginCall(config, vinextBinding);
|
|
746
|
-
|
|
747
|
-
if (call.
|
|
748
|
-
|
|
749
|
-
|
|
1225
|
+
const firstArgument = call?.arguments[0];
|
|
1226
|
+
if (!call || !firstArgument || firstArgument.type === "SpreadElement") return;
|
|
1227
|
+
if (firstArgument.type !== "ObjectExpression") throw new Error("The vinext() plugin options must be a static object for vinext init to configure build-time prerendering.");
|
|
1228
|
+
const optionsObject = firstArgument;
|
|
1229
|
+
const additions = [];
|
|
1230
|
+
const prerender = findProperty(optionsObject, "prerender");
|
|
1231
|
+
if (!prerender) additions.push(" prerender: { routes: \"*\" },");
|
|
1232
|
+
else {
|
|
1233
|
+
const value = prerender.value;
|
|
1234
|
+
if (value.type === "Literal" && (value.value === false || value.value === null) || value.type === "Identifier" && value.name === "undefined") output.overwrite(value.start, value.end, "{ routes: \"*\" }");
|
|
750
1235
|
}
|
|
751
|
-
const
|
|
752
|
-
if (
|
|
753
|
-
|
|
1236
|
+
const clientOutDir = assetsDirectory && findProperty(optionsObject, "clientOutDir");
|
|
1237
|
+
if (assetsDirectory && !clientOutDir) {
|
|
1238
|
+
if (path.normalize(assetsDirectory) !== path.normalize("dist/client")) additions.push(` clientOutDir: ${JSON.stringify(assetsDirectory)},`);
|
|
1239
|
+
} else if (assetsDirectory && clientOutDir) {
|
|
1240
|
+
const value = clientOutDir.value;
|
|
1241
|
+
if (value.type !== "Literal" || typeof value.value !== "string") throw new Error("The vinext() clientOutDir option must be a string literal for vinext init to align it with Wrangler assets.directory.");
|
|
1242
|
+
if (path.normalize(value.value) !== path.normalize(assetsDirectory)) throw new Error(`The vinext() clientOutDir (${JSON.stringify(value.value)}) must match Wrangler assets.directory (${JSON.stringify(assetsDirectory)}) when using the Static Assets cache.`);
|
|
1243
|
+
}
|
|
1244
|
+
if (additions.length > 0) insertObjectProperty(output, optionsObject, additions.join("\n"), code);
|
|
754
1245
|
}
|
|
755
1246
|
function indentBlock(source, indent) {
|
|
756
1247
|
return source.split("\n").map((line) => `${indent}${line}`).join("\n");
|
|
@@ -763,8 +1254,9 @@ function ensurePlugins(output, config, additions, code) {
|
|
|
763
1254
|
}
|
|
764
1255
|
if (plugins.value.type !== "ArrayExpression") throw new Error("The Vite config's plugins option must be an array for vinext init to update it.");
|
|
765
1256
|
const array = plugins.value;
|
|
766
|
-
const propertyIndent = code.slice(0, plugins.start).split("\n").at(-1)?.match(
|
|
767
|
-
const
|
|
1257
|
+
const propertyIndent = code.slice(0, plugins.start).split("\n").at(-1)?.match(/^[ \t]*/)?.[0] ?? "";
|
|
1258
|
+
const inlinePropertyIndent = code.slice(config.start, plugins.start).includes("\n") ? propertyIndent : `${propertyIndent} `;
|
|
1259
|
+
const elementIndent = `${inlinePropertyIndent} `;
|
|
768
1260
|
const missingExpressions = [];
|
|
769
1261
|
for (const addition of additions) if (!array.elements.some((element) => element?.type === "CallExpression" && element.callee.type === "Identifier" && element.callee.name === addition.binding)) missingExpressions.push(addition.expression);
|
|
770
1262
|
if (missingExpressions.length === 0) return;
|
|
@@ -793,7 +1285,91 @@ function ensurePlugins(output, config, additions, code) {
|
|
|
793
1285
|
previousElement = element;
|
|
794
1286
|
}
|
|
795
1287
|
}
|
|
796
|
-
output.appendLeft(closingOffset, `${prefix}\n${missingExpressions.map((expression) => indentBlock(expression, elementIndent)).join(",\n")},\n${
|
|
1288
|
+
output.appendLeft(closingOffset, `${prefix}\n${missingExpressions.map((expression) => indentBlock(expression, elementIndent)).join(",\n")},\n${inlinePropertyIndent}`);
|
|
1289
|
+
}
|
|
1290
|
+
function simpleCssConfig(program) {
|
|
1291
|
+
const value = program.body.find((statement) => statement.type === "ExportDefaultDeclaration")?.declaration;
|
|
1292
|
+
const direct = value && value.type !== "FunctionDeclaration" && value.type !== "ClassDeclaration" ? unwrapObject(value) : void 0;
|
|
1293
|
+
if (direct) return direct;
|
|
1294
|
+
if (value?.type === "CallExpression" && value.callee.type === "Identifier" && value.callee.name === findImportedBinding(program, "vite", "defineConfig") && value.arguments[0]?.type === "ObjectExpression") return value.arguments[0];
|
|
1295
|
+
throw new Error("CSS Modules require an inline Vite config object (export default { ... } or defineConfig({ ... })). Convert a dynamic config to an inline object before running vinext init, or finish migration manually with patchCssModules({ exportMode: \"default\" }) and a deterministic css.modules.generateScopedName.");
|
|
1296
|
+
}
|
|
1297
|
+
function simpleProperties(object) {
|
|
1298
|
+
const names = /* @__PURE__ */ new Set();
|
|
1299
|
+
for (const property of object.properties) {
|
|
1300
|
+
const name = property.type === "Property" ? propertyName(property) : void 0;
|
|
1301
|
+
if (!name || property.type !== "Property" || property.kind !== "init" || names.has(name)) throw new Error("CSS Modules cannot safely update Vite config spreads, computed keys, accessors, or duplicate properties. Add patchCssModules({ exportMode: \"default\" }) before vinext() and a deterministic css.modules.generateScopedName manually.");
|
|
1302
|
+
names.add(name);
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
function updateViteConfigForCssModules(filePath, code) {
|
|
1306
|
+
const program = parseViteConfig(filePath, code);
|
|
1307
|
+
const config = simpleCssConfig(program);
|
|
1308
|
+
simpleProperties(config);
|
|
1309
|
+
const css = findProperty(config, "css");
|
|
1310
|
+
const cssObject = css?.value.type === "ObjectExpression" ? css.value : void 0;
|
|
1311
|
+
if (css && !cssObject) throw new Error("CSS Modules require a literal css config object.");
|
|
1312
|
+
if (cssObject) simpleProperties(cssObject);
|
|
1313
|
+
const modules = cssObject && findProperty(cssObject, "modules");
|
|
1314
|
+
const modulesObject = modules?.value.type === "ObjectExpression" ? modules.value : void 0;
|
|
1315
|
+
if (modules && !modulesObject) throw new Error("CSS Modules require a literal css.modules object.");
|
|
1316
|
+
if (modulesObject) simpleProperties(modulesObject);
|
|
1317
|
+
const existingName = modulesObject && findProperty(modulesObject, "generateScopedName");
|
|
1318
|
+
if (existingName) {
|
|
1319
|
+
const value = existingName.value;
|
|
1320
|
+
if (value.type !== "FunctionExpression" && value.type !== "ArrowFunctionExpression" && !(value.type === "Literal" && typeof value.value === "string" && !/\[hash(?::[^\]]*)?\]/i.test(value.value))) throw new Error("CSS Modules need a deterministic generateScopedName function; replace the existing hash template or dynamic value manually.");
|
|
1321
|
+
}
|
|
1322
|
+
const firstOutput = new MagicString(code);
|
|
1323
|
+
if (!existingName) {
|
|
1324
|
+
const bindings = collectTopLevelBindings(program);
|
|
1325
|
+
const hashBinding = ensureNamedImport(program, firstOutput, "node:crypto", "createHash", allocateBinding(bindings, "createHash"));
|
|
1326
|
+
const source = scopedNameSource(" ", ensureDefaultImport(program, firstOutput, "node:path", allocateBinding(bindings, "path")), hashBinding, [
|
|
1327
|
+
".ts",
|
|
1328
|
+
".mts",
|
|
1329
|
+
".cts"
|
|
1330
|
+
].includes(path.extname(filePath)));
|
|
1331
|
+
if (modulesObject) insertObjectProperty(firstOutput, modulesObject, `${source},`, code);
|
|
1332
|
+
else if (cssObject) insertObjectProperty(firstOutput, cssObject, ` modules: {\n${source},\n },`, code);
|
|
1333
|
+
else insertObjectProperty(firstOutput, config, ` css: {\n modules: {\n${source},\n },\n },`, code);
|
|
1334
|
+
}
|
|
1335
|
+
const withCss = firstOutput.toString();
|
|
1336
|
+
const nextProgram = parseViteConfig(filePath, withCss);
|
|
1337
|
+
const nextConfig = simpleCssConfig(nextProgram);
|
|
1338
|
+
const plugins = findProperty(nextConfig, "plugins");
|
|
1339
|
+
const pluginArray = plugins?.value.type === "ArrayExpression" ? plugins.value : void 0;
|
|
1340
|
+
if (plugins && !pluginArray) throw new Error("CSS Modules require a literal plugins array.");
|
|
1341
|
+
if (pluginArray?.elements.some((element) => element?.type === "SpreadElement")) throw new Error("CSS Modules cannot safely update a plugins array containing spreads.");
|
|
1342
|
+
if (pluginArray?.elements.some((element) => element && element.type !== "CallExpression")) throw new Error("CSS Modules require direct plugin calls in the plugins array.");
|
|
1343
|
+
const existingBinding = findImportedBinding(nextProgram, "vite-css-modules", "patchCssModules");
|
|
1344
|
+
const namespaceBinding = nextProgram.body.filter((statement) => statement.type === "ImportDeclaration" && statement.importKind !== "type" && statement.source.value === "vite-css-modules").flatMap((statement) => statement.specifiers).find((specifier) => specifier.type === "ImportNamespaceSpecifier")?.local.name;
|
|
1345
|
+
const existingCall = pluginArray?.elements.find((element) => element?.type === "CallExpression" && (element.callee.type === "Identifier" && element.callee.name === (existingBinding ?? "patchCssModules") || element.callee.type === "MemberExpression" && !element.callee.computed && element.callee.property.type === "Identifier" && element.callee.property.name === "patchCssModules"));
|
|
1346
|
+
if (existingCall?.type === "CallExpression") {
|
|
1347
|
+
const callee = existingCall.callee;
|
|
1348
|
+
if (callee.type === "Identifier" && callee.name !== existingBinding || callee.type === "MemberExpression" && (callee.object.type !== "Identifier" || callee.object.name !== namespaceBinding)) throw new Error("Import patchCssModules from \"vite-css-modules\" before configuring CSS Modules.");
|
|
1349
|
+
const argument = existingCall.arguments[0];
|
|
1350
|
+
if (argument?.type === "ObjectExpression") simpleProperties(argument);
|
|
1351
|
+
const mode = argument?.type === "ObjectExpression" ? findProperty(argument, "exportMode") : void 0;
|
|
1352
|
+
if (argument?.type !== "ObjectExpression" || argument.properties.some((property) => property.type !== "Property" || property.computed) || mode?.value.type !== "Literal" || mode.value.value !== "default") throw new Error("Set the existing patchCssModules plugin to exportMode: \"default\" for CSS classes named \"default\".");
|
|
1353
|
+
} else {
|
|
1354
|
+
const output = new MagicString(withCss);
|
|
1355
|
+
const expression = `${ensureNamedImport(nextProgram, output, "vite-css-modules", "patchCssModules", allocateBinding(collectTopLevelBindings(nextProgram), "patchCssModules"))}({ exportMode: "default" })`;
|
|
1356
|
+
if (!pluginArray) insertObjectProperty(output, nextConfig, ` plugins: [${expression}],`, withCss);
|
|
1357
|
+
else {
|
|
1358
|
+
const first = pluginArray.elements.find(Boolean);
|
|
1359
|
+
output.appendLeft(first ? first.start : pluginArray.end - 1, first ? `${expression}, ` : expression);
|
|
1360
|
+
}
|
|
1361
|
+
const updated = output.toString();
|
|
1362
|
+
parseViteConfig(filePath, updated);
|
|
1363
|
+
return {
|
|
1364
|
+
code: formatInlineConfig(filePath, updated, code),
|
|
1365
|
+
preservedExistingGenerateScopedName: Boolean(existingName)
|
|
1366
|
+
};
|
|
1367
|
+
}
|
|
1368
|
+
parseViteConfig(filePath, withCss);
|
|
1369
|
+
return {
|
|
1370
|
+
code: formatInlineConfig(filePath, withCss, code),
|
|
1371
|
+
preservedExistingGenerateScopedName: Boolean(existingName)
|
|
1372
|
+
};
|
|
797
1373
|
}
|
|
798
1374
|
function ensureNativeAliases(output, config, modules, pathBinding, code) {
|
|
799
1375
|
if (modules.length === 0) return;
|
|
@@ -818,11 +1394,7 @@ function ensureNativeAliases(output, config, modules, pathBinding, code) {
|
|
|
818
1394
|
}
|
|
819
1395
|
function updateViteConfigForCloudflare(filePath, code, options) {
|
|
820
1396
|
const program = parseViteConfig(filePath, code);
|
|
821
|
-
const cacheOptions = options.cache ??
|
|
822
|
-
dataCache: "none",
|
|
823
|
-
cdnCache: "workers-cache",
|
|
824
|
-
imageOptimization: "cloudflare-images"
|
|
825
|
-
};
|
|
1397
|
+
const cacheOptions = options.cache ?? DEFAULT_CLOUDFLARE_INIT_OPTIONS;
|
|
826
1398
|
const config = findConfigObject(program);
|
|
827
1399
|
if (!config) throw new Error(`Could not find a static Vite config object in ${path.basename(filePath)}. Use an object export or defineConfig({...}) so vinext init can update it.`);
|
|
828
1400
|
const output = new MagicString(code);
|
|
@@ -832,9 +1404,45 @@ function updateViteConfigForCloudflare(filePath, code, options) {
|
|
|
832
1404
|
const vinextBinding = commonJs ? ensureDefaultRequire(program, output, "vinext", vinextLocal) : ensureDefaultImport(program, output, "vinext", vinextLocal);
|
|
833
1405
|
const existingVinextCall = findPluginCall(config, vinextBinding);
|
|
834
1406
|
const existingImageOptimizer = getVinextImageOptimizer(existingVinextCall);
|
|
835
|
-
const needsPrerender = Boolean(options.prerender && !hasVinextPrerender(existingVinextCall));
|
|
836
1407
|
const configureCaches = options.cache !== void 0;
|
|
1408
|
+
const existingCache = getVinextCacheOption(existingVinextCall);
|
|
1409
|
+
if (configureCaches && existingCache) {
|
|
1410
|
+
const cacheObject = existingCache.value.type === "ObjectExpression" ? existingCache.value : void 0;
|
|
1411
|
+
if (!cacheObject && cacheOptions.cdnCache !== "response-store" || cacheObject && (cacheOptions.cdnCache === "none" || cacheOptions.cdnCache === "data-cache") && findProperty(cacheObject, "cdn") || cacheObject && cacheOptions.dataCache === "none" && findProperty(cacheObject, "data")) throw new Error("The existing vinext() cache configuration does not match the selected cache options. Remove it before rerunning vinext init.");
|
|
1412
|
+
}
|
|
837
1413
|
const cacheAdditions = [];
|
|
1414
|
+
let responseStoreExpression;
|
|
1415
|
+
let responseStoreBinding = "responseStoreAdapter";
|
|
1416
|
+
if (configureCaches && cacheOptions.cdnCache === "response-store") {
|
|
1417
|
+
const source = "@vinext/cloudflare/cache/response-store-adapter";
|
|
1418
|
+
const imported = "responseStoreAdapter";
|
|
1419
|
+
const existing = commonJs ? findRequiredBinding(program, source, imported) : findImportedBinding(program, source, imported);
|
|
1420
|
+
const cache = getVinextCacheOption(existingVinextCall);
|
|
1421
|
+
const alreadyConfigured = Boolean(existing && cache?.value.type === "CallExpression" && cache.value.callee.type === "Identifier" && cache.value.callee.name === existing);
|
|
1422
|
+
if (cache && !alreadyConfigured && !(cache.value.type === "ObjectExpression" && cache.value.properties.length === 0)) throw new Error("The vinext() cache option is already configured. Remove it before configuring Workers Response Store.");
|
|
1423
|
+
if (!cache || alreadyConfigured || cache.value.type === "ObjectExpression" && cache.value.properties.length === 0) {
|
|
1424
|
+
const local = existing ?? allocateBinding(bindings, imported);
|
|
1425
|
+
const binding = commonJs ? ensureNamedRequire(program, output, source, imported, local) : ensureNamedImport(program, output, source, imported, local);
|
|
1426
|
+
responseStoreBinding = binding;
|
|
1427
|
+
responseStoreExpression = `${binding}(${cacheOptions.responseStoreMode === "self-contained" ? "{ mode: \"self-contained\" }" : ""})`;
|
|
1428
|
+
if (alreadyConfigured && cache) {
|
|
1429
|
+
const call = cache.value;
|
|
1430
|
+
const argument = call.arguments[0];
|
|
1431
|
+
const mode = cacheOptions.responseStoreMode ?? "service-binding";
|
|
1432
|
+
if (!argument) {
|
|
1433
|
+
if (mode === "self-contained") output.appendLeft(call.end - 1, "{ mode: \"self-contained\" }");
|
|
1434
|
+
} else if (argument.type === "ObjectExpression") {
|
|
1435
|
+
const optionsObject = argument;
|
|
1436
|
+
const existingMode = findProperty(optionsObject, "mode");
|
|
1437
|
+
if (existingMode) {
|
|
1438
|
+
if (existingMode.shorthand) output.overwrite(existingMode.start, existingMode.end, `mode: ${JSON.stringify(mode)}`);
|
|
1439
|
+
else output.overwrite(existingMode.value.start, existingMode.value.end, JSON.stringify(mode));
|
|
1440
|
+
} else if (mode === "self-contained") insertObjectProperty(output, optionsObject, " mode: \"self-contained\",", code);
|
|
1441
|
+
} else throw new Error("responseStoreAdapter() options must be a static object for vinext init to update its mode.");
|
|
1442
|
+
responseStoreExpression = void 0;
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
838
1446
|
if (cacheOptions.dataCache === "kv" && !hasVinextCacheSlot(existingVinextCall, "data")) {
|
|
839
1447
|
const local = (commonJs ? findRequiredBinding(program, "@vinext/cloudflare/cache/kv-data-adapter", "kvDataAdapter") : findImportedBinding(program, "@vinext/cloudflare/cache/kv-data-adapter", "kvDataAdapter")) ?? allocateBinding(bindings, "kvDataAdapter");
|
|
840
1448
|
const binding = commonJs ? ensureNamedRequire(program, output, "@vinext/cloudflare/cache/kv-data-adapter", "kvDataAdapter", local) : ensureNamedImport(program, output, "@vinext/cloudflare/cache/kv-data-adapter", "kvDataAdapter", local);
|
|
@@ -843,15 +1451,41 @@ function updateViteConfigForCloudflare(filePath, code, options) {
|
|
|
843
1451
|
expression: `${binding}()`
|
|
844
1452
|
});
|
|
845
1453
|
}
|
|
846
|
-
if (configureCaches && cacheOptions.cdnCache === "workers-cache"
|
|
847
|
-
const
|
|
848
|
-
const
|
|
849
|
-
const
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
});
|
|
1454
|
+
if (configureCaches && cacheOptions.cdnCache === "workers-cache") {
|
|
1455
|
+
const existingCdnSlot = getVinextCacheSlot(existingVinextCall, "cdn");
|
|
1456
|
+
const existingCallee = existingCdnSlot?.value.type === "CallExpression" && existingCdnSlot.value.callee.type === "Identifier" ? existingCdnSlot.value.callee.name : void 0;
|
|
1457
|
+
const adapterImports = [["@vinext/cloudflare/cache/workers-cache-cdn-adapter", "workersCacheCdnAdapter"], ["@vinext/cloudflare/cache/cdn-adapter", "cdnAdapter"]].map(([source, imported]) => ({
|
|
1458
|
+
source,
|
|
1459
|
+
imported,
|
|
1460
|
+
local: commonJs ? findRequiredBinding(program, source, imported) : findImportedBinding(program, source, imported)
|
|
1461
|
+
}));
|
|
1462
|
+
const { source, imported, local: existing } = adapterImports.find(({ local }) => local && local === existingCallee) ?? adapterImports[0];
|
|
1463
|
+
if (!existingCdnSlot || Boolean(existing && existingCallee === existing)) {
|
|
1464
|
+
const local = existing ?? allocateBinding(bindings, imported);
|
|
1465
|
+
const expression = `${commonJs ? ensureNamedRequire(program, output, source, imported, local) : ensureNamedImport(program, output, source, imported, local)}(${options.versionMetadataBinding && options.versionMetadataBinding !== DEFAULT_VERSION_METADATA_BINDING ? `{ versionMetadataBinding: ${JSON.stringify(options.versionMetadataBinding)} }` : ""})`;
|
|
1466
|
+
if (existingCdnSlot) output.overwrite(existingCdnSlot.value.start, existingCdnSlot.value.end, expression);
|
|
1467
|
+
else cacheAdditions.push({
|
|
1468
|
+
name: "cdn",
|
|
1469
|
+
expression
|
|
1470
|
+
});
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
if (configureCaches && cacheOptions.cdnCache === "static-assets") {
|
|
1474
|
+
const imported = "staticAssetsAdapter";
|
|
1475
|
+
const source = "@vinext/cloudflare/cache/static-assets-adapter";
|
|
1476
|
+
const existing = commonJs ? findRequiredBinding(program, source, imported) : findImportedBinding(program, source, imported);
|
|
1477
|
+
const existingCdnSlot = getVinextCacheSlot(existingVinextCall, "cdn");
|
|
1478
|
+
const existingUsesStaticAssets = Boolean(existing && existingCdnSlot?.value.type === "CallExpression" && existingCdnSlot.value.callee.type === "Identifier" && existingCdnSlot.value.callee.name === existing);
|
|
1479
|
+
if (existingCdnSlot && !existingUsesStaticAssets) throw new Error("The existing vinext() CDN cache adapter does not match the selected Static Assets cache. Remove it before rerunning vinext init.");
|
|
1480
|
+
if (!existingCdnSlot || existingUsesStaticAssets) {
|
|
1481
|
+
const local = existing ?? allocateBinding(bindings, imported);
|
|
1482
|
+
const expression = `${commonJs ? ensureNamedRequire(program, output, source, imported, local) : ensureNamedImport(program, output, source, imported, local)}(${options.assetsBinding && options.assetsBinding !== "ASSETS" ? `{ binding: ${JSON.stringify(options.assetsBinding)} }` : ""})`;
|
|
1483
|
+
if (existingCdnSlot) output.overwrite(existingCdnSlot.value.start, existingCdnSlot.value.end, expression);
|
|
1484
|
+
else cacheAdditions.push({
|
|
1485
|
+
name: "cdn",
|
|
1486
|
+
expression
|
|
1487
|
+
});
|
|
1488
|
+
}
|
|
855
1489
|
}
|
|
856
1490
|
let imageOptimizerExpression;
|
|
857
1491
|
if (cacheOptions.imageOptimization === "cloudflare-images") {
|
|
@@ -866,37 +1500,44 @@ function updateViteConfigForCloudflare(filePath, code, options) {
|
|
|
866
1500
|
const cloudflareLocal = (commonJs ? findRequiredBinding(program, "@cloudflare/vite-plugin", "cloudflare") : findImportedBinding(program, "@cloudflare/vite-plugin", "cloudflare")) ?? allocateBinding(bindings, "cloudflare");
|
|
867
1501
|
const cloudflareBinding = commonJs ? ensureNamedRequire(program, output, "@cloudflare/vite-plugin", "cloudflare", cloudflareLocal) : ensureNamedImport(program, output, "@cloudflare/vite-plugin", "cloudflare", cloudflareLocal);
|
|
868
1502
|
ensurePlugins(output, config, [{
|
|
869
|
-
expression: existingVinextCall ? `${vinextBinding}()` : options.cache
|
|
1503
|
+
expression: existingVinextCall ? `${vinextBinding}()` : options.cache ? vinextExpression(cacheOptions, vinextBinding, imageOptimizerExpression?.slice(0, imageOptimizerExpression.indexOf("(")) || "imagesOptimizer", options.imagesBinding, options.versionMetadataBinding, responseStoreBinding, options.assetsBinding, options.assetsDirectory) : `${vinextBinding}()`,
|
|
870
1504
|
binding: vinextBinding
|
|
871
1505
|
}, {
|
|
872
1506
|
expression: cloudflarePluginExpression(options.isAppRouter, cloudflareBinding),
|
|
873
1507
|
binding: cloudflareBinding
|
|
874
1508
|
}], code);
|
|
875
1509
|
ensureCloudflareViteEnvironment(output, config, cloudflareBinding, options.isAppRouter, code);
|
|
876
|
-
if (existingVinextCall)
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
1510
|
+
if (existingVinextCall) {
|
|
1511
|
+
if (existingVinextCall.arguments.length === 0 && (responseStoreExpression || cacheAdditions.length > 0 || imageOptimizerExpression || cacheOptions.cdnCache === "static-assets" || cacheOptions.prerender)) {
|
|
1512
|
+
const properties = [];
|
|
1513
|
+
if (responseStoreExpression) properties.push(`cache: ${responseStoreExpression}`);
|
|
1514
|
+
else if (cacheAdditions.length > 0) properties.push(`cache: { ${cacheAdditions.map(({ name, expression }) => `${name}: ${expression}`).join(", ")} }`);
|
|
1515
|
+
if (imageOptimizerExpression) properties.push(`images: { optimizer: ${imageOptimizerExpression} }`);
|
|
1516
|
+
if (cacheOptions.cdnCache === "static-assets" || cacheOptions.prerender) properties.push("prerender: { routes: \"*\" }");
|
|
1517
|
+
if (cacheOptions.cdnCache === "static-assets") {
|
|
1518
|
+
if (options.assetsDirectory && path.normalize(options.assetsDirectory) !== path.normalize("dist/client")) properties.push(`clientOutDir: ${JSON.stringify(options.assetsDirectory)}`);
|
|
1519
|
+
}
|
|
1520
|
+
const plugins = findProperty(config, "plugins");
|
|
1521
|
+
const closingIndent = `${plugins ? code.slice(0, plugins.start).split("\n").at(-1)?.match(/^\s*/)?.[0] ?? "" : ""} `;
|
|
1522
|
+
const propertyEntryIndent = `${closingIndent} `;
|
|
1523
|
+
output.appendLeft(existingVinextCall.end - 1, `{\n${propertyEntryIndent}${properties.join(`,\n${propertyEntryIndent}`)},\n${closingIndent}}`);
|
|
1524
|
+
} else {
|
|
1525
|
+
ensureVinextResponseStore(output, config, vinextBinding, responseStoreExpression, code);
|
|
1526
|
+
ensureVinextCache(output, config, vinextBinding, cacheAdditions, code);
|
|
1527
|
+
ensureVinextImageOptimizer(output, config, vinextBinding, imageOptimizerExpression, code);
|
|
1528
|
+
if (cacheOptions.cdnCache === "static-assets" || cacheOptions.prerender) ensureVinextPrerenderOptions(output, config, vinextBinding, cacheOptions.cdnCache === "static-assets" ? options.assetsDirectory ?? "dist/client" : void 0, code);
|
|
1529
|
+
}
|
|
889
1530
|
}
|
|
890
1531
|
if (options.nativeModulesToStub.length > 0) {
|
|
891
1532
|
const pathLocal = (commonJs ? findRequiredBinding(program, "node:path", "default") : program.body.filter((statement) => statement.type === "ImportDeclaration").find((statement) => statement.source.value === "node:path")?.specifiers.find((specifier) => specifier.type === "ImportDefaultSpecifier")?.local.name) ?? allocateBinding(bindings, "path");
|
|
892
1533
|
const pathBinding = commonJs ? ensureDefaultRequire(program, output, "node:path", pathLocal) : ensureDefaultImport(program, output, "node:path", pathLocal);
|
|
893
1534
|
ensureNativeAliases(output, config, options.nativeModulesToStub, pathBinding, code);
|
|
894
1535
|
}
|
|
895
|
-
return output.toString();
|
|
1536
|
+
return formatInlineConfig(filePath, output.toString(), code);
|
|
896
1537
|
}
|
|
897
1538
|
function usesCommonJsViteConfig(filePath, code) {
|
|
898
1539
|
if (/\.(?:cjs|cts)$/.test(filePath)) return true;
|
|
899
1540
|
return parseViteConfig(filePath, code).body.some((statement) => statement.type === "ExpressionStatement" && statement.expression.type === "AssignmentExpression" && statement.expression.left.type === "MemberExpression" && statement.expression.left.object.type === "Identifier" && statement.expression.left.object.name === "module" && statement.expression.left.property.type === "Identifier" && statement.expression.left.property.name === "exports");
|
|
900
1541
|
}
|
|
901
1542
|
//#endregion
|
|
902
|
-
export { generateAppRouterViteConfig, generatePagesRouterViteConfig, generateWranglerConfig, getWranglerImagesBinding, setupCloudflarePlatform, updateViteConfigForCloudflare, updateWranglerConfigForCloudflare, usesCommonJsViteConfig, validateCloudflarePlatformSetup };
|
|
1543
|
+
export { compactResourceName, cssModulesConfigSource, generateAppRouterViteConfig, generatePagesRouterViteConfig, generateResponseStoreWranglerConfig, generateWranglerConfig, getWranglerImagesBinding, getWranglerVersionMetadataBinding, setupCloudflarePlatform, updateViteConfigForCloudflare, updateViteConfigForCssModules, updateWranglerConfigForCloudflare, usesCommonJsViteConfig, validateCloudflarePlatformSetup };
|