vinext 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/THIRD_PARTY_LICENSES.md +26 -0
- package/dist/build/lifecycle.js +10 -10
- package/dist/build/pages-client-assets-module.js +6 -1
- package/dist/build/precompress.js +1 -1
- package/dist/build/prerender-paths.js +3 -7
- package/dist/build/prerender.d.ts +8 -1
- package/dist/build/prerender.js +134 -38
- package/dist/build/run-prerender.js +4 -3
- package/dist/build/server-entry.d.ts +2 -0
- package/dist/build/server-entry.js +7 -1
- package/dist/client/browser-globals.d.ts +4 -0
- package/dist/client/browser-globals.js +5 -0
- package/dist/client/navigation-runtime.d.ts +0 -1
- package/dist/client/navigation-runtime.js +2 -2
- package/dist/config/dotenv.js +14 -3
- package/dist/entries/app-rsc-entry.js +3 -2
- package/dist/index.js +142 -71
- package/dist/init-cloudflare.d.ts +1 -1
- package/dist/init-cloudflare.js +6 -6
- package/dist/init-platform.js +1 -1
- package/dist/init.js +4 -2
- package/dist/plugins/commonjs-syntax.d.ts +16 -0
- package/dist/plugins/commonjs-syntax.js +22 -0
- package/dist/plugins/ignore-dynamic-requests.d.ts +11 -0
- package/dist/plugins/ignore-dynamic-requests.js +54 -3
- package/dist/plugins/import-meta-url.js +6 -6
- package/dist/plugins/og-asset-ownership.d.ts +2 -0
- package/dist/plugins/og-asset-ownership.js +24 -13
- package/dist/plugins/og-assets.d.ts +18 -0
- package/dist/plugins/og-assets.js +50 -8
- package/dist/plugins/og-harfbuzz.js +38 -27
- package/dist/plugins/optimize-imports.js +2 -1
- package/dist/plugins/require-context.d.ts +1 -0
- package/dist/plugins/require-context.js +28 -1
- package/dist/plugins/scan-build-css.d.ts +12 -0
- package/dist/plugins/scan-build-css.js +39 -0
- package/dist/plugins/strip-server-exports.d.ts +2 -0
- package/dist/plugins/strip-server-exports.js +3 -1
- package/dist/plugins/transform-result.d.ts +18 -0
- package/dist/plugins/transform-result.js +23 -2
- package/dist/plugins/typeof-window.d.ts +10 -0
- package/dist/plugins/typeof-window.js +33 -9
- package/dist/routing/app-route-graph.d.ts +0 -1
- package/dist/routing/app-route-graph.js +2 -4
- package/dist/routing/app-route-ids.d.ts +3 -0
- package/dist/routing/app-route-ids.js +6 -0
- package/dist/server/app-bfcache-id.d.ts +1 -0
- package/dist/server/app-bfcache-id.js +7 -1
- package/dist/server/app-bfcache-identity.js +1 -2
- package/dist/server/app-browser-entry.js +4 -2
- package/dist/server/app-browser-hydration.d.ts +1 -1
- package/dist/server/app-browser-hydration.js +2 -2
- package/dist/server/app-browser-navigation-controller.js +1 -1
- package/dist/server/app-browser-state.js +1 -1
- package/dist/server/app-browser-stream.d.ts +1 -1
- package/dist/server/app-history-state.d.ts +0 -1
- package/dist/server/app-history-state.js +2 -5
- package/dist/server/app-page-cache-render.js +2 -1
- package/dist/server/app-page-render.js +2 -1
- package/dist/server/app-page-search-params-observation.js +1 -1
- package/dist/server/app-page-stream.js +1 -1
- package/dist/server/app-page-tracing.js +2 -1
- package/dist/server/app-pages-bridge.js +3 -2
- package/dist/server/app-render-abort-error.d.ts +3 -0
- package/dist/server/app-render-abort-error.js +8 -0
- package/dist/server/app-request-stage-independent-entry.js +4 -7
- package/dist/server/app-route-handler-cache.d.ts +2 -1
- package/dist/server/app-route-handler-cache.js +11 -7
- package/dist/server/app-route-handler-dispatch.js +10 -3
- package/dist/server/app-route-handler-execution.d.ts +9 -1
- package/dist/server/app-route-handler-execution.js +28 -13
- package/dist/server/app-route-handler-policy.js +2 -2
- package/dist/server/app-route-handler-response.d.ts +1 -1
- package/dist/server/app-route-handler-response.js +14 -5
- package/dist/server/app-router-entry.d.ts +2 -1
- package/dist/server/app-router-entry.js +5 -9
- package/dist/server/app-rsc-errors.d.ts +0 -1
- package/dist/server/app-rsc-errors.js +2 -6
- package/dist/server/app-rsc-handler.d.ts +1 -0
- package/dist/server/app-rsc-handler.js +18 -7
- package/dist/server/app-rsc-request-normalization.d.ts +1 -1
- package/dist/server/app-rsc-request-normalization.js +3 -2
- package/dist/server/app-rsc-response-finalizer.js +4 -1
- package/dist/server/app-rsc-route-matching.js +1 -1
- package/dist/server/app-server-action-execution.d.ts +2 -1
- package/dist/server/app-ssr-entry.js +3 -3
- package/dist/server/app-ssr-search-params-gate.js +1 -1
- package/dist/server/app-ssr-stream.js +1 -1
- package/dist/server/cache-control.js +3 -11
- package/dist/server/cacheability-request.js +49 -49
- package/dist/server/config-headers.js +1 -1
- package/dist/server/dev-server.js +11 -3
- package/dist/server/headers.d.ts +2 -0
- package/dist/server/headers.js +5 -1
- package/dist/server/http-error-responses.js +1 -0
- package/dist/server/isr-cache.d.ts +2 -0
- package/dist/server/isr-cache.js +6 -1
- package/dist/server/metadata-route-response.js +94 -37
- package/dist/server/pages-api-route.js +8 -2
- package/dist/server/pages-asset-tags.d.ts +1 -0
- package/dist/server/pages-asset-tags.js +73 -22
- package/dist/server/pages-client-assets.d.ts +2 -0
- package/dist/server/pages-page-data.d.ts +6 -1
- package/dist/server/pages-page-data.js +71 -65
- package/dist/server/pages-page-handler.js +29 -11
- package/dist/server/pages-page-response.js +3 -1
- package/dist/server/pages-request-pipeline.d.ts +2 -1
- package/dist/server/pages-request-pipeline.js +20 -5
- package/dist/server/pages-request-stage-entry.js +6 -4
- package/dist/server/prerender-manifest.d.ts +6 -0
- package/dist/server/prerender-manifest.js +1 -1
- package/dist/server/prod-server.js +3 -13
- package/dist/server/response-stage-cacheability.js +1 -1
- package/dist/server/worker-revalidation-context.d.ts +2 -1
- package/dist/server/worker-revalidation-context.js +1 -0
- package/dist/server/workers-tracing.d.ts +17 -0
- package/dist/server/workers-tracing.js +48 -8
- package/dist/shims/cache-request-state.d.ts +3 -14
- package/dist/shims/cache-request-state.js +2 -13
- package/dist/shims/cache-runtime.js +4 -2
- package/dist/shims/cache.d.ts +2 -1
- package/dist/shims/cache.js +4 -2
- package/dist/shims/cacheability-classification.d.ts +1 -1
- package/dist/shims/cacheability-classification.js +2 -2
- package/dist/shims/cdn-cache.d.ts +10 -1
- package/dist/shims/cdn-cache.js +16 -9
- package/dist/shims/error.d.ts +4 -18
- package/dist/shims/error.js +17 -10
- package/dist/shims/error.react-server.d.ts +4 -6
- package/dist/shims/error.react-server.js +4 -1
- package/dist/shims/fetch-cache.js +4 -3
- package/dist/shims/headers.d.ts +6 -69
- package/dist/shims/headers.js +37 -181
- package/dist/shims/internal/cache-context-accessor.d.ts +16 -0
- package/dist/shims/internal/cache-context-accessor.js +15 -0
- package/dist/shims/internal/headers-state.d.ts +74 -0
- package/dist/shims/internal/headers-state.js +157 -0
- package/dist/shims/navigation.js +2 -2
- package/dist/shims/request-state-types.d.ts +2 -1
- package/dist/shims/root-params.js +1 -1
- package/dist/shims/server.js +52 -2
- package/dist/shims/unified-request-context.d.ts +1 -1
- package/dist/utils/encode-cache-tag.d.ts +1 -0
- package/dist/utils/encode-cache-tag.js +11 -1
- package/dist/utils/vite-cli-invocation.js +8 -1
- package/package.json +6 -2
- package/dist/server/metadata-route-cache-policy.d.ts +0 -5
- package/dist/server/metadata-route-cache-policy.js +0 -6
package/THIRD_PARTY_LICENSES.md
CHANGED
|
@@ -23,3 +23,29 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
23
23
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
24
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
25
|
SOFTWARE.
|
|
26
|
+
|
|
27
|
+
## dotenv (parser adapted from version 16.3.1)
|
|
28
|
+
|
|
29
|
+
Copyright (c) 2015, Scott Motte
|
|
30
|
+
All rights reserved.
|
|
31
|
+
|
|
32
|
+
Redistribution and use in source and binary forms, with or without
|
|
33
|
+
modification, are permitted provided that the following conditions are met:
|
|
34
|
+
|
|
35
|
+
- Redistributions of source code must retain the above copyright notice, this
|
|
36
|
+
list of conditions and the following disclaimer.
|
|
37
|
+
|
|
38
|
+
- Redistributions in binary form must reproduce the above copyright notice,
|
|
39
|
+
this list of conditions and the following disclaimer in the documentation
|
|
40
|
+
and/or other materials provided with the distribution.
|
|
41
|
+
|
|
42
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
43
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
44
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
45
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
46
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
47
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
48
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
49
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
50
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
51
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/dist/build/lifecycle.js
CHANGED
|
@@ -141,16 +141,6 @@ async function finalizeBuild(builder, context) {
|
|
|
141
141
|
__VINEXT_SHARED_RSC_COMPATIBILITY_ID: context.rscCompatibilityId
|
|
142
142
|
}, () => runWithPreviewBuildCredentials(() => buildHybridPagesBundle(builder, context), context.previewBuildCredentials));
|
|
143
143
|
if (context.deferPostBuild) return;
|
|
144
|
-
if (context.nextConfig.output === "standalone") {
|
|
145
|
-
const { emitStandaloneOutput } = await import("./standalone.js");
|
|
146
|
-
const standalone = emitStandaloneOutput({
|
|
147
|
-
root: context.root,
|
|
148
|
-
outDir: path.resolve(context.root, "dist")
|
|
149
|
-
});
|
|
150
|
-
console.log(` Generated standalone output in ${path.relative(context.root, standalone.standaloneDir)}/`);
|
|
151
|
-
console.log(" Start it with: node dist/standalone/server.js\n");
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
144
|
const prerenderDecision = resolveVinextPrerenderDecision({
|
|
155
145
|
prerenderAllFlag: context.prerenderAll,
|
|
156
146
|
vinextPrerenderConfig: context.prerenderConfig,
|
|
@@ -187,6 +177,16 @@ async function finalizeBuild(builder, context) {
|
|
|
187
177
|
routeRootConfig: buildOutput
|
|
188
178
|
});
|
|
189
179
|
}
|
|
180
|
+
if (context.nextConfig.output === "standalone") {
|
|
181
|
+
const { emitStandaloneOutput } = await import("./standalone.js");
|
|
182
|
+
const standalone = emitStandaloneOutput({
|
|
183
|
+
root: context.root,
|
|
184
|
+
outDir: path.resolve(context.root, "dist")
|
|
185
|
+
});
|
|
186
|
+
console.log(` Generated standalone output in ${path.relative(context.root, standalone.standaloneDir)}/`);
|
|
187
|
+
console.log(" Start it with: node dist/standalone/server.js\n");
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
190
|
const { printBuildReport } = await import("./report.js");
|
|
191
191
|
await printBuildReport({
|
|
192
192
|
root: context.root,
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import path from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
2
|
+
import { getSharedChunkFiles } from "../server/pages-asset-tags.js";
|
|
2
3
|
import fs from "node:fs";
|
|
3
4
|
//#region src/build/pages-client-assets-module.ts
|
|
4
5
|
const PAGES_CLIENT_ASSETS_MODULE = "vinext-client-assets.js";
|
|
5
6
|
function buildPagesClientAssetsModule(assets) {
|
|
6
|
-
|
|
7
|
+
const prepared = assets.ssrManifest ? {
|
|
8
|
+
...assets,
|
|
9
|
+
sharedChunks: getSharedChunkFiles(assets.ssrManifest)
|
|
10
|
+
} : assets;
|
|
11
|
+
return `export default ${JSON.stringify(prepared)};\n`;
|
|
7
12
|
}
|
|
8
13
|
function writePagesClientAssetsModuleIfMissing(outputDir, moduleSource) {
|
|
9
14
|
const outputPath = path.join(outputDir, PAGES_CLIENT_ASSETS_MODULE);
|
|
@@ -3,9 +3,9 @@ import { ASSET_PREFIX_URL_DIR } from "../utils/asset-prefix.js";
|
|
|
3
3
|
import { isPrecompressedVariantBeneficial } from "../utils/precompressed-variant.js";
|
|
4
4
|
import fsp from "node:fs/promises";
|
|
5
5
|
import { randomUUID } from "node:crypto";
|
|
6
|
-
import { promisify } from "node:util";
|
|
7
6
|
import os from "node:os";
|
|
8
7
|
import zlib from "node:zlib";
|
|
8
|
+
import { promisify } from "node:util";
|
|
9
9
|
//#region src/build/precompress.ts
|
|
10
10
|
/**
|
|
11
11
|
* Build-time precompression for hashed static assets.
|
|
@@ -19,9 +19,9 @@ import { readPrerenderSecret } from "./server-manifest.js";
|
|
|
19
19
|
import { loadMdxEsmReader } from "../utils/mdx-scan.js";
|
|
20
20
|
import { startProdServer } from "../server/prod-server.js";
|
|
21
21
|
import { enterPrerenderPhase } from "./prerender-phase.js";
|
|
22
|
-
import { buildUrlFromParams, layoutOnlyParamSets, resolveParentParams, routeStaticParamSets, validateDiscoveredParams } from "./prerender.js";
|
|
22
|
+
import { buildUrlFromParams, layoutOnlyParamSets, localizePagesPath, resolveParentParams, routeStaticParamSets, validateDiscoveredParams } from "./prerender.js";
|
|
23
23
|
import { collectAppPageStaticGenerationRuntimes, hasAppPageGenerateStaticParamsAtLastDynamicSegment, isAppPageStaticEligible, isEdgeRuntime, resolveAppPageDynamicConfig, resolveAppPageSegmentConfig, resolveAppPageStaticGenerationRuntime } from "../server/app-segment-config.js";
|
|
24
|
-
import { resolveBuiltRscEntryPath } from "./server-entry.js";
|
|
24
|
+
import { resolveBuiltPagesEntryPath, resolveBuiltRscEntryPath } from "./server-entry.js";
|
|
25
25
|
import fs from "node:fs";
|
|
26
26
|
//#region src/build/prerender-paths.ts
|
|
27
27
|
const PRERENDER_PATH_DISCOVERY_ENV = "__VINEXT_PRERENDER_PATH_DISCOVERY";
|
|
@@ -325,10 +325,6 @@ async function resolvePagesWarmRouteMetadata(options) {
|
|
|
325
325
|
routePatterns
|
|
326
326
|
};
|
|
327
327
|
}
|
|
328
|
-
function localizePagesPath(pathname, locale, i18n) {
|
|
329
|
-
if (!i18n || !locale || locale === i18n.defaultLocale) return pathname;
|
|
330
|
-
return pathname === "/" ? `/${locale}` : `/${locale}${pathname}`;
|
|
331
|
-
}
|
|
332
328
|
/**
|
|
333
329
|
* Next.js data URLs always carry the locale segment, including the default
|
|
334
330
|
* locale that is omitted from the corresponding public HTML pathname.
|
|
@@ -795,7 +791,7 @@ async function discoverPrerenderPathManifest(options) {
|
|
|
795
791
|
const rscBundlePath = options.rscBundlePath ?? defaultRscBundlePath;
|
|
796
792
|
const relativeRscEntryPath = path.relative(configuredRscServerDir, rscBundlePath);
|
|
797
793
|
const rscServerDir = !relativeRscEntryPath.startsWith("../") && !path.isAbsolute(relativeRscEntryPath) ? configuredRscServerDir : path.dirname(rscBundlePath);
|
|
798
|
-
const pagesBundlePath = options.pagesBundlePath ?? path.
|
|
794
|
+
const pagesBundlePath = options.pagesBundlePath ?? resolveBuiltPagesEntryPath(path.resolve(root, options.routeRootConfig?.ssrOutDir ?? path.join("dist", "server")));
|
|
799
795
|
const bundleServerDir = fs.existsSync(rscBundlePath) ? rscServerDir : path.dirname(pagesBundlePath);
|
|
800
796
|
const manifestDir = path.join(root, "dist", "server");
|
|
801
797
|
const config = options.nextConfig ? { ...options.nextConfig } : { ...await resolveNextConfig(await loadNextConfig(root, PHASE_PRODUCTION_BUILD), root) };
|
|
@@ -30,8 +30,14 @@ export type PrerenderRouteResult = {
|
|
|
30
30
|
router: "app" | "pages" | "metadata";
|
|
31
31
|
/** Response headers that must be replayed with the prerendered artifact. */
|
|
32
32
|
headers?: Record<string, string | string[]>;
|
|
33
|
-
/** Original HTTP status for prerendered
|
|
33
|
+
/** Original HTTP status for prerendered route responses. */
|
|
34
34
|
responseStatus?: number;
|
|
35
|
+
/** Pages source returned notFound, distinct from the custom 404 document. */
|
|
36
|
+
notFound?: true;
|
|
37
|
+
/** Original Pages redirect props, including client navigation semantics. */
|
|
38
|
+
redirectProps?: object;
|
|
39
|
+
/** Pages locale rendered for this public pathname. */
|
|
40
|
+
locale?: string;
|
|
35
41
|
/** Cache tags collected while rendering this route. */
|
|
36
42
|
tags?: string[];
|
|
37
43
|
/** Raw app-tree segments used to derive App Route implicit tags. */
|
|
@@ -234,6 +240,7 @@ export declare function routeStaticParamSets(route: Pick<AppRoute, "pattern">, p
|
|
|
234
240
|
* sets still go through routeStaticParamSets.
|
|
235
241
|
*/
|
|
236
242
|
export declare function layoutOnlyParamSets(route: Pick<AppRoute, "params" | "pattern">, parentParamSets: Record<string, string | string[]>[]): Record<string, string | string[]>[] | null;
|
|
243
|
+
export declare function localizePagesPath(pathname: string, locale: string | undefined, i18n: ResolvedNextConfig["i18n"]): string;
|
|
237
244
|
/**
|
|
238
245
|
* Run the prerender phase for Pages Router.
|
|
239
246
|
*
|
package/dist/build/prerender.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import path from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
2
2
|
import { createValidFileMatcher, findFileWithExtensions } from "../routing/file-matcher.js";
|
|
3
|
+
import { isUnknownRecord } from "../utils/record.js";
|
|
3
4
|
import { BLOCKED_PAGES } from "../shims/constants.js";
|
|
4
5
|
import { VINEXT_PRERENDER_ROUTE_PARAMS_HEADER, VINEXT_PRERENDER_SECRET_HEADER, VINEXT_PRERENDER_SPECULATIVE_HEADER } from "../utils/protocol-headers.js";
|
|
5
6
|
import { appRouteLayoutStaticParamsGroups } from "../routing/app-router.js";
|
|
6
7
|
import { NEXT_CACHE_TAGS_HEADER, VINEXT_METADATA_ROUTE_CACHE_HEADER, VINEXT_PRERENDER_CACHE_LIFE_HEADER, VINEXT_PRERENDER_METADATA_ROUTES_PATH, VINEXT_PRERENDER_RENDER_ERROR_HEADER } from "../server/headers.js";
|
|
8
|
+
import { extractLocaleFromUrl } from "../server/pages-i18n.js";
|
|
7
9
|
import { classifyAppRoute, classifyPagesRoute, getAppRouteRenderEntryPath } from "./report.js";
|
|
8
10
|
import { resolveClientStaleTimeSeconds } from "../utils/cache-control-metadata.js";
|
|
9
11
|
import { NoOpCacheHandler, getCacheHandler, setCacheHandler } from "../shims/cache-handler.js";
|
|
@@ -21,7 +23,6 @@ import { startProdServer } from "../server/prod-server.js";
|
|
|
21
23
|
import { prerenderPoolAvailable, resolvePrerenderPoolSize, startPrerenderServerPool } from "./prerender-server-pool.js";
|
|
22
24
|
import { enterPrerenderPhase } from "./prerender-phase.js";
|
|
23
25
|
import { buildAppRouteCacheValue } from "../server/app-route-handler-response.js";
|
|
24
|
-
import { isMetadataResponseCacheable } from "../server/metadata-route-cache-policy.js";
|
|
25
26
|
import fs from "node:fs";
|
|
26
27
|
import os from "node:os";
|
|
27
28
|
//#region src/build/prerender.ts
|
|
@@ -337,6 +338,14 @@ function routeStaticParamSets(route, paramSets, options = {}) {
|
|
|
337
338
|
function layoutOnlyParamSets(route, parentParamSets) {
|
|
338
339
|
return parentParamSets.length > 0 && parentParamSets.every((params) => route.params.every((name) => name in params)) ? parentParamSets : null;
|
|
339
340
|
}
|
|
341
|
+
function localizePagesPath(pathname, locale, i18n) {
|
|
342
|
+
if (!i18n || !locale) return pathname;
|
|
343
|
+
if (locale === i18n.defaultLocale) {
|
|
344
|
+
const firstSegment = pathname.split("/")[1]?.toLowerCase();
|
|
345
|
+
if (!i18n.locales.some((candidate) => candidate.toLowerCase() === firstSegment)) return pathname;
|
|
346
|
+
}
|
|
347
|
+
return pathname === "/" ? `/${locale}` : `/${locale}${pathname}`;
|
|
348
|
+
}
|
|
340
349
|
/**
|
|
341
350
|
* Run the prerender phase for Pages Router.
|
|
342
351
|
*
|
|
@@ -379,6 +388,8 @@ async function prerenderPages({ routes, apiRoutes, pagesDir, outDir, config, mod
|
|
|
379
388
|
port: 0,
|
|
380
389
|
host: "127.0.0.1",
|
|
381
390
|
outDir: path.dirname(path.dirname(pagesBundlePath)),
|
|
391
|
+
serverDir: path.dirname(pagesBundlePath),
|
|
392
|
+
serverEntryPath: pagesBundlePath,
|
|
382
393
|
noCompression: true,
|
|
383
394
|
purpose: "prerender"
|
|
384
395
|
});
|
|
@@ -428,7 +439,7 @@ async function prerenderPages({ routes, apiRoutes, pagesDir, outDir, config, mod
|
|
|
428
439
|
for (const route of bundlePageRoutes) {
|
|
429
440
|
if (BLOCKED_PAGES.includes(route.pattern)) continue;
|
|
430
441
|
if (route.pattern === "/404") continue;
|
|
431
|
-
const { type, revalidate: classifiedRevalidate } = classifyPagesRoute(route.filePath);
|
|
442
|
+
const { type, revalidate: classifiedRevalidate, hasStaticProps = false } = classifyPagesRoute(route.filePath);
|
|
432
443
|
if (type === "ssr") {
|
|
433
444
|
if (mode === "export") results.push({
|
|
434
445
|
route: route.pattern,
|
|
@@ -460,8 +471,8 @@ async function prerenderPages({ routes, apiRoutes, pagesDir, outDir, config, mod
|
|
|
460
471
|
let pathsResult;
|
|
461
472
|
try {
|
|
462
473
|
pathsResult = await route.module.getStaticPaths({
|
|
463
|
-
locales: [],
|
|
464
|
-
defaultLocale: ""
|
|
474
|
+
locales: [...config.i18n?.locales ?? []],
|
|
475
|
+
defaultLocale: config.i18n?.defaultLocale ?? ""
|
|
465
476
|
});
|
|
466
477
|
} catch (e) {
|
|
467
478
|
results.push({
|
|
@@ -483,21 +494,38 @@ async function prerenderPages({ routes, apiRoutes, pagesDir, outDir, config, mod
|
|
|
483
494
|
}
|
|
484
495
|
const paths = pathsResult?.paths ?? [];
|
|
485
496
|
let entryError = null;
|
|
497
|
+
const seenPaths = /* @__PURE__ */ new Set();
|
|
486
498
|
for (const item of paths) {
|
|
487
|
-
|
|
499
|
+
let locale = config.i18n?.defaultLocale;
|
|
500
|
+
let pathEntry = item;
|
|
501
|
+
if (config.i18n && typeof item === "string") {
|
|
502
|
+
const localized = extractLocaleFromUrl(item, config.i18n);
|
|
503
|
+
locale = localized.locale;
|
|
504
|
+
pathEntry = localized.url;
|
|
505
|
+
} else if (item && typeof item === "object" && item.locale !== void 0) locale = item.locale;
|
|
506
|
+
const normalized = normalizeStaticPathsEntry(pathEntry, route.pattern);
|
|
488
507
|
if ("error" in normalized) {
|
|
489
508
|
entryError = normalized.error;
|
|
490
509
|
break;
|
|
491
510
|
}
|
|
511
|
+
if (locale !== void 0 && !config.i18n?.locales.includes(locale)) {
|
|
512
|
+
entryError = `Invalid locale returned from getStaticPaths for ${route.pattern}: ${locale}`;
|
|
513
|
+
break;
|
|
514
|
+
}
|
|
492
515
|
const { params } = normalized;
|
|
493
516
|
try {
|
|
494
|
-
const urlPath = buildUrlFromParams(route.pattern, params);
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
517
|
+
const urlPath = localizePagesPath(buildUrlFromParams(route.pattern, params), locale, config.i18n);
|
|
518
|
+
if (!seenPaths.has(urlPath)) {
|
|
519
|
+
seenPaths.add(urlPath);
|
|
520
|
+
pagesToRender.push({
|
|
521
|
+
route,
|
|
522
|
+
urlPath,
|
|
523
|
+
params,
|
|
524
|
+
revalidate,
|
|
525
|
+
hasStaticProps,
|
|
526
|
+
locale
|
|
527
|
+
});
|
|
528
|
+
}
|
|
501
529
|
} catch (e) {
|
|
502
530
|
entryError = e.message;
|
|
503
531
|
break;
|
|
@@ -511,25 +539,58 @@ async function prerenderPages({ routes, apiRoutes, pagesDir, outDir, config, mod
|
|
|
511
539
|
});
|
|
512
540
|
continue;
|
|
513
541
|
}
|
|
514
|
-
} else pagesToRender.push({
|
|
542
|
+
} else for (const locale of config.i18n?.locales ?? [void 0]) pagesToRender.push({
|
|
515
543
|
route,
|
|
516
|
-
urlPath: route.pattern,
|
|
544
|
+
urlPath: localizePagesPath(route.pattern, locale, config.i18n),
|
|
517
545
|
params: {},
|
|
518
|
-
revalidate
|
|
546
|
+
revalidate,
|
|
547
|
+
hasStaticProps,
|
|
548
|
+
locale
|
|
519
549
|
});
|
|
520
550
|
}
|
|
521
551
|
if (!options._prodServer && pagesBundlePath && prerenderPoolAvailable()) {
|
|
522
552
|
const poolSize = resolvePrerenderPoolSize(pagesToRender.length, concurrency);
|
|
523
553
|
if (poolSize > 1) {
|
|
524
|
-
renderPool = await startOptionalPrerenderServerPool(path.dirname(path.dirname(pagesBundlePath)), poolSize);
|
|
554
|
+
renderPool = await startOptionalPrerenderServerPool(path.dirname(path.dirname(pagesBundlePath)), poolSize, void 0, path.dirname(pagesBundlePath));
|
|
525
555
|
if (renderPool) renderPorts = renderPool.ports;
|
|
526
556
|
}
|
|
527
557
|
}
|
|
528
558
|
let completed = 0;
|
|
529
|
-
const pageResults = await runWithConcurrency(pagesToRender, concurrency, async ({ route, urlPath, revalidate }) => {
|
|
559
|
+
const pageResults = await runWithConcurrency(pagesToRender, concurrency, async ({ route, urlPath, revalidate, hasStaticProps, locale }) => {
|
|
530
560
|
let result;
|
|
531
561
|
try {
|
|
532
562
|
const response = await renderPage(urlPath);
|
|
563
|
+
if (mode === "default" && response.headers.get("x-vinext-prerender-rewritten") !== "0") {
|
|
564
|
+
response.body?.cancel().catch(() => {});
|
|
565
|
+
const skipped = {
|
|
566
|
+
route: route.pattern,
|
|
567
|
+
status: "skipped",
|
|
568
|
+
reason: "dynamic"
|
|
569
|
+
};
|
|
570
|
+
onProgress?.({
|
|
571
|
+
completed: ++completed,
|
|
572
|
+
total: pagesToRender.length,
|
|
573
|
+
route: urlPath,
|
|
574
|
+
status: skipped.status
|
|
575
|
+
});
|
|
576
|
+
return skipped;
|
|
577
|
+
}
|
|
578
|
+
const contentType = response.headers.get("content-type");
|
|
579
|
+
const isStaticPropsResponse = mode === "default" && hasStaticProps && response.headers.get("X-Vinext-Cache") === "MISS";
|
|
580
|
+
const notFound = isStaticPropsResponse && response.status === 404;
|
|
581
|
+
const redirect = isStaticPropsResponse && [
|
|
582
|
+
301,
|
|
583
|
+
302,
|
|
584
|
+
303,
|
|
585
|
+
307,
|
|
586
|
+
308
|
|
587
|
+
].includes(response.status);
|
|
588
|
+
let redirectProps;
|
|
589
|
+
if (redirect) {
|
|
590
|
+
const props = await response.json();
|
|
591
|
+
if (!isUnknownRecord(props) || !isUnknownRecord(props.pageProps) || typeof props.pageProps.__N_REDIRECT !== "string" || props.pageProps.__N_REDIRECT_STATUS !== response.status || props.pageProps.__N_REDIRECT_BASE_PATH !== void 0 && typeof props.pageProps.__N_REDIRECT_BASE_PATH !== "boolean") throw new Error(`Invalid prerendered Pages redirect props for ${urlPath}`);
|
|
592
|
+
redirectProps = props;
|
|
593
|
+
}
|
|
533
594
|
const outputFiles = [];
|
|
534
595
|
const htmlOutputPath = getOutputPath(urlPath, config.trailingSlash, mode === "export" ? config.basePath : "");
|
|
535
596
|
const htmlFullPath = path.join(outDir, htmlOutputPath);
|
|
@@ -539,7 +600,7 @@ async function prerenderPages({ routes, apiRoutes, pagesDir, outDir, config, mod
|
|
|
539
600
|
fs.writeFileSync(htmlFullPath, html, "utf-8");
|
|
540
601
|
outputFiles.push(htmlOutputPath);
|
|
541
602
|
} else {
|
|
542
|
-
if (!response.ok) throw new Error(`renderPage returned ${response.status} for ${urlPath}`);
|
|
603
|
+
if (!response.ok && !notFound) throw new Error(`renderPage returned ${response.status} for ${urlPath}`);
|
|
543
604
|
const html = await response.text();
|
|
544
605
|
fs.mkdirSync(path.dirname(htmlFullPath), { recursive: true });
|
|
545
606
|
fs.writeFileSync(htmlFullPath, html, "utf-8");
|
|
@@ -552,7 +613,19 @@ async function prerenderPages({ routes, apiRoutes, pagesDir, outDir, config, mod
|
|
|
552
613
|
revalidate,
|
|
553
614
|
...typeof revalidate === "number" ? { expire: config.expireTime } : {},
|
|
554
615
|
router: "pages",
|
|
555
|
-
...urlPath !== route.pattern ? { path: urlPath } : {}
|
|
616
|
+
...urlPath !== route.pattern ? { path: urlPath } : {},
|
|
617
|
+
...locale ? { locale } : {},
|
|
618
|
+
...response.ok ? { responseStatus: response.status } : {},
|
|
619
|
+
...response.ok && contentType ? { headers: { "content-type": contentType } } : {},
|
|
620
|
+
...notFound ? {
|
|
621
|
+
notFound: true,
|
|
622
|
+
responseStatus: 404
|
|
623
|
+
} : {},
|
|
624
|
+
...redirect ? {
|
|
625
|
+
responseStatus: response.status,
|
|
626
|
+
redirectProps,
|
|
627
|
+
headers: { location: response.headers.get("location") ?? "/" }
|
|
628
|
+
} : {}
|
|
556
629
|
};
|
|
557
630
|
} catch (e) {
|
|
558
631
|
renderPool?.recordRenderError(e);
|
|
@@ -575,21 +648,41 @@ async function prerenderPages({ routes, apiRoutes, pagesDir, outDir, config, mod
|
|
|
575
648
|
renderPool?.assertHealthy();
|
|
576
649
|
const hasCustom404 = findFileWithExtensions(path.join(pagesDir, "404"), fileMatcher);
|
|
577
650
|
const hasErrorPage = findFileWithExtensions(path.join(pagesDir, "_error"), fileMatcher);
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
651
|
+
for (const locale of config.i18n?.locales ?? [void 0]) {
|
|
652
|
+
if (!hasCustom404 && !hasErrorPage) break;
|
|
653
|
+
try {
|
|
654
|
+
const notFoundRes = await renderPage(localizePagesPath(hasCustom404 ? "/404" : NOT_FOUND_SENTINEL_PATH, locale, config.i18n));
|
|
655
|
+
if (mode === "default" && notFoundRes.headers.get("x-vinext-prerender-rewritten") !== "0") {
|
|
656
|
+
notFoundRes.body?.cancel().catch(() => {});
|
|
657
|
+
continue;
|
|
658
|
+
}
|
|
659
|
+
const contentType = notFoundRes.headers.get("content-type") ?? "";
|
|
660
|
+
if (notFoundRes.status === 404 && contentType.includes("text/html")) {
|
|
661
|
+
const html404 = await notFoundRes.text();
|
|
662
|
+
const pathname = localizePagesPath("/404", locale, config.i18n);
|
|
663
|
+
let outputFiles;
|
|
664
|
+
if (pathname === "/404") outputFiles = emitStatic404Files(outDir, html404, config.trailingSlash);
|
|
665
|
+
else {
|
|
666
|
+
const outputPath = getOutputPath(pathname, config.trailingSlash);
|
|
667
|
+
const fullPath = path.join(outDir, outputPath);
|
|
668
|
+
fs.mkdirSync(path.dirname(fullPath), { recursive: true });
|
|
669
|
+
fs.writeFileSync(fullPath, html404, "utf8");
|
|
670
|
+
outputFiles = [outputPath];
|
|
671
|
+
}
|
|
672
|
+
results.push({
|
|
673
|
+
route: "/404",
|
|
674
|
+
status: "rendered",
|
|
675
|
+
outputFiles,
|
|
676
|
+
revalidate: false,
|
|
677
|
+
router: "pages",
|
|
678
|
+
headers: { "content-type": contentType },
|
|
679
|
+
...pathname !== "/404" ? { path: pathname } : {},
|
|
680
|
+
...locale ? { locale } : {}
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
} catch (e) {
|
|
684
|
+
renderPool?.recordRenderError(e);
|
|
590
685
|
}
|
|
591
|
-
} catch (e) {
|
|
592
|
-
renderPool?.recordRenderError(e);
|
|
593
686
|
}
|
|
594
687
|
renderPool?.assertHealthy();
|
|
595
688
|
if (!skipManifest) writePrerenderIndex(results, manifestDir, {
|
|
@@ -900,7 +993,8 @@ async function prerenderApp({ routes, metadataRoutes = [], outDir, config, mode,
|
|
|
900
993
|
};
|
|
901
994
|
}
|
|
902
995
|
const cacheControl = response.headers.get("cache-control") ?? "";
|
|
903
|
-
|
|
996
|
+
const requestCacheLife = readPrerenderCacheLifeHeader(response.headers);
|
|
997
|
+
if (requestCacheLife?.revalidate === 0) {
|
|
904
998
|
await response.body?.cancel();
|
|
905
999
|
return {
|
|
906
1000
|
route: routePattern,
|
|
@@ -908,15 +1002,14 @@ async function prerenderApp({ routes, metadataRoutes = [], outDir, config, mode,
|
|
|
908
1002
|
reason: "dynamic"
|
|
909
1003
|
};
|
|
910
1004
|
}
|
|
911
|
-
const requestCacheLife = readPrerenderCacheLifeHeader(response.headers);
|
|
912
1005
|
const collectedTags = readPrerenderCacheTagsHeader(response.headers);
|
|
913
|
-
const cacheValue = await buildAppRouteCacheValue(response);
|
|
1006
|
+
const cacheValue = await buildAppRouteCacheValue(response, cacheControl);
|
|
914
1007
|
cacheValue.headers[VINEXT_METADATA_ROUTE_CACHE_HEADER] = "1";
|
|
915
1008
|
const outputPath = getAppRouteOutputPath(urlPath);
|
|
916
1009
|
const fullPath = path.join(outDir, outputPath);
|
|
917
1010
|
fs.mkdirSync(path.dirname(fullPath), { recursive: true });
|
|
918
1011
|
fs.writeFileSync(fullPath, new Uint8Array(cacheValue.body));
|
|
919
|
-
const renderedCacheControl = resolveRenderedCacheControl(requestCacheLife ?? {},
|
|
1012
|
+
const renderedCacheControl = resolveRenderedCacheControl(requestCacheLife ?? {}, "", config.expireTime);
|
|
920
1013
|
const renderedRevalidate = renderedCacheControl.revalidate ?? false;
|
|
921
1014
|
const renderedStale = resolveClientStaleTimeSeconds(requestCacheLife ?? void 0);
|
|
922
1015
|
return {
|
|
@@ -1187,6 +1280,9 @@ function writePrerenderIndex(routes, outDir, options) {
|
|
|
1187
1280
|
...r.routeSegments ? { routeSegments: r.routeSegments } : {},
|
|
1188
1281
|
...r.headers ? { headers: r.headers } : {},
|
|
1189
1282
|
...typeof r.responseStatus === "number" ? { responseStatus: r.responseStatus } : {},
|
|
1283
|
+
...r.notFound ? { notFound: true } : {},
|
|
1284
|
+
...r.redirectProps ? { redirectProps: r.redirectProps } : {},
|
|
1285
|
+
...r.locale ? { locale: r.locale } : {},
|
|
1190
1286
|
...r.path ? { path: r.path } : {},
|
|
1191
1287
|
...r.fallback ? { fallback: true } : {}
|
|
1192
1288
|
};
|
|
@@ -1210,4 +1306,4 @@ function writePrerenderIndex(routes, outDir, options) {
|
|
|
1210
1306
|
fs.writeFileSync(path.join(outDir, "vinext-prerender.json"), JSON.stringify(index, null, 2), "utf-8");
|
|
1211
1307
|
}
|
|
1212
1308
|
//#endregion
|
|
1213
|
-
export { buildUrlFromParams, extractRscPayloadFromPrerenderedHtml, layoutOnlyParamSets, prerenderApp, prerenderPages, readPrerenderSecret, resolveParentParams, routeStaticParamSets, validateDiscoveredParams, writePrerenderIndex };
|
|
1309
|
+
export { buildUrlFromParams, extractRscPayloadFromPrerenderedHtml, layoutOnlyParamSets, localizePagesPath, prerenderApp, prerenderPages, readPrerenderSecret, resolveParentParams, routeStaticParamSets, validateDiscoveredParams, writePrerenderIndex };
|
|
@@ -11,7 +11,7 @@ import { rememberCurrentServerEntryImportMtime, startProdServer } from "../serve
|
|
|
11
11
|
import { enterPrerenderPhase } from "./prerender-phase.js";
|
|
12
12
|
import { prerenderApp, prerenderPages, writePrerenderIndex } from "./prerender.js";
|
|
13
13
|
import { injectPregeneratedConcretePaths } from "./inject-pregenerated-paths.js";
|
|
14
|
-
import { resolveBuiltRscEntryPath } from "./server-entry.js";
|
|
14
|
+
import { resolveBuiltPagesEntryPath, resolveBuiltRscEntryPath } from "./server-entry.js";
|
|
15
15
|
import fs from "node:fs";
|
|
16
16
|
//#region src/build/run-prerender.ts
|
|
17
17
|
/**
|
|
@@ -112,10 +112,11 @@ async function runPrerender(options) {
|
|
|
112
112
|
const buildOutDir = path.resolve(root, "dist");
|
|
113
113
|
const configuredRscServerDir = path.resolve(root, options.routeRootConfig?.rscOutDir ?? path.join("dist", "server"));
|
|
114
114
|
const rscBundlePath = options.rscBundlePath ?? resolveBuiltRscEntryPath(configuredRscServerDir);
|
|
115
|
+
const pagesBundlePath = options.pagesBundlePath ?? resolveBuiltPagesEntryPath(path.resolve(root, options.routeRootConfig?.ssrOutDir ?? path.join("dist", "server")));
|
|
115
116
|
const relativeEntryPath = path.relative(configuredRscServerDir, rscBundlePath);
|
|
116
117
|
const serverDir = !relativeEntryPath.startsWith("../") && !path.isAbsolute(relativeEntryPath) ? configuredRscServerDir : path.dirname(rscBundlePath);
|
|
117
118
|
const config = options.nextConfig ? { ...options.nextConfig } : { ...await resolveNextConfig(await loadNextConfig(root, PHASE_PRODUCTION_BUILD), root) };
|
|
118
|
-
const builtBuildId = readBuiltBuildId(manifestDir) ?? readBuiltBuildId(serverDir);
|
|
119
|
+
const builtBuildId = readBuiltBuildId(manifestDir) ?? readBuiltBuildId(appDir ? serverDir : path.dirname(pagesBundlePath));
|
|
119
120
|
if (builtBuildId) config.buildId = builtBuildId;
|
|
120
121
|
const mode = config.output === "export" ? "export" : "default";
|
|
121
122
|
const allRoutes = [];
|
|
@@ -183,7 +184,7 @@ async function runPrerender(options) {
|
|
|
183
184
|
...sharedProdServer ? {
|
|
184
185
|
_prodServer: sharedProdServer,
|
|
185
186
|
_prerenderSecret: sharedPrerenderSecret
|
|
186
|
-
} : { pagesBundlePath
|
|
187
|
+
} : { pagesBundlePath },
|
|
187
188
|
onProgress: ({ total, route }) => {
|
|
188
189
|
if (pagesTotal === 0) {
|
|
189
190
|
pagesTotal = total;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
//#region src/build/server-entry.d.ts
|
|
2
|
+
/** Pages builds emit entry.js in Node or index.js when the host owns the Worker entry. */
|
|
3
|
+
export declare function resolveBuiltPagesEntryPath(serverDir: string): string;
|
|
2
4
|
/** Resolve the built App handler even when a deployment host owns index.js. */
|
|
3
5
|
export declare function resolveBuiltRscEntryPath(serverDir: string): string;
|
|
4
6
|
//#endregion
|
|
@@ -2,6 +2,12 @@ import path from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
//#region src/build/server-entry.ts
|
|
4
4
|
const RSC_ENTRY_MANIFEST_KEY = "virtual:vinext-rsc-entry";
|
|
5
|
+
/** Pages builds emit entry.js in Node or index.js when the host owns the Worker entry. */
|
|
6
|
+
function resolveBuiltPagesEntryPath(serverDir) {
|
|
7
|
+
const nodeEntryPath = path.join(serverDir, "entry.js");
|
|
8
|
+
const workerEntryPath = path.join(serverDir, "index.js");
|
|
9
|
+
return fs.existsSync(nodeEntryPath) || !fs.existsSync(workerEntryPath) ? nodeEntryPath : workerEntryPath;
|
|
10
|
+
}
|
|
5
11
|
/** Resolve the built App handler even when a deployment host owns index.js. */
|
|
6
12
|
function resolveBuiltRscEntryPath(serverDir) {
|
|
7
13
|
const fallbackPath = path.join(serverDir, "index.js");
|
|
@@ -25,4 +31,4 @@ function resolveBuiltRscEntryPath(serverDir) {
|
|
|
25
31
|
return fs.existsSync(entryPath) ? entryPath : fallbackPath;
|
|
26
32
|
}
|
|
27
33
|
//#endregion
|
|
28
|
-
export { resolveBuiltRscEntryPath };
|
|
34
|
+
export { resolveBuiltPagesEntryPath, resolveBuiltRscEntryPath };
|
|
@@ -66,7 +66,6 @@ export type NavigationRuntime = {
|
|
|
66
66
|
bootstrap: NavigationRuntimeBootstrap;
|
|
67
67
|
functions: NavigationRuntimeFunctions;
|
|
68
68
|
};
|
|
69
|
-
export declare const NAVIGATION_RUNTIME_SYMBOL_DESCRIPTION = "vinext.navigationRuntime";
|
|
70
69
|
export declare const NAVIGATION_RUNTIME_KEY: unique symbol;
|
|
71
70
|
export declare function getNavigationRuntime(): NavigationRuntime | null;
|
|
72
71
|
export declare function registerNavigationRuntimeBootstrap(bootstrap: Partial<NavigationRuntimeBootstrap>): NavigationRuntime;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isUnknownRecord } from "../utils/record.js";
|
|
2
|
+
import { NAVIGATION_RUNTIME_SYMBOL_DESCRIPTION } from "./browser-globals.js";
|
|
2
3
|
//#region src/client/navigation-runtime.ts
|
|
3
|
-
const NAVIGATION_RUNTIME_SYMBOL_DESCRIPTION = "vinext.navigationRuntime";
|
|
4
4
|
const NAVIGATION_RUNTIME_KEY = Symbol.for(NAVIGATION_RUNTIME_SYMBOL_DESCRIPTION);
|
|
5
5
|
const ROUTE_MANIFEST_SEGMENT_GRAPH_MAP_KEYS = [
|
|
6
6
|
"boundaries",
|
|
@@ -169,4 +169,4 @@ function hasAppNavigationRuntimeBootstrap() {
|
|
|
169
169
|
return getNavigationRuntime() !== null;
|
|
170
170
|
}
|
|
171
171
|
//#endregion
|
|
172
|
-
export { NAVIGATION_RUNTIME_KEY,
|
|
172
|
+
export { NAVIGATION_RUNTIME_KEY, ensureNavigationRuntimeRscBootstrap, getNavigationRuntime, hasAppNavigationRuntime, hasAppNavigationRuntimeBootstrap, registerNavigationRuntimeBootstrap, registerNavigationRuntimeFunctions };
|
package/dist/config/dotenv.js
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import path from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
2
2
|
import fs from "node:fs";
|
|
3
|
-
import { parseEnv } from "node:util";
|
|
4
3
|
//#region src/config/dotenv.ts
|
|
4
|
+
const DOTENV_LINE = /^\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?$/gm;
|
|
5
|
+
function parseDotenv(content) {
|
|
6
|
+
const parsed = {};
|
|
7
|
+
const lines = content.replace(/\r\n?/g, "\n");
|
|
8
|
+
for (const match of lines.matchAll(DOTENV_LINE)) {
|
|
9
|
+
let value = (match[2] ?? "").trim();
|
|
10
|
+
const quote = value[0];
|
|
11
|
+
value = value.replace(/^(['"`])([\s\S]*)\1$/gm, "$2");
|
|
12
|
+
if (quote === "\"") value = value.replace(/\\n/g, "\n").replace(/\\r/g, "\r");
|
|
13
|
+
parsed[match[1]] = value;
|
|
14
|
+
}
|
|
15
|
+
return parsed;
|
|
16
|
+
}
|
|
5
17
|
/**
|
|
6
18
|
* Next.js-compatible dotenv lookup order (highest priority first).
|
|
7
19
|
*/
|
|
@@ -42,8 +54,7 @@ function loadDotenv({ root, mode, processEnv = process.env }) {
|
|
|
42
54
|
for (const relativeFile of getDotenvFiles(mode)) {
|
|
43
55
|
const filePath = path.join(root, relativeFile);
|
|
44
56
|
if (!fs.existsSync(filePath)) continue;
|
|
45
|
-
const
|
|
46
|
-
const expanded = expandEnv(parseEnv(fileContent), processEnv);
|
|
57
|
+
const expanded = expandEnv(parseDotenv(fs.readFileSync(filePath, "utf-8")), processEnv);
|
|
47
58
|
for (const [key, value] of Object.entries(expanded)) {
|
|
48
59
|
if (processEnv[key] !== void 0) continue;
|
|
49
60
|
processEnv[key] = value;
|
|
@@ -46,7 +46,6 @@ const appPageRequestPath = resolveEntryPath("../server/app-page-request.js", imp
|
|
|
46
46
|
const appSegmentConfigPath = resolveEntryPath("../server/app-segment-config.js", import.meta.url);
|
|
47
47
|
const appRscRouteMatchingPath = resolveEntryPath("../server/app-rsc-route-matching.js", import.meta.url);
|
|
48
48
|
const appRscResponseStagePath = resolveEntryPath("../server/app-rsc-response-stage.js", import.meta.url);
|
|
49
|
-
const appRscCombinedHandlerPath = resolveEntryPath("../server/app-rsc-combined-handler.js", import.meta.url);
|
|
50
49
|
const rscStreamHintsPath = resolveEntryPath("../server/rsc-stream-hints.js", import.meta.url);
|
|
51
50
|
const isrCachePath = resolveEntryPath("../server/isr-cache.js", import.meta.url);
|
|
52
51
|
const thenableParamsShimPath = resolveEntryPath("../shims/thenable-params.js", import.meta.url);
|
|
@@ -240,6 +239,7 @@ function __isMetadataPath(pathname) {
|
|
|
240
239
|
${generateDevOriginCheckCode(config?.allowedDevOrigins)}
|
|
241
240
|
|
|
242
241
|
const __requestHandler = createAppRscRequestHandler({
|
|
242
|
+
assetPrefix: __assetPrefix,
|
|
243
243
|
basePath: __basePath,
|
|
244
244
|
buildId: process.env.__VINEXT_BUILD_ID ?? null,
|
|
245
245
|
cacheabilityRequestProjection: __cacheabilityRequestProjection,
|
|
@@ -475,7 +475,7 @@ ${instrumentationPath ? `import * as _instrumentation from ${JSON.stringify(toSl
|
|
|
475
475
|
import { ensureInstrumentationRegistered as __ensureInstrumentationRegistered } from ${JSON.stringify(instrumentationRuntimePath)};` : ""}
|
|
476
476
|
${applicationInitializationCode}
|
|
477
477
|
${middlewarePath ? instrumentationPath ? "let middlewareModule;" : `import * as middlewareModule from ${JSON.stringify(toSlash(middlewarePath))};` : ""}
|
|
478
|
-
${responseStageOnly ? `import { renderAppWorkerResponseStage as __renderAppWorkerResponseStage } from ${JSON.stringify(appRscResponseStagePath)};` : `import { createAppRscHandler } from
|
|
478
|
+
${responseStageOnly ? `import { renderAppWorkerResponseStage as __renderAppWorkerResponseStage } from ${JSON.stringify(appRscResponseStagePath)};` : `import { createAppRscHandler } from "vinext/server/app-rsc-combined-handler";`}
|
|
479
479
|
import { registerConfiguredCacheAdapters as __registerConfiguredCacheAdapters } from "virtual:vinext-cache-adapters";
|
|
480
480
|
import __pagesClientAssets from "virtual:vinext-pages-client-assets";
|
|
481
481
|
${actionOwners === void 0 ? `import __vinextActionOwners from ${JSON.stringify(ACTION_OWNER_MANIFEST_ID)};` : ""}
|
|
@@ -952,6 +952,7 @@ ${rootParamNameEntries.join("\n")}
|
|
|
952
952
|
__setPagesClientAssets(__pagesClientAssets);
|
|
953
953
|
function __VINEXT_ACTION_OWNERS() { return ${actionOwners === void 0 ? "__vinextActionOwners" : safeJsonStringify(actionOwners)}; }
|
|
954
954
|
${responseStageOnly ? "const __responseStageOptions = {" : "const __appRscHandler = createAppRscHandler({"}
|
|
955
|
+
assetPrefix: __assetPrefix,
|
|
955
956
|
basePath: __basePath,
|
|
956
957
|
buildId: process.env.__VINEXT_BUILD_ID ?? null,
|
|
957
958
|
ensureRouteLoaded: __ensureRouteLoaded,
|