vinext 0.0.22 → 0.0.24
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/static-export.d.ts.map +1 -1
- package/dist/build/static-export.js +9 -7
- package/dist/build/static-export.js.map +1 -1
- package/dist/config/config-matchers.d.ts.map +1 -1
- package/dist/config/config-matchers.js +13 -3
- package/dist/config/config-matchers.js.map +1 -1
- package/dist/config/next-config.d.ts +4 -1
- package/dist/config/next-config.d.ts.map +1 -1
- package/dist/config/next-config.js +10 -5
- package/dist/config/next-config.js.map +1 -1
- package/dist/deploy.d.ts.map +1 -1
- package/dist/deploy.js +83 -24
- package/dist/deploy.js.map +1 -1
- package/dist/index.d.ts +36 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +230 -40
- package/dist/index.js.map +1 -1
- package/dist/routing/app-router.d.ts +2 -1
- package/dist/routing/app-router.d.ts.map +1 -1
- package/dist/routing/app-router.js +73 -66
- package/dist/routing/app-router.js.map +1 -1
- package/dist/routing/file-matcher.d.ts +24 -0
- package/dist/routing/file-matcher.d.ts.map +1 -0
- package/dist/routing/file-matcher.js +75 -0
- package/dist/routing/file-matcher.js.map +1 -0
- package/dist/routing/pages-router.d.ts +3 -2
- package/dist/routing/pages-router.d.ts.map +1 -1
- package/dist/routing/pages-router.js +24 -17
- package/dist/routing/pages-router.js.map +1 -1
- package/dist/server/app-dev-server.d.ts.map +1 -1
- package/dist/server/app-dev-server.js +110 -64
- package/dist/server/app-dev-server.js.map +1 -1
- package/dist/server/dev-server.d.ts +2 -1
- package/dist/server/dev-server.d.ts.map +1 -1
- package/dist/server/dev-server.js +16 -14
- package/dist/server/dev-server.js.map +1 -1
- package/dist/server/prod-server.d.ts +8 -2
- package/dist/server/prod-server.d.ts.map +1 -1
- package/dist/server/prod-server.js +71 -16
- package/dist/server/prod-server.js.map +1 -1
- package/dist/server/worker-utils.d.ts +15 -0
- package/dist/server/worker-utils.d.ts.map +1 -0
- package/dist/server/worker-utils.js +41 -0
- package/dist/server/worker-utils.js.map +1 -0
- package/dist/shims/cache.d.ts +1 -1
- package/dist/shims/cache.d.ts.map +1 -1
- package/dist/shims/cache.js +8 -3
- package/dist/shims/cache.js.map +1 -1
- package/dist/shims/headers.d.ts +6 -0
- package/dist/shims/headers.d.ts.map +1 -1
- package/dist/shims/headers.js +8 -0
- package/dist/shims/headers.js.map +1 -1
- package/dist/shims/metadata.d.ts +1 -0
- package/dist/shims/metadata.d.ts.map +1 -1
- package/dist/shims/metadata.js +5 -1
- package/dist/shims/metadata.js.map +1 -1
- package/dist/utils/project.d.ts +13 -1
- package/dist/utils/project.d.ts.map +1 -1
- package/dist/utils/project.js +63 -13
- package/dist/utils/project.js.map +1 -1
- package/package.json +6 -1
|
@@ -8,6 +8,8 @@ import path from "node:path";
|
|
|
8
8
|
import { pathToFileURL } from "node:url";
|
|
9
9
|
import { createRequire } from "node:module";
|
|
10
10
|
import fs from "node:fs";
|
|
11
|
+
import { PHASE_DEVELOPMENT_SERVER } from "../shims/constants.js";
|
|
12
|
+
import { normalizePageExtensions } from "../routing/file-matcher.js";
|
|
11
13
|
const CONFIG_FILES = [
|
|
12
14
|
"next.config.ts",
|
|
13
15
|
"next.config.mjs",
|
|
@@ -33,10 +35,10 @@ function isCjsError(e) {
|
|
|
33
35
|
* Unwrap the config value from a loaded module, calling it if it's a
|
|
34
36
|
* function-form config (Next.js supports `module.exports = (phase, opts) => config`).
|
|
35
37
|
*/
|
|
36
|
-
async function unwrapConfig(mod) {
|
|
38
|
+
async function unwrapConfig(mod, phase = PHASE_DEVELOPMENT_SERVER) {
|
|
37
39
|
const config = mod.default ?? mod;
|
|
38
40
|
if (typeof config === "function") {
|
|
39
|
-
const result = await config(
|
|
41
|
+
const result = await config(phase, {
|
|
40
42
|
defaultConfig: {},
|
|
41
43
|
});
|
|
42
44
|
return result;
|
|
@@ -52,7 +54,7 @@ async function unwrapConfig(mod) {
|
|
|
52
54
|
* back to loading it via `createRequire` so that CJS config files (common in
|
|
53
55
|
* the Next.js ecosystem for plugin wrappers like nextra, @next/mdx, etc.) work.
|
|
54
56
|
*/
|
|
55
|
-
export async function loadNextConfig(root) {
|
|
57
|
+
export async function loadNextConfig(root, phase = PHASE_DEVELOPMENT_SERVER) {
|
|
56
58
|
for (const filename of CONFIG_FILES) {
|
|
57
59
|
const configPath = path.join(root, filename);
|
|
58
60
|
if (!fs.existsSync(configPath))
|
|
@@ -61,7 +63,7 @@ export async function loadNextConfig(root) {
|
|
|
61
63
|
// Use dynamic import for ESM/TS config files
|
|
62
64
|
const fileUrl = pathToFileURL(configPath).href;
|
|
63
65
|
const mod = await import(fileUrl);
|
|
64
|
-
return await unwrapConfig(mod);
|
|
66
|
+
return await unwrapConfig(mod, phase);
|
|
65
67
|
}
|
|
66
68
|
catch (e) {
|
|
67
69
|
// If the error indicates a CJS file loaded in ESM context, retry with
|
|
@@ -70,7 +72,7 @@ export async function loadNextConfig(root) {
|
|
|
70
72
|
try {
|
|
71
73
|
const require = createRequire(path.join(root, "package.json"));
|
|
72
74
|
const mod = require(configPath);
|
|
73
|
-
return await unwrapConfig({ default: mod });
|
|
75
|
+
return await unwrapConfig({ default: mod }, phase);
|
|
74
76
|
}
|
|
75
77
|
catch (e2) {
|
|
76
78
|
console.warn(`[vinext] Failed to load ${filename}: ${e2.message}`);
|
|
@@ -94,6 +96,7 @@ export async function resolveNextConfig(config) {
|
|
|
94
96
|
basePath: "",
|
|
95
97
|
trailingSlash: false,
|
|
96
98
|
output: "",
|
|
99
|
+
pageExtensions: normalizePageExtensions(),
|
|
97
100
|
cacheComponents: false,
|
|
98
101
|
redirects: [],
|
|
99
102
|
rewrites: { beforeFiles: [], afterFiles: [], fallback: [] },
|
|
@@ -149,6 +152,7 @@ export async function resolveNextConfig(config) {
|
|
|
149
152
|
if (output && output !== "export" && output !== "standalone") {
|
|
150
153
|
console.warn(`[vinext] Unknown output mode "${output}", ignoring`);
|
|
151
154
|
}
|
|
155
|
+
const pageExtensions = normalizePageExtensions(config.pageExtensions);
|
|
152
156
|
// Parse i18n config
|
|
153
157
|
let i18n = null;
|
|
154
158
|
if (config.i18n) {
|
|
@@ -164,6 +168,7 @@ export async function resolveNextConfig(config) {
|
|
|
164
168
|
basePath: config.basePath ?? "",
|
|
165
169
|
trailingSlash: config.trailingSlash ?? false,
|
|
166
170
|
output: output === "export" || output === "standalone" ? output : "",
|
|
171
|
+
pageExtensions,
|
|
167
172
|
cacheComponents: config.cacheComponents ?? false,
|
|
168
173
|
redirects,
|
|
169
174
|
rewrites,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-config.js","sourceRoot":"","sources":["../../src/config/next-config.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,MAAM,SAAS,CAAC;AA8IzB,MAAM,YAAY,GAAG;IACnB,gBAAgB;IAChB,iBAAiB;IACjB,gBAAgB;IAChB,iBAAiB;CAClB,CAAC;AAEF;;;GAGG;AACH,SAAS,UAAU,CAAC,CAAU;IAC5B,IAAI,CAAC,CAAC,CAAC,YAAY,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACxC,MAAM,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC;IACtB,OAAO,CACL,GAAG,CAAC,QAAQ,CAAC,2BAA2B,CAAC;QACzC,GAAG,CAAC,QAAQ,CAAC,wBAAwB,CAAC;QACtC,GAAG,CAAC,QAAQ,CAAC,wBAAwB,CAAC;QACtC,GAAG,CAAC,QAAQ,CAAC,uBAAuB,CAAC;QACrC,GAAG,CAAC,QAAQ,CAAC,0BAA0B,CAAC;QACxC,GAAG,CAAC,QAAQ,CAAC,2BAA2B,CAAC,CAC1C,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,KAAK,UAAU,Y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Q;QAAE,OAAO,IAAI,CAAC;IAEnD,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC;IACzF,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC;IACzF,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC;IAEtF,wDAAwD;IACxD,IACE,CAAC,aAAa,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC;QAC3C,CAAC,aAAa,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC;QAC3C,CAAC,YAAY,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,EACzC,CAAC;QACD,OAAO;YACL,GAAG,CAAC,aAAa,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACvE,GAAG,CAAC,aAAa,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACvE,GAAG,CAAC,YAAY,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACrE,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["/**\n * next.config.js / next.config.mjs / next.config.ts parser\n *\n * Loads the Next.js config file (if present) and extracts supported options.\n * Unsupported options are logged as warnings.\n */\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { createRequire } from \"node:module\";\nimport fs from \"node:fs\";\n\nexport interface HasCondition {\n type: \"header\" | \"cookie\" | \"query\" | \"host\";\n key: string;\n value?: string;\n}\n\nexport interface NextRedirect {\n source: string;\n destination: string;\n permanent: boolean;\n has?: HasCondition[];\n missing?: HasCondition[];\n}\n\nexport interface NextRewrite {\n source: string;\n destination: string;\n has?: HasCondition[];\n missing?: HasCondition[];\n}\n\nexport interface NextHeader {\n source: string;\n has?: HasCondition[];\n missing?: HasCondition[];\n headers: Array<{ key: string; value: string }>;\n}\n\nexport interface NextI18nConfig {\n /** List of supported locales */\n locales: string[];\n /** The default locale (used when no locale prefix is in the URL) */\n defaultLocale: string;\n /**\n * Whether to auto-detect locale from Accept-Language header.\n * Defaults to true in Next.js.\n */\n localeDetection?: boolean;\n /**\n * Domain-based routing. Each domain maps to a specific locale.\n */\n domains?: Array<{\n domain: string;\n defaultLocale: string;\n locales?: string[];\n http?: boolean;\n }>;\n}\n\n/**\n * MDX compilation options extracted from @next/mdx config.\n * These are passed through to @mdx-js/rollup so that custom\n * remark/rehype/recma plugins configured in next.config work with Vite.\n */\nexport interface MdxOptions {\n remarkPlugins?: unknown[];\n rehypePlugins?: unknown[];\n recmaPlugins?: unknown[];\n}\n\nexport interface NextConfig {\n /** Additional env variables */\n env?: Record<string, string>;\n /** Base URL path prefix */\n basePath?: string;\n /** Whether to add trailing slashes */\n trailingSlash?: boolean;\n /** Internationalization routing config */\n i18n?: NextI18nConfig;\n /** URL redirect rules */\n redirects?: () => Promise<NextRedirect[]> | NextRedirect[];\n /** URL rewrite rules */\n rewrites?: () =>\n | Promise<NextRewrite[] | { beforeFiles: NextRewrite[]; afterFiles: NextRewrite[]; fallback: NextRewrite[] }>\n | NextRewrite[]\n | { beforeFiles: NextRewrite[]; afterFiles: NextRewrite[]; fallback: NextRewrite[] };\n /** Custom response headers */\n headers?: () => Promise<NextHeader[]> | NextHeader[];\n /** Image optimization config */\n images?: {\n remotePatterns?: Array<{\n protocol?: string;\n hostname: string;\n port?: string;\n pathname?: string;\n search?: string;\n }>;\n domains?: string[];\n unoptimized?: boolean;\n /** Allowed device widths for image optimization. Defaults to Next.js defaults: [640, 750, 828, 1080, 1200, 1920, 2048, 3840] */\n deviceSizes?: number[];\n /** Allowed image sizes for fixed-width images. Defaults to Next.js defaults: [16, 32, 48, 64, 96, 128, 256, 384] */\n imageSizes?: number[];\n /** Allow SVG images through the image optimization endpoint. SVG can contain scripts, so only enable if you trust all image sources. */\n dangerouslyAllowSVG?: boolean;\n /** Content-Disposition header for image responses. Defaults to \"inline\". */\n contentDispositionType?: \"inline\" | \"attachment\";\n /** Content-Security-Policy header for image responses. Defaults to \"script-src 'none'; frame-src 'none'; sandbox;\" */\n contentSecurityPolicy?: string;\n };\n /** Build output mode: 'export' for full static export, 'standalone' for single server */\n output?: \"export\" | \"standalone\";\n /**\n * Enable Cache Components (Next.js 16).\n * When true, enables the \"use cache\" directive for pages, components, and functions.\n * Replaces the removed experimental.ppr and experimental.dynamicIO flags.\n */\n cacheComponents?: boolean;\n /** Transpile packages (Vite handles this natively) */\n transpilePackages?: string[];\n /** Webpack config (ignored — we use Vite) */\n webpack?: unknown;\n /** Any other options */\n [key: string]: unknown;\n}\n\n/**\n * Resolved configuration with all async values awaited.\n */\nexport interface ResolvedNextConfig {\n env: Record<string, string>;\n basePath: string;\n trailingSlash: boolean;\n output: \"\" | \"export\" | \"standalone\";\n cacheComponents: boolean;\n redirects: NextRedirect[];\n rewrites: {\n beforeFiles: NextRewrite[];\n afterFiles: NextRewrite[];\n fallback: NextRewrite[];\n };\n headers: NextHeader[];\n images: NextConfig[\"images\"];\n i18n: NextI18nConfig | null;\n /** MDX remark/rehype/recma plugins extracted from @next/mdx config */\n mdx: MdxOptions | null;\n /** Extra allowed origins for server action CSRF validation (from experimental.serverActions.allowedOrigins). */\n serverActionsAllowedOrigins: string[];\n}\n\nconst CONFIG_FILES = [\n \"next.config.ts\",\n \"next.config.mjs\",\n \"next.config.js\",\n \"next.config.cjs\",\n];\n\n/**\n * Check whether an error indicates a CJS module was loaded in an ESM context\n * (i.e. the file uses `require()` which is not available in ESM).\n */\nfunction isCjsError(e: unknown): boolean {\n if (!(e instanceof Error)) return false;\n const msg = e.message;\n return (\n msg.includes(\"require is not a function\") ||\n msg.includes(\"require is not defined\") ||\n msg.includes(\"exports is not defined\") ||\n msg.includes(\"module is not defined\") ||\n msg.includes(\"__dirname is not defined\") ||\n msg.includes(\"__filename is not defined\")\n );\n}\n\n/**\n * Unwrap the config value from a loaded module, calling it if it's a\n * function-form config (Next.js supports `module.exports = (phase, opts) => config`).\n */\nasync function unwrapConfig(mod: any): Promise<NextConfig> {\n const config = mod.default ?? mod;\n if (typeof config === \"function\") {\n const result = await config(\"phase-development-server\", {\n defaultConfig: {},\n });\n return result as NextConfig;\n }\n return config as NextConfig;\n}\n\n/**\n * Find and load the next.config file from the project root.\n * Returns null if no config file is found.\n *\n * Attempts ESM dynamic `import()` first. If the file uses CJS constructs\n * (`require`, `module.exports`) that aren't available in ESM context, falls\n * back to loading it via `createRequire` so that CJS config files (common in\n * the Next.js ecosystem for plugin wrappers like nextra, @next/mdx, etc.) work.\n */\nexport async function loadNextConfig(root: string): Promise<NextConfig | null> {\n for (const filename of CONFIG_FILES) {\n const configPath = path.join(root, filename);\n if (!fs.existsSync(configPath)) continue;\n\n try {\n // Use dynamic import for ESM/TS config files\n const fileUrl = pathToFileURL(configPath).href;\n const mod = await import(fileUrl);\n return await unwrapConfig(mod);\n } catch (e) {\n // If the error indicates a CJS file loaded in ESM context, retry with\n // createRequire which provides a proper CommonJS environment.\n if (isCjsError(e) && (filename.endsWith(\".js\") || filename.endsWith(\".cjs\"))) {\n try {\n const require = createRequire(path.join(root, \"package.json\"));\n const mod = require(configPath);\n return await unwrapConfig({ default: mod });\n } catch (e2) {\n console.warn(\n `[vinext] Failed to load ${filename}: ${(e2 as Error).message}`,\n );\n return null;\n }\n }\n\n console.warn(\n `[vinext] Failed to load ${filename}: ${(e as Error).message}`,\n );\n return null;\n }\n }\n\n return null;\n}\n\n/**\n * Resolve a NextConfig into a fully-resolved ResolvedNextConfig.\n * Awaits async functions for redirects/rewrites/headers.\n */\nexport async function resolveNextConfig(\n config: NextConfig | null,\n): Promise<ResolvedNextConfig> {\n if (!config) {\n return {\n env: {},\n basePath: \"\",\n trailingSlash: false,\n output: \"\",\n cacheComponents: false,\n redirects: [],\n rewrites: { beforeFiles: [], afterFiles: [], fallback: [] },\n headers: [],\n images: undefined,\n i18n: null,\n mdx: null,\n serverActionsAllowedOrigins: [],\n };\n }\n\n // Resolve redirects\n let redirects: NextRedirect[] = [];\n if (config.redirects) {\n const result = await config.redirects();\n redirects = Array.isArray(result) ? result : [];\n }\n\n // Resolve rewrites\n let rewrites = { beforeFiles: [] as NextRewrite[], afterFiles: [] as NextRewrite[], fallback: [] as NextRewrite[] };\n if (config.rewrites) {\n const result = await config.rewrites();\n if (Array.isArray(result)) {\n rewrites.afterFiles = result;\n } else {\n rewrites = {\n beforeFiles: result.beforeFiles ?? [],\n afterFiles: result.afterFiles ?? [],\n fallback: result.fallback ?? [],\n };\n }\n }\n\n // Resolve headers\n let headers: NextHeader[] = [];\n if (config.headers) {\n headers = await config.headers();\n }\n\n // Extract MDX remark/rehype plugins from @next/mdx's webpack wrapper\n const mdx = extractMdxOptions(config);\n\n // Resolve serverActions.allowedOrigins from experimental config\n const experimental = config.experimental as Record<string, unknown> | undefined;\n const serverActionsConfig = experimental?.serverActions as Record<string, unknown> | undefined;\n const serverActionsAllowedOrigins = Array.isArray(serverActionsConfig?.allowedOrigins)\n ? (serverActionsConfig.allowedOrigins as string[])\n : [];\n\n // Warn about unsupported options (skip webpack if we extracted MDX from it)\n const unsupported = mdx ? [] : [\"webpack\"];\n for (const key of unsupported) {\n if (config[key] !== undefined) {\n console.warn(\n `[vinext] next.config option \"${key}\" is not yet supported and will be ignored`,\n );\n }\n }\n\n const output = config.output ?? \"\";\n if (output && output !== \"export\" && output !== \"standalone\") {\n console.warn(`[vinext] Unknown output mode \"${output as string}\", ignoring`);\n }\n\n // Parse i18n config\n let i18n: NextI18nConfig | null = null;\n if (config.i18n) {\n i18n = {\n locales: config.i18n.locales,\n defaultLocale: config.i18n.defaultLocale,\n localeDetection: config.i18n.localeDetection ?? true,\n domains: config.i18n.domains,\n };\n }\n\n return {\n env: config.env ?? {},\n basePath: config.basePath ?? \"\",\n trailingSlash: config.trailingSlash ?? false,\n output: output === \"export\" || output === \"standalone\" ? output : \"\",\n cacheComponents: config.cacheComponents ?? false,\n redirects,\n rewrites,\n headers,\n images: config.images,\n i18n,\n mdx,\n serverActionsAllowedOrigins,\n };\n}\n\n/**\n * Extract MDX compilation options (remark/rehype/recma plugins) from\n * a Next.js config that uses @next/mdx.\n *\n * @next/mdx wraps the config with a webpack function that injects an MDX\n * loader rule. The remark/rehype plugins are captured in that closure.\n * We probe the webpack function with a mock config to extract them.\n */\nexport function extractMdxOptions(config: NextConfig): MdxOptions | null {\n if (typeof config.webpack !== \"function\") return null;\n\n // Build a mock webpack config object that @next/mdx's wrapper will mutate\n const mockModuleRules: any[] = [];\n const mockConfig = {\n resolve: { alias: {} as Record<string, string> },\n module: { rules: mockModuleRules },\n plugins: [] as any[],\n };\n const mockOptions = {\n defaultLoaders: { babel: { loader: \"next-babel-loader\" } },\n isServer: false,\n dev: false,\n dir: \"/mock\",\n };\n\n try {\n const result = (config.webpack as Function)(mockConfig, mockOptions);\n // @next/mdx may return the config or mutate in place\n const finalConfig = result ?? mockConfig;\n const rules: any[] = finalConfig.module?.rules ?? mockModuleRules;\n\n // Search through webpack rules for the MDX loader injected by @next/mdx\n for (const rule of rules) {\n const loaders = extractMdxLoaders(rule);\n if (loaders) return loaders;\n }\n } catch {\n // If the webpack function throws (e.g. expects real webpack internals),\n // silently skip — we'll fall back to bare mdx() with no plugins.\n }\n\n return null;\n}\n\n/**\n * Recursively search a webpack rule (which may have nested `oneOf` arrays)\n * for an MDX loader and extract its remark/rehype/recma plugin options.\n */\nfunction extractMdxLoaders(rule: any): MdxOptions | null {\n if (!rule) return null;\n\n // Check `oneOf` arrays (Next.js uses these extensively)\n if (Array.isArray(rule.oneOf)) {\n for (const child of rule.oneOf) {\n const result = extractMdxLoaders(child);\n if (result) return result;\n }\n }\n\n // Check `use` array (loader chain)\n const use = Array.isArray(rule.use) ? rule.use : rule.use ? [rule.use] : [];\n for (const loader of use) {\n const loaderPath = typeof loader === \"string\" ? loader : loader?.loader;\n if (typeof loaderPath === \"string\" && isMdxLoader(loaderPath)) {\n const opts = typeof loader === \"object\" ? loader.options : {};\n return extractPluginsFromOptions(opts);\n }\n }\n\n // Check direct `loader` field\n if (typeof rule.loader === \"string\" && isMdxLoader(rule.loader)) {\n return extractPluginsFromOptions(rule.options);\n }\n\n return null;\n}\n\nfunction isMdxLoader(loaderPath: string): boolean {\n return (\n loaderPath.includes(\"mdx\") &&\n (loaderPath.includes(\"@next\") ||\n loaderPath.includes(\"@mdx-js\") ||\n loaderPath.includes(\"mdx-js-loader\") ||\n loaderPath.includes(\"next-mdx\"))\n );\n}\n\nfunction extractPluginsFromOptions(opts: any): MdxOptions | null {\n if (!opts || typeof opts !== \"object\") return null;\n\n const remarkPlugins = Array.isArray(opts.remarkPlugins) ? opts.remarkPlugins : undefined;\n const rehypePlugins = Array.isArray(opts.rehypePlugins) ? opts.rehypePlugins : undefined;\n const recmaPlugins = Array.isArray(opts.recmaPlugins) ? opts.recmaPlugins : undefined;\n\n // Only return if at least one plugin array is non-empty\n if (\n (remarkPlugins && remarkPlugins.length > 0) ||\n (rehypePlugins && rehypePlugins.length > 0) ||\n (recmaPlugins && recmaPlugins.length > 0)\n ) {\n return {\n ...(remarkPlugins && remarkPlugins.length > 0 ? { remarkPlugins } : {}),\n ...(rehypePlugins && rehypePlugins.length > 0 ? { rehypePlugins } : {}),\n ...(recmaPlugins && recmaPlugins.length > 0 ? { recmaPlugins } : {}),\n };\n }\n\n return null;\n}\n"]}
|
|
1
|
+
{"version":3,"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AC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC;IACzF,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC;IACzF,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC;IAEtF,wDAAwD;IACxD,IACE,CAAC,aAAa,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC;QAC3C,CAAC,aAAa,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC;QAC3C,CAAC,YAAY,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,EACzC,CAAC;QACD,OAAO;YACL,GAAG,CAAC,aAAa,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACvE,GAAG,CAAC,aAAa,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACvE,GAAG,CAAC,YAAY,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACrE,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["/**\n * next.config.js / next.config.mjs / next.config.ts parser\n *\n * Loads the Next.js config file (if present) and extracts supported options.\n * Unsupported options are logged as warnings.\n */\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { createRequire } from \"node:module\";\nimport fs from \"node:fs\";\nimport { PHASE_DEVELOPMENT_SERVER } from \"../shims/constants.js\";\nimport { normalizePageExtensions } from \"../routing/file-matcher.js\";\n\nexport interface HasCondition {\n type: \"header\" | \"cookie\" | \"query\" | \"host\";\n key: string;\n value?: string;\n}\n\nexport interface NextRedirect {\n source: string;\n destination: string;\n permanent: boolean;\n has?: HasCondition[];\n missing?: HasCondition[];\n}\n\nexport interface NextRewrite {\n source: string;\n destination: string;\n has?: HasCondition[];\n missing?: HasCondition[];\n}\n\nexport interface NextHeader {\n source: string;\n has?: HasCondition[];\n missing?: HasCondition[];\n headers: Array<{ key: string; value: string }>;\n}\n\nexport interface NextI18nConfig {\n /** List of supported locales */\n locales: string[];\n /** The default locale (used when no locale prefix is in the URL) */\n defaultLocale: string;\n /**\n * Whether to auto-detect locale from Accept-Language header.\n * Defaults to true in Next.js.\n */\n localeDetection?: boolean;\n /**\n * Domain-based routing. Each domain maps to a specific locale.\n */\n domains?: Array<{\n domain: string;\n defaultLocale: string;\n locales?: string[];\n http?: boolean;\n }>;\n}\n\n/**\n * MDX compilation options extracted from @next/mdx config.\n * These are passed through to @mdx-js/rollup so that custom\n * remark/rehype/recma plugins configured in next.config work with Vite.\n */\nexport interface MdxOptions {\n remarkPlugins?: unknown[];\n rehypePlugins?: unknown[];\n recmaPlugins?: unknown[];\n}\n\nexport interface NextConfig {\n /** Additional env variables */\n env?: Record<string, string>;\n /** Base URL path prefix */\n basePath?: string;\n /** Whether to add trailing slashes */\n trailingSlash?: boolean;\n /** Internationalization routing config */\n i18n?: NextI18nConfig;\n /** URL redirect rules */\n redirects?: () => Promise<NextRedirect[]> | NextRedirect[];\n /** URL rewrite rules */\n rewrites?: () =>\n | Promise<NextRewrite[] | { beforeFiles: NextRewrite[]; afterFiles: NextRewrite[]; fallback: NextRewrite[] }>\n | NextRewrite[]\n | { beforeFiles: NextRewrite[]; afterFiles: NextRewrite[]; fallback: NextRewrite[] };\n /** Custom response headers */\n headers?: () => Promise<NextHeader[]> | NextHeader[];\n /** Image optimization config */\n images?: {\n remotePatterns?: Array<{\n protocol?: string;\n hostname: string;\n port?: string;\n pathname?: string;\n search?: string;\n }>;\n domains?: string[];\n unoptimized?: boolean;\n /** Allowed device widths for image optimization. Defaults to Next.js defaults: [640, 750, 828, 1080, 1200, 1920, 2048, 3840] */\n deviceSizes?: number[];\n /** Allowed image sizes for fixed-width images. Defaults to Next.js defaults: [16, 32, 48, 64, 96, 128, 256, 384] */\n imageSizes?: number[];\n /** Allow SVG images through the image optimization endpoint. SVG can contain scripts, so only enable if you trust all image sources. */\n dangerouslyAllowSVG?: boolean;\n /** Content-Disposition header for image responses. Defaults to \"inline\". */\n contentDispositionType?: \"inline\" | \"attachment\";\n /** Content-Security-Policy header for image responses. Defaults to \"script-src 'none'; frame-src 'none'; sandbox;\" */\n contentSecurityPolicy?: string;\n };\n /** Build output mode: 'export' for full static export, 'standalone' for single server */\n output?: \"export\" | \"standalone\";\n /** File extensions treated as routable pages/routes (Next.js pageExtensions) */\n pageExtensions?: string[];\n /**\n * Enable Cache Components (Next.js 16).\n * When true, enables the \"use cache\" directive for pages, components, and functions.\n * Replaces the removed experimental.ppr and experimental.dynamicIO flags.\n */\n cacheComponents?: boolean;\n /** Transpile packages (Vite handles this natively) */\n transpilePackages?: string[];\n /** Webpack config (ignored — we use Vite) */\n webpack?: unknown;\n /** Any other options */\n [key: string]: unknown;\n}\n\n/**\n * Resolved configuration with all async values awaited.\n */\nexport interface ResolvedNextConfig {\n env: Record<string, string>;\n basePath: string;\n trailingSlash: boolean;\n output: \"\" | \"export\" | \"standalone\";\n pageExtensions: string[];\n cacheComponents: boolean;\n redirects: NextRedirect[];\n rewrites: {\n beforeFiles: NextRewrite[];\n afterFiles: NextRewrite[];\n fallback: NextRewrite[];\n };\n headers: NextHeader[];\n images: NextConfig[\"images\"];\n i18n: NextI18nConfig | null;\n /** MDX remark/rehype/recma plugins extracted from @next/mdx config */\n mdx: MdxOptions | null;\n /** Extra allowed origins for server action CSRF validation (from experimental.serverActions.allowedOrigins). */\n serverActionsAllowedOrigins: string[];\n}\n\nconst CONFIG_FILES = [\n \"next.config.ts\",\n \"next.config.mjs\",\n \"next.config.js\",\n \"next.config.cjs\",\n];\n\n/**\n * Check whether an error indicates a CJS module was loaded in an ESM context\n * (i.e. the file uses `require()` which is not available in ESM).\n */\nfunction isCjsError(e: unknown): boolean {\n if (!(e instanceof Error)) return false;\n const msg = e.message;\n return (\n msg.includes(\"require is not a function\") ||\n msg.includes(\"require is not defined\") ||\n msg.includes(\"exports is not defined\") ||\n msg.includes(\"module is not defined\") ||\n msg.includes(\"__dirname is not defined\") ||\n msg.includes(\"__filename is not defined\")\n );\n}\n\n/**\n * Unwrap the config value from a loaded module, calling it if it's a\n * function-form config (Next.js supports `module.exports = (phase, opts) => config`).\n */\nasync function unwrapConfig(mod: any, phase: string = PHASE_DEVELOPMENT_SERVER): Promise<NextConfig> {\n const config = mod.default ?? mod;\n if (typeof config === \"function\") {\n const result = await config(phase, {\n defaultConfig: {},\n });\n return result as NextConfig;\n }\n return config as NextConfig;\n}\n\n/**\n * Find and load the next.config file from the project root.\n * Returns null if no config file is found.\n *\n * Attempts ESM dynamic `import()` first. If the file uses CJS constructs\n * (`require`, `module.exports`) that aren't available in ESM context, falls\n * back to loading it via `createRequire` so that CJS config files (common in\n * the Next.js ecosystem for plugin wrappers like nextra, @next/mdx, etc.) work.\n */\nexport async function loadNextConfig(root: string, phase: string = PHASE_DEVELOPMENT_SERVER): Promise<NextConfig | null> {\n for (const filename of CONFIG_FILES) {\n const configPath = path.join(root, filename);\n if (!fs.existsSync(configPath)) continue;\n\n try {\n // Use dynamic import for ESM/TS config files\n const fileUrl = pathToFileURL(configPath).href;\n const mod = await import(fileUrl);\n return await unwrapConfig(mod, phase);\n } catch (e) {\n // If the error indicates a CJS file loaded in ESM context, retry with\n // createRequire which provides a proper CommonJS environment.\n if (isCjsError(e) && (filename.endsWith(\".js\") || filename.endsWith(\".cjs\"))) {\n try {\n const require = createRequire(path.join(root, \"package.json\"));\n const mod = require(configPath);\n return await unwrapConfig({ default: mod }, phase);\n } catch (e2) {\n console.warn(\n `[vinext] Failed to load ${filename}: ${(e2 as Error).message}`,\n );\n return null;\n }\n }\n\n console.warn(\n `[vinext] Failed to load ${filename}: ${(e as Error).message}`,\n );\n return null;\n }\n }\n\n return null;\n}\n\n/**\n * Resolve a NextConfig into a fully-resolved ResolvedNextConfig.\n * Awaits async functions for redirects/rewrites/headers.\n */\nexport async function resolveNextConfig(\n config: NextConfig | null,\n): Promise<ResolvedNextConfig> {\n if (!config) {\n return {\n env: {},\n basePath: \"\",\n trailingSlash: false,\n output: \"\",\n pageExtensions: normalizePageExtensions(),\n cacheComponents: false,\n redirects: [],\n rewrites: { beforeFiles: [], afterFiles: [], fallback: [] },\n headers: [],\n images: undefined,\n i18n: null,\n mdx: null,\n serverActionsAllowedOrigins: [],\n };\n }\n\n // Resolve redirects\n let redirects: NextRedirect[] = [];\n if (config.redirects) {\n const result = await config.redirects();\n redirects = Array.isArray(result) ? result : [];\n }\n\n // Resolve rewrites\n let rewrites = { beforeFiles: [] as NextRewrite[], afterFiles: [] as NextRewrite[], fallback: [] as NextRewrite[] };\n if (config.rewrites) {\n const result = await config.rewrites();\n if (Array.isArray(result)) {\n rewrites.afterFiles = result;\n } else {\n rewrites = {\n beforeFiles: result.beforeFiles ?? [],\n afterFiles: result.afterFiles ?? [],\n fallback: result.fallback ?? [],\n };\n }\n }\n\n // Resolve headers\n let headers: NextHeader[] = [];\n if (config.headers) {\n headers = await config.headers();\n }\n\n // Extract MDX remark/rehype plugins from @next/mdx's webpack wrapper\n const mdx = extractMdxOptions(config);\n\n // Resolve serverActions.allowedOrigins from experimental config\n const experimental = config.experimental as Record<string, unknown> | undefined;\n const serverActionsConfig = experimental?.serverActions as Record<string, unknown> | undefined;\n const serverActionsAllowedOrigins = Array.isArray(serverActionsConfig?.allowedOrigins)\n ? (serverActionsConfig.allowedOrigins as string[])\n : [];\n\n // Warn about unsupported options (skip webpack if we extracted MDX from it)\n const unsupported = mdx ? [] : [\"webpack\"];\n for (const key of unsupported) {\n if (config[key] !== undefined) {\n console.warn(\n `[vinext] next.config option \"${key}\" is not yet supported and will be ignored`,\n );\n }\n }\n\n const output = config.output ?? \"\";\n if (output && output !== \"export\" && output !== \"standalone\") {\n console.warn(`[vinext] Unknown output mode \"${output as string}\", ignoring`);\n }\n\n const pageExtensions = normalizePageExtensions(config.pageExtensions);\n\n // Parse i18n config\n let i18n: NextI18nConfig | null = null;\n if (config.i18n) {\n i18n = {\n locales: config.i18n.locales,\n defaultLocale: config.i18n.defaultLocale,\n localeDetection: config.i18n.localeDetection ?? true,\n domains: config.i18n.domains,\n };\n }\n\n return {\n env: config.env ?? {},\n basePath: config.basePath ?? \"\",\n trailingSlash: config.trailingSlash ?? false,\n output: output === \"export\" || output === \"standalone\" ? output : \"\",\n pageExtensions,\n cacheComponents: config.cacheComponents ?? false,\n redirects,\n rewrites,\n headers,\n images: config.images,\n i18n,\n mdx,\n serverActionsAllowedOrigins,\n };\n}\n\n/**\n * Extract MDX compilation options (remark/rehype/recma plugins) from\n * a Next.js config that uses @next/mdx.\n *\n * @next/mdx wraps the config with a webpack function that injects an MDX\n * loader rule. The remark/rehype plugins are captured in that closure.\n * We probe the webpack function with a mock config to extract them.\n */\nexport function extractMdxOptions(config: NextConfig): MdxOptions | null {\n if (typeof config.webpack !== \"function\") return null;\n\n // Build a mock webpack config object that @next/mdx's wrapper will mutate\n const mockModuleRules: any[] = [];\n const mockConfig = {\n resolve: { alias: {} as Record<string, string> },\n module: { rules: mockModuleRules },\n plugins: [] as any[],\n };\n const mockOptions = {\n defaultLoaders: { babel: { loader: \"next-babel-loader\" } },\n isServer: false,\n dev: false,\n dir: \"/mock\",\n };\n\n try {\n const result = (config.webpack as Function)(mockConfig, mockOptions);\n // @next/mdx may return the config or mutate in place\n const finalConfig = result ?? mockConfig;\n const rules: any[] = finalConfig.module?.rules ?? mockModuleRules;\n\n // Search through webpack rules for the MDX loader injected by @next/mdx\n for (const rule of rules) {\n const loaders = extractMdxLoaders(rule);\n if (loaders) return loaders;\n }\n } catch {\n // If the webpack function throws (e.g. expects real webpack internals),\n // silently skip — we'll fall back to bare mdx() with no plugins.\n }\n\n return null;\n}\n\n/**\n * Recursively search a webpack rule (which may have nested `oneOf` arrays)\n * for an MDX loader and extract its remark/rehype/recma plugin options.\n */\nfunction extractMdxLoaders(rule: any): MdxOptions | null {\n if (!rule) return null;\n\n // Check `oneOf` arrays (Next.js uses these extensively)\n if (Array.isArray(rule.oneOf)) {\n for (const child of rule.oneOf) {\n const result = extractMdxLoaders(child);\n if (result) return result;\n }\n }\n\n // Check `use` array (loader chain)\n const use = Array.isArray(rule.use) ? rule.use : rule.use ? [rule.use] : [];\n for (const loader of use) {\n const loaderPath = typeof loader === \"string\" ? loader : loader?.loader;\n if (typeof loaderPath === \"string\" && isMdxLoader(loaderPath)) {\n const opts = typeof loader === \"object\" ? loader.options : {};\n return extractPluginsFromOptions(opts);\n }\n }\n\n // Check direct `loader` field\n if (typeof rule.loader === \"string\" && isMdxLoader(rule.loader)) {\n return extractPluginsFromOptions(rule.options);\n }\n\n return null;\n}\n\nfunction isMdxLoader(loaderPath: string): boolean {\n return (\n loaderPath.includes(\"mdx\") &&\n (loaderPath.includes(\"@next\") ||\n loaderPath.includes(\"@mdx-js\") ||\n loaderPath.includes(\"mdx-js-loader\") ||\n loaderPath.includes(\"next-mdx\"))\n );\n}\n\nfunction extractPluginsFromOptions(opts: any): MdxOptions | null {\n if (!opts || typeof opts !== \"object\") return null;\n\n const remarkPlugins = Array.isArray(opts.remarkPlugins) ? opts.remarkPlugins : undefined;\n const rehypePlugins = Array.isArray(opts.rehypePlugins) ? opts.rehypePlugins : undefined;\n const recmaPlugins = Array.isArray(opts.recmaPlugins) ? opts.recmaPlugins : undefined;\n\n // Only return if at least one plugin array is non-empty\n if (\n (remarkPlugins && remarkPlugins.length > 0) ||\n (rehypePlugins && rehypePlugins.length > 0) ||\n (recmaPlugins && recmaPlugins.length > 0)\n ) {\n return {\n ...(remarkPlugins && remarkPlugins.length > 0 ? { remarkPlugins } : {}),\n ...(rehypePlugins && rehypePlugins.length > 0 ? { rehypePlugins } : {}),\n ...(recmaPlugins && recmaPlugins.length > 0 ? { recmaPlugins } : {}),\n };\n }\n\n return null;\n}\n"]}
|
package/dist/deploy.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../src/deploy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAQH,OAAO,EACL,cAAc,IAAI,eAAe,EACjC,gBAAgB,IAAI,iBAAiB,
|
|
1
|
+
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../src/deploy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAQH,OAAO,EACL,cAAc,IAAI,eAAe,EACjC,gBAAgB,IAAI,iBAAiB,EAGtC,MAAM,oBAAoB,CAAC;AAO5B,MAAM,WAAW,aAAa;IAC5B,6BAA6B;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,0DAA0D;IAC1D,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,+DAA+D;IAC/D,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,yCAAyC;IACzC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,iDAAiD;IACjD,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,gEAAgE;IAChE,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,4DAA4D;IAC5D,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,mEAAmE;IACnE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qEAAqE;IACrE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,4DAA4D;IAC5D,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAkBD,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE;;;;;;;;;;;EAc7C;AAID,UAAU,WAAW;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,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AAO,CAQ9E;AAED,wBAAgB,cAAc,CAC5B,IAAI,EAAE,WAAW;AACjB,+DAA+D;AAC/D,aAAa,GAAE,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,OAA6B,GAC1E,UAAU,EAAE,CA2Bd;AAoBD,UAAU,aAAa;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,WAAW,GAAG,aAAa,EAAE,CAkCrE;AAmCD,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;CACzB;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,SAAS,GAAG,KAAK,CAAC,GAAG,kBAAkB,CAO3G;AA2CD,wBAAsB,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAoGlE"}
|
package/dist/deploy.js
CHANGED
|
@@ -19,7 +19,7 @@ import { createRequire } from "node:module";
|
|
|
19
19
|
import { execFileSync } from "node:child_process";
|
|
20
20
|
import { parseArgs as nodeParseArgs } from "node:util";
|
|
21
21
|
import { createBuilder, build } from "vite";
|
|
22
|
-
import { ensureESModule as _ensureESModule, renameCJSConfigs as _renameCJSConfigs, detectPackageManager as _detectPackageManager, } from "./utils/project.js";
|
|
22
|
+
import { ensureESModule as _ensureESModule, renameCJSConfigs as _renameCJSConfigs, detectPackageManager as _detectPackageManager, findInNodeModules as _findInNodeModules, } from "./utils/project.js";
|
|
23
23
|
import { getReactUpgradeDeps } from "./init.js";
|
|
24
24
|
import { runTPR } from "./cloudflare/tpr.js";
|
|
25
25
|
import { loadDotenv } from "./config/dotenv.js";
|
|
@@ -69,10 +69,12 @@ export function detectProject(root) {
|
|
|
69
69
|
fs.existsSync(path.join(root, "wrangler.toml"));
|
|
70
70
|
const hasWorkerEntry = fs.existsSync(path.join(root, "worker", "index.ts")) ||
|
|
71
71
|
fs.existsSync(path.join(root, "worker", "index.js"));
|
|
72
|
-
// Check node_modules for installed packages
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const
|
|
72
|
+
// Check node_modules for installed packages.
|
|
73
|
+
// Walk up ancestor directories so that monorepo-hoisted packages are found
|
|
74
|
+
// even when node_modules lives at the workspace root rather than app root.
|
|
75
|
+
const hasCloudflarePlugin = _findInNodeModules(root, "@cloudflare/vite-plugin") !== null;
|
|
76
|
+
const hasRscPlugin = _findInNodeModules(root, "@vitejs/plugin-rsc") !== null;
|
|
77
|
+
const hasWrangler = _findInNodeModules(root, ".bin/wrangler") !== null;
|
|
76
78
|
// Derive project name from package.json or directory name
|
|
77
79
|
let projectName = path.basename(root);
|
|
78
80
|
const pkgPath = path.join(root, "package.json");
|
|
@@ -457,12 +459,16 @@ export default {
|
|
|
457
459
|
}
|
|
458
460
|
|
|
459
461
|
// Build request context for has/missing condition matching.
|
|
460
|
-
//
|
|
462
|
+
// headers and redirects run before middleware, so they use this
|
|
463
|
+
// pre-middleware snapshot. beforeFiles, afterFiles, and fallback
|
|
464
|
+
// rewrites run after middleware (App Router order), so they use
|
|
465
|
+
// postMwReqCtx created after x-middleware-request-* headers are
|
|
466
|
+
// unpacked into request.
|
|
461
467
|
const reqCtx = requestContextFromRequest(request);
|
|
462
468
|
|
|
463
469
|
// ── 3. Run middleware ──────────────────────────────────────────
|
|
464
470
|
let resolvedUrl = urlWithQuery;
|
|
465
|
-
const middlewareHeaders: Record<string, string> = {};
|
|
471
|
+
const middlewareHeaders: Record<string, string | string[]> = {};
|
|
466
472
|
let middlewareRewriteStatus: number | undefined;
|
|
467
473
|
if (typeof runMiddleware === "function") {
|
|
468
474
|
const result = await runMiddleware(request);
|
|
@@ -479,10 +485,22 @@ export default {
|
|
|
479
485
|
}
|
|
480
486
|
}
|
|
481
487
|
|
|
482
|
-
// Collect middleware response headers to merge into final response
|
|
488
|
+
// Collect middleware response headers to merge into final response.
|
|
489
|
+
// Use an array for Set-Cookie to preserve multiple values.
|
|
483
490
|
if (result.responseHeaders) {
|
|
484
491
|
for (const [key, value] of result.responseHeaders) {
|
|
485
|
-
|
|
492
|
+
if (key === "set-cookie") {
|
|
493
|
+
const existing = middlewareHeaders[key];
|
|
494
|
+
if (Array.isArray(existing)) {
|
|
495
|
+
existing.push(value);
|
|
496
|
+
} else if (existing) {
|
|
497
|
+
middlewareHeaders[key] = [existing as string, value];
|
|
498
|
+
} else {
|
|
499
|
+
middlewareHeaders[key] = [value];
|
|
500
|
+
}
|
|
501
|
+
} else {
|
|
502
|
+
middlewareHeaders[key] = value;
|
|
503
|
+
}
|
|
486
504
|
}
|
|
487
505
|
}
|
|
488
506
|
|
|
@@ -503,7 +521,7 @@ export default {
|
|
|
503
521
|
for (const key of Object.keys(middlewareHeaders)) {
|
|
504
522
|
if (key.startsWith(mwReqPrefix)) {
|
|
505
523
|
const realName = key.slice(mwReqPrefix.length);
|
|
506
|
-
mwReqHeaders[realName] = middlewareHeaders[key];
|
|
524
|
+
mwReqHeaders[realName] = middlewareHeaders[key] as string;
|
|
507
525
|
delete middlewareHeaders[key];
|
|
508
526
|
} else if (key.startsWith("x-middleware-")) {
|
|
509
527
|
delete middlewareHeaders[key];
|
|
@@ -523,13 +541,36 @@ export default {
|
|
|
523
541
|
});
|
|
524
542
|
}
|
|
525
543
|
|
|
544
|
+
// Rebuild context after middleware has unpacked x-middleware-request-*
|
|
545
|
+
// headers into the cloned request. Used only for afterFiles and fallback
|
|
546
|
+
// rewrites, which run after middleware in the App Router execution order.
|
|
547
|
+
const postMwReqCtx = requestContextFromRequest(request);
|
|
548
|
+
|
|
526
549
|
let resolvedPathname = resolvedUrl.split("?")[0];
|
|
527
550
|
|
|
528
551
|
// ── 4. Apply custom headers from next.config.js ───────────────
|
|
552
|
+
// Config headers are additive for multi-value headers (Vary,
|
|
553
|
+
// Set-Cookie) and override for everything else. Vary values are
|
|
554
|
+
// comma-joined per HTTP spec. Set-Cookie values are accumulated
|
|
555
|
+
// as arrays (RFC 6265 forbids comma-joining cookies).
|
|
529
556
|
if (configHeaders.length) {
|
|
530
557
|
const matched = matchHeaders(resolvedPathname, configHeaders, reqCtx);
|
|
531
558
|
for (const h of matched) {
|
|
532
|
-
|
|
559
|
+
const lk = h.key.toLowerCase();
|
|
560
|
+
if (lk === "set-cookie") {
|
|
561
|
+
const existing = middlewareHeaders[lk];
|
|
562
|
+
if (Array.isArray(existing)) {
|
|
563
|
+
existing.push(h.value);
|
|
564
|
+
} else if (existing) {
|
|
565
|
+
middlewareHeaders[lk] = [existing as string, h.value];
|
|
566
|
+
} else {
|
|
567
|
+
middlewareHeaders[lk] = [h.value];
|
|
568
|
+
}
|
|
569
|
+
} else if (lk === "vary" && middlewareHeaders[lk]) {
|
|
570
|
+
middlewareHeaders[lk] += ", " + h.value;
|
|
571
|
+
} else {
|
|
572
|
+
middlewareHeaders[lk] = h.value;
|
|
573
|
+
}
|
|
533
574
|
}
|
|
534
575
|
}
|
|
535
576
|
|
|
@@ -551,7 +592,7 @@ export default {
|
|
|
551
592
|
|
|
552
593
|
// ��─ 6. Apply beforeFiles rewrites from next.config.js ─────────
|
|
553
594
|
if (configRewrites.beforeFiles?.length) {
|
|
554
|
-
const rewritten = matchRewrite(resolvedPathname, configRewrites.beforeFiles,
|
|
595
|
+
const rewritten = matchRewrite(resolvedPathname, configRewrites.beforeFiles, postMwReqCtx);
|
|
555
596
|
if (rewritten) {
|
|
556
597
|
if (isExternalUrl(rewritten)) {
|
|
557
598
|
return proxyExternalRequest(request, rewritten);
|
|
@@ -571,7 +612,7 @@ export default {
|
|
|
571
612
|
|
|
572
613
|
// ── 8. Apply afterFiles rewrites from next.config.js ──────────
|
|
573
614
|
if (configRewrites.afterFiles?.length) {
|
|
574
|
-
const rewritten = matchRewrite(resolvedPathname, configRewrites.afterFiles,
|
|
615
|
+
const rewritten = matchRewrite(resolvedPathname, configRewrites.afterFiles, postMwReqCtx);
|
|
575
616
|
if (rewritten) {
|
|
576
617
|
if (isExternalUrl(rewritten)) {
|
|
577
618
|
return proxyExternalRequest(request, rewritten);
|
|
@@ -588,7 +629,7 @@ export default {
|
|
|
588
629
|
|
|
589
630
|
// ── 10. Fallback rewrites (if SSR returned 404) ─────────────
|
|
590
631
|
if (response && response.status === 404 && configRewrites.fallback?.length) {
|
|
591
|
-
const fallbackRewrite = matchRewrite(resolvedPathname, configRewrites.fallback,
|
|
632
|
+
const fallbackRewrite = matchRewrite(resolvedPathname, configRewrites.fallback, postMwReqCtx);
|
|
592
633
|
if (fallbackRewrite) {
|
|
593
634
|
if (isExternalUrl(fallbackRewrite)) {
|
|
594
635
|
return proxyExternalRequest(request, fallbackRewrite);
|
|
@@ -612,19 +653,34 @@ export default {
|
|
|
612
653
|
|
|
613
654
|
/**
|
|
614
655
|
* Merge middleware/config headers into a response.
|
|
615
|
-
* Response headers take precedence over middleware headers
|
|
616
|
-
*
|
|
656
|
+
* Response headers take precedence over middleware headers for all headers
|
|
657
|
+
* except Set-Cookie, which is additive (both middleware and response cookies
|
|
658
|
+
* are preserved). Matches the behavior in prod-server.ts. Uses getSetCookie()
|
|
659
|
+
* to preserve multiple Set-Cookie values.
|
|
617
660
|
*/
|
|
618
661
|
function mergeHeaders(
|
|
619
662
|
response: Response,
|
|
620
|
-
extraHeaders: Record<string, string>,
|
|
663
|
+
extraHeaders: Record<string, string | string[]>,
|
|
621
664
|
statusOverride?: number,
|
|
622
665
|
): Response {
|
|
623
666
|
if (!Object.keys(extraHeaders).length && !statusOverride) return response;
|
|
624
|
-
|
|
625
|
-
//
|
|
626
|
-
const
|
|
627
|
-
|
|
667
|
+
const merged = new Headers();
|
|
668
|
+
// Middleware/config headers go in first (lower precedence)
|
|
669
|
+
for (const [k, v] of Object.entries(extraHeaders)) {
|
|
670
|
+
if (Array.isArray(v)) {
|
|
671
|
+
for (const item of v) merged.append(k, item);
|
|
672
|
+
} else {
|
|
673
|
+
merged.set(k, v);
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
// Response headers overlay them (higher precedence), except Set-Cookie
|
|
677
|
+
// which is additive (both middleware and response cookies should be sent).
|
|
678
|
+
response.headers.forEach((v, k) => {
|
|
679
|
+
if (k === "set-cookie") return;
|
|
680
|
+
merged.set(k, v);
|
|
681
|
+
});
|
|
682
|
+
const responseCookies = response.headers.getSetCookie?.() ?? [];
|
|
683
|
+
for (const cookie of responseCookies) merged.append("set-cookie", cookie);
|
|
628
684
|
return new Response(response.body, {
|
|
629
685
|
status: statusOverride ?? response.status,
|
|
630
686
|
statusText: response.statusText,
|
|
@@ -742,8 +798,8 @@ _isResolvable = isPackageResolvable) {
|
|
|
742
798
|
}
|
|
743
799
|
}
|
|
744
800
|
if (info.hasMDX) {
|
|
745
|
-
// Check if @mdx-js/rollup is already installed
|
|
746
|
-
const hasMdxRollup =
|
|
801
|
+
// Check if @mdx-js/rollup is already installed (walk up for monorepo hoisting)
|
|
802
|
+
const hasMdxRollup = _findInNodeModules(info.root, "@mdx-js/rollup") !== null;
|
|
747
803
|
if (!hasMdxRollup) {
|
|
748
804
|
missing.push({ name: "@mdx-js/rollup", version: "latest" });
|
|
749
805
|
}
|
|
@@ -830,7 +886,10 @@ export function buildWranglerDeployArgs(options) {
|
|
|
830
886
|
return { args, env };
|
|
831
887
|
}
|
|
832
888
|
function runWranglerDeploy(root, options) {
|
|
833
|
-
|
|
889
|
+
// Walk up ancestor directories so the binary is found even when node_modules
|
|
890
|
+
// is hoisted to the workspace root in a monorepo.
|
|
891
|
+
const wranglerBin = _findInNodeModules(root, ".bin/wrangler") ??
|
|
892
|
+
path.join(root, "node_modules", ".bin", "wrangler"); // fallback for error message clarity
|
|
834
893
|
const execOpts = {
|
|
835
894
|
cwd: root,
|
|
836
895
|
stdio: "pipe",
|