vinext 1.0.0-beta.0 → 1.0.0-beta.2
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 +21 -2
- package/dist/build/assets-ignore.js +1 -1
- package/dist/build/clean-output.js +1 -1
- package/dist/build/client-build-config.js +7 -4
- package/dist/build/css-url-assets.js +3 -3
- package/dist/build/google-fonts/fallback-metrics.js +1 -1
- package/dist/build/google-fonts/font-metadata.js +1 -1
- package/dist/build/inject-pregenerated-paths.js +1 -1
- package/dist/build/inline-css.js +2 -5
- package/dist/build/module-dependency-cache.d.ts +4 -0
- package/dist/build/module-dependency-cache.js +13 -0
- package/dist/build/next-client-runtime-manifests.js +1 -1
- package/dist/build/pages-client-assets-module.js +1 -1
- package/dist/build/precompress.js +7 -7
- package/dist/build/prerender-paths.d.ts +2 -2
- package/dist/build/prerender-paths.js +10 -15
- package/dist/build/prerender-server-pool.js +2 -2
- package/dist/build/prerender.js +1 -1
- package/dist/build/preview-credentials.d.ts +11 -0
- package/dist/build/preview-credentials.js +19 -0
- package/dist/build/report.d.ts +8 -4
- package/dist/build/report.js +14 -6
- package/dist/build/run-prerender.d.ts +2 -11
- package/dist/build/run-prerender.js +2 -10
- package/dist/build/server-manifest.js +1 -1
- package/dist/build/ssr-manifest.d.ts +4 -0
- package/dist/build/ssr-manifest.js +10 -6
- package/dist/build/standalone.js +37 -37
- package/dist/cache/cache-adapters-virtual.d.ts +1 -17
- package/dist/cache/cache-adapters-virtual.js +20 -11
- package/dist/check.d.ts +0 -16
- package/dist/check.js +27 -36
- package/dist/cli.js +61 -55
- package/dist/client/instrumentation-client-inject.js +1 -1
- package/dist/client/pages-router-link-navigation.js +1 -1
- package/dist/config/config-matchers.d.ts +13 -37
- package/dist/config/config-matchers.js +33 -123
- package/dist/config/dotenv.js +1 -1
- package/dist/config/next-config.d.ts +7 -3
- package/dist/config/next-config.js +84 -15
- package/dist/config/prerender.d.ts +2 -2
- package/dist/config/prerender.js +7 -15
- package/dist/config/request-context.d.ts +14 -0
- package/dist/config/request-context.js +26 -0
- package/dist/config/server-external-packages.js +1 -1
- package/dist/config/tsconfig-paths.js +2 -2
- package/dist/{node_modules/.pnpm/am-i-vibing@0.5.0/node_modules → deps/.pnpm/am-i-vibing@0.5.0/deps}/am-i-vibing/dist/detector-1yx2Hoe0.js +2 -2
- package/dist/deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js +50 -0
- package/dist/entries/app-rsc-entry.js +39 -14
- package/dist/entries/app-rsc-manifest.js +21 -4
- package/dist/entries/pages-client-entry.js +6 -5
- package/dist/entries/pages-server-entry.js +18 -28
- package/dist/entries/runtime-entry-module.js +2 -2
- package/dist/index.js +314 -230
- package/dist/init-cloudflare.js +1 -1
- package/dist/init-platform.js +1 -1
- package/dist/init.d.ts +6 -4
- package/dist/init.js +25 -27
- package/dist/plugins/ast-utils.js +1 -1
- package/dist/plugins/dynamic-preload-metadata.js +7 -7
- package/dist/plugins/extensionless-dynamic-import.js +1 -1
- package/dist/plugins/fonts.js +3 -3
- package/dist/plugins/ignore-dynamic-requests.js +13 -8
- package/dist/plugins/import-meta-url.js +16 -17
- package/dist/plugins/middleware-export-validation.js +1 -1
- package/dist/plugins/middleware-server-only.js +2 -2
- package/dist/plugins/og-asset-ownership.js +7 -6
- package/dist/plugins/og-assets.js +5 -6
- package/dist/plugins/optimize-imports.js +12 -13
- package/dist/plugins/postcss.js +1 -1
- package/dist/plugins/remove-console.js +1 -1
- package/dist/plugins/require-context.js +1 -1
- package/dist/plugins/sass.js +2 -2
- package/dist/plugins/server-externals-manifest.js +1 -1
- package/dist/plugins/strip-server-exports.js +1 -1
- package/dist/plugins/styled-jsx.js +3 -2
- package/dist/plugins/typeof-window.js +1 -1
- package/dist/routing/app-route-graph.d.ts +16 -15
- package/dist/routing/app-route-graph.js +86 -88
- package/dist/routing/app-router.d.ts +0 -5
- package/dist/routing/app-router.js +12 -11
- package/dist/routing/file-matcher.d.ts +13 -28
- package/dist/routing/file-matcher.js +31 -44
- package/dist/routing/pages-router.js +26 -32
- package/dist/routing/route-matching.d.ts +14 -1
- package/dist/routing/route-matching.js +13 -1
- package/dist/routing/route-pattern.d.ts +2 -1
- package/dist/routing/route-pattern.js +7 -4
- package/dist/routing/route-trie.d.ts +5 -1
- package/dist/routing/route-trie.js +5 -2
- package/dist/server/api-handler.js +41 -33
- package/dist/server/app-browser-entry.js +18 -11
- package/dist/server/app-browser-history-controller.d.ts +1 -1
- package/dist/server/app-browser-history-controller.js +3 -3
- package/dist/server/app-browser-navigation-controller.js +4 -2
- package/dist/server/app-browser-server-action-client.js +1 -1
- package/dist/server/app-elements-wire.d.ts +2 -1
- package/dist/server/app-fallback-renderer.d.ts +11 -0
- package/dist/server/app-fallback-renderer.js +16 -2
- package/dist/server/app-middleware.js +2 -1
- package/dist/server/app-page-boundary-render.d.ts +26 -2
- package/dist/server/app-page-boundary-render.js +190 -55
- package/dist/server/app-page-cache-finalizer.d.ts +1 -1
- package/dist/server/app-page-cache.d.ts +1 -1
- package/dist/server/app-page-dispatch.d.ts +12 -2
- package/dist/server/app-page-dispatch.js +37 -51
- package/dist/server/app-page-element-builder.d.ts +8 -2
- package/dist/server/app-page-element-builder.js +112 -27
- package/dist/server/app-page-execution.d.ts +3 -1
- package/dist/server/app-page-execution.js +31 -39
- package/dist/server/app-page-head.d.ts +54 -2
- package/dist/server/app-page-head.js +164 -78
- package/dist/server/app-page-http-access-fallback-metadata.d.ts +29 -0
- package/dist/server/app-page-http-access-fallback-metadata.js +106 -0
- package/dist/server/app-page-render.d.ts +2 -2
- package/dist/server/app-page-render.js +1 -1
- package/dist/server/app-page-request.d.ts +12 -0
- package/dist/server/app-page-request.js +134 -14
- package/dist/server/app-page-route-wiring.d.ts +9 -0
- package/dist/server/app-page-route-wiring.js +44 -4
- package/dist/server/app-post-middleware-context.d.ts +1 -1
- package/dist/server/app-post-middleware-context.js +1 -1
- package/dist/server/app-route-handler-dispatch.js +31 -17
- package/dist/server/app-route-handler-execution.d.ts +6 -1
- package/dist/server/app-route-handler-execution.js +41 -15
- package/dist/server/app-route-handler-policy.d.ts +2 -0
- package/dist/server/app-route-handler-policy.js +3 -3
- package/dist/server/app-route-module-loader.d.ts +3 -1
- package/dist/server/app-route-module-loader.js +1 -0
- package/dist/server/app-route-tree-prefetch.js +1 -1
- package/dist/server/app-rsc-cache-busting.d.ts +1 -1
- package/dist/server/app-rsc-cache-busting.js +1 -1
- package/dist/server/app-rsc-errors.d.ts +1 -1
- package/dist/server/app-rsc-errors.js +12 -2
- package/dist/server/app-rsc-handler.d.ts +10 -5
- package/dist/server/app-rsc-handler.js +51 -23
- package/dist/server/app-rsc-redirect-flight.d.ts +66 -0
- package/dist/server/app-rsc-redirect-flight.js +71 -0
- package/dist/server/app-rsc-request-normalization.d.ts +3 -2
- package/dist/server/app-rsc-request-normalization.js +8 -2
- package/dist/server/app-rsc-response-finalizer.d.ts +2 -2
- package/dist/server/app-rsc-response-finalizer.js +5 -11
- package/dist/server/app-rsc-route-matching.d.ts +20 -0
- package/dist/server/app-rsc-route-matching.js +87 -11
- package/dist/server/app-segment-config.js +15 -5
- package/dist/server/app-server-action-execution.d.ts +3 -1
- package/dist/server/app-server-action-execution.js +8 -6
- package/dist/server/app-ssr-entry.js +4 -1
- package/dist/server/app-ssr-stream.d.ts +2 -7
- package/dist/server/app-ssr-stream.js +5 -10
- package/dist/server/cache-proof.js +1 -1
- package/dist/server/config-headers.d.ts +24 -0
- package/dist/server/config-headers.js +52 -0
- package/dist/server/default-global-error-module.d.ts +3 -1
- package/dist/server/default-not-found-module.d.ts +3 -1
- package/dist/server/dev-initial-server-error.d.ts +1 -1
- package/dist/server/dev-lockfile.js +2 -3
- package/dist/server/dev-route-files.js +1 -1
- package/dist/server/dev-server.js +281 -173
- package/dist/server/dev-stack-sourcemap.js +4 -3
- package/dist/server/headers.d.ts +3 -1
- package/dist/server/headers.js +3 -1
- package/dist/server/image-optimization.js +2 -2
- package/dist/server/implicit-tags.js +2 -1
- package/dist/server/instrumentation.js +2 -2
- package/dist/server/isr-cache.d.ts +1 -1
- package/dist/server/isr-cache.js +1 -1
- package/dist/server/metadata-routes.js +4 -4
- package/dist/server/middleware-matcher-pattern.d.ts +22 -0
- package/dist/server/middleware-matcher-pattern.js +219 -0
- package/dist/server/middleware-matcher.d.ts +2 -7
- package/dist/server/middleware-matcher.js +13 -60
- package/dist/server/middleware-path-to-regexp.d.ts +14 -0
- package/dist/server/middleware-path-to-regexp.js +228 -0
- package/dist/server/middleware-response-headers.js +1 -1
- package/dist/server/middleware-runtime.js +5 -4
- package/dist/server/middleware.d.ts +2 -1
- package/dist/server/middleware.js +3 -2
- package/dist/server/navigation-planner.d.ts +2 -0
- package/dist/server/navigation-planner.js +8 -2
- package/dist/server/next-error-digest.d.ts +9 -24
- package/dist/server/next-error-digest.js +23 -15
- package/dist/server/operation-token.js +1 -1
- package/dist/server/pages-body-parser-config.js +2 -1
- package/dist/server/pages-data-route.d.ts +11 -1
- package/dist/server/pages-data-route.js +16 -1
- package/dist/server/pages-dev-hydration.d.ts +14 -0
- package/dist/server/pages-dev-hydration.js +83 -0
- package/dist/server/pages-dev-module-url.js +2 -2
- package/dist/server/pages-get-initial-props.d.ts +15 -2
- package/dist/server/pages-get-initial-props.js +16 -6
- package/dist/server/pages-node-compat.d.ts +13 -6
- package/dist/server/pages-node-compat.js +44 -45
- package/dist/server/pages-page-data.d.ts +4 -2
- package/dist/server/pages-page-data.js +20 -10
- package/dist/server/pages-page-handler.d.ts +4 -2
- package/dist/server/pages-page-handler.js +74 -43
- package/dist/server/pages-page-response.d.ts +2 -2
- package/dist/server/pages-page-response.js +1 -1
- package/dist/server/pages-preview.d.ts +26 -0
- package/dist/server/pages-preview.js +165 -0
- package/dist/server/pages-readiness.d.ts +5 -4
- package/dist/server/pages-readiness.js +4 -2
- package/dist/server/pages-request-pipeline.d.ts +1 -0
- package/dist/server/pages-request-pipeline.js +25 -11
- package/dist/server/pages-router-entry.js +6 -0
- package/dist/server/prerender-route-params.js +2 -2
- package/dist/server/prod-server.d.ts +1 -4
- package/dist/server/prod-server.js +44 -30
- package/dist/server/request-pipeline.d.ts +15 -29
- package/dist/server/request-pipeline.js +25 -60
- package/dist/server/rsc-stream-hints.js +122 -18
- package/dist/server/seed-cache.js +1 -1
- package/dist/server/socket-error-backstop.js +1 -1
- package/dist/server/static-file-cache.js +7 -8
- package/dist/server/worker-utils.js +1 -1
- package/dist/shims/app.d.ts +1 -1
- package/dist/shims/cache-request-state.d.ts +27 -1
- package/dist/shims/cache-request-state.js +60 -1
- package/dist/shims/cache-runtime.d.ts +12 -1
- package/dist/shims/cache-runtime.js +22 -7
- package/dist/shims/cache.d.ts +5 -5
- package/dist/shims/cache.js +28 -11
- package/dist/shims/constants.js +1 -1
- package/dist/shims/document.d.ts +42 -83
- package/dist/shims/document.js +62 -53
- package/dist/shims/dynamic.d.ts +5 -25
- package/dist/shims/dynamic.js +29 -8
- package/dist/shims/error-boundary.d.ts +4 -4
- package/dist/shims/error.d.ts +22 -6
- package/dist/shims/error.js +53 -15
- package/dist/shims/fetch-cache.js +13 -4
- package/dist/shims/font-google-base.d.ts +11 -4
- package/dist/shims/font-local.d.ts +10 -3
- package/dist/shims/font-utils.js +1 -1
- package/dist/shims/form.d.ts +1 -1
- package/dist/shims/head.d.ts +13 -2
- package/dist/shims/head.js +6 -6
- package/dist/shims/headers.d.ts +28 -31
- package/dist/shims/headers.js +115 -53
- package/dist/shims/image.d.ts +27 -37
- package/dist/shims/image.js +21 -14
- package/dist/shims/internal/cookie-serialize.d.ts +3 -1
- package/dist/shims/internal/cookie-serialize.js +3 -1
- package/dist/shims/internal/hybrid-client-route-owner.js +3 -1
- package/dist/shims/internal/pages-data-fetch-dedup.js +5 -3
- package/dist/shims/internal/utils.d.ts +3 -3
- package/dist/shims/layout-segment-context.d.ts +1 -1
- package/dist/shims/legacy-image.d.ts +3 -37
- package/dist/shims/legacy-image.js +6 -16
- package/dist/shims/link.d.ts +16 -21
- package/dist/shims/link.js +25 -13
- package/dist/shims/navigation-context-state.d.ts +1 -1
- package/dist/shims/navigation-errors.d.ts +2 -1
- package/dist/shims/navigation-errors.js +9 -13
- package/dist/shims/navigation.d.ts +8 -4
- package/dist/shims/navigation.js +29 -18
- package/dist/shims/next-shims-augmentations.d.ts +1 -0
- package/dist/shims/next-shims-public.d.ts +1 -0
- package/dist/shims/public-shim-map.json.js +103 -0
- package/dist/shims/readonly-url-search-params.d.ts +3 -3
- package/dist/shims/readonly-url-search-params.js +3 -3
- package/dist/shims/request-state-types.d.ts +1 -1
- package/dist/shims/router-state.d.ts +1 -0
- package/dist/shims/router.d.ts +57 -22
- package/dist/shims/router.js +178 -46
- package/dist/shims/script.d.ts +6 -10
- package/dist/shims/script.js +7 -4
- package/dist/shims/server.d.ts +45 -22
- package/dist/shims/server.js +46 -7
- package/dist/shims/slot.d.ts +1 -1
- package/dist/shims/thenable-params.js +1 -1
- package/dist/shims/unified-request-context.d.ts +1 -1
- package/dist/shims/unified-request-context.js +2 -0
- package/dist/shims/url-safety.d.ts +1 -1
- package/dist/shims/url-safety.js +2 -2
- package/dist/typegen.d.ts +8 -2
- package/dist/typegen.js +84 -25
- package/dist/utils/client-build-manifest.js +2 -2
- package/dist/utils/client-entry-manifest.js +1 -1
- package/dist/utils/client-runtime-metadata.js +1 -1
- package/dist/utils/commonjs-loader.js +3 -3
- package/dist/utils/domain-locale.d.ts +2 -2
- package/dist/utils/external-url.d.ts +5 -0
- package/dist/utils/external-url.js +7 -0
- package/dist/utils/mdx-scan.js +1 -1
- package/dist/utils/path.d.ts +1 -13
- package/dist/utils/path.js +1 -15
- package/dist/utils/plugin-options.d.ts +4 -0
- package/dist/utils/plugin-options.js +8 -0
- package/dist/utils/project.d.ts +0 -6
- package/dist/utils/project.js +2 -8
- package/dist/utils/public-routes.js +2 -2
- package/dist/utils/react-version.js +1 -1
- package/dist/utils/redirect-digest.d.ts +9 -0
- package/dist/utils/redirect-digest.js +25 -0
- package/dist/utils/regex-safety.d.ts +8 -0
- package/dist/utils/regex-safety.js +737 -0
- package/dist/utils/vinext-root.js +1 -1
- package/dist/utils/vite-version.d.ts +5 -2
- package/dist/utils/vite-version.js +43 -17
- package/package.json +16 -4
- /package/dist/build/google-fonts/{fallback-metrics-data.js → fallback-metrics-data.json.js} +0 -0
- /package/dist/build/google-fonts/{font-data.js → font-data.json.js} +0 -0
- /package/dist/{node_modules/.pnpm/process-ancestry@0.1.0/node_modules → deps/.pnpm/process-ancestry@0.1.0/deps}/process-ancestry/dist/index.js +0 -0
package/README.md
CHANGED
|
@@ -32,7 +32,23 @@ Run `vinext check` against an existing application before migrating. If a gap is
|
|
|
32
32
|
|
|
33
33
|
## Quick start
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
**Use the official setup commands below.** They are the recommended way to create or migrate a vinext project because they configure dependencies, scripts, Vite, and your deployment target for you.
|
|
36
|
+
|
|
37
|
+
Start a new project with `create-vinext-app`:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pnpm create vinext-app@latest my-app
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Migrate an existing Next.js project with `vinext init`:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npx vinext init
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Optional: migrate with an AI agent
|
|
50
|
+
|
|
51
|
+
Prefer `vinext init` for a direct, repeatable migration. If you want an AI agent to investigate compatibility issues and guide the migration, vinext also includes an optional [Agent Skill](https://agentskills.io/home). It works with Claude Code, OpenCode, Cursor, Codex, and dozens of other AI coding tools:
|
|
36
52
|
|
|
37
53
|
```sh
|
|
38
54
|
npx skills add cloudflare/vinext
|
|
@@ -190,7 +206,10 @@ vinext works everywhere. It natively supports Cloudflare Workers (with `npx @vin
|
|
|
190
206
|
vinext is a Vite plugin that reimplements the public Next.js API — routing, server rendering, `next/*` module imports, the CLI — so you can run Next.js applications on Vite instead of the Next.js compiler toolchain. It can be deployed anywhere: Cloudflare Workers is the first natively supported target, with other platforms available via Nitro. Native adapters for more platforms are [planned](https://github.com/cloudflare/vinext/issues/80).
|
|
191
207
|
|
|
192
208
|
**Is this a fork of Next.js?**
|
|
193
|
-
No. vinext is an alternative implementation of the Next.js API surface built on Vite.
|
|
209
|
+
No. vinext is an alternative implementation of the Next.js API surface built on Vite. The core is written from scratch. The goal is not to create a competing framework or add features beyond what Next.js offers; it is to provide the same well-defined API surface on Vite's toolchain.
|
|
210
|
+
|
|
211
|
+
**Does vinext require Next.js to be installed?**
|
|
212
|
+
No. vinext ships fallback declarations for the supported `next` and `next/*` APIs, so applications can run and type-check without the `next` package. If both packages are installed, vinext keeps using Next.js's authoritative types and adds only its own extensions. Compatibility features that consume Next.js internals, such as `styled-jsx`, may still require a matching Next.js installation when used.
|
|
194
213
|
|
|
195
214
|
**How is this different from OpenNext?**
|
|
196
215
|
[OpenNext](https://opennext.js.org/) adapts the _output_ of a standard `next build` to run on various platforms. Because it builds on Next.js's own output, it inherits broad API coverage and has been well-tested for much longer. vinext takes a different approach: it reimplements the Next.js APIs on Vite from scratch, which means faster builds and smaller bundles, but less coverage of the long tail of Next.js features. If you need a mature, well-tested way to run Next.js outside Vercel, OpenNext is the safer choice. If you want a lighter Vite-based toolchain and do not need every Next.js API, vinext may be a good fit.
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { toSlash } from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
1
2
|
//#region src/build/client-build-config.ts
|
|
2
|
-
const ROUTE_OWNED_CLIENT_SHIMS = new Set([
|
|
3
|
+
const ROUTE_OWNED_CLIENT_SHIMS = /* @__PURE__ */ new Set([
|
|
3
4
|
"compat-router",
|
|
4
5
|
"dynamic",
|
|
5
6
|
"dynamic-preload-chunks",
|
|
6
7
|
"form",
|
|
7
8
|
"image",
|
|
9
|
+
"internal/hybrid-client-route-owner",
|
|
8
10
|
"layout-segment-context",
|
|
9
11
|
"legacy-image",
|
|
10
12
|
"link",
|
|
@@ -47,7 +49,7 @@ function createClientAssetFileNames(assetsDir) {
|
|
|
47
49
|
* (node_modules/.pnpm/pkg@ver/node_modules/pkg).
|
|
48
50
|
*/
|
|
49
51
|
function getPackageName(id) {
|
|
50
|
-
const normalizedId = id
|
|
52
|
+
const normalizedId = toSlash(id);
|
|
51
53
|
const nmIdx = normalizedId.lastIndexOf("node_modules/");
|
|
52
54
|
if (nmIdx === -1) return null;
|
|
53
55
|
const rest = normalizedId.slice(nmIdx + 13);
|
|
@@ -90,9 +92,10 @@ function createClientManualChunks(shimsDir, preserveRouteBoundaries = false) {
|
|
|
90
92
|
if (pkg === "react" || pkg === "react-dom" || pkg === "scheduler") return "framework";
|
|
91
93
|
return;
|
|
92
94
|
}
|
|
93
|
-
|
|
95
|
+
const slashedId = toSlash(id);
|
|
96
|
+
if (slashedId.startsWith(shimsDir)) {
|
|
94
97
|
if (preserveRouteBoundaries) {
|
|
95
|
-
const relativeId =
|
|
98
|
+
const relativeId = slashedId.slice(shimsDir.length).split("?", 1)[0] ?? "";
|
|
96
99
|
const extensionIndex = relativeId.lastIndexOf(".");
|
|
97
100
|
const shimName = extensionIndex === -1 ? relativeId : relativeId.slice(0, extensionIndex);
|
|
98
101
|
if (ROUTE_OWNED_CLIENT_SHIMS.has(shimName)) return void 0;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import path from "
|
|
1
|
+
import path, { toSlash } from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
2
2
|
//#region src/build/css-url-assets.ts
|
|
3
3
|
/**
|
|
4
4
|
* Next-parity for CSS `url()` asset dependencies.
|
|
@@ -35,7 +35,7 @@ const CSS_URL_RE = /url\(\s*(?:"([^"]*)"|'([^']*)'|([^'")]*?))\s*\)/g;
|
|
|
35
35
|
const CSS_ASSET_EXT_RE = /\.(?:avif|bmp|gif|ico|jpe?g|png|svg|webp|woff2?|eot|ttf|otf|mp4|webm|ogg|mp3|wav|flac|aac|wasm)$/i;
|
|
36
36
|
const CSS_REQUEST_RE = /\.(?:css|scss|sass|less|styl|stylus)(?:\?|$)/i;
|
|
37
37
|
function basename(value) {
|
|
38
|
-
const normalized = value
|
|
38
|
+
const normalized = toSlash(value);
|
|
39
39
|
const slash = normalized.lastIndexOf("/");
|
|
40
40
|
return slash === -1 ? normalized : normalized.slice(slash + 1);
|
|
41
41
|
}
|
|
@@ -137,7 +137,7 @@ function rebaseCssUrlAssetReferences(code, sourceDirectory, targetDirectory) {
|
|
|
137
137
|
const lower = parts.path.toLowerCase();
|
|
138
138
|
if (!CSS_ASSET_EXT_RE.test(lower) || lower.endsWith(".css")) return null;
|
|
139
139
|
const absolutePath = path.resolve(sourceDirectory, parts.path);
|
|
140
|
-
let rebasedPath = path.relative(targetDirectory, absolutePath)
|
|
140
|
+
let rebasedPath = path.relative(targetDirectory, absolutePath);
|
|
141
141
|
if (!rebasedPath.startsWith(".")) rebasedPath = `./${rebasedPath}`;
|
|
142
142
|
return joinUrl({
|
|
143
143
|
...parts,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { escapeCSSString } from "../../shims/font-utils.js";
|
|
2
|
-
import fallback_metrics_data_default from "./fallback-metrics-data.js";
|
|
2
|
+
import fallback_metrics_data_default from "./fallback-metrics-data.json.js";
|
|
3
3
|
//#region src/build/google-fonts/fallback-metrics.ts
|
|
4
4
|
const EXPECTED_METRIC_LENGTH = 6;
|
|
5
5
|
const fallbackMetrics = fallback_metrics_data_default;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import path from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
1
2
|
import { escapeRegExp } from "../utils/regex.js";
|
|
2
3
|
import { readPrerenderManifest } from "../server/prerender-manifest.js";
|
|
3
4
|
import fs from "node:fs";
|
|
4
|
-
import path from "node:path";
|
|
5
5
|
//#region src/build/inject-pregenerated-paths.ts
|
|
6
6
|
const VINEXT_PREGEN_START = "/* __VINEXT_PREGENERATED_CONCRETE_PATHS_START__ */";
|
|
7
7
|
const VINEXT_PREGEN_END = "/* __VINEXT_PREGENERATED_CONCRETE_PATHS_END__ */";
|
package/dist/build/inline-css.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import path from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
1
2
|
import { resolveAssetUrlPrefix, resolveAssetsDir } from "../utils/asset-prefix.js";
|
|
2
3
|
import fs from "node:fs";
|
|
3
|
-
import path from "node:path";
|
|
4
4
|
//#region src/build/inline-css.ts
|
|
5
5
|
const INLINE_CSS_GLOBAL_MARKER = "globalThis.__VINEXT_INLINE_CSS__ = ";
|
|
6
6
|
function collectCssFiles(directory) {
|
|
@@ -12,9 +12,6 @@ function collectCssFiles(directory) {
|
|
|
12
12
|
}
|
|
13
13
|
return files;
|
|
14
14
|
}
|
|
15
|
-
function toUrlPath(filePath) {
|
|
16
|
-
return filePath.split(path.sep).join("/");
|
|
17
|
-
}
|
|
18
15
|
function addPathnameAlias(manifest, href, css) {
|
|
19
16
|
try {
|
|
20
17
|
const url = new URL(href);
|
|
@@ -27,7 +24,7 @@ function collectInlineCssManifest(clientDir, assetPrefix) {
|
|
|
27
24
|
const urlPrefix = resolveAssetUrlPrefix(assetPrefix);
|
|
28
25
|
const manifest = {};
|
|
29
26
|
for (const filePath of collectCssFiles(assetsDir)) {
|
|
30
|
-
const href = `${urlPrefix}${
|
|
27
|
+
const href = `${urlPrefix}${path.relative(assetsDir, filePath)}`;
|
|
31
28
|
const css = fs.readFileSync(filePath, "utf8");
|
|
32
29
|
manifest[href] = css;
|
|
33
30
|
addPathnameAlias(manifest, href, css);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/build/module-dependency-cache.ts
|
|
2
|
+
function createModuleDependencyCache(collect) {
|
|
3
|
+
const cache = /* @__PURE__ */ new Map();
|
|
4
|
+
return function getModuleDependencies(moduleId) {
|
|
5
|
+
const cached = cache.get(moduleId);
|
|
6
|
+
if (cached) return cached;
|
|
7
|
+
const pending = collect(moduleId);
|
|
8
|
+
cache.set(moduleId, pending);
|
|
9
|
+
return pending;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { createModuleDependencyCache };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import path from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
1
2
|
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
3
|
//#region src/build/next-client-runtime-manifests.ts
|
|
4
4
|
function normalizeRewriteForClientManifest(rewrite) {
|
|
5
5
|
if (rewrite.destination.startsWith("/")) return {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import path from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
1
2
|
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
3
|
//#region src/build/pages-client-assets-module.ts
|
|
4
4
|
const PAGES_CLIENT_ASSETS_MODULE = "vinext-client-assets.js";
|
|
5
5
|
const pagesClientAssetsByBuildSession = /* @__PURE__ */ new Map();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import path from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
1
2
|
import { ASSET_PREFIX_URL_DIR } from "../utils/asset-prefix.js";
|
|
2
|
-
import
|
|
3
|
-
import fs from "node:fs/promises";
|
|
3
|
+
import fsp from "node:fs/promises";
|
|
4
4
|
import os from "node:os";
|
|
5
5
|
import zlib from "node:zlib";
|
|
6
6
|
import { promisify } from "node:util";
|
|
@@ -20,7 +20,7 @@ const brotliCompress = promisify(zlib.brotliCompress);
|
|
|
20
20
|
const gzip = promisify(zlib.gzip);
|
|
21
21
|
const zstdCompress = typeof zlib.zstdCompress === "function" ? promisify(zlib.zstdCompress) : null;
|
|
22
22
|
/** File extensions worth compressing (text-based, not already compressed). */
|
|
23
|
-
const COMPRESSIBLE_EXTENSIONS = new Set([
|
|
23
|
+
const COMPRESSIBLE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
24
24
|
".js",
|
|
25
25
|
".mjs",
|
|
26
26
|
".css",
|
|
@@ -46,7 +46,7 @@ const CONCURRENCY = Math.min(os.availableParallelism(), 8);
|
|
|
46
46
|
async function* walkFiles(dir, base = dir) {
|
|
47
47
|
let entries;
|
|
48
48
|
try {
|
|
49
|
-
entries = await
|
|
49
|
+
entries = await fsp.readdir(dir, { withFileTypes: true });
|
|
50
50
|
} catch {
|
|
51
51
|
return;
|
|
52
52
|
}
|
|
@@ -89,13 +89,13 @@ async function precompressAssets(clientDir, options = {}) {
|
|
|
89
89
|
for (let i = 0; i < filePaths.length; i += CONCURRENCY) {
|
|
90
90
|
const chunk = filePaths.slice(i, i + CONCURRENCY);
|
|
91
91
|
await Promise.all(chunk.map(async (fullPath) => {
|
|
92
|
-
const content = await
|
|
92
|
+
const content = await fsp.readFile(fullPath);
|
|
93
93
|
if (content.length < MIN_SIZE) return;
|
|
94
94
|
const compressions = [brotliCompress(content, { params: { [zlib.constants.BROTLI_PARAM_QUALITY]: 5 } }), gzip(content, { level: 8 })];
|
|
95
95
|
if (zstdCompress) compressions.push(zstdCompress(content, { params: { [zlib.constants.ZSTD_c_compressionLevel]: 8 } }));
|
|
96
96
|
const [brContent, gzContent, zstdContent] = await Promise.all(compressions);
|
|
97
|
-
const writes = [
|
|
98
|
-
if (zstdContent) writes.push(
|
|
97
|
+
const writes = [fsp.writeFile(fullPath + ".br", brContent), fsp.writeFile(fullPath + ".gz", gzContent)];
|
|
98
|
+
if (zstdContent) writes.push(fsp.writeFile(fullPath + ".zst", zstdContent));
|
|
99
99
|
await Promise.all(writes);
|
|
100
100
|
result.filesCompressed++;
|
|
101
101
|
result.totalOriginalBytes += content.length;
|
|
@@ -10,8 +10,8 @@ type PrerenderPathManifest = {
|
|
|
10
10
|
declare const PRERENDER_PATH_DISCOVERY_ENV = "__VINEXT_PRERENDER_PATH_DISCOVERY";
|
|
11
11
|
declare const PRERENDER_PATHS_MANIFEST = "vinext-prerender-paths.json";
|
|
12
12
|
type EmitPrerenderPathManifestOptions = {
|
|
13
|
-
root: string;
|
|
14
|
-
|
|
13
|
+
root: string; /** Fully resolved Next.js config. Loaded from disk when omitted. */
|
|
14
|
+
nextConfig?: ResolvedNextConfig;
|
|
15
15
|
appDir?: string | null;
|
|
16
16
|
pagesDir?: string | null;
|
|
17
17
|
routeRootConfig?: VinextRouteRootConfig | null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import path, { toSlash } from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
1
2
|
import { findDir } from "../utils/project.js";
|
|
2
|
-
import { normalizePathSeparators } from "../utils/path.js";
|
|
3
3
|
import { apiRouter, pagesRouter } from "../routing/pages-router.js";
|
|
4
4
|
import { VINEXT_PRERENDER_SECRET_HEADER } from "../utils/protocol-headers.js";
|
|
5
5
|
import { classifyAppRoute, classifyPagesRoute, getAppRouteRenderEntryPath, hasNamedExport } from "./report.js";
|
|
@@ -11,7 +11,6 @@ import { readPrerenderSecret } from "./server-manifest.js";
|
|
|
11
11
|
import { startProdServer } from "../server/prod-server.js";
|
|
12
12
|
import { buildUrlFromParams, resolveParentParams } from "./prerender.js";
|
|
13
13
|
import fs from "node:fs";
|
|
14
|
-
import path from "node:path";
|
|
15
14
|
//#region src/build/prerender-paths.ts
|
|
16
15
|
const PRERENDER_PATH_DISCOVERY_ENV = "__VINEXT_PRERENDER_PATH_DISCOVERY";
|
|
17
16
|
const PRERENDER_PATHS_MANIFEST = "vinext-prerender-paths.json";
|
|
@@ -68,16 +67,16 @@ function resolveConfiguredRouteDirs(root, routeRootConfig) {
|
|
|
68
67
|
let baseDir;
|
|
69
68
|
if (routeRootConfig.appDir) {
|
|
70
69
|
baseDir = path.isAbsolute(routeRootConfig.appDir) ? routeRootConfig.appDir : path.resolve(root, routeRootConfig.appDir);
|
|
71
|
-
baseDir =
|
|
70
|
+
baseDir = toSlash(baseDir);
|
|
72
71
|
} else {
|
|
73
|
-
const hasRootApp = fs.existsSync(path.
|
|
74
|
-
const hasRootPages = fs.existsSync(path.
|
|
75
|
-
const hasSrcApp = fs.existsSync(path.
|
|
76
|
-
const hasSrcPages = fs.existsSync(path.
|
|
77
|
-
baseDir = hasRootApp || hasRootPages ? root : hasSrcApp || hasSrcPages ? path.
|
|
72
|
+
const hasRootApp = fs.existsSync(path.join(root, "app"));
|
|
73
|
+
const hasRootPages = fs.existsSync(path.join(root, "pages"));
|
|
74
|
+
const hasSrcApp = fs.existsSync(path.join(root, "src", "app"));
|
|
75
|
+
const hasSrcPages = fs.existsSync(path.join(root, "src", "pages"));
|
|
76
|
+
baseDir = hasRootApp || hasRootPages ? root : hasSrcApp || hasSrcPages ? path.join(root, "src") : root;
|
|
78
77
|
}
|
|
79
|
-
const appDir = path.
|
|
80
|
-
const pagesDir = path.
|
|
78
|
+
const appDir = path.join(baseDir, "app");
|
|
79
|
+
const pagesDir = path.join(baseDir, "pages");
|
|
81
80
|
return {
|
|
82
81
|
appDir: !routeRootConfig.disableAppRouter && fs.existsSync(appDir) ? appDir : null,
|
|
83
82
|
pagesDir: fs.existsSync(pagesDir) ? pagesDir : null
|
|
@@ -237,11 +236,7 @@ async function emitPrerenderPathManifest(options) {
|
|
|
237
236
|
const pagesBundlePath = options.pagesBundlePath ?? path.join(root, "dist", "server", "entry.js");
|
|
238
237
|
const bundleServerDir = fs.existsSync(rscBundlePath) ? path.dirname(rscBundlePath) : path.dirname(pagesBundlePath);
|
|
239
238
|
const manifestDir = path.join(root, "dist", "server");
|
|
240
|
-
const
|
|
241
|
-
const config = options.nextConfigOverride ? {
|
|
242
|
-
...loadedConfig,
|
|
243
|
-
...options.nextConfigOverride
|
|
244
|
-
} : { ...loadedConfig };
|
|
239
|
+
const config = options.nextConfig ? { ...options.nextConfig } : { ...await resolveNextConfig(await loadNextConfig(root, PHASE_PRODUCTION_BUILD), root) };
|
|
245
240
|
const builtBuildId = readBuiltBuildId(manifestDir) ?? readBuiltBuildId(bundleServerDir);
|
|
246
241
|
if (builtBuildId) config.buildId = builtBuildId;
|
|
247
242
|
const paths = [];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import path from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
1
2
|
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
import os from "node:os";
|
|
5
5
|
import { fork } from "node:child_process";
|
|
@@ -50,7 +50,7 @@ const APPROX_BYTES_PER_WORKER = 768 * 1024 * 1024;
|
|
|
50
50
|
const WORKER_READY_TIMEOUT_MS = 6e4;
|
|
51
51
|
/** Best-effort close timeout so build cleanup is not blocked forever by a wedged child. */
|
|
52
52
|
const WORKER_CLOSE_TIMEOUT_MS = 5e3;
|
|
53
|
-
const PRERENDER_WORKER_TRANSPORT_ERROR_CODES = new Set([
|
|
53
|
+
const PRERENDER_WORKER_TRANSPORT_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
54
54
|
"ECONNREFUSED",
|
|
55
55
|
"ECONNRESET",
|
|
56
56
|
"EPIPE",
|
package/dist/build/prerender.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import path from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
1
2
|
import { createValidFileMatcher, findFileWithExtensions } from "../routing/file-matcher.js";
|
|
2
3
|
import { VINEXT_PRERENDER_ROUTE_PARAMS_HEADER, VINEXT_PRERENDER_SECRET_HEADER, VINEXT_PRERENDER_SPECULATIVE_HEADER } from "../utils/protocol-headers.js";
|
|
3
4
|
import { VINEXT_PRERENDER_CACHE_LIFE_HEADER } from "../server/headers.js";
|
|
@@ -17,7 +18,6 @@ import { getOutputPath, getRscOutputPath } from "../utils/prerender-output-paths
|
|
|
17
18
|
import { startProdServer } from "../server/prod-server.js";
|
|
18
19
|
import { prerenderPoolAvailable, resolvePrerenderPoolSize, startPrerenderServerPool } from "./prerender-server-pool.js";
|
|
19
20
|
import fs from "node:fs";
|
|
20
|
-
import path from "node:path";
|
|
21
21
|
import os from "node:os";
|
|
22
22
|
//#region src/build/prerender.ts
|
|
23
23
|
/**
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/build/preview-credentials.d.ts
|
|
2
|
+
type PreviewBuildCredentials = {
|
|
3
|
+
id: string;
|
|
4
|
+
signingKey: string;
|
|
5
|
+
encryptionKey: string;
|
|
6
|
+
};
|
|
7
|
+
declare function createPreviewBuildCredentials(): PreviewBuildCredentials;
|
|
8
|
+
declare function getPreviewBuildCredentials(): PreviewBuildCredentials | undefined;
|
|
9
|
+
declare function runWithPreviewBuildCredentials<T>(callback: () => T): T;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { PreviewBuildCredentials, createPreviewBuildCredentials, getPreviewBuildCredentials, runWithPreviewBuildCredentials };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { randomBytes } from "node:crypto";
|
|
3
|
+
//#region src/build/preview-credentials.ts
|
|
4
|
+
const previewBuildCredentialsStorage = new AsyncLocalStorage();
|
|
5
|
+
function createPreviewBuildCredentials() {
|
|
6
|
+
return {
|
|
7
|
+
id: randomBytes(16).toString("hex"),
|
|
8
|
+
signingKey: randomBytes(32).toString("hex"),
|
|
9
|
+
encryptionKey: randomBytes(32).toString("hex")
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function getPreviewBuildCredentials() {
|
|
13
|
+
return previewBuildCredentialsStorage.getStore();
|
|
14
|
+
}
|
|
15
|
+
function runWithPreviewBuildCredentials(callback) {
|
|
16
|
+
return previewBuildCredentialsStorage.run(createPreviewBuildCredentials(), callback);
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { createPreviewBuildCredentials, getPreviewBuildCredentials, runWithPreviewBuildCredentials };
|
package/dist/build/report.d.ts
CHANGED
|
@@ -44,6 +44,13 @@ declare function hasExportedName(code: string, name: string): boolean;
|
|
|
44
44
|
*/
|
|
45
45
|
declare function extractExportConstString(code: string, name: string): string | null;
|
|
46
46
|
declare function extractMiddlewareMatcherConfig(filePath: string): StaticMiddlewareMatcher | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Extract the statically analyzable `config.matcher` value without first
|
|
49
|
+
* narrowing it to vinext's runtime matcher type. Build validation needs the
|
|
50
|
+
* raw value so malformed matcher objects are rejected instead of disappearing
|
|
51
|
+
* as though no matcher had been configured.
|
|
52
|
+
*/
|
|
53
|
+
declare function extractMiddlewareMatcherConfigValue(filePath: string): unknown;
|
|
47
54
|
/**
|
|
48
55
|
* Extracts the numeric value of `export const <name> = <number|false>`.
|
|
49
56
|
* Supports integers, decimals, negative values, `Infinity`, and `false`.
|
|
@@ -130,9 +137,6 @@ declare function formatBuildReport(rows: RouteRow[], routerLabel?: string): stri
|
|
|
130
137
|
/**
|
|
131
138
|
* Scans the project at `root`, classifies all routes, and prints the
|
|
132
139
|
* Next.js-style build report to stdout.
|
|
133
|
-
*
|
|
134
|
-
* `root` must be forward-slash — it is passed to `findDir`. The caller (the
|
|
135
|
-
* `vinext build` entry in cli.ts) normalizes it.
|
|
136
140
|
*/
|
|
137
141
|
declare function printBuildReport(options: {
|
|
138
142
|
root: string;
|
|
@@ -140,4 +144,4 @@ declare function printBuildReport(options: {
|
|
|
140
144
|
prerenderResult?: PrerenderResult;
|
|
141
145
|
}): Promise<void>;
|
|
142
146
|
//#endregion
|
|
143
|
-
export { RouteRow, RouteType, StaticMiddlewareMatcher, buildReportRows, classifyAppRoute, classifyLayoutSegmentConfig, classifyPagesRoute, extractExportConstNumber, extractExportConstString, extractGetStaticPropsRevalidate, extractMiddlewareMatcherConfig, formatBuildReport, getAppRouteRenderEntryPath, hasExportedName, hasNamedExport, printBuildReport };
|
|
147
|
+
export { RouteRow, RouteType, StaticMiddlewareMatcher, buildReportRows, classifyAppRoute, classifyLayoutSegmentConfig, classifyPagesRoute, extractExportConstNumber, extractExportConstString, extractGetStaticPropsRevalidate, extractMiddlewareMatcherConfig, extractMiddlewareMatcherConfigValue, formatBuildReport, getAppRouteRenderEntryPath, hasExportedName, hasNamedExport, printBuildReport };
|
package/dist/build/report.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { toSlash } from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
1
2
|
import { findDir } from "../utils/project.js";
|
|
2
3
|
import fs from "node:fs";
|
|
3
4
|
import { parseSync } from "vite";
|
|
@@ -134,6 +135,16 @@ function extractStringFromConstInitializer(initializer) {
|
|
|
134
135
|
return null;
|
|
135
136
|
}
|
|
136
137
|
function extractMiddlewareMatcherConfig(filePath) {
|
|
138
|
+
const value = extractMiddlewareMatcherConfigValue(filePath);
|
|
139
|
+
return isStaticMiddlewareMatcher(value) ? value : void 0;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Extract the statically analyzable `config.matcher` value without first
|
|
143
|
+
* narrowing it to vinext's runtime matcher type. Build validation needs the
|
|
144
|
+
* raw value so malformed matcher objects are rejected instead of disappearing
|
|
145
|
+
* as though no matcher had been configured.
|
|
146
|
+
*/
|
|
147
|
+
function extractMiddlewareMatcherConfigValue(filePath) {
|
|
137
148
|
let code;
|
|
138
149
|
try {
|
|
139
150
|
code = fs.readFileSync(filePath, "utf8");
|
|
@@ -147,7 +158,7 @@ function extractMiddlewareMatcherConfig(filePath) {
|
|
|
147
158
|
const matcherExpression = objectPropertyValue(config, "matcher");
|
|
148
159
|
if (!matcherExpression) return void 0;
|
|
149
160
|
const value = extractStaticJsonValue(matcherExpression);
|
|
150
|
-
return
|
|
161
|
+
return value === UNSUPPORTED_STATIC_VALUE ? void 0 : value;
|
|
151
162
|
}
|
|
152
163
|
function objectPropertyValue(object, key) {
|
|
153
164
|
for (const property of object.properties) {
|
|
@@ -415,7 +426,7 @@ function classifyLayoutSegmentConfig(code) {
|
|
|
415
426
|
* API routes (files under pages/api/) are always `api`.
|
|
416
427
|
*/
|
|
417
428
|
function classifyPagesRoute(filePath) {
|
|
418
|
-
if (filePath
|
|
429
|
+
if (toSlash(filePath).includes("/pages/api/")) return { type: "api" };
|
|
419
430
|
let code;
|
|
420
431
|
try {
|
|
421
432
|
code = fs.readFileSync(filePath, "utf8");
|
|
@@ -569,9 +580,6 @@ function formatBuildReport(rows, routerLabel = "app") {
|
|
|
569
580
|
/**
|
|
570
581
|
* Scans the project at `root`, classifies all routes, and prints the
|
|
571
582
|
* Next.js-style build report to stdout.
|
|
572
|
-
*
|
|
573
|
-
* `root` must be forward-slash — it is passed to `findDir`. The caller (the
|
|
574
|
-
* `vinext build` entry in cli.ts) normalizes it.
|
|
575
583
|
*/
|
|
576
584
|
async function printBuildReport(options) {
|
|
577
585
|
const { root } = options;
|
|
@@ -598,4 +606,4 @@ async function printBuildReport(options) {
|
|
|
598
606
|
}
|
|
599
607
|
}
|
|
600
608
|
//#endregion
|
|
601
|
-
export { buildReportRows, classifyAppRoute, classifyLayoutSegmentConfig, classifyPagesRoute, extractExportConstNumber, extractExportConstString, extractGetStaticPropsRevalidate, extractMiddlewareMatcherConfig, formatBuildReport, getAppRouteRenderEntryPath, hasExportedName, hasNamedExport, printBuildReport };
|
|
609
|
+
export { buildReportRows, classifyAppRoute, classifyLayoutSegmentConfig, classifyPagesRoute, extractExportConstNumber, extractExportConstString, extractGetStaticPropsRevalidate, extractMiddlewareMatcherConfig, extractMiddlewareMatcherConfigValue, formatBuildReport, getAppRouteRenderEntryPath, hasExportedName, hasNamedExport, printBuildReport };
|
|
@@ -3,13 +3,8 @@ import { PrerenderResult, PrerenderRouteResult } from "./prerender.js";
|
|
|
3
3
|
|
|
4
4
|
//#region src/build/run-prerender.d.ts
|
|
5
5
|
type RunPrerenderOptions = {
|
|
6
|
-
/** Project root directory. */root: string;
|
|
7
|
-
|
|
8
|
-
* Override next.config values. Merged on top of the config loaded from disk.
|
|
9
|
-
* Intended for tests that need to exercise a specific config (e.g. output: 'export')
|
|
10
|
-
* without writing a next.config file.
|
|
11
|
-
*/
|
|
12
|
-
nextConfigOverride?: Partial<ResolvedNextConfig>;
|
|
6
|
+
/** Project root directory. */root: string; /** Fully resolved Next.js config. Loaded from disk when omitted. */
|
|
7
|
+
nextConfig?: ResolvedNextConfig;
|
|
13
8
|
/**
|
|
14
9
|
* Override the path to the Pages Router server bundle.
|
|
15
10
|
* Defaults to `<root>/dist/server/entry.js`.
|
|
@@ -58,10 +53,6 @@ type RunPrerenderOptions = {
|
|
|
58
53
|
declare function assertNoFatalPrerenderRoutes(routes: readonly PrerenderRouteResult[]): void;
|
|
59
54
|
/**
|
|
60
55
|
* Statically generate routes and return the prerender result.
|
|
61
|
-
*
|
|
62
|
-
* `options.root` must be forward-slash — it is passed to `findDir` and flows
|
|
63
|
-
* into the route model. The caller (the `vinext build` entry in cli.ts)
|
|
64
|
-
* normalizes it.
|
|
65
56
|
*/
|
|
66
57
|
declare function runPrerender(options: RunPrerenderOptions): Promise<PrerenderResult | null>;
|
|
67
58
|
//#endregion
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import path from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
1
2
|
import { findDir } from "../utils/project.js";
|
|
2
3
|
import { apiRouter, pagesRouter } from "../routing/pages-router.js";
|
|
3
4
|
import { appRouter } from "../routing/app-router.js";
|
|
@@ -8,7 +9,6 @@ import { rememberCurrentServerEntryImportMtime, startProdServer } from "../serve
|
|
|
8
9
|
import { prerenderApp, prerenderPages, writePrerenderIndex } from "./prerender.js";
|
|
9
10
|
import { injectPregeneratedConcretePaths } from "./inject-pregenerated-paths.js";
|
|
10
11
|
import fs from "node:fs";
|
|
11
|
-
import path from "node:path";
|
|
12
12
|
//#region src/build/run-prerender.ts
|
|
13
13
|
/**
|
|
14
14
|
* Shared prerender runner used by both `vinext build` (cli.ts) and
|
|
@@ -98,10 +98,6 @@ function assertNoFatalPrerenderRoutes(routes) {
|
|
|
98
98
|
}
|
|
99
99
|
/**
|
|
100
100
|
* Statically generate routes and return the prerender result.
|
|
101
|
-
*
|
|
102
|
-
* `options.root` must be forward-slash — it is passed to `findDir` and flows
|
|
103
|
-
* into the route model. The caller (the `vinext build` entry in cli.ts)
|
|
104
|
-
* normalizes it.
|
|
105
101
|
*/
|
|
106
102
|
async function runPrerender(options) {
|
|
107
103
|
const { root } = options;
|
|
@@ -113,11 +109,7 @@ async function runPrerender(options) {
|
|
|
113
109
|
const manifestDir = path.join(root, "dist", "server");
|
|
114
110
|
const rscBundlePath = options.rscBundlePath ?? path.join(root, "dist", "server", "index.js");
|
|
115
111
|
const serverDir = path.dirname(rscBundlePath);
|
|
116
|
-
const
|
|
117
|
-
const config = options.nextConfigOverride ? {
|
|
118
|
-
...loadedConfig,
|
|
119
|
-
...options.nextConfigOverride
|
|
120
|
-
} : { ...loadedConfig };
|
|
112
|
+
const config = options.nextConfig ? { ...options.nextConfig } : { ...await resolveNextConfig(await loadNextConfig(root), root) };
|
|
121
113
|
const builtBuildId = readBuiltBuildId(serverDir);
|
|
122
114
|
if (builtBuildId) config.buildId = builtBuildId;
|
|
123
115
|
const mode = config.output === "export" ? "export" : "default";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import path from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
1
2
|
import { readJsonFile } from "../utils/safe-json-file.js";
|
|
2
|
-
import path from "node:path";
|
|
3
3
|
//#region src/build/server-manifest.ts
|
|
4
4
|
/**
|
|
5
5
|
* Shared utilities for reading/writing vinext-server.json.
|
|
@@ -9,6 +9,10 @@ type BundleBackfillChunk = {
|
|
|
9
9
|
importedAssets?: Set<string>;
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* Realpath with NATIVE separators (backslashes on Windows). Callers apply
|
|
14
|
+
* `toSlash` where the result becomes a module id / manifest key.
|
|
15
|
+
*/
|
|
12
16
|
declare function tryRealpathSync(candidate: string): string | null;
|
|
13
17
|
declare function relativeWithinRoot(root: string, moduleId: string): string | null;
|
|
14
18
|
declare function augmentSsrManifestFromBundle(ssrManifest: Record<string, string[]>, bundle: Record<string, BundleBackfillChunk | {
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import path, { toSlash } from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
1
2
|
import { collapseDuplicateBase, manifestFileWithBase } from "../utils/manifest-paths.js";
|
|
2
3
|
import fs from "node:fs";
|
|
3
|
-
import path from "node:path";
|
|
4
4
|
//#region src/build/ssr-manifest.ts
|
|
5
|
+
/**
|
|
6
|
+
* Realpath with NATIVE separators (backslashes on Windows). Callers apply
|
|
7
|
+
* `toSlash` where the result becomes a module id / manifest key.
|
|
8
|
+
*/
|
|
5
9
|
function tryRealpathSync(candidate) {
|
|
6
10
|
try {
|
|
7
11
|
return fs.realpathSync.native(candidate);
|
|
@@ -13,26 +17,26 @@ function isWindowsAbsolutePath(candidate) {
|
|
|
13
17
|
return /^[a-zA-Z]:[\\/]/.test(candidate) || candidate.startsWith("\\\\");
|
|
14
18
|
}
|
|
15
19
|
function relativeWithinRoot(root, moduleId) {
|
|
16
|
-
const relativeId =
|
|
20
|
+
const relativeId = isWindowsAbsolutePath(root) || isWindowsAbsolutePath(moduleId) ? path.win32.relative(root, moduleId) : path.relative(root, moduleId);
|
|
17
21
|
if (!relativeId || relativeId === ".." || relativeId.startsWith("../")) return null;
|
|
18
22
|
return relativeId;
|
|
19
23
|
}
|
|
20
24
|
function normalizeManifestModuleId(moduleId, root) {
|
|
21
|
-
const normalizedId = moduleId
|
|
25
|
+
const normalizedId = toSlash(moduleId);
|
|
22
26
|
if (normalizedId.startsWith("\0")) return normalizedId;
|
|
23
27
|
if (normalizedId.startsWith("node_modules/") || normalizedId.includes("/node_modules/")) return normalizedId;
|
|
24
28
|
if (!isWindowsAbsolutePath(moduleId) && !path.isAbsolute(moduleId)) {
|
|
25
29
|
if (!normalizedId.startsWith(".") && !normalizedId.includes("../")) return normalizedId;
|
|
26
30
|
}
|
|
27
|
-
const rootCandidates = new Set([root]);
|
|
31
|
+
const rootCandidates = /* @__PURE__ */ new Set([root]);
|
|
28
32
|
const realRoot = tryRealpathSync(root);
|
|
29
|
-
if (realRoot) rootCandidates.add(realRoot);
|
|
33
|
+
if (realRoot) rootCandidates.add(toSlash(realRoot));
|
|
30
34
|
const moduleCandidates = /* @__PURE__ */ new Set();
|
|
31
35
|
if (isWindowsAbsolutePath(moduleId) || path.isAbsolute(moduleId)) moduleCandidates.add(moduleId);
|
|
32
36
|
else moduleCandidates.add(path.resolve(root, moduleId));
|
|
33
37
|
for (const candidate of moduleCandidates) {
|
|
34
38
|
const realCandidate = tryRealpathSync(candidate);
|
|
35
|
-
if (realCandidate) moduleCandidates.add(realCandidate);
|
|
39
|
+
if (realCandidate) moduleCandidates.add(toSlash(realCandidate));
|
|
36
40
|
}
|
|
37
41
|
for (const rootCandidate of rootCandidates) for (const moduleCandidate of moduleCandidates) {
|
|
38
42
|
const relativeId = relativeWithinRoot(rootCandidate, moduleCandidate);
|