vinext 0.0.28 → 0.0.30
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/report.d.ts +117 -0
- package/dist/build/report.d.ts.map +1 -0
- package/dist/build/report.js +303 -0
- package/dist/build/report.js.map +1 -0
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +11 -7
- package/dist/check.js.map +1 -1
- package/dist/cli.js +106 -9
- package/dist/cli.js.map +1 -1
- package/dist/cloudflare/kv-cache-handler.d.ts.map +1 -1
- package/dist/cloudflare/kv-cache-handler.js +58 -42
- package/dist/cloudflare/kv-cache-handler.js.map +1 -1
- package/dist/cloudflare/tpr.d.ts +10 -0
- package/dist/cloudflare/tpr.d.ts.map +1 -1
- package/dist/cloudflare/tpr.js +36 -41
- package/dist/cloudflare/tpr.js.map +1 -1
- package/dist/config/next-config.d.ts.map +1 -1
- package/dist/config/next-config.js +16 -0
- package/dist/config/next-config.js.map +1 -1
- package/dist/entries/app-rsc-entry.d.ts +1 -1
- package/dist/entries/app-rsc-entry.d.ts.map +1 -1
- package/dist/entries/app-rsc-entry.js +225 -186
- package/dist/entries/app-rsc-entry.js.map +1 -1
- package/dist/entries/pages-server-entry.d.ts.map +1 -1
- package/dist/entries/pages-server-entry.js +192 -91
- package/dist/entries/pages-server-entry.js.map +1 -1
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +121 -40
- package/dist/index.js.map +1 -1
- package/dist/routing/app-router.d.ts +2 -0
- package/dist/routing/app-router.d.ts.map +1 -1
- package/dist/routing/app-router.js +131 -104
- package/dist/routing/app-router.js.map +1 -1
- package/dist/routing/pages-router.d.ts.map +1 -1
- package/dist/routing/pages-router.js +17 -57
- package/dist/routing/pages-router.js.map +1 -1
- package/dist/routing/route-trie.d.ts +57 -0
- package/dist/routing/route-trie.d.ts.map +1 -0
- package/dist/routing/route-trie.js +160 -0
- package/dist/routing/route-trie.js.map +1 -0
- package/dist/routing/route-validation.d.ts.map +1 -1
- package/dist/routing/route-validation.js +13 -1
- package/dist/routing/route-validation.js.map +1 -1
- package/dist/routing/utils.d.ts +19 -0
- package/dist/routing/utils.d.ts.map +1 -1
- package/dist/routing/utils.js +47 -0
- package/dist/routing/utils.js.map +1 -1
- package/dist/server/api-handler.d.ts.map +1 -1
- package/dist/server/api-handler.js +28 -13
- package/dist/server/api-handler.js.map +1 -1
- package/dist/server/app-router-entry.js +1 -1
- package/dist/server/app-router-entry.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 +167 -115
- package/dist/server/dev-server.js.map +1 -1
- package/dist/server/image-optimization.d.ts.map +1 -1
- package/dist/server/image-optimization.js +24 -12
- package/dist/server/image-optimization.js.map +1 -1
- package/dist/server/instrumentation.d.ts.map +1 -1
- package/dist/server/instrumentation.js +17 -8
- package/dist/server/instrumentation.js.map +1 -1
- package/dist/server/isr-cache.d.ts.map +1 -1
- package/dist/server/isr-cache.js +8 -3
- package/dist/server/isr-cache.js.map +1 -1
- package/dist/server/metadata-routes.d.ts.map +1 -1
- package/dist/server/metadata-routes.js +56 -18
- package/dist/server/metadata-routes.js.map +1 -1
- package/dist/server/middleware-codegen.d.ts +10 -0
- package/dist/server/middleware-codegen.d.ts.map +1 -1
- package/dist/server/middleware-codegen.js +76 -4
- package/dist/server/middleware-codegen.js.map +1 -1
- package/dist/server/middleware.d.ts.map +1 -1
- package/dist/server/middleware.js +52 -7
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/pages-i18n.d.ts +50 -0
- package/dist/server/pages-i18n.d.ts.map +1 -0
- package/dist/server/pages-i18n.js +152 -0
- package/dist/server/pages-i18n.js.map +1 -0
- 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 +60 -20
- package/dist/server/prod-server.js.map +1 -1
- package/dist/shims/cache-runtime.d.ts +3 -0
- package/dist/shims/cache-runtime.d.ts.map +1 -1
- package/dist/shims/cache-runtime.js +22 -5
- package/dist/shims/cache-runtime.js.map +1 -1
- package/dist/shims/cache.d.ts +3 -0
- package/dist/shims/cache.d.ts.map +1 -1
- package/dist/shims/cache.js +21 -12
- package/dist/shims/cache.js.map +1 -1
- package/dist/shims/constants.d.ts.map +1 -1
- package/dist/shims/constants.js +0 -1
- package/dist/shims/constants.js.map +1 -1
- package/dist/shims/fetch-cache.d.ts +14 -0
- package/dist/shims/fetch-cache.d.ts.map +1 -1
- package/dist/shims/fetch-cache.js +102 -37
- package/dist/shims/fetch-cache.js.map +1 -1
- package/dist/shims/head-state.d.ts +4 -0
- package/dist/shims/head-state.d.ts.map +1 -1
- package/dist/shims/head-state.js +14 -11
- package/dist/shims/head-state.js.map +1 -1
- package/dist/shims/head.d.ts +4 -2
- package/dist/shims/head.d.ts.map +1 -1
- package/dist/shims/head.js +162 -52
- package/dist/shims/head.js.map +1 -1
- package/dist/shims/headers.d.ts +8 -1
- package/dist/shims/headers.d.ts.map +1 -1
- package/dist/shims/headers.js +23 -34
- package/dist/shims/headers.js.map +1 -1
- package/dist/shims/i18n-context.d.ts +27 -0
- package/dist/shims/i18n-context.d.ts.map +1 -0
- package/dist/shims/i18n-context.js +57 -0
- package/dist/shims/i18n-context.js.map +1 -0
- package/dist/shims/i18n-state.d.ts +20 -0
- package/dist/shims/i18n-state.d.ts.map +1 -0
- package/dist/shims/i18n-state.js +53 -0
- package/dist/shims/i18n-state.js.map +1 -0
- package/dist/shims/image.d.ts +2 -0
- package/dist/shims/image.d.ts.map +1 -1
- package/dist/shims/image.js +14 -6
- package/dist/shims/image.js.map +1 -1
- package/dist/shims/internal/utils.d.ts +1 -0
- package/dist/shims/internal/utils.d.ts.map +1 -1
- package/dist/shims/internal/utils.js.map +1 -1
- package/dist/shims/link.d.ts.map +1 -1
- package/dist/shims/link.js +38 -54
- package/dist/shims/link.js.map +1 -1
- package/dist/shims/metadata.d.ts +78 -22
- package/dist/shims/metadata.d.ts.map +1 -1
- package/dist/shims/metadata.js +96 -28
- package/dist/shims/metadata.js.map +1 -1
- package/dist/shims/navigation-state.d.ts +14 -0
- package/dist/shims/navigation-state.d.ts.map +1 -1
- package/dist/shims/navigation-state.js +33 -15
- package/dist/shims/navigation-state.js.map +1 -1
- package/dist/shims/navigation.d.ts +2 -0
- package/dist/shims/navigation.d.ts.map +1 -1
- package/dist/shims/navigation.js +80 -51
- package/dist/shims/navigation.js.map +1 -1
- package/dist/shims/request-context.d.ts.map +1 -1
- package/dist/shims/request-context.js +9 -0
- package/dist/shims/request-context.js.map +1 -1
- package/dist/shims/request-state-types.d.ts +11 -0
- package/dist/shims/request-state-types.d.ts.map +1 -0
- package/dist/shims/request-state-types.js +2 -0
- package/dist/shims/request-state-types.js.map +1 -0
- package/dist/shims/router-state.d.ts +11 -0
- package/dist/shims/router-state.d.ts.map +1 -1
- package/dist/shims/router-state.js +10 -8
- package/dist/shims/router-state.js.map +1 -1
- package/dist/shims/router.d.ts +4 -0
- package/dist/shims/router.d.ts.map +1 -1
- package/dist/shims/router.js +130 -40
- package/dist/shims/router.js.map +1 -1
- package/dist/shims/server.d.ts +8 -1
- package/dist/shims/server.d.ts.map +1 -1
- package/dist/shims/server.js +52 -6
- package/dist/shims/server.js.map +1 -1
- package/dist/shims/unified-request-context.d.ts +66 -0
- package/dist/shims/unified-request-context.d.ts.map +1 -0
- package/dist/shims/unified-request-context.js +116 -0
- package/dist/shims/unified-request-context.js.map +1 -0
- package/dist/shims/url-utils.d.ts +20 -6
- package/dist/shims/url-utils.d.ts.map +1 -1
- package/dist/shims/url-utils.js +79 -0
- package/dist/shims/url-utils.js.map +1 -1
- package/dist/utils/domain-locale.d.ts +18 -0
- package/dist/utils/domain-locale.d.ts.map +1 -0
- package/dist/utils/domain-locale.js +64 -0
- package/dist/utils/domain-locale.js.map +1 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import { createDirectRunner } from "./server/dev-module-runner.js";
|
|
|
10
10
|
import { generateRscEntry } from "./entries/app-rsc-entry.js";
|
|
11
11
|
import { generateSsrEntry } from "./entries/app-ssr-entry.js";
|
|
12
12
|
import { generateBrowserEntry } from "./entries/app-browser-entry.js";
|
|
13
|
+
import { normalizePathnameForRouteMatchStrict } from "./routing/utils.js";
|
|
13
14
|
import { loadNextConfig, resolveNextConfig, } from "./config/next-config.js";
|
|
14
15
|
import { findMiddlewareFile, runMiddleware } from "./server/middleware.js";
|
|
15
16
|
import { logRequest, now } from "./server/request-log.js";
|
|
@@ -227,6 +228,12 @@ const POSTCSS_CONFIG_FILES = [
|
|
|
227
228
|
".postcssrc.yaml",
|
|
228
229
|
".postcssrc.yml",
|
|
229
230
|
];
|
|
231
|
+
/**
|
|
232
|
+
* Module-level cache for resolvePostcssStringPlugins — avoids re-scanning per Vite environment.
|
|
233
|
+
* Stores the Promise itself so concurrent calls (RSC/SSR/Client config() hooks firing in
|
|
234
|
+
* parallel) all await the same in-flight scan rather than each starting their own.
|
|
235
|
+
*/
|
|
236
|
+
const _postcssCache = new Map();
|
|
230
237
|
/**
|
|
231
238
|
* Resolve PostCSS string plugin names in a project's PostCSS config.
|
|
232
239
|
*
|
|
@@ -239,7 +246,14 @@ const POSTCSS_CONFIG_FILES = [
|
|
|
239
246
|
* Returns the resolved PostCSS config object to inject into Vite's
|
|
240
247
|
* `css.postcss`, or `undefined` if no resolution is needed.
|
|
241
248
|
*/
|
|
242
|
-
|
|
249
|
+
function resolvePostcssStringPlugins(projectRoot) {
|
|
250
|
+
if (_postcssCache.has(projectRoot))
|
|
251
|
+
return _postcssCache.get(projectRoot);
|
|
252
|
+
const promise = _resolvePostcssStringPluginsUncached(projectRoot);
|
|
253
|
+
_postcssCache.set(projectRoot, promise);
|
|
254
|
+
return promise;
|
|
255
|
+
}
|
|
256
|
+
async function _resolvePostcssStringPluginsUncached(projectRoot) {
|
|
243
257
|
// Find the PostCSS config file
|
|
244
258
|
let configPath = null;
|
|
245
259
|
for (const name of POSTCSS_CONFIG_FILES) {
|
|
@@ -249,8 +263,9 @@ async function resolvePostcssStringPlugins(projectRoot) {
|
|
|
249
263
|
break;
|
|
250
264
|
}
|
|
251
265
|
}
|
|
252
|
-
if (!configPath)
|
|
266
|
+
if (!configPath) {
|
|
253
267
|
return undefined;
|
|
268
|
+
}
|
|
254
269
|
// Load the config file
|
|
255
270
|
let config;
|
|
256
271
|
try {
|
|
@@ -277,11 +292,13 @@ async function resolvePostcssStringPlugins(projectRoot) {
|
|
|
277
292
|
}
|
|
278
293
|
// Only process array-form plugins that contain string entries
|
|
279
294
|
// (either bare strings or tuple form ["plugin-name", { options }])
|
|
280
|
-
if (!config || !Array.isArray(config.plugins))
|
|
295
|
+
if (!config || !Array.isArray(config.plugins)) {
|
|
281
296
|
return undefined;
|
|
297
|
+
}
|
|
282
298
|
const hasStringPlugins = config.plugins.some((p) => typeof p === "string" || (Array.isArray(p) && typeof p[0] === "string"));
|
|
283
|
-
if (!hasStringPlugins)
|
|
299
|
+
if (!hasStringPlugins) {
|
|
284
300
|
return undefined;
|
|
301
|
+
}
|
|
285
302
|
// Resolve string plugin names to actual plugin functions
|
|
286
303
|
const req = createRequire(path.join(projectRoot, "package.json"));
|
|
287
304
|
const resolved = await Promise.all(config.plugins.filter(Boolean).map(async (plugin) => {
|
|
@@ -556,6 +573,7 @@ function augmentSsrManifestFromBundle(ssrManifest, bundle, root, base = "/") {
|
|
|
556
573
|
return Object.fromEntries(Object.entries(nextManifest).map(([key, files]) => [key, [...files]]));
|
|
557
574
|
}
|
|
558
575
|
export default function vinext(options = {}) {
|
|
576
|
+
const viteMajorVersion = getViteMajorVersion();
|
|
559
577
|
let root;
|
|
560
578
|
let pagesDir;
|
|
561
579
|
let appDir;
|
|
@@ -571,6 +589,11 @@ export default function vinext(options = {}) {
|
|
|
571
589
|
const shimsDir = path.resolve(__dirname, "shims");
|
|
572
590
|
// Shim alias map — populated in config(), used by resolveId() for .js variants
|
|
573
591
|
let nextShimMap = {};
|
|
592
|
+
// Build-only cache for og-inline-fetch-assets to avoid repeated file reads
|
|
593
|
+
// during a single production build. Dev mode skips the cache so asset edits
|
|
594
|
+
// are picked up without restarting the Vite server.
|
|
595
|
+
const _ogInlineCache = new Map();
|
|
596
|
+
let _ogInlineIsBuild = false;
|
|
574
597
|
/**
|
|
575
598
|
* Generate the virtual SSR server entry module.
|
|
576
599
|
* This is the entry point for `vite build --ssr`.
|
|
@@ -650,7 +673,8 @@ export default function vinext(options = {}) {
|
|
|
650
673
|
const plugins = [
|
|
651
674
|
// Resolve tsconfig paths/baseUrl aliases so real-world Next.js repos
|
|
652
675
|
// that use @/*, #/*, or baseUrl imports work out of the box.
|
|
653
|
-
tsconfigPaths
|
|
676
|
+
// Vite 8+ supports this natively via resolve.tsconfigPaths.
|
|
677
|
+
...(viteMajorVersion >= 8 ? [] : [tsconfigPaths()]),
|
|
654
678
|
// React Fast Refresh + JSX transform for client components.
|
|
655
679
|
reactPlugin,
|
|
656
680
|
// Transform CJS require()/module.exports to ESM before other plugins
|
|
@@ -661,6 +685,8 @@ export default function vinext(options = {}) {
|
|
|
661
685
|
enforce: "pre",
|
|
662
686
|
async config(config, env) {
|
|
663
687
|
root = config.root ?? process.cwd();
|
|
688
|
+
const userResolve = config.resolve;
|
|
689
|
+
const shouldEnableNativeTsconfigPaths = viteMajorVersion >= 8 && userResolve?.tsconfigPaths === undefined;
|
|
664
690
|
// Load .env files into process.env before anything else.
|
|
665
691
|
// Next.js loads .env files before evaluating next.config.js, so
|
|
666
692
|
// env vars are available in config, server-side code, and as
|
|
@@ -767,33 +793,59 @@ export default function vinext(options = {}) {
|
|
|
767
793
|
// Also used to namespace ISR cache keys so old cached entries from a
|
|
768
794
|
// previous deploy are never served by the new one.
|
|
769
795
|
defines["process.env.__VINEXT_BUILD_ID"] = JSON.stringify(nextConfig.buildId);
|
|
770
|
-
// Build the shim alias map
|
|
771
|
-
//
|
|
796
|
+
// Build the shim alias map. Exact `.js` variants are included for the
|
|
797
|
+
// public Next entrypoints that are file-backed in `next/package.json`.
|
|
798
|
+
// Some libraries (for example `nuqs`) import `next/navigation.js`
|
|
799
|
+
// directly; aliasing the `.js` form ensures optimizeDeps pre-bundles
|
|
800
|
+
// vinext's shim instead of real Next.
|
|
772
801
|
nextShimMap = {
|
|
773
802
|
...nextConfig.aliases,
|
|
774
803
|
"next/link": path.join(shimsDir, "link"),
|
|
804
|
+
"next/link.js": path.join(shimsDir, "link"),
|
|
775
805
|
"next/head": path.join(shimsDir, "head"),
|
|
806
|
+
"next/head.js": path.join(shimsDir, "head"),
|
|
776
807
|
"next/router": path.join(shimsDir, "router"),
|
|
808
|
+
"next/router.js": path.join(shimsDir, "router"),
|
|
777
809
|
"next/compat/router": path.join(shimsDir, "compat-router"),
|
|
810
|
+
"next/compat/router.js": path.join(shimsDir, "compat-router"),
|
|
778
811
|
"next/image": path.join(shimsDir, "image"),
|
|
812
|
+
"next/image.js": path.join(shimsDir, "image"),
|
|
779
813
|
"next/legacy/image": path.join(shimsDir, "legacy-image"),
|
|
814
|
+
"next/legacy/image.js": path.join(shimsDir, "legacy-image"),
|
|
780
815
|
"next/dynamic": path.join(shimsDir, "dynamic"),
|
|
816
|
+
"next/dynamic.js": path.join(shimsDir, "dynamic"),
|
|
781
817
|
"next/app": path.join(shimsDir, "app"),
|
|
818
|
+
"next/app.js": path.join(shimsDir, "app"),
|
|
782
819
|
"next/document": path.join(shimsDir, "document"),
|
|
820
|
+
"next/document.js": path.join(shimsDir, "document"),
|
|
783
821
|
"next/config": path.join(shimsDir, "config"),
|
|
822
|
+
"next/config.js": path.join(shimsDir, "config"),
|
|
784
823
|
"next/script": path.join(shimsDir, "script"),
|
|
824
|
+
"next/script.js": path.join(shimsDir, "script"),
|
|
785
825
|
"next/server": path.join(shimsDir, "server"),
|
|
826
|
+
"next/server.js": path.join(shimsDir, "server"),
|
|
786
827
|
"next/navigation": path.join(shimsDir, "navigation"),
|
|
828
|
+
"next/navigation.js": path.join(shimsDir, "navigation"),
|
|
787
829
|
"next/headers": path.join(shimsDir, "headers"),
|
|
830
|
+
"next/headers.js": path.join(shimsDir, "headers"),
|
|
788
831
|
"next/font/google": path.join(shimsDir, "font-google"),
|
|
832
|
+
"next/font/google.js": path.join(shimsDir, "font-google"),
|
|
789
833
|
"next/font/local": path.join(shimsDir, "font-local"),
|
|
834
|
+
"next/font/local.js": path.join(shimsDir, "font-local"),
|
|
790
835
|
"next/cache": path.join(shimsDir, "cache"),
|
|
836
|
+
"next/cache.js": path.join(shimsDir, "cache"),
|
|
791
837
|
"next/form": path.join(shimsDir, "form"),
|
|
838
|
+
"next/form.js": path.join(shimsDir, "form"),
|
|
792
839
|
"next/og": path.join(shimsDir, "og"),
|
|
840
|
+
"next/og.js": path.join(shimsDir, "og"),
|
|
793
841
|
"next/web-vitals": path.join(shimsDir, "web-vitals"),
|
|
842
|
+
"next/web-vitals.js": path.join(shimsDir, "web-vitals"),
|
|
794
843
|
"next/amp": path.join(shimsDir, "amp"),
|
|
844
|
+
"next/amp.js": path.join(shimsDir, "amp"),
|
|
795
845
|
"next/error": path.join(shimsDir, "error"),
|
|
846
|
+
"next/error.js": path.join(shimsDir, "error"),
|
|
796
847
|
"next/constants": path.join(shimsDir, "constants"),
|
|
848
|
+
"next/constants.js": path.join(shimsDir, "constants"),
|
|
797
849
|
// Internal next/dist/* paths used by popular libraries
|
|
798
850
|
// (next-intl, @clerk/nextjs, @sentry/nextjs, next-nprogress-bar, etc.)
|
|
799
851
|
"next/dist/shared/lib/app-router-context.shared-runtime": path.join(shimsDir, "internal", "app-router-context"),
|
|
@@ -819,8 +871,11 @@ export default function vinext(options = {}) {
|
|
|
819
871
|
"vinext/fetch-cache": path.join(shimsDir, "fetch-cache"),
|
|
820
872
|
"vinext/cache-runtime": path.join(shimsDir, "cache-runtime"),
|
|
821
873
|
"vinext/navigation-state": path.join(shimsDir, "navigation-state"),
|
|
874
|
+
"vinext/unified-request-context": path.join(shimsDir, "unified-request-context"),
|
|
822
875
|
"vinext/router-state": path.join(shimsDir, "router-state"),
|
|
823
876
|
"vinext/head-state": path.join(shimsDir, "head-state"),
|
|
877
|
+
"vinext/i18n-state": path.join(shimsDir, "i18n-state"),
|
|
878
|
+
"vinext/i18n-context": path.join(shimsDir, "i18n-context"),
|
|
824
879
|
"vinext/instrumentation": path.resolve(__dirname, "server", "instrumentation"),
|
|
825
880
|
"vinext/html": path.resolve(__dirname, "server", "html"),
|
|
826
881
|
};
|
|
@@ -986,6 +1041,7 @@ export default function vinext(options = {}) {
|
|
|
986
1041
|
// causing cryptic "Invalid hook call" errors. This is a no-op
|
|
987
1042
|
// when only one copy exists.
|
|
988
1043
|
dedupe: ["react", "react-dom", "react/jsx-runtime", "react/jsx-dev-runtime"],
|
|
1044
|
+
...(shouldEnableNativeTsconfigPaths ? { tsconfigPaths: true } : {}),
|
|
989
1045
|
},
|
|
990
1046
|
// Exclude vinext from dependency optimization so esbuild doesn't
|
|
991
1047
|
// scan dist files containing virtual module imports (virtual:vinext-*)
|
|
@@ -998,7 +1054,7 @@ export default function vinext(options = {}) {
|
|
|
998
1054
|
},
|
|
999
1055
|
// Enable JSX in .tsx/.jsx files
|
|
1000
1056
|
// Vite 7 uses `esbuild` for transforms, Vite 8+ uses `oxc`
|
|
1001
|
-
...(
|
|
1057
|
+
...(viteMajorVersion >= 8
|
|
1002
1058
|
? { oxc: { jsx: { runtime: "automatic" } } }
|
|
1003
1059
|
: { esbuild: { jsx: "automatic" } }),
|
|
1004
1060
|
// Define env vars for client bundle
|
|
@@ -1099,6 +1155,10 @@ export default function vinext(options = {}) {
|
|
|
1099
1155
|
consumer: "client",
|
|
1100
1156
|
optimizeDeps: {
|
|
1101
1157
|
exclude: ["vinext"],
|
|
1158
|
+
// Crawl app/ source files up front so client-only deps imported
|
|
1159
|
+
// by user components are discovered during startup instead of
|
|
1160
|
+
// triggering a late re-optimisation + full page reload.
|
|
1161
|
+
entries: appEntries,
|
|
1102
1162
|
// React packages aren't crawled from app/ source files,
|
|
1103
1163
|
// so must be pre-included to avoid late discovery (#25).
|
|
1104
1164
|
include: [
|
|
@@ -1193,18 +1253,6 @@ export default function vinext(options = {}) {
|
|
|
1193
1253
|
// ID (with \0 prefix). We need to re-resolve it so the client
|
|
1194
1254
|
// environment's import-analysis can find it.
|
|
1195
1255
|
const cleanId = id.startsWith("\0") ? id.slice(1) : id;
|
|
1196
|
-
// Handle next/* imports with .js extension (e.g. "next/navigation.js")
|
|
1197
|
-
// Libraries like nuqs import "next/navigation.js" which doesn't match
|
|
1198
|
-
// our resolve.alias for "next/navigation". Strip the .js and resolve
|
|
1199
|
-
// through our shim map, appending .js to the resolved path.
|
|
1200
|
-
if (cleanId.startsWith("next/") && cleanId.endsWith(".js")) {
|
|
1201
|
-
const withoutExt = cleanId.slice(0, -3);
|
|
1202
|
-
if (nextShimMap[withoutExt]) {
|
|
1203
|
-
const shimPath = nextShimMap[withoutExt];
|
|
1204
|
-
// Alias values don't include .js — append it for resolveId
|
|
1205
|
-
return shimPath.endsWith(".js") ? shimPath : shimPath + ".js";
|
|
1206
|
-
}
|
|
1207
|
-
}
|
|
1208
1256
|
// Pages Router virtual modules
|
|
1209
1257
|
if (cleanId === VIRTUAL_SERVER_ENTRY)
|
|
1210
1258
|
return RESOLVED_SERVER_ENTRY;
|
|
@@ -1662,7 +1710,8 @@ export default function vinext(options = {}) {
|
|
|
1662
1710
|
res.end("Only relative URLs allowed");
|
|
1663
1711
|
return;
|
|
1664
1712
|
}
|
|
1665
|
-
|
|
1713
|
+
const encodedLocation = resolvedImg.pathname + resolvedImg.search;
|
|
1714
|
+
res.writeHead(302, { Location: encodedLocation });
|
|
1666
1715
|
res.end();
|
|
1667
1716
|
return;
|
|
1668
1717
|
}
|
|
@@ -1695,7 +1744,7 @@ export default function vinext(options = {}) {
|
|
|
1695
1744
|
// decodeURIComponent prevents /%61dmin bypassing /admin matchers.
|
|
1696
1745
|
// normalizePath collapses // and resolves . / .. segments.
|
|
1697
1746
|
try {
|
|
1698
|
-
pathname = normalizePath(
|
|
1747
|
+
pathname = normalizePath(normalizePathnameForRouteMatchStrict(pathname));
|
|
1699
1748
|
}
|
|
1700
1749
|
catch {
|
|
1701
1750
|
// Malformed percent-encoding (e.g. /%E0%A4%A) — return 400 instead of crashing.
|
|
@@ -1821,7 +1870,7 @@ export default function vinext(options = {}) {
|
|
|
1821
1870
|
for (const [key, value] of result.response.headers) {
|
|
1822
1871
|
res.appendHeader(key, value);
|
|
1823
1872
|
}
|
|
1824
|
-
const body = await result.response.
|
|
1873
|
+
const body = Buffer.from(await result.response.arrayBuffer());
|
|
1825
1874
|
res.end(body);
|
|
1826
1875
|
return;
|
|
1827
1876
|
}
|
|
@@ -1926,7 +1975,7 @@ export default function vinext(options = {}) {
|
|
|
1926
1975
|
await proxyExternalRewriteNode(req, res, resolvedUrl);
|
|
1927
1976
|
return;
|
|
1928
1977
|
}
|
|
1929
|
-
const handler = createSSRHandler(server, routes, pagesDir, nextConfig?.i18n, fileMatcher);
|
|
1978
|
+
const handler = createSSRHandler(server, routes, pagesDir, nextConfig?.i18n, fileMatcher, nextConfig?.basePath ?? "", nextConfig?.trailingSlash ?? false);
|
|
1930
1979
|
const mwStatus = req.__vinextRewriteStatus;
|
|
1931
1980
|
// Try rendering the resolved URL
|
|
1932
1981
|
const match = matchRoute(resolvedUrl.split("?")[0], routes);
|
|
@@ -2462,11 +2511,20 @@ export default function vinext(options = {}) {
|
|
|
2462
2511
|
{
|
|
2463
2512
|
name: "vinext:og-inline-fetch-assets",
|
|
2464
2513
|
enforce: "pre",
|
|
2465
|
-
|
|
2514
|
+
configResolved(config) {
|
|
2515
|
+
_ogInlineIsBuild = config.command === "build";
|
|
2516
|
+
},
|
|
2517
|
+
buildStart() {
|
|
2518
|
+
if (_ogInlineIsBuild) {
|
|
2519
|
+
_ogInlineCache.clear();
|
|
2520
|
+
}
|
|
2521
|
+
},
|
|
2522
|
+
async transform(code, id) {
|
|
2466
2523
|
// Quick bail-out: only process modules that use new URL(..., import.meta.url)
|
|
2467
2524
|
if (!code.includes("import.meta.url")) {
|
|
2468
2525
|
return null;
|
|
2469
2526
|
}
|
|
2527
|
+
const useCache = _ogInlineIsBuild;
|
|
2470
2528
|
const moduleDir = path.dirname(id);
|
|
2471
2529
|
let newCode = code;
|
|
2472
2530
|
let didReplace = false;
|
|
@@ -2478,13 +2536,19 @@ export default function vinext(options = {}) {
|
|
|
2478
2536
|
const fullMatch = match[0];
|
|
2479
2537
|
const relPath = match[2]; // e.g. "./noto-sans-v27-latin-regular.ttf"
|
|
2480
2538
|
const absPath = path.resolve(moduleDir, relPath);
|
|
2481
|
-
let fileBase64;
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2539
|
+
let fileBase64 = useCache ? _ogInlineCache.get(absPath) : undefined;
|
|
2540
|
+
if (fileBase64 === undefined) {
|
|
2541
|
+
try {
|
|
2542
|
+
const buf = await fs.promises.readFile(absPath);
|
|
2543
|
+
fileBase64 = buf.toString("base64");
|
|
2544
|
+
if (useCache) {
|
|
2545
|
+
_ogInlineCache.set(absPath, fileBase64);
|
|
2546
|
+
}
|
|
2547
|
+
}
|
|
2548
|
+
catch {
|
|
2549
|
+
// File not found on disk — skip (may be a runtime-only asset)
|
|
2550
|
+
continue;
|
|
2551
|
+
}
|
|
2488
2552
|
}
|
|
2489
2553
|
// Replace fetch(...).then(...) with an inline IIFE that returns Promise<ArrayBuffer>.
|
|
2490
2554
|
const inlined = [
|
|
@@ -2509,13 +2573,19 @@ export default function vinext(options = {}) {
|
|
|
2509
2573
|
const fullMatch = match[0];
|
|
2510
2574
|
const relPath = match[2]; // e.g. "./noto-sans-v27-latin-regular.ttf"
|
|
2511
2575
|
const absPath = path.resolve(moduleDir, relPath);
|
|
2512
|
-
let fileBase64;
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2576
|
+
let fileBase64 = useCache ? _ogInlineCache.get(absPath) : undefined;
|
|
2577
|
+
if (fileBase64 === undefined) {
|
|
2578
|
+
try {
|
|
2579
|
+
const buf = await fs.promises.readFile(absPath);
|
|
2580
|
+
fileBase64 = buf.toString("base64");
|
|
2581
|
+
if (useCache) {
|
|
2582
|
+
_ogInlineCache.set(absPath, fileBase64);
|
|
2583
|
+
}
|
|
2584
|
+
}
|
|
2585
|
+
catch {
|
|
2586
|
+
// File not found on disk — skip
|
|
2587
|
+
continue;
|
|
2588
|
+
}
|
|
2519
2589
|
}
|
|
2520
2590
|
// Replace readFileSync(...) with Buffer.from("<base64>", "base64").
|
|
2521
2591
|
// Buffer is always available in Node.js and in the vinext SSR/RSC environments.
|
|
@@ -3104,15 +3174,23 @@ function findFileWithExts(dir, name, matcher) {
|
|
|
3104
3174
|
}
|
|
3105
3175
|
return null;
|
|
3106
3176
|
}
|
|
3177
|
+
/** Module-level cache for hasMdxFiles — avoids re-scanning per Vite environment. */
|
|
3178
|
+
const _mdxScanCache = new Map();
|
|
3107
3179
|
/**
|
|
3108
3180
|
* Check if the project has .mdx files in app/ or pages/ directories.
|
|
3109
3181
|
*/
|
|
3110
3182
|
function hasMdxFiles(root, appDir, pagesDir) {
|
|
3183
|
+
const cacheKey = `${root}\0${appDir ?? ""}\0${pagesDir ?? ""}`;
|
|
3184
|
+
if (_mdxScanCache.has(cacheKey))
|
|
3185
|
+
return _mdxScanCache.get(cacheKey);
|
|
3111
3186
|
const dirs = [appDir, pagesDir].filter(Boolean);
|
|
3112
3187
|
for (const dir of dirs) {
|
|
3113
|
-
if (fs.existsSync(dir) && scanDirForMdx(dir))
|
|
3188
|
+
if (fs.existsSync(dir) && scanDirForMdx(dir)) {
|
|
3189
|
+
_mdxScanCache.set(cacheKey, true);
|
|
3114
3190
|
return true;
|
|
3191
|
+
}
|
|
3115
3192
|
}
|
|
3193
|
+
_mdxScanCache.set(cacheKey, false);
|
|
3116
3194
|
return false;
|
|
3117
3195
|
}
|
|
3118
3196
|
function scanDirForMdx(dir) {
|
|
@@ -3142,6 +3220,9 @@ export { staticExportPages, staticExportApp } from "./build/static-export.js";
|
|
|
3142
3220
|
export { clientManualChunks, clientOutputConfig, clientTreeshakeConfig, computeLazyChunks };
|
|
3143
3221
|
export { augmentSsrManifestFromBundle as _augmentSsrManifestFromBundle };
|
|
3144
3222
|
export { resolvePostcssStringPlugins as _resolvePostcssStringPlugins };
|
|
3223
|
+
export { _postcssCache };
|
|
3224
|
+
export { hasMdxFiles as _hasMdxFiles };
|
|
3225
|
+
export { _mdxScanCache };
|
|
3145
3226
|
export { parseStaticObjectLiteral as _parseStaticObjectLiteral };
|
|
3146
3227
|
export { stripServerExports as _stripServerExports };
|
|
3147
3228
|
export { asyncHooksStubPlugin as _asyncHooksStubPlugin };
|