vite-plugin-vercel 11.0.0-beta.15 → 11.0.0-beta.17
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/vite.js +54 -3
- package/package.json +1 -1
package/dist/vite.js
CHANGED
|
@@ -543,6 +543,30 @@ function getVcConfig(pluginConfig, filename, options) {
|
|
|
543
543
|
});
|
|
544
544
|
}
|
|
545
545
|
|
|
546
|
+
//#endregion
|
|
547
|
+
//#region src/utils/request.ts
|
|
548
|
+
function getOriginalRequest(request) {
|
|
549
|
+
const xNowRouteMatchesHeader = request.headers.get("x-now-route-matches");
|
|
550
|
+
let newUrl = null;
|
|
551
|
+
let newRequest = request;
|
|
552
|
+
if (typeof xNowRouteMatchesHeader === "string") {
|
|
553
|
+
const originalPathBis = new URLSearchParams(xNowRouteMatchesHeader).get("1");
|
|
554
|
+
if (originalPathBis) newUrl = new URL(originalPathBis, request.url).toString();
|
|
555
|
+
}
|
|
556
|
+
if (newUrl) newRequest = new Request(newUrl, {
|
|
557
|
+
method: request.method,
|
|
558
|
+
headers: request.headers,
|
|
559
|
+
body: request.body,
|
|
560
|
+
mode: request.mode,
|
|
561
|
+
credentials: request.credentials,
|
|
562
|
+
cache: request.cache,
|
|
563
|
+
redirect: request.redirect,
|
|
564
|
+
referrer: request.referrer,
|
|
565
|
+
integrity: request.integrity
|
|
566
|
+
});
|
|
567
|
+
return newRequest;
|
|
568
|
+
}
|
|
569
|
+
|
|
546
570
|
//#endregion
|
|
547
571
|
//#region src/plugins/loader.ts
|
|
548
572
|
const re_DUMMY = new RegExp(`__DUMMY__$`);
|
|
@@ -584,8 +608,15 @@ function loaderPlugin(pluginConfig) {
|
|
|
584
608
|
async handler(id) {
|
|
585
609
|
const mod = id.replace(re_edge, "");
|
|
586
610
|
return `import mod from ${JSON.stringify(mod)};
|
|
587
|
-
|
|
588
|
-
|
|
611
|
+
|
|
612
|
+
${getOriginalRequest.toString()}
|
|
613
|
+
|
|
614
|
+
const fn = (...args) => {
|
|
615
|
+
Object.assign(args[0], getOriginalRequest(request));
|
|
616
|
+
return mod.fetch(...args);
|
|
617
|
+
};
|
|
618
|
+
|
|
619
|
+
export default fn`;
|
|
589
620
|
}
|
|
590
621
|
}
|
|
591
622
|
},
|
|
@@ -605,7 +636,19 @@ export default def;`;
|
|
|
605
636
|
async handler(id) {
|
|
606
637
|
const mod = id.replace(re_node, "");
|
|
607
638
|
return `import mod from ${JSON.stringify(mod)};
|
|
639
|
+
|
|
640
|
+
${getOriginalRequest.toString()}
|
|
641
|
+
|
|
642
|
+
if (mod?.fetch) {
|
|
643
|
+
const ori = mod.fetch;
|
|
644
|
+
mod.fetch = (...args) => {
|
|
645
|
+
Object.assign(args[0], getOriginalRequest(request));
|
|
646
|
+
return ori(...args);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
|
|
608
650
|
const def = mod?.server?.nodeHandler ?? mod;
|
|
651
|
+
|
|
609
652
|
export default def;`;
|
|
610
653
|
}
|
|
611
654
|
}
|
|
@@ -630,7 +673,10 @@ export default def;`;
|
|
|
630
673
|
const entries = dedupeRoutes().filter((e) => (e.vercel?.edge ?? false) === isEdge);
|
|
631
674
|
return { build: { rollupOptions: {
|
|
632
675
|
input: Object.fromEntries(entries.map((e) => [entryDestination(root ?? process.cwd(), e, ".func/index"), isEdge ? `${e.id}?vercel_edge` : `${e.id}?vercel_node`])),
|
|
633
|
-
output: {
|
|
676
|
+
output: {
|
|
677
|
+
hoistTransitiveImports: false,
|
|
678
|
+
entryFileNames: "[name].js"
|
|
679
|
+
}
|
|
634
680
|
} } };
|
|
635
681
|
}
|
|
636
682
|
}
|
|
@@ -742,6 +788,7 @@ function getConfig(pluginConfig) {
|
|
|
742
788
|
routes: buildRoutes
|
|
743
789
|
}]
|
|
744
790
|
});
|
|
791
|
+
for (const route of cleanRoutes) wrapRouteInParentheses(route);
|
|
745
792
|
return vercelOutputConfigSchema.parse({
|
|
746
793
|
version: 3,
|
|
747
794
|
...pluginConfig.config,
|
|
@@ -749,6 +796,10 @@ function getConfig(pluginConfig) {
|
|
|
749
796
|
overrides: { ...pluginConfig.config?.overrides }
|
|
750
797
|
});
|
|
751
798
|
}
|
|
799
|
+
function wrapRouteInParentheses(route) {
|
|
800
|
+
if (!route.dest || route.dest.match(/^\(.*\)$/) || route.dest.match(/^\^\(.*\)\$$/)) return;
|
|
801
|
+
route.dest = `(${route.dest})`;
|
|
802
|
+
}
|
|
752
803
|
|
|
753
804
|
//#endregion
|
|
754
805
|
//#region src/utils/const.ts
|