vinext 0.1.7 → 0.2.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 +51 -30
- package/dist/build/inject-pregenerated-paths.d.ts +4 -0
- package/dist/build/inject-pregenerated-paths.js +18 -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.d.ts +2 -1
- package/dist/build/prerender.js +13 -6
- 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 +10 -1
- package/dist/build/standalone.js +2 -0
- package/dist/cache/cache-adapters-virtual.js +3 -3
- package/dist/check.d.ts +18 -0
- package/dist/check.js +77 -19
- 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 +113 -97
- 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/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 +14 -10
- package/dist/config/next-config.d.ts +6 -3
- package/dist/config/next-config.js +47 -1
- package/dist/config/prerender.d.ts +34 -0
- package/dist/config/prerender.js +55 -0
- package/dist/config/server-external-packages.d.ts +4 -0
- package/dist/config/server-external-packages.js +91 -0
- package/dist/entries/app-rsc-entry.d.ts +2 -1
- package/dist/entries/app-rsc-entry.js +89 -15
- package/dist/entries/app-rsc-manifest.js +10 -0
- package/dist/entries/pages-client-entry.d.ts +3 -0
- package/dist/entries/pages-client-entry.js +16 -1
- package/dist/entries/pages-server-entry.js +6 -2
- 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 +211 -118
- 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 +208 -97
- 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 +1 -1
- 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 +276 -0
- package/dist/{cloudflare → packages/cloudflare/src}/tpr.d.ts +4 -41
- package/dist/{cloudflare → packages/cloudflare/src}/tpr.js +18 -15
- 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/ignore-dynamic-requests.d.ts +11 -0
- package/dist/plugins/ignore-dynamic-requests.js +530 -0
- package/dist/plugins/middleware-server-only.d.ts +8 -6
- package/dist/plugins/middleware-server-only.js +8 -7
- package/dist/plugins/optimize-imports.js +1 -1
- 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 +29 -4
- package/dist/routing/app-route-graph.js +182 -40
- package/dist/routing/app-router.d.ts +5 -0
- package/dist/routing/app-router.js +5 -0
- package/dist/routing/file-matcher.d.ts +8 -0
- package/dist/routing/file-matcher.js +10 -1
- 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 +194 -190
- package/dist/server/app-browser-history-controller.d.ts +2 -1
- package/dist/server/app-browser-history-controller.js +6 -2
- 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 +32 -0
- package/dist/server/app-browser-server-action-client.js +127 -0
- package/dist/server/app-browser-state.d.ts +11 -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 +43 -25
- 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 +5 -2
- package/dist/server/app-fallback-renderer.js +15 -7
- 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-render.d.ts +3 -0
- package/dist/server/app-page-boundary-render.js +14 -3
- package/dist/server/app-page-cache-finalizer.d.ts +1 -0
- package/dist/server/app-page-cache-finalizer.js +10 -3
- 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 +5 -2
- package/dist/server/app-page-dispatch.d.ts +33 -4
- package/dist/server/app-page-dispatch.js +63 -90
- package/dist/server/app-page-element-builder.d.ts +9 -2
- package/dist/server/app-page-element-builder.js +114 -23
- package/dist/server/app-page-head.d.ts +16 -1
- package/dist/server/app-page-head.js +44 -22
- package/dist/server/app-page-params.d.ts +2 -1
- package/dist/server/app-page-params.js +8 -1
- package/dist/server/app-page-ppr-runtime.d.ts +7 -0
- package/dist/server/app-page-ppr-runtime.js +70 -0
- package/dist/server/app-page-probe.d.ts +1 -0
- package/dist/server/app-page-probe.js +6 -1
- package/dist/server/app-page-render-identity.d.ts +1 -0
- package/dist/server/app-page-render-identity.js +1 -1
- package/dist/server/app-page-render.d.ts +4 -1
- package/dist/server/app-page-render.js +26 -3
- package/dist/server/app-page-request.d.ts +22 -1
- package/dist/server/app-page-request.js +92 -15
- package/dist/server/app-page-route-wiring.d.ts +14 -2
- package/dist/server/app-page-route-wiring.js +61 -25
- package/dist/server/app-page-search-params-observation.d.ts +4 -2
- package/dist/server/app-page-search-params-observation.js +11 -7
- 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 +5 -0
- package/dist/server/app-page-stream.js +3 -1
- package/dist/server/app-ppr-fallback-shell-render.d.ts +4 -3
- package/dist/server/app-route-handler-dispatch.js +1 -0
- package/dist/server/app-route-handler-execution.js +7 -2
- 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-module-loader.d.ts +2 -0
- package/dist/server/app-route-module-loader.js +1 -0
- package/dist/server/app-router-entry.js +16 -8
- package/dist/server/app-rsc-errors.js +7 -1
- package/dist/server/app-rsc-handler.d.ts +3 -1
- package/dist/server/app-rsc-handler.js +67 -39
- package/dist/server/app-rsc-request-normalization.d.ts +3 -2
- package/dist/server/app-rsc-request-normalization.js +6 -3
- package/dist/server/app-rsc-route-matching.d.ts +7 -0
- package/dist/server/app-rsc-route-matching.js +36 -3
- package/dist/server/app-segment-config.d.ts +12 -0
- package/dist/server/app-segment-config.js +91 -5
- package/dist/server/app-server-action-execution.d.ts +5 -0
- package/dist/server/app-server-action-execution.js +94 -33
- package/dist/server/app-ssr-entry.d.ts +3 -0
- package/dist/server/app-ssr-entry.js +19 -8
- package/dist/server/app-ssr-stream.d.ts +7 -3
- package/dist/server/app-ssr-stream.js +10 -6
- package/dist/server/app-static-generation.d.ts +1 -0
- package/dist/server/app-static-generation.js +1 -0
- package/dist/server/app-visited-response-cache.d.ts +6 -0
- package/dist/server/app-visited-response-cache.js +3 -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.js +19 -18
- 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 +5 -15
- package/dist/server/headers.js +4 -15
- 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 +1 -1
- package/dist/server/isr-cache.js +2 -2
- 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-node-compat.d.ts +8 -1
- package/dist/server/pages-node-compat.js +32 -4
- package/dist/server/pages-page-data.d.ts +24 -1
- package/dist/server/pages-page-data.js +45 -24
- package/dist/server/pages-page-handler.d.ts +2 -1
- package/dist/server/pages-page-handler.js +19 -12
- package/dist/server/pages-page-response.d.ts +7 -0
- package/dist/server/pages-page-response.js +4 -1
- package/dist/server/pages-request-pipeline.d.ts +2 -0
- package/dist/server/pages-request-pipeline.js +25 -1
- 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 +1 -1
- package/dist/server/prod-server.js +48 -26
- package/dist/server/request-pipeline.js +1 -0
- package/dist/server/seed-cache.js +4 -4
- package/dist/server/worker-utils.d.ts +2 -1
- package/dist/server/worker-utils.js +7 -1
- 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.js +19 -15
- package/dist/shims/cdn-cache.js +1 -1
- package/dist/shims/dynamic-preload-chunks.js +2 -1
- package/dist/shims/error-boundary.d.ts +19 -1
- package/dist/shims/error-boundary.js +11 -1
- package/dist/shims/form.d.ts +3 -1
- package/dist/shims/form.js +37 -43
- package/dist/shims/headers.d.ts +9 -1
- package/dist/shims/headers.js +31 -6
- package/dist/shims/image.js +75 -14
- 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 +2 -15
- package/dist/shims/internal/hybrid-client-route-owner.js +9 -60
- package/dist/shims/internal/pages-data-fetch-dedup.d.ts +9 -5
- package/dist/shims/internal/pages-data-fetch-dedup.js +73 -14
- package/dist/shims/internal/pages-data-target.d.ts +10 -9
- package/dist/shims/internal/pages-data-target.js +91 -12
- 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.js +70 -37
- package/dist/shims/metadata.d.ts +3 -2
- package/dist/shims/metadata.js +8 -4
- package/dist/shims/navigation.d.ts +5 -1
- package/dist/shims/navigation.js +45 -10
- package/dist/shims/navigation.react-server.js +1 -1
- 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 +374 -94
- package/dist/shims/server.js +3 -2
- package/dist/shims/slot.js +3 -6
- package/dist/typegen.js +6 -5
- 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 +2 -2
- package/dist/utils/path.d.ts +2 -1
- package/dist/utils/path.js +1 -1
- package/dist/utils/project.d.ts +52 -2
- package/dist/utils/project.js +230 -5
- package/dist/utils/protocol-headers.d.ts +17 -0
- package/dist/utils/protocol-headers.js +17 -0
- package/dist/utils/react-version.d.ts +4 -0
- package/dist/utils/react-version.js +44 -0
- package/package.json +53 -4
- package/dist/deploy.d.ts +0 -190
- package/dist/deploy.js +0 -1033
- 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) {
|
package/dist/typegen.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { findDir } from "./utils/project.js";
|
|
2
2
|
import { decodeRouteSegment, isInvisibleSegment } from "./routing/utils.js";
|
|
3
|
+
import { normalizePathSeparators } from "./utils/path.js";
|
|
3
4
|
import { patternToNextFormat } from "./routing/route-validation.js";
|
|
4
5
|
import { compareStrings } from "./utils/compare.js";
|
|
5
6
|
import "./routing/app-route-graph.js";
|
|
@@ -15,17 +16,17 @@ import "./.next/types/routes.d.ts";
|
|
|
15
16
|
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
|
|
16
17
|
`;
|
|
17
18
|
async function generateRouteTypes(options) {
|
|
18
|
-
const root = path.resolve(options.root);
|
|
19
|
-
const appDir = options.appDir ? path.resolve(options.appDir) : findDir(root, "app",
|
|
20
|
-
const outPath = path.join(root, ".next", "types", "routes.d.ts");
|
|
19
|
+
const root = normalizePathSeparators(path.resolve(options.root));
|
|
20
|
+
const appDir = options.appDir ? normalizePathSeparators(path.resolve(options.appDir)) : findDir(root, "app", "src/app");
|
|
21
|
+
const outPath = path.posix.join(root, ".next", "types", "routes.d.ts");
|
|
21
22
|
const content = appDir ? renderRouteTypes(await collectRouteTypeModel(appDir, options.pageExtensions)) : renderRouteTypes(emptyRouteTypeModel());
|
|
22
|
-
await fs.mkdir(path.dirname(outPath), { recursive: true });
|
|
23
|
+
await fs.mkdir(path.posix.dirname(outPath), { recursive: true });
|
|
23
24
|
await fs.writeFile(outPath, content, "utf-8");
|
|
24
25
|
await ensureNextEnvFile(root);
|
|
25
26
|
return outPath;
|
|
26
27
|
}
|
|
27
28
|
async function ensureNextEnvFile(root) {
|
|
28
|
-
const envPath = path.join(root, "next-env.d.ts");
|
|
29
|
+
const envPath = path.posix.join(root, "next-env.d.ts");
|
|
29
30
|
try {
|
|
30
31
|
await fs.writeFile(envPath, NEXT_ENV_FILE_CONTENT, {
|
|
31
32
|
encoding: "utf-8",
|
|
@@ -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);
|
package/dist/utils/path.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
//#region src/utils/path.d.ts
|
|
2
|
+
declare const isWindows: boolean;
|
|
2
3
|
/**
|
|
3
4
|
* Convert Windows-style backslash path separators to forward slashes.
|
|
4
5
|
*
|
|
@@ -19,4 +20,4 @@ declare function stripViteModuleQuery(id: string): string;
|
|
|
19
20
|
* files like `headers.js.ts`. */
|
|
20
21
|
declare function stripJsExtension(name: string): string;
|
|
21
22
|
//#endregion
|
|
22
|
-
export { normalizePathSeparators, stripJsExtension, stripViteModuleQuery };
|
|
23
|
+
export { isWindows, normalizePathSeparators, stripJsExtension, stripViteModuleQuery };
|
package/dist/utils/path.js
CHANGED
|
@@ -27,4 +27,4 @@ function stripJsExtension(name) {
|
|
|
27
27
|
return name.endsWith(".js") ? name.slice(0, -3) : name;
|
|
28
28
|
}
|
|
29
29
|
//#endregion
|
|
30
|
-
export { normalizePathSeparators, stripJsExtension, stripViteModuleQuery };
|
|
30
|
+
export { isWindows, normalizePathSeparators, stripJsExtension, stripViteModuleQuery };
|
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,15 +63,64 @@ 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
|
|
68
112
|
* at the root or under `src/`.
|
|
113
|
+
*
|
|
114
|
+
* `root` and `candidates` must be forward-slash, and the returned path is
|
|
115
|
+
* forward-slash too: the candidate is joined with `path.posix.join`, which only
|
|
116
|
+
* stays canonical when its inputs already are.
|
|
69
117
|
*/
|
|
70
118
|
declare function findDir(root: string, ...candidates: string[]): string | null;
|
|
71
119
|
/**
|
|
72
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`.
|
|
73
123
|
*/
|
|
74
124
|
declare function hasAppDir(root: string): boolean;
|
|
75
125
|
//#endregion
|
|
76
|
-
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,16 +189,237 @@ 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,
|
|
194
413
|
* or null. Used to locate conventional `app`/`pages` directories that may live
|
|
195
414
|
* at the root or under `src/`.
|
|
415
|
+
*
|
|
416
|
+
* `root` and `candidates` must be forward-slash, and the returned path is
|
|
417
|
+
* forward-slash too: the candidate is joined with `path.posix.join`, which only
|
|
418
|
+
* stays canonical when its inputs already are.
|
|
196
419
|
*/
|
|
197
420
|
function findDir(root, ...candidates) {
|
|
198
421
|
for (const candidate of candidates) {
|
|
199
|
-
const full = path.join(root, candidate);
|
|
422
|
+
const full = path.posix.join(root, candidate);
|
|
200
423
|
try {
|
|
201
424
|
if (fs.statSync(full).isDirectory()) return full;
|
|
202
425
|
} catch {}
|
|
@@ -205,9 +428,11 @@ function findDir(root, ...candidates) {
|
|
|
205
428
|
}
|
|
206
429
|
/**
|
|
207
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`.
|
|
208
433
|
*/
|
|
209
434
|
function hasAppDir(root) {
|
|
210
|
-
return findDir(root, "app",
|
|
435
|
+
return findDir(root, "app", "src/app") !== null;
|
|
211
436
|
}
|
|
212
437
|
//#endregion
|
|
213
|
-
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,17 @@
|
|
|
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
|
+
/** Prefix for forwarded request headers (e.g. `x-middleware-request-cookie`). */
|
|
9
|
+
declare const MIDDLEWARE_REQUEST_HEADER_PREFIX = "x-middleware-request-";
|
|
10
|
+
/** Comma-separated list of header names that middleware wants to override. */
|
|
11
|
+
declare const MIDDLEWARE_OVERRIDE_HEADERS = "x-middleware-override-headers";
|
|
12
|
+
/** Carries cookies set by middleware for same-render reads. */
|
|
13
|
+
declare const MIDDLEWARE_SET_COOKIE_HEADER = "x-middleware-set-cookie";
|
|
14
|
+
/** Generic prefix for all middleware internal headers. */
|
|
15
|
+
declare const MIDDLEWARE_HEADER_PREFIX = "x-middleware-";
|
|
16
|
+
//#endregion
|
|
17
|
+
export { MIDDLEWARE_HEADER_PREFIX, MIDDLEWARE_OVERRIDE_HEADERS, MIDDLEWARE_REQUEST_HEADER_PREFIX, MIDDLEWARE_SET_COOKIE_HEADER, VINEXT_MW_CTX_HEADER, VINEXT_PRERENDER_ROUTE_PARAMS_HEADER, VINEXT_PRERENDER_SECRET_HEADER };
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
/** Prefix for forwarded request headers (e.g. `x-middleware-request-cookie`). */
|
|
9
|
+
const MIDDLEWARE_REQUEST_HEADER_PREFIX = "x-middleware-request-";
|
|
10
|
+
/** Comma-separated list of header names that middleware wants to override. */
|
|
11
|
+
const MIDDLEWARE_OVERRIDE_HEADERS = "x-middleware-override-headers";
|
|
12
|
+
/** Carries cookies set by middleware for same-render reads. */
|
|
13
|
+
const MIDDLEWARE_SET_COOKIE_HEADER = "x-middleware-set-cookie";
|
|
14
|
+
/** Generic prefix for all middleware internal headers. */
|
|
15
|
+
const MIDDLEWARE_HEADER_PREFIX = "x-middleware-";
|
|
16
|
+
//#endregion
|
|
17
|
+
export { MIDDLEWARE_HEADER_PREFIX, MIDDLEWARE_OVERRIDE_HEADERS, MIDDLEWARE_REQUEST_HEADER_PREFIX, MIDDLEWARE_SET_COOKIE_HEADER, VINEXT_MW_CTX_HEADER, VINEXT_PRERENDER_ROUTE_PARAMS_HEADER, VINEXT_PRERENDER_SECRET_HEADER };
|