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/dist/build/standalone.js
CHANGED
|
@@ -2,7 +2,7 @@ import { readJsonFile } from "../utils/safe-json-file.js";
|
|
|
2
2
|
import { resolveVinextPackageRoot } from "../utils/vinext-root.js";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import fs from "node:fs";
|
|
5
|
-
import
|
|
5
|
+
import nodePath from "node:path";
|
|
6
6
|
//#region src/build/standalone.ts
|
|
7
7
|
function readPackageJson(packageJsonPath) {
|
|
8
8
|
return JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
|
|
@@ -29,7 +29,7 @@ function runtimeDeps(pkg) {
|
|
|
29
29
|
* running against a build that predates this feature).
|
|
30
30
|
*/
|
|
31
31
|
function readServerExternalsManifest(serverDir) {
|
|
32
|
-
const manifestPath =
|
|
32
|
+
const manifestPath = nodePath.join(serverDir, "vinext-externals.json");
|
|
33
33
|
if (!fs.existsSync(manifestPath)) return [];
|
|
34
34
|
return readJsonFile(manifestPath, { onError: (err) => {
|
|
35
35
|
console.warn(`[vinext] Warning: failed to parse ${manifestPath}, proceeding without externals manifest: ${String(err)}`);
|
|
@@ -41,28 +41,28 @@ function resolvePackageJsonPath(packageName, resolver) {
|
|
|
41
41
|
} catch {
|
|
42
42
|
const lookupPaths = resolver.resolve.paths(packageName) ?? [];
|
|
43
43
|
for (const lookupPath of lookupPaths) {
|
|
44
|
-
const candidate =
|
|
44
|
+
const candidate = nodePath.join(lookupPath, packageName, "package.json");
|
|
45
45
|
if (fs.existsSync(candidate)) {
|
|
46
46
|
if (readPackageJson(candidate).name === packageName) return candidate;
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
try {
|
|
50
50
|
const entryPath = resolver.resolve(packageName);
|
|
51
|
-
let dir =
|
|
52
|
-
while (dir !==
|
|
53
|
-
const candidate =
|
|
51
|
+
let dir = nodePath.dirname(entryPath);
|
|
52
|
+
while (dir !== nodePath.dirname(dir)) {
|
|
53
|
+
const candidate = nodePath.join(dir, "package.json");
|
|
54
54
|
if (fs.existsSync(candidate)) {
|
|
55
55
|
if (readPackageJson(candidate).name === packageName) return candidate;
|
|
56
56
|
}
|
|
57
|
-
dir =
|
|
57
|
+
dir = nodePath.dirname(dir);
|
|
58
58
|
}
|
|
59
59
|
} catch {}
|
|
60
60
|
return null;
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
function copyPackageAndRuntimeDeps(root, targetNodeModulesDir, initialPackages, alreadyCopied) {
|
|
64
|
-
const rootResolver = createRequire(
|
|
65
|
-
const rootPkg = readPackageJson(
|
|
64
|
+
const rootResolver = createRequire(nodePath.join(root, "package.json"));
|
|
65
|
+
const rootPkg = readPackageJson(nodePath.join(root, "package.json"));
|
|
66
66
|
const rootOptional = new Set(Object.keys(rootPkg.optionalDependencies ?? {}));
|
|
67
67
|
const copied = alreadyCopied ?? /* @__PURE__ */ new Set();
|
|
68
68
|
const queue = initialPackages.map((packageName) => ({
|
|
@@ -80,14 +80,14 @@ function copyPackageAndRuntimeDeps(root, targetNodeModulesDir, initialPackages,
|
|
|
80
80
|
throw new Error(`Failed to resolve required runtime dependency "${entry.packageName}" for standalone output`);
|
|
81
81
|
}
|
|
82
82
|
const realPackageJsonPath = fs.realpathSync(packageJsonPath);
|
|
83
|
-
const packageRoot =
|
|
84
|
-
const packageTarget =
|
|
85
|
-
fs.mkdirSync(
|
|
83
|
+
const packageRoot = nodePath.dirname(realPackageJsonPath);
|
|
84
|
+
const packageTarget = nodePath.join(targetNodeModulesDir, entry.packageName);
|
|
85
|
+
fs.mkdirSync(nodePath.dirname(packageTarget), { recursive: true });
|
|
86
86
|
fs.cpSync(packageRoot, packageTarget, {
|
|
87
87
|
recursive: true,
|
|
88
88
|
dereference: true,
|
|
89
89
|
filter: (src) => {
|
|
90
|
-
return !
|
|
90
|
+
return !nodePath.relative(packageRoot, src).split(nodePath.sep).includes("node_modules");
|
|
91
91
|
}
|
|
92
92
|
});
|
|
93
93
|
copied.add(entry.packageName);
|
|
@@ -144,58 +144,58 @@ function writeStandalonePackageJson(filePath) {
|
|
|
144
144
|
* included.
|
|
145
145
|
*/
|
|
146
146
|
function emitStandaloneOutput(options) {
|
|
147
|
-
const root =
|
|
148
|
-
const outDir =
|
|
149
|
-
const clientDir =
|
|
150
|
-
const serverDir =
|
|
147
|
+
const root = nodePath.resolve(options.root);
|
|
148
|
+
const outDir = nodePath.resolve(options.outDir);
|
|
149
|
+
const clientDir = nodePath.join(outDir, "client");
|
|
150
|
+
const serverDir = nodePath.join(outDir, "server");
|
|
151
151
|
if (!fs.existsSync(clientDir) || !fs.existsSync(serverDir)) throw new Error(`No build output found in ${outDir}. Run vinext build first.`);
|
|
152
|
-
const standaloneDir =
|
|
153
|
-
const standaloneDistDir =
|
|
154
|
-
const standaloneNodeModulesDir =
|
|
152
|
+
const standaloneDir = nodePath.join(outDir, "standalone");
|
|
153
|
+
const standaloneDistDir = nodePath.join(standaloneDir, "dist");
|
|
154
|
+
const standaloneNodeModulesDir = nodePath.join(standaloneDir, "node_modules");
|
|
155
155
|
fs.rmSync(standaloneDir, {
|
|
156
156
|
recursive: true,
|
|
157
157
|
force: true
|
|
158
158
|
});
|
|
159
159
|
fs.mkdirSync(standaloneDistDir, { recursive: true });
|
|
160
|
-
fs.cpSync(clientDir,
|
|
160
|
+
fs.cpSync(clientDir, nodePath.join(standaloneDistDir, "client"), {
|
|
161
161
|
recursive: true,
|
|
162
162
|
dereference: true,
|
|
163
|
-
filter: (src) => !
|
|
163
|
+
filter: (src) => !nodePath.relative(clientDir, src).split(nodePath.sep).includes("node_modules")
|
|
164
164
|
});
|
|
165
|
-
fs.cpSync(serverDir,
|
|
165
|
+
fs.cpSync(serverDir, nodePath.join(standaloneDistDir, "server"), {
|
|
166
166
|
recursive: true,
|
|
167
167
|
dereference: true,
|
|
168
|
-
filter: (src) => !
|
|
168
|
+
filter: (src) => !nodePath.relative(serverDir, src).split(nodePath.sep).includes("node_modules")
|
|
169
169
|
});
|
|
170
|
-
const clientAssetsSidecar =
|
|
171
|
-
if (fs.existsSync(clientAssetsSidecar)) fs.copyFileSync(clientAssetsSidecar,
|
|
172
|
-
const publicDir =
|
|
173
|
-
if (fs.existsSync(publicDir)) fs.cpSync(publicDir,
|
|
170
|
+
const clientAssetsSidecar = nodePath.join(outDir, "vinext-client-assets.js");
|
|
171
|
+
if (fs.existsSync(clientAssetsSidecar)) fs.copyFileSync(clientAssetsSidecar, nodePath.join(standaloneDistDir, "vinext-client-assets.js"));
|
|
172
|
+
const publicDir = nodePath.join(root, "public");
|
|
173
|
+
if (fs.existsSync(publicDir)) fs.cpSync(publicDir, nodePath.join(standaloneDir, "public"), {
|
|
174
174
|
recursive: true,
|
|
175
175
|
dereference: true,
|
|
176
|
-
filter: (src) => !
|
|
176
|
+
filter: (src) => !nodePath.relative(publicDir, src).split(nodePath.sep).includes("node_modules")
|
|
177
177
|
});
|
|
178
178
|
fs.mkdirSync(standaloneNodeModulesDir, { recursive: true });
|
|
179
179
|
const initialPackages = readServerExternalsManifest(serverDir).filter((name) => name !== "vinext");
|
|
180
180
|
const copiedSet = /* @__PURE__ */ new Set();
|
|
181
181
|
copyPackageAndRuntimeDeps(root, standaloneNodeModulesDir, initialPackages, copiedSet);
|
|
182
182
|
const vinextPackageRoot = resolveVinextPackageRoot(options.vinextPackageRoot);
|
|
183
|
-
const vinextDistDir =
|
|
183
|
+
const vinextDistDir = nodePath.join(vinextPackageRoot, "dist");
|
|
184
184
|
if (!fs.existsSync(vinextDistDir)) throw new Error(`vinext runtime dist/ not found at ${vinextPackageRoot}`);
|
|
185
|
-
const vinextTargetDir =
|
|
185
|
+
const vinextTargetDir = nodePath.join(standaloneNodeModulesDir, "vinext");
|
|
186
186
|
fs.mkdirSync(vinextTargetDir, { recursive: true });
|
|
187
|
-
fs.copyFileSync(
|
|
188
|
-
fs.cpSync(vinextDistDir,
|
|
187
|
+
fs.copyFileSync(nodePath.join(vinextPackageRoot, "package.json"), nodePath.join(vinextTargetDir, "package.json"));
|
|
188
|
+
fs.cpSync(vinextDistDir, nodePath.join(vinextTargetDir, "dist"), {
|
|
189
189
|
recursive: true,
|
|
190
190
|
dereference: true,
|
|
191
191
|
filter: (src) => {
|
|
192
|
-
return !
|
|
192
|
+
return !nodePath.relative(vinextDistDir, src).split(nodePath.sep).includes("node_modules");
|
|
193
193
|
}
|
|
194
194
|
});
|
|
195
195
|
copiedSet.add("vinext");
|
|
196
|
-
copyPackageAndRuntimeDeps(vinextPackageRoot, standaloneNodeModulesDir, runtimeDeps(readPackageJson(
|
|
197
|
-
writeStandaloneServerEntry(
|
|
198
|
-
writeStandalonePackageJson(
|
|
196
|
+
copyPackageAndRuntimeDeps(vinextPackageRoot, standaloneNodeModulesDir, runtimeDeps(readPackageJson(nodePath.join(vinextPackageRoot, "package.json"))).filter((name) => !copiedSet.has(name)), copiedSet);
|
|
197
|
+
writeStandaloneServerEntry(nodePath.join(standaloneDir, "server.js"));
|
|
198
|
+
writeStandalonePackageJson(nodePath.join(standaloneDir, "package.json"));
|
|
199
199
|
return {
|
|
200
200
|
standaloneDir,
|
|
201
201
|
copiedPackages: [...copiedSet]
|
|
@@ -1,20 +1,4 @@
|
|
|
1
1
|
//#region src/cache/cache-adapters-virtual.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Code generation for the `virtual:vinext-cache-adapters` module, resolved by
|
|
4
|
-
* the vinext vite plugin from the user's `cache` config ({@link VinextCacheConfig}).
|
|
5
|
-
*
|
|
6
|
-
* The generated module exports `registerConfiguredCacheAdapters(env)`, which the
|
|
7
|
-
* server entries call on each request. It self-guards (adapters instantiate once
|
|
8
|
-
* per isolate) and is a no-op when nothing is configured. Registration is
|
|
9
|
-
* resilient: a factory that throws (e.g. a KV adapter on the Node.js server,
|
|
10
|
-
* where the binding can't exist) is logged and skipped rather than failing every
|
|
11
|
-
* request, so the same config can be registered from every runtime/router entry.
|
|
12
|
-
*
|
|
13
|
-
* Descriptor `options` are inlined into the generated module and forwarded to the
|
|
14
|
-
* factory at runtime, so a config-time builder like `kvDataAdapter({ binding })`
|
|
15
|
-
* never touches the Workers runtime — instantiation is deferred to the first
|
|
16
|
-
* request.
|
|
17
|
-
*/
|
|
18
2
|
/**
|
|
19
3
|
* A serializable pointer to a cache adapter module — the shape of each `cache`
|
|
20
4
|
* slot in the vinext() plugin config. Produced by an adapter builder (e.g.
|
|
@@ -45,7 +29,7 @@ declare const VINEXT_CACHE_CONFIG_PLUGIN_PROPERTY = "__vinextCacheConfig";
|
|
|
45
29
|
type ViteConfigLoader = {
|
|
46
30
|
loadConfigFromFile: typeof import("vite").loadConfigFromFile;
|
|
47
31
|
};
|
|
48
|
-
declare function findVinextCacheConfigInPlugins(plugins: import("vite").PluginOption[] | undefined): VinextCacheConfig | null
|
|
32
|
+
declare function findVinextCacheConfigInPlugins(plugins: import("vite").PluginOption[] | undefined): Promise<VinextCacheConfig | null>;
|
|
49
33
|
declare function loadVinextCacheConfigFromViteConfig(vite: ViteConfigLoader, root: string): Promise<VinextCacheConfig | null>;
|
|
50
34
|
/**
|
|
51
35
|
* Generate the source of the `virtual:vinext-cache-adapters` module for the
|
|
@@ -1,17 +1,26 @@
|
|
|
1
|
+
import { flattenPluginOptions } from "../utils/plugin-options.js";
|
|
1
2
|
//#region src/cache/cache-adapters-virtual.ts
|
|
3
|
+
/**
|
|
4
|
+
* Code generation for the `virtual:vinext-cache-adapters` module, resolved by
|
|
5
|
+
* the vinext vite plugin from the user's `cache` config ({@link VinextCacheConfig}).
|
|
6
|
+
*
|
|
7
|
+
* The generated module exports `registerConfiguredCacheAdapters(env)`, which the
|
|
8
|
+
* server entries call on each request. It self-guards (adapters instantiate once
|
|
9
|
+
* per isolate) and is a no-op when nothing is configured. Registration is
|
|
10
|
+
* resilient: a factory that throws (e.g. a KV adapter on the Node.js server,
|
|
11
|
+
* where the binding can't exist) is logged and skipped rather than failing every
|
|
12
|
+
* request, so the same config can be registered from every runtime/router entry.
|
|
13
|
+
*
|
|
14
|
+
* Descriptor `options` are inlined into the generated module and forwarded to the
|
|
15
|
+
* factory at runtime, so a config-time builder like `kvDataAdapter({ binding })`
|
|
16
|
+
* never touches the Workers runtime — instantiation is deferred to the first
|
|
17
|
+
* request.
|
|
18
|
+
*/
|
|
2
19
|
/** Public virtual module id imported by the server entries. */
|
|
3
20
|
const VIRTUAL_CACHE_ADAPTERS = "virtual:vinext-cache-adapters";
|
|
4
21
|
const VINEXT_CACHE_CONFIG_PLUGIN_PROPERTY = "__vinextCacheConfig";
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
for (const item of value) flattenPluginOptions(item, target);
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
if (value) target.push(value);
|
|
11
|
-
}
|
|
12
|
-
function findVinextCacheConfigInPlugins(plugins) {
|
|
13
|
-
const flattened = [];
|
|
14
|
-
flattenPluginOptions(plugins, flattened);
|
|
22
|
+
async function findVinextCacheConfigInPlugins(plugins) {
|
|
23
|
+
const flattened = await flattenPluginOptions(plugins);
|
|
15
24
|
for (const plugin of flattened) {
|
|
16
25
|
if (!plugin || typeof plugin !== "object") continue;
|
|
17
26
|
const cacheConfig = plugin[VINEXT_CACHE_CONFIG_PLUGIN_PROPERTY];
|
|
@@ -20,7 +29,7 @@ function findVinextCacheConfigInPlugins(plugins) {
|
|
|
20
29
|
return null;
|
|
21
30
|
}
|
|
22
31
|
async function loadVinextCacheConfigFromViteConfig(vite, root) {
|
|
23
|
-
return findVinextCacheConfigInPlugins((await vite.loadConfigFromFile({
|
|
32
|
+
return await findVinextCacheConfigInPlugins((await vite.loadConfigFromFile({
|
|
24
33
|
command: "build",
|
|
25
34
|
mode: "production"
|
|
26
35
|
}, void 0, root))?.config.plugins);
|
package/dist/check.d.ts
CHANGED
|
@@ -59,38 +59,22 @@ type CheckResult = {
|
|
|
59
59
|
declare function hasFreeCjsGlobal(content: string): boolean;
|
|
60
60
|
/**
|
|
61
61
|
* Scan source files for `import ... from 'next/...'` statements.
|
|
62
|
-
*
|
|
63
|
-
* `root` must be forward-slash: it is passed to `findSourceFiles`, which
|
|
64
|
-
* requires it.
|
|
65
62
|
*/
|
|
66
63
|
declare function scanImports(root: string): CheckItem[];
|
|
67
64
|
/**
|
|
68
65
|
* Analyze next.config.js/mjs/ts for supported and unsupported options.
|
|
69
|
-
*
|
|
70
|
-
* `root` must be forward-slash — joined with `path.posix.join`. Only called
|
|
71
|
-
* from `runCheck`, which normalizes it.
|
|
72
66
|
*/
|
|
73
67
|
declare function analyzeConfig(root: string): CheckItem[];
|
|
74
68
|
/**
|
|
75
69
|
* Check package.json dependencies for known libraries.
|
|
76
|
-
*
|
|
77
|
-
* `root` must be forward-slash — joined with `path.posix.join`. Only called
|
|
78
|
-
* from `runCheck`, which normalizes it.
|
|
79
70
|
*/
|
|
80
71
|
declare function checkLibraries(root: string): CheckItem[];
|
|
81
72
|
/**
|
|
82
73
|
* Check file conventions (pages, app directory, middleware, etc.)
|
|
83
|
-
*
|
|
84
|
-
* `root` must be forward-slash — joined with `path.posix.join` and passed to
|
|
85
|
-
* `findDir`. Only called from `runCheck`, which normalizes it.
|
|
86
74
|
*/
|
|
87
75
|
declare function checkConventions(root: string): CheckItem[];
|
|
88
76
|
/**
|
|
89
77
|
* Run the full compatibility check.
|
|
90
|
-
*
|
|
91
|
-
* `root` must be forward-slash — callers normalize it at the CLI entry, and it
|
|
92
|
-
* is forwarded to `scanImports` / `checkConventions` / `findDir`, which build
|
|
93
|
-
* paths with `path.posix.*`.
|
|
94
78
|
*/
|
|
95
79
|
declare function runCheck(root: string): CheckResult;
|
|
96
80
|
/**
|
package/dist/check.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import path from "./deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
1
2
|
import { detectPackageManager, findDir } from "./utils/project.js";
|
|
2
|
-
import { normalizePathSeparators } from "./utils/path.js";
|
|
3
3
|
import fs from "node:fs";
|
|
4
|
-
import path from "node:path";
|
|
5
4
|
import { parseAst } from "vite";
|
|
6
5
|
//#region src/check.ts
|
|
7
6
|
/**
|
|
@@ -371,11 +370,6 @@ const LIBRARY_SUPPORT = {
|
|
|
371
370
|
};
|
|
372
371
|
/**
|
|
373
372
|
* Recursively find all source files in a directory.
|
|
374
|
-
*
|
|
375
|
-
* `dir` must be forward-slash, and the returned paths are forward-slash too:
|
|
376
|
-
* each entry is joined with `path.posix.join`, which only stays canonical when
|
|
377
|
-
* the base already is. This keeps downstream substring checks (e.g.
|
|
378
|
-
* `f.includes("/api/")`) and reported paths consistent across platforms.
|
|
379
373
|
*/
|
|
380
374
|
function findSourceFiles(dir, extensions = [
|
|
381
375
|
".ts",
|
|
@@ -388,7 +382,7 @@ function findSourceFiles(dir, extensions = [
|
|
|
388
382
|
if (!fs.existsSync(dir)) return results;
|
|
389
383
|
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
390
384
|
for (const entry of entries) {
|
|
391
|
-
const fullPath = path.
|
|
385
|
+
const fullPath = path.join(dir, entry.name);
|
|
392
386
|
if (entry.isDirectory()) {
|
|
393
387
|
if (entry.name === "node_modules" || entry.name === ".next" || entry.name === "dist" || entry.name === ".git") continue;
|
|
394
388
|
results.push(...findSourceFiles(fullPath, extensions));
|
|
@@ -396,14 +390,27 @@ function findSourceFiles(dir, extensions = [
|
|
|
396
390
|
}
|
|
397
391
|
return results;
|
|
398
392
|
}
|
|
393
|
+
/**
|
|
394
|
+
* Find files that can contribute to the application compatibility surface.
|
|
395
|
+
* Test modules and test-runner configuration are executed by their own runners
|
|
396
|
+
* rather than bundled into the vinext application, so reporting their imports
|
|
397
|
+
* or CJS globals as migration blockers produces false positives.
|
|
398
|
+
*/
|
|
399
|
+
function findRuntimeSourceFiles(root) {
|
|
400
|
+
return findSourceFiles(root).filter((file) => {
|
|
401
|
+
const basename = path.basename(file);
|
|
402
|
+
const isTestRunnerConfig = /^(?:jest|playwright|vitest)\.config\.[cm]?[jt]sx?$/.test(basename);
|
|
403
|
+
return !/\.(?:test|spec)\.[cm]?[jt]sx?$/.test(basename) && !isTestRunnerConfig;
|
|
404
|
+
});
|
|
405
|
+
}
|
|
399
406
|
function isIdentStart(c) {
|
|
400
407
|
return c >= "a" && c <= "z" || c >= "A" && c <= "Z" || c === "_" || c === "$";
|
|
401
408
|
}
|
|
402
409
|
function isIdentChar(c) {
|
|
403
410
|
return c >= "a" && c <= "z" || c >= "A" && c <= "Z" || c >= "0" && c <= "9" || c === "_" || c === "$";
|
|
404
411
|
}
|
|
405
|
-
const CJS_GLOBALS = new Set(["__dirname", "__filename"]);
|
|
406
|
-
const REGEX_PRECEDING_KEYWORDS = new Set([
|
|
412
|
+
const CJS_GLOBALS = /* @__PURE__ */ new Set(["__dirname", "__filename"]);
|
|
413
|
+
const REGEX_PRECEDING_KEYWORDS = /* @__PURE__ */ new Set([
|
|
407
414
|
"return",
|
|
408
415
|
"typeof",
|
|
409
416
|
"instanceof",
|
|
@@ -592,12 +599,9 @@ function hasFreeCjsGlobal(content) {
|
|
|
592
599
|
}
|
|
593
600
|
/**
|
|
594
601
|
* Scan source files for `import ... from 'next/...'` statements.
|
|
595
|
-
*
|
|
596
|
-
* `root` must be forward-slash: it is passed to `findSourceFiles`, which
|
|
597
|
-
* requires it.
|
|
598
602
|
*/
|
|
599
603
|
function scanImports(root) {
|
|
600
|
-
const files =
|
|
604
|
+
const files = findRuntimeSourceFiles(root);
|
|
601
605
|
const importUsage = /* @__PURE__ */ new Map();
|
|
602
606
|
const importRegex = /(?:import\s+(?:[\w{},\s*]+\s+from\s+)?|require\s*\()['"]([^'"]+)['"]\)?/g;
|
|
603
607
|
const typeOnlyImportRegex = /import\s+type\s+/;
|
|
@@ -612,7 +616,7 @@ function scanImports(root) {
|
|
|
612
616
|
if (mod.startsWith("next/") || mod === "next" || mod === "server-only" || mod === "client-only") {
|
|
613
617
|
const normalized = mod === "next" ? "next" : mod;
|
|
614
618
|
if (!importUsage.has(normalized)) importUsage.set(normalized, []);
|
|
615
|
-
const relFile =
|
|
619
|
+
const relFile = path.relative(root, file);
|
|
616
620
|
const usedInFiles = importUsage.get(normalized) ?? [];
|
|
617
621
|
if (!usedInFiles.includes(relFile)) usedInFiles.push(relFile);
|
|
618
622
|
}
|
|
@@ -739,9 +743,6 @@ function collectConfigKeys(source) {
|
|
|
739
743
|
}
|
|
740
744
|
/**
|
|
741
745
|
* Analyze next.config.js/mjs/ts for supported and unsupported options.
|
|
742
|
-
*
|
|
743
|
-
* `root` must be forward-slash — joined with `path.posix.join`. Only called
|
|
744
|
-
* from `runCheck`, which normalizes it.
|
|
745
746
|
*/
|
|
746
747
|
function analyzeConfig(root) {
|
|
747
748
|
const configFiles = [
|
|
@@ -753,7 +754,7 @@ function analyzeConfig(root) {
|
|
|
753
754
|
];
|
|
754
755
|
let configPath = null;
|
|
755
756
|
for (const f of configFiles) {
|
|
756
|
-
const p = path.
|
|
757
|
+
const p = path.join(root, f);
|
|
757
758
|
if (fs.existsSync(p)) {
|
|
758
759
|
configPath = p;
|
|
759
760
|
break;
|
|
@@ -811,12 +812,9 @@ function analyzeConfig(root) {
|
|
|
811
812
|
}
|
|
812
813
|
/**
|
|
813
814
|
* Check package.json dependencies for known libraries.
|
|
814
|
-
*
|
|
815
|
-
* `root` must be forward-slash — joined with `path.posix.join`. Only called
|
|
816
|
-
* from `runCheck`, which normalizes it.
|
|
817
815
|
*/
|
|
818
816
|
function checkLibraries(root) {
|
|
819
|
-
const pkgPath = path.
|
|
817
|
+
const pkgPath = path.join(root, "package.json");
|
|
820
818
|
if (!fs.existsSync(pkgPath)) return [];
|
|
821
819
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
822
820
|
const allDeps = {
|
|
@@ -834,16 +832,13 @@ function checkLibraries(root) {
|
|
|
834
832
|
}
|
|
835
833
|
/**
|
|
836
834
|
* Check file conventions (pages, app directory, middleware, etc.)
|
|
837
|
-
*
|
|
838
|
-
* `root` must be forward-slash — joined with `path.posix.join` and passed to
|
|
839
|
-
* `findDir`. Only called from `runCheck`, which normalizes it.
|
|
840
835
|
*/
|
|
841
836
|
function checkConventions(root) {
|
|
842
837
|
const items = [];
|
|
843
838
|
const pagesDir = findDir(root, "pages", "src/pages");
|
|
844
839
|
const appDirPath = findDir(root, "app", "src/app");
|
|
845
|
-
const hasProxy = fs.existsSync(path.
|
|
846
|
-
const hasMiddleware = fs.existsSync(path.
|
|
840
|
+
const hasProxy = fs.existsSync(path.join(root, "proxy.ts")) || fs.existsSync(path.join(root, "proxy.js"));
|
|
841
|
+
const hasMiddleware = fs.existsSync(path.join(root, "middleware.ts")) || fs.existsSync(path.join(root, "middleware.js"));
|
|
847
842
|
if (pagesDir !== null) {
|
|
848
843
|
const isSrc = pagesDir.includes("src/pages");
|
|
849
844
|
items.push({
|
|
@@ -921,7 +916,7 @@ function checkConventions(root) {
|
|
|
921
916
|
status: "unsupported",
|
|
922
917
|
detail: "vinext requires a pages/ or app/ directory"
|
|
923
918
|
});
|
|
924
|
-
const pkgPath = path.
|
|
919
|
+
const pkgPath = path.join(root, "package.json");
|
|
925
920
|
if (fs.existsSync(pkgPath)) {
|
|
926
921
|
if (JSON.parse(fs.readFileSync(pkgPath, "utf-8")).type !== "module") items.push({
|
|
927
922
|
name: "Missing \"type\": \"module\" in package.json",
|
|
@@ -929,13 +924,13 @@ function checkConventions(root) {
|
|
|
929
924
|
detail: "required for Vite — vinext init will add it automatically"
|
|
930
925
|
});
|
|
931
926
|
}
|
|
932
|
-
const allSourceFiles =
|
|
927
|
+
const allSourceFiles = findRuntimeSourceFiles(root);
|
|
933
928
|
const viewTransitionRegex = /import\s+\{[^}]*\bViewTransition\b[^}]*\}\s+from\s+['"]react['"]/;
|
|
934
929
|
const viewTransitionFiles = [];
|
|
935
930
|
const cjsGlobalFiles = [];
|
|
936
931
|
for (const file of allSourceFiles) {
|
|
937
932
|
const content = fs.readFileSync(file, "utf-8");
|
|
938
|
-
const rel =
|
|
933
|
+
const rel = path.relative(root, file);
|
|
939
934
|
if (viewTransitionRegex.test(content)) viewTransitionFiles.push(rel);
|
|
940
935
|
if (hasFreeCjsGlobal(content)) cjsGlobalFiles.push(rel);
|
|
941
936
|
}
|
|
@@ -950,7 +945,7 @@ function checkConventions(root) {
|
|
|
950
945
|
"postcss.config.js",
|
|
951
946
|
"postcss.config.cjs"
|
|
952
947
|
]) {
|
|
953
|
-
const configPath = path.
|
|
948
|
+
const configPath = path.join(root, configFile);
|
|
954
949
|
if (fs.existsSync(configPath)) {
|
|
955
950
|
const content = fs.readFileSync(configPath, "utf-8");
|
|
956
951
|
if (/plugins\s*:\s*\[\s*['"]/.test(content)) items.push({
|
|
@@ -971,10 +966,6 @@ function checkConventions(root) {
|
|
|
971
966
|
}
|
|
972
967
|
/**
|
|
973
968
|
* Run the full compatibility check.
|
|
974
|
-
*
|
|
975
|
-
* `root` must be forward-slash — callers normalize it at the CLI entry, and it
|
|
976
|
-
* is forwarded to `scanImports` / `checkConventions` / `findDir`, which build
|
|
977
|
-
* paths with `path.posix.*`.
|
|
978
969
|
*/
|
|
979
970
|
function runCheck(root) {
|
|
980
971
|
const imports = scanImports(root);
|
package/dist/cli.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import path, { toSlash } from "./deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
2
3
|
import { detectPackageManager, ensureViteConfigCompatibility, hasAppDir, hasViteConfig } from "./utils/project.js";
|
|
3
|
-
import { normalizePathSeparators } from "./utils/path.js";
|
|
4
4
|
import { formatReport, runCheck } from "./check.js";
|
|
5
5
|
import { parseArgs } from "./cli-args.js";
|
|
6
6
|
import { createDevServerConfigPlugin, normalizeDevServerHostname } from "./cli-dev-config.js";
|
|
7
7
|
import { PHASE_PRODUCTION_BUILD } from "./shims/constants.js";
|
|
8
|
-
import { createRscCompatibilityId, loadNextConfig, resolveNextConfig } from "./config/next-config.js";
|
|
8
|
+
import { createRscCompatibilityId, findVinextNextConfigInPlugins, loadNextConfig, resolveNextConfig, resolveNextConfigInput } from "./config/next-config.js";
|
|
9
9
|
import { generateRouteTypes } from "./typegen.js";
|
|
10
10
|
import { clearPagesClientAssetsBuildMetadata } from "./build/pages-client-assets-module.js";
|
|
11
|
+
import { runWithPreviewBuildCredentials } from "./build/preview-credentials.js";
|
|
11
12
|
import { findVinextPrerenderConfigInPlugins, findVinextRouteRootConfigInPlugins, formatVinextPrerenderLabel, resolveVinextPrerenderDecision } from "./config/prerender.js";
|
|
12
13
|
import vinext from "./index.js";
|
|
13
14
|
import { runPrerender } from "./build/run-prerender.js";
|
|
@@ -22,7 +23,6 @@ import { cleanBuildOutput } from "./build/clean-output.js";
|
|
|
22
23
|
import { formatAlreadyRunningError, tryAcquireLockfile } from "./server/dev-lockfile.js";
|
|
23
24
|
import { createRequire } from "node:module";
|
|
24
25
|
import fs from "node:fs";
|
|
25
|
-
import path from "node:path";
|
|
26
26
|
import { pathToFileURL } from "node:url";
|
|
27
27
|
import { randomBytes } from "node:crypto";
|
|
28
28
|
import { execFileSync } from "node:child_process";
|
|
@@ -127,6 +127,7 @@ function hasPagesDir() {
|
|
|
127
127
|
}
|
|
128
128
|
async function loadBuildViteConfigMetadata(vite, root) {
|
|
129
129
|
if (!hasViteConfig(root)) return {
|
|
130
|
+
nextConfig: null,
|
|
130
131
|
prerenderConfig: null,
|
|
131
132
|
routeRootConfig: null
|
|
132
133
|
};
|
|
@@ -137,8 +138,9 @@ async function loadBuildViteConfigMetadata(vite, root) {
|
|
|
137
138
|
const emptyOutDir = loaded?.config.build?.emptyOutDir;
|
|
138
139
|
return {
|
|
139
140
|
emptyOutDir: typeof emptyOutDir === "boolean" ? emptyOutDir : void 0,
|
|
140
|
-
|
|
141
|
-
|
|
141
|
+
nextConfig: await findVinextNextConfigInPlugins(loaded?.config.plugins),
|
|
142
|
+
prerenderConfig: await findVinextPrerenderConfigInPlugins(loaded?.config.plugins),
|
|
143
|
+
routeRootConfig: await findVinextRouteRootConfigInPlugins(loaded?.config.plugins)
|
|
142
144
|
};
|
|
143
145
|
}
|
|
144
146
|
/**
|
|
@@ -281,9 +283,10 @@ async function buildApp() {
|
|
|
281
283
|
const vite = await loadVite();
|
|
282
284
|
const withBuildBundlerOptions = (bundlerOptions) => ({ rolldownOptions: bundlerOptions });
|
|
283
285
|
console.log(`\n vinext build (Vite ${getViteVersion()})\n`);
|
|
284
|
-
const root = process.cwd();
|
|
285
|
-
const isApp = hasAppDir(
|
|
286
|
-
const
|
|
286
|
+
const root = toSlash(process.cwd());
|
|
287
|
+
const isApp = hasAppDir(root);
|
|
288
|
+
const buildConfigMetadata = await loadBuildViteConfigMetadata(vite, root);
|
|
289
|
+
const resolvedNextConfig = await resolveNextConfig(buildConfigMetadata.nextConfig ? await resolveNextConfigInput(buildConfigMetadata.nextConfig, PHASE_PRODUCTION_BUILD) : await loadNextConfig(root, PHASE_PRODUCTION_BUILD), root);
|
|
287
290
|
process.env.__VINEXT_SHARED_BUILD_ID = resolvedNextConfig.buildId;
|
|
288
291
|
process.env.__VINEXT_SHARED_RSC_COMPATIBILITY_ID = createRscCompatibilityId(resolvedNextConfig);
|
|
289
292
|
if (!process.env.__VINEXT_SHARED_REVALIDATE_SECRET) process.env.__VINEXT_SHARED_REVALIDATE_SECRET = randomBytes(32).toString("hex");
|
|
@@ -309,7 +312,6 @@ async function buildApp() {
|
|
|
309
312
|
});
|
|
310
313
|
}
|
|
311
314
|
}
|
|
312
|
-
const buildConfigMetadata = await loadBuildViteConfigMetadata(vite, root);
|
|
313
315
|
cleanBuildOutput({
|
|
314
316
|
root,
|
|
315
317
|
outDir: distDir,
|
|
@@ -318,46 +320,48 @@ async function buildApp() {
|
|
|
318
320
|
const isHybrid = isApp && hasPagesDir();
|
|
319
321
|
const pagesClientAssetsBuildSession = isHybrid ? randomBytes(16).toString("hex") : null;
|
|
320
322
|
if (pagesClientAssetsBuildSession) process.env.__VINEXT_PAGES_CLIENT_ASSETS_BUILD_SESSION = pagesClientAssetsBuildSession;
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
await vite.build({
|
|
337
|
-
root,
|
|
338
|
-
configFile: false,
|
|
339
|
-
plugins: [...userTransformPlugins, vinext({ disableAppRouter: true })],
|
|
340
|
-
resolve: { dedupe: [
|
|
341
|
-
"react",
|
|
342
|
-
"react-dom",
|
|
343
|
-
"react/jsx-runtime",
|
|
344
|
-
"react/jsx-dev-runtime"
|
|
345
|
-
] },
|
|
346
|
-
...logger ? { customLogger: logger } : {},
|
|
347
|
-
build: {
|
|
348
|
-
outDir: "dist/server",
|
|
349
|
-
emptyOutDir: false,
|
|
350
|
-
ssr: "virtual:vinext-server-entry",
|
|
351
|
-
...withBuildBundlerOptions({ output: { entryFileNames: "entry.js" } })
|
|
323
|
+
await runWithPreviewBuildCredentials(async () => {
|
|
324
|
+
try {
|
|
325
|
+
const config = buildViteConfig({}, logger);
|
|
326
|
+
await (await vite.createBuilder(config)).buildApp();
|
|
327
|
+
if (isHybrid) {
|
|
328
|
+
console.log(" Building Pages Router server (hybrid)...");
|
|
329
|
+
const root = process.cwd();
|
|
330
|
+
let userTransformPlugins = [];
|
|
331
|
+
if (hasViteConfig(process.cwd())) {
|
|
332
|
+
const loaded = await vite.loadConfigFromFile({
|
|
333
|
+
command: "build",
|
|
334
|
+
mode: "production",
|
|
335
|
+
isSsrBuild: true
|
|
336
|
+
}, void 0, root);
|
|
337
|
+
if (loaded?.config.plugins) userTransformPlugins = loaded.config.plugins.flat(Infinity).filter((p) => !!p && typeof p.name === "string" && !p.name.startsWith("vinext:") && !p.name.startsWith("vite:react") && !p.name.startsWith("rsc:") && p.name !== "vite-rsc-load-module-dev-proxy" && !p.name.startsWith("vite-plugin-cloudflare"));
|
|
352
338
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
339
|
+
await vite.build({
|
|
340
|
+
root,
|
|
341
|
+
configFile: false,
|
|
342
|
+
plugins: [...userTransformPlugins, vinext({ disableAppRouter: true })],
|
|
343
|
+
resolve: { dedupe: [
|
|
344
|
+
"react",
|
|
345
|
+
"react-dom",
|
|
346
|
+
"react/jsx-runtime",
|
|
347
|
+
"react/jsx-dev-runtime"
|
|
348
|
+
] },
|
|
349
|
+
...logger ? { customLogger: logger } : {},
|
|
350
|
+
build: {
|
|
351
|
+
outDir: "dist/server",
|
|
352
|
+
emptyOutDir: false,
|
|
353
|
+
ssr: "virtual:vinext-server-entry",
|
|
354
|
+
...withBuildBundlerOptions({ output: { entryFileNames: "entry.js" } })
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
} finally {
|
|
359
|
+
if (pagesClientAssetsBuildSession) {
|
|
360
|
+
clearPagesClientAssetsBuildMetadata(pagesClientAssetsBuildSession);
|
|
361
|
+
if (process.env.__VINEXT_PAGES_CLIENT_ASSETS_BUILD_SESSION === pagesClientAssetsBuildSession) delete process.env.__VINEXT_PAGES_CLIENT_ASSETS_BUILD_SESSION;
|
|
362
|
+
}
|
|
359
363
|
}
|
|
360
|
-
}
|
|
364
|
+
});
|
|
361
365
|
if (outputMode === "standalone") {
|
|
362
366
|
const standalone = emitStandaloneOutput({
|
|
363
367
|
root: process.cwd(),
|
|
@@ -381,19 +385,20 @@ async function buildApp() {
|
|
|
381
385
|
process.stdout.write("\x1B[0m");
|
|
382
386
|
console.log(` ${formatVinextPrerenderLabel(prerenderDecision)}`);
|
|
383
387
|
prerenderResult = await runPrerender({
|
|
384
|
-
root
|
|
385
|
-
concurrency: parsed.prerenderConcurrency
|
|
388
|
+
root,
|
|
389
|
+
concurrency: parsed.prerenderConcurrency,
|
|
390
|
+
nextConfig: resolvedNextConfig
|
|
386
391
|
});
|
|
387
392
|
await emitPrerenderPathManifest({
|
|
388
|
-
root
|
|
389
|
-
|
|
393
|
+
root,
|
|
394
|
+
nextConfig: resolvedNextConfig,
|
|
390
395
|
routeRootConfig: buildConfigMetadata.routeRootConfig
|
|
391
396
|
});
|
|
392
397
|
}
|
|
393
398
|
process.stdout.write("\x1B[0m");
|
|
394
399
|
const { printBuildReport } = await import("./build/report.js");
|
|
395
400
|
await printBuildReport({
|
|
396
|
-
root
|
|
401
|
+
root,
|
|
397
402
|
pageExtensions: resolvedNextConfig.pageExtensions,
|
|
398
403
|
prerenderResult: prerenderResult ?? void 0
|
|
399
404
|
});
|
|
@@ -466,7 +471,7 @@ async function check() {
|
|
|
466
471
|
if (parseArgs(rawArgs).help) return printHelp("check");
|
|
467
472
|
console.log(`\n vinext check\n`);
|
|
468
473
|
console.log(" Scanning project...\n");
|
|
469
|
-
const result = runCheck(
|
|
474
|
+
const result = runCheck(toSlash(process.cwd()));
|
|
470
475
|
console.log(formatReport(result));
|
|
471
476
|
}
|
|
472
477
|
async function typegen() {
|
|
@@ -477,11 +482,12 @@ async function typegen() {
|
|
|
477
482
|
root,
|
|
478
483
|
mode: "production"
|
|
479
484
|
});
|
|
480
|
-
const
|
|
485
|
+
const result = await generateRouteTypes({
|
|
481
486
|
root,
|
|
482
487
|
pageExtensions: (await resolveNextConfig(await loadNextConfig(root, PHASE_PRODUCTION_BUILD), root)).pageExtensions
|
|
483
488
|
});
|
|
484
|
-
|
|
489
|
+
const nextEnvMessage = result.nextEnvStatus === "unchanged" ? `${path.relative(root, result.nextEnvPath)} is up to date` : `${result.nextEnvStatus === "created" ? "Created" : "Updated"} ${path.relative(root, result.nextEnvPath)}`;
|
|
490
|
+
console.log(`\n Generated route types at ${path.relative(root, result.routeTypesPath)}\n ${nextEnvMessage}\n`);
|
|
485
491
|
}
|
|
486
492
|
async function initCommand() {
|
|
487
493
|
const parsed = parseArgs(rawArgs);
|
|
@@ -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/client/instrumentation-client-inject.ts
|
|
4
4
|
/** Resolve empty-module next to this file (.js in dist, .ts in source). */
|
|
5
5
|
function resolveInstrumentationClientEmptyModule(dir) {
|