vinext 0.1.8 → 0.2.1
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 +51 -30
- package/dist/build/css-url-assets.d.ts +3 -1
- package/dist/build/css-url-assets.js +18 -1
- package/dist/build/inject-pregenerated-paths.d.ts +7 -0
- package/dist/build/inject-pregenerated-paths.js +21 -0
- package/dist/build/layout-classification.js +1 -1
- package/dist/build/nitro-route-rules.js +1 -1
- package/dist/build/pages-client-assets-module.d.ts +11 -0
- package/dist/build/pages-client-assets-module.js +27 -0
- package/dist/build/prerender-server-entry.d.ts +1 -0
- package/dist/build/prerender-server-entry.js +49 -0
- package/dist/build/prerender-server-pool.d.ts +44 -0
- package/dist/build/prerender-server-pool.js +194 -0
- package/dist/build/prerender.d.ts +2 -1
- package/dist/build/prerender.js +98 -27
- package/dist/build/report.d.ts +13 -2
- package/dist/build/report.js +99 -2
- package/dist/build/run-prerender.d.ts +7 -0
- package/dist/build/run-prerender.js +12 -2
- package/dist/build/standalone.js +2 -0
- package/dist/cache/cache-adapters-virtual.js +3 -3
- package/dist/check.d.ts +4 -6
- package/dist/check.js +48 -11
- package/dist/cli-args.d.ts +1 -2
- package/dist/cli-args.js +1 -1
- package/dist/cli-dev-config.d.ts +12 -0
- package/dist/cli-dev-config.js +23 -0
- package/dist/cli.js +112 -96
- package/dist/{server → client}/dev-error-overlay-store.d.ts +1 -1
- package/dist/{server → client}/dev-error-overlay-store.js +1 -1
- package/dist/{server → client}/dev-error-overlay.d.ts +1 -1
- package/dist/{server → client}/dev-error-overlay.js +2 -2
- package/dist/client/navigation-runtime.d.ts +2 -0
- package/dist/client/navigation-runtime.js +3 -1
- package/dist/client/vinext-next-data.d.ts +4 -1
- package/dist/client/window-next.d.ts +2 -1
- package/dist/cloudflare/index.d.ts +2 -2
- package/dist/cloudflare/index.js +2 -2
- package/dist/config/config-matchers.js +45 -19
- package/dist/config/next-config.d.ts +41 -9
- package/dist/config/next-config.js +60 -3
- package/dist/config/prerender.d.ts +34 -0
- package/dist/config/prerender.js +55 -0
- package/dist/entries/app-browser-entry.js +5 -1
- package/dist/entries/app-rsc-entry.d.ts +5 -3
- package/dist/entries/app-rsc-entry.js +44 -10
- package/dist/entries/app-rsc-manifest.js +2 -0
- package/dist/entries/pages-client-entry.d.ts +3 -0
- package/dist/entries/pages-client-entry.js +28 -3
- package/dist/entries/pages-server-entry.js +23 -6
- package/dist/image/image-adapters-virtual.d.ts +59 -0
- package/dist/image/image-adapters-virtual.js +59 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +482 -120
- package/dist/init-cloudflare.d.ts +43 -0
- package/dist/init-cloudflare.js +839 -0
- package/dist/init-platform.d.ts +40 -0
- package/dist/init-platform.js +195 -0
- package/dist/init.d.ts +16 -38
- package/dist/init.js +209 -99
- package/dist/node_modules/.pnpm/am-i-vibing@0.5.0/node_modules/am-i-vibing/dist/detector-1yx2Hoe0.js +294 -0
- package/dist/node_modules/.pnpm/process-ancestry@0.1.0/node_modules/process-ancestry/dist/index.js +94 -0
- package/dist/{cloudflare → packages/cloudflare}/src/cache/cdn-adapter.runtime.js +1 -1
- package/dist/{cloudflare → packages/cloudflare}/src/cache/kv-data-adapter.runtime.d.ts +2 -2
- package/dist/{cloudflare → packages/cloudflare}/src/cache/kv-data-adapter.runtime.js +9 -2
- package/dist/packages/cloudflare/src/deploy-config.js +150 -0
- package/dist/packages/cloudflare/src/deploy-help.js +55 -0
- package/dist/packages/cloudflare/src/deploy.js +272 -0
- package/dist/{cloudflare → packages/cloudflare/src}/tpr.d.ts +4 -41
- package/dist/{cloudflare → packages/cloudflare/src}/tpr.js +44 -20
- package/dist/plugins/ast-scope.d.ts +16 -0
- package/dist/plugins/ast-scope.js +62 -0
- package/dist/plugins/ast-utils.d.ts +27 -1
- package/dist/plugins/ast-utils.js +32 -1
- package/dist/plugins/css-module-imports.d.ts +14 -0
- package/dist/plugins/css-module-imports.js +59 -0
- package/dist/plugins/extensionless-dynamic-import.js +2 -2
- package/dist/plugins/fonts.js +1 -1
- package/dist/plugins/ignore-dynamic-requests.d.ts +11 -0
- package/dist/plugins/ignore-dynamic-requests.js +530 -0
- package/dist/plugins/og-assets.js +2 -1
- package/dist/plugins/optimize-imports.js +1 -1
- package/dist/plugins/rsc-reference-validation-normalizer.d.ts +12 -0
- package/dist/plugins/rsc-reference-validation-normalizer.js +48 -0
- package/dist/plugins/sass.d.ts +17 -1
- package/dist/plugins/sass.js +74 -1
- package/dist/plugins/styled-jsx.d.ts +16 -0
- package/dist/plugins/styled-jsx.js +149 -0
- package/dist/plugins/typeof-window.d.ts +1 -1
- package/dist/plugins/typeof-window.js +28 -56
- package/dist/routing/app-route-graph.d.ts +23 -2
- package/dist/routing/app-route-graph.js +138 -38
- package/dist/routing/file-matcher.d.ts +11 -1
- package/dist/routing/file-matcher.js +18 -3
- package/dist/routing/pages-router.js +2 -2
- package/dist/server/api-handler.js +9 -14
- package/dist/server/app-browser-action-result.d.ts +4 -1
- package/dist/server/app-browser-action-result.js +8 -1
- package/dist/server/app-browser-entry.js +198 -57
- package/dist/server/app-browser-interception-context.d.ts +1 -0
- package/dist/server/app-browser-interception-context.js +4 -2
- package/dist/server/app-browser-navigation-controller.d.ts +2 -0
- package/dist/server/app-browser-navigation-controller.js +60 -31
- package/dist/server/app-browser-server-action-client.d.ts +1 -1
- package/dist/server/app-browser-server-action-client.js +8 -7
- package/dist/server/app-browser-state.d.ts +12 -1
- package/dist/server/app-browser-state.js +25 -8
- package/dist/server/app-browser-visible-commit.d.ts +6 -1
- package/dist/server/app-browser-visible-commit.js +42 -24
- package/dist/server/app-elements-wire.d.ts +9 -2
- package/dist/server/app-elements-wire.js +8 -1
- package/dist/server/app-elements.d.ts +2 -2
- package/dist/server/app-elements.js +4 -3
- package/dist/server/app-fallback-renderer.d.ts +2 -1
- package/dist/server/app-fallback-renderer.js +10 -6
- package/dist/server/app-hydration-cache-publication.d.ts +11 -0
- package/dist/server/app-hydration-cache-publication.js +43 -0
- package/dist/server/app-middleware.d.ts +4 -3
- package/dist/server/app-middleware.js +8 -3
- package/dist/server/app-optimistic-routing.js +11 -4
- package/dist/server/app-page-boundary.js +2 -1
- package/dist/server/app-page-cache-finalizer.d.ts +1 -0
- package/dist/server/app-page-cache-finalizer.js +5 -4
- package/dist/server/app-page-cache-render.d.ts +1 -0
- package/dist/server/app-page-cache-render.js +8 -4
- package/dist/server/app-page-cache.d.ts +1 -0
- package/dist/server/app-page-cache.js +27 -7
- package/dist/server/app-page-dispatch.d.ts +1 -0
- package/dist/server/app-page-dispatch.js +26 -8
- package/dist/server/app-page-element-builder.d.ts +2 -1
- package/dist/server/app-page-element-builder.js +59 -4
- package/dist/server/app-page-execution.js +2 -1
- package/dist/server/app-page-probe.js +5 -0
- package/dist/server/app-page-render-identity.d.ts +2 -0
- package/dist/server/app-page-render-identity.js +3 -2
- package/dist/server/app-page-render.d.ts +2 -0
- package/dist/server/app-page-render.js +85 -16
- package/dist/server/app-page-request.d.ts +14 -0
- package/dist/server/app-page-request.js +69 -4
- package/dist/server/app-page-response.d.ts +7 -0
- package/dist/server/app-page-response.js +16 -4
- package/dist/server/app-page-route-wiring.d.ts +8 -1
- package/dist/server/app-page-route-wiring.js +32 -18
- package/dist/server/app-page-segment-state.d.ts +2 -1
- package/dist/server/app-page-segment-state.js +3 -1
- package/dist/server/app-page-stream.d.ts +7 -1
- package/dist/server/app-page-stream.js +3 -1
- package/dist/server/app-route-handler-execution.js +5 -1
- package/dist/server/app-route-handler-response.js +1 -0
- package/dist/server/app-route-handler-runtime.js +1 -1
- package/dist/server/app-route-tree-prefetch.d.ts +43 -0
- package/dist/server/app-route-tree-prefetch.js +187 -0
- package/dist/server/app-router-entry.js +9 -2
- package/dist/server/app-rsc-cache-busting.d.ts +2 -1
- package/dist/server/app-rsc-cache-busting.js +9 -4
- package/dist/server/app-rsc-handler.d.ts +7 -0
- package/dist/server/app-rsc-handler.js +148 -39
- package/dist/server/app-rsc-render-mode.d.ts +3 -2
- package/dist/server/app-rsc-render-mode.js +4 -1
- package/dist/server/app-rsc-request-normalization.d.ts +6 -6
- package/dist/server/app-rsc-request-normalization.js +10 -8
- package/dist/server/app-segment-config.d.ts +11 -0
- package/dist/server/app-segment-config.js +62 -6
- package/dist/server/app-server-action-execution.d.ts +1 -0
- package/dist/server/app-server-action-execution.js +61 -30
- package/dist/server/app-ssr-entry.d.ts +3 -0
- package/dist/server/app-ssr-entry.js +13 -5
- package/dist/server/app-ssr-stream.d.ts +7 -3
- package/dist/server/app-ssr-stream.js +10 -6
- package/dist/server/app-visited-response-cache.d.ts +6 -0
- package/dist/server/app-visited-response-cache.js +3 -1
- package/dist/server/cache-control.d.ts +3 -1
- package/dist/server/cache-control.js +13 -1
- package/dist/server/client-trace-metadata.js +26 -0
- package/dist/server/default-global-not-found-module.d.ts +14 -0
- package/dist/server/default-global-not-found-module.js +14 -0
- package/dist/server/dev-route-files.js +4 -0
- package/dist/server/dev-server.d.ts +11 -1
- package/dist/server/dev-server.js +94 -35
- package/dist/server/dev-stack-sourcemap.d.ts +1 -1
- package/dist/server/dev-stack-sourcemap.js +1 -1
- package/dist/server/fetch-handler.d.ts +2 -0
- package/dist/server/fetch-handler.js +18 -0
- package/dist/server/headers.d.ts +7 -15
- package/dist/server/headers.js +11 -18
- package/dist/server/image-optimization.d.ts +51 -1
- package/dist/server/image-optimization.js +52 -2
- package/dist/server/implicit-tags.js +1 -1
- package/dist/server/isr-cache.d.ts +3 -2
- package/dist/server/isr-cache.js +9 -5
- package/dist/server/metadata-routes.d.ts +3 -1
- package/dist/server/metadata-routes.js +12 -2
- package/dist/server/middleware-runtime.js +6 -1
- package/dist/server/navigation-planner.d.ts +1 -0
- package/dist/server/navigation-planner.js +14 -3
- package/dist/server/pages-api-route.js +2 -2
- package/dist/server/pages-asset-tags.d.ts +4 -6
- package/dist/server/pages-asset-tags.js +12 -12
- package/dist/server/pages-client-assets.d.ts +12 -0
- package/dist/server/pages-client-assets.js +10 -0
- package/dist/server/pages-data-route.d.ts +4 -2
- package/dist/server/pages-data-route.js +18 -4
- package/dist/server/pages-dev-module-url.d.ts +2 -1
- package/dist/server/pages-dev-module-url.js +6 -3
- package/dist/server/pages-node-compat.d.ts +19 -1
- package/dist/server/pages-node-compat.js +81 -4
- package/dist/server/pages-page-data.d.ts +33 -1
- package/dist/server/pages-page-data.js +62 -33
- package/dist/server/pages-page-handler.d.ts +2 -1
- package/dist/server/pages-page-handler.js +38 -19
- package/dist/server/pages-page-response.d.ts +8 -0
- package/dist/server/pages-page-response.js +7 -3
- package/dist/server/pages-request-pipeline.d.ts +9 -5
- package/dist/server/pages-request-pipeline.js +55 -7
- package/dist/server/pages-router-entry.d.ts +30 -0
- package/dist/server/pages-router-entry.js +108 -0
- package/dist/server/prerender-manifest.d.ts +3 -1
- package/dist/server/prerender-route-params.js +1 -1
- package/dist/server/prod-server.d.ts +5 -3
- package/dist/server/prod-server.js +68 -39
- package/dist/server/request-pipeline.js +2 -1
- package/dist/server/seed-cache.js +4 -4
- package/dist/shims/app-router-scroll-state.d.ts +1 -0
- package/dist/shims/app-router-scroll-state.js +1 -0
- package/dist/shims/app-router-scroll.js +2 -1
- package/dist/shims/cache-handler.js +8 -1
- package/dist/shims/cache.js +22 -15
- package/dist/shims/cdn-cache.js +1 -1
- package/dist/shims/dynamic-preload-chunks.js +2 -1
- package/dist/shims/fetch-cache.d.ts +3 -1
- package/dist/shims/fetch-cache.js +77 -52
- package/dist/shims/form.d.ts +4 -2
- package/dist/shims/form.js +37 -43
- package/dist/shims/headers.d.ts +7 -1
- package/dist/shims/headers.js +17 -3
- package/dist/shims/image.js +75 -14
- package/dist/shims/internal/app-prefetch-fetch-queue.d.ts +10 -0
- package/dist/shims/internal/app-prefetch-fetch-queue.js +61 -0
- package/dist/shims/internal/app-route-detection.d.ts +2 -17
- package/dist/shims/internal/app-route-detection.js +4 -17
- package/dist/shims/internal/hybrid-client-route-owner-direct.d.ts +23 -0
- package/dist/shims/internal/hybrid-client-route-owner-direct.js +51 -0
- package/dist/shims/internal/hybrid-client-route-owner.d.ts +3 -15
- package/dist/shims/internal/hybrid-client-route-owner.js +40 -58
- package/dist/shims/internal/pages-data-fetch-dedup.d.ts +10 -5
- package/dist/shims/internal/pages-data-fetch-dedup.js +84 -14
- package/dist/shims/internal/pages-data-target.d.ts +18 -12
- package/dist/shims/internal/pages-data-target.js +97 -13
- package/dist/shims/internal/pages-router-components.d.ts +7 -0
- package/dist/shims/internal/pages-router-components.js +13 -0
- package/dist/shims/layout-segment-context.d.ts +4 -1
- package/dist/shims/layout-segment-context.js +18 -4
- package/dist/shims/link.d.ts +1 -1
- package/dist/shims/link.js +224 -58
- package/dist/shims/navigation.d.ts +19 -3
- package/dist/shims/navigation.js +245 -47
- package/dist/shims/request-context.js +18 -0
- package/dist/shims/root-params.d.ts +15 -1
- package/dist/shims/root-params.js +21 -1
- package/dist/shims/router.d.ts +5 -7
- package/dist/shims/router.js +387 -102
- package/dist/shims/server.js +3 -2
- package/dist/shims/slot.js +3 -6
- package/dist/shims/unified-request-context.js +1 -0
- package/dist/typegen.js +1 -1
- package/dist/utils/client-runtime-metadata.d.ts +2 -18
- package/dist/utils/client-runtime-metadata.js +31 -22
- package/dist/utils/dev-stack-sourcemap-endpoint.d.ts +4 -0
- package/dist/{server → utils}/dev-stack-sourcemap-endpoint.js +1 -1
- package/dist/utils/domain-locale.d.ts +6 -3
- package/dist/{server → utils}/middleware-request-headers.d.ts +1 -1
- package/dist/{server → utils}/middleware-request-headers.js +3 -3
- package/dist/utils/project.d.ts +48 -2
- package/dist/utils/project.js +225 -4
- package/dist/utils/protocol-headers.d.ts +23 -0
- package/dist/utils/protocol-headers.js +23 -0
- package/dist/utils/react-version.d.ts +4 -0
- package/dist/utils/react-version.js +44 -0
- package/dist/utils/vite-version.d.ts +2 -0
- package/dist/utils/vite-version.js +11 -1
- package/package.json +47 -2
- package/dist/deploy.d.ts +0 -197
- package/dist/deploy.js +0 -1040
- package/dist/server/dev-stack-sourcemap-endpoint.d.ts +0 -4
- /package/dist/{cloudflare → packages/cloudflare}/src/utils/cache-control-metadata.js +0 -0
package/dist/shims/server.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { hasBasePath, stripBasePath } from "../utils/base-path.js";
|
|
2
2
|
import { getRequestExecutionContext } from "./request-context.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { MIDDLEWARE_SET_COOKIE_HEADER } from "../utils/protocol-headers.js";
|
|
4
|
+
import { MIDDLEWARE_NEXT_HEADER, MIDDLEWARE_REWRITE_HEADER } from "../server/headers.js";
|
|
5
|
+
import { encodeMiddlewareRequestHeaders } from "../utils/middleware-request-headers.js";
|
|
5
6
|
import { serializeSetCookie, validateCookieName } from "./internal/cookie-serialize.js";
|
|
6
7
|
import { parseEdgeRequestCookieHeader } from "../utils/parse-cookie.js";
|
|
7
8
|
import { assertSafeNavigationUrl } from "./url-safety.js";
|
package/dist/shims/slot.js
CHANGED
|
@@ -166,12 +166,9 @@ function mergeElements(prev, next, options = {}) {
|
|
|
166
166
|
const preserveElementIds = typeof options === "boolean" ? [] : options.preserveElementIds ?? [];
|
|
167
167
|
const preservePreviousSlotIds = typeof options === "boolean" ? [] : options.preservePreviousSlotIds ?? [];
|
|
168
168
|
const merged = { ...next };
|
|
169
|
-
for (const id of preserveElementIds) {
|
|
170
|
-
|
|
171
|
-
if (
|
|
172
|
-
const value = prev[id];
|
|
173
|
-
if (value !== void 0) merged[id] = value;
|
|
174
|
-
}
|
|
169
|
+
for (const id of preserveElementIds) if (Object.hasOwn(prev, id)) {
|
|
170
|
+
const value = prev[id];
|
|
171
|
+
if (value !== void 0) merged[id] = value;
|
|
175
172
|
}
|
|
176
173
|
const slotKeys = new Set([...Object.keys(prev), ...Object.keys(next)].filter((key) => AppElementsWire.isSlotId(key)));
|
|
177
174
|
if (clearAbsentSlots) {
|
|
@@ -36,6 +36,7 @@ function createRequestContext(opts) {
|
|
|
36
36
|
currentFetchCacheMode: null,
|
|
37
37
|
currentForceDynamicFetchDefault: false,
|
|
38
38
|
dynamicFetchUrls: /* @__PURE__ */ new Set(),
|
|
39
|
+
refreshStaleFetchesInForeground: false,
|
|
39
40
|
isFetchDedupeActive: false,
|
|
40
41
|
currentFetchDedupeEntries: /* @__PURE__ */ new Map(),
|
|
41
42
|
executionContext: _getInheritedExecutionContext(),
|
package/dist/typegen.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { findDir } from "./utils/project.js";
|
|
2
|
-
import { decodeRouteSegment, isInvisibleSegment } from "./routing/utils.js";
|
|
3
2
|
import { normalizePathSeparators } from "./utils/path.js";
|
|
3
|
+
import { decodeRouteSegment, isInvisibleSegment } from "./routing/utils.js";
|
|
4
4
|
import { patternToNextFormat } from "./routing/route-validation.js";
|
|
5
5
|
import { compareStrings } from "./utils/compare.js";
|
|
6
6
|
import "./routing/app-route-graph.js";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
//#region src/utils/client-runtime-metadata.d.ts
|
|
2
2
|
type ClientRuntimeMetadata = {
|
|
3
3
|
clientEntryFile?: string;
|
|
4
|
+
appBootstrapPreinitModules?: string[];
|
|
4
5
|
lazyChunks?: string[];
|
|
5
6
|
dynamicPreloads?: Record<string, string[]>;
|
|
6
7
|
};
|
|
@@ -24,22 +25,5 @@ declare function computeClientRuntimeMetadata(opts: {
|
|
|
24
25
|
assetPrefix: string;
|
|
25
26
|
includeClientEntry?: boolean | "pages-client-entry";
|
|
26
27
|
}): ClientRuntimeMetadata;
|
|
27
|
-
/**
|
|
28
|
-
* Serialize runtime metadata into the `globalThis.__VINEXT_*` assignment script
|
|
29
|
-
* that the Cloudflare `closeBundle` hook prepends to the worker entry. Returns
|
|
30
|
-
* `""` when there is nothing to inject.
|
|
31
|
-
*
|
|
32
|
-
* Both the App Router and Pages Router closeBundle paths call this (and the
|
|
33
|
-
* deploy tests mirror it), so the injection shape stays in one place. The caller
|
|
34
|
-
* decides which fields to pass — e.g. App Router only forwards `clientEntryFile`
|
|
35
|
-
* for mixed app+pages builds (where `computeClientRuntimeMetadata` was asked for
|
|
36
|
-
* the Pages client entry); pure App Router leaves it undefined.
|
|
37
|
-
*/
|
|
38
|
-
declare function buildRuntimeGlobalsScript(input: {
|
|
39
|
-
clientEntryFile?: string | null;
|
|
40
|
-
ssrManifest?: Record<string, string[]> | null;
|
|
41
|
-
lazyChunks?: string[] | null;
|
|
42
|
-
dynamicPreloads?: Record<string, string[]> | null;
|
|
43
|
-
}): string;
|
|
44
28
|
//#endregion
|
|
45
|
-
export {
|
|
29
|
+
export { computeClientRuntimeMetadata };
|
|
@@ -1,10 +1,34 @@
|
|
|
1
|
-
import { resolveAssetsDir } from "./asset-prefix.js";
|
|
1
|
+
import { isAbsoluteAssetPrefix, resolveAssetsDir } from "./asset-prefix.js";
|
|
2
2
|
import { manifestFileWithAssetPrefix, manifestFileWithBase } from "./manifest-paths.js";
|
|
3
3
|
import { findClientEntryFile, findPagesClientEntryFile, readClientBuildManifest } from "./client-build-manifest.js";
|
|
4
4
|
import { findClientEntryFileFromVinextManifest, findPagesClientEntryFileFromVinextManifest, readClientEntryManifest } from "./client-entry-manifest.js";
|
|
5
5
|
import { computeDynamicImportPreloads, computeLazyChunks, dynamicImportPreloadsWithBase } from "./lazy-chunks.js";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
//#region src/utils/client-runtime-metadata.ts
|
|
8
|
+
function collectAppBootstrapPreinitModules(buildManifest, appBrowserEntry, applyBase) {
|
|
9
|
+
if (!appBrowserEntry) return void 0;
|
|
10
|
+
const entryKey = Object.keys(buildManifest).find((key) => buildManifest[key].file === appBrowserEntry);
|
|
11
|
+
if (!entryKey) return void 0;
|
|
12
|
+
const modules = [];
|
|
13
|
+
const seenFiles = /* @__PURE__ */ new Set();
|
|
14
|
+
const visitedChunks = /* @__PURE__ */ new Set();
|
|
15
|
+
function visit(key) {
|
|
16
|
+
if (visitedChunks.has(key)) return;
|
|
17
|
+
visitedChunks.add(key);
|
|
18
|
+
const chunk = buildManifest[key];
|
|
19
|
+
if (!chunk) return;
|
|
20
|
+
for (const importedKey of chunk.imports ?? []) {
|
|
21
|
+
const importedChunk = buildManifest[importedKey];
|
|
22
|
+
if (importedChunk?.file.endsWith(".js") && !seenFiles.has(importedChunk.file)) {
|
|
23
|
+
seenFiles.add(importedChunk.file);
|
|
24
|
+
modules.push(applyBase(importedChunk.file));
|
|
25
|
+
}
|
|
26
|
+
visit(importedKey);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
visit(entryKey);
|
|
30
|
+
return modules.length > 0 ? modules : void 0;
|
|
31
|
+
}
|
|
8
32
|
/**
|
|
9
33
|
* Read the client build manifest and compute runtime metadata used by
|
|
10
34
|
* Cloudflare worker entry injection and Node production server startup.
|
|
@@ -21,9 +45,9 @@ import path from "node:path";
|
|
|
21
45
|
*/
|
|
22
46
|
function computeClientRuntimeMetadata(opts) {
|
|
23
47
|
const buildManifest = readClientBuildManifest(path.join(opts.clientDir, ".vite", "manifest.json"));
|
|
48
|
+
const clientEntryManifest = readClientEntryManifest(opts.clientDir);
|
|
24
49
|
const metadata = {};
|
|
25
50
|
if (opts.includeClientEntry) {
|
|
26
|
-
const clientEntryManifest = readClientEntryManifest(opts.clientDir);
|
|
27
51
|
const entryOptions = {
|
|
28
52
|
buildManifest,
|
|
29
53
|
clientDir: opts.clientDir,
|
|
@@ -34,30 +58,15 @@ function computeClientRuntimeMetadata(opts) {
|
|
|
34
58
|
if (entry) metadata.clientEntryFile = entry;
|
|
35
59
|
}
|
|
36
60
|
if (!buildManifest) return metadata;
|
|
61
|
+
metadata.appBootstrapPreinitModules = collectAppBootstrapPreinitModules(buildManifest, clientEntryManifest?.appBrowserEntry, (file) => {
|
|
62
|
+
const url = manifestFileWithAssetPrefix(file, opts.assetBase, opts.assetPrefix);
|
|
63
|
+
return isAbsoluteAssetPrefix(opts.assetPrefix) ? url : "/" + url;
|
|
64
|
+
});
|
|
37
65
|
const lazyChunks = computeLazyChunks(buildManifest).map((file) => manifestFileWithBase(file, opts.assetBase));
|
|
38
66
|
if (lazyChunks.length > 0) metadata.lazyChunks = lazyChunks;
|
|
39
67
|
const dynamicPreloads = dynamicImportPreloadsWithBase(computeDynamicImportPreloads(buildManifest), (file) => manifestFileWithAssetPrefix(file, opts.assetBase, opts.assetPrefix));
|
|
40
68
|
if (Object.keys(dynamicPreloads).length > 0) metadata.dynamicPreloads = dynamicPreloads;
|
|
41
69
|
return metadata;
|
|
42
70
|
}
|
|
43
|
-
/**
|
|
44
|
-
* Serialize runtime metadata into the `globalThis.__VINEXT_*` assignment script
|
|
45
|
-
* that the Cloudflare `closeBundle` hook prepends to the worker entry. Returns
|
|
46
|
-
* `""` when there is nothing to inject.
|
|
47
|
-
*
|
|
48
|
-
* Both the App Router and Pages Router closeBundle paths call this (and the
|
|
49
|
-
* deploy tests mirror it), so the injection shape stays in one place. The caller
|
|
50
|
-
* decides which fields to pass — e.g. App Router only forwards `clientEntryFile`
|
|
51
|
-
* for mixed app+pages builds (where `computeClientRuntimeMetadata` was asked for
|
|
52
|
-
* the Pages client entry); pure App Router leaves it undefined.
|
|
53
|
-
*/
|
|
54
|
-
function buildRuntimeGlobalsScript(input) {
|
|
55
|
-
const globals = [];
|
|
56
|
-
if (input.clientEntryFile) globals.push(`globalThis.__VINEXT_CLIENT_ENTRY__ = ${JSON.stringify(input.clientEntryFile)};`);
|
|
57
|
-
if (input.ssrManifest && Object.keys(input.ssrManifest).length > 0) globals.push(`globalThis.__VINEXT_SSR_MANIFEST__ = ${JSON.stringify(input.ssrManifest)};`);
|
|
58
|
-
if (input.lazyChunks && input.lazyChunks.length > 0) globals.push(`globalThis.__VINEXT_LAZY_CHUNKS__ = ${JSON.stringify(input.lazyChunks)};`);
|
|
59
|
-
if (input.dynamicPreloads && Object.keys(input.dynamicPreloads).length > 0) globals.push(`globalThis.__VINEXT_DYNAMIC_PRELOADS__ = ${JSON.stringify(input.dynamicPreloads)};`);
|
|
60
|
-
return globals.join("\n");
|
|
61
|
-
}
|
|
62
71
|
//#endregion
|
|
63
|
-
export {
|
|
72
|
+
export { computeClientRuntimeMetadata };
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { NextI18nConfig } from "../config/next-config.js";
|
|
2
|
-
|
|
3
1
|
//#region src/utils/domain-locale.d.ts
|
|
4
|
-
type DomainLocale =
|
|
2
|
+
type DomainLocale = {
|
|
3
|
+
domain: string;
|
|
4
|
+
defaultLocale: string;
|
|
5
|
+
locales?: string[];
|
|
6
|
+
http?: boolean;
|
|
7
|
+
};
|
|
5
8
|
declare function normalizeDomainHostname(hostname: string | null | undefined): string | undefined;
|
|
6
9
|
/**
|
|
7
10
|
* Match a configured domain either by hostname or locale.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region src/
|
|
1
|
+
//#region src/utils/middleware-request-headers.d.ts
|
|
2
2
|
type MiddlewareHeaderValue = string | string[];
|
|
3
3
|
type MiddlewareHeaderSource = Headers | Record<string, MiddlewareHeaderValue>;
|
|
4
4
|
type BuildRequestHeadersOptions = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { MIDDLEWARE_OVERRIDE_HEADERS, MIDDLEWARE_REQUEST_HEADER_PREFIX } from "./headers.js";
|
|
2
|
-
//#region src/
|
|
1
|
+
import { MIDDLEWARE_OVERRIDE_HEADERS, MIDDLEWARE_REQUEST_HEADER_PREFIX } from "./protocol-headers.js";
|
|
2
|
+
//#region src/utils/middleware-request-headers.ts
|
|
3
3
|
const CREDENTIAL_REQUEST_HEADERS = ["authorization", "cookie"];
|
|
4
4
|
function getMiddlewareHeaderValue(source, key) {
|
|
5
5
|
if (source instanceof Headers) return source.get(key);
|
|
@@ -59,7 +59,7 @@ function buildRequestHeadersFromMiddlewareResponse(baseHeaders, middlewareHeader
|
|
|
59
59
|
return nextHeaders;
|
|
60
60
|
}
|
|
61
61
|
function shouldKeepMiddlewareHeader(key) {
|
|
62
|
-
return key === "x-middleware-override-headers" || key === "x-middleware-set-cookie" || key.startsWith("x-middleware-request-");
|
|
62
|
+
return key === "x-middleware-override-headers" || key === "x-middleware-cache" || key === "x-middleware-set-cookie" || key.startsWith("x-middleware-request-");
|
|
63
63
|
}
|
|
64
64
|
//#endregion
|
|
65
65
|
export { buildRequestHeadersFromMiddlewareResponse, encodeMiddlewareRequestHeaders, shouldKeepMiddlewareHeader };
|
package/dist/utils/project.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
//#region src/utils/project.d.ts
|
|
2
2
|
/**
|
|
3
|
-
* Shared project utilities
|
|
3
|
+
* Shared project utilities used by `vinext init`, the vinext plugin, and
|
|
4
|
+
* platform packages such as `@vinext/cloudflare`.
|
|
4
5
|
*
|
|
5
6
|
* These functions detect and modify project configuration without touching
|
|
6
7
|
* any Next.js source files, config files, or tsconfig.json.
|
|
@@ -62,6 +63,49 @@ declare function findInNodeModules(start: string, subPath: string): string | nul
|
|
|
62
63
|
* Check if a vite.config file exists in the project root.
|
|
63
64
|
*/
|
|
64
65
|
declare function hasViteConfig(root: string): boolean;
|
|
66
|
+
/** Return the config file Vite will load, using Vite's default precedence. */
|
|
67
|
+
declare function findViteConfigPath(root: string): string | undefined;
|
|
68
|
+
declare function formatMissingCloudflarePluginError(options: {
|
|
69
|
+
isAppRouter: boolean;
|
|
70
|
+
configFile?: string;
|
|
71
|
+
}): string;
|
|
72
|
+
type ProjectInfo = {
|
|
73
|
+
root: string;
|
|
74
|
+
isAppRouter: boolean;
|
|
75
|
+
isPagesRouter: boolean;
|
|
76
|
+
hasViteConfig: boolean;
|
|
77
|
+
hasWranglerConfig: boolean;
|
|
78
|
+
hasWorkerEntry: boolean;
|
|
79
|
+
hasCloudflarePlugin: boolean;
|
|
80
|
+
hasRscPlugin: boolean;
|
|
81
|
+
hasWrangler: boolean;
|
|
82
|
+
projectName: string; /** Pages that use `revalidate` (ISR) */
|
|
83
|
+
hasISR: boolean; /** package.json has "type": "module" */
|
|
84
|
+
hasTypeModule: boolean; /** .mdx files detected in app/ or pages/ */
|
|
85
|
+
hasMDX: boolean; /** CodeHike is a dependency */
|
|
86
|
+
hasCodeHike: boolean; /** Native Node modules that need stubbing for Workers */
|
|
87
|
+
nativeModulesToStub: string[];
|
|
88
|
+
};
|
|
89
|
+
/** Check whether a wrangler config file exists in the given directory. */
|
|
90
|
+
declare function hasWranglerConfig(root: string): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Detect the project structure, routing mode, relevant config files, and
|
|
93
|
+
* deploy-related dependencies. This lives in core because `vinext init`, the
|
|
94
|
+
* Vite plugin, and platform packages all need the same project facts.
|
|
95
|
+
*/
|
|
96
|
+
declare function detectProject(root: string): ProjectInfo;
|
|
97
|
+
type MissingDep = {
|
|
98
|
+
name: string;
|
|
99
|
+
version: string;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Check if a package is resolvable from a given root directory using Node's
|
|
103
|
+
* module resolution. Handles hoisting, pnpm symlinks, monorepos, and Yarn PnP.
|
|
104
|
+
*/
|
|
105
|
+
declare function isPackageResolvable(root: string, packageName: string): boolean;
|
|
106
|
+
declare function getMissingDeps(info: ProjectInfo, /** Override for testing — defaults to `isPackageResolvable` */
|
|
107
|
+
|
|
108
|
+
_isResolvable?: (root: string, pkg: string) => boolean): MissingDep[];
|
|
65
109
|
/**
|
|
66
110
|
* Return the first candidate directory (resolved against `root`) that exists,
|
|
67
111
|
* or null. Used to locate conventional `app`/`pages` directories that may live
|
|
@@ -74,7 +118,9 @@ declare function hasViteConfig(root: string): boolean;
|
|
|
74
118
|
declare function findDir(root: string, ...candidates: string[]): string | null;
|
|
75
119
|
/**
|
|
76
120
|
* Check if the project uses App Router (has an app/ directory).
|
|
121
|
+
*
|
|
122
|
+
* `root` must be forward-slash — it is passed straight to `findDir`.
|
|
77
123
|
*/
|
|
78
124
|
declare function hasAppDir(root: string): boolean;
|
|
79
125
|
//#endregion
|
|
80
|
-
export { detectPackageManager, detectPackageManagerName, ensureESModule, ensureViteConfigCompatibility, findDir, findInNodeModules, hasAppDir, hasViteConfig, renameCJSConfigs };
|
|
126
|
+
export { ProjectInfo, detectPackageManager, detectPackageManagerName, detectProject, ensureESModule, ensureViteConfigCompatibility, findDir, findInNodeModules, findViteConfigPath, formatMissingCloudflarePluginError, getMissingDeps, hasAppDir, hasViteConfig, hasWranglerConfig, isPackageResolvable, renameCJSConfigs };
|
package/dist/utils/project.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
1
2
|
import fs from "node:fs";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
//#region src/utils/project.ts
|
|
4
5
|
/**
|
|
5
|
-
* Shared project utilities
|
|
6
|
+
* Shared project utilities used by `vinext init`, the vinext plugin, and
|
|
7
|
+
* platform packages such as `@vinext/cloudflare`.
|
|
6
8
|
*
|
|
7
9
|
* These functions detect and modify project configuration without touching
|
|
8
10
|
* any Next.js source files, config files, or tsconfig.json.
|
|
@@ -187,7 +189,224 @@ function findInNodeModules(start, subPath) {
|
|
|
187
189
|
* Check if a vite.config file exists in the project root.
|
|
188
190
|
*/
|
|
189
191
|
function hasViteConfig(root) {
|
|
190
|
-
return
|
|
192
|
+
return findViteConfigPath(root) !== void 0;
|
|
193
|
+
}
|
|
194
|
+
/** Return the config file Vite will load, using Vite's default precedence. */
|
|
195
|
+
function findViteConfigPath(root) {
|
|
196
|
+
return [
|
|
197
|
+
"vite.config.js",
|
|
198
|
+
"vite.config.mjs",
|
|
199
|
+
"vite.config.ts",
|
|
200
|
+
"vite.config.cjs",
|
|
201
|
+
"vite.config.mts",
|
|
202
|
+
"vite.config.cts"
|
|
203
|
+
].map((fileName) => path.join(root, fileName)).find((candidate) => fs.existsSync(candidate));
|
|
204
|
+
}
|
|
205
|
+
function formatMissingCloudflarePluginError(options) {
|
|
206
|
+
const cfArg = options.isAppRouter ? "{\n viteEnvironment: { name: \"rsc\", childEnvironments: [\"ssr\"] },\n }" : "";
|
|
207
|
+
const configRef = options.configFile ? options.configFile : "your Vite config";
|
|
208
|
+
return `[vinext] Missing @cloudflare/vite-plugin in ${configRef}.\n\n Cloudflare Workers builds require the cloudflare() plugin.\n Run \`vinext init --platform=cloudflare\` to update ${configRef}.\n\n Expected plugin shape:\n\n cloudflare(${cfArg})`;
|
|
209
|
+
}
|
|
210
|
+
/** Check whether a wrangler config file exists in the given directory. */
|
|
211
|
+
function hasWranglerConfig(root) {
|
|
212
|
+
return fs.existsSync(path.join(root, "wrangler.jsonc")) || fs.existsSync(path.join(root, "wrangler.json")) || fs.existsSync(path.join(root, "wrangler.toml")) || fs.existsSync(path.join(root, "cloudflare.config.ts"));
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Detect the project structure, routing mode, relevant config files, and
|
|
216
|
+
* deploy-related dependencies. This lives in core because `vinext init`, the
|
|
217
|
+
* Vite plugin, and platform packages all need the same project facts.
|
|
218
|
+
*/
|
|
219
|
+
function detectProject(root) {
|
|
220
|
+
const hasApp = resolveProjectDir(root, "app") !== null;
|
|
221
|
+
const hasPages = resolveProjectDir(root, "pages") !== null;
|
|
222
|
+
const isAppRouter = hasApp;
|
|
223
|
+
const isPagesRouter = !hasApp && hasPages;
|
|
224
|
+
const hasViteConfigFile = hasViteConfig(root);
|
|
225
|
+
const wranglerConfigExists = hasWranglerConfig(root);
|
|
226
|
+
const hasWorkerEntry = fs.existsSync(path.join(root, "worker", "index.ts")) || fs.existsSync(path.join(root, "worker", "index.js"));
|
|
227
|
+
const hasCloudflarePlugin = findInNodeModules(root, "@cloudflare/vite-plugin") !== null;
|
|
228
|
+
const hasRscPlugin = findInNodeModules(root, "@vitejs/plugin-rsc") !== null;
|
|
229
|
+
const hasWrangler = findInNodeModules(root, ".bin/wrangler") !== null || findInNodeModules(root, ".bin/cf") !== null;
|
|
230
|
+
const pkgPath = path.join(root, "package.json");
|
|
231
|
+
let pkg = null;
|
|
232
|
+
if (fs.existsSync(pkgPath)) try {
|
|
233
|
+
pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
234
|
+
} catch {}
|
|
235
|
+
let projectName = path.basename(root);
|
|
236
|
+
if (pkg?.name && typeof pkg.name === "string") projectName = pkg.name.replace(/^@[^/]+\//, "").toLowerCase().replace(/[^a-z0-9-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
237
|
+
const hasTypeModule = pkg?.type === "module";
|
|
238
|
+
let hasISR = false;
|
|
239
|
+
let hasMDX = detectMDXFromConfig(root);
|
|
240
|
+
if (isAppRouter) {
|
|
241
|
+
const appDir = resolveProjectDir(root, "app");
|
|
242
|
+
if (appDir) {
|
|
243
|
+
const found = scanTreeForDetection(appDir, {
|
|
244
|
+
isr: true,
|
|
245
|
+
mdx: !hasMDX
|
|
246
|
+
});
|
|
247
|
+
hasISR = found.isr;
|
|
248
|
+
hasMDX = hasMDX || found.mdx;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
if (hasPages) {
|
|
252
|
+
const pagesDir = resolveProjectDir(root, "pages");
|
|
253
|
+
if (pagesDir) {
|
|
254
|
+
const found = scanTreeForDetection(pagesDir, {
|
|
255
|
+
isr: !hasISR,
|
|
256
|
+
mdx: !hasMDX
|
|
257
|
+
});
|
|
258
|
+
hasISR = hasISR || found.isr;
|
|
259
|
+
hasMDX = hasMDX || found.mdx;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
hasISR = hasISR || detectCacheComponents(root);
|
|
263
|
+
const allDeps = {
|
|
264
|
+
...pkg?.dependencies,
|
|
265
|
+
...pkg?.devDependencies
|
|
266
|
+
};
|
|
267
|
+
const hasCodeHike = "codehike" in allDeps;
|
|
268
|
+
const nativeModulesToStub = detectNativeModules(allDeps);
|
|
269
|
+
return {
|
|
270
|
+
root,
|
|
271
|
+
isAppRouter,
|
|
272
|
+
isPagesRouter,
|
|
273
|
+
hasViteConfig: hasViteConfigFile,
|
|
274
|
+
hasWranglerConfig: wranglerConfigExists,
|
|
275
|
+
hasWorkerEntry,
|
|
276
|
+
hasCloudflarePlugin,
|
|
277
|
+
hasRscPlugin,
|
|
278
|
+
hasWrangler,
|
|
279
|
+
projectName,
|
|
280
|
+
hasISR,
|
|
281
|
+
hasTypeModule,
|
|
282
|
+
hasMDX,
|
|
283
|
+
hasCodeHike,
|
|
284
|
+
nativeModulesToStub
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
const ISR_PATTERN = /export\s+(?:const\s+revalidate\s*=|(?:async\s+)?function\s+getStaticProps\b|const\s+getStaticProps\s*=|\{[^}]*\bgetStaticProps\b[^}]*\})/;
|
|
288
|
+
const ISR_SCANNABLE_EXTENSION = /\.(ts|tsx|js|jsx)$/;
|
|
289
|
+
function resolveProjectDir(root, name) {
|
|
290
|
+
const rootDir = path.join(root, name);
|
|
291
|
+
try {
|
|
292
|
+
if (fs.statSync(rootDir).isDirectory()) return rootDir;
|
|
293
|
+
} catch {}
|
|
294
|
+
const srcDir = path.join(root, "src", name);
|
|
295
|
+
try {
|
|
296
|
+
if (fs.statSync(srcDir).isDirectory()) return srcDir;
|
|
297
|
+
} catch {}
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
300
|
+
function scanTreeForDetection(dir, want) {
|
|
301
|
+
const found = {
|
|
302
|
+
isr: false,
|
|
303
|
+
mdx: false
|
|
304
|
+
};
|
|
305
|
+
const walk = (current) => {
|
|
306
|
+
let entries;
|
|
307
|
+
try {
|
|
308
|
+
entries = fs.readdirSync(current, { withFileTypes: true });
|
|
309
|
+
} catch {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
for (const entry of entries) {
|
|
313
|
+
if ((!want.isr || found.isr) && (!want.mdx || found.mdx)) return;
|
|
314
|
+
const fullPath = path.join(current, entry.name);
|
|
315
|
+
if (entry.isDirectory()) {
|
|
316
|
+
if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
|
|
317
|
+
walk(fullPath);
|
|
318
|
+
} else if (entry.isFile()) {
|
|
319
|
+
if (want.mdx && !found.mdx && entry.name.endsWith(".mdx")) found.mdx = true;
|
|
320
|
+
if (want.isr && !found.isr && ISR_SCANNABLE_EXTENSION.test(entry.name)) try {
|
|
321
|
+
if (ISR_PATTERN.test(fs.readFileSync(fullPath, "utf-8"))) found.isr = true;
|
|
322
|
+
} catch {}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
walk(dir);
|
|
327
|
+
return found;
|
|
328
|
+
}
|
|
329
|
+
function detectMDXFromConfig(root) {
|
|
330
|
+
for (const f of [
|
|
331
|
+
"next.config.ts",
|
|
332
|
+
"next.config.mts",
|
|
333
|
+
"next.config.mjs",
|
|
334
|
+
"next.config.js",
|
|
335
|
+
"next.config.cjs"
|
|
336
|
+
]) {
|
|
337
|
+
const p = path.join(root, f);
|
|
338
|
+
if (fs.existsSync(p)) try {
|
|
339
|
+
const content = fs.readFileSync(p, "utf-8");
|
|
340
|
+
if (/pageExtensions.*mdx/i.test(content) || /@next\/mdx/.test(content)) return true;
|
|
341
|
+
} catch {}
|
|
342
|
+
}
|
|
343
|
+
return false;
|
|
344
|
+
}
|
|
345
|
+
function detectCacheComponents(root) {
|
|
346
|
+
for (const fileName of [
|
|
347
|
+
"next.config.ts",
|
|
348
|
+
"next.config.mts",
|
|
349
|
+
"next.config.mjs",
|
|
350
|
+
"next.config.js",
|
|
351
|
+
"next.config.cjs"
|
|
352
|
+
]) {
|
|
353
|
+
const configPath = path.join(root, fileName);
|
|
354
|
+
if (!fs.existsSync(configPath)) continue;
|
|
355
|
+
try {
|
|
356
|
+
if (/\bcacheComponents\s*:\s*true\b/.test(fs.readFileSync(configPath, "utf-8"))) return true;
|
|
357
|
+
} catch {}
|
|
358
|
+
}
|
|
359
|
+
return false;
|
|
360
|
+
}
|
|
361
|
+
const NATIVE_MODULES_TO_STUB = [
|
|
362
|
+
"@resvg/resvg-js",
|
|
363
|
+
"satori",
|
|
364
|
+
"lightningcss",
|
|
365
|
+
"@napi-rs/canvas",
|
|
366
|
+
"sharp"
|
|
367
|
+
];
|
|
368
|
+
function detectNativeModules(allDeps) {
|
|
369
|
+
return NATIVE_MODULES_TO_STUB.filter((mod) => mod in allDeps);
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Check if a package is resolvable from a given root directory using Node's
|
|
373
|
+
* module resolution. Handles hoisting, pnpm symlinks, monorepos, and Yarn PnP.
|
|
374
|
+
*/
|
|
375
|
+
function isPackageResolvable(root, packageName) {
|
|
376
|
+
try {
|
|
377
|
+
createRequire(path.join(root, "package.json")).resolve(packageName);
|
|
378
|
+
return true;
|
|
379
|
+
} catch {
|
|
380
|
+
return false;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
function getMissingDeps(info, _isResolvable = isPackageResolvable) {
|
|
384
|
+
const missing = [];
|
|
385
|
+
if (!info.hasCloudflarePlugin) missing.push({
|
|
386
|
+
name: "@cloudflare/vite-plugin",
|
|
387
|
+
version: "latest"
|
|
388
|
+
});
|
|
389
|
+
if (!info.hasWrangler) missing.push({
|
|
390
|
+
name: "wrangler",
|
|
391
|
+
version: "latest"
|
|
392
|
+
});
|
|
393
|
+
if (!_isResolvable(info.root, "@vitejs/plugin-react")) missing.push({
|
|
394
|
+
name: "@vitejs/plugin-react",
|
|
395
|
+
version: "latest"
|
|
396
|
+
});
|
|
397
|
+
if (info.isAppRouter && !info.hasRscPlugin) missing.push({
|
|
398
|
+
name: "@vitejs/plugin-rsc",
|
|
399
|
+
version: "latest"
|
|
400
|
+
});
|
|
401
|
+
if (info.isAppRouter && !_isResolvable(info.root, "react-server-dom-webpack")) missing.push({
|
|
402
|
+
name: "react-server-dom-webpack",
|
|
403
|
+
version: "latest"
|
|
404
|
+
});
|
|
405
|
+
if (info.hasMDX && !_isResolvable(info.root, "@mdx-js/rollup")) missing.push({
|
|
406
|
+
name: "@mdx-js/rollup",
|
|
407
|
+
version: "latest"
|
|
408
|
+
});
|
|
409
|
+
return missing;
|
|
191
410
|
}
|
|
192
411
|
/**
|
|
193
412
|
* Return the first candidate directory (resolved against `root`) that exists,
|
|
@@ -209,9 +428,11 @@ function findDir(root, ...candidates) {
|
|
|
209
428
|
}
|
|
210
429
|
/**
|
|
211
430
|
* Check if the project uses App Router (has an app/ directory).
|
|
431
|
+
*
|
|
432
|
+
* `root` must be forward-slash — it is passed straight to `findDir`.
|
|
212
433
|
*/
|
|
213
434
|
function hasAppDir(root) {
|
|
214
|
-
return findDir(root, "app",
|
|
435
|
+
return findDir(root, "app", "src/app") !== null;
|
|
215
436
|
}
|
|
216
437
|
//#endregion
|
|
217
|
-
export { detectPackageManager, detectPackageManagerName, ensureESModule, ensureViteConfigCompatibility, findDir, findInNodeModules, hasAppDir, hasViteConfig, renameCJSConfigs };
|
|
438
|
+
export { detectPackageManager, detectPackageManagerName, detectProject, ensureESModule, ensureViteConfigCompatibility, findDir, findInNodeModules, findViteConfigPath, formatMissingCloudflarePluginError, getMissingDeps, hasAppDir, hasViteConfig, hasWranglerConfig, isPackageResolvable, renameCJSConfigs };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/utils/protocol-headers.d.ts
|
|
2
|
+
/** Serialized middleware context (JSON) forwarded from dev server to RSC entry. */
|
|
3
|
+
declare const VINEXT_MW_CTX_HEADER = "x-vinext-mw-ctx";
|
|
4
|
+
/** Build-time prerender authentication secret. */
|
|
5
|
+
declare const VINEXT_PRERENDER_SECRET_HEADER = "x-vinext-prerender-secret";
|
|
6
|
+
/** URL-encoded JSON route params for build-time prerender renders. */
|
|
7
|
+
declare const VINEXT_PRERENDER_ROUTE_PARAMS_HEADER = "x-vinext-prerender-route-params";
|
|
8
|
+
/** Indicates a build-time prerender render is probing whether a route can be static. */
|
|
9
|
+
declare const VINEXT_PRERENDER_SPECULATIVE_HEADER = "x-vinext-prerender-speculative";
|
|
10
|
+
/** Prefix for forwarded request headers (e.g. `x-middleware-request-cookie`). */
|
|
11
|
+
declare const MIDDLEWARE_REQUEST_HEADER_PREFIX = "x-middleware-request-";
|
|
12
|
+
/** Comma-separated list of header names that middleware wants to override. */
|
|
13
|
+
declare const MIDDLEWARE_OVERRIDE_HEADERS = "x-middleware-override-headers";
|
|
14
|
+
/** Carries cookies set by middleware for same-render reads. */
|
|
15
|
+
declare const MIDDLEWARE_SET_COOKIE_HEADER = "x-middleware-set-cookie";
|
|
16
|
+
/** Signals Pages Router prefetch cache opt-out. */
|
|
17
|
+
declare const MIDDLEWARE_CACHE_HEADER = "x-middleware-cache";
|
|
18
|
+
/** Skip-middleware signal. */
|
|
19
|
+
declare const MIDDLEWARE_SKIP_HEADER = "x-middleware-skip";
|
|
20
|
+
/** Generic prefix for all middleware internal headers. */
|
|
21
|
+
declare const MIDDLEWARE_HEADER_PREFIX = "x-middleware-";
|
|
22
|
+
//#endregion
|
|
23
|
+
export { MIDDLEWARE_CACHE_HEADER, MIDDLEWARE_HEADER_PREFIX, MIDDLEWARE_OVERRIDE_HEADERS, MIDDLEWARE_REQUEST_HEADER_PREFIX, MIDDLEWARE_SET_COOKIE_HEADER, MIDDLEWARE_SKIP_HEADER, VINEXT_MW_CTX_HEADER, VINEXT_PRERENDER_ROUTE_PARAMS_HEADER, VINEXT_PRERENDER_SECRET_HEADER, VINEXT_PRERENDER_SPECULATIVE_HEADER };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/utils/protocol-headers.ts
|
|
2
|
+
/** Serialized middleware context (JSON) forwarded from dev server to RSC entry. */
|
|
3
|
+
const VINEXT_MW_CTX_HEADER = "x-vinext-mw-ctx";
|
|
4
|
+
/** Build-time prerender authentication secret. */
|
|
5
|
+
const VINEXT_PRERENDER_SECRET_HEADER = "x-vinext-prerender-secret";
|
|
6
|
+
/** URL-encoded JSON route params for build-time prerender renders. */
|
|
7
|
+
const VINEXT_PRERENDER_ROUTE_PARAMS_HEADER = "x-vinext-prerender-route-params";
|
|
8
|
+
/** Indicates a build-time prerender render is probing whether a route can be static. */
|
|
9
|
+
const VINEXT_PRERENDER_SPECULATIVE_HEADER = "x-vinext-prerender-speculative";
|
|
10
|
+
/** Prefix for forwarded request headers (e.g. `x-middleware-request-cookie`). */
|
|
11
|
+
const MIDDLEWARE_REQUEST_HEADER_PREFIX = "x-middleware-request-";
|
|
12
|
+
/** Comma-separated list of header names that middleware wants to override. */
|
|
13
|
+
const MIDDLEWARE_OVERRIDE_HEADERS = "x-middleware-override-headers";
|
|
14
|
+
/** Carries cookies set by middleware for same-render reads. */
|
|
15
|
+
const MIDDLEWARE_SET_COOKIE_HEADER = "x-middleware-set-cookie";
|
|
16
|
+
/** Signals Pages Router prefetch cache opt-out. */
|
|
17
|
+
const MIDDLEWARE_CACHE_HEADER = "x-middleware-cache";
|
|
18
|
+
/** Skip-middleware signal. */
|
|
19
|
+
const MIDDLEWARE_SKIP_HEADER = "x-middleware-skip";
|
|
20
|
+
/** Generic prefix for all middleware internal headers. */
|
|
21
|
+
const MIDDLEWARE_HEADER_PREFIX = "x-middleware-";
|
|
22
|
+
//#endregion
|
|
23
|
+
export { MIDDLEWARE_CACHE_HEADER, MIDDLEWARE_HEADER_PREFIX, MIDDLEWARE_OVERRIDE_HEADERS, MIDDLEWARE_REQUEST_HEADER_PREFIX, MIDDLEWARE_SET_COOKIE_HEADER, MIDDLEWARE_SKIP_HEADER, VINEXT_MW_CTX_HEADER, VINEXT_PRERENDER_ROUTE_PARAMS_HEADER, VINEXT_PRERENDER_SECRET_HEADER, VINEXT_PRERENDER_SPECULATIVE_HEADER };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
//#region src/utils/react-version.ts
|
|
5
|
+
function getDependencyUpgradeDeps(root, recommendations) {
|
|
6
|
+
const req = createRequire(path.join(root, "package.json"));
|
|
7
|
+
for (const [dependency, recommendation] of Object.entries(recommendations)) try {
|
|
8
|
+
const version = findPackageVersion(req.resolve(dependency), dependency);
|
|
9
|
+
if (version && isVersionBelow(version, recommendation.minimumVersion)) return recommendation.upgrades;
|
|
10
|
+
} catch {
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
function getReactUpgradeDeps(root) {
|
|
16
|
+
return getDependencyUpgradeDeps(root, { react: {
|
|
17
|
+
minimumVersion: [
|
|
18
|
+
19,
|
|
19
|
+
2,
|
|
20
|
+
6
|
|
21
|
+
],
|
|
22
|
+
upgrades: ["react@latest", "react-dom@latest"]
|
|
23
|
+
} });
|
|
24
|
+
}
|
|
25
|
+
function isVersionBelow(version, minimum) {
|
|
26
|
+
const current = version.split(".").map((part) => parseInt(part, 10));
|
|
27
|
+
for (let index = 0; index < minimum.length; index++) if ((current[index] ?? 0) !== minimum[index]) return (current[index] ?? 0) < minimum[index];
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
/** Walk up from a resolved module entry to find its package version. */
|
|
31
|
+
function findPackageVersion(resolvedEntry, packageName) {
|
|
32
|
+
let dir = path.dirname(resolvedEntry);
|
|
33
|
+
while (dir !== path.dirname(dir)) {
|
|
34
|
+
const candidate = path.join(dir, "package.json");
|
|
35
|
+
try {
|
|
36
|
+
const pkg = JSON.parse(fs.readFileSync(candidate, "utf-8"));
|
|
37
|
+
if (pkg.name === packageName) return pkg.version ?? null;
|
|
38
|
+
} catch {}
|
|
39
|
+
dir = path.dirname(dir);
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { getReactUpgradeDeps };
|
|
@@ -5,9 +5,11 @@ declare function getDepOptimizeNodeEnvOptions(viteMajorVersion: number, nodeEnvD
|
|
|
5
5
|
transform: {
|
|
6
6
|
define: Record<string, string>;
|
|
7
7
|
};
|
|
8
|
+
moduleTypes?: Record<string, "jsx">;
|
|
8
9
|
};
|
|
9
10
|
esbuildOptions?: {
|
|
10
11
|
define: Record<string, string>;
|
|
12
|
+
loader?: Record<string, "jsx">;
|
|
11
13
|
};
|
|
12
14
|
};
|
|
13
15
|
/**
|