vite-plugin-vercel 11.0.0-beta.9 → 11.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -5
- package/dist/{api-DR2y7JVQ.js → api-DQ9HQe2a.js} +1 -3
- package/dist/api.js +2 -3
- package/dist/index.js +3 -5
- package/dist/{path-B4ThGm96.js → path-CzW38gOA.js} +1 -3
- package/dist/types.js +1 -1
- package/dist/vite.js +121 -77
- package/package.json +21 -20
package/README.md
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
# vite-plugin-vercel
|
|
2
2
|
|
|
3
|
-
> [!NOTE]
|
|
4
|
-
> You are on the [Vite Environment API](https://vite.dev/guide/api-environment.html#environment-configuration) beta branch (v11). Check out [v9 branch](https://github.com/magne4000/vite-plugin-vercel/tree/v9) for current stable version.
|
|
5
|
-
|
|
6
3
|
Vercel adapter for [Vite](https://vitejs.dev/).
|
|
7
4
|
|
|
8
|
-
Bundle your Vite application as supported by [Vercel Output API
|
|
5
|
+
Bundle your Vite application as supported by [Vercel Output API](https://vercel.com/docs/build-output-api).
|
|
9
6
|
|
|
10
7
|
## Install
|
|
11
8
|
|
|
@@ -111,7 +108,7 @@ import vercel from 'vite-plugin-vercel';
|
|
|
111
108
|
|
|
112
109
|
export default defineConfig({
|
|
113
110
|
plugins: [vercel({
|
|
114
|
-
// All the followings optional
|
|
111
|
+
// All the followings are optional
|
|
115
112
|
|
|
116
113
|
/**
|
|
117
114
|
* How long Functions should be allowed to run for every request, in seconds.
|
|
@@ -3,7 +3,6 @@ function assert(condition, errorMessage) {
|
|
|
3
3
|
if (condition) return;
|
|
4
4
|
throw new Error(`[vite-plugin-vercel] ${errorMessage}`);
|
|
5
5
|
}
|
|
6
|
-
|
|
7
6
|
//#endregion
|
|
8
7
|
//#region src/api.ts
|
|
9
8
|
function createAPI(outfiles, pluginConfig) {
|
|
@@ -65,6 +64,5 @@ function getVercelAPI(pluginContextOrServer) {
|
|
|
65
64
|
assert(vpv.api, "Missing `api`. Make sure vite-plugin-vercel is up-to-date");
|
|
66
65
|
return vpv.api("environment" in pluginContextOrServer ? pluginContextOrServer : void 0);
|
|
67
66
|
}
|
|
68
|
-
|
|
69
67
|
//#endregion
|
|
70
|
-
export { getVercelAPI as n, assert as r, createAPI as t };
|
|
68
|
+
export { getVercelAPI as n, assert as r, createAPI as t };
|
package/dist/api.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { n as getVercelAPI, t as createAPI } from "./api-
|
|
2
|
-
|
|
3
|
-
export { createAPI, getVercelAPI };
|
|
1
|
+
import { n as getVercelAPI, t as createAPI } from "./api-DQ9HQe2a.js";
|
|
2
|
+
export { createAPI, getVercelAPI };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as pathRelativeTo } from "./path-
|
|
1
|
+
import { t as pathRelativeTo } from "./path-CzW38gOA.js";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { vercelEndpointExports } from "@vite-plugin-vercel/schemas";
|
|
4
4
|
import { fromNextFs } from "convert-route/next-fs";
|
|
@@ -6,7 +6,6 @@ import { toRou3 } from "convert-route/rou3";
|
|
|
6
6
|
import glob from "fast-glob";
|
|
7
7
|
import { generateCode, loadFile } from "magicast";
|
|
8
8
|
import { normalizePath } from "vite";
|
|
9
|
-
|
|
10
9
|
//#region src/index.ts
|
|
11
10
|
/**
|
|
12
11
|
* Scans the filesystem for entry points.
|
|
@@ -31,7 +30,7 @@ async function getVercelEntries(dir, { destination = dir, tryParseExports = true
|
|
|
31
30
|
if (xports?.isr) entry.vercel.isr = xports.isr;
|
|
32
31
|
if (xports?.headers) entry.vercel.headers = xports.headers;
|
|
33
32
|
if (xports?.streaming) entry.vercel.streaming = xports.streaming;
|
|
34
|
-
entry.
|
|
33
|
+
entry.route = entryToRou3(key);
|
|
35
34
|
if (key.includes("[...")) entry.vercel.enforce = "post";
|
|
36
35
|
entryPoints.push(entry);
|
|
37
36
|
}
|
|
@@ -65,6 +64,5 @@ function evalExport(exp) {
|
|
|
65
64
|
if (!exp) return;
|
|
66
65
|
return _eval(isPrimitive(exp) ? exp : generateCode(exp).code);
|
|
67
66
|
}
|
|
68
|
-
|
|
69
67
|
//#endregion
|
|
70
|
-
export { extractExports, getVercelEntries };
|
|
68
|
+
export { extractExports, getVercelEntries };
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { normalizePath } from "vite";
|
|
3
|
-
|
|
4
3
|
//#region src/utils/path.ts
|
|
5
4
|
function pathRelativeTo(filePath, rel) {
|
|
6
5
|
return normalizePath(path.relative(normalizePath(path.resolve(rel)), path.resolve(filePath)));
|
|
7
6
|
}
|
|
8
|
-
|
|
9
7
|
//#endregion
|
|
10
|
-
export { pathRelativeTo as t };
|
|
8
|
+
export { pathRelativeTo as t };
|
package/dist/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {};
|
package/dist/vite.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { t as pathRelativeTo$1 } from "./path-
|
|
2
|
-
import { n as getVercelAPI, r as assert, t as createAPI } from "./api-
|
|
1
|
+
import { t as pathRelativeTo$1 } from "./path-CzW38gOA.js";
|
|
2
|
+
import { n as getVercelAPI, r as assert, t as createAPI } from "./api-DQ9HQe2a.js";
|
|
3
3
|
import { builtinModules } from "node:module";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { vercelOutputConfigSchema, vercelOutputPrerenderConfigSchema, vercelOutputVcConfigSchema } from "@vite-plugin-vercel/schemas";
|
|
6
6
|
import { fromRou3 } from "convert-route/rou3";
|
|
7
7
|
import { BuildEnvironment, createRunnableDevEnvironment, mergeConfig, normalizePath } from "vite";
|
|
8
|
-
import { catchAll, devServer } from "@universal-deploy/
|
|
9
|
-
import {
|
|
8
|
+
import { catchAll, devServer } from "@universal-deploy/vite";
|
|
9
|
+
import { addEntry, getAllEntries } from "@universal-deploy/store";
|
|
10
10
|
import fs, { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
11
11
|
import { copyFile, cp, rmdir, unlink } from "node:fs/promises";
|
|
12
12
|
import { findRoot } from "@manypkg/find-root";
|
|
@@ -19,7 +19,6 @@ import pLimit from "p-limit";
|
|
|
19
19
|
import { getNodeVersion } from "@vercel/build-utils";
|
|
20
20
|
import { toPathToRegexpV6 } from "convert-route/path-to-regexp-v6";
|
|
21
21
|
import { getTransformedRoutes, mergeRoutes, normalizeRoutes } from "@vercel/routing-utils";
|
|
22
|
-
|
|
23
22
|
//#region src/utils/buildEnvs.ts
|
|
24
23
|
function getBuildEnvNames(pluginConfig) {
|
|
25
24
|
return {
|
|
@@ -28,7 +27,6 @@ function getBuildEnvNames(pluginConfig) {
|
|
|
28
27
|
node: pluginConfig.viteEnvNames?.node ?? "vercel_node"
|
|
29
28
|
};
|
|
30
29
|
}
|
|
31
|
-
|
|
32
30
|
//#endregion
|
|
33
31
|
//#region src/utils/dedupeRoutes.ts
|
|
34
32
|
/**
|
|
@@ -37,17 +35,17 @@ function getBuildEnvNames(pluginConfig) {
|
|
|
37
35
|
*/
|
|
38
36
|
function dedupeRoutes() {
|
|
39
37
|
const entriesToKeep = [];
|
|
40
|
-
const entriesGroupedByModuleId = groupBy(
|
|
38
|
+
const entriesGroupedByModuleId = groupBy(getAllEntries(), (e) => e.id);
|
|
41
39
|
for (const entries of entriesGroupedByModuleId.values()) {
|
|
42
40
|
let groupedEntry;
|
|
43
41
|
for (const entry of entries) if (entry.vercel && Object.keys(entry.vercel).length > 0) {
|
|
44
|
-
if (!Array.isArray(entry.
|
|
42
|
+
if (!Array.isArray(entry.route)) entry.route = [entry.route];
|
|
45
43
|
entriesToKeep.push(entry);
|
|
46
44
|
} else if (!groupedEntry) {
|
|
47
45
|
groupedEntry = structuredClone(entry);
|
|
48
|
-
if (!Array.isArray(groupedEntry.
|
|
46
|
+
if (!Array.isArray(groupedEntry.route)) groupedEntry.route = [groupedEntry.route];
|
|
49
47
|
entriesToKeep.push(groupedEntry);
|
|
50
|
-
} else groupedEntry.
|
|
48
|
+
} else groupedEntry.route.push(...[entry.route].flat());
|
|
51
49
|
}
|
|
52
50
|
return entriesToKeep;
|
|
53
51
|
}
|
|
@@ -105,27 +103,47 @@ function groupBy(list, fn, selector) {
|
|
|
105
103
|
return acc;
|
|
106
104
|
}, /* @__PURE__ */ new Map());
|
|
107
105
|
}
|
|
108
|
-
|
|
109
106
|
//#endregion
|
|
110
107
|
//#region src/utils/extension.ts
|
|
111
108
|
function removeExtension$1(subject) {
|
|
112
109
|
return subject.replace(/\.[^/.]+$/, "");
|
|
113
110
|
}
|
|
114
|
-
|
|
115
111
|
//#endregion
|
|
116
112
|
//#region src/utils/destination.ts
|
|
113
|
+
function parseViteId(id) {
|
|
114
|
+
const [path, query] = id.split("?");
|
|
115
|
+
return {
|
|
116
|
+
path: decodeURIComponent(path),
|
|
117
|
+
query
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function extractBestPath({ path, query }) {
|
|
121
|
+
if (!query) return path;
|
|
122
|
+
return query.split("&").map(decodeURIComponent).find((p) => p.includes("/")) || path;
|
|
123
|
+
}
|
|
124
|
+
function shortenPath(path, maxSegments = 2) {
|
|
125
|
+
return removeExtension$1(path.split(/[\\/]/).filter(Boolean).slice(-maxSegments).join("_"));
|
|
126
|
+
}
|
|
127
|
+
function mapPath(path, maxSegments = 2) {
|
|
128
|
+
const nodeModuleMatch = path.match(/node_modules[\\/](.+?)([\\/].*)?$/);
|
|
129
|
+
if (nodeModuleMatch) return `${nodeModuleMatch[1].split(/[\\/]/)[0]}_${removeExtension$1(nodeModuleMatch[2]?.split(/[\\/]/).pop() || "index")}`;
|
|
130
|
+
return shortenPath(path, maxSegments);
|
|
131
|
+
}
|
|
132
|
+
function hashString(str, length = 6) {
|
|
133
|
+
let hash = 5381;
|
|
134
|
+
for (let i = 0; i < str.length; i++) hash = hash * 33 ^ str.charCodeAt(i);
|
|
135
|
+
hash = hash >>> 0;
|
|
136
|
+
return hash.toString(36).slice(0, length);
|
|
137
|
+
}
|
|
138
|
+
function uniqueViteName(id, entry, maxSegments = 2) {
|
|
139
|
+
return removeExtension$1(`${mapPath(extractBestPath(parseViteId(id)), maxSegments)}_${hashString(JSON.stringify(entry))}`.replace(/[^a-zA-Z0-9\-_[\]/]/g, "-"));
|
|
140
|
+
}
|
|
117
141
|
function entryDestinationDefault(root, entry) {
|
|
118
|
-
|
|
119
|
-
if (rel.includes("node_modules")) {
|
|
120
|
-
const split = rel.split("node_modules");
|
|
121
|
-
rel = split[split.length - 1];
|
|
122
|
-
}
|
|
123
|
-
return `${removeExtension$1(rel).replace(/[^a-zA-Z0-9\-_[\]/]/g, "-")}`;
|
|
142
|
+
return uniqueViteName(pathRelativeTo$1(entry.id, root), entry);
|
|
124
143
|
}
|
|
125
144
|
function entryDestination(root, entry, postfix) {
|
|
126
145
|
return `${path.posix.join("functions/", entryDestinationDefault(root, entry))}${postfix}`;
|
|
127
146
|
}
|
|
128
|
-
|
|
129
147
|
//#endregion
|
|
130
148
|
//#region src/plugins/api.ts
|
|
131
149
|
function apiPlugin(pluginConfig) {
|
|
@@ -139,10 +157,10 @@ function apiPlugin(pluginConfig) {
|
|
|
139
157
|
applyToEnvironment({ name }) {
|
|
140
158
|
return name === envNames.edge || name === envNames.node;
|
|
141
159
|
},
|
|
142
|
-
writeBundle(_opts, bundle
|
|
160
|
+
writeBundle(_opts, bundle) {
|
|
143
161
|
const root = this.environment.config.root ?? process.cwd();
|
|
144
162
|
const entryMapByDestination = new Map(dedupeRoutes().map((e) => [entryDestination(root, e, ".func/index"), e]));
|
|
145
|
-
for (const [key, value] of Object.entries(bundle
|
|
163
|
+
for (const [key, value] of Object.entries(bundle)) if (value.type === "chunk" && entryMapByDestination.has(removeExtension$1(key))) outfiles.push({
|
|
146
164
|
type: "chunk",
|
|
147
165
|
root: this.environment.config.root,
|
|
148
166
|
outdir: this.environment.config.build.outDir,
|
|
@@ -159,7 +177,6 @@ function apiPlugin(pluginConfig) {
|
|
|
159
177
|
sharedDuringBuild: true
|
|
160
178
|
};
|
|
161
179
|
}
|
|
162
|
-
|
|
163
180
|
//#endregion
|
|
164
181
|
//#region src/utils/edge.ts
|
|
165
182
|
const edgeConditions = [
|
|
@@ -170,7 +187,6 @@ const edgeConditions = [
|
|
|
170
187
|
"import",
|
|
171
188
|
"default"
|
|
172
189
|
];
|
|
173
|
-
|
|
174
190
|
//#endregion
|
|
175
191
|
//#region src/utils/external.ts
|
|
176
192
|
const _external = [
|
|
@@ -181,7 +197,6 @@ const _external = [
|
|
|
181
197
|
"util"
|
|
182
198
|
];
|
|
183
199
|
const edgeExternal = [..._external, ..._external.map((e) => `node:${e}`)];
|
|
184
|
-
|
|
185
200
|
//#endregion
|
|
186
201
|
//#region src/plugins/bundle/basic.ts
|
|
187
202
|
const builtIns = new Set(builtinModules.flatMap((m) => [m, `node:${m}`]));
|
|
@@ -223,8 +238,8 @@ function basicBundlePlugin(pluginConfig) {
|
|
|
223
238
|
name: "vite-plugin-vercel:bundle",
|
|
224
239
|
enforce: "post",
|
|
225
240
|
apply: "build",
|
|
226
|
-
generateBundle(_opts, bundle
|
|
227
|
-
for (const b of Object.values(bundle
|
|
241
|
+
generateBundle(_opts, bundle) {
|
|
242
|
+
for (const b of Object.values(bundle)) {
|
|
228
243
|
const outFile = joinAbsolute(this.environment, this.environment.config.build.outDir, b.fileName);
|
|
229
244
|
if (b.type === "asset") {
|
|
230
245
|
const originalFileNames = b.originalFileNames.map((relativePath) => path.resolve(this.environment.config.root, relativePath));
|
|
@@ -268,8 +283,8 @@ async function bundle$1(pluginContext, bundledAssets, outfile) {
|
|
|
268
283
|
const buildOptions = {};
|
|
269
284
|
buildOptions.output = {
|
|
270
285
|
format: "esm",
|
|
271
|
-
|
|
272
|
-
|
|
286
|
+
comments: { legal: false },
|
|
287
|
+
codeSplitting: false
|
|
273
288
|
};
|
|
274
289
|
buildOptions.checks = { pluginTimings: false };
|
|
275
290
|
buildOptions.input = [source];
|
|
@@ -289,13 +304,6 @@ async function bundle$1(pluginContext, bundledAssets, outfile) {
|
|
|
289
304
|
} else {
|
|
290
305
|
buildOptions.platform = "node";
|
|
291
306
|
buildOptions.output.file = destination.replace(/\.js$/, ".mjs");
|
|
292
|
-
buildOptions.output.banner = `import { createRequire as topLevelCreateRequire } from 'node:module';
|
|
293
|
-
import { dirname as topLevelDirname } from 'node:path';
|
|
294
|
-
import { fileURLToPath as topLevelFileURLToPath } from 'node:url';
|
|
295
|
-
var require = topLevelCreateRequire(import.meta.url);
|
|
296
|
-
var __filename = topLevelFileURLToPath(import.meta.url);
|
|
297
|
-
var __dirname = topLevelDirname(__filename);
|
|
298
|
-
`;
|
|
299
307
|
}
|
|
300
308
|
try {
|
|
301
309
|
await build(buildOptions);
|
|
@@ -371,7 +379,6 @@ async function cleanup$1(filesToKeep, bundledChunks) {
|
|
|
371
379
|
await rmdir(dir);
|
|
372
380
|
} catch {}
|
|
373
381
|
}
|
|
374
|
-
|
|
375
382
|
//#endregion
|
|
376
383
|
//#region src/plugins/bundle/nf3.ts
|
|
377
384
|
function nf3BundlePlugin(pluginConfig) {
|
|
@@ -394,15 +401,15 @@ function nf3BundlePlugin(pluginConfig) {
|
|
|
394
401
|
async writeBundle(_, output) {
|
|
395
402
|
const isEdge = this.environment.name === envNames.edge;
|
|
396
403
|
const config = this.environment.config;
|
|
397
|
-
const outDir
|
|
404
|
+
const outDir = normalizePath(path.isAbsolute(config.build.outDir) ? config.build.outDir : path.join(config.root, config.build.outDir));
|
|
398
405
|
const entries = Object.entries(output).filter((e) => "isEntry" in e[1] && e[1].isEntry).map((e) => ({
|
|
399
406
|
name: e[1].name,
|
|
400
407
|
fileName: e[1].fileName,
|
|
401
|
-
outPath: path.join(outDir
|
|
408
|
+
outPath: path.join(outDir, e[1].fileName)
|
|
402
409
|
}));
|
|
403
410
|
if (entries.length === 0) return;
|
|
404
411
|
const outPaths = entries.map((entry) => entry.outPath);
|
|
405
|
-
const input = Object.fromEntries(outPaths.map((e) => [removeExtension(pathRelativeTo(e, outDir
|
|
412
|
+
const input = Object.fromEntries(outPaths.map((e) => [removeExtension(pathRelativeTo(e, outDir)), e]));
|
|
406
413
|
const limit = pLimit(Math.max(1, Math.ceil(cpus().length / 2)));
|
|
407
414
|
const nonVitePlugins = this.environment.config.plugins.filter((p) => {
|
|
408
415
|
return !p.name.startsWith("vite:") && p.name !== "alias" && p.name !== "commonjs" && p.name !== "nitro:externals";
|
|
@@ -411,12 +418,12 @@ function nf3BundlePlugin(pluginConfig) {
|
|
|
411
418
|
return rest;
|
|
412
419
|
});
|
|
413
420
|
const localOutput = (await Promise.all(Object.values(input).map((entryPath) => limit(async () => {
|
|
414
|
-
const outDir
|
|
421
|
+
const outDir = path.dirname(entryPath);
|
|
415
422
|
return { output: (await bundle({
|
|
416
423
|
plugins: nonVitePlugins,
|
|
417
424
|
isEdge,
|
|
418
425
|
input: { index: entryPath },
|
|
419
|
-
outDir
|
|
426
|
+
outDir,
|
|
420
427
|
externals: {
|
|
421
428
|
conditions: this.environment.config.resolve.conditions,
|
|
422
429
|
rootDir: this.environment.config.root,
|
|
@@ -429,7 +436,7 @@ function nf3BundlePlugin(pluginConfig) {
|
|
|
429
436
|
}
|
|
430
437
|
})).output.map((o) => ({
|
|
431
438
|
...o,
|
|
432
|
-
fileName: path.join(outDir
|
|
439
|
+
fileName: path.join(outDir, o.fileName)
|
|
433
440
|
})) };
|
|
434
441
|
})))).flatMap((r) => r.output);
|
|
435
442
|
buildOutput = buildOutput ? [...buildOutput, ...localOutput] : localOutput;
|
|
@@ -477,26 +484,22 @@ function pathRelativeTo(filePath, rel) {
|
|
|
477
484
|
function removeExtension(subject) {
|
|
478
485
|
return subject.replace(/\.[^/.]+$/, "");
|
|
479
486
|
}
|
|
480
|
-
|
|
481
487
|
//#endregion
|
|
482
488
|
//#region src/plugins/clean-outdir.ts
|
|
489
|
+
const outDir$1 = path.posix.join(process.cwd(), ".vercel/output");
|
|
483
490
|
function vercelCleanupPlugin(pluginConfig) {
|
|
484
491
|
let alreadyRun = false;
|
|
485
|
-
const envNames = getBuildEnvNames(pluginConfig);
|
|
486
492
|
return {
|
|
487
493
|
apply: "build",
|
|
488
494
|
name: "vite-plugin-vercel:cleanup",
|
|
489
495
|
enforce: "pre",
|
|
490
|
-
applyToEnvironment(env) {
|
|
491
|
-
return env.name === envNames.client;
|
|
492
|
-
},
|
|
493
496
|
buildStart: {
|
|
494
497
|
order: "pre",
|
|
495
498
|
sequential: true,
|
|
496
499
|
handler() {
|
|
497
500
|
if (alreadyRun) return;
|
|
498
501
|
alreadyRun = true;
|
|
499
|
-
cleanOutputDirectory(pluginConfig
|
|
502
|
+
cleanOutputDirectory(pluginConfig.outDir ?? outDir$1);
|
|
500
503
|
}
|
|
501
504
|
},
|
|
502
505
|
sharedDuringBuild: true
|
|
@@ -509,7 +512,6 @@ function cleanOutputDirectory(outdir) {
|
|
|
509
512
|
});
|
|
510
513
|
fs.mkdirSync(outdir, { recursive: true });
|
|
511
514
|
}
|
|
512
|
-
|
|
513
515
|
//#endregion
|
|
514
516
|
//#region src/build.ts
|
|
515
517
|
function getVcConfig(pluginConfig, filename, options) {
|
|
@@ -525,10 +527,29 @@ function getVcConfig(pluginConfig, filename, options) {
|
|
|
525
527
|
supportsResponseStreaming: options.streaming ?? pluginConfig.defaultSupportsResponseStreaming ?? true
|
|
526
528
|
});
|
|
527
529
|
}
|
|
528
|
-
|
|
530
|
+
//#endregion
|
|
531
|
+
//#region src/utils/request.ts
|
|
532
|
+
function getOriginalRequest(request) {
|
|
533
|
+
const xOriginalPath = request.headers.get("x-original-path");
|
|
534
|
+
let newUrl = null;
|
|
535
|
+
let newRequest = request;
|
|
536
|
+
if (typeof xOriginalPath === "string") newUrl = new URL(xOriginalPath, request.url).toString();
|
|
537
|
+
if (newUrl && request.url !== newUrl) newRequest = new Request(newUrl, {
|
|
538
|
+
method: request.method,
|
|
539
|
+
headers: request.headers,
|
|
540
|
+
body: request.body,
|
|
541
|
+
mode: request.mode,
|
|
542
|
+
credentials: request.credentials,
|
|
543
|
+
cache: request.cache,
|
|
544
|
+
redirect: request.redirect,
|
|
545
|
+
referrer: request.referrer,
|
|
546
|
+
integrity: request.integrity
|
|
547
|
+
});
|
|
548
|
+
return newRequest;
|
|
549
|
+
}
|
|
529
550
|
//#endregion
|
|
530
551
|
//#region src/plugins/loader.ts
|
|
531
|
-
const re_DUMMY =
|
|
552
|
+
const re_DUMMY = new RegExp(`__DUMMY__$`);
|
|
532
553
|
const re_edge = /[?&]vercel_edge\b/;
|
|
533
554
|
const re_node = /[?&]vercel_node\b/;
|
|
534
555
|
function loaderPlugin(pluginConfig) {
|
|
@@ -567,8 +588,14 @@ function loaderPlugin(pluginConfig) {
|
|
|
567
588
|
async handler(id) {
|
|
568
589
|
const mod = id.replace(re_edge, "");
|
|
569
590
|
return `import mod from ${JSON.stringify(mod)};
|
|
570
|
-
|
|
571
|
-
|
|
591
|
+
|
|
592
|
+
${getOriginalRequest.toString()}
|
|
593
|
+
|
|
594
|
+
const fn = (r) => {
|
|
595
|
+
return mod.fetch(getOriginalRequest(r));
|
|
596
|
+
};
|
|
597
|
+
|
|
598
|
+
export default fn`;
|
|
572
599
|
}
|
|
573
600
|
}
|
|
574
601
|
},
|
|
@@ -588,7 +615,18 @@ export default def;`;
|
|
|
588
615
|
async handler(id) {
|
|
589
616
|
const mod = id.replace(re_node, "");
|
|
590
617
|
return `import mod from ${JSON.stringify(mod)};
|
|
618
|
+
|
|
619
|
+
${getOriginalRequest.toString()}
|
|
620
|
+
|
|
621
|
+
if (mod?.fetch) {
|
|
622
|
+
const ori = mod.fetch;
|
|
623
|
+
mod.fetch = (r) => {
|
|
624
|
+
return ori(getOriginalRequest(r));
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
|
|
591
628
|
const def = mod?.server?.nodeHandler ?? mod;
|
|
629
|
+
|
|
592
630
|
export default def;`;
|
|
593
631
|
}
|
|
594
632
|
}
|
|
@@ -613,7 +651,10 @@ export default def;`;
|
|
|
613
651
|
const entries = dedupeRoutes().filter((e) => (e.vercel?.edge ?? false) === isEdge);
|
|
614
652
|
return { build: { rollupOptions: {
|
|
615
653
|
input: Object.fromEntries(entries.map((e) => [entryDestination(root ?? process.cwd(), e, ".func/index"), isEdge ? `${e.id}?vercel_edge` : `${e.id}?vercel_node`])),
|
|
616
|
-
output: {
|
|
654
|
+
output: {
|
|
655
|
+
hoistTransitiveImports: false,
|
|
656
|
+
entryFileNames: "[name].js"
|
|
657
|
+
}
|
|
617
658
|
} } };
|
|
618
659
|
}
|
|
619
660
|
}
|
|
@@ -638,7 +679,7 @@ export default def;`;
|
|
|
638
679
|
source: JSON.stringify(vercelOutputPrerenderConfigSchema.parse(entry.vercel.isr), void 0, 2)
|
|
639
680
|
});
|
|
640
681
|
pluginConfig.rewrites ??= [];
|
|
641
|
-
for (const ir of sortRoutes([entry.
|
|
682
|
+
for (const ir of sortRoutes([entry.route].flat().map((p) => fromRou3(p)))) {
|
|
642
683
|
const source = toPathToRegexpV6(ir);
|
|
643
684
|
pluginConfig.rewrites.push({
|
|
644
685
|
enforce: entry.vercel?.enforce,
|
|
@@ -662,7 +703,6 @@ export default def;`;
|
|
|
662
703
|
}
|
|
663
704
|
];
|
|
664
705
|
}
|
|
665
|
-
|
|
666
706
|
//#endregion
|
|
667
707
|
//#region src/plugins/react-edge.ts
|
|
668
708
|
function reactEdgePlugin(pluginConfig) {
|
|
@@ -681,7 +721,6 @@ function reactEdgePlugin(pluginConfig) {
|
|
|
681
721
|
}
|
|
682
722
|
};
|
|
683
723
|
}
|
|
684
|
-
|
|
685
724
|
//#endregion
|
|
686
725
|
//#region src/config.ts
|
|
687
726
|
function reorderEnforce(arr) {
|
|
@@ -701,7 +740,13 @@ function getConfig(pluginConfig) {
|
|
|
701
740
|
return r;
|
|
702
741
|
})),
|
|
703
742
|
redirects: pluginConfig.redirects ? reorderEnforce(pluginConfig.redirects) : void 0,
|
|
704
|
-
headers:
|
|
743
|
+
headers: [{
|
|
744
|
+
source: "/(.*)",
|
|
745
|
+
headers: [{
|
|
746
|
+
key: "x-original-path",
|
|
747
|
+
value: "/$1"
|
|
748
|
+
}]
|
|
749
|
+
}, ...pluginConfig.headers ?? []]
|
|
705
750
|
});
|
|
706
751
|
if (error) throw error;
|
|
707
752
|
if (pluginConfig.config?.routes && pluginConfig.config.routes.length > 0 && !pluginConfig.config.routes.every((r) => "continue" in r && r.continue)) console.warn("Did you forget to add `\"continue\": true` to your routes? See https://vercel.com/docs/build-output-api/v3/configuration#source-route\nIf not, it is discouraged to use `routes` config to override routes. Prefer using `rewrites` and `redirects`.");
|
|
@@ -732,11 +777,9 @@ function getConfig(pluginConfig) {
|
|
|
732
777
|
overrides: { ...pluginConfig.config?.overrides }
|
|
733
778
|
});
|
|
734
779
|
}
|
|
735
|
-
|
|
736
780
|
//#endregion
|
|
737
781
|
//#region src/utils/const.ts
|
|
738
782
|
const virtualEntry = "virtual:vite-plugin-vercel:entry";
|
|
739
|
-
|
|
740
783
|
//#endregion
|
|
741
784
|
//#region src/plugins/setupEnvs.ts
|
|
742
785
|
const outDir = path.posix.join(process.cwd(), ".vercel/output");
|
|
@@ -764,7 +807,9 @@ function setupEnvs(pluginConfig) {
|
|
|
764
807
|
handler() {
|
|
765
808
|
if (!injected) {
|
|
766
809
|
injected = true;
|
|
767
|
-
if (pluginConfig.entries)
|
|
810
|
+
if (pluginConfig.entries) pluginConfig.entries.forEach((entry) => {
|
|
811
|
+
addEntry(entry);
|
|
812
|
+
});
|
|
768
813
|
}
|
|
769
814
|
const outDirOverride = pluginConfig.outDir ? { build: { outDir: pluginConfig.outDir } } : {};
|
|
770
815
|
const environments = {};
|
|
@@ -772,7 +817,8 @@ function setupEnvs(pluginConfig) {
|
|
|
772
817
|
build: {
|
|
773
818
|
outDir: path.join(pluginConfig.outDir ?? outDir, "static"),
|
|
774
819
|
copyPublicDir: true,
|
|
775
|
-
rollupOptions: { input: getDummyInput() }
|
|
820
|
+
rollupOptions: { input: getDummyInput() },
|
|
821
|
+
emptyOutDir: false
|
|
776
822
|
},
|
|
777
823
|
consumer: "client"
|
|
778
824
|
};
|
|
@@ -802,8 +848,9 @@ function setupEnvs(pluginConfig) {
|
|
|
802
848
|
target: "es2022",
|
|
803
849
|
rollupOptions: {
|
|
804
850
|
input: {},
|
|
805
|
-
treeshake:
|
|
806
|
-
}
|
|
851
|
+
treeshake: true
|
|
852
|
+
},
|
|
853
|
+
rolldownOptions: {}
|
|
807
854
|
},
|
|
808
855
|
optimizeDeps: {
|
|
809
856
|
...config.optimizeDeps,
|
|
@@ -819,8 +866,8 @@ function setupEnvs(pluginConfig) {
|
|
|
819
866
|
},
|
|
820
867
|
generateBundle: {
|
|
821
868
|
order: "post",
|
|
822
|
-
async handler(_opts, bundle
|
|
823
|
-
cleanupDummy(bundle
|
|
869
|
+
async handler(_opts, bundle) {
|
|
870
|
+
cleanupDummy(bundle);
|
|
824
871
|
}
|
|
825
872
|
},
|
|
826
873
|
sharedDuringBuild: true
|
|
@@ -836,8 +883,8 @@ function setupEnvs(pluginConfig) {
|
|
|
836
883
|
},
|
|
837
884
|
generateBundle: {
|
|
838
885
|
order: "post",
|
|
839
|
-
async handler(_opts, bundle
|
|
840
|
-
cleanupDummy(bundle
|
|
886
|
+
async handler(_opts, bundle) {
|
|
887
|
+
cleanupDummy(bundle);
|
|
841
888
|
this.emitFile({
|
|
842
889
|
type: "asset",
|
|
843
890
|
fileName: "config.json",
|
|
@@ -852,8 +899,8 @@ function setupEnvs(pluginConfig) {
|
|
|
852
899
|
applyToEnvironment(env) {
|
|
853
900
|
return env.name === envNames.client;
|
|
854
901
|
},
|
|
855
|
-
generateBundle: { async handler(_opts, bundle
|
|
856
|
-
cleanupDummy(bundle
|
|
902
|
+
generateBundle: { async handler(_opts, bundle) {
|
|
903
|
+
cleanupDummy(bundle);
|
|
857
904
|
const topLevelConfig = this.environment.getTopLevelConfig();
|
|
858
905
|
const clientEnv = topLevelConfig.environments.client;
|
|
859
906
|
if (clientEnv) try {
|
|
@@ -901,11 +948,10 @@ function createVercelEnvironmentOptions(overrides) {
|
|
|
901
948
|
function getDummyInput() {
|
|
902
949
|
return { [DUMMY]: `${virtualEntry}:${DUMMY}` };
|
|
903
950
|
}
|
|
904
|
-
function cleanupDummy(bundle
|
|
905
|
-
const dummy = Object.keys(bundle
|
|
906
|
-
if (dummy) delete bundle
|
|
951
|
+
function cleanupDummy(bundle) {
|
|
952
|
+
const dummy = Object.keys(bundle).find((key) => key.includes("_DUMMY_"));
|
|
953
|
+
if (dummy) delete bundle[dummy];
|
|
907
954
|
}
|
|
908
|
-
|
|
909
955
|
//#endregion
|
|
910
956
|
//#region src/plugins/index.ts
|
|
911
957
|
function vercel(pluginConfig = {}) {
|
|
@@ -920,7 +966,5 @@ function vercel(pluginConfig = {}) {
|
|
|
920
966
|
devServer()
|
|
921
967
|
];
|
|
922
968
|
}
|
|
923
|
-
var plugins_default = vercel;
|
|
924
|
-
|
|
925
969
|
//#endregion
|
|
926
|
-
export {
|
|
970
|
+
export { vercel as default, vercel };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-vercel",
|
|
3
|
-
"version": "11.0.
|
|
3
|
+
"version": "11.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -24,31 +24,32 @@
|
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/node": "^22.19.3",
|
|
27
|
-
"@universal-middleware/express": "^0.4.
|
|
28
|
-
"@vercel/node": "^5.
|
|
29
|
-
"tsdown": "^0.
|
|
27
|
+
"@universal-middleware/express": "^0.4.26",
|
|
28
|
+
"@vercel/node": "^5.6.16",
|
|
29
|
+
"tsdown": "^0.21.4",
|
|
30
30
|
"typescript": "^5.9.3",
|
|
31
|
-
"vite": "^7.
|
|
32
|
-
"vitest": "^4.0
|
|
31
|
+
"vite": "^7.3.1",
|
|
32
|
+
"vitest": "^4.1.0"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@manypkg/find-root": "^3.1.0",
|
|
36
|
-
"@universal-deploy/store": "^0.0
|
|
37
|
-
"@universal-
|
|
38
|
-
"@universal-middleware/
|
|
39
|
-
"@vercel
|
|
40
|
-
"@vercel/
|
|
41
|
-
"@vercel/
|
|
42
|
-
"
|
|
36
|
+
"@universal-deploy/store": "^0.2.0",
|
|
37
|
+
"@universal-deploy/vite": "^0.1.0",
|
|
38
|
+
"@universal-middleware/core": "^0.4.17",
|
|
39
|
+
"@universal-middleware/vercel": "^0.4.31",
|
|
40
|
+
"@vercel/build-utils": "^13.8.1",
|
|
41
|
+
"@vercel/nft": "^1.3.2",
|
|
42
|
+
"@vercel/routing-utils": "^6.0.2",
|
|
43
|
+
"convert-route": "^1.1.1",
|
|
43
44
|
"fast-glob": "^3.3.3",
|
|
44
|
-
"magicast": "^0.5.
|
|
45
|
-
"nf3": "^0.3.
|
|
46
|
-
"oxc-transform": "^0.
|
|
47
|
-
"p-limit": "^7.
|
|
45
|
+
"magicast": "^0.5.2",
|
|
46
|
+
"nf3": "^0.3.11",
|
|
47
|
+
"oxc-transform": "^0.120.0",
|
|
48
|
+
"p-limit": "^7.3.0",
|
|
48
49
|
"path-to-regexp": "^8.3.0",
|
|
49
|
-
"rolldown": "^1.0.0-
|
|
50
|
-
"strip-ansi": "^7.
|
|
51
|
-
"vite-plugin-wasm": "^3.
|
|
50
|
+
"rolldown": "^1.0.0-rc.9",
|
|
51
|
+
"strip-ansi": "^7.2.0",
|
|
52
|
+
"vite-plugin-wasm": "^3.6.0",
|
|
52
53
|
"@vite-plugin-vercel/schemas": "^1.0.0"
|
|
53
54
|
},
|
|
54
55
|
"scripts": {
|