vinext 0.2.1 → 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +67 -30
- package/dist/build/assets-ignore.js +1 -1
- package/dist/build/clean-output.js +1 -1
- package/dist/build/client-build-config.d.ts +13 -92
- package/dist/build/client-build-config.js +23 -99
- 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 +23 -0
- package/dist/build/prerender-paths.js +291 -0
- package/dist/build/prerender-server-pool.js +2 -2
- package/dist/build/prerender.d.ts +12 -1
- package/dist/build/prerender.js +2 -2
- package/dist/build/preview-credentials.d.ts +11 -0
- package/dist/build/preview-credentials.js +19 -0
- package/dist/build/report.d.ts +0 -3
- package/dist/build/report.js +2 -4
- 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 +7 -17
- package/dist/cache/cache-adapters-virtual.js +35 -2
- package/dist/check.d.ts +0 -16
- package/dist/check.js +17 -34
- package/dist/cli.js +86 -101
- package/dist/client/instrumentation-client-inject.js +1 -1
- package/dist/client/pages-router-link-navigation.js +1 -1
- package/dist/config/config-matchers.js +2 -2
- package/dist/config/dotenv.js +1 -1
- package/dist/config/next-config.d.ts +4 -1
- package/dist/config/next-config.js +82 -16
- package/dist/config/prerender.d.ts +12 -2
- package/dist/config/prerender.js +22 -12
- package/dist/config/server-external-packages.js +1 -1
- package/dist/config/tsconfig-paths.js +7 -3
- 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 +12 -5
- package/dist/entries/app-rsc-manifest.js +4 -4
- package/dist/entries/pages-client-entry.js +6 -5
- package/dist/entries/pages-server-entry.js +15 -26
- package/dist/entries/runtime-entry-module.js +2 -2
- package/dist/image/image-adapters-virtual.js +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +500 -338
- package/dist/init-cloudflare.js +13 -4
- package/dist/init-platform.d.ts +10 -1
- package/dist/init-platform.js +79 -13
- package/dist/init.d.ts +11 -3
- package/dist/init.js +133 -35
- 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 +4 -5
- 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 +3 -10
- package/dist/routing/app-route-graph.js +28 -76
- package/dist/routing/app-router.d.ts +0 -5
- package/dist/routing/app-router.js +0 -5
- package/dist/routing/file-matcher.d.ts +2 -6
- package/dist/routing/file-matcher.js +10 -11
- package/dist/routing/pages-router.js +3 -3
- package/dist/server/api-handler.js +41 -33
- package/dist/server/app-browser-entry.js +15 -11
- package/dist/server/app-browser-navigation-controller.js +9 -4
- 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 +8 -0
- package/dist/server/app-fallback-renderer.js +13 -1
- package/dist/server/app-layout-param-observation.d.ts +1 -1
- package/dist/server/app-page-boundary-render.d.ts +14 -1
- package/dist/server/app-page-boundary-render.js +107 -54
- package/dist/server/app-page-cache-render.d.ts +1 -1
- package/dist/server/app-page-dispatch.d.ts +2 -1
- package/dist/server/app-page-dispatch.js +29 -40
- package/dist/server/app-page-element-builder.d.ts +2 -1
- package/dist/server/app-page-element-builder.js +3 -3
- package/dist/server/app-page-execution.d.ts +3 -1
- package/dist/server/app-page-execution.js +31 -39
- package/dist/server/app-page-render.d.ts +1 -1
- package/dist/server/app-page-request.js +1 -1
- package/dist/server/app-page-route-wiring.js +4 -4
- package/dist/server/app-route-handler-execution.d.ts +1 -1
- package/dist/server/app-route-tree-prefetch.js +1 -1
- package/dist/server/app-rsc-cache-busting.js +1 -2
- package/dist/server/app-rsc-handler.js +2 -2
- 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-render-mode.d.ts +2 -5
- package/dist/server/app-rsc-render-mode.js +2 -12
- package/dist/server/app-segment-config.js +2 -2
- package/dist/server/app-server-action-execution.js +3 -3
- package/dist/server/app-ssr-entry.js +4 -1
- package/dist/server/app-ssr-stream.d.ts +2 -1
- package/dist/server/app-ssr-stream.js +4 -1
- package/dist/server/cache-proof.js +1 -1
- 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-lockfile.js +2 -3
- package/dist/server/dev-module-runner.js +1 -1
- package/dist/server/dev-origin-check.d.ts +2 -2
- package/dist/server/dev-origin-check.js +2 -2
- package/dist/server/dev-route-files.js +1 -1
- package/dist/server/dev-server.js +256 -164
- 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.d.ts +12 -1
- package/dist/server/image-optimization.js +15 -3
- package/dist/server/implicit-tags.js +2 -1
- package/dist/server/instrumentation.js +2 -2
- package/dist/server/isr-cache.d.ts +12 -4
- package/dist/server/isr-cache.js +3 -3
- package/dist/server/metadata-routes.js +4 -4
- package/dist/server/middleware-response-headers.js +1 -1
- package/dist/server/middleware-runtime.js +1 -1
- package/dist/server/middleware.d.ts +1 -0
- package/dist/server/middleware.js +1 -1
- 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-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-node-compat.d.ts +13 -6
- package/dist/server/pages-node-compat.js +44 -45
- package/dist/server/pages-page-data.d.ts +1 -1
- package/dist/server/pages-page-data.js +5 -4
- package/dist/server/pages-page-handler.js +61 -29
- package/dist/server/pages-page-response.d.ts +2 -2
- package/dist/server/pages-page-response.js +2 -2
- package/dist/server/pages-preview.d.ts +26 -0
- package/dist/server/pages-preview.js +165 -0
- package/dist/server/pages-readiness.d.ts +2 -1
- package/dist/server/pages-readiness.js +4 -2
- package/dist/server/pages-request-pipeline.js +1 -1
- package/dist/server/prerender-manifest.d.ts +15 -1
- package/dist/server/prerender-manifest.js +29 -1
- package/dist/server/prod-server.d.ts +6 -5
- package/dist/server/prod-server.js +15 -15
- package/dist/server/request-pipeline.js +1 -1
- package/dist/server/seed-cache.js +1 -1
- package/dist/server/socket-error-backstop.js +1 -1
- package/dist/server/static-file-cache.js +8 -9
- package/dist/server/worker-utils.js +1 -1
- package/dist/shims/cache.d.ts +1 -1
- package/dist/shims/cache.js +2 -1
- package/dist/shims/cdn-cache.d.ts +2 -7
- package/dist/shims/cdn-cache.js +2 -14
- package/dist/shims/constants.js +1 -1
- package/dist/shims/error-boundary.d.ts +4 -4
- package/dist/shims/error.d.ts +21 -5
- package/dist/shims/error.js +52 -14
- package/dist/shims/fetch-cache.js +1 -1
- package/dist/shims/font-utils.js +1 -1
- package/dist/shims/form.d.ts +1 -1
- package/dist/shims/head.js +3 -3
- package/dist/shims/headers.js +6 -4
- package/dist/shims/internal/pages-data-fetch-dedup.js +5 -3
- package/dist/shims/layout-segment-context.d.ts +1 -1
- package/dist/shims/link.d.ts +3 -1
- package/dist/shims/link.js +6 -3
- package/dist/shims/navigation-errors.d.ts +2 -1
- package/dist/shims/navigation-errors.js +9 -13
- package/dist/shims/navigation.d.ts +1 -1
- package/dist/shims/navigation.js +5 -5
- package/dist/shims/request-state-types.d.ts +2 -2
- package/dist/shims/router-state.d.ts +1 -0
- package/dist/shims/router.d.ts +2 -1
- package/dist/shims/router.js +18 -11
- package/dist/shims/script.js +1 -1
- package/dist/shims/server.js +2 -2
- 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/typegen.js +9 -11
- 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/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 +1 -7
- 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/vinext-root.js +1 -1
- package/dist/utils/vite-version.d.ts +6 -13
- package/dist/utils/vite-version.js +68 -34
- package/package.json +33 -14
- package/dist/cloudflare/index.d.ts +0 -3
- package/dist/cloudflare/index.js +0 -3
- package/dist/packages/cloudflare/src/cache/cdn-adapter.runtime.js +0 -102
- package/dist/packages/cloudflare/src/cache/kv-data-adapter.runtime.d.ts +0 -126
- package/dist/packages/cloudflare/src/cache/kv-data-adapter.runtime.js +0 -442
- package/dist/packages/cloudflare/src/deploy-config.js +0 -150
- package/dist/packages/cloudflare/src/deploy-help.js +0 -55
- package/dist/packages/cloudflare/src/deploy.js +0 -272
- package/dist/packages/cloudflare/src/tpr.d.ts +0 -45
- package/dist/packages/cloudflare/src/tpr.js +0 -582
- package/dist/packages/cloudflare/src/utils/cache-control-metadata.js +0 -20
- /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.
|
|
@@ -41,10 +25,16 @@ type VinextCacheConfig = {
|
|
|
41
25
|
};
|
|
42
26
|
/** Public virtual module id imported by the server entries. */
|
|
43
27
|
declare const VIRTUAL_CACHE_ADAPTERS = "virtual:vinext-cache-adapters";
|
|
28
|
+
declare const VINEXT_CACHE_CONFIG_PLUGIN_PROPERTY = "__vinextCacheConfig";
|
|
29
|
+
type ViteConfigLoader = {
|
|
30
|
+
loadConfigFromFile: typeof import("vite").loadConfigFromFile;
|
|
31
|
+
};
|
|
32
|
+
declare function findVinextCacheConfigInPlugins(plugins: import("vite").PluginOption[] | undefined): Promise<VinextCacheConfig | null>;
|
|
33
|
+
declare function loadVinextCacheConfigFromViteConfig(vite: ViteConfigLoader, root: string): Promise<VinextCacheConfig | null>;
|
|
44
34
|
/**
|
|
45
35
|
* Generate the source of the `virtual:vinext-cache-adapters` module for the
|
|
46
36
|
* given config. Always exports `registerConfiguredCacheAdapters(env)`.
|
|
47
37
|
*/
|
|
48
38
|
declare function generateCacheAdaptersModule(cache?: VinextCacheConfig): string;
|
|
49
39
|
//#endregion
|
|
50
|
-
export { VIRTUAL_CACHE_ADAPTERS, VinextCacheConfig, generateCacheAdaptersModule };
|
|
40
|
+
export { VINEXT_CACHE_CONFIG_PLUGIN_PROPERTY, VIRTUAL_CACHE_ADAPTERS, VinextCacheConfig, findVinextCacheConfigInPlugins, generateCacheAdaptersModule, loadVinextCacheConfigFromViteConfig };
|
|
@@ -1,6 +1,39 @@
|
|
|
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";
|
|
21
|
+
const VINEXT_CACHE_CONFIG_PLUGIN_PROPERTY = "__vinextCacheConfig";
|
|
22
|
+
async function findVinextCacheConfigInPlugins(plugins) {
|
|
23
|
+
const flattened = await flattenPluginOptions(plugins);
|
|
24
|
+
for (const plugin of flattened) {
|
|
25
|
+
if (!plugin || typeof plugin !== "object") continue;
|
|
26
|
+
const cacheConfig = plugin[VINEXT_CACHE_CONFIG_PLUGIN_PROPERTY];
|
|
27
|
+
if (cacheConfig) return cacheConfig;
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
async function loadVinextCacheConfigFromViteConfig(vite, root) {
|
|
32
|
+
return await findVinextCacheConfigInPlugins((await vite.loadConfigFromFile({
|
|
33
|
+
command: "build",
|
|
34
|
+
mode: "production"
|
|
35
|
+
}, void 0, root))?.config.plugins);
|
|
36
|
+
}
|
|
4
37
|
/**
|
|
5
38
|
* Serialize descriptor options into a JS expression for inlining. Plain JSON is
|
|
6
39
|
* a valid JS literal; `undefined` when there are no options. Throws a clear
|
|
@@ -35,11 +68,11 @@ function generateCacheAdaptersModule(cache) {
|
|
|
35
68
|
lines.push(`import __vinextCdnAdapterFactory from ${JSON.stringify(cdn.adapter)};`);
|
|
36
69
|
lines.push(`import { setCdnCacheAdapter } from "vinext/shims/cdn-cache";`);
|
|
37
70
|
}
|
|
38
|
-
lines.push("", "// A factory that throws (e.g. a missing binding on an incompatible runtime)", "// is logged and skipped so the default handler stays in place.", "function __vinextFormatAdapterError(error) {", " if (error instanceof Error && error.message) return error.message;", " try {", " return String(error);", " } catch {", " return '<unknown error>';", " }", "}", "", "let __vinextCacheAdaptersRegistered = false;", "", "export function registerConfiguredCacheAdapters(env) {", " if (__vinextCacheAdaptersRegistered) return;", " __vinextCacheAdaptersRegistered = true;");
|
|
71
|
+
lines.push("", "// A factory that throws (e.g. a missing binding on an incompatible runtime)", "// is logged and skipped so the default handler stays in place.", "function __vinextFormatAdapterError(error) {", " if (error instanceof Error && error.message) return error.message;", " try {", " return String(error);", " } catch {", " return '<unknown error>';", " }", "}", "", "let __vinextCacheAdaptersRegistered = false;", "", "export function registerConfiguredCacheAdapters(env) {", " if (typeof process !== 'undefined' && process.env?.__VINEXT_PRERENDER_PATH_DISCOVERY === '1') return;", " if (__vinextCacheAdaptersRegistered) return;", " __vinextCacheAdaptersRegistered = true;");
|
|
39
72
|
if (data?.adapter) lines.push(" try {", ` setDataCacheHandler(__vinextDataAdapterFactory({ env, options: ${inlineOptions(data.adapter, data.options)} }));`, " } catch (error) {", " console.warn(\"[vinext] failed to initialize the configured data cache adapter; using the default handler.\\n\" + __vinextFormatAdapterError(error));", " }");
|
|
40
73
|
if (cdn?.adapter) lines.push(" try {", ` setCdnCacheAdapter(__vinextCdnAdapterFactory({ env, options: ${inlineOptions(cdn.adapter, cdn.options)} }));`, " } catch (error) {", " console.warn(\"[vinext] failed to initialize the configured CDN cache adapter; using the default adapter.\\n\" + __vinextFormatAdapterError(error));", " }");
|
|
41
74
|
lines.push("}", "");
|
|
42
75
|
return lines.join("\n");
|
|
43
76
|
}
|
|
44
77
|
//#endregion
|
|
45
|
-
export { VIRTUAL_CACHE_ADAPTERS, generateCacheAdaptersModule };
|
|
78
|
+
export { VINEXT_CACHE_CONFIG_PLUGIN_PROPERTY, VIRTUAL_CACHE_ADAPTERS, findVinextCacheConfigInPlugins, generateCacheAdaptersModule, loadVinextCacheConfigFromViteConfig };
|
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
|
/**
|
|
@@ -215,6 +214,10 @@ const CONFIG_SUPPORT = {
|
|
|
215
214
|
status: "supported",
|
|
216
215
|
detail: "sourcemap-resolved stack traces during prerender"
|
|
217
216
|
},
|
|
217
|
+
cacheComponents: {
|
|
218
|
+
status: "partial",
|
|
219
|
+
detail: "experimental support; behavior is incomplete"
|
|
220
|
+
},
|
|
218
221
|
"experimental.ppr": {
|
|
219
222
|
status: "unsupported",
|
|
220
223
|
detail: "partial prerendering not yet implemented"
|
|
@@ -367,11 +370,6 @@ const LIBRARY_SUPPORT = {
|
|
|
367
370
|
};
|
|
368
371
|
/**
|
|
369
372
|
* Recursively find all source files in a directory.
|
|
370
|
-
*
|
|
371
|
-
* `dir` must be forward-slash, and the returned paths are forward-slash too:
|
|
372
|
-
* each entry is joined with `path.posix.join`, which only stays canonical when
|
|
373
|
-
* the base already is. This keeps downstream substring checks (e.g.
|
|
374
|
-
* `f.includes("/api/")`) and reported paths consistent across platforms.
|
|
375
373
|
*/
|
|
376
374
|
function findSourceFiles(dir, extensions = [
|
|
377
375
|
".ts",
|
|
@@ -384,7 +382,7 @@ function findSourceFiles(dir, extensions = [
|
|
|
384
382
|
if (!fs.existsSync(dir)) return results;
|
|
385
383
|
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
386
384
|
for (const entry of entries) {
|
|
387
|
-
const fullPath = path.
|
|
385
|
+
const fullPath = path.join(dir, entry.name);
|
|
388
386
|
if (entry.isDirectory()) {
|
|
389
387
|
if (entry.name === "node_modules" || entry.name === ".next" || entry.name === "dist" || entry.name === ".git") continue;
|
|
390
388
|
results.push(...findSourceFiles(fullPath, extensions));
|
|
@@ -398,8 +396,8 @@ function isIdentStart(c) {
|
|
|
398
396
|
function isIdentChar(c) {
|
|
399
397
|
return c >= "a" && c <= "z" || c >= "A" && c <= "Z" || c >= "0" && c <= "9" || c === "_" || c === "$";
|
|
400
398
|
}
|
|
401
|
-
const CJS_GLOBALS = new Set(["__dirname", "__filename"]);
|
|
402
|
-
const REGEX_PRECEDING_KEYWORDS = new Set([
|
|
399
|
+
const CJS_GLOBALS = /* @__PURE__ */ new Set(["__dirname", "__filename"]);
|
|
400
|
+
const REGEX_PRECEDING_KEYWORDS = /* @__PURE__ */ new Set([
|
|
403
401
|
"return",
|
|
404
402
|
"typeof",
|
|
405
403
|
"instanceof",
|
|
@@ -588,9 +586,6 @@ function hasFreeCjsGlobal(content) {
|
|
|
588
586
|
}
|
|
589
587
|
/**
|
|
590
588
|
* Scan source files for `import ... from 'next/...'` statements.
|
|
591
|
-
*
|
|
592
|
-
* `root` must be forward-slash: it is passed to `findSourceFiles`, which
|
|
593
|
-
* requires it.
|
|
594
589
|
*/
|
|
595
590
|
function scanImports(root) {
|
|
596
591
|
const files = findSourceFiles(root);
|
|
@@ -608,7 +603,7 @@ function scanImports(root) {
|
|
|
608
603
|
if (mod.startsWith("next/") || mod === "next" || mod === "server-only" || mod === "client-only") {
|
|
609
604
|
const normalized = mod === "next" ? "next" : mod;
|
|
610
605
|
if (!importUsage.has(normalized)) importUsage.set(normalized, []);
|
|
611
|
-
const relFile =
|
|
606
|
+
const relFile = path.relative(root, file);
|
|
612
607
|
const usedInFiles = importUsage.get(normalized) ?? [];
|
|
613
608
|
if (!usedInFiles.includes(relFile)) usedInFiles.push(relFile);
|
|
614
609
|
}
|
|
@@ -735,9 +730,6 @@ function collectConfigKeys(source) {
|
|
|
735
730
|
}
|
|
736
731
|
/**
|
|
737
732
|
* Analyze next.config.js/mjs/ts for supported and unsupported options.
|
|
738
|
-
*
|
|
739
|
-
* `root` must be forward-slash — joined with `path.posix.join`. Only called
|
|
740
|
-
* from `runCheck`, which normalizes it.
|
|
741
733
|
*/
|
|
742
734
|
function analyzeConfig(root) {
|
|
743
735
|
const configFiles = [
|
|
@@ -749,7 +741,7 @@ function analyzeConfig(root) {
|
|
|
749
741
|
];
|
|
750
742
|
let configPath = null;
|
|
751
743
|
for (const f of configFiles) {
|
|
752
|
-
const p = path.
|
|
744
|
+
const p = path.join(root, f);
|
|
753
745
|
if (fs.existsSync(p)) {
|
|
754
746
|
configPath = p;
|
|
755
747
|
break;
|
|
@@ -775,6 +767,7 @@ function analyzeConfig(root) {
|
|
|
775
767
|
"output",
|
|
776
768
|
"transpilePackages",
|
|
777
769
|
"webpack",
|
|
770
|
+
"cacheComponents",
|
|
778
771
|
"reactStrictMode",
|
|
779
772
|
"poweredByHeader",
|
|
780
773
|
"skipMiddlewareUrlNormalize",
|
|
@@ -806,12 +799,9 @@ function analyzeConfig(root) {
|
|
|
806
799
|
}
|
|
807
800
|
/**
|
|
808
801
|
* Check package.json dependencies for known libraries.
|
|
809
|
-
*
|
|
810
|
-
* `root` must be forward-slash — joined with `path.posix.join`. Only called
|
|
811
|
-
* from `runCheck`, which normalizes it.
|
|
812
802
|
*/
|
|
813
803
|
function checkLibraries(root) {
|
|
814
|
-
const pkgPath = path.
|
|
804
|
+
const pkgPath = path.join(root, "package.json");
|
|
815
805
|
if (!fs.existsSync(pkgPath)) return [];
|
|
816
806
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
817
807
|
const allDeps = {
|
|
@@ -829,16 +819,13 @@ function checkLibraries(root) {
|
|
|
829
819
|
}
|
|
830
820
|
/**
|
|
831
821
|
* Check file conventions (pages, app directory, middleware, etc.)
|
|
832
|
-
*
|
|
833
|
-
* `root` must be forward-slash — joined with `path.posix.join` and passed to
|
|
834
|
-
* `findDir`. Only called from `runCheck`, which normalizes it.
|
|
835
822
|
*/
|
|
836
823
|
function checkConventions(root) {
|
|
837
824
|
const items = [];
|
|
838
825
|
const pagesDir = findDir(root, "pages", "src/pages");
|
|
839
826
|
const appDirPath = findDir(root, "app", "src/app");
|
|
840
|
-
const hasProxy = fs.existsSync(path.
|
|
841
|
-
const hasMiddleware = fs.existsSync(path.
|
|
827
|
+
const hasProxy = fs.existsSync(path.join(root, "proxy.ts")) || fs.existsSync(path.join(root, "proxy.js"));
|
|
828
|
+
const hasMiddleware = fs.existsSync(path.join(root, "middleware.ts")) || fs.existsSync(path.join(root, "middleware.js"));
|
|
842
829
|
if (pagesDir !== null) {
|
|
843
830
|
const isSrc = pagesDir.includes("src/pages");
|
|
844
831
|
items.push({
|
|
@@ -916,7 +903,7 @@ function checkConventions(root) {
|
|
|
916
903
|
status: "unsupported",
|
|
917
904
|
detail: "vinext requires a pages/ or app/ directory"
|
|
918
905
|
});
|
|
919
|
-
const pkgPath = path.
|
|
906
|
+
const pkgPath = path.join(root, "package.json");
|
|
920
907
|
if (fs.existsSync(pkgPath)) {
|
|
921
908
|
if (JSON.parse(fs.readFileSync(pkgPath, "utf-8")).type !== "module") items.push({
|
|
922
909
|
name: "Missing \"type\": \"module\" in package.json",
|
|
@@ -930,7 +917,7 @@ function checkConventions(root) {
|
|
|
930
917
|
const cjsGlobalFiles = [];
|
|
931
918
|
for (const file of allSourceFiles) {
|
|
932
919
|
const content = fs.readFileSync(file, "utf-8");
|
|
933
|
-
const rel =
|
|
920
|
+
const rel = path.relative(root, file);
|
|
934
921
|
if (viewTransitionRegex.test(content)) viewTransitionFiles.push(rel);
|
|
935
922
|
if (hasFreeCjsGlobal(content)) cjsGlobalFiles.push(rel);
|
|
936
923
|
}
|
|
@@ -945,7 +932,7 @@ function checkConventions(root) {
|
|
|
945
932
|
"postcss.config.js",
|
|
946
933
|
"postcss.config.cjs"
|
|
947
934
|
]) {
|
|
948
|
-
const configPath = path.
|
|
935
|
+
const configPath = path.join(root, configFile);
|
|
949
936
|
if (fs.existsSync(configPath)) {
|
|
950
937
|
const content = fs.readFileSync(configPath, "utf-8");
|
|
951
938
|
if (/plugins\s*:\s*\[\s*['"]/.test(content)) items.push({
|
|
@@ -966,10 +953,6 @@ function checkConventions(root) {
|
|
|
966
953
|
}
|
|
967
954
|
/**
|
|
968
955
|
* Run the full compatibility check.
|
|
969
|
-
*
|
|
970
|
-
* `root` must be forward-slash — callers normalize it at the CLI entry, and it
|
|
971
|
-
* is forwarded to `scanImports` / `checkConventions` / `findDir`, which build
|
|
972
|
-
* paths with `path.posix.*`.
|
|
973
956
|
*/
|
|
974
957
|
function runCheck(root) {
|
|
975
958
|
const imports = scanImports(root);
|