vinext 0.1.8 → 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.js +40 -2
- 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 +111 -95
- 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 +5 -3
- package/dist/config/next-config.js +44 -1
- package/dist/config/prerender.d.ts +34 -0
- package/dist/config/prerender.js +55 -0
- package/dist/entries/app-rsc-entry.d.ts +2 -1
- package/dist/entries/app-rsc-entry.js +40 -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 +15 -1
- package/dist/entries/pages-server-entry.js +5 -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 +167 -100
- 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 +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/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 +126 -32
- package/dist/routing/file-matcher.d.ts +3 -0
- package/dist/routing/file-matcher.js +3 -0
- 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 +161 -52
- 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 +3 -4
- 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 +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-cache-finalizer.js +2 -1
- 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.js +1 -0
- package/dist/server/app-page-element-builder.d.ts +2 -1
- package/dist/server/app-page-element-builder.js +58 -4
- package/dist/server/app-page-probe.js +5 -0
- 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.js +18 -0
- package/dist/server/app-page-request.d.ts +14 -0
- package/dist/server/app-page-request.js +69 -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 +5 -0
- 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-router-entry.js +9 -2
- package/dist/server/app-rsc-handler.d.ts +1 -0
- package/dist/server/app-rsc-handler.js +62 -31
- 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-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 +58 -28
- package/dist/server/app-ssr-entry.d.ts +3 -0
- package/dist/server/app-ssr-entry.js +15 -7
- 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/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 +3 -15
- package/dist/server/headers.js +2 -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 +33 -20
- package/dist/server/request-pipeline.js +1 -0
- 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.js +19 -15
- package/dist/shims/cdn-cache.js +1 -1
- package/dist/shims/dynamic-preload-chunks.js +2 -1
- package/dist/shims/form.d.ts +3 -1
- 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-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 +55 -26
- 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 +362 -93
- package/dist/shims/server.js +3 -2
- package/dist/shims/slot.js +3 -6
- 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/project.d.ts +48 -2
- package/dist/utils/project.js +225 -4
- 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 +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
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
//#region src/image/image-adapters-virtual.ts
|
|
2
|
+
/** Public virtual module id imported by the server entries. */
|
|
3
|
+
const VIRTUAL_IMAGE_ADAPTERS = "virtual:vinext-image-adapters";
|
|
4
|
+
/**
|
|
5
|
+
* Serialize descriptor options into a JS expression for inlining. Plain JSON is
|
|
6
|
+
* a valid JS literal; `undefined` when there are no options. Throws a clear
|
|
7
|
+
* config-time error (not a runtime one) if options are not serializable.
|
|
8
|
+
*/
|
|
9
|
+
function inlineOptions(adapter, options) {
|
|
10
|
+
if (options === void 0) return "undefined";
|
|
11
|
+
try {
|
|
12
|
+
return JSON.stringify(options);
|
|
13
|
+
} catch (cause) {
|
|
14
|
+
throw new Error(`[vinext] image adapter "${adapter}" options must be JSON-serializable.`, { cause });
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Generate the source of the `virtual:vinext-image-adapters` module for the
|
|
19
|
+
* given config. Always exports `registerConfiguredImageOptimizer(env)`.
|
|
20
|
+
*/
|
|
21
|
+
function generateImageAdaptersModule(images) {
|
|
22
|
+
const optimizer = images?.optimizer;
|
|
23
|
+
if (!optimizer?.adapter) return [
|
|
24
|
+
"// vinext: no images.optimizer adapter configured — registration is a no-op.",
|
|
25
|
+
"export function registerConfiguredImageOptimizer() {}",
|
|
26
|
+
""
|
|
27
|
+
].join("\n");
|
|
28
|
+
return [
|
|
29
|
+
"// vinext: generated from the `images` option in your vinext() plugin config.",
|
|
30
|
+
`import __vinextImageOptimizerFactory from ${JSON.stringify(optimizer.adapter)};`,
|
|
31
|
+
`import { setImageOptimizer } from "vinext/server/image-optimization";`,
|
|
32
|
+
"",
|
|
33
|
+
"// A factory that throws (e.g. a missing binding on an incompatible runtime)",
|
|
34
|
+
"// is logged and skipped so images fall back to unoptimized passthrough.",
|
|
35
|
+
"function __vinextFormatAdapterError(error) {",
|
|
36
|
+
" if (error instanceof Error && error.message) return error.message;",
|
|
37
|
+
" try {",
|
|
38
|
+
" return String(error);",
|
|
39
|
+
" } catch {",
|
|
40
|
+
" return '<unknown error>';",
|
|
41
|
+
" }",
|
|
42
|
+
"}",
|
|
43
|
+
"",
|
|
44
|
+
"let __vinextImageOptimizerRegistered = false;",
|
|
45
|
+
"",
|
|
46
|
+
"export function registerConfiguredImageOptimizer(env) {",
|
|
47
|
+
" if (__vinextImageOptimizerRegistered) return;",
|
|
48
|
+
" __vinextImageOptimizerRegistered = true;",
|
|
49
|
+
" try {",
|
|
50
|
+
` setImageOptimizer(__vinextImageOptimizerFactory({ env, options: ${inlineOptions(optimizer.adapter, optimizer.options)} }));`,
|
|
51
|
+
" } catch (error) {",
|
|
52
|
+
" console.warn(\"[vinext] failed to initialize the configured image optimizer; serving images unoptimized.\\n\" + __vinextFormatAdapterError(error));",
|
|
53
|
+
" }",
|
|
54
|
+
"}",
|
|
55
|
+
""
|
|
56
|
+
].join("\n");
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
export { VIRTUAL_IMAGE_ADAPTERS, generateImageAdaptersModule };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { NextConfig, NextConfigInput } from "./config/next-config.js";
|
|
2
2
|
import { AppStaticExportOptions, StaticExportOptions, StaticExportResult, staticExportApp, staticExportPages } from "./build/static-export.js";
|
|
3
3
|
import { VinextCacheConfig } from "./cache/cache-adapters-virtual.js";
|
|
4
|
+
import { VinextPrerenderConfig } from "./config/prerender.js";
|
|
5
|
+
import { VinextImageConfig } from "./image/image-adapters-virtual.js";
|
|
4
6
|
import { PluginOption } from "vite";
|
|
5
7
|
import { Options } from "@vitejs/plugin-react";
|
|
6
8
|
|
|
@@ -79,6 +81,26 @@ type VinextOptions = {
|
|
|
79
81
|
* @default false
|
|
80
82
|
*/
|
|
81
83
|
precompress?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Pre-render routes after `vinext build` without passing
|
|
86
|
+
* `--prerender-all`.
|
|
87
|
+
*
|
|
88
|
+
* Use `true` as shorthand for `{ routes: "*" }`. The object form is
|
|
89
|
+
* available so future releases can support narrower route selections, but
|
|
90
|
+
* currently only `"*"` is supported.
|
|
91
|
+
*
|
|
92
|
+
* The `vinext build --prerender-all` and `vinext deploy --prerender-all`
|
|
93
|
+
* flags still work and take priority when present.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* vinext({ prerender: true })
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* vinext({ prerender: { routes: "*" } })
|
|
100
|
+
*
|
|
101
|
+
* @default undefined
|
|
102
|
+
*/
|
|
103
|
+
prerender?: VinextPrerenderConfig;
|
|
82
104
|
/**
|
|
83
105
|
* Configure cache handlers declaratively, so you don't need a custom worker
|
|
84
106
|
* entry that calls `setDataCacheHandler()` / `setCdnCacheAdapter()`. Each slot
|
|
@@ -97,6 +119,17 @@ type VinextOptions = {
|
|
|
97
119
|
* })
|
|
98
120
|
*/
|
|
99
121
|
cache?: VinextCacheConfig;
|
|
122
|
+
/**
|
|
123
|
+
* Configure the server-side image optimizer declaratively. The adapter factory
|
|
124
|
+
* receives the host `env`, allowing bindings such as Cloudflare Images to be
|
|
125
|
+
* used by both built-in and custom worker entrypoints that forward `env`.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* import { imagesOptimizer } from "@vinext/cloudflare/images/images-optimizer";
|
|
129
|
+
*
|
|
130
|
+
* vinext({ images: { optimizer: imagesOptimizer() } })
|
|
131
|
+
*/
|
|
132
|
+
images?: VinextImageConfig;
|
|
100
133
|
/**
|
|
101
134
|
* Experimental vinext-only feature flags.
|
|
102
135
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1,32 +1,37 @@
|
|
|
1
|
-
import { detectPackageManager } from "./utils/project.js";
|
|
1
|
+
import { detectPackageManager, formatMissingCloudflarePluginError, hasWranglerConfig } from "./utils/project.js";
|
|
2
2
|
import { normalizePathnameForRouteMatchStrict } from "./routing/utils.js";
|
|
3
3
|
import { escapeRegExp } from "./utils/regex.js";
|
|
4
4
|
import { normalizePathSeparators, stripJsExtension, stripViteModuleQuery } from "./utils/path.js";
|
|
5
5
|
import { buildViteResolveExtensions, createValidFileMatcher, findFileWithExts, normalizeViteResolveExtensions } from "./routing/file-matcher.js";
|
|
6
6
|
import { apiRouter, invalidateRouteCache, matchRoute, pagesRouter } from "./routing/pages-router.js";
|
|
7
|
-
import {
|
|
7
|
+
import { VINEXT_MW_CTX_HEADER } from "./utils/protocol-headers.js";
|
|
8
|
+
import { INTERNAL_HEADERS, NEXTJS_DEPLOYMENT_ID_HEADER, VINEXT_INTERNAL_HEADERS, VINEXT_TIMING_HEADER } from "./server/headers.js";
|
|
8
9
|
import { normalizePath as normalizePath$1 } from "./server/normalize-path.js";
|
|
9
10
|
import { matchesRewriteSource, proxyExternalRequest } from "./config/config-matchers.js";
|
|
10
11
|
import { isOpenRedirectShaped } from "./server/open-redirect.js";
|
|
11
12
|
import { filterInternalHeaders, normalizeTrailingSlash } from "./server/request-pipeline.js";
|
|
12
13
|
import { findMiddlewareFile, isProxyFile, runMiddleware } from "./server/middleware.js";
|
|
13
14
|
import { generateServerEntry } from "./entries/pages-server-entry.js";
|
|
15
|
+
import { extractMiddlewareMatcherConfig } from "./build/report.js";
|
|
14
16
|
import { generateClientEntry } from "./entries/pages-client-entry.js";
|
|
15
17
|
import { appRouteGraph, appRouter, invalidateAppRouteCache, matchAppRoute } from "./routing/app-router.js";
|
|
16
18
|
import { findInstrumentationClientFile, findInstrumentationFile, runInstrumentation } from "./server/instrumentation.js";
|
|
17
19
|
import { isUnknownRecord } from "./utils/record.js";
|
|
18
20
|
import { logRequest, now } from "./server/request-log.js";
|
|
21
|
+
import { resolvePagesI18nRequest } from "./server/pages-i18n.js";
|
|
22
|
+
import { isNextDataPathname, parseNextDataPathname } from "./server/pages-data-route.js";
|
|
19
23
|
import { createSSRHandler } from "./server/dev-server.js";
|
|
20
24
|
import { handleApiRoute } from "./server/api-handler.js";
|
|
21
25
|
import { DEFAULT_DEVICE_SIZES, DEFAULT_IMAGE_SIZES, isImageOptimizationPath, resolveDevImageRedirect } from "./server/image-optimization.js";
|
|
22
26
|
import { installSocketErrorBackstop } from "./server/socket-error-backstop.js";
|
|
23
|
-
import { scanMetadataFiles } from "./server/metadata-routes.js";
|
|
27
|
+
import { invalidateMetadataFileCache, scanMetadataFiles } from "./server/metadata-routes.js";
|
|
24
28
|
import { shouldInvalidateAppRouteFile } from "./server/dev-route-files.js";
|
|
25
29
|
import { createDirectRunner } from "./server/dev-module-runner.js";
|
|
26
30
|
import { validateDevRequest } from "./server/dev-origin-check.js";
|
|
27
31
|
import { generateRscEntry } from "./entries/app-rsc-entry.js";
|
|
28
32
|
import { generateSsrEntry } from "./entries/app-ssr-entry.js";
|
|
29
33
|
import { VIRTUAL_CACHE_ADAPTERS, generateCacheAdaptersModule } from "./cache/cache-adapters-virtual.js";
|
|
34
|
+
import { VIRTUAL_IMAGE_ADAPTERS, generateImageAdaptersModule } from "./image/image-adapters-virtual.js";
|
|
30
35
|
import { generateBrowserEntry, isLinkPrefetchRoute, toDocumentOnlyAppRoute, toLinkPrefetchRoute } from "./entries/app-browser-entry.js";
|
|
31
36
|
import { collectRouteClassificationManifest } from "./build/route-classification-manifest.js";
|
|
32
37
|
import { planRouteClassificationInjection } from "./build/route-classification-injector.js";
|
|
@@ -36,7 +41,6 @@ import { RESOLVED_VIRTUAL_GOOGLE_FONTS, VIRTUAL_GOOGLE_FONTS, createGoogleFontsP
|
|
|
36
41
|
import { getDepOptimizeNodeEnvOptions, getViteMajorVersion, serializeViteDefine } from "./utils/vite-version.js";
|
|
37
42
|
import { createRscCompatibilityId, findNextConfigPath, loadNextConfig, resolveNextConfig, resolveNextConfigInput } from "./config/next-config.js";
|
|
38
43
|
import { mergeServerExternalPackages } from "./config/server-external-packages.js";
|
|
39
|
-
import { isNextDataPathname, parseNextDataPathname } from "./server/pages-data-route.js";
|
|
40
44
|
import { precompressAssets } from "./build/precompress.js";
|
|
41
45
|
import { ensureAssetsIgnore } from "./build/assets-ignore.js";
|
|
42
46
|
import { emitNextClientRuntimeManifests } from "./build/next-client-runtime-manifests.js";
|
|
@@ -49,6 +53,7 @@ import { renderVinextBuiltUrl } from "./utils/built-asset-url.js";
|
|
|
49
53
|
import { asyncHooksStubPlugin } from "./plugins/async-hooks-stub.js";
|
|
50
54
|
import { clientReferenceDedupPlugin } from "./plugins/client-reference-dedup.js";
|
|
51
55
|
import { dataUrlCssPlugin } from "./plugins/css-data-url.js";
|
|
56
|
+
import { createCssModuleImportCompatibilityPlugin } from "./plugins/css-module-imports.js";
|
|
52
57
|
import { createRscClientReferenceLoadersPlugin } from "./plugins/rsc-client-reference-loaders.js";
|
|
53
58
|
import { createInstrumentationClientTransformPlugin } from "./plugins/instrumentation-client.js";
|
|
54
59
|
import { INSTRUMENTATION_CLIENT_EMPTY_MODULE, generateInstrumentationClientInjectModule } from "./client/instrumentation-client-inject.js";
|
|
@@ -62,8 +67,8 @@ import { generateRouteTypes } from "./typegen.js";
|
|
|
62
67
|
import { SSR_EXTERNAL_REACT_ENTRIES, VINEXT_OPTIMIZE_DEPS_EXCLUDE, mergeOptimizeDepsExclude } from "./plugins/rsc-client-shim-excludes.js";
|
|
63
68
|
import { createServerExternalsManifestPlugin } from "./plugins/server-externals-manifest.js";
|
|
64
69
|
import { VINEXT_CLIENT_ENTRY_MANIFEST } from "./utils/client-entry-manifest.js";
|
|
65
|
-
import {
|
|
66
|
-
import {
|
|
70
|
+
import { computeClientRuntimeMetadata } from "./utils/client-runtime-metadata.js";
|
|
71
|
+
import { PAGES_CLIENT_ASSETS_MODULE, buildPagesClientAssetsModule, setPagesClientAssetsBuildMetadata, takePagesClientAssetsBuildMetadata, writePagesClientAssetsModuleIfMissing } from "./build/pages-client-assets-module.js";
|
|
67
72
|
import { resolvePostcssStringPlugins } from "./plugins/postcss.js";
|
|
68
73
|
import { buildSassPreprocessorOptions, createSassAwareFileSystemLoader, createSassTildeImporter } from "./plugins/sass.js";
|
|
69
74
|
import { createClientAssetFileNames, createClientCodeSplittingConfig, createClientFileNameConfig, createClientManualChunks, createClientOutputConfig, createRscFrameworkChunkOutputConfig, getBuildBundlerOptions, getClientTreeshakeConfigForVite, withBuildBundlerOptions } from "./build/client-build-config.js";
|
|
@@ -77,6 +82,8 @@ import { createWasmModuleImportPlugin } from "./plugins/wasm-module-import.js";
|
|
|
77
82
|
import { getTypeofWindowReplacement, replaceTypeofWindow } from "./plugins/typeof-window.js";
|
|
78
83
|
import { hasMdxFiles } from "./utils/mdx-scan.js";
|
|
79
84
|
import { scanPublicFileRoutes } from "./utils/public-routes.js";
|
|
85
|
+
import { createIgnoreDynamicRequestsPlugin } from "./plugins/ignore-dynamic-requests.js";
|
|
86
|
+
import { VINEXT_PRERENDER_CONFIG_PLUGIN_PROPERTY, normalizeVinextPrerenderConfig } from "./config/prerender.js";
|
|
80
87
|
import { staticExportApp, staticExportPages } from "./build/static-export.js";
|
|
81
88
|
import { createRequire } from "node:module";
|
|
82
89
|
import fs from "node:fs";
|
|
@@ -235,6 +242,20 @@ function toViteAliasReplacement(absolutePath, projectRoot) {
|
|
|
235
242
|
}
|
|
236
243
|
return normalizedPath;
|
|
237
244
|
}
|
|
245
|
+
function resolveSwcHelpersAlias(root) {
|
|
246
|
+
const rootRequire = createRequire(path.join(root, "package.json"));
|
|
247
|
+
const resolvers = [];
|
|
248
|
+
try {
|
|
249
|
+
const nextPackageJson = rootRequire.resolve("next/package.json");
|
|
250
|
+
const realNextPackageJson = tryRealpathSync(nextPackageJson) ?? nextPackageJson;
|
|
251
|
+
resolvers.push(createRequire(realNextPackageJson));
|
|
252
|
+
} catch {}
|
|
253
|
+
resolvers.push(rootRequire, createRequire(import.meta.url));
|
|
254
|
+
for (const resolver of resolvers) try {
|
|
255
|
+
const packageJsonPath = resolver.resolve("@swc/helpers/package.json");
|
|
256
|
+
return normalizePathSeparators(path.join(path.dirname(packageJsonPath), "_"));
|
|
257
|
+
} catch {}
|
|
258
|
+
}
|
|
238
259
|
function loadTsconfigPathAliases(configPath, projectRoot, seen = /* @__PURE__ */ new Set()) {
|
|
239
260
|
const normalizedPath = tryRealpathSync(configPath) ?? configPath;
|
|
240
261
|
if (seen.has(normalizedPath)) return {};
|
|
@@ -298,10 +319,14 @@ function resolveTsconfigAliases(projectRoot) {
|
|
|
298
319
|
_tsconfigAliasCache.set(projectRoot, aliases);
|
|
299
320
|
return aliases;
|
|
300
321
|
}
|
|
322
|
+
const VIRTUAL_WORKER_ENTRY = "virtual:vinext-worker-entry";
|
|
323
|
+
const RESOLVED_WORKER_ENTRY = "\0virtual:vinext-worker-entry";
|
|
301
324
|
const VIRTUAL_SERVER_ENTRY = "virtual:vinext-server-entry";
|
|
302
325
|
const RESOLVED_SERVER_ENTRY = "\0virtual:vinext-server-entry";
|
|
303
326
|
const VIRTUAL_CLIENT_ENTRY = "virtual:vinext-client-entry";
|
|
304
327
|
const RESOLVED_CLIENT_ENTRY = "\0virtual:vinext-client-entry";
|
|
328
|
+
const VIRTUAL_PAGES_CLIENT_ASSETS = "virtual:vinext-pages-client-assets";
|
|
329
|
+
const RESOLVED_PAGES_CLIENT_ASSETS = "\0virtual:vinext-pages-client-assets";
|
|
305
330
|
const VIRTUAL_RSC_ENTRY = "virtual:vinext-rsc-entry";
|
|
306
331
|
const RESOLVED_RSC_ENTRY = "\0virtual:vinext-rsc-entry";
|
|
307
332
|
const VIRTUAL_APP_SSR_ENTRY = "virtual:vinext-app-ssr-entry";
|
|
@@ -313,6 +338,8 @@ const RESOLVED_APP_CAPABILITIES = "\0virtual:vinext-app-capabilities";
|
|
|
313
338
|
const RESOLVED_ROOT_PARAMS = "\0virtual:vinext-root-params";
|
|
314
339
|
/** Virtual module that registers config-driven cache adapters (see VinextOptions.cache). */
|
|
315
340
|
const RESOLVED_CACHE_ADAPTERS = "\0" + VIRTUAL_CACHE_ADAPTERS;
|
|
341
|
+
/** Virtual module that registers the config-driven image optimizer (see VinextOptions.images). */
|
|
342
|
+
const RESOLVED_IMAGE_ADAPTERS = "\0" + VIRTUAL_IMAGE_ADAPTERS;
|
|
316
343
|
/** Virtual module for composed instrumentation-client bootstrap. */
|
|
317
344
|
const VIRTUAL_INSTRUMENTATION_CLIENT = "private-next-instrumentation-client";
|
|
318
345
|
const RESOLVED_INSTRUMENTATION_CLIENT = `${VIRTUAL_INSTRUMENTATION_CLIENT}.mjs`;
|
|
@@ -338,9 +365,11 @@ function createStaticImageAsset(imagePath) {
|
|
|
338
365
|
* the `id.startsWith(_shimsDir)` checks would never match.
|
|
339
366
|
*/
|
|
340
367
|
const _shimsDir = normalizePathSeparators(path.resolve(__dirname, "shims")) + "/";
|
|
368
|
+
const _serverDir = normalizePathSeparators(path.resolve(__dirname, "server"));
|
|
341
369
|
const _fontGoogleShimPath = resolveShimModulePath(_shimsDir, "font-google");
|
|
342
|
-
const _appBrowserServerActionClientPath = resolveShimModulePath(
|
|
343
|
-
const _appRscHandlerPath = resolveShimModulePath(
|
|
370
|
+
const _appBrowserServerActionClientPath = resolveShimModulePath(_serverDir, "app-browser-server-action-client");
|
|
371
|
+
const _appRscHandlerPath = resolveShimModulePath(_serverDir, "app-rsc-handler");
|
|
372
|
+
const _pagesClientAssetsPath = resolveShimModulePath(_serverDir, "pages-client-assets");
|
|
344
373
|
const _canExternalizeAppRscHandler = _appRscHandlerPath.endsWith(".js");
|
|
345
374
|
function isValidExportIdentifier(name) {
|
|
346
375
|
return /^[$A-Z_a-z][$\w]*$/.test(name);
|
|
@@ -440,6 +469,7 @@ function getClientOutputConfigForVite(viteMajorVersion, assetsDir, preserveAppRo
|
|
|
440
469
|
} : createClientOutputConfig(manualChunks, assetsDir);
|
|
441
470
|
}
|
|
442
471
|
function vinext(options = {}) {
|
|
472
|
+
const prerenderConfig = normalizeVinextPrerenderConfig(options.prerender);
|
|
443
473
|
const viteMajorVersion = getViteMajorVersion();
|
|
444
474
|
let root;
|
|
445
475
|
let pagesDir;
|
|
@@ -457,6 +487,8 @@ function vinext(options = {}) {
|
|
|
457
487
|
let hasCloudflarePlugin = false;
|
|
458
488
|
let warnedInlineNextConfigOverride = false;
|
|
459
489
|
let hasNitroPlugin = false;
|
|
490
|
+
const pagesClientAssetsOutputDirs = /* @__PURE__ */ new Set();
|
|
491
|
+
let pagesClientAssetsModule = null;
|
|
460
492
|
let rscCompatibilityId;
|
|
461
493
|
const draftModeSecret = randomUUID();
|
|
462
494
|
const sassComposesLoader = createSassAwareFileSystemLoader();
|
|
@@ -502,7 +534,9 @@ function vinext(options = {}) {
|
|
|
502
534
|
const appPrefetchRoutes = hasAppDir ? (await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher)).map((route) => isLinkPrefetchRoute(route) ? toLinkPrefetchRoute(route) : toDocumentOnlyAppRoute(route)) : [];
|
|
503
535
|
return generateClientEntry(pagesDir, nextConfig, fileMatcher, {
|
|
504
536
|
appPrefetchRoutes,
|
|
505
|
-
instrumentationClientPath
|
|
537
|
+
instrumentationClientPath,
|
|
538
|
+
middlewareMatcher: middlewarePath ? extractMiddlewareMatcherConfig(middlewarePath) : void 0,
|
|
539
|
+
reactPreamble: options.react !== false
|
|
506
540
|
});
|
|
507
541
|
}
|
|
508
542
|
async function writeRouteTypes() {
|
|
@@ -593,6 +627,7 @@ function vinext(options = {}) {
|
|
|
593
627
|
const plugins = [
|
|
594
628
|
...viteMajorVersion >= 8 ? [] : [loadVite7TsconfigPathsPlugin(earlyBaseDir)],
|
|
595
629
|
reactPluginPromise,
|
|
630
|
+
createIgnoreDynamicRequestsPlugin(() => nextConfig?.turbopackTranspilePackages ?? []),
|
|
596
631
|
commonjs(),
|
|
597
632
|
...viteMajorVersion >= 8 ? [{
|
|
598
633
|
name: "vinext:jsx-in-js",
|
|
@@ -628,14 +663,17 @@ function vinext(options = {}) {
|
|
|
628
663
|
serverOnlyShimPath: resolveShimModulePath(shimsDir, "server-only")
|
|
629
664
|
}),
|
|
630
665
|
dataUrlCssPlugin(),
|
|
666
|
+
createCssModuleImportCompatibilityPlugin(),
|
|
631
667
|
{
|
|
632
668
|
name: "vinext:config",
|
|
633
669
|
enforce: "pre",
|
|
670
|
+
[VINEXT_PRERENDER_CONFIG_PLUGIN_PROPERTY]: prerenderConfig,
|
|
634
671
|
async config(config, env) {
|
|
635
672
|
root = normalizePathSeparators(config.root ?? process.cwd());
|
|
636
673
|
const userResolve = config.resolve;
|
|
637
674
|
const shouldEnableNativeTsconfigPaths = viteMajorVersion >= 8 && userResolve?.tsconfigPaths === void 0;
|
|
638
675
|
const tsconfigPathAliases = resolveTsconfigAliases(root);
|
|
676
|
+
const swcHelpersAlias = resolveSwcHelpersAlias(root);
|
|
639
677
|
const mode = env?.mode ?? "development";
|
|
640
678
|
const dotenvVars = loadEnv(mode, config.envDir ?? root, "");
|
|
641
679
|
for (const [key, value] of Object.entries(dotenvVars)) if (process.env[key] === void 0) process.env[key] = value;
|
|
@@ -701,6 +739,7 @@ function vinext(options = {}) {
|
|
|
701
739
|
}
|
|
702
740
|
defines["process.env.__NEXT_ROUTER_BASEPATH"] = JSON.stringify(nextConfig.basePath);
|
|
703
741
|
defines["process.env.__VINEXT_HAS_PAGES_ROUTER"] = JSON.stringify(String(hasPagesDir));
|
|
742
|
+
defines["process.env.__NEXT_CLIENT_ROUTER_DYNAMIC_STALETIME"] = JSON.stringify(String(nextConfig.staleTimes.dynamic));
|
|
704
743
|
defines["process.env.__NEXT_CLIENT_ROUTER_STATIC_STALETIME"] = JSON.stringify(String(nextConfig.staleTimes.static));
|
|
705
744
|
defines["process.env.__VINEXT_PREFETCH_INLINING"] = JSON.stringify(nextConfig.prefetchInlining ? "true" : "false");
|
|
706
745
|
defines["process.env.__NEXT_GESTURE_TRANSITION"] = JSON.stringify(nextConfig.gestureTransition);
|
|
@@ -736,6 +775,7 @@ function vinext(options = {}) {
|
|
|
736
775
|
}
|
|
737
776
|
defines["process.env.__VINEXT_IMAGE_DANGEROUSLY_ALLOW_SVG"] = JSON.stringify(String(nextConfig.images?.dangerouslyAllowSVG ?? false));
|
|
738
777
|
defines["process.env.__VINEXT_IMAGE_DANGEROUSLY_ALLOW_LOCAL_IP"] = JSON.stringify(String(nextConfig.images?.dangerouslyAllowLocalIP ?? false));
|
|
778
|
+
defines["process.env.__VINEXT_IMAGE_UNOPTIMIZED"] = JSON.stringify(String(nextConfig.images?.unoptimized === true));
|
|
739
779
|
defines["process.env.__VINEXT_BUILD_ID"] = JSON.stringify(nextConfig.buildId);
|
|
740
780
|
defines["process.env.__VINEXT_RSC_COMPATIBILITY_ID"] = JSON.stringify(rscCompatibilityId);
|
|
741
781
|
defines["process.env.__VINEXT_DEPLOYMENT_ID"] = JSON.stringify(nextConfig.deploymentId ?? "");
|
|
@@ -802,7 +842,7 @@ function vinext(options = {}) {
|
|
|
802
842
|
"vinext/cache": path.resolve(__dirname, "cache"),
|
|
803
843
|
"vinext/instrumentation": path.resolve(__dirname, "server", "instrumentation"),
|
|
804
844
|
"vinext/instrumentation-client": path.resolve(__dirname, "client", "instrumentation-client"),
|
|
805
|
-
"vinext/dev-error-overlay": path.resolve(__dirname, "
|
|
845
|
+
"vinext/dev-error-overlay": path.resolve(__dirname, "client", "dev-error-overlay"),
|
|
806
846
|
"vinext/html": path.resolve(__dirname, "server", "html"),
|
|
807
847
|
...clientInjectModule === null ? { "private-next-instrumentation-client": instrumentationClientPath ?? INSTRUMENTATION_CLIENT_EMPTY_MODULE } : {}
|
|
808
848
|
}).flatMap(([k, v]) => k.startsWith("next/") ? [[k, v], [`${k}.js`, v]] : [[k, v]]));
|
|
@@ -820,7 +860,8 @@ function vinext(options = {}) {
|
|
|
820
860
|
hasUserMdxPlugin = pluginsFlat.some((p) => p && typeof p === "object" && "name" in p && typeof p.name === "string" && (p.name === "@mdx-js/rollup" || p.name === "mdx"));
|
|
821
861
|
if (!hasUserMdxPlugin && hasMdxFiles(root, hasAppDir ? appDir : null, hasPagesDir ? pagesDir : null)) await ensureMdxDelegate("detected");
|
|
822
862
|
const isSSR = !!config.build?.ssr;
|
|
823
|
-
const
|
|
863
|
+
const serverTranspilePackages = [...nextConfig?.turbopackTranspilePackages ?? [], ...nextConfig?.optimizePackageImports ?? []];
|
|
864
|
+
const nextServerExternal = mergeServerExternalPackages(nextConfig?.serverExternalPackages, serverTranspilePackages);
|
|
824
865
|
const isMultiEnv = hasAppDir || hasCloudflarePlugin || hasNitroPlugin;
|
|
825
866
|
const hasBuildInput = getBuildBundlerOptions(config.build)?.input !== void 0;
|
|
826
867
|
const shouldInjectPlainPagesEnvironments = !hasAppDir && !hasCloudflarePlugin && !isSSR && !hasBuildInput;
|
|
@@ -879,9 +920,11 @@ function vinext(options = {}) {
|
|
|
879
920
|
} },
|
|
880
921
|
resolve: {
|
|
881
922
|
alias: {
|
|
923
|
+
...swcHelpersAlias ? { "@swc/helpers/_": swcHelpersAlias } : {},
|
|
882
924
|
...tsconfigPathAliases,
|
|
883
925
|
...nextConfig.aliases,
|
|
884
|
-
...nextShimMap
|
|
926
|
+
...nextShimMap,
|
|
927
|
+
"vinext/server/pages-client-assets": _pagesClientAssetsPath
|
|
885
928
|
},
|
|
886
929
|
dedupe: [
|
|
887
930
|
"react",
|
|
@@ -1135,6 +1178,8 @@ function vinext(options = {}) {
|
|
|
1135
1178
|
}
|
|
1136
1179
|
if (isVercelOgImport(cleanId) && !isVinextOgShimImporter(importer)) return resolveShimModulePath(_shimsDir, "og");
|
|
1137
1180
|
if (cleanId.startsWith("vinext/shims/")) return resolveShimModulePath(_shimsDir, stripJsExtension(stripViteModuleQuery(cleanId.slice(13))));
|
|
1181
|
+
if (cleanId === VIRTUAL_WORKER_ENTRY) return RESOLVED_WORKER_ENTRY;
|
|
1182
|
+
if (cleanId.endsWith("/virtual:vinext-worker-entry")) return RESOLVED_WORKER_ENTRY;
|
|
1138
1183
|
if (cleanId === VIRTUAL_SERVER_ENTRY) return RESOLVED_SERVER_ENTRY;
|
|
1139
1184
|
if (cleanId === VIRTUAL_CLIENT_ENTRY) return RESOLVED_CLIENT_ENTRY;
|
|
1140
1185
|
if (cleanId.endsWith("/virtual:vinext-server-entry")) return RESOLVED_SERVER_ENTRY;
|
|
@@ -1145,6 +1190,7 @@ function vinext(options = {}) {
|
|
|
1145
1190
|
if (cleanId === VIRTUAL_APP_CAPABILITIES) return RESOLVED_APP_CAPABILITIES;
|
|
1146
1191
|
if (cleanId === "next/root-params" || cleanId === "next/root-params.js") return RESOLVED_ROOT_PARAMS;
|
|
1147
1192
|
if (cleanId === "virtual:vinext-cache-adapters" || cleanId.endsWith("/virtual:vinext-cache-adapters")) return RESOLVED_CACHE_ADAPTERS;
|
|
1193
|
+
if (cleanId === "virtual:vinext-image-adapters" || cleanId.endsWith("/virtual:vinext-image-adapters")) return RESOLVED_IMAGE_ADAPTERS;
|
|
1148
1194
|
if (cleanId.startsWith("virtual:vinext-google-fonts?")) return RESOLVED_VIRTUAL_GOOGLE_FONTS + cleanId.slice(VIRTUAL_GOOGLE_FONTS.length);
|
|
1149
1195
|
if (cleanId.endsWith("/virtual:vinext-rsc-entry")) return RESOLVED_RSC_ENTRY;
|
|
1150
1196
|
if (cleanId.endsWith("/virtual:vinext-app-ssr-entry")) return RESOLVED_APP_SSR_ENTRY;
|
|
@@ -1158,14 +1204,16 @@ function vinext(options = {}) {
|
|
|
1158
1204
|
}
|
|
1159
1205
|
},
|
|
1160
1206
|
async load(id) {
|
|
1207
|
+
if (id === RESOLVED_WORKER_ENTRY) return `export { default } from ${JSON.stringify(hasAppDir ? "vinext/server/app-router-entry" : "vinext/server/pages-router-entry")};`;
|
|
1161
1208
|
if (id === RESOLVED_SERVER_ENTRY) return await generateServerEntry$1();
|
|
1162
1209
|
if (id === RESOLVED_CLIENT_ENTRY) return await generateClientEntry$1();
|
|
1210
|
+
if (id === RESOLVED_PAGES_CLIENT_ASSETS) return "export default { clientEntry: '/@id/__x00__virtual:vinext-client-entry' };";
|
|
1163
1211
|
if (id === RESOLVED_RSC_ENTRY && hasAppDir) {
|
|
1164
1212
|
const routes = await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher);
|
|
1165
1213
|
const metaRoutes = scanMetadataFiles(appDir);
|
|
1166
1214
|
const hasServerActions = await resolveHasServerActions(this.environment.config);
|
|
1167
1215
|
const globalErrorPath = findFileWithExts(appDir, "global-error", fileMatcher);
|
|
1168
|
-
const globalNotFoundPath = findFileWithExts(appDir, "global-not-found", fileMatcher);
|
|
1216
|
+
const globalNotFoundPath = nextConfig?.globalNotFound ? findFileWithExts(appDir, "global-not-found", fileMatcher) : null;
|
|
1169
1217
|
rscClassificationManifest = collectRouteClassificationManifest(routes);
|
|
1170
1218
|
return generateRscEntry(appDir, routes, middlewarePath, metaRoutes, globalErrorPath, nextConfig?.basePath, nextConfig?.trailingSlash, {
|
|
1171
1219
|
redirects: nextConfig?.redirects,
|
|
@@ -1182,13 +1230,18 @@ function vinext(options = {}) {
|
|
|
1182
1230
|
reactMaxHeadersLength: nextConfig?.reactMaxHeadersLength,
|
|
1183
1231
|
cacheMaxMemorySize: nextConfig?.cacheMaxMemorySize,
|
|
1184
1232
|
inlineCss: nextConfig?.inlineCss,
|
|
1233
|
+
globalNotFound: nextConfig?.globalNotFound,
|
|
1185
1234
|
cacheComponents: nextConfig?.cacheComponents,
|
|
1186
1235
|
hasServerActions,
|
|
1187
1236
|
i18n: nextConfig?.i18n,
|
|
1188
1237
|
imageConfig: {
|
|
1189
1238
|
deviceSizes: nextConfig?.images?.deviceSizes,
|
|
1190
1239
|
imageSizes: nextConfig?.images?.imageSizes,
|
|
1191
|
-
qualities: nextConfig?.images?.qualities
|
|
1240
|
+
qualities: nextConfig?.images?.qualities,
|
|
1241
|
+
dangerouslyAllowSVG: nextConfig?.images?.dangerouslyAllowSVG,
|
|
1242
|
+
dangerouslyAllowLocalIP: nextConfig?.images?.dangerouslyAllowLocalIP,
|
|
1243
|
+
contentDispositionType: nextConfig?.images?.contentDispositionType,
|
|
1244
|
+
contentSecurityPolicy: nextConfig?.images?.contentSecurityPolicy
|
|
1192
1245
|
},
|
|
1193
1246
|
hasPagesDir,
|
|
1194
1247
|
publicFiles: scanPublicFileRoutes(root),
|
|
@@ -1198,6 +1251,7 @@ function vinext(options = {}) {
|
|
|
1198
1251
|
}
|
|
1199
1252
|
if (id === RESOLVED_ROOT_PARAMS) return generateRootParamsModule((hasAppDir ? await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher) : []).flatMap((route) => route.rootParamNames ?? []));
|
|
1200
1253
|
if (id === RESOLVED_CACHE_ADAPTERS) return generateCacheAdaptersModule(options.cache);
|
|
1254
|
+
if (id === RESOLVED_IMAGE_ADAPTERS) return generateImageAdaptersModule(options.images);
|
|
1201
1255
|
if (id === RESOLVED_APP_SSR_ENTRY && hasAppDir) return generateSsrEntry(hasPagesDir);
|
|
1202
1256
|
if (id === RESOLVED_APP_BROWSER_ENTRY && hasAppDir) {
|
|
1203
1257
|
const graph = await appRouteGraph(appDir, nextConfig?.pageExtensions, fileMatcher);
|
|
@@ -1257,6 +1311,28 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1257
1311
|
}
|
|
1258
1312
|
}
|
|
1259
1313
|
},
|
|
1314
|
+
{
|
|
1315
|
+
name: "vinext:pages-client-assets-resolver",
|
|
1316
|
+
sharedDuringBuild: true,
|
|
1317
|
+
resolveId: {
|
|
1318
|
+
filter: { id: /virtual:vinext-pages-client-assets$/ },
|
|
1319
|
+
handler(id) {
|
|
1320
|
+
const cleanId = normalizePathSeparators(id.startsWith("\0") ? id.slice(1) : id);
|
|
1321
|
+
if (cleanId !== VIRTUAL_PAGES_CLIENT_ASSETS && !cleanId.endsWith("/virtual:vinext-pages-client-assets")) return;
|
|
1322
|
+
if (this.environment?.config.command !== "build") return RESOLVED_PAGES_CLIENT_ASSETS;
|
|
1323
|
+
const buildRoot = this.environment.config.root ?? process.cwd();
|
|
1324
|
+
const environmentOutDir = path.resolve(buildRoot, this.environment.config.build.outDir);
|
|
1325
|
+
const sidecarDir = !hasAppDir && this.environment.name === "ssr" ? path.dirname(environmentOutDir) : environmentOutDir;
|
|
1326
|
+
let externalId = normalizePathSeparators(path.relative(environmentOutDir, path.join(sidecarDir, PAGES_CLIENT_ASSETS_MODULE)));
|
|
1327
|
+
if (!externalId.startsWith(".")) externalId = `./${externalId}`;
|
|
1328
|
+
pagesClientAssetsOutputDirs.add(sidecarDir);
|
|
1329
|
+
return {
|
|
1330
|
+
id: externalId,
|
|
1331
|
+
external: true
|
|
1332
|
+
};
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
},
|
|
1260
1336
|
{
|
|
1261
1337
|
name: "vinext:css-url-assets-mark",
|
|
1262
1338
|
enforce: "pre",
|
|
@@ -1277,11 +1353,14 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1277
1353
|
}
|
|
1278
1354
|
},
|
|
1279
1355
|
{
|
|
1280
|
-
name: "vinext:
|
|
1356
|
+
name: "vinext:css-url-assets-defaults",
|
|
1281
1357
|
apply: "build",
|
|
1282
|
-
configEnvironment(name) {
|
|
1283
|
-
if (name
|
|
1284
|
-
|
|
1358
|
+
configEnvironment(name, config) {
|
|
1359
|
+
if (name === "client") return { build: { assetsInlineLimit: clientAssetsInlineLimit } };
|
|
1360
|
+
if (!hasAppDir || name !== "rsc" && name !== "ssr") return null;
|
|
1361
|
+
const output = getBuildBundlerOptions(config.build)?.output;
|
|
1362
|
+
if (Array.isArray(output) || output?.assetFileNames !== void 0) return null;
|
|
1363
|
+
return { build: { ...withBuildBundlerOptions(viteMajorVersion, { output: { assetFileNames: createClientAssetFileNames(resolveAssetsDir(nextConfig.assetPrefix ?? "")) } }) } };
|
|
1285
1364
|
}
|
|
1286
1365
|
},
|
|
1287
1366
|
{
|
|
@@ -1364,6 +1443,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1364
1443
|
}
|
|
1365
1444
|
}
|
|
1366
1445
|
},
|
|
1446
|
+
createCssModuleImportCompatibilityPlugin({ compiledMdx: true }),
|
|
1367
1447
|
{
|
|
1368
1448
|
name: "vinext:react-canary",
|
|
1369
1449
|
enforce: "pre",
|
|
@@ -1453,6 +1533,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1453
1533
|
}
|
|
1454
1534
|
function invalidateAppRoutingModules() {
|
|
1455
1535
|
invalidateAppRouteCache();
|
|
1536
|
+
invalidateMetadataFileCache();
|
|
1456
1537
|
invalidateRscEntryModule();
|
|
1457
1538
|
invalidateRootParamsModule();
|
|
1458
1539
|
}
|
|
@@ -1823,11 +1904,15 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1823
1904
|
hadBasePath: true,
|
|
1824
1905
|
isDataReq,
|
|
1825
1906
|
isDataRequest,
|
|
1907
|
+
hasMiddleware: capturedMiddlewarePath !== null,
|
|
1826
1908
|
rawSearch: url.includes("?") ? url.slice(url.indexOf("?")) : "",
|
|
1827
1909
|
runMiddleware: devRunMiddlewareAdapter,
|
|
1828
|
-
matchPageRoute: (resolvedPathname) => {
|
|
1829
|
-
const m = matchRoute(resolvedPathname, devPageRoutes);
|
|
1830
|
-
return m ? { route: {
|
|
1910
|
+
matchPageRoute: (resolvedPathname, request) => {
|
|
1911
|
+
const m = matchRoute(nextConfig?.i18n ? resolvePagesI18nRequest(resolvedPathname, nextConfig.i18n, request.headers, new URL(request.url).hostname, bp, nextConfig.trailingSlash ?? false).url : resolvedPathname, devPageRoutes);
|
|
1912
|
+
return m ? { route: {
|
|
1913
|
+
isDynamic: m.route.isDynamic,
|
|
1914
|
+
pattern: m.route.pattern
|
|
1915
|
+
} } : null;
|
|
1831
1916
|
},
|
|
1832
1917
|
proxyExternal: async (currentRequest, externalUrl) => {
|
|
1833
1918
|
const externalMethod = req.method ?? "GET";
|
|
@@ -2014,7 +2099,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2014
2099
|
handler(code, id) {
|
|
2015
2100
|
const cacheDirPrefix = getCacheDirPrefix(this.environment.config.cacheDir);
|
|
2016
2101
|
if (normalizePathSeparators(id).startsWith(cacheDirPrefix)) return null;
|
|
2017
|
-
return replaceTypeofWindow(code, getTypeofWindowReplacement(this.environment));
|
|
2102
|
+
return replaceTypeofWindow(code, getTypeofWindowReplacement(this.environment), id);
|
|
2018
2103
|
}
|
|
2019
2104
|
}
|
|
2020
2105
|
},
|
|
@@ -2268,29 +2353,6 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2268
2353
|
createOgInlineFetchAssetsPlugin(),
|
|
2269
2354
|
createOgAssetsPlugin(),
|
|
2270
2355
|
createServerExternalsManifestPlugin(),
|
|
2271
|
-
{
|
|
2272
|
-
name: "vinext:image-config",
|
|
2273
|
-
apply: "build",
|
|
2274
|
-
enforce: "post",
|
|
2275
|
-
writeBundle: {
|
|
2276
|
-
sequential: true,
|
|
2277
|
-
order: "post",
|
|
2278
|
-
handler(options) {
|
|
2279
|
-
if (this.environment?.name !== "rsc") return;
|
|
2280
|
-
const outDir = options.dir;
|
|
2281
|
-
if (!outDir) return;
|
|
2282
|
-
const imageConfig = {
|
|
2283
|
-
deviceSizes: nextConfig?.images?.deviceSizes,
|
|
2284
|
-
imageSizes: nextConfig?.images?.imageSizes,
|
|
2285
|
-
qualities: nextConfig?.images?.qualities,
|
|
2286
|
-
dangerouslyAllowSVG: nextConfig?.images?.dangerouslyAllowSVG,
|
|
2287
|
-
contentDispositionType: nextConfig?.images?.contentDispositionType,
|
|
2288
|
-
contentSecurityPolicy: nextConfig?.images?.contentSecurityPolicy
|
|
2289
|
-
};
|
|
2290
|
-
fs.writeFileSync(path.join(outDir, "image-config.json"), JSON.stringify(imageConfig));
|
|
2291
|
-
}
|
|
2292
|
-
}
|
|
2293
|
-
},
|
|
2294
2356
|
(() => {
|
|
2295
2357
|
let buildIdWritten = false;
|
|
2296
2358
|
return {
|
|
@@ -2463,6 +2525,65 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2463
2525
|
}
|
|
2464
2526
|
};
|
|
2465
2527
|
})(),
|
|
2528
|
+
{
|
|
2529
|
+
name: "vinext:pages-client-assets",
|
|
2530
|
+
apply: "build",
|
|
2531
|
+
enforce: "post",
|
|
2532
|
+
sharedDuringBuild: true,
|
|
2533
|
+
closeBundle: {
|
|
2534
|
+
sequential: true,
|
|
2535
|
+
order: "post",
|
|
2536
|
+
handler() {
|
|
2537
|
+
const envConfig = this.environment.config;
|
|
2538
|
+
if (this.environment.name === "client") {
|
|
2539
|
+
const buildRoot = envConfig.root ?? process.cwd();
|
|
2540
|
+
const clientDir = path.resolve(buildRoot, envConfig.build.outDir);
|
|
2541
|
+
const runtimeMetadata = computeClientRuntimeMetadata({
|
|
2542
|
+
clientDir,
|
|
2543
|
+
assetBase: envConfig.base ?? "/",
|
|
2544
|
+
assetPrefix: nextConfig.assetPrefix,
|
|
2545
|
+
includeClientEntry: !hasAppDir ? true : hasPagesDir ? "pages-client-entry" : false
|
|
2546
|
+
});
|
|
2547
|
+
let ssrManifest;
|
|
2548
|
+
const ssrManifestPath = path.join(clientDir, ".vite", "ssr-manifest.json");
|
|
2549
|
+
if (fs.existsSync(ssrManifestPath)) try {
|
|
2550
|
+
ssrManifest = JSON.parse(fs.readFileSync(ssrManifestPath, "utf-8"));
|
|
2551
|
+
} catch {}
|
|
2552
|
+
pagesClientAssetsModule = buildPagesClientAssetsModule({
|
|
2553
|
+
clientEntry: runtimeMetadata.clientEntryFile ?? void 0,
|
|
2554
|
+
appBootstrapPreinitModules: runtimeMetadata.appBootstrapPreinitModules,
|
|
2555
|
+
ssrManifest,
|
|
2556
|
+
lazyChunks: runtimeMetadata.lazyChunks ?? void 0,
|
|
2557
|
+
dynamicPreloads: runtimeMetadata.dynamicPreloads ?? void 0
|
|
2558
|
+
});
|
|
2559
|
+
const buildSession = process.env.__VINEXT_PAGES_CLIENT_ASSETS_BUILD_SESSION;
|
|
2560
|
+
if (hasAppDir && hasPagesDir && buildSession) setPagesClientAssetsBuildMetadata(buildSession, pagesClientAssetsModule);
|
|
2561
|
+
}
|
|
2562
|
+
if (pagesClientAssetsModule === null) {
|
|
2563
|
+
if (pagesClientAssetsOutputDirs.size === 0) return;
|
|
2564
|
+
const buildSession = process.env.__VINEXT_PAGES_CLIENT_ASSETS_BUILD_SESSION;
|
|
2565
|
+
if (buildSession) pagesClientAssetsModule = takePagesClientAssetsBuildMetadata(buildSession);
|
|
2566
|
+
}
|
|
2567
|
+
if (pagesClientAssetsModule === null) {
|
|
2568
|
+
const emptyModule = buildPagesClientAssetsModule({});
|
|
2569
|
+
for (const outputDir of pagesClientAssetsOutputDirs) writePagesClientAssetsModuleIfMissing(outputDir, emptyModule);
|
|
2570
|
+
return;
|
|
2571
|
+
}
|
|
2572
|
+
for (const outputDir of pagesClientAssetsOutputDirs) {
|
|
2573
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
2574
|
+
fs.writeFileSync(path.join(outputDir, PAGES_CLIENT_ASSETS_MODULE), pagesClientAssetsModule);
|
|
2575
|
+
}
|
|
2576
|
+
}
|
|
2577
|
+
},
|
|
2578
|
+
buildApp() {
|
|
2579
|
+
if (pagesClientAssetsModule === null) return Promise.resolve();
|
|
2580
|
+
for (const outputDir of pagesClientAssetsOutputDirs) {
|
|
2581
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
2582
|
+
fs.writeFileSync(path.join(outputDir, PAGES_CLIENT_ASSETS_MODULE), pagesClientAssetsModule);
|
|
2583
|
+
}
|
|
2584
|
+
return Promise.resolve();
|
|
2585
|
+
}
|
|
2586
|
+
},
|
|
2466
2587
|
{
|
|
2467
2588
|
name: "vinext:inline-css-manifest",
|
|
2468
2589
|
apply: "build",
|
|
@@ -2496,61 +2617,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2496
2617
|
const envConfig = this.environment?.config;
|
|
2497
2618
|
if (!envConfig) return;
|
|
2498
2619
|
const buildRoot = envConfig.root ?? process.cwd();
|
|
2499
|
-
const
|
|
2500
|
-
if (!fs.existsSync(distDir)) return;
|
|
2501
|
-
const clientDir = path.resolve(buildRoot, "dist", "client");
|
|
2502
|
-
const runtimeMetadata = computeClientRuntimeMetadata({
|
|
2503
|
-
clientDir,
|
|
2504
|
-
assetBase: envConfig.base ?? "/",
|
|
2505
|
-
assetPrefix: nextConfig.assetPrefix,
|
|
2506
|
-
includeClientEntry: !hasAppDir ? true : hasPagesDir ? "pages-client-entry" : false
|
|
2507
|
-
});
|
|
2508
|
-
const lazyChunksData = runtimeMetadata.lazyChunks ?? null;
|
|
2509
|
-
const dynamicPreloadsData = runtimeMetadata.dynamicPreloads ?? null;
|
|
2510
|
-
let clientEntryFile = runtimeMetadata.clientEntryFile ?? null;
|
|
2511
|
-
let ssrManifestData = null;
|
|
2512
|
-
const ssrManifestPath = path.join(clientDir, ".vite", "ssr-manifest.json");
|
|
2513
|
-
if (fs.existsSync(ssrManifestPath)) try {
|
|
2514
|
-
ssrManifestData = JSON.parse(fs.readFileSync(ssrManifestPath, "utf-8"));
|
|
2515
|
-
} catch {}
|
|
2516
|
-
if (hasAppDir) {
|
|
2517
|
-
const workerEntry = path.resolve(distDir, "server", "index.js");
|
|
2518
|
-
if (fs.existsSync(workerEntry)) {
|
|
2519
|
-
const script = buildRuntimeGlobalsScript({
|
|
2520
|
-
clientEntryFile,
|
|
2521
|
-
ssrManifest: ssrManifestData,
|
|
2522
|
-
lazyChunks: lazyChunksData,
|
|
2523
|
-
dynamicPreloads: dynamicPreloadsData
|
|
2524
|
-
});
|
|
2525
|
-
if (script) {
|
|
2526
|
-
const code = fs.readFileSync(workerEntry, "utf-8");
|
|
2527
|
-
fs.writeFileSync(workerEntry, script + "\n" + code);
|
|
2528
|
-
}
|
|
2529
|
-
}
|
|
2530
|
-
} else {
|
|
2531
|
-
let workerOutDir = null;
|
|
2532
|
-
for (const entry of fs.readdirSync(distDir)) {
|
|
2533
|
-
const candidate = path.join(distDir, entry);
|
|
2534
|
-
if (entry === "client") continue;
|
|
2535
|
-
if (fs.statSync(candidate).isDirectory() && fs.existsSync(path.join(candidate, "wrangler.json"))) {
|
|
2536
|
-
workerOutDir = candidate;
|
|
2537
|
-
break;
|
|
2538
|
-
}
|
|
2539
|
-
}
|
|
2540
|
-
if (!workerOutDir) return;
|
|
2541
|
-
const workerEntry = path.join(workerOutDir, "index.js");
|
|
2542
|
-
if (!fs.existsSync(workerEntry)) return;
|
|
2543
|
-
const script = buildRuntimeGlobalsScript({
|
|
2544
|
-
clientEntryFile,
|
|
2545
|
-
ssrManifest: ssrManifestData,
|
|
2546
|
-
lazyChunks: lazyChunksData,
|
|
2547
|
-
dynamicPreloads: dynamicPreloadsData
|
|
2548
|
-
});
|
|
2549
|
-
if (script) {
|
|
2550
|
-
const code = fs.readFileSync(workerEntry, "utf-8");
|
|
2551
|
-
fs.writeFileSync(workerEntry, script + "\n" + code);
|
|
2552
|
-
}
|
|
2553
|
-
}
|
|
2620
|
+
const clientDir = path.resolve(buildRoot, envConfig.build.outDir);
|
|
2554
2621
|
const headersPath = path.join(clientDir, "_headers");
|
|
2555
2622
|
if (!fs.existsSync(headersPath)) {
|
|
2556
2623
|
const headersContent = [
|