vinext 0.2.0 → 0.2.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/dist/build/css-url-assets.d.ts +3 -1
- package/dist/build/css-url-assets.js +18 -1
- package/dist/build/inject-pregenerated-paths.d.ts +3 -0
- package/dist/build/inject-pregenerated-paths.js +4 -1
- package/dist/build/prerender-server-entry.d.ts +1 -0
- package/dist/build/prerender-server-entry.js +49 -0
- package/dist/build/prerender-server-pool.d.ts +44 -0
- package/dist/build/prerender-server-pool.js +194 -0
- package/dist/build/prerender.js +86 -22
- package/dist/build/run-prerender.js +2 -1
- package/dist/check.d.ts +4 -6
- package/dist/check.js +8 -9
- package/dist/cli.js +1 -1
- package/dist/client/vinext-next-data.d.ts +4 -1
- package/dist/config/config-matchers.js +33 -11
- package/dist/config/next-config.d.ts +36 -6
- package/dist/config/next-config.js +16 -2
- package/dist/entries/app-browser-entry.js +5 -1
- package/dist/entries/app-rsc-entry.d.ts +3 -2
- package/dist/entries/app-rsc-entry.js +4 -0
- package/dist/entries/pages-client-entry.js +14 -3
- package/dist/entries/pages-server-entry.js +18 -4
- package/dist/index.js +320 -25
- package/dist/packages/cloudflare/src/cache/kv-data-adapter.runtime.js +8 -1
- package/dist/packages/cloudflare/src/deploy.js +1 -5
- package/dist/packages/cloudflare/src/tpr.js +26 -5
- package/dist/plugins/fonts.js +1 -1
- package/dist/plugins/ignore-dynamic-requests.js +1 -1
- package/dist/plugins/og-assets.js +2 -1
- package/dist/plugins/optimize-imports.js +1 -1
- package/dist/plugins/rsc-reference-validation-normalizer.d.ts +12 -0
- package/dist/plugins/rsc-reference-validation-normalizer.js +48 -0
- package/dist/plugins/sass.d.ts +17 -1
- package/dist/plugins/sass.js +74 -1
- package/dist/plugins/styled-jsx.d.ts +16 -0
- package/dist/plugins/styled-jsx.js +149 -0
- package/dist/routing/app-route-graph.js +22 -16
- package/dist/routing/file-matcher.d.ts +8 -1
- package/dist/routing/file-matcher.js +15 -3
- package/dist/server/app-browser-entry.js +46 -14
- package/dist/server/app-browser-navigation-controller.js +1 -1
- package/dist/server/app-browser-server-action-client.js +5 -3
- package/dist/server/app-browser-state.d.ts +1 -0
- package/dist/server/app-browser-state.js +2 -2
- package/dist/server/app-browser-visible-commit.js +1 -1
- package/dist/server/app-page-boundary.js +2 -1
- package/dist/server/app-page-cache-finalizer.d.ts +1 -0
- package/dist/server/app-page-cache-finalizer.js +3 -3
- package/dist/server/app-page-cache.js +23 -6
- package/dist/server/app-page-dispatch.d.ts +1 -0
- package/dist/server/app-page-dispatch.js +25 -8
- package/dist/server/app-page-element-builder.js +1 -0
- package/dist/server/app-page-execution.js +2 -1
- package/dist/server/app-page-render-identity.d.ts +1 -0
- package/dist/server/app-page-render-identity.js +2 -1
- package/dist/server/app-page-render.d.ts +2 -0
- package/dist/server/app-page-render.js +67 -16
- package/dist/server/app-page-response.d.ts +7 -0
- package/dist/server/app-page-response.js +16 -4
- package/dist/server/app-page-stream.d.ts +2 -1
- package/dist/server/app-page-stream.js +1 -1
- package/dist/server/app-route-handler-execution.js +1 -1
- package/dist/server/app-route-tree-prefetch.d.ts +43 -0
- package/dist/server/app-route-tree-prefetch.js +187 -0
- package/dist/server/app-router-entry.js +1 -1
- package/dist/server/app-rsc-cache-busting.d.ts +2 -1
- package/dist/server/app-rsc-cache-busting.js +9 -4
- package/dist/server/app-rsc-handler.d.ts +6 -0
- package/dist/server/app-rsc-handler.js +89 -11
- package/dist/server/app-rsc-render-mode.d.ts +3 -2
- package/dist/server/app-rsc-render-mode.js +4 -1
- package/dist/server/app-rsc-request-normalization.d.ts +3 -4
- package/dist/server/app-rsc-request-normalization.js +4 -5
- package/dist/server/app-server-action-execution.js +4 -3
- package/dist/server/app-ssr-entry.js +3 -3
- package/dist/server/cache-control.d.ts +3 -1
- package/dist/server/cache-control.js +13 -1
- package/dist/server/dev-server.d.ts +11 -1
- package/dist/server/dev-server.js +78 -20
- package/dist/server/headers.d.ts +6 -2
- package/dist/server/headers.js +11 -5
- package/dist/server/isr-cache.d.ts +2 -1
- package/dist/server/isr-cache.js +7 -3
- package/dist/server/pages-data-route.d.ts +4 -2
- package/dist/server/pages-data-route.js +18 -4
- package/dist/server/pages-dev-module-url.d.ts +2 -1
- package/dist/server/pages-dev-module-url.js +6 -3
- package/dist/server/pages-node-compat.d.ts +12 -1
- package/dist/server/pages-node-compat.js +50 -1
- package/dist/server/pages-page-data.d.ts +9 -0
- package/dist/server/pages-page-data.js +17 -9
- package/dist/server/pages-page-handler.js +19 -7
- package/dist/server/pages-page-response.d.ts +1 -0
- package/dist/server/pages-page-response.js +3 -2
- package/dist/server/pages-request-pipeline.d.ts +8 -6
- package/dist/server/pages-request-pipeline.js +30 -6
- package/dist/server/pages-router-entry.js +1 -1
- package/dist/server/prod-server.d.ts +4 -2
- package/dist/server/prod-server.js +38 -22
- package/dist/server/request-pipeline.js +1 -1
- package/dist/shims/cache-handler.js +8 -1
- package/dist/shims/cache.js +3 -0
- package/dist/shims/fetch-cache.d.ts +3 -1
- package/dist/shims/fetch-cache.js +77 -52
- package/dist/shims/form.d.ts +1 -1
- package/dist/shims/internal/app-prefetch-fetch-queue.d.ts +10 -0
- package/dist/shims/internal/app-prefetch-fetch-queue.js +61 -0
- package/dist/shims/internal/hybrid-client-route-owner.d.ts +2 -1
- package/dist/shims/internal/hybrid-client-route-owner.js +34 -1
- package/dist/shims/internal/pages-data-fetch-dedup.d.ts +2 -1
- package/dist/shims/internal/pages-data-fetch-dedup.js +13 -2
- package/dist/shims/internal/pages-data-target.d.ts +8 -3
- package/dist/shims/internal/pages-data-target.js +9 -4
- package/dist/shims/link.d.ts +1 -1
- package/dist/shims/link.js +179 -42
- package/dist/shims/navigation.d.ts +15 -3
- package/dist/shims/navigation.js +202 -39
- package/dist/shims/navigation.react-server.js +1 -1
- package/dist/shims/request-context.js +18 -0
- package/dist/shims/router.js +31 -15
- package/dist/shims/unified-request-context.js +1 -0
- package/dist/typegen.js +1 -1
- package/dist/utils/middleware-request-headers.js +1 -1
- package/dist/utils/protocol-headers.d.ts +7 -1
- package/dist/utils/protocol-headers.js +7 -1
- package/dist/utils/vite-version.d.ts +2 -0
- package/dist/utils/vite-version.js +11 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { detectPackageManager, formatMissingCloudflarePluginError, hasWranglerConfig } from "./utils/project.js";
|
|
2
|
+
import { normalizePathSeparators, stripJsExtension, stripViteModuleQuery } from "./utils/path.js";
|
|
2
3
|
import { normalizePathnameForRouteMatchStrict } from "./routing/utils.js";
|
|
3
4
|
import { escapeRegExp } from "./utils/regex.js";
|
|
4
|
-
import { normalizePathSeparators, stripJsExtension, stripViteModuleQuery } from "./utils/path.js";
|
|
5
5
|
import { buildViteResolveExtensions, createValidFileMatcher, findFileWithExts, normalizeViteResolveExtensions } from "./routing/file-matcher.js";
|
|
6
6
|
import { apiRouter, invalidateRouteCache, matchRoute, pagesRouter } from "./routing/pages-router.js";
|
|
7
7
|
import { VINEXT_MW_CTX_HEADER } from "./utils/protocol-headers.js";
|
|
@@ -11,15 +11,16 @@ import { matchesRewriteSource, proxyExternalRequest } from "./config/config-matc
|
|
|
11
11
|
import { isOpenRedirectShaped } from "./server/open-redirect.js";
|
|
12
12
|
import { filterInternalHeaders, normalizeTrailingSlash } from "./server/request-pipeline.js";
|
|
13
13
|
import { findMiddlewareFile, isProxyFile, runMiddleware } from "./server/middleware.js";
|
|
14
|
+
import { extractMiddlewareMatcherConfig, hasExportedName } from "./build/report.js";
|
|
14
15
|
import { generateServerEntry } from "./entries/pages-server-entry.js";
|
|
15
|
-
import { extractMiddlewareMatcherConfig } from "./build/report.js";
|
|
16
16
|
import { generateClientEntry } from "./entries/pages-client-entry.js";
|
|
17
17
|
import { appRouteGraph, appRouter, invalidateAppRouteCache, matchAppRoute } from "./routing/app-router.js";
|
|
18
18
|
import { findInstrumentationClientFile, findInstrumentationFile, runInstrumentation } from "./server/instrumentation.js";
|
|
19
19
|
import { isUnknownRecord } from "./utils/record.js";
|
|
20
20
|
import { logRequest, now } from "./server/request-log.js";
|
|
21
|
-
import { resolvePagesI18nRequest } from "./server/pages-i18n.js";
|
|
22
|
-
import { isNextDataPathname, parseNextDataPathname } from "./server/pages-data-route.js";
|
|
21
|
+
import { resolvePagesI18nRequest, stripI18nLocaleForApiRoute } from "./server/pages-i18n.js";
|
|
22
|
+
import { isNextDataPathname, normalizeNextDataPagePathname, parseNextDataPathname } from "./server/pages-data-route.js";
|
|
23
|
+
import { resolveAssetsDir } from "./utils/asset-prefix.js";
|
|
23
24
|
import { createSSRHandler } from "./server/dev-server.js";
|
|
24
25
|
import { handleApiRoute } from "./server/api-handler.js";
|
|
25
26
|
import { DEFAULT_DEVICE_SIZES, DEFAULT_IMAGE_SIZES, isImageOptimizationPath, resolveDevImageRedirect } from "./server/image-optimization.js";
|
|
@@ -36,7 +37,6 @@ import { generateBrowserEntry, isLinkPrefetchRoute, toDocumentOnlyAppRoute, toLi
|
|
|
36
37
|
import { collectRouteClassificationManifest } from "./build/route-classification-manifest.js";
|
|
37
38
|
import { planRouteClassificationInjection } from "./build/route-classification-injector.js";
|
|
38
39
|
import { PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD } from "./shims/constants.js";
|
|
39
|
-
import { resolveAssetsDir } from "./utils/asset-prefix.js";
|
|
40
40
|
import { RESOLVED_VIRTUAL_GOOGLE_FONTS, VIRTUAL_GOOGLE_FONTS, createGoogleFontsPlugin, createLocalFontsPlugin, generateGoogleFontsVirtualModule, parseStaticObjectLiteral } from "./plugins/fonts.js";
|
|
41
41
|
import { getDepOptimizeNodeEnvOptions, getViteMajorVersion, serializeViteDefine } from "./utils/vite-version.js";
|
|
42
42
|
import { createRscCompatibilityId, findNextConfigPath, loadNextConfig, resolveNextConfig, resolveNextConfigInput } from "./config/next-config.js";
|
|
@@ -55,7 +55,9 @@ import { clientReferenceDedupPlugin } from "./plugins/client-reference-dedup.js"
|
|
|
55
55
|
import { dataUrlCssPlugin } from "./plugins/css-data-url.js";
|
|
56
56
|
import { createCssModuleImportCompatibilityPlugin } from "./plugins/css-module-imports.js";
|
|
57
57
|
import { createRscClientReferenceLoadersPlugin } from "./plugins/rsc-client-reference-loaders.js";
|
|
58
|
+
import { createRscReferenceValidationNormalizerPlugin } from "./plugins/rsc-reference-validation-normalizer.js";
|
|
58
59
|
import { createInstrumentationClientTransformPlugin } from "./plugins/instrumentation-client.js";
|
|
60
|
+
import { createStyledJsxPlugin } from "./plugins/styled-jsx.js";
|
|
59
61
|
import { INSTRUMENTATION_CLIENT_EMPTY_MODULE, generateInstrumentationClientInjectModule } from "./client/instrumentation-client-inject.js";
|
|
60
62
|
import { createMiddlewareServerOnlyPlugin } from "./plugins/middleware-server-only.js";
|
|
61
63
|
import { validateMiddlewareModuleExports } from "./plugins/middleware-export-validation.js";
|
|
@@ -70,9 +72,9 @@ import { VINEXT_CLIENT_ENTRY_MANIFEST } from "./utils/client-entry-manifest.js";
|
|
|
70
72
|
import { computeClientRuntimeMetadata } from "./utils/client-runtime-metadata.js";
|
|
71
73
|
import { PAGES_CLIENT_ASSETS_MODULE, buildPagesClientAssetsModule, setPagesClientAssetsBuildMetadata, takePagesClientAssetsBuildMetadata, writePagesClientAssetsModuleIfMissing } from "./build/pages-client-assets-module.js";
|
|
72
74
|
import { resolvePostcssStringPlugins } from "./plugins/postcss.js";
|
|
73
|
-
import { buildSassPreprocessorOptions, createSassAwareFileSystemLoader, createSassTildeImporter } from "./plugins/sass.js";
|
|
74
|
-
import { createClientAssetFileNames, createClientCodeSplittingConfig, createClientFileNameConfig, createClientManualChunks, createClientOutputConfig, createRscFrameworkChunkOutputConfig, getBuildBundlerOptions, getClientTreeshakeConfigForVite, withBuildBundlerOptions } from "./build/client-build-config.js";
|
|
75
75
|
import { markCssUrlAssetReferences, restoreDedupedCssAssetReferences } from "./build/css-url-assets.js";
|
|
76
|
+
import { buildSassPreprocessorOptions, createSassAwareFileSystemLoader, createSassCssUrlAssetImporter, createSassTildeImporter } from "./plugins/sass.js";
|
|
77
|
+
import { createClientAssetFileNames, createClientCodeSplittingConfig, createClientFileNameConfig, createClientManualChunks, createClientOutputConfig, createRscFrameworkChunkOutputConfig, getBuildBundlerOptions, getClientTreeshakeConfigForVite, withBuildBundlerOptions } from "./build/client-build-config.js";
|
|
76
78
|
import { hasExportAllCandidate, stripServerExports, validatePageExports } from "./plugins/strip-server-exports.js";
|
|
77
79
|
import { removeConsoleCalls } from "./plugins/remove-console.js";
|
|
78
80
|
import { createImportMetaUrlPlugin } from "./plugins/import-meta-url.js";
|
|
@@ -94,6 +96,18 @@ import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
|
94
96
|
import commonjs from "vite-plugin-commonjs";
|
|
95
97
|
import MagicString from "magic-string";
|
|
96
98
|
//#region src/index.ts
|
|
99
|
+
const PAGES_CLOUDFLARE_WORKER_OPTIMIZE_DEPS_EXCLUDE = Object.freeze(["vinext/server/fetch-handler", "vinext/server/pages-router-entry"]);
|
|
100
|
+
const PAGES_CLOUDFLARE_WORKER_OPTIMIZE_DEPS_INCLUDE = Object.freeze([
|
|
101
|
+
"react",
|
|
102
|
+
"react-dom",
|
|
103
|
+
"react-dom/server.edge",
|
|
104
|
+
"react/jsx-runtime",
|
|
105
|
+
"react/jsx-dev-runtime",
|
|
106
|
+
"use-sync-external-store/with-selector"
|
|
107
|
+
]);
|
|
108
|
+
const OPTIONAL_OPTIMIZE_DEPS_WARNING_RE = /Failed to resolve dependency: .*use-sync-external-store\/with-selector.*present in .* 'optimizeDeps\.include'/;
|
|
109
|
+
const VINEXT_FILTERED_OPTIMIZE_DEPS_WARN = Symbol.for("vinext.filteredOptimizeDepsWarn");
|
|
110
|
+
const ANSI_ESCAPE_RE = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`, "g");
|
|
97
111
|
installSocketErrorBackstop();
|
|
98
112
|
function getCacheDirPrefix(cacheDir) {
|
|
99
113
|
const normalizedCacheDir = normalizePathSeparators(cacheDir);
|
|
@@ -172,6 +186,122 @@ function isVinextOgShimImporter(importer) {
|
|
|
172
186
|
function toRelativeFileEntry(root, absPath) {
|
|
173
187
|
return path.relative(root, absPath).split(path.sep).join("/");
|
|
174
188
|
}
|
|
189
|
+
const DEV_PAGES_CLIENT_ENTRY = "/@id/__x00__virtual:vinext-client-entry";
|
|
190
|
+
const STYLESHEET_IMPORT_RE = /\.(?:css|scss|sass)$/i;
|
|
191
|
+
const STYLESHEET_FILE_RE = /\.(?:css|scss|sass)$/i;
|
|
192
|
+
const SCRIPT_IMPORT_RE = /\.(?:[cm]?[jt]sx?)$/i;
|
|
193
|
+
const GLOBAL_NOT_FOUND_CSS_QUERY = "?vinext-global-not-found-css";
|
|
194
|
+
function toMagicStringTransformResult(output) {
|
|
195
|
+
return {
|
|
196
|
+
code: output.toString(),
|
|
197
|
+
map: output.generateMap({ hires: "boundary" })
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
function parserLanguageForScript(id) {
|
|
201
|
+
const cleanId = stripViteModuleQuery(id).toLowerCase();
|
|
202
|
+
return cleanId.endsWith(".ts") || cleanId.endsWith(".mts") || cleanId.endsWith(".cts") ? "ts" : "tsx";
|
|
203
|
+
}
|
|
204
|
+
function isStylesheetSpecifier(specifier) {
|
|
205
|
+
if (specifier.includes("?") || specifier.includes("#")) return false;
|
|
206
|
+
return STYLESHEET_IMPORT_RE.test(specifier.toLowerCase());
|
|
207
|
+
}
|
|
208
|
+
function isMdxModuleId(id) {
|
|
209
|
+
return stripViteModuleQuery(id).toLowerCase().endsWith(".mdx");
|
|
210
|
+
}
|
|
211
|
+
function isolateMdxStylesheetImports(code) {
|
|
212
|
+
const importRe = /(^|[;\n])(\s*import\s*)(["'])([^"'\n;]+)(\3)/g;
|
|
213
|
+
let output = null;
|
|
214
|
+
for (const match of code.matchAll(importRe)) {
|
|
215
|
+
const specifier = match[4];
|
|
216
|
+
if (!isStylesheetSpecifier(specifier)) continue;
|
|
217
|
+
const specifierStart = match.index + match[1].length + match[2].length + match[3].length;
|
|
218
|
+
const specifierEnd = specifierStart + specifier.length;
|
|
219
|
+
output ??= new MagicString(code);
|
|
220
|
+
output.overwrite(specifierStart, specifierEnd, specifier + GLOBAL_NOT_FOUND_CSS_QUERY);
|
|
221
|
+
}
|
|
222
|
+
return output ? toMagicStringTransformResult(output) : null;
|
|
223
|
+
}
|
|
224
|
+
function isolateGlobalNotFoundStylesheetImports(code, id) {
|
|
225
|
+
if (isMdxModuleId(id)) return isolateMdxStylesheetImports(code);
|
|
226
|
+
let ast;
|
|
227
|
+
try {
|
|
228
|
+
ast = parseAst(code, { lang: parserLanguageForScript(id) });
|
|
229
|
+
} catch {
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
let output = null;
|
|
233
|
+
for (const statement of ast.body) {
|
|
234
|
+
if (statement.type !== "ImportDeclaration" || statement.importKind === "type") continue;
|
|
235
|
+
if (statement.specifiers && statement.specifiers.length > 0) continue;
|
|
236
|
+
if (statement.attributes && statement.attributes.length > 0) continue;
|
|
237
|
+
const source = statement.source;
|
|
238
|
+
const specifier = source?.value;
|
|
239
|
+
if (typeof specifier !== "string" || !isStylesheetSpecifier(specifier)) continue;
|
|
240
|
+
const range = source;
|
|
241
|
+
if (typeof range.start !== "number" || typeof range.end !== "number") continue;
|
|
242
|
+
output ??= new MagicString(code);
|
|
243
|
+
output.overwrite(range.start, range.end, JSON.stringify(specifier + GLOBAL_NOT_FOUND_CSS_QUERY));
|
|
244
|
+
}
|
|
245
|
+
return output ? toMagicStringTransformResult(output) : null;
|
|
246
|
+
}
|
|
247
|
+
function isScriptModuleId(id) {
|
|
248
|
+
return SCRIPT_IMPORT_RE.test(stripViteModuleQuery(id).toLowerCase());
|
|
249
|
+
}
|
|
250
|
+
function skipCommonjsForLocalCjs(id) {
|
|
251
|
+
const cleanId = normalizePathSeparators(stripViteModuleQuery(id));
|
|
252
|
+
return /\.c[jt]s$/i.test(cleanId) && !cleanId.includes("node_modules") ? false : void 0;
|
|
253
|
+
}
|
|
254
|
+
function hasOnlyTypeSpecifiers(statement) {
|
|
255
|
+
return statement.specifiers !== void 0 && statement.specifiers.length > 0 && statement.specifiers.every((specifier) => specifier.importKind === "type" || specifier.exportKind === "type");
|
|
256
|
+
}
|
|
257
|
+
function resolvedStylesheetToDevManifestAsset(root, resolvedId) {
|
|
258
|
+
const cleanId = stripViteModuleQuery(resolvedId);
|
|
259
|
+
if (!path.isAbsolute(cleanId)) return null;
|
|
260
|
+
const rootForRelative = tryRealpathSync(root) ?? root;
|
|
261
|
+
const fileForRelative = tryRealpathSync(cleanId) ?? cleanId;
|
|
262
|
+
const relativePath = path.relative(rootForRelative, fileForRelative);
|
|
263
|
+
if (relativePath !== "" && !relativePath.startsWith("..") && !path.isAbsolute(relativePath)) return normalizePathSeparators(relativePath);
|
|
264
|
+
return `@fs/${normalizePathSeparators(cleanId).replace(/^\/+/, "")}`;
|
|
265
|
+
}
|
|
266
|
+
async function collectDevPagesAppStylesheetAssets(root, appFilePath, resolve) {
|
|
267
|
+
const stylesheetAssets = [];
|
|
268
|
+
const seenAssets = /* @__PURE__ */ new Set();
|
|
269
|
+
const seenModules = /* @__PURE__ */ new Set();
|
|
270
|
+
async function visitModule(modulePath) {
|
|
271
|
+
const cleanModulePath = stripViteModuleQuery(modulePath);
|
|
272
|
+
if (!path.isAbsolute(cleanModulePath) || !fs.existsSync(cleanModulePath)) return;
|
|
273
|
+
if (seenModules.has(cleanModulePath)) return;
|
|
274
|
+
seenModules.add(cleanModulePath);
|
|
275
|
+
let ast;
|
|
276
|
+
try {
|
|
277
|
+
ast = parseAst(fs.readFileSync(cleanModulePath, "utf-8"), { lang: parserLanguageForScript(cleanModulePath) });
|
|
278
|
+
} catch {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
for (const statement of ast.body) {
|
|
282
|
+
if (statement.type !== "ImportDeclaration" && statement.type !== "ExportNamedDeclaration" && statement.type !== "ExportAllDeclaration") continue;
|
|
283
|
+
if (statement.importKind === "type") continue;
|
|
284
|
+
if (statement.exportKind === "type") continue;
|
|
285
|
+
if (hasOnlyTypeSpecifiers(statement)) continue;
|
|
286
|
+
if (statement.attributes && statement.attributes.length > 0) continue;
|
|
287
|
+
const specifier = statement.source?.value;
|
|
288
|
+
if (typeof specifier !== "string") continue;
|
|
289
|
+
const resolved = await resolve(specifier, cleanModulePath, { skipSelf: true });
|
|
290
|
+
if (!resolved?.id) continue;
|
|
291
|
+
if (isStylesheetSpecifier(specifier)) {
|
|
292
|
+
const asset = resolvedStylesheetToDevManifestAsset(root, resolved.id);
|
|
293
|
+
if (!asset || seenAssets.has(asset)) continue;
|
|
294
|
+
seenAssets.add(asset);
|
|
295
|
+
stylesheetAssets.push(asset);
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
if (specifier.includes("?") || specifier.includes("#")) continue;
|
|
299
|
+
if (isScriptModuleId(resolved.id)) await visitModule(resolved.id);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
await visitModule(appFilePath);
|
|
303
|
+
return stylesheetAssets;
|
|
304
|
+
}
|
|
175
305
|
const TSCONFIG_FILES = ["tsconfig.json", "jsconfig.json"];
|
|
176
306
|
function resolveTsconfigPathCandidate(candidate) {
|
|
177
307
|
const candidates = candidate.endsWith(".json") ? [candidate] : [
|
|
@@ -306,6 +436,22 @@ function getVinextVersion() {
|
|
|
306
436
|
}
|
|
307
437
|
return _vinextVersionCache;
|
|
308
438
|
}
|
|
439
|
+
function mergeStringArrayValues(value, additions) {
|
|
440
|
+
return [...new Set([...value === void 0 ? [] : Array.isArray(value) ? value : [value], ...additions])];
|
|
441
|
+
}
|
|
442
|
+
function stripAnsi(value) {
|
|
443
|
+
return value.replace(ANSI_ESCAPE_RE, "");
|
|
444
|
+
}
|
|
445
|
+
function suppressOptionalOptimizeDepsWarnings(logger) {
|
|
446
|
+
const marker = logger;
|
|
447
|
+
if (marker[VINEXT_FILTERED_OPTIMIZE_DEPS_WARN]) return;
|
|
448
|
+
const warn = logger.warn.bind(logger);
|
|
449
|
+
logger.warn = (msg, options) => {
|
|
450
|
+
if (OPTIONAL_OPTIMIZE_DEPS_WARNING_RE.test(stripAnsi(msg))) return;
|
|
451
|
+
warn(msg, options);
|
|
452
|
+
};
|
|
453
|
+
marker[VINEXT_FILTERED_OPTIMIZE_DEPS_WARN] = true;
|
|
454
|
+
}
|
|
309
455
|
const _tsconfigAliasCache = /* @__PURE__ */ new Map();
|
|
310
456
|
function resolveTsconfigAliases(projectRoot) {
|
|
311
457
|
if (_tsconfigAliasCache.has(projectRoot)) return _tsconfigAliasCache.get(projectRoot);
|
|
@@ -483,10 +629,13 @@ function vinext(options = {}) {
|
|
|
483
629
|
let instrumentationPath = null;
|
|
484
630
|
let instrumentationClientPath = null;
|
|
485
631
|
let clientInjectModule = null;
|
|
632
|
+
let globalNotFoundCssIsolationPath = null;
|
|
486
633
|
let clientAssetsInlineLimit = 0;
|
|
487
634
|
let hasCloudflarePlugin = false;
|
|
488
635
|
let warnedInlineNextConfigOverride = false;
|
|
489
636
|
let hasNitroPlugin = false;
|
|
637
|
+
let isServeCommand = false;
|
|
638
|
+
let pagesOptimizeEntries = [];
|
|
490
639
|
const pagesClientAssetsOutputDirs = /* @__PURE__ */ new Set();
|
|
491
640
|
let pagesClientAssetsModule = null;
|
|
492
641
|
let rscCompatibilityId;
|
|
@@ -626,9 +775,26 @@ function vinext(options = {}) {
|
|
|
626
775
|
}
|
|
627
776
|
const plugins = [
|
|
628
777
|
...viteMajorVersion >= 8 ? [] : [loadVite7TsconfigPathsPlugin(earlyBaseDir)],
|
|
778
|
+
createStyledJsxPlugin(earlyBaseDir),
|
|
629
779
|
reactPluginPromise,
|
|
630
780
|
createIgnoreDynamicRequestsPlugin(() => nextConfig?.turbopackTranspilePackages ?? []),
|
|
631
|
-
commonjs(),
|
|
781
|
+
commonjs({ filter: skipCommonjsForLocalCjs }),
|
|
782
|
+
{
|
|
783
|
+
name: "vinext:global-not-found-css-isolation",
|
|
784
|
+
apply: "build",
|
|
785
|
+
enforce: "pre",
|
|
786
|
+
transform: {
|
|
787
|
+
filter: {
|
|
788
|
+
id: /(?:^|[/\\])global-not-found(?:\.[^./?\\]+)+(?:\?.*)?$/,
|
|
789
|
+
code: /\.(?:css|scss|sass)['"]/
|
|
790
|
+
},
|
|
791
|
+
handler(code, id) {
|
|
792
|
+
const cleanId = normalizePathSeparators(stripViteModuleQuery(id));
|
|
793
|
+
if (!globalNotFoundCssIsolationPath || canonicalize(cleanId) !== canonicalize(globalNotFoundCssIsolationPath)) return null;
|
|
794
|
+
return isolateGlobalNotFoundStylesheetImports(code, cleanId);
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
},
|
|
632
798
|
...viteMajorVersion >= 8 ? [{
|
|
633
799
|
name: "vinext:jsx-in-js",
|
|
634
800
|
enforce: "pre",
|
|
@@ -669,6 +835,7 @@ function vinext(options = {}) {
|
|
|
669
835
|
enforce: "pre",
|
|
670
836
|
[VINEXT_PRERENDER_CONFIG_PLUGIN_PROPERTY]: prerenderConfig,
|
|
671
837
|
async config(config, env) {
|
|
838
|
+
isServeCommand = env.command === "serve";
|
|
672
839
|
root = normalizePathSeparators(config.root ?? process.cwd());
|
|
673
840
|
const userResolve = config.resolve;
|
|
674
841
|
const shouldEnableNativeTsconfigPaths = viteMajorVersion >= 8 && userResolve?.tsconfigPaths === void 0;
|
|
@@ -721,6 +888,7 @@ function vinext(options = {}) {
|
|
|
721
888
|
rscCompatibilityId = sharedRscCompatibilityId && sharedRscCompatibilityId.length > 0 ? sharedRscCompatibilityId : createRscCompatibilityId(nextConfig);
|
|
722
889
|
}
|
|
723
890
|
fileMatcher = createValidFileMatcher(nextConfig.pageExtensions);
|
|
891
|
+
globalNotFoundCssIsolationPath = env?.command === "build" && nextConfig.globalNotFound ? findFileWithExts(appDir, "global-not-found", fileMatcher) : null;
|
|
724
892
|
instrumentationPath = findInstrumentationFile(root, fileMatcher);
|
|
725
893
|
instrumentationClientPath = findInstrumentationClientFile(root, fileMatcher);
|
|
726
894
|
const middlewareConventionDir = canonicalize(baseDir) === canonicalize(path.posix.join(root, "src")) ? path.posix.join(root, "src") : root;
|
|
@@ -934,7 +1102,13 @@ function vinext(options = {}) {
|
|
|
934
1102
|
],
|
|
935
1103
|
...shouldEnableNativeTsconfigPaths ? { tsconfigPaths: true } : {}
|
|
936
1104
|
},
|
|
937
|
-
...viteMajorVersion >= 8 ? { oxc: {
|
|
1105
|
+
...viteMajorVersion >= 8 ? { oxc: {
|
|
1106
|
+
jsx: { runtime: "automatic" },
|
|
1107
|
+
typescript: { onlyRemoveTypeImports: false }
|
|
1108
|
+
} } : { esbuild: {
|
|
1109
|
+
jsx: "automatic",
|
|
1110
|
+
tsconfigRaw: { compilerOptions: { verbatimModuleSyntax: false } }
|
|
1111
|
+
} },
|
|
938
1112
|
define: defines,
|
|
939
1113
|
...nextConfig.basePath ? { base: nextConfig.basePath + "/" } : {},
|
|
940
1114
|
...nextConfig.assetPrefix || nextConfig.deploymentId ? { experimental: { renderBuiltUrl: (filename, context) => renderVinextBuiltUrl(filename, nextConfig.assetPrefix, nextConfig.deploymentId, context.hostType) } } : {},
|
|
@@ -949,9 +1123,19 @@ function vinext(options = {}) {
|
|
|
949
1123
|
...postcssOverride ? { postcss: postcssOverride } : {},
|
|
950
1124
|
preprocessorOptions: (() => {
|
|
951
1125
|
const tildeImporter = createSassTildeImporter(root);
|
|
1126
|
+
const cssUrlAssetImporter = env.command === "build" ? createSassCssUrlAssetImporter() : null;
|
|
1127
|
+
const userAdditionalData = sassPreprocessorOptions?.additionalData;
|
|
952
1128
|
const baseOpts = {
|
|
953
1129
|
...sassPreprocessorOptions,
|
|
954
|
-
|
|
1130
|
+
...cssUrlAssetImporter ? { additionalData: async (source, filename) => {
|
|
1131
|
+
const withUserData = typeof userAdditionalData === "function" ? await userAdditionalData(source, filename) : typeof userAdditionalData === "string" ? `${userAdditionalData}${source}` : source;
|
|
1132
|
+
return cssUrlAssetImporter.rewriteImports(withUserData, filename);
|
|
1133
|
+
} } : {},
|
|
1134
|
+
importers: [
|
|
1135
|
+
tildeImporter,
|
|
1136
|
+
...cssUrlAssetImporter ? [cssUrlAssetImporter] : [],
|
|
1137
|
+
...sassPreprocessorOptions?.importers ?? []
|
|
1138
|
+
]
|
|
955
1139
|
};
|
|
956
1140
|
return {
|
|
957
1141
|
scss: baseOpts,
|
|
@@ -982,7 +1166,7 @@ function vinext(options = {}) {
|
|
|
982
1166
|
plugins: [depOptimizeAliasPlugin]
|
|
983
1167
|
}
|
|
984
1168
|
};
|
|
985
|
-
|
|
1169
|
+
pagesOptimizeEntries = !hasAppDir ? [...hasPagesDir ? [toRelativeFileEntry(root, pagesDir) + "/**/*.{tsx,ts,jsx,js}"] : [], ...[instrumentationPath, instrumentationClientPath].flatMap((entry) => entry ? [toRelativeFileEntry(root, entry)] : [])] : [];
|
|
986
1170
|
if (hasAppDir) {
|
|
987
1171
|
const appEntries = [`${path.relative(root, appDir)}/**/*.{tsx,ts,jsx,js}`];
|
|
988
1172
|
const explicitInstrumentationEntries = [instrumentationPath, instrumentationClientPath].flatMap((entry) => entry ? [toRelativeFileEntry(root, entry)] : []);
|
|
@@ -1046,7 +1230,8 @@ function vinext(options = {}) {
|
|
|
1046
1230
|
"react-dom/client",
|
|
1047
1231
|
"react/jsx-runtime",
|
|
1048
1232
|
"react/jsx-dev-runtime"
|
|
1049
|
-
])]
|
|
1233
|
+
])],
|
|
1234
|
+
...depOptimizeNodeEnvOptions
|
|
1050
1235
|
},
|
|
1051
1236
|
build: {
|
|
1052
1237
|
manifest: true,
|
|
@@ -1062,7 +1247,10 @@ function vinext(options = {}) {
|
|
|
1062
1247
|
};
|
|
1063
1248
|
} else if (hasCloudflarePlugin) viteConfig.environments = { client: {
|
|
1064
1249
|
consumer: "client",
|
|
1065
|
-
optimizeDeps:
|
|
1250
|
+
optimizeDeps: {
|
|
1251
|
+
...pagesOptimizeEntries.length > 0 ? { entries: pagesOptimizeEntries } : {},
|
|
1252
|
+
...depOptimizeNodeEnvOptions
|
|
1253
|
+
},
|
|
1066
1254
|
build: {
|
|
1067
1255
|
manifest: true,
|
|
1068
1256
|
ssrManifest: true,
|
|
@@ -1077,7 +1265,10 @@ function vinext(options = {}) {
|
|
|
1077
1265
|
else if (shouldInjectPlainPagesEnvironments) viteConfig.environments = {
|
|
1078
1266
|
client: {
|
|
1079
1267
|
consumer: "client",
|
|
1080
|
-
optimizeDeps:
|
|
1268
|
+
optimizeDeps: {
|
|
1269
|
+
...pagesOptimizeEntries.length > 0 ? { entries: pagesOptimizeEntries } : {},
|
|
1270
|
+
...depOptimizeNodeEnvOptions
|
|
1271
|
+
},
|
|
1081
1272
|
build: {
|
|
1082
1273
|
outDir: "dist/client",
|
|
1083
1274
|
manifest: true,
|
|
@@ -1121,6 +1312,12 @@ function vinext(options = {}) {
|
|
|
1121
1312
|
return viteConfig;
|
|
1122
1313
|
},
|
|
1123
1314
|
configEnvironment(name, config) {
|
|
1315
|
+
if (isServeCommand && hasCloudflarePlugin && hasPagesDir && !hasAppDir && name !== "client") {
|
|
1316
|
+
config.optimizeDeps ??= {};
|
|
1317
|
+
config.optimizeDeps.entries = mergeStringArrayValues(config.optimizeDeps.entries, pagesOptimizeEntries);
|
|
1318
|
+
config.optimizeDeps.include = mergeStringArrayValues(config.optimizeDeps.include, PAGES_CLOUDFLARE_WORKER_OPTIMIZE_DEPS_INCLUDE);
|
|
1319
|
+
config.optimizeDeps.exclude = mergeOptimizeDepsExclude(config.optimizeDeps.exclude ?? [], VINEXT_OPTIMIZE_DEPS_EXCLUDE, PAGES_CLOUDFLARE_WORKER_OPTIMIZE_DEPS_EXCLUDE);
|
|
1320
|
+
}
|
|
1124
1321
|
const configuredExtensions = name === "client" ? nextConfig.resolveExtensions : nextConfig.serverResolveExtensions;
|
|
1125
1322
|
const extensions = configuredExtensions === null ? buildViteResolveExtensions(nextConfig.pageExtensions, config.resolve?.extensions) : normalizeViteResolveExtensions(configuredExtensions);
|
|
1126
1323
|
config.resolve ??= {};
|
|
@@ -1130,6 +1327,7 @@ function vinext(options = {}) {
|
|
|
1130
1327
|
async configResolved(config) {
|
|
1131
1328
|
const cacheDirPrefix = getCacheDirPrefix(config.cacheDir);
|
|
1132
1329
|
typeofWindowIdFilter.exclude = new RegExp(`^${escapeRegExp(cacheDirPrefix)}`);
|
|
1330
|
+
if (isServeCommand && hasCloudflarePlugin && hasPagesDir && !hasAppDir) suppressOptionalOptimizeDepsWarnings(config.logger);
|
|
1133
1331
|
sassComposesLoader.setResolvedConfig(config);
|
|
1134
1332
|
if (config.command === "build" && hasAppDir && hasPagesDir) {
|
|
1135
1333
|
const [appRoutes, pageRoutes, apiRoutes] = await Promise.all([
|
|
@@ -1207,7 +1405,19 @@ function vinext(options = {}) {
|
|
|
1207
1405
|
if (id === RESOLVED_WORKER_ENTRY) return `export { default } from ${JSON.stringify(hasAppDir ? "vinext/server/app-router-entry" : "vinext/server/pages-router-entry")};`;
|
|
1208
1406
|
if (id === RESOLVED_SERVER_ENTRY) return await generateServerEntry$1();
|
|
1209
1407
|
if (id === RESOLVED_CLIENT_ENTRY) return await generateClientEntry$1();
|
|
1210
|
-
if (id === RESOLVED_PAGES_CLIENT_ASSETS)
|
|
1408
|
+
if (id === RESOLVED_PAGES_CLIENT_ASSETS) {
|
|
1409
|
+
const metadata = { clientEntry: DEV_PAGES_CLIENT_ENTRY };
|
|
1410
|
+
const ssrManifest = {};
|
|
1411
|
+
const appFilePath = findFileWithExts(pagesDir, "_app", fileMatcher);
|
|
1412
|
+
const pagesRoutes = await pagesRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher);
|
|
1413
|
+
const moduleFilePaths = [...appFilePath ? [appFilePath] : [], ...pagesRoutes.map((route) => route.filePath)];
|
|
1414
|
+
for (const moduleFilePath of moduleFilePaths) {
|
|
1415
|
+
const stylesheetAssets = await collectDevPagesAppStylesheetAssets(root, moduleFilePath, this.resolve.bind(this));
|
|
1416
|
+
if (stylesheetAssets.length > 0) ssrManifest[normalizePathSeparators(moduleFilePath)] = stylesheetAssets;
|
|
1417
|
+
}
|
|
1418
|
+
if (Object.keys(ssrManifest).length > 0) metadata.ssrManifest = ssrManifest;
|
|
1419
|
+
return `export default ${JSON.stringify(metadata)};`;
|
|
1420
|
+
}
|
|
1211
1421
|
if (id === RESOLVED_RSC_ENTRY && hasAppDir) {
|
|
1212
1422
|
const routes = await appRouter(appDir, nextConfig?.pageExtensions, fileMatcher);
|
|
1213
1423
|
const metaRoutes = scanMetadataFiles(appDir);
|
|
@@ -1232,6 +1442,7 @@ function vinext(options = {}) {
|
|
|
1232
1442
|
inlineCss: nextConfig?.inlineCss,
|
|
1233
1443
|
globalNotFound: nextConfig?.globalNotFound,
|
|
1234
1444
|
cacheComponents: nextConfig?.cacheComponents,
|
|
1445
|
+
prefetchInlining: nextConfig?.prefetchInlining,
|
|
1235
1446
|
hasServerActions,
|
|
1236
1447
|
i18n: nextConfig?.i18n,
|
|
1237
1448
|
imageConfig: {
|
|
@@ -1478,7 +1689,32 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1478
1689
|
{
|
|
1479
1690
|
name: "vinext:pages-router",
|
|
1480
1691
|
hotUpdate(options) {
|
|
1481
|
-
if (!hasPagesDir
|
|
1692
|
+
if (!hasPagesDir) return;
|
|
1693
|
+
const isPagesAppFile = (filePath) => {
|
|
1694
|
+
const relativePath = normalizePathSeparators(path.relative(pagesDir, filePath));
|
|
1695
|
+
return !relativePath.includes("/") && relativePath.startsWith("_app.") && fileMatcher.extensionRegex.test(filePath);
|
|
1696
|
+
};
|
|
1697
|
+
const isPotentialPagesAssetGraphScript = (filePath) => {
|
|
1698
|
+
const cleanPath = stripViteModuleQuery(filePath);
|
|
1699
|
+
if (!path.isAbsolute(cleanPath)) return false;
|
|
1700
|
+
if (!isScriptModuleId(cleanPath) || cleanPath.endsWith(".d.ts")) return false;
|
|
1701
|
+
const relativeRootPath = normalizePathSeparators(path.relative(root, cleanPath));
|
|
1702
|
+
if (relativeRootPath.startsWith("..") || path.isAbsolute(relativeRootPath)) return false;
|
|
1703
|
+
if (relativeRootPath.includes("/node_modules/") || relativeRootPath.startsWith("node_modules/")) return false;
|
|
1704
|
+
const relativeAppPath = normalizePathSeparators(path.relative(appDir, cleanPath));
|
|
1705
|
+
return relativeAppPath.startsWith("..") || path.isAbsolute(relativeAppPath);
|
|
1706
|
+
};
|
|
1707
|
+
const pagesAppChanged = isPagesAppFile(options.file);
|
|
1708
|
+
const pagesAssetGraphScriptChanged = isPotentialPagesAssetGraphScript(options.file);
|
|
1709
|
+
if (pagesAppChanged || STYLESHEET_FILE_RE.test(options.file) || pagesAssetGraphScriptChanged) for (const env of Object.values(options.server.environments)) {
|
|
1710
|
+
const mod = env.moduleGraph.getModuleById(RESOLVED_PAGES_CLIENT_ASSETS);
|
|
1711
|
+
if (mod) env.moduleGraph.invalidateModule(mod);
|
|
1712
|
+
}
|
|
1713
|
+
if (pagesAppChanged || !hasAppDir && pagesAssetGraphScriptChanged) {
|
|
1714
|
+
options.server.ws.send({ type: "full-reload" });
|
|
1715
|
+
return [];
|
|
1716
|
+
}
|
|
1717
|
+
if (hasAppDir) return;
|
|
1482
1718
|
if (options.file.startsWith(pagesDir) && fileMatcher.extensionRegex.test(options.file)) {
|
|
1483
1719
|
options.server.environments.client.hot.send({ type: "full-reload" });
|
|
1484
1720
|
return [];
|
|
@@ -1531,6 +1767,14 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1531
1767
|
}
|
|
1532
1768
|
pagesRunner?.clearCache();
|
|
1533
1769
|
}
|
|
1770
|
+
function invalidatePagesClientAssetsModule(reloadDocument = false) {
|
|
1771
|
+
for (const env of Object.values(server.environments)) {
|
|
1772
|
+
const mod = env.moduleGraph.getModuleById(RESOLVED_PAGES_CLIENT_ASSETS);
|
|
1773
|
+
if (mod) env.moduleGraph.invalidateModule(mod);
|
|
1774
|
+
}
|
|
1775
|
+
pagesRunner?.clearCache();
|
|
1776
|
+
if (reloadDocument) server.ws.send({ type: "full-reload" });
|
|
1777
|
+
}
|
|
1534
1778
|
function invalidateAppRoutingModules() {
|
|
1535
1779
|
invalidateAppRouteCache();
|
|
1536
1780
|
invalidateMetadataFileCache();
|
|
@@ -1578,6 +1822,20 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1578
1822
|
}
|
|
1579
1823
|
let appRouteTypeGeneration = null;
|
|
1580
1824
|
let appRouteTypeGenerationPending = false;
|
|
1825
|
+
function isPagesAppFile(filePath) {
|
|
1826
|
+
const relativePath = normalizePathSeparators(path.relative(pagesDir, filePath));
|
|
1827
|
+
return !relativePath.includes("/") && relativePath.startsWith("_app.") && fileMatcher.extensionRegex.test(filePath);
|
|
1828
|
+
}
|
|
1829
|
+
function isPotentialPagesAssetGraphScript(filePath) {
|
|
1830
|
+
const cleanPath = stripViteModuleQuery(filePath);
|
|
1831
|
+
if (!path.isAbsolute(cleanPath)) return false;
|
|
1832
|
+
if (!isScriptModuleId(cleanPath) || cleanPath.endsWith(".d.ts")) return false;
|
|
1833
|
+
const relativeRootPath = normalizePathSeparators(path.relative(root, cleanPath));
|
|
1834
|
+
if (relativeRootPath.startsWith("..") || path.isAbsolute(relativeRootPath)) return false;
|
|
1835
|
+
if (relativeRootPath.includes("/node_modules/") || relativeRootPath.startsWith("node_modules/")) return false;
|
|
1836
|
+
const relativeAppPath = normalizePathSeparators(path.relative(appDir, cleanPath));
|
|
1837
|
+
return relativeAppPath.startsWith("..") || path.isAbsolute(relativeAppPath);
|
|
1838
|
+
}
|
|
1581
1839
|
function warnRouteTypeGenerationFailure(error) {
|
|
1582
1840
|
server.config.logger.warn(`[vinext] Failed to regenerate route types: ${error instanceof Error ? error.message : String(error)}`);
|
|
1583
1841
|
}
|
|
@@ -1606,6 +1864,9 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1606
1864
|
});
|
|
1607
1865
|
server.watcher.on("add", (filePath) => {
|
|
1608
1866
|
let routeChanged = false;
|
|
1867
|
+
const pagesAppChanged = isPagesAppFile(filePath);
|
|
1868
|
+
const pagesAssetGraphScriptChanged = isPotentialPagesAssetGraphScript(filePath);
|
|
1869
|
+
if (hasPagesDir && (pagesAppChanged || STYLESHEET_FILE_RE.test(filePath) || pagesAssetGraphScriptChanged)) invalidatePagesClientAssetsModule(pagesAppChanged || !hasAppDir && pagesAssetGraphScriptChanged);
|
|
1609
1870
|
if (hasPagesDir && filePath.startsWith(pagesDir) && pageExtensions.test(filePath)) {
|
|
1610
1871
|
invalidateRouteCache(pagesDir);
|
|
1611
1872
|
routeChanged = true;
|
|
@@ -1621,8 +1882,16 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1621
1882
|
revalidateHybridRoutes();
|
|
1622
1883
|
}
|
|
1623
1884
|
});
|
|
1885
|
+
server.watcher.on("change", (filePath) => {
|
|
1886
|
+
const pagesAppChanged = isPagesAppFile(filePath);
|
|
1887
|
+
const pagesAssetGraphScriptChanged = isPotentialPagesAssetGraphScript(filePath);
|
|
1888
|
+
if (hasPagesDir && (pagesAppChanged || STYLESHEET_FILE_RE.test(filePath) || pagesAssetGraphScriptChanged)) invalidatePagesClientAssetsModule(pagesAppChanged || !hasAppDir && pagesAssetGraphScriptChanged);
|
|
1889
|
+
});
|
|
1624
1890
|
server.watcher.on("unlink", (filePath) => {
|
|
1625
1891
|
let routeChanged = false;
|
|
1892
|
+
const pagesAppChanged = isPagesAppFile(filePath);
|
|
1893
|
+
const pagesAssetGraphScriptChanged = isPotentialPagesAssetGraphScript(filePath);
|
|
1894
|
+
if (hasPagesDir && (pagesAppChanged || STYLESHEET_FILE_RE.test(filePath) || pagesAssetGraphScriptChanged)) invalidatePagesClientAssetsModule(pagesAppChanged || !hasAppDir && pagesAssetGraphScriptChanged);
|
|
1626
1895
|
if (hasPagesDir && filePath.startsWith(pagesDir) && pageExtensions.test(filePath)) {
|
|
1627
1896
|
invalidateRouteCache(pagesDir);
|
|
1628
1897
|
routeChanged = true;
|
|
@@ -1774,8 +2043,11 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1774
2043
|
res.end("Forbidden");
|
|
1775
2044
|
return;
|
|
1776
2045
|
}
|
|
2046
|
+
const requestHost = (Array.isArray(req.headers.host) ? req.headers.host[0] : req.headers.host) || "localhost";
|
|
2047
|
+
const requestOrigin = `http://${requestHost}`;
|
|
2048
|
+
const getUrlHostname = (requestUrl) => new URL(requestUrl).hostname;
|
|
1777
2049
|
if (isImageOptimizationPath(url.split("?")[0])) {
|
|
1778
|
-
const encodedLocation = resolveDevImageRedirect(new URL(url,
|
|
2050
|
+
const encodedLocation = resolveDevImageRedirect(new URL(url, requestOrigin), [...nextConfig.images?.deviceSizes ?? DEFAULT_DEVICE_SIZES, ...nextConfig.images?.imageSizes ?? DEFAULT_IMAGE_SIZES], nextConfig.images?.qualities);
|
|
1779
2051
|
if (!encodedLocation) {
|
|
1780
2052
|
res.writeHead(400);
|
|
1781
2053
|
res.end("Invalid image optimization parameters");
|
|
@@ -1806,6 +2078,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1806
2078
|
const qs = url.includes("?") ? url.slice(url.indexOf("?")) : "";
|
|
1807
2079
|
url = pathname + qs;
|
|
1808
2080
|
}
|
|
2081
|
+
const capturedMiddlewarePath = middlewarePath;
|
|
1809
2082
|
const bp = nextConfig?.basePath ?? "";
|
|
1810
2083
|
if (bp && pathname.startsWith(bp)) {
|
|
1811
2084
|
const stripped = pathname.slice(bp.length) || "/";
|
|
@@ -1830,8 +2103,9 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1830
2103
|
if (dataMatch) {
|
|
1831
2104
|
isDataReq = true;
|
|
1832
2105
|
const qs = url.includes("?") ? url.slice(url.indexOf("?")) : "";
|
|
1833
|
-
|
|
1834
|
-
|
|
2106
|
+
const pagePathname = normalizeNextDataPagePathname(dataMatch.pagePathname, capturedMiddlewarePath !== null && nextConfig?.trailingSlash === true);
|
|
2107
|
+
url = pagePathname + qs;
|
|
2108
|
+
pathname = pagePathname;
|
|
1835
2109
|
req.url = url;
|
|
1836
2110
|
} else {
|
|
1837
2111
|
const deploymentId = process.env.__VINEXT_DEPLOYMENT_ID || process.env.NEXT_DEPLOYMENT_ID;
|
|
@@ -1850,13 +2124,21 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1850
2124
|
basePath: bp,
|
|
1851
2125
|
hadBasePath: true
|
|
1852
2126
|
}));
|
|
1853
|
-
|
|
2127
|
+
const isFilePathRequest = pathname.includes(".") && !pathname.endsWith(".html");
|
|
2128
|
+
let filePathMatchesPagesRoute = false;
|
|
2129
|
+
const requestHostname = getUrlHostname(requestOrigin);
|
|
2130
|
+
if (isFilePathRequest && !filePathMatchesRewrite) {
|
|
2131
|
+
const [pageRoutes, apiRoutes] = await Promise.all([pagesRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher), apiRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher)]);
|
|
2132
|
+
const pageRouteUrl = nextConfig?.i18n ? resolvePagesI18nRequest(pathname, nextConfig.i18n, req.headers, requestHostname, bp, nextConfig.trailingSlash ?? false).url : pathname;
|
|
2133
|
+
const apiRouteUrl = stripI18nLocaleForApiRoute(pathname, nextConfig?.i18n ?? null);
|
|
2134
|
+
filePathMatchesPagesRoute = matchRoute(pageRouteUrl, pageRoutes) !== null || matchRoute(apiRouteUrl, apiRoutes) !== null;
|
|
2135
|
+
}
|
|
2136
|
+
if (isFilePathRequest && !filePathMatchesRewrite && !filePathMatchesPagesRoute) return next();
|
|
1854
2137
|
const rawHeaders = new Headers(Object.fromEntries(Object.entries(req.headers).filter(([k, v]) => v !== void 0 && !k.startsWith(":")).map(([k, v]) => [k, Array.isArray(v) ? v.join(", ") : String(v)])));
|
|
1855
2138
|
const isDataRequest = isDataReq;
|
|
1856
2139
|
const nodeRequestHeaders = filterInternalHeaders(rawHeaders);
|
|
1857
2140
|
for (const header of INTERNAL_HEADERS) delete req.headers[header];
|
|
1858
2141
|
for (const header of VINEXT_INTERNAL_HEADERS) delete req.headers[header];
|
|
1859
|
-
const requestOrigin = `http://${req.headers.host || "localhost"}`;
|
|
1860
2142
|
const method = req.method ?? "GET";
|
|
1861
2143
|
const webRequest = new Request(new URL(url, requestOrigin), {
|
|
1862
2144
|
method,
|
|
@@ -1866,10 +2148,9 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1866
2148
|
for (const key of Object.keys(req.headers)) delete req.headers[key];
|
|
1867
2149
|
for (const [key, value] of nextRequestHeaders) req.headers[key] = value;
|
|
1868
2150
|
};
|
|
1869
|
-
const capturedMiddlewarePath = middlewarePath;
|
|
1870
2151
|
const devRunMiddlewareAdapter = capturedMiddlewarePath ? async (_request, _ctx, opts) => {
|
|
1871
2152
|
const rawProto = process.env.VINEXT_TRUST_PROXY === "1" || (process.env.VINEXT_TRUSTED_HOSTS ?? "").split(",").some((h) => h.trim()) ? String(req.headers["x-forwarded-proto"] || "").split(",")[0].trim() : "";
|
|
1872
|
-
const mwOrigin = `${rawProto === "https" || rawProto === "http" ? rawProto : "http"}://${
|
|
2153
|
+
const mwOrigin = `${rawProto === "https" || rawProto === "http" ? rawProto : "http"}://${requestHost}`;
|
|
1873
2154
|
const middlewareRequest = new Request(new URL(url, mwOrigin), {
|
|
1874
2155
|
method: req.method,
|
|
1875
2156
|
headers: nodeRequestHeaders
|
|
@@ -1890,6 +2171,18 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1890
2171
|
return result;
|
|
1891
2172
|
} : null;
|
|
1892
2173
|
const devPageRoutes = await pagesRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher);
|
|
2174
|
+
const devPageRouteDataKinds = /* @__PURE__ */ new Map();
|
|
2175
|
+
const classifyDevPageRoute = (route) => {
|
|
2176
|
+
const cached = devPageRouteDataKinds.get(route.filePath);
|
|
2177
|
+
if (cached) return cached;
|
|
2178
|
+
let dataKind = "none";
|
|
2179
|
+
try {
|
|
2180
|
+
const source = fs.readFileSync(route.filePath, "utf8");
|
|
2181
|
+
dataKind = hasExportedName(source, "getStaticProps") ? "static" : hasExportedName(source, "getServerSideProps") ? "server" : "none";
|
|
2182
|
+
} catch {}
|
|
2183
|
+
devPageRouteDataKinds.set(route.filePath, dataKind);
|
|
2184
|
+
return dataKind;
|
|
2185
|
+
};
|
|
1893
2186
|
const pipelineResult = await runPagesRequest(webRequest, {
|
|
1894
2187
|
basePath: bp,
|
|
1895
2188
|
trailingSlash: nextConfig?.trailingSlash ?? false,
|
|
@@ -1908,8 +2201,9 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1908
2201
|
rawSearch: url.includes("?") ? url.slice(url.indexOf("?")) : "",
|
|
1909
2202
|
runMiddleware: devRunMiddlewareAdapter,
|
|
1910
2203
|
matchPageRoute: (resolvedPathname, request) => {
|
|
1911
|
-
const m = matchRoute(nextConfig?.i18n ? resolvePagesI18nRequest(resolvedPathname, nextConfig.i18n, request.headers,
|
|
2204
|
+
const m = matchRoute(nextConfig?.i18n ? resolvePagesI18nRequest(resolvedPathname, nextConfig.i18n, request.headers, getUrlHostname(request.url), bp, nextConfig.trailingSlash ?? false).url : resolvedPathname, devPageRoutes);
|
|
1912
2205
|
return m ? { route: {
|
|
2206
|
+
dataKind: classifyDevPageRoute(m.route),
|
|
1913
2207
|
isDynamic: m.route.isDynamic,
|
|
1914
2208
|
pattern: m.route.pattern
|
|
1915
2209
|
} } : null;
|
|
@@ -1980,7 +2274,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1980
2274
|
}
|
|
1981
2275
|
if (!cachedSSRHandler || cachedSSRHandler.routes !== routes) cachedSSRHandler = {
|
|
1982
2276
|
routes,
|
|
1983
|
-
handler: createSSRHandler(server, getPagesRunner(), routes, pagesDir, nextConfig?.i18n, fileMatcher, nextConfig?.basePath ?? "", nextConfig?.trailingSlash ?? false, middlewarePath !== null, (nextConfig?.rewrites.beforeFiles.length ?? 0) > 0 || (nextConfig?.rewrites.afterFiles.length ?? 0) > 0 || (nextConfig?.rewrites.fallback.length ?? 0) > 0, nextConfig?.clientTraceMetadata, nextConfig?.htmlLimitedBots)
|
|
2277
|
+
handler: createSSRHandler(server, getPagesRunner(), routes, pagesDir, nextConfig?.i18n, fileMatcher, nextConfig?.basePath ?? "", nextConfig?.trailingSlash ?? false, middlewarePath !== null, (nextConfig?.rewrites.beforeFiles.length ?? 0) > 0 || (nextConfig?.rewrites.afterFiles.length ?? 0) > 0 || (nextConfig?.rewrites.fallback.length ?? 0) > 0, nextConfig?.clientTraceMetadata, nextConfig?.htmlLimitedBots, nextConfig?.reactStrictMode === true)
|
|
1984
2278
|
};
|
|
1985
2279
|
flushStagedHeaders();
|
|
1986
2280
|
flushRequestHeaders();
|
|
@@ -2692,6 +2986,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2692
2986
|
];
|
|
2693
2987
|
if (rscPluginPromise) {
|
|
2694
2988
|
plugins.push(rscPluginPromise);
|
|
2989
|
+
plugins.push(createRscReferenceValidationNormalizerPlugin());
|
|
2695
2990
|
plugins.push(createRscClientReferenceLoadersPlugin());
|
|
2696
2991
|
}
|
|
2697
2992
|
return plugins;
|
|
@@ -46,6 +46,10 @@ function readStringArrayField(ctx, field) {
|
|
|
46
46
|
if (!Array.isArray(value)) return [];
|
|
47
47
|
return value.filter((item) => typeof item === "string");
|
|
48
48
|
}
|
|
49
|
+
function readPositiveNumberField(ctx, field) {
|
|
50
|
+
const value = ctx?.[field];
|
|
51
|
+
return typeof value === "number" && value > 0 ? value : void 0;
|
|
52
|
+
}
|
|
49
53
|
function validUniqueTags(tags) {
|
|
50
54
|
const result = [];
|
|
51
55
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -139,7 +143,10 @@ var KVCacheHandler = class {
|
|
|
139
143
|
this._deleteInBackground(kvKey);
|
|
140
144
|
return null;
|
|
141
145
|
}
|
|
142
|
-
|
|
146
|
+
const now = Date.now();
|
|
147
|
+
const requestedRevalidate = readPositiveNumberField(_ctx, "revalidate");
|
|
148
|
+
const requestedRevalidateAt = requestedRevalidate === void 0 ? null : entry.lastModified + requestedRevalidate * 1e3;
|
|
149
|
+
if (entry.revalidateAt !== null && now > entry.revalidateAt || requestedRevalidateAt !== null && now > requestedRevalidateAt) return {
|
|
143
150
|
lastModified: entry.lastModified,
|
|
144
151
|
value: restoredValue,
|
|
145
152
|
cacheState: "stale",
|
|
@@ -214,11 +214,7 @@ async function deploy(options) {
|
|
|
214
214
|
console.log(` Project: ${info.projectName}`);
|
|
215
215
|
console.log(` Router: ${info.isAppRouter ? "App Router" : "Pages Router"}`);
|
|
216
216
|
console.log(` ISR: ${info.hasISR ? "detected" : "none"}`);
|
|
217
|
-
const missingScaffolding = [
|
|
218
|
-
!info.hasViteConfig && "Vite config",
|
|
219
|
-
!info.hasWranglerConfig && "Wrangler config",
|
|
220
|
-
info.isPagesRouter && !info.hasWorkerEntry && "Worker entry"
|
|
221
|
-
].filter((value) => Boolean(value));
|
|
217
|
+
const missingScaffolding = [!info.hasViteConfig && "Vite config", !info.hasWranglerConfig && "Wrangler config"].filter((value) => Boolean(value));
|
|
222
218
|
if (missingScaffolding.length > 0) throw new Error(`Missing Cloudflare deployment setup: ${missingScaffolding.join(", ")}. Run \`vinext init --platform=cloudflare\` first.`);
|
|
223
219
|
const missingDeps = getMissingDeps(info);
|
|
224
220
|
if (missingDeps.length > 0) throw new Error(`Missing deployment dependencies: ${missingDeps.map((dependency) => dependency.name).join(", ")}. Run \`vinext init --platform=cloudflare\` first.`);
|