vite-plugin-vercel 0.0.3 → 0.0.6
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/index.cjs +424 -0
- package/dist/index.d.ts +502 -478
- package/dist/index.js +270 -283
- package/package.json +19 -18
- package/dist/index.mjs +0 -386
package/dist/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var
|
|
4
|
-
var
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
7
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -18,280 +16,226 @@ var __spreadValues = (a, b) => {
|
|
|
18
16
|
}
|
|
19
17
|
return a;
|
|
20
18
|
};
|
|
21
|
-
var
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (
|
|
28
|
-
for (
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
32
30
|
return target;
|
|
33
31
|
};
|
|
34
|
-
var __toESM = (module2, isNodeMode) => {
|
|
35
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
36
|
-
};
|
|
37
|
-
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
38
|
-
return (module2, temp) => {
|
|
39
|
-
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
40
|
-
};
|
|
41
|
-
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
42
32
|
|
|
43
33
|
// src/index.ts
|
|
44
|
-
|
|
45
|
-
__export(src_exports, {
|
|
46
|
-
default: () => allPlugins
|
|
47
|
-
});
|
|
48
|
-
var import_promises3 = __toESM(require("fs/promises"));
|
|
34
|
+
import fs5 from "fs/promises";
|
|
49
35
|
|
|
50
36
|
// src/utils.ts
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
37
|
+
import { normalizePath } from "vite";
|
|
38
|
+
import path from "path";
|
|
39
|
+
import fs from "fs/promises";
|
|
54
40
|
function getRoot(config) {
|
|
55
|
-
return
|
|
41
|
+
return normalizePath(config.root || process.cwd());
|
|
56
42
|
}
|
|
57
43
|
function getOutDir(config, force) {
|
|
58
|
-
const p =
|
|
44
|
+
const p = normalizePath(config.build.outDir);
|
|
59
45
|
if (!force)
|
|
60
46
|
return p;
|
|
61
|
-
return
|
|
47
|
+
return path.join(path.dirname(p), force);
|
|
62
48
|
}
|
|
63
49
|
function getOutput(config, suffix) {
|
|
64
50
|
var _a, _b;
|
|
65
|
-
return
|
|
51
|
+
return path.join(((_a = config.vercel) == null ? void 0 : _a.outDir) ? "" : getRoot(config), ((_b = config.vercel) == null ? void 0 : _b.outDir) ?? ".vercel/output", suffix ?? "");
|
|
66
52
|
}
|
|
67
53
|
function pathRelativeToApi(filePath, config) {
|
|
68
54
|
const root = getRoot(config);
|
|
69
|
-
return
|
|
55
|
+
return normalizePath(path.relative(path.join(root, "api"), filePath));
|
|
70
56
|
}
|
|
71
57
|
async function copyDir(src, dest) {
|
|
72
|
-
await
|
|
73
|
-
const entries = await
|
|
58
|
+
await fs.mkdir(dest, { recursive: true });
|
|
59
|
+
const entries = await fs.readdir(src, { withFileTypes: true });
|
|
74
60
|
for (const entry of entries) {
|
|
75
|
-
const srcPath =
|
|
76
|
-
const destPath =
|
|
77
|
-
entry.isDirectory() ? await copyDir(srcPath, destPath) : await
|
|
61
|
+
const srcPath = path.join(src, entry.name);
|
|
62
|
+
const destPath = path.join(dest, entry.name);
|
|
63
|
+
entry.isDirectory() ? await copyDir(srcPath, destPath) : await fs.copyFile(srcPath, destPath);
|
|
78
64
|
}
|
|
79
65
|
}
|
|
80
66
|
|
|
81
|
-
// src/
|
|
82
|
-
|
|
67
|
+
// src/config.ts
|
|
68
|
+
import path2 from "path";
|
|
69
|
+
|
|
70
|
+
// src/schemas/config/config.ts
|
|
71
|
+
import { z } from "zod";
|
|
72
|
+
var HasOrMissing = z.array(z.union([
|
|
73
|
+
z.object({
|
|
74
|
+
type: z.literal("host"),
|
|
75
|
+
value: z.string()
|
|
76
|
+
}).strict(),
|
|
77
|
+
z.object({
|
|
78
|
+
type: z.literal("header"),
|
|
79
|
+
key: z.string(),
|
|
80
|
+
value: z.string().optional()
|
|
81
|
+
}).strict(),
|
|
82
|
+
z.object({
|
|
83
|
+
type: z.literal("cookie"),
|
|
84
|
+
key: z.string(),
|
|
85
|
+
value: z.string().optional()
|
|
86
|
+
}).strict(),
|
|
87
|
+
z.object({
|
|
88
|
+
type: z.literal("query"),
|
|
89
|
+
key: z.string(),
|
|
90
|
+
value: z.string().optional()
|
|
91
|
+
}).strict()
|
|
92
|
+
])).optional();
|
|
93
|
+
var vercelOutputConfigSchema = z.object({
|
|
94
|
+
version: z.literal(3),
|
|
95
|
+
routes: z.array(z.union([
|
|
96
|
+
z.object({
|
|
97
|
+
src: z.string(),
|
|
98
|
+
dest: z.string().optional(),
|
|
99
|
+
headers: z.record(z.string()).optional(),
|
|
100
|
+
methods: z.array(z.string()).optional(),
|
|
101
|
+
status: z.number().int().positive().optional(),
|
|
102
|
+
continue: z.boolean().optional(),
|
|
103
|
+
check: z.boolean().optional(),
|
|
104
|
+
missing: HasOrMissing,
|
|
105
|
+
has: HasOrMissing,
|
|
106
|
+
locale: z.object({
|
|
107
|
+
redirect: z.record(z.string()).optional(),
|
|
108
|
+
cookie: z.string().optional()
|
|
109
|
+
}).strict().optional(),
|
|
110
|
+
middlewarePath: z.string().optional()
|
|
111
|
+
}).strict(),
|
|
112
|
+
z.object({
|
|
113
|
+
handle: z.union([
|
|
114
|
+
z.literal("rewrite"),
|
|
115
|
+
z.literal("filesystem"),
|
|
116
|
+
z.literal("resource"),
|
|
117
|
+
z.literal("miss"),
|
|
118
|
+
z.literal("hit"),
|
|
119
|
+
z.literal("error")
|
|
120
|
+
]),
|
|
121
|
+
src: z.string().optional(),
|
|
122
|
+
dest: z.string().optional(),
|
|
123
|
+
status: z.number().optional()
|
|
124
|
+
}).strict()
|
|
125
|
+
])).optional(),
|
|
126
|
+
images: z.object({
|
|
127
|
+
sizes: z.tuple([
|
|
128
|
+
z.number().int().positive(),
|
|
129
|
+
z.number().int().positive()
|
|
130
|
+
]),
|
|
131
|
+
domains: z.array(z.string()).nonempty().optional(),
|
|
132
|
+
minimumCacheTTL: z.number().int().positive().optional(),
|
|
133
|
+
formats: z.union([z.literal("image/avif"), z.literal("image/webp")]).array().nonempty().optional(),
|
|
134
|
+
dangerouslyAllowSVG: z.boolean().optional(),
|
|
135
|
+
contentSecurityPolicy: z.string().optional()
|
|
136
|
+
}).strict().optional(),
|
|
137
|
+
wildcard: z.array(z.object({
|
|
138
|
+
domain: z.string(),
|
|
139
|
+
value: z.string()
|
|
140
|
+
}).strict()).optional(),
|
|
141
|
+
overrides: z.record(z.object({
|
|
142
|
+
path: z.string().optional(),
|
|
143
|
+
contentType: z.string().optional()
|
|
144
|
+
}).strict()).optional(),
|
|
145
|
+
cache: z.array(z.string()).optional()
|
|
146
|
+
}).strict();
|
|
147
|
+
|
|
148
|
+
// src/config.ts
|
|
149
|
+
import fs2 from "fs/promises";
|
|
150
|
+
import { getTransformedRoutes } from "@vercel/routing-utils";
|
|
151
|
+
function getConfig(resolvedConfig, config) {
|
|
152
|
+
var _a, _b, _c, _d, _e;
|
|
153
|
+
const { routes } = getTransformedRoutes({
|
|
154
|
+
nowConfig: {
|
|
155
|
+
cleanUrls: true
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
return vercelOutputConfigSchema.parse(__spreadProps(__spreadValues({
|
|
159
|
+
version: 3
|
|
160
|
+
}, (_a = resolvedConfig.vercel) == null ? void 0 : _a.config), {
|
|
161
|
+
routes: [
|
|
162
|
+
...routes ?? [],
|
|
163
|
+
...(config == null ? void 0 : config.routes) ?? [],
|
|
164
|
+
...((_c = (_b = resolvedConfig.vercel) == null ? void 0 : _b.config) == null ? void 0 : _c.routes) ?? []
|
|
165
|
+
],
|
|
166
|
+
overrides: __spreadValues(__spreadValues({}, (_e = (_d = resolvedConfig.vercel) == null ? void 0 : _d.config) == null ? void 0 : _e.overrides), config == null ? void 0 : config.overrides)
|
|
167
|
+
}));
|
|
168
|
+
}
|
|
169
|
+
function getConfigDestination(resolvedConfig) {
|
|
170
|
+
return path2.join(getOutput(resolvedConfig), "config.json");
|
|
171
|
+
}
|
|
172
|
+
async function writeConfig(resolvedConfig, config) {
|
|
173
|
+
await fs2.writeFile(getConfigDestination(resolvedConfig), JSON.stringify(getConfig(resolvedConfig, config), void 0, 2), "utf-8");
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// src/build.ts
|
|
177
|
+
import glob from "fast-glob";
|
|
178
|
+
import path3 from "path";
|
|
179
|
+
import { build } from "esbuild";
|
|
83
180
|
|
|
84
181
|
// src/assert.ts
|
|
85
|
-
|
|
182
|
+
import { newError } from "@brillout/libassert";
|
|
86
183
|
var libName = "vite-plugin-vercel";
|
|
87
184
|
function assert(condition, errorMessage) {
|
|
88
185
|
if (condition) {
|
|
89
186
|
return;
|
|
90
187
|
}
|
|
91
|
-
const err =
|
|
188
|
+
const err = newError(`[${libName}][Wrong Usage] ${errorMessage}`, 2);
|
|
92
189
|
throw err;
|
|
93
190
|
}
|
|
94
191
|
|
|
95
|
-
// src/schemas/
|
|
96
|
-
|
|
97
|
-
var
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
regex: import_zod.z.string()
|
|
192
|
+
// src/schemas/config/vc-config.ts
|
|
193
|
+
import { z as z2 } from "zod";
|
|
194
|
+
var vercelOutputEdgeVcConfigSchema = z2.object({
|
|
195
|
+
runtime: z2.literal("edge"),
|
|
196
|
+
entrypoint: z2.string(),
|
|
197
|
+
envVarsInUse: z2.array(z2.string()).optional()
|
|
102
198
|
}).strict();
|
|
103
|
-
var
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
199
|
+
var vercelOutputServerlessVcConfigSchema = z2.object({
|
|
200
|
+
runtime: z2.string(),
|
|
201
|
+
handler: z2.string(),
|
|
202
|
+
memory: z2.number().int().min(128).max(3008).optional(),
|
|
203
|
+
maxDuration: z2.number().int().positive().optional(),
|
|
204
|
+
environment: z2.record(z2.string()).optional(),
|
|
205
|
+
regions: z2.array(z2.string()).optional()
|
|
110
206
|
}).strict();
|
|
111
|
-
var
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
type: import_zod.z.enum(["header", "cookie", "host", "query"])
|
|
117
|
-
}).strict()).optional(),
|
|
118
|
-
destination: import_zod.z.string(),
|
|
119
|
-
regex: import_zod.z.string()
|
|
120
|
-
}).strict();
|
|
121
|
-
var routesManifestDynamicRouteSchema = import_zod.z.object({
|
|
122
|
-
page: import_zod.z.string(),
|
|
123
|
-
regex: import_zod.z.string(),
|
|
124
|
-
routeKeys: import_zod.z.record(import_zod.z.string()).optional(),
|
|
125
|
-
namedRegex: import_zod.z.string().optional()
|
|
126
|
-
}).strict();
|
|
127
|
-
var routesManifestSchema = import_zod.z.object({
|
|
128
|
-
version: import_zod.z.literal(3),
|
|
129
|
-
basePath: import_zod.z.string().regex(/^\/.*/),
|
|
130
|
-
pages404: import_zod.z.boolean(),
|
|
131
|
-
redirects: import_zod.z.array(routesManifestRedirectSchema).optional(),
|
|
132
|
-
headers: import_zod.z.array(routesManifestHeaderSchema).optional(),
|
|
133
|
-
rewrites: import_zod.z.array(routesManifestRewriteSchema).optional(),
|
|
134
|
-
dynamicRoutes: import_zod.z.array(routesManifestDynamicRouteSchema).optional()
|
|
135
|
-
}).strict();
|
|
136
|
-
|
|
137
|
-
// src/schemas/manifests/functions.ts
|
|
138
|
-
var import_zod2 = require("zod");
|
|
139
|
-
var functionsManifestSchemaPage = import_zod2.z.object({
|
|
140
|
-
runtime: import_zod2.z.string().optional(),
|
|
141
|
-
handler: import_zod2.z.string().optional(),
|
|
142
|
-
regions: import_zod2.z.array(import_zod2.z.string()).optional(),
|
|
143
|
-
maxDuration: import_zod2.z.number().min(1).max(900).optional(),
|
|
144
|
-
memory: import_zod2.z.number().min(128).max(3008).optional()
|
|
145
|
-
}).strict();
|
|
146
|
-
var functionsManifestSchemaPageWeb = functionsManifestSchemaPage.omit({
|
|
147
|
-
runtime: true
|
|
148
|
-
}).merge(import_zod2.z.object({
|
|
149
|
-
runtime: import_zod2.z.literal("web"),
|
|
150
|
-
env: import_zod2.z.array(import_zod2.z.string()),
|
|
151
|
-
files: import_zod2.z.array(import_zod2.z.string()),
|
|
152
|
-
name: import_zod2.z.string(),
|
|
153
|
-
page: import_zod2.z.string(),
|
|
154
|
-
regexp: import_zod2.z.string(),
|
|
155
|
-
sortingIndex: import_zod2.z.number()
|
|
156
|
-
}).strict());
|
|
157
|
-
var functionsManifestSchema = import_zod2.z.object({
|
|
158
|
-
version: import_zod2.z.literal(1),
|
|
159
|
-
pages: import_zod2.z.object({
|
|
160
|
-
"_middleware.js": functionsManifestSchemaPageWeb.optional()
|
|
161
|
-
}).and(import_zod2.z.record(import_zod2.z.intersection(functionsManifestSchemaPageWeb.omit({
|
|
162
|
-
runtime: true
|
|
163
|
-
}).partial(), functionsManifestSchemaPage)))
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
// src/schemas/manifests/prerender.ts
|
|
167
|
-
var import_zod3 = require("zod");
|
|
168
|
-
var prerenderManifestSchemaRoute = import_zod3.z.object({
|
|
169
|
-
initialRevalidateSeconds: import_zod3.z.number(),
|
|
170
|
-
srcRoute: import_zod3.z.string(),
|
|
171
|
-
dataRoute: import_zod3.z.string()
|
|
172
|
-
}).strict();
|
|
173
|
-
var prerenderManifestSchemaDynamicRoute = import_zod3.z.object({
|
|
174
|
-
routeRegex: import_zod3.z.string(),
|
|
175
|
-
fallback: import_zod3.z.string().or(import_zod3.z.null()),
|
|
176
|
-
dataRoute: import_zod3.z.string(),
|
|
177
|
-
dataRouteRegex: import_zod3.z.string()
|
|
178
|
-
}).strict();
|
|
179
|
-
var prerenderManifestSchema = import_zod3.z.object({
|
|
180
|
-
version: import_zod3.z.literal(3),
|
|
181
|
-
routes: import_zod3.z.record(prerenderManifestSchemaRoute),
|
|
182
|
-
dynamicRoutes: import_zod3.z.record(prerenderManifestSchemaDynamicRoute),
|
|
183
|
-
preview: import_zod3.z.object({
|
|
184
|
-
previewModeId: import_zod3.z.string().or(import_zod3.z.null())
|
|
185
|
-
}).strict()
|
|
207
|
+
var vercelOutputServerlessNodeVcConfigSchema = vercelOutputServerlessVcConfigSchema.extend({
|
|
208
|
+
launcherType: z2.literal("Nodejs"),
|
|
209
|
+
shouldAddHelpers: z2.boolean().optional(),
|
|
210
|
+
shouldAddSourcemapSupport: z2.boolean().optional(),
|
|
211
|
+
awsLambdaHandler: z2.string().optional()
|
|
186
212
|
}).strict();
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
const routes = Object.entries((isrPages == null ? void 0 : isrPages.routes) ?? {}).reduce((acc, [key, val]) => {
|
|
193
|
-
var _a2, _b2, _c, _d, _e, _f, _g;
|
|
194
|
-
const srcRoute = (val == null ? void 0 : val.srcRoute) ?? ((_b2 = (_a2 = prerenderManifestDefault == null ? void 0 : prerenderManifestDefault.routes) == null ? void 0 : _a2[key]) == null ? void 0 : _b2.srcRoute);
|
|
195
|
-
assert(typeof srcRoute === "string", `\`[prerender-manifest] { srcRoute }\` is required for route ${key}`);
|
|
196
|
-
acc[key === "/" ? "/index" : key] = {
|
|
197
|
-
initialRevalidateSeconds: (val == null ? void 0 : val.initialRevalidateSeconds) ?? ((_d = (_c = prerenderManifestDefault == null ? void 0 : prerenderManifestDefault.routes) == null ? void 0 : _c[key]) == null ? void 0 : _d.initialRevalidateSeconds) ?? ((_e = resolvedConfig.vercel) == null ? void 0 : _e.initialRevalidateSeconds) ?? 86400,
|
|
198
|
-
srcRoute,
|
|
199
|
-
dataRoute: (val == null ? void 0 : val.dataRoute) ?? ((_g = (_f = prerenderManifestDefault == null ? void 0 : prerenderManifestDefault.routes) == null ? void 0 : _f[key]) == null ? void 0 : _g.dataRoute) ?? ""
|
|
200
|
-
};
|
|
201
|
-
return acc;
|
|
202
|
-
}, {});
|
|
203
|
-
const dynamicRoutes = Object.entries((isrPages == null ? void 0 : isrPages.dynamicRoutes) ?? {}).reduce((acc, [key, val]) => {
|
|
204
|
-
var _a2;
|
|
205
|
-
const override = (_a2 = prerenderManifestDefault == null ? void 0 : prerenderManifestDefault.dynamicRoutes) == null ? void 0 : _a2[key];
|
|
206
|
-
const routeRegex = (val == null ? void 0 : val.routeRegex) ?? (override == null ? void 0 : override.routeRegex);
|
|
207
|
-
const fallback = (val == null ? void 0 : val.fallback) === null || typeof (val == null ? void 0 : val.fallback) === "string" ? val == null ? void 0 : val.fallback : (override == null ? void 0 : override.fallback) === null || typeof (override == null ? void 0 : override.fallback) === "string" ? override == null ? void 0 : override.fallback : null;
|
|
208
|
-
assert(routeRegex, `\`[prerender-manifest] { routeRegex }\` is required for route ${key}`);
|
|
209
|
-
acc[key] = {
|
|
210
|
-
routeRegex,
|
|
211
|
-
fallback,
|
|
212
|
-
dataRoute: (val == null ? void 0 : val.dataRoute) ?? (override == null ? void 0 : override.dataRoute) ?? "",
|
|
213
|
-
dataRouteRegex: (val == null ? void 0 : val.dataRouteRegex) ?? (override == null ? void 0 : override.dataRouteRegex) ?? ""
|
|
214
|
-
};
|
|
215
|
-
return acc;
|
|
216
|
-
}, {});
|
|
217
|
-
return prerenderManifestSchema.parse({
|
|
218
|
-
version: 3,
|
|
219
|
-
routes,
|
|
220
|
-
dynamicRoutes,
|
|
221
|
-
preview: {
|
|
222
|
-
previewModeId: ((_b = prerenderManifestDefault == null ? void 0 : prerenderManifestDefault.preview) == null ? void 0 : _b.previewModeId) ?? null
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
function getPrerenderManifestDestination(resolvedConfig) {
|
|
227
|
-
return import_path2.default.join(getOutput(resolvedConfig), "prerender-manifest.json");
|
|
228
|
-
}
|
|
229
|
-
function getRoutesManifest(resolvedConfig, ssr) {
|
|
230
|
-
var _a;
|
|
231
|
-
const routesManifest = (_a = resolvedConfig.vercel) == null ? void 0 : _a.routesManifest;
|
|
232
|
-
const allRewrites = [
|
|
233
|
-
...(routesManifest == null ? void 0 : routesManifest.rewrites) ?? [],
|
|
234
|
-
...(ssr == null ? void 0 : ssr.rewrites) ?? []
|
|
235
|
-
];
|
|
236
|
-
const allDynamicRoutes = [
|
|
237
|
-
...(routesManifest == null ? void 0 : routesManifest.dynamicRoutes) ?? [],
|
|
238
|
-
...(ssr == null ? void 0 : ssr.dynamicRoutes) ?? []
|
|
239
|
-
];
|
|
240
|
-
const allHeaders = [
|
|
241
|
-
...(routesManifest == null ? void 0 : routesManifest.headers) ?? [],
|
|
242
|
-
...(ssr == null ? void 0 : ssr.headers) ?? []
|
|
243
|
-
];
|
|
244
|
-
return routesManifestSchema.parse({
|
|
245
|
-
version: 3,
|
|
246
|
-
basePath: (routesManifest == null ? void 0 : routesManifest.basePath) ?? "/",
|
|
247
|
-
pages404: (routesManifest == null ? void 0 : routesManifest.pages404) ?? true,
|
|
248
|
-
dynamicRoutes: allDynamicRoutes.length > 0 ? allDynamicRoutes : void 0,
|
|
249
|
-
rewrites: allRewrites.length > 0 ? allRewrites : void 0,
|
|
250
|
-
redirects: routesManifest == null ? void 0 : routesManifest.redirects,
|
|
251
|
-
headers: allHeaders.length > 0 ? allHeaders : void 0
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
function getRoutesManifestDestination(resolvedConfig) {
|
|
255
|
-
return import_path2.default.join(getOutput(resolvedConfig), "routes-manifest.json");
|
|
256
|
-
}
|
|
257
|
-
function getFunctionsManifest(pages) {
|
|
258
|
-
return functionsManifestSchema.parse({
|
|
259
|
-
version: 1,
|
|
260
|
-
pages
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
function getFunctionsManifestDestination(resolvedConfig) {
|
|
264
|
-
return import_path2.default.join(getOutput(resolvedConfig), "functions-manifest.json");
|
|
265
|
-
}
|
|
213
|
+
var vercelOutputVcConfigSchema = z2.union([
|
|
214
|
+
vercelOutputEdgeVcConfigSchema,
|
|
215
|
+
vercelOutputServerlessVcConfigSchema,
|
|
216
|
+
vercelOutputServerlessNodeVcConfigSchema
|
|
217
|
+
]);
|
|
266
218
|
|
|
267
219
|
// src/build.ts
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
var import_esbuild = require("esbuild");
|
|
271
|
-
var import_promises2 = __toESM(require("fs/promises"));
|
|
272
|
-
function getPagesEndpoints(resolvedConfig) {
|
|
220
|
+
import fs3 from "fs/promises";
|
|
221
|
+
function getAdditionalEndpoints(resolvedConfig) {
|
|
273
222
|
var _a;
|
|
274
|
-
|
|
275
|
-
|
|
223
|
+
return (((_a = resolvedConfig.vercel) == null ? void 0 : _a.additionalEndpoints) ?? []).map((e) => __spreadProps(__spreadValues({}, e), {
|
|
224
|
+
destination: e.destination + ".func"
|
|
225
|
+
}));
|
|
276
226
|
}
|
|
277
|
-
function
|
|
278
|
-
|
|
279
|
-
const pagesEndpoints = getPagesEndpoints(resolvedConfig);
|
|
280
|
-
const apiEntries = import_fast_glob.default.sync(`${getRoot(resolvedConfig)}/api/**/*.*([a-zA-Z0-9])`).filter((filepath) => !import_path3.default.basename(filepath).startsWith("_"));
|
|
227
|
+
function getEntries(resolvedConfig) {
|
|
228
|
+
const apiEntries = glob.sync(`${getRoot(resolvedConfig)}/api/**/*.*([a-zA-Z0-9])`).filter((filepath) => !path3.basename(filepath).startsWith("_"));
|
|
281
229
|
return apiEntries.reduce((entryPoints, filePath) => {
|
|
282
230
|
const outFilePath = pathRelativeToApi(filePath, resolvedConfig);
|
|
283
|
-
const parsed =
|
|
284
|
-
const alsoPage = pagesEndpoints.has(filePath);
|
|
231
|
+
const parsed = path3.parse(outFilePath);
|
|
285
232
|
const entry = {
|
|
286
233
|
source: filePath,
|
|
287
|
-
destination:
|
|
234
|
+
destination: `api/${path3.join(parsed.dir, parsed.name)}.func`
|
|
288
235
|
};
|
|
289
|
-
if (alsoPage) {
|
|
290
|
-
entry.destination.push(`${import_path3.default.join(parsed.dir, parsed.name)}`);
|
|
291
|
-
}
|
|
292
236
|
entryPoints.push(entry);
|
|
293
237
|
return entryPoints;
|
|
294
|
-
}, (
|
|
238
|
+
}, getAdditionalEndpoints(resolvedConfig));
|
|
295
239
|
}
|
|
296
240
|
var standardBuildOptions = {
|
|
297
241
|
bundle: true,
|
|
@@ -302,15 +246,8 @@ var standardBuildOptions = {
|
|
|
302
246
|
minify: true
|
|
303
247
|
};
|
|
304
248
|
async function buildFn(resolvedConfig, entry, buildOptions) {
|
|
305
|
-
var _a, _b, _c, _d;
|
|
306
|
-
if (!Array.isArray(entry.destination)) {
|
|
307
|
-
entry.destination = [entry.destination];
|
|
308
|
-
}
|
|
309
249
|
assert(entry.destination.length > 0, `Endpoint ${typeof entry.source === "string" ? entry.source : "-"} does not have build destination`);
|
|
310
|
-
const
|
|
311
|
-
const pages = ((_b = (_a = resolvedConfig.vercel) == null ? void 0 : _a.functionsManifest) == null ? void 0 : _b.pages) ?? {};
|
|
312
|
-
const fnManifests = {};
|
|
313
|
-
const outfile = import_path3.default.join(getOutput(resolvedConfig, "server/pages"), firstDestination + ".js");
|
|
250
|
+
const outfile = path3.join(getOutput(resolvedConfig, "functions"), entry.destination, "index.js");
|
|
314
251
|
const options = Object.assign({}, standardBuildOptions, { outfile });
|
|
315
252
|
if (buildOptions) {
|
|
316
253
|
Object.assign(options, buildOptions);
|
|
@@ -324,31 +261,42 @@ async function buildFn(resolvedConfig, entry, buildOptions) {
|
|
|
324
261
|
options.stdin = entry.source;
|
|
325
262
|
}
|
|
326
263
|
}
|
|
327
|
-
await
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
}
|
|
340
|
-
return fnManifests;
|
|
264
|
+
await build(options);
|
|
265
|
+
await writeVcConfig(resolvedConfig, entry.destination);
|
|
266
|
+
}
|
|
267
|
+
async function writeVcConfig(resolvedConfig, destination) {
|
|
268
|
+
var _a;
|
|
269
|
+
const vcConfig = path3.join(getOutput(resolvedConfig, "functions"), destination, ".vc-config.json");
|
|
270
|
+
await fs3.writeFile(vcConfig, JSON.stringify(vercelOutputVcConfigSchema.parse({
|
|
271
|
+
runtime: "nodejs16.x",
|
|
272
|
+
handler: "index.js",
|
|
273
|
+
maxDuration: (_a = resolvedConfig.vercel) == null ? void 0 : _a.defaultMaxDuration,
|
|
274
|
+
launcherType: "Nodejs",
|
|
275
|
+
shouldAddHelpers: true
|
|
276
|
+
}), void 0, 2), "utf-8");
|
|
341
277
|
}
|
|
342
|
-
async function
|
|
343
|
-
const entries =
|
|
344
|
-
const fnManifests = {};
|
|
278
|
+
async function buildEndpoints(resolvedConfig) {
|
|
279
|
+
const entries = getEntries(resolvedConfig);
|
|
345
280
|
for (const entry of entries) {
|
|
346
|
-
|
|
281
|
+
await buildFn(resolvedConfig, entry);
|
|
347
282
|
}
|
|
348
|
-
return fnManifests;
|
|
349
283
|
}
|
|
350
284
|
|
|
351
285
|
// src/prerender.ts
|
|
286
|
+
import path4 from "path";
|
|
287
|
+
|
|
288
|
+
// src/schemas/config/prerender-config.ts
|
|
289
|
+
import { z as z3 } from "zod";
|
|
290
|
+
var vercelOutputPrerenderConfigSchema = z3.object({
|
|
291
|
+
expiration: z3.union([z3.number().int().positive(), z3.literal(false)]),
|
|
292
|
+
group: z3.number().int().optional(),
|
|
293
|
+
bypassToken: z3.string().optional(),
|
|
294
|
+
fallback: z3.string().optional(),
|
|
295
|
+
allowQuery: z3.array(z3.string()).optional()
|
|
296
|
+
}).strict();
|
|
297
|
+
|
|
298
|
+
// src/prerender.ts
|
|
299
|
+
import fs4 from "fs/promises";
|
|
352
300
|
function execPrerender(resolvedConfig) {
|
|
353
301
|
var _a;
|
|
354
302
|
const prerender = (_a = resolvedConfig.vercel) == null ? void 0 : _a.prerender;
|
|
@@ -357,6 +305,51 @@ function execPrerender(resolvedConfig) {
|
|
|
357
305
|
}
|
|
358
306
|
return prerender == null ? void 0 : prerender(resolvedConfig);
|
|
359
307
|
}
|
|
308
|
+
var group = 1;
|
|
309
|
+
async function writePrerenderConfig(resolvedConfig, destination, isr) {
|
|
310
|
+
const parsed = path4.parse(destination);
|
|
311
|
+
const outfile = path4.join(getOutput(resolvedConfig, "functions"), parsed.dir, parsed.name + ".prerender-config.json");
|
|
312
|
+
await fs4.mkdir(path4.join(getOutput(resolvedConfig, "functions"), parsed.dir), { recursive: true });
|
|
313
|
+
await fs4.writeFile(outfile, JSON.stringify(vercelOutputPrerenderConfigSchema.parse(__spreadValues({
|
|
314
|
+
group: group++
|
|
315
|
+
}, isr)), void 0, 2), "utf-8");
|
|
316
|
+
}
|
|
317
|
+
function getPrerenderSymlinkInfo(resolvedConfig, destination, target) {
|
|
318
|
+
const parsed = path4.parse(destination);
|
|
319
|
+
const targetParsed = path4.parse(target);
|
|
320
|
+
return {
|
|
321
|
+
target: path4.join(getOutput(resolvedConfig, "functions"), targetParsed.dir, targetParsed.name + ".func"),
|
|
322
|
+
link: path4.join(getOutput(resolvedConfig, "functions"), parsed.dir, parsed.name + ".func")
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
async function buildPrerenderConfigs(resolvedConfig) {
|
|
326
|
+
const isr = await getIsrConfig(resolvedConfig);
|
|
327
|
+
const entries = Object.entries(isr);
|
|
328
|
+
const rewrites = [];
|
|
329
|
+
for (const _a of entries) {
|
|
330
|
+
const [destination, _b] = _a, _c = _b, { symlink, route } = _c, isr2 = __objRest(_c, ["symlink", "route"]);
|
|
331
|
+
await writePrerenderConfig(resolvedConfig, destination, isr2);
|
|
332
|
+
if (symlink) {
|
|
333
|
+
const info = getPrerenderSymlinkInfo(resolvedConfig, destination, symlink);
|
|
334
|
+
await copyDir(info.target, info.link);
|
|
335
|
+
}
|
|
336
|
+
if (route) {
|
|
337
|
+
rewrites.push({
|
|
338
|
+
src: `(${route})`,
|
|
339
|
+
dest: `${destination}/?__original_path=$1`
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return rewrites;
|
|
344
|
+
}
|
|
345
|
+
async function getIsrConfig(resolvedConfig) {
|
|
346
|
+
var _a;
|
|
347
|
+
const isr = ((_a = resolvedConfig.vercel) == null ? void 0 : _a.isr) ?? {};
|
|
348
|
+
if (typeof isr === "function") {
|
|
349
|
+
return await isr();
|
|
350
|
+
}
|
|
351
|
+
return isr;
|
|
352
|
+
}
|
|
360
353
|
|
|
361
354
|
// src/index.ts
|
|
362
355
|
function vercelPlugin() {
|
|
@@ -364,6 +357,7 @@ function vercelPlugin() {
|
|
|
364
357
|
return {
|
|
365
358
|
apply: "build",
|
|
366
359
|
name: "vite-plugin-vercel",
|
|
360
|
+
enforce: "post",
|
|
367
361
|
configResolved(config) {
|
|
368
362
|
resolvedConfig = config;
|
|
369
363
|
},
|
|
@@ -371,45 +365,38 @@ function vercelPlugin() {
|
|
|
371
365
|
if (process.env.VERCEL_ENV === "production" && !process.env.ENABLE_FILE_SYSTEM_API) {
|
|
372
366
|
throw new Error("Missing ENABLE_FILE_SYSTEM_API=1 to your environment variables in your project settings");
|
|
373
367
|
}
|
|
374
|
-
if (resolvedConfig.build.ssr)
|
|
375
|
-
|
|
376
|
-
|
|
368
|
+
if (!resolvedConfig.build.ssr) {
|
|
369
|
+
await cleanOutputDirectory(resolvedConfig);
|
|
370
|
+
} else {
|
|
371
|
+
await copyDistClientToOutputStatic(resolvedConfig);
|
|
372
|
+
}
|
|
377
373
|
},
|
|
378
374
|
async writeBundle() {
|
|
379
375
|
var _a;
|
|
380
|
-
if (!((_a = resolvedConfig.build) == null ? void 0 : _a.ssr))
|
|
381
|
-
await copyDistClientToOutputStatic(resolvedConfig);
|
|
376
|
+
if (!((_a = resolvedConfig.build) == null ? void 0 : _a.ssr))
|
|
382
377
|
return;
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
const
|
|
386
|
-
await
|
|
387
|
-
|
|
388
|
-
|
|
378
|
+
const overrides = await execPrerender(resolvedConfig);
|
|
379
|
+
await buildEndpoints(resolvedConfig);
|
|
380
|
+
const rewrites = await buildPrerenderConfigs(resolvedConfig);
|
|
381
|
+
await writeConfig(resolvedConfig, {
|
|
382
|
+
routes: [{ handle: "filesystem" }, ...rewrites],
|
|
383
|
+
overrides
|
|
384
|
+
});
|
|
389
385
|
}
|
|
390
386
|
};
|
|
391
387
|
}
|
|
392
388
|
async function copyDistClientToOutputStatic(resolvedConfig) {
|
|
393
|
-
await copyDir(getOutDir(resolvedConfig), getOutput(resolvedConfig, "static"));
|
|
389
|
+
await copyDir(getOutDir(resolvedConfig, "client"), getOutput(resolvedConfig, "static"));
|
|
394
390
|
}
|
|
395
391
|
async function cleanOutputDirectory(resolvedConfig) {
|
|
396
|
-
await
|
|
392
|
+
await fs5.rm(getOutput(resolvedConfig), {
|
|
397
393
|
recursive: true,
|
|
398
394
|
force: true
|
|
399
395
|
});
|
|
400
396
|
}
|
|
401
|
-
async function generatePrerenderManifest(resolvedConfig, isrPages) {
|
|
402
|
-
await import_promises3.default.writeFile(getPrerenderManifestDestination(resolvedConfig), JSON.stringify(getPrerenderManifest(resolvedConfig, isrPages), void 0, 2));
|
|
403
|
-
}
|
|
404
|
-
async function generateRoutesManifest(resolvedConfig, ssr) {
|
|
405
|
-
await import_promises3.default.writeFile(getRoutesManifestDestination(resolvedConfig), JSON.stringify(getRoutesManifest(resolvedConfig, ssr), void 0, 2));
|
|
406
|
-
}
|
|
407
|
-
async function generateFunctionsManifest(resolvedConfig, fnManifests) {
|
|
408
|
-
await import_promises3.default.writeFile(getFunctionsManifestDestination(resolvedConfig), JSON.stringify(getFunctionsManifest(fnManifests), void 0, 2));
|
|
409
|
-
}
|
|
410
397
|
function allPlugins() {
|
|
411
398
|
return [vercelPlugin()];
|
|
412
399
|
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
400
|
+
export {
|
|
401
|
+
allPlugins as default
|
|
402
|
+
};
|