vite-plugin-vercel 11.0.0-beta.9 → 11.0.0
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.js +63 -1
- package/dist/assert-vtiLgQIb.js +8 -0
- package/dist/index.js +2 -2
- package/dist/vite.js +123 -59
- package/package.json +5 -4
- package/dist/api-DR2y7JVQ.js +0 -70
- /package/dist/{path-B4ThGm96.js → path-DoLvGKnz.js} +0 -0
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.
|
package/dist/api.js
CHANGED
|
@@ -1,3 +1,65 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as assert } from "./assert-vtiLgQIb.js";
|
|
2
2
|
|
|
3
|
+
//#region src/api.ts
|
|
4
|
+
function createAPI(outfiles, pluginConfig) {
|
|
5
|
+
return {
|
|
6
|
+
getOutFiles() {
|
|
7
|
+
return outfiles;
|
|
8
|
+
},
|
|
9
|
+
get config() {
|
|
10
|
+
pluginConfig.config ??= {};
|
|
11
|
+
return pluginConfig.config;
|
|
12
|
+
},
|
|
13
|
+
get defaultMaxDuration() {
|
|
14
|
+
return pluginConfig.defaultMaxDuration;
|
|
15
|
+
},
|
|
16
|
+
set defaultMaxDuration(value) {
|
|
17
|
+
pluginConfig.defaultMaxDuration = value;
|
|
18
|
+
},
|
|
19
|
+
get expiration() {
|
|
20
|
+
return pluginConfig.expiration;
|
|
21
|
+
},
|
|
22
|
+
set expiration(value) {
|
|
23
|
+
pluginConfig.expiration = value;
|
|
24
|
+
},
|
|
25
|
+
get rewrites() {
|
|
26
|
+
pluginConfig.rewrites ??= [];
|
|
27
|
+
return pluginConfig.rewrites;
|
|
28
|
+
},
|
|
29
|
+
get headers() {
|
|
30
|
+
pluginConfig.headers ??= [];
|
|
31
|
+
return pluginConfig.headers;
|
|
32
|
+
},
|
|
33
|
+
get redirects() {
|
|
34
|
+
pluginConfig.redirects ??= [];
|
|
35
|
+
return pluginConfig.redirects;
|
|
36
|
+
},
|
|
37
|
+
get cleanUrls() {
|
|
38
|
+
return pluginConfig.cleanUrls;
|
|
39
|
+
},
|
|
40
|
+
set cleanUrls(value) {
|
|
41
|
+
pluginConfig.cleanUrls = value;
|
|
42
|
+
},
|
|
43
|
+
get trailingSlash() {
|
|
44
|
+
return pluginConfig.trailingSlash;
|
|
45
|
+
},
|
|
46
|
+
set trailingSlash(value) {
|
|
47
|
+
pluginConfig.trailingSlash = value;
|
|
48
|
+
},
|
|
49
|
+
get defaultSupportsResponseStreaming() {
|
|
50
|
+
return pluginConfig.defaultSupportsResponseStreaming;
|
|
51
|
+
},
|
|
52
|
+
set defaultSupportsResponseStreaming(value) {
|
|
53
|
+
pluginConfig.defaultSupportsResponseStreaming = value;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function getVercelAPI(pluginContextOrServer) {
|
|
58
|
+
const vpv = ("environment" in pluginContextOrServer ? pluginContextOrServer.environment.config : pluginContextOrServer.config).plugins.find((p) => p.name === "vite-plugin-vercel:api");
|
|
59
|
+
assert(vpv, "Could not find vite-plugin-vercel:api plugin");
|
|
60
|
+
assert(vpv.api, "Missing `api`. Make sure vite-plugin-vercel is up-to-date");
|
|
61
|
+
return vpv.api("environment" in pluginContextOrServer ? pluginContextOrServer : void 0);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
//#endregion
|
|
3
65
|
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-DoLvGKnz.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";
|
|
@@ -31,7 +31,7 @@ async function getVercelEntries(dir, { destination = dir, tryParseExports = true
|
|
|
31
31
|
if (xports?.isr) entry.vercel.isr = xports.isr;
|
|
32
32
|
if (xports?.headers) entry.vercel.headers = xports.headers;
|
|
33
33
|
if (xports?.streaming) entry.vercel.streaming = xports.streaming;
|
|
34
|
-
entry.
|
|
34
|
+
entry.route = entryToRou3(key);
|
|
35
35
|
if (key.includes("[...")) entry.vercel.enforce = "post";
|
|
36
36
|
entryPoints.push(entry);
|
|
37
37
|
}
|
package/dist/vite.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { t as pathRelativeTo$1 } from "./path-
|
|
2
|
-
import {
|
|
1
|
+
import { t as pathRelativeTo$1 } from "./path-DoLvGKnz.js";
|
|
2
|
+
import { t as assert } from "./assert-vtiLgQIb.js";
|
|
3
|
+
import { createAPI, getVercelAPI } from "./api.js";
|
|
3
4
|
import { builtinModules } from "node:module";
|
|
4
5
|
import path from "node:path";
|
|
5
6
|
import { vercelOutputConfigSchema, vercelOutputPrerenderConfigSchema, vercelOutputVcConfigSchema } from "@vite-plugin-vercel/schemas";
|
|
6
7
|
import { fromRou3 } from "convert-route/rou3";
|
|
7
8
|
import { BuildEnvironment, createRunnableDevEnvironment, mergeConfig, normalizePath } from "vite";
|
|
8
|
-
import { catchAll, devServer } from "@universal-deploy/
|
|
9
|
-
import {
|
|
9
|
+
import { catchAll, devServer } from "@universal-deploy/vite";
|
|
10
|
+
import { addEntry, getAllEntries } from "@universal-deploy/store";
|
|
10
11
|
import fs, { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
11
12
|
import { copyFile, cp, rmdir, unlink } from "node:fs/promises";
|
|
12
13
|
import { findRoot } from "@manypkg/find-root";
|
|
@@ -37,17 +38,17 @@ function getBuildEnvNames(pluginConfig) {
|
|
|
37
38
|
*/
|
|
38
39
|
function dedupeRoutes() {
|
|
39
40
|
const entriesToKeep = [];
|
|
40
|
-
const entriesGroupedByModuleId = groupBy(
|
|
41
|
+
const entriesGroupedByModuleId = groupBy(getAllEntries(), (e) => e.id);
|
|
41
42
|
for (const entries of entriesGroupedByModuleId.values()) {
|
|
42
43
|
let groupedEntry;
|
|
43
44
|
for (const entry of entries) if (entry.vercel && Object.keys(entry.vercel).length > 0) {
|
|
44
|
-
if (!Array.isArray(entry.
|
|
45
|
+
if (!Array.isArray(entry.route)) entry.route = [entry.route];
|
|
45
46
|
entriesToKeep.push(entry);
|
|
46
47
|
} else if (!groupedEntry) {
|
|
47
48
|
groupedEntry = structuredClone(entry);
|
|
48
|
-
if (!Array.isArray(groupedEntry.
|
|
49
|
+
if (!Array.isArray(groupedEntry.route)) groupedEntry.route = [groupedEntry.route];
|
|
49
50
|
entriesToKeep.push(groupedEntry);
|
|
50
|
-
} else groupedEntry.
|
|
51
|
+
} else groupedEntry.route.push(...[entry.route].flat());
|
|
51
52
|
}
|
|
52
53
|
return entriesToKeep;
|
|
53
54
|
}
|
|
@@ -114,13 +115,36 @@ function removeExtension$1(subject) {
|
|
|
114
115
|
|
|
115
116
|
//#endregion
|
|
116
117
|
//#region src/utils/destination.ts
|
|
118
|
+
function parseViteId(id) {
|
|
119
|
+
const [path, query] = id.split("?");
|
|
120
|
+
return {
|
|
121
|
+
path: decodeURIComponent(path),
|
|
122
|
+
query
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function extractBestPath({ path, query }) {
|
|
126
|
+
if (!query) return path;
|
|
127
|
+
return query.split("&").map(decodeURIComponent).find((p) => p.includes("/")) || path;
|
|
128
|
+
}
|
|
129
|
+
function shortenPath(path, maxSegments = 2) {
|
|
130
|
+
return removeExtension$1(path.split(/[\\/]/).filter(Boolean).slice(-maxSegments).join("_"));
|
|
131
|
+
}
|
|
132
|
+
function mapPath(path, maxSegments = 2) {
|
|
133
|
+
const nodeModuleMatch = path.match(/node_modules[\\/](.+?)([\\/].*)?$/);
|
|
134
|
+
if (nodeModuleMatch) return `${nodeModuleMatch[1].split(/[\\/]/)[0]}_${removeExtension$1(nodeModuleMatch[2]?.split(/[\\/]/).pop() || "index")}`;
|
|
135
|
+
return shortenPath(path, maxSegments);
|
|
136
|
+
}
|
|
137
|
+
function hashString(str, length = 6) {
|
|
138
|
+
let hash = 5381;
|
|
139
|
+
for (let i = 0; i < str.length; i++) hash = hash * 33 ^ str.charCodeAt(i);
|
|
140
|
+
hash = hash >>> 0;
|
|
141
|
+
return hash.toString(36).slice(0, length);
|
|
142
|
+
}
|
|
143
|
+
function uniqueViteName(id, entry, maxSegments = 2) {
|
|
144
|
+
return removeExtension$1(`${mapPath(extractBestPath(parseViteId(id)), maxSegments)}_${hashString(JSON.stringify(entry))}`.replace(/[^a-zA-Z0-9\-_[\]/]/g, "-"));
|
|
145
|
+
}
|
|
117
146
|
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, "-")}`;
|
|
147
|
+
return uniqueViteName(pathRelativeTo$1(entry.id, root), entry);
|
|
124
148
|
}
|
|
125
149
|
function entryDestination(root, entry, postfix) {
|
|
126
150
|
return `${path.posix.join("functions/", entryDestinationDefault(root, entry))}${postfix}`;
|
|
@@ -139,10 +163,10 @@ function apiPlugin(pluginConfig) {
|
|
|
139
163
|
applyToEnvironment({ name }) {
|
|
140
164
|
return name === envNames.edge || name === envNames.node;
|
|
141
165
|
},
|
|
142
|
-
writeBundle(_opts, bundle
|
|
166
|
+
writeBundle(_opts, bundle) {
|
|
143
167
|
const root = this.environment.config.root ?? process.cwd();
|
|
144
168
|
const entryMapByDestination = new Map(dedupeRoutes().map((e) => [entryDestination(root, e, ".func/index"), e]));
|
|
145
|
-
for (const [key, value] of Object.entries(bundle
|
|
169
|
+
for (const [key, value] of Object.entries(bundle)) if (value.type === "chunk" && entryMapByDestination.has(removeExtension$1(key))) outfiles.push({
|
|
146
170
|
type: "chunk",
|
|
147
171
|
root: this.environment.config.root,
|
|
148
172
|
outdir: this.environment.config.build.outDir,
|
|
@@ -223,8 +247,8 @@ function basicBundlePlugin(pluginConfig) {
|
|
|
223
247
|
name: "vite-plugin-vercel:bundle",
|
|
224
248
|
enforce: "post",
|
|
225
249
|
apply: "build",
|
|
226
|
-
generateBundle(_opts, bundle
|
|
227
|
-
for (const b of Object.values(bundle
|
|
250
|
+
generateBundle(_opts, bundle) {
|
|
251
|
+
for (const b of Object.values(bundle)) {
|
|
228
252
|
const outFile = joinAbsolute(this.environment, this.environment.config.build.outDir, b.fileName);
|
|
229
253
|
if (b.type === "asset") {
|
|
230
254
|
const originalFileNames = b.originalFileNames.map((relativePath) => path.resolve(this.environment.config.root, relativePath));
|
|
@@ -268,8 +292,8 @@ async function bundle$1(pluginContext, bundledAssets, outfile) {
|
|
|
268
292
|
const buildOptions = {};
|
|
269
293
|
buildOptions.output = {
|
|
270
294
|
format: "esm",
|
|
271
|
-
|
|
272
|
-
|
|
295
|
+
comments: { legal: false },
|
|
296
|
+
codeSplitting: false
|
|
273
297
|
};
|
|
274
298
|
buildOptions.checks = { pluginTimings: false };
|
|
275
299
|
buildOptions.input = [source];
|
|
@@ -289,13 +313,6 @@ async function bundle$1(pluginContext, bundledAssets, outfile) {
|
|
|
289
313
|
} else {
|
|
290
314
|
buildOptions.platform = "node";
|
|
291
315
|
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
316
|
}
|
|
300
317
|
try {
|
|
301
318
|
await build(buildOptions);
|
|
@@ -394,15 +411,15 @@ function nf3BundlePlugin(pluginConfig) {
|
|
|
394
411
|
async writeBundle(_, output) {
|
|
395
412
|
const isEdge = this.environment.name === envNames.edge;
|
|
396
413
|
const config = this.environment.config;
|
|
397
|
-
const outDir
|
|
414
|
+
const outDir = normalizePath(path.isAbsolute(config.build.outDir) ? config.build.outDir : path.join(config.root, config.build.outDir));
|
|
398
415
|
const entries = Object.entries(output).filter((e) => "isEntry" in e[1] && e[1].isEntry).map((e) => ({
|
|
399
416
|
name: e[1].name,
|
|
400
417
|
fileName: e[1].fileName,
|
|
401
|
-
outPath: path.join(outDir
|
|
418
|
+
outPath: path.join(outDir, e[1].fileName)
|
|
402
419
|
}));
|
|
403
420
|
if (entries.length === 0) return;
|
|
404
421
|
const outPaths = entries.map((entry) => entry.outPath);
|
|
405
|
-
const input = Object.fromEntries(outPaths.map((e) => [removeExtension(pathRelativeTo(e, outDir
|
|
422
|
+
const input = Object.fromEntries(outPaths.map((e) => [removeExtension(pathRelativeTo(e, outDir)), e]));
|
|
406
423
|
const limit = pLimit(Math.max(1, Math.ceil(cpus().length / 2)));
|
|
407
424
|
const nonVitePlugins = this.environment.config.plugins.filter((p) => {
|
|
408
425
|
return !p.name.startsWith("vite:") && p.name !== "alias" && p.name !== "commonjs" && p.name !== "nitro:externals";
|
|
@@ -411,12 +428,12 @@ function nf3BundlePlugin(pluginConfig) {
|
|
|
411
428
|
return rest;
|
|
412
429
|
});
|
|
413
430
|
const localOutput = (await Promise.all(Object.values(input).map((entryPath) => limit(async () => {
|
|
414
|
-
const outDir
|
|
431
|
+
const outDir = path.dirname(entryPath);
|
|
415
432
|
return { output: (await bundle({
|
|
416
433
|
plugins: nonVitePlugins,
|
|
417
434
|
isEdge,
|
|
418
435
|
input: { index: entryPath },
|
|
419
|
-
outDir
|
|
436
|
+
outDir,
|
|
420
437
|
externals: {
|
|
421
438
|
conditions: this.environment.config.resolve.conditions,
|
|
422
439
|
rootDir: this.environment.config.root,
|
|
@@ -429,7 +446,7 @@ function nf3BundlePlugin(pluginConfig) {
|
|
|
429
446
|
}
|
|
430
447
|
})).output.map((o) => ({
|
|
431
448
|
...o,
|
|
432
|
-
fileName: path.join(outDir
|
|
449
|
+
fileName: path.join(outDir, o.fileName)
|
|
433
450
|
})) };
|
|
434
451
|
})))).flatMap((r) => r.output);
|
|
435
452
|
buildOutput = buildOutput ? [...buildOutput, ...localOutput] : localOutput;
|
|
@@ -480,23 +497,20 @@ function removeExtension(subject) {
|
|
|
480
497
|
|
|
481
498
|
//#endregion
|
|
482
499
|
//#region src/plugins/clean-outdir.ts
|
|
500
|
+
const outDir$1 = path.posix.join(process.cwd(), ".vercel/output");
|
|
483
501
|
function vercelCleanupPlugin(pluginConfig) {
|
|
484
502
|
let alreadyRun = false;
|
|
485
|
-
const envNames = getBuildEnvNames(pluginConfig);
|
|
486
503
|
return {
|
|
487
504
|
apply: "build",
|
|
488
505
|
name: "vite-plugin-vercel:cleanup",
|
|
489
506
|
enforce: "pre",
|
|
490
|
-
applyToEnvironment(env) {
|
|
491
|
-
return env.name === envNames.client;
|
|
492
|
-
},
|
|
493
507
|
buildStart: {
|
|
494
508
|
order: "pre",
|
|
495
509
|
sequential: true,
|
|
496
510
|
handler() {
|
|
497
511
|
if (alreadyRun) return;
|
|
498
512
|
alreadyRun = true;
|
|
499
|
-
cleanOutputDirectory(pluginConfig
|
|
513
|
+
cleanOutputDirectory(pluginConfig.outDir ?? outDir$1);
|
|
500
514
|
}
|
|
501
515
|
},
|
|
502
516
|
sharedDuringBuild: true
|
|
@@ -526,9 +540,30 @@ function getVcConfig(pluginConfig, filename, options) {
|
|
|
526
540
|
});
|
|
527
541
|
}
|
|
528
542
|
|
|
543
|
+
//#endregion
|
|
544
|
+
//#region src/utils/request.ts
|
|
545
|
+
function getOriginalRequest(request) {
|
|
546
|
+
const xOriginalPath = request.headers.get("x-original-path");
|
|
547
|
+
let newUrl = null;
|
|
548
|
+
let newRequest = request;
|
|
549
|
+
if (typeof xOriginalPath === "string") newUrl = new URL(xOriginalPath, request.url).toString();
|
|
550
|
+
if (newUrl && request.url !== newUrl) newRequest = new Request(newUrl, {
|
|
551
|
+
method: request.method,
|
|
552
|
+
headers: request.headers,
|
|
553
|
+
body: request.body,
|
|
554
|
+
mode: request.mode,
|
|
555
|
+
credentials: request.credentials,
|
|
556
|
+
cache: request.cache,
|
|
557
|
+
redirect: request.redirect,
|
|
558
|
+
referrer: request.referrer,
|
|
559
|
+
integrity: request.integrity
|
|
560
|
+
});
|
|
561
|
+
return newRequest;
|
|
562
|
+
}
|
|
563
|
+
|
|
529
564
|
//#endregion
|
|
530
565
|
//#region src/plugins/loader.ts
|
|
531
|
-
const re_DUMMY =
|
|
566
|
+
const re_DUMMY = new RegExp(`__DUMMY__$`);
|
|
532
567
|
const re_edge = /[?&]vercel_edge\b/;
|
|
533
568
|
const re_node = /[?&]vercel_node\b/;
|
|
534
569
|
function loaderPlugin(pluginConfig) {
|
|
@@ -567,8 +602,14 @@ function loaderPlugin(pluginConfig) {
|
|
|
567
602
|
async handler(id) {
|
|
568
603
|
const mod = id.replace(re_edge, "");
|
|
569
604
|
return `import mod from ${JSON.stringify(mod)};
|
|
570
|
-
|
|
571
|
-
|
|
605
|
+
|
|
606
|
+
${getOriginalRequest.toString()}
|
|
607
|
+
|
|
608
|
+
const fn = (r) => {
|
|
609
|
+
return mod.fetch(getOriginalRequest(r));
|
|
610
|
+
};
|
|
611
|
+
|
|
612
|
+
export default fn`;
|
|
572
613
|
}
|
|
573
614
|
}
|
|
574
615
|
},
|
|
@@ -588,7 +629,18 @@ export default def;`;
|
|
|
588
629
|
async handler(id) {
|
|
589
630
|
const mod = id.replace(re_node, "");
|
|
590
631
|
return `import mod from ${JSON.stringify(mod)};
|
|
632
|
+
|
|
633
|
+
${getOriginalRequest.toString()}
|
|
634
|
+
|
|
635
|
+
if (mod?.fetch) {
|
|
636
|
+
const ori = mod.fetch;
|
|
637
|
+
mod.fetch = (r) => {
|
|
638
|
+
return ori(getOriginalRequest(r));
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
|
|
591
642
|
const def = mod?.server?.nodeHandler ?? mod;
|
|
643
|
+
|
|
592
644
|
export default def;`;
|
|
593
645
|
}
|
|
594
646
|
}
|
|
@@ -613,7 +665,10 @@ export default def;`;
|
|
|
613
665
|
const entries = dedupeRoutes().filter((e) => (e.vercel?.edge ?? false) === isEdge);
|
|
614
666
|
return { build: { rollupOptions: {
|
|
615
667
|
input: Object.fromEntries(entries.map((e) => [entryDestination(root ?? process.cwd(), e, ".func/index"), isEdge ? `${e.id}?vercel_edge` : `${e.id}?vercel_node`])),
|
|
616
|
-
output: {
|
|
668
|
+
output: {
|
|
669
|
+
hoistTransitiveImports: false,
|
|
670
|
+
entryFileNames: "[name].js"
|
|
671
|
+
}
|
|
617
672
|
} } };
|
|
618
673
|
}
|
|
619
674
|
}
|
|
@@ -638,7 +693,7 @@ export default def;`;
|
|
|
638
693
|
source: JSON.stringify(vercelOutputPrerenderConfigSchema.parse(entry.vercel.isr), void 0, 2)
|
|
639
694
|
});
|
|
640
695
|
pluginConfig.rewrites ??= [];
|
|
641
|
-
for (const ir of sortRoutes([entry.
|
|
696
|
+
for (const ir of sortRoutes([entry.route].flat().map((p) => fromRou3(p)))) {
|
|
642
697
|
const source = toPathToRegexpV6(ir);
|
|
643
698
|
pluginConfig.rewrites.push({
|
|
644
699
|
enforce: entry.vercel?.enforce,
|
|
@@ -701,7 +756,13 @@ function getConfig(pluginConfig) {
|
|
|
701
756
|
return r;
|
|
702
757
|
})),
|
|
703
758
|
redirects: pluginConfig.redirects ? reorderEnforce(pluginConfig.redirects) : void 0,
|
|
704
|
-
headers:
|
|
759
|
+
headers: [{
|
|
760
|
+
source: "/(.*)",
|
|
761
|
+
headers: [{
|
|
762
|
+
key: "x-original-path",
|
|
763
|
+
value: "/$1"
|
|
764
|
+
}]
|
|
765
|
+
}, ...pluginConfig.headers ?? []]
|
|
705
766
|
});
|
|
706
767
|
if (error) throw error;
|
|
707
768
|
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`.");
|
|
@@ -764,7 +825,9 @@ function setupEnvs(pluginConfig) {
|
|
|
764
825
|
handler() {
|
|
765
826
|
if (!injected) {
|
|
766
827
|
injected = true;
|
|
767
|
-
if (pluginConfig.entries)
|
|
828
|
+
if (pluginConfig.entries) pluginConfig.entries.forEach((entry) => {
|
|
829
|
+
addEntry(entry);
|
|
830
|
+
});
|
|
768
831
|
}
|
|
769
832
|
const outDirOverride = pluginConfig.outDir ? { build: { outDir: pluginConfig.outDir } } : {};
|
|
770
833
|
const environments = {};
|
|
@@ -772,7 +835,8 @@ function setupEnvs(pluginConfig) {
|
|
|
772
835
|
build: {
|
|
773
836
|
outDir: path.join(pluginConfig.outDir ?? outDir, "static"),
|
|
774
837
|
copyPublicDir: true,
|
|
775
|
-
rollupOptions: { input: getDummyInput() }
|
|
838
|
+
rollupOptions: { input: getDummyInput() },
|
|
839
|
+
emptyOutDir: false
|
|
776
840
|
},
|
|
777
841
|
consumer: "client"
|
|
778
842
|
};
|
|
@@ -802,8 +866,9 @@ function setupEnvs(pluginConfig) {
|
|
|
802
866
|
target: "es2022",
|
|
803
867
|
rollupOptions: {
|
|
804
868
|
input: {},
|
|
805
|
-
treeshake:
|
|
806
|
-
}
|
|
869
|
+
treeshake: true
|
|
870
|
+
},
|
|
871
|
+
rolldownOptions: {}
|
|
807
872
|
},
|
|
808
873
|
optimizeDeps: {
|
|
809
874
|
...config.optimizeDeps,
|
|
@@ -819,8 +884,8 @@ function setupEnvs(pluginConfig) {
|
|
|
819
884
|
},
|
|
820
885
|
generateBundle: {
|
|
821
886
|
order: "post",
|
|
822
|
-
async handler(_opts, bundle
|
|
823
|
-
cleanupDummy(bundle
|
|
887
|
+
async handler(_opts, bundle) {
|
|
888
|
+
cleanupDummy(bundle);
|
|
824
889
|
}
|
|
825
890
|
},
|
|
826
891
|
sharedDuringBuild: true
|
|
@@ -836,8 +901,8 @@ function setupEnvs(pluginConfig) {
|
|
|
836
901
|
},
|
|
837
902
|
generateBundle: {
|
|
838
903
|
order: "post",
|
|
839
|
-
async handler(_opts, bundle
|
|
840
|
-
cleanupDummy(bundle
|
|
904
|
+
async handler(_opts, bundle) {
|
|
905
|
+
cleanupDummy(bundle);
|
|
841
906
|
this.emitFile({
|
|
842
907
|
type: "asset",
|
|
843
908
|
fileName: "config.json",
|
|
@@ -852,8 +917,8 @@ function setupEnvs(pluginConfig) {
|
|
|
852
917
|
applyToEnvironment(env) {
|
|
853
918
|
return env.name === envNames.client;
|
|
854
919
|
},
|
|
855
|
-
generateBundle: { async handler(_opts, bundle
|
|
856
|
-
cleanupDummy(bundle
|
|
920
|
+
generateBundle: { async handler(_opts, bundle) {
|
|
921
|
+
cleanupDummy(bundle);
|
|
857
922
|
const topLevelConfig = this.environment.getTopLevelConfig();
|
|
858
923
|
const clientEnv = topLevelConfig.environments.client;
|
|
859
924
|
if (clientEnv) try {
|
|
@@ -901,9 +966,9 @@ function createVercelEnvironmentOptions(overrides) {
|
|
|
901
966
|
function getDummyInput() {
|
|
902
967
|
return { [DUMMY]: `${virtualEntry}:${DUMMY}` };
|
|
903
968
|
}
|
|
904
|
-
function cleanupDummy(bundle
|
|
905
|
-
const dummy = Object.keys(bundle
|
|
906
|
-
if (dummy) delete bundle
|
|
969
|
+
function cleanupDummy(bundle) {
|
|
970
|
+
const dummy = Object.keys(bundle).find((key) => key.includes("_DUMMY_"));
|
|
971
|
+
if (dummy) delete bundle[dummy];
|
|
907
972
|
}
|
|
908
973
|
|
|
909
974
|
//#endregion
|
|
@@ -920,7 +985,6 @@ function vercel(pluginConfig = {}) {
|
|
|
920
985
|
devServer()
|
|
921
986
|
];
|
|
922
987
|
}
|
|
923
|
-
var plugins_default = vercel;
|
|
924
988
|
|
|
925
989
|
//#endregion
|
|
926
|
-
export {
|
|
990
|
+
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.0
|
|
3
|
+
"version": "11.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -26,14 +26,15 @@
|
|
|
26
26
|
"@types/node": "^22.19.3",
|
|
27
27
|
"@universal-middleware/express": "^0.4.22",
|
|
28
28
|
"@vercel/node": "^5.5.15",
|
|
29
|
-
"tsdown": "^0.
|
|
29
|
+
"tsdown": "^0.20.3",
|
|
30
30
|
"typescript": "^5.9.3",
|
|
31
31
|
"vite": "^7.2.4",
|
|
32
32
|
"vitest": "^4.0.16"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@manypkg/find-root": "^3.1.0",
|
|
36
|
-
"@universal-deploy/store": "^0.0
|
|
36
|
+
"@universal-deploy/store": "^0.2.0",
|
|
37
|
+
"@universal-deploy/vite": "^0.1.0",
|
|
37
38
|
"@universal-middleware/core": "^0.4.13",
|
|
38
39
|
"@universal-middleware/vercel": "^0.4.29",
|
|
39
40
|
"@vercel/build-utils": "^13.2.3",
|
|
@@ -46,7 +47,7 @@
|
|
|
46
47
|
"oxc-transform": "^0.108.0",
|
|
47
48
|
"p-limit": "^7.2.0",
|
|
48
49
|
"path-to-regexp": "^8.3.0",
|
|
49
|
-
"rolldown": "^1.0.0-
|
|
50
|
+
"rolldown": "^1.0.0-rc.4",
|
|
50
51
|
"strip-ansi": "^7.1.2",
|
|
51
52
|
"vite-plugin-wasm": "^3.5.0",
|
|
52
53
|
"@vite-plugin-vercel/schemas": "^1.0.0"
|
package/dist/api-DR2y7JVQ.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
//#region src/utils/assert.ts
|
|
2
|
-
function assert(condition, errorMessage) {
|
|
3
|
-
if (condition) return;
|
|
4
|
-
throw new Error(`[vite-plugin-vercel] ${errorMessage}`);
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
//#endregion
|
|
8
|
-
//#region src/api.ts
|
|
9
|
-
function createAPI(outfiles, pluginConfig) {
|
|
10
|
-
return {
|
|
11
|
-
getOutFiles() {
|
|
12
|
-
return outfiles;
|
|
13
|
-
},
|
|
14
|
-
get config() {
|
|
15
|
-
pluginConfig.config ??= {};
|
|
16
|
-
return pluginConfig.config;
|
|
17
|
-
},
|
|
18
|
-
get defaultMaxDuration() {
|
|
19
|
-
return pluginConfig.defaultMaxDuration;
|
|
20
|
-
},
|
|
21
|
-
set defaultMaxDuration(value) {
|
|
22
|
-
pluginConfig.defaultMaxDuration = value;
|
|
23
|
-
},
|
|
24
|
-
get expiration() {
|
|
25
|
-
return pluginConfig.expiration;
|
|
26
|
-
},
|
|
27
|
-
set expiration(value) {
|
|
28
|
-
pluginConfig.expiration = value;
|
|
29
|
-
},
|
|
30
|
-
get rewrites() {
|
|
31
|
-
pluginConfig.rewrites ??= [];
|
|
32
|
-
return pluginConfig.rewrites;
|
|
33
|
-
},
|
|
34
|
-
get headers() {
|
|
35
|
-
pluginConfig.headers ??= [];
|
|
36
|
-
return pluginConfig.headers;
|
|
37
|
-
},
|
|
38
|
-
get redirects() {
|
|
39
|
-
pluginConfig.redirects ??= [];
|
|
40
|
-
return pluginConfig.redirects;
|
|
41
|
-
},
|
|
42
|
-
get cleanUrls() {
|
|
43
|
-
return pluginConfig.cleanUrls;
|
|
44
|
-
},
|
|
45
|
-
set cleanUrls(value) {
|
|
46
|
-
pluginConfig.cleanUrls = value;
|
|
47
|
-
},
|
|
48
|
-
get trailingSlash() {
|
|
49
|
-
return pluginConfig.trailingSlash;
|
|
50
|
-
},
|
|
51
|
-
set trailingSlash(value) {
|
|
52
|
-
pluginConfig.trailingSlash = value;
|
|
53
|
-
},
|
|
54
|
-
get defaultSupportsResponseStreaming() {
|
|
55
|
-
return pluginConfig.defaultSupportsResponseStreaming;
|
|
56
|
-
},
|
|
57
|
-
set defaultSupportsResponseStreaming(value) {
|
|
58
|
-
pluginConfig.defaultSupportsResponseStreaming = value;
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
function getVercelAPI(pluginContextOrServer) {
|
|
63
|
-
const vpv = ("environment" in pluginContextOrServer ? pluginContextOrServer.environment.config : pluginContextOrServer.config).plugins.find((p) => p.name === "vite-plugin-vercel:api");
|
|
64
|
-
assert(vpv, "Could not find vite-plugin-vercel:api plugin");
|
|
65
|
-
assert(vpv.api, "Missing `api`. Make sure vite-plugin-vercel is up-to-date");
|
|
66
|
-
return vpv.api("environment" in pluginContextOrServer ? pluginContextOrServer : void 0);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
//#endregion
|
|
70
|
-
export { getVercelAPI as n, assert as r, createAPI as t };
|
|
File without changes
|