vite-plugin-vercel 0.0.0-alpha.0 → 0.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/dist/index.d.ts +5 -0
- package/dist/index.js +422 -0
- package/dist/index.mjs +393 -0
- package/index.d.ts +11 -0
- package/package.json +44 -5
- package/readme.md +28 -1
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __spreadValues = (a, b) => {
|
|
11
|
+
for (var prop in b || (b = {}))
|
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
if (__getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
20
|
+
};
|
|
21
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
22
|
+
var __export = (target, all) => {
|
|
23
|
+
for (var name in all)
|
|
24
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
25
|
+
};
|
|
26
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
27
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
28
|
+
for (let key of __getOwnPropNames(module2))
|
|
29
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
30
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
31
|
+
}
|
|
32
|
+
return target;
|
|
33
|
+
};
|
|
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
|
+
|
|
43
|
+
// src/index.ts
|
|
44
|
+
var src_exports = {};
|
|
45
|
+
__export(src_exports, {
|
|
46
|
+
default: () => allPlugins
|
|
47
|
+
});
|
|
48
|
+
var import_promises3 = __toESM(require("fs/promises"));
|
|
49
|
+
|
|
50
|
+
// src/utils.ts
|
|
51
|
+
var import_vite = require("vite");
|
|
52
|
+
var import_path = __toESM(require("path"));
|
|
53
|
+
var import_promises = __toESM(require("fs/promises"));
|
|
54
|
+
function getRoot(config) {
|
|
55
|
+
return (0, import_vite.normalizePath)(config.root || process.cwd());
|
|
56
|
+
}
|
|
57
|
+
function getOutDir(config, force) {
|
|
58
|
+
const p = (0, import_vite.normalizePath)(config.build.outDir);
|
|
59
|
+
if (!force)
|
|
60
|
+
return p;
|
|
61
|
+
return import_path.default.join(import_path.default.dirname(p), force);
|
|
62
|
+
}
|
|
63
|
+
function getOutput(config, suffix) {
|
|
64
|
+
var _a, _b;
|
|
65
|
+
return import_path.default.join(((_a = config.vercel) == null ? void 0 : _a.outDir) ? "" : getRoot(config), ((_b = config.vercel) == null ? void 0 : _b.outDir) ?? ".output", suffix ?? "");
|
|
66
|
+
}
|
|
67
|
+
function pathRelativeToApi(filePath, config) {
|
|
68
|
+
const root = getRoot(config);
|
|
69
|
+
return (0, import_vite.normalizePath)(import_path.default.relative(import_path.default.join(root, "api"), filePath));
|
|
70
|
+
}
|
|
71
|
+
async function copyDir(src, dest) {
|
|
72
|
+
await import_promises.default.mkdir(dest, { recursive: true });
|
|
73
|
+
const entries = await import_promises.default.readdir(src, { withFileTypes: true });
|
|
74
|
+
for (const entry of entries) {
|
|
75
|
+
const srcPath = import_path.default.join(src, entry.name);
|
|
76
|
+
const destPath = import_path.default.join(dest, entry.name);
|
|
77
|
+
entry.isDirectory() ? await copyDir(srcPath, destPath) : await import_promises.default.copyFile(srcPath, destPath);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// src/manifests.ts
|
|
82
|
+
var import_path2 = __toESM(require("path"));
|
|
83
|
+
|
|
84
|
+
// src/assert.ts
|
|
85
|
+
var import_libassert = require("@brillout/libassert");
|
|
86
|
+
var libName = "vite-plugin-vercel";
|
|
87
|
+
function assert(condition, errorMessage) {
|
|
88
|
+
if (condition) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const err = (0, import_libassert.newError)(`[${libName}][Wrong Usage] ${errorMessage}`, 2);
|
|
92
|
+
throw err;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/schemas/manifests/routes.ts
|
|
96
|
+
var import_myzod = __toESM(require("myzod"));
|
|
97
|
+
function record(schema) {
|
|
98
|
+
return import_myzod.default.object({
|
|
99
|
+
[import_myzod.default.keySignature]: schema
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
var routesManifestRedirectSchema = import_myzod.default.object({
|
|
103
|
+
source: import_myzod.default.string(),
|
|
104
|
+
destination: import_myzod.default.string(),
|
|
105
|
+
statusCode: import_myzod.default.literals(301, 302, 307, 308),
|
|
106
|
+
regex: import_myzod.default.string()
|
|
107
|
+
});
|
|
108
|
+
var routesManifestHeaderSchema = import_myzod.default.object({
|
|
109
|
+
source: import_myzod.default.string(),
|
|
110
|
+
headers: import_myzod.default.array(import_myzod.default.object({
|
|
111
|
+
key: import_myzod.default.string(),
|
|
112
|
+
value: import_myzod.default.string()
|
|
113
|
+
})),
|
|
114
|
+
regex: import_myzod.default.string()
|
|
115
|
+
});
|
|
116
|
+
var routesManifestRewriteSchema = import_myzod.default.object({
|
|
117
|
+
source: import_myzod.default.string(),
|
|
118
|
+
has: import_myzod.default.array(import_myzod.default.object({
|
|
119
|
+
key: import_myzod.default.string(),
|
|
120
|
+
value: import_myzod.default.string(),
|
|
121
|
+
type: import_myzod.default.literals("header", "cookie", "host", "query")
|
|
122
|
+
})).optional(),
|
|
123
|
+
destination: import_myzod.default.string(),
|
|
124
|
+
regex: import_myzod.default.string()
|
|
125
|
+
});
|
|
126
|
+
var routesManifestDynamicRouteSchema = import_myzod.default.object({
|
|
127
|
+
page: import_myzod.default.string(),
|
|
128
|
+
regex: import_myzod.default.string(),
|
|
129
|
+
routeKeys: record(import_myzod.default.string()).optional(),
|
|
130
|
+
namedRegex: import_myzod.default.string().optional()
|
|
131
|
+
});
|
|
132
|
+
var routesManifestSchema = import_myzod.default.object({
|
|
133
|
+
version: import_myzod.default.literal(3),
|
|
134
|
+
basePath: import_myzod.default.string().pattern(/^\/.*/),
|
|
135
|
+
pages404: import_myzod.default.boolean(),
|
|
136
|
+
redirects: import_myzod.default.array(routesManifestRedirectSchema).optional(),
|
|
137
|
+
headers: import_myzod.default.array(routesManifestHeaderSchema).optional(),
|
|
138
|
+
rewrites: import_myzod.default.array(routesManifestRewriteSchema).optional(),
|
|
139
|
+
dynamicRoutes: import_myzod.default.array(routesManifestDynamicRouteSchema).optional()
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// src/schemas/manifests/functions.ts
|
|
143
|
+
var import_myzod2 = __toESM(require("myzod"));
|
|
144
|
+
function record2(schema) {
|
|
145
|
+
return import_myzod2.default.object({
|
|
146
|
+
[import_myzod2.default.keySignature]: schema
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
var functionsManifestSchemaPage = import_myzod2.default.object({
|
|
150
|
+
runtime: import_myzod2.default.string().optional(),
|
|
151
|
+
handler: import_myzod2.default.string().optional(),
|
|
152
|
+
regions: import_myzod2.default.array(import_myzod2.default.string()).optional(),
|
|
153
|
+
maxDuration: import_myzod2.default.number().min(1).max(900).optional(),
|
|
154
|
+
memory: import_myzod2.default.number().min(128).max(3008).optional()
|
|
155
|
+
});
|
|
156
|
+
var functionsManifestSchemaPageWeb = import_myzod2.default.omit(functionsManifestSchemaPage, ["runtime"]).and(import_myzod2.default.object({
|
|
157
|
+
runtime: import_myzod2.default.literal("web"),
|
|
158
|
+
env: import_myzod2.default.array(import_myzod2.default.string()),
|
|
159
|
+
files: import_myzod2.default.array(import_myzod2.default.string()),
|
|
160
|
+
name: import_myzod2.default.string(),
|
|
161
|
+
page: import_myzod2.default.string(),
|
|
162
|
+
regexp: import_myzod2.default.string(),
|
|
163
|
+
sortingIndex: import_myzod2.default.number()
|
|
164
|
+
}));
|
|
165
|
+
var functionsManifestSchema = import_myzod2.default.object({
|
|
166
|
+
version: import_myzod2.default.literal(1),
|
|
167
|
+
pages: import_myzod2.default.object({
|
|
168
|
+
"_middleware.js": functionsManifestSchemaPageWeb.optional()
|
|
169
|
+
}).and(record2(import_myzod2.default.intersection(import_myzod2.default.partial(import_myzod2.default.omit(functionsManifestSchemaPageWeb, ["runtime"])), functionsManifestSchemaPage)))
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
// src/schemas/manifests/prerender.ts
|
|
173
|
+
var import_myzod3 = __toESM(require("myzod"));
|
|
174
|
+
function record3(schema) {
|
|
175
|
+
return import_myzod3.default.object({
|
|
176
|
+
[import_myzod3.default.keySignature]: schema
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
var prerenderManifestSchemaRoute = import_myzod3.default.object({
|
|
180
|
+
initialRevalidateSeconds: import_myzod3.default.number(),
|
|
181
|
+
srcRoute: import_myzod3.default.string(),
|
|
182
|
+
dataRoute: import_myzod3.default.string()
|
|
183
|
+
});
|
|
184
|
+
var prerenderManifestSchemaDynamicRoute = import_myzod3.default.object({
|
|
185
|
+
routeRegex: import_myzod3.default.string(),
|
|
186
|
+
fallback: import_myzod3.default.string().or(import_myzod3.default.null()),
|
|
187
|
+
dataRoute: import_myzod3.default.string(),
|
|
188
|
+
dataRouteRegex: import_myzod3.default.string()
|
|
189
|
+
});
|
|
190
|
+
var prerenderManifestSchema = import_myzod3.default.object({
|
|
191
|
+
version: import_myzod3.default.literal(3),
|
|
192
|
+
routes: record3(prerenderManifestSchemaRoute),
|
|
193
|
+
dynamicRoutes: record3(prerenderManifestSchemaDynamicRoute),
|
|
194
|
+
preview: import_myzod3.default.object({
|
|
195
|
+
previewModeId: import_myzod3.default.string().or(import_myzod3.default.null())
|
|
196
|
+
})
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
// src/manifests.ts
|
|
200
|
+
function getPrerenderManifest(resolvedConfig, isrPages) {
|
|
201
|
+
var _a, _b;
|
|
202
|
+
const prerenderManifestDefault = (_a = resolvedConfig.vercel) == null ? void 0 : _a.prerenderManifest;
|
|
203
|
+
const routes = Object.entries((isrPages == null ? void 0 : isrPages.routes) ?? {}).reduce((acc, [key, val]) => {
|
|
204
|
+
var _a2, _b2, _c, _d, _e, _f, _g;
|
|
205
|
+
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);
|
|
206
|
+
assert(typeof srcRoute === "string", `\`[prerender-manifest] { srcRoute }\` is required for route ${key}`);
|
|
207
|
+
acc[key === "/" ? "/index" : key] = {
|
|
208
|
+
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,
|
|
209
|
+
srcRoute,
|
|
210
|
+
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) ?? ""
|
|
211
|
+
};
|
|
212
|
+
return acc;
|
|
213
|
+
}, {});
|
|
214
|
+
const uniqueRoutes = Array.from(new Set(Object.values(routes).map((r) => r.srcRoute)));
|
|
215
|
+
const dynamicRoutes = uniqueRoutes.reduce((acc, cur) => {
|
|
216
|
+
var _a2, _b2, _c, _d, _e, _f;
|
|
217
|
+
acc[cur] = {
|
|
218
|
+
routeRegex: "^" + cur + "$",
|
|
219
|
+
dataRoute: ((_b2 = (_a2 = prerenderManifestDefault == null ? void 0 : prerenderManifestDefault.dynamicRoutes) == null ? void 0 : _a2[cur]) == null ? void 0 : _b2.dataRoute) ?? "",
|
|
220
|
+
fallback: ((_d = (_c = prerenderManifestDefault == null ? void 0 : prerenderManifestDefault.dynamicRoutes) == null ? void 0 : _c[cur]) == null ? void 0 : _d.fallback) ?? null,
|
|
221
|
+
dataRouteRegex: ((_f = (_e = prerenderManifestDefault == null ? void 0 : prerenderManifestDefault.dynamicRoutes) == null ? void 0 : _e[cur]) == null ? void 0 : _f.dataRouteRegex) ?? ""
|
|
222
|
+
};
|
|
223
|
+
return acc;
|
|
224
|
+
}, {});
|
|
225
|
+
return prerenderManifestSchema.parse({
|
|
226
|
+
version: 3,
|
|
227
|
+
routes,
|
|
228
|
+
dynamicRoutes,
|
|
229
|
+
preview: {
|
|
230
|
+
previewModeId: ((_b = prerenderManifestDefault == null ? void 0 : prerenderManifestDefault.preview) == null ? void 0 : _b.previewModeId) ?? null
|
|
231
|
+
}
|
|
232
|
+
}, {
|
|
233
|
+
collectErrors: true
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
function getPrerenderManifestDestination(resolvedConfig) {
|
|
237
|
+
return import_path2.default.join(getOutput(resolvedConfig), "prerender-manifest.json");
|
|
238
|
+
}
|
|
239
|
+
function getRoutesManifest(resolvedConfig, ssr) {
|
|
240
|
+
var _a;
|
|
241
|
+
const routesManifest = (_a = resolvedConfig.vercel) == null ? void 0 : _a.routesManifest;
|
|
242
|
+
const allRewrites = [
|
|
243
|
+
...(ssr == null ? void 0 : ssr.rewrites) ?? [],
|
|
244
|
+
...(routesManifest == null ? void 0 : routesManifest.rewrites) ?? []
|
|
245
|
+
];
|
|
246
|
+
const allDynamicRoutes = [
|
|
247
|
+
...(ssr == null ? void 0 : ssr.dynamicRoutes) ?? [],
|
|
248
|
+
...(routesManifest == null ? void 0 : routesManifest.dynamicRoutes) ?? []
|
|
249
|
+
];
|
|
250
|
+
return routesManifestSchema.parse({
|
|
251
|
+
version: 3,
|
|
252
|
+
basePath: (routesManifest == null ? void 0 : routesManifest.basePath) ?? "/",
|
|
253
|
+
pages404: (routesManifest == null ? void 0 : routesManifest.pages404) ?? true,
|
|
254
|
+
dynamicRoutes: allDynamicRoutes.length > 0 ? allDynamicRoutes : void 0,
|
|
255
|
+
rewrites: allRewrites.length > 0 ? allRewrites : void 0,
|
|
256
|
+
redirects: routesManifest == null ? void 0 : routesManifest.redirects,
|
|
257
|
+
headers: routesManifest == null ? void 0 : routesManifest.headers
|
|
258
|
+
}, {
|
|
259
|
+
collectErrors: true
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
function getRoutesManifestDestination(resolvedConfig) {
|
|
263
|
+
return import_path2.default.join(getOutput(resolvedConfig), "routes-manifest.json");
|
|
264
|
+
}
|
|
265
|
+
function getFunctionsManifest(pages) {
|
|
266
|
+
return functionsManifestSchema.parse({
|
|
267
|
+
version: 1,
|
|
268
|
+
pages
|
|
269
|
+
}, {
|
|
270
|
+
collectErrors: true
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
function getFunctionsManifestDestination(resolvedConfig) {
|
|
274
|
+
return import_path2.default.join(getOutput(resolvedConfig), "functions-manifest.json");
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// src/build.ts
|
|
278
|
+
var import_fast_glob = __toESM(require("fast-glob"));
|
|
279
|
+
var import_path3 = __toESM(require("path"));
|
|
280
|
+
var import_esbuild = require("esbuild");
|
|
281
|
+
var import_promises2 = __toESM(require("fs/promises"));
|
|
282
|
+
function getPagesEndpoints(resolvedConfig) {
|
|
283
|
+
var _a;
|
|
284
|
+
const apiEndpoints = (((_a = resolvedConfig.vercel) == null ? void 0 : _a.pagesEndpoints) ?? []).map((p) => import_path3.default.isAbsolute(p) ? p : import_path3.default.resolve(getRoot(resolvedConfig), p));
|
|
285
|
+
return new Set(apiEndpoints);
|
|
286
|
+
}
|
|
287
|
+
function getApiEntries(resolvedConfig) {
|
|
288
|
+
var _a;
|
|
289
|
+
const pagesEndpoints = getPagesEndpoints(resolvedConfig);
|
|
290
|
+
const apiEntries = import_fast_glob.default.sync(`${getRoot(resolvedConfig)}/api/**/*.*([a-zA-Z0-9])`).filter((filepath) => !import_path3.default.basename(filepath).startsWith("_"));
|
|
291
|
+
return apiEntries.reduce((entryPoints, filePath) => {
|
|
292
|
+
const outFilePath = pathRelativeToApi(filePath, resolvedConfig);
|
|
293
|
+
const parsed = import_path3.default.parse(outFilePath);
|
|
294
|
+
const alsoPage = pagesEndpoints.has(filePath);
|
|
295
|
+
const entry = {
|
|
296
|
+
source: filePath,
|
|
297
|
+
destination: [`api/${import_path3.default.join(parsed.dir, parsed.name)}`]
|
|
298
|
+
};
|
|
299
|
+
if (alsoPage) {
|
|
300
|
+
entry.destination.push(`${import_path3.default.join(parsed.dir, parsed.name)}`);
|
|
301
|
+
}
|
|
302
|
+
entryPoints.push(entry);
|
|
303
|
+
return entryPoints;
|
|
304
|
+
}, ((_a = resolvedConfig.vercel) == null ? void 0 : _a.additionalEndpoints) ?? []);
|
|
305
|
+
}
|
|
306
|
+
var standardBuildOptions = {
|
|
307
|
+
bundle: true,
|
|
308
|
+
target: "es2020",
|
|
309
|
+
format: "cjs",
|
|
310
|
+
platform: "node",
|
|
311
|
+
logLevel: "info",
|
|
312
|
+
minify: true
|
|
313
|
+
};
|
|
314
|
+
async function buildFn(resolvedConfig, entry, buildOptions) {
|
|
315
|
+
var _a, _b, _c, _d;
|
|
316
|
+
if (!Array.isArray(entry.destination)) {
|
|
317
|
+
entry.destination = [entry.destination];
|
|
318
|
+
}
|
|
319
|
+
assert(entry.destination.length > 0, `Endpoint ${typeof entry.source === "string" ? entry.source : "-"} does not have build destination`);
|
|
320
|
+
const [firstDestination, ...remainingDestinations] = entry.destination;
|
|
321
|
+
const pages = ((_b = (_a = resolvedConfig.vercel) == null ? void 0 : _a.functionsManifest) == null ? void 0 : _b.pages) ?? {};
|
|
322
|
+
const fnManifests = {};
|
|
323
|
+
const outfile = import_path3.default.join(getOutput(resolvedConfig, "server/pages"), firstDestination + ".js");
|
|
324
|
+
const options = Object.assign({}, standardBuildOptions, { outfile });
|
|
325
|
+
if (buildOptions) {
|
|
326
|
+
Object.assign(options, buildOptions);
|
|
327
|
+
}
|
|
328
|
+
if (!options.stdin) {
|
|
329
|
+
if (typeof entry.source === "string") {
|
|
330
|
+
options.entryPoints = [entry.source];
|
|
331
|
+
} else {
|
|
332
|
+
assert(typeof entry.source === "object", `\`{ source }\` must be a string or an object`);
|
|
333
|
+
assert(typeof entry.source.contents === "string", `\`{ contents }\` must be a string`);
|
|
334
|
+
options.stdin = entry.source;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
await (0, import_esbuild.build)(options);
|
|
338
|
+
fnManifests[firstDestination + ".js"] = __spreadValues({
|
|
339
|
+
maxDuration: (_c = resolvedConfig.vercel) == null ? void 0 : _c.defaultMaxDuration
|
|
340
|
+
}, pages[firstDestination + ".js"]);
|
|
341
|
+
for (const dest of remainingDestinations) {
|
|
342
|
+
await import_promises2.default.mkdir(import_path3.default.join(getOutput(resolvedConfig, "server/pages"), import_path3.default.dirname(dest)), {
|
|
343
|
+
recursive: true
|
|
344
|
+
});
|
|
345
|
+
await import_promises2.default.copyFile(outfile, import_path3.default.join(getOutput(resolvedConfig, "server/pages"), dest + ".js"));
|
|
346
|
+
fnManifests[dest + ".js"] = __spreadValues({
|
|
347
|
+
maxDuration: (_d = resolvedConfig.vercel) == null ? void 0 : _d.defaultMaxDuration
|
|
348
|
+
}, pages[dest + ".js"] ?? pages[firstDestination + ".js"]);
|
|
349
|
+
}
|
|
350
|
+
return fnManifests;
|
|
351
|
+
}
|
|
352
|
+
async function buildApiEndpoints(resolvedConfig) {
|
|
353
|
+
const entries = getApiEntries(resolvedConfig);
|
|
354
|
+
const fnManifests = {};
|
|
355
|
+
for (const entry of entries) {
|
|
356
|
+
Object.assign(fnManifests, await buildFn(resolvedConfig, entry));
|
|
357
|
+
}
|
|
358
|
+
return fnManifests;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// src/prerender.ts
|
|
362
|
+
function execPrerender(resolvedConfig) {
|
|
363
|
+
var _a;
|
|
364
|
+
const prerender = (_a = resolvedConfig.vercel) == null ? void 0 : _a.prerender;
|
|
365
|
+
if (prerender === false) {
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
return prerender == null ? void 0 : prerender(resolvedConfig);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// src/index.ts
|
|
372
|
+
function vercelPlugin() {
|
|
373
|
+
let resolvedConfig;
|
|
374
|
+
return {
|
|
375
|
+
apply: "build",
|
|
376
|
+
name: "vite-plugin-vercel",
|
|
377
|
+
configResolved(config) {
|
|
378
|
+
resolvedConfig = config;
|
|
379
|
+
},
|
|
380
|
+
async buildStart() {
|
|
381
|
+
if (resolvedConfig.build.ssr)
|
|
382
|
+
return;
|
|
383
|
+
await cleanOutputDirectory(resolvedConfig);
|
|
384
|
+
},
|
|
385
|
+
async writeBundle() {
|
|
386
|
+
var _a;
|
|
387
|
+
if (!((_a = resolvedConfig.build) == null ? void 0 : _a.ssr)) {
|
|
388
|
+
await copyDistClientToOutputStatic(resolvedConfig);
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
const isrPages = await execPrerender(resolvedConfig);
|
|
392
|
+
const fnManifests = await buildApiEndpoints(resolvedConfig);
|
|
393
|
+
await generateFunctionsManifest(resolvedConfig, fnManifests);
|
|
394
|
+
await generateRoutesManifest(resolvedConfig, isrPages == null ? void 0 : isrPages.ssr);
|
|
395
|
+
await generatePrerenderManifest(resolvedConfig, isrPages == null ? void 0 : isrPages.isr);
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
async function copyDistClientToOutputStatic(resolvedConfig) {
|
|
400
|
+
await copyDir(getOutDir(resolvedConfig), getOutput(resolvedConfig, "static"));
|
|
401
|
+
}
|
|
402
|
+
async function cleanOutputDirectory(resolvedConfig) {
|
|
403
|
+
await import_promises3.default.rm(getOutput(resolvedConfig), {
|
|
404
|
+
recursive: true,
|
|
405
|
+
force: true
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
async function generatePrerenderManifest(resolvedConfig, isrPages) {
|
|
409
|
+
await import_promises3.default.writeFile(getPrerenderManifestDestination(resolvedConfig), JSON.stringify(getPrerenderManifest(resolvedConfig, isrPages), void 0, 2));
|
|
410
|
+
}
|
|
411
|
+
async function generateRoutesManifest(resolvedConfig, ssr) {
|
|
412
|
+
await import_promises3.default.writeFile(getRoutesManifestDestination(resolvedConfig), JSON.stringify(getRoutesManifest(resolvedConfig, ssr), void 0, 2));
|
|
413
|
+
}
|
|
414
|
+
async function generateFunctionsManifest(resolvedConfig, fnManifests) {
|
|
415
|
+
await import_promises3.default.writeFile(getFunctionsManifestDestination(resolvedConfig), JSON.stringify(getFunctionsManifest(fnManifests), void 0, 2));
|
|
416
|
+
}
|
|
417
|
+
function allPlugins() {
|
|
418
|
+
return [vercelPlugin()];
|
|
419
|
+
}
|
|
420
|
+
module.exports = __toCommonJS(src_exports);
|
|
421
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
422
|
+
0 && (module.exports = {});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// src/index.ts
|
|
19
|
+
import fs3 from "fs/promises";
|
|
20
|
+
|
|
21
|
+
// src/utils.ts
|
|
22
|
+
import { normalizePath } from "vite";
|
|
23
|
+
import path from "path";
|
|
24
|
+
import fs from "fs/promises";
|
|
25
|
+
function getRoot(config) {
|
|
26
|
+
return normalizePath(config.root || process.cwd());
|
|
27
|
+
}
|
|
28
|
+
function getOutDir(config, force) {
|
|
29
|
+
const p = normalizePath(config.build.outDir);
|
|
30
|
+
if (!force)
|
|
31
|
+
return p;
|
|
32
|
+
return path.join(path.dirname(p), force);
|
|
33
|
+
}
|
|
34
|
+
function getOutput(config, suffix) {
|
|
35
|
+
var _a, _b;
|
|
36
|
+
return path.join(((_a = config.vercel) == null ? void 0 : _a.outDir) ? "" : getRoot(config), ((_b = config.vercel) == null ? void 0 : _b.outDir) ?? ".output", suffix ?? "");
|
|
37
|
+
}
|
|
38
|
+
function pathRelativeToApi(filePath, config) {
|
|
39
|
+
const root = getRoot(config);
|
|
40
|
+
return normalizePath(path.relative(path.join(root, "api"), filePath));
|
|
41
|
+
}
|
|
42
|
+
async function copyDir(src, dest) {
|
|
43
|
+
await fs.mkdir(dest, { recursive: true });
|
|
44
|
+
const entries = await fs.readdir(src, { withFileTypes: true });
|
|
45
|
+
for (const entry of entries) {
|
|
46
|
+
const srcPath = path.join(src, entry.name);
|
|
47
|
+
const destPath = path.join(dest, entry.name);
|
|
48
|
+
entry.isDirectory() ? await copyDir(srcPath, destPath) : await fs.copyFile(srcPath, destPath);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/manifests.ts
|
|
53
|
+
import path2 from "path";
|
|
54
|
+
|
|
55
|
+
// src/assert.ts
|
|
56
|
+
import { newError } from "@brillout/libassert";
|
|
57
|
+
var libName = "vite-plugin-vercel";
|
|
58
|
+
function assert(condition, errorMessage) {
|
|
59
|
+
if (condition) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const err = newError(`[${libName}][Wrong Usage] ${errorMessage}`, 2);
|
|
63
|
+
throw err;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// src/schemas/manifests/routes.ts
|
|
67
|
+
import myzod from "myzod";
|
|
68
|
+
function record(schema) {
|
|
69
|
+
return myzod.object({
|
|
70
|
+
[myzod.keySignature]: schema
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
var routesManifestRedirectSchema = myzod.object({
|
|
74
|
+
source: myzod.string(),
|
|
75
|
+
destination: myzod.string(),
|
|
76
|
+
statusCode: myzod.literals(301, 302, 307, 308),
|
|
77
|
+
regex: myzod.string()
|
|
78
|
+
});
|
|
79
|
+
var routesManifestHeaderSchema = myzod.object({
|
|
80
|
+
source: myzod.string(),
|
|
81
|
+
headers: myzod.array(myzod.object({
|
|
82
|
+
key: myzod.string(),
|
|
83
|
+
value: myzod.string()
|
|
84
|
+
})),
|
|
85
|
+
regex: myzod.string()
|
|
86
|
+
});
|
|
87
|
+
var routesManifestRewriteSchema = myzod.object({
|
|
88
|
+
source: myzod.string(),
|
|
89
|
+
has: myzod.array(myzod.object({
|
|
90
|
+
key: myzod.string(),
|
|
91
|
+
value: myzod.string(),
|
|
92
|
+
type: myzod.literals("header", "cookie", "host", "query")
|
|
93
|
+
})).optional(),
|
|
94
|
+
destination: myzod.string(),
|
|
95
|
+
regex: myzod.string()
|
|
96
|
+
});
|
|
97
|
+
var routesManifestDynamicRouteSchema = myzod.object({
|
|
98
|
+
page: myzod.string(),
|
|
99
|
+
regex: myzod.string(),
|
|
100
|
+
routeKeys: record(myzod.string()).optional(),
|
|
101
|
+
namedRegex: myzod.string().optional()
|
|
102
|
+
});
|
|
103
|
+
var routesManifestSchema = myzod.object({
|
|
104
|
+
version: myzod.literal(3),
|
|
105
|
+
basePath: myzod.string().pattern(/^\/.*/),
|
|
106
|
+
pages404: myzod.boolean(),
|
|
107
|
+
redirects: myzod.array(routesManifestRedirectSchema).optional(),
|
|
108
|
+
headers: myzod.array(routesManifestHeaderSchema).optional(),
|
|
109
|
+
rewrites: myzod.array(routesManifestRewriteSchema).optional(),
|
|
110
|
+
dynamicRoutes: myzod.array(routesManifestDynamicRouteSchema).optional()
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// src/schemas/manifests/functions.ts
|
|
114
|
+
import myzod2 from "myzod";
|
|
115
|
+
function record2(schema) {
|
|
116
|
+
return myzod2.object({
|
|
117
|
+
[myzod2.keySignature]: schema
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
var functionsManifestSchemaPage = myzod2.object({
|
|
121
|
+
runtime: myzod2.string().optional(),
|
|
122
|
+
handler: myzod2.string().optional(),
|
|
123
|
+
regions: myzod2.array(myzod2.string()).optional(),
|
|
124
|
+
maxDuration: myzod2.number().min(1).max(900).optional(),
|
|
125
|
+
memory: myzod2.number().min(128).max(3008).optional()
|
|
126
|
+
});
|
|
127
|
+
var functionsManifestSchemaPageWeb = myzod2.omit(functionsManifestSchemaPage, ["runtime"]).and(myzod2.object({
|
|
128
|
+
runtime: myzod2.literal("web"),
|
|
129
|
+
env: myzod2.array(myzod2.string()),
|
|
130
|
+
files: myzod2.array(myzod2.string()),
|
|
131
|
+
name: myzod2.string(),
|
|
132
|
+
page: myzod2.string(),
|
|
133
|
+
regexp: myzod2.string(),
|
|
134
|
+
sortingIndex: myzod2.number()
|
|
135
|
+
}));
|
|
136
|
+
var functionsManifestSchema = myzod2.object({
|
|
137
|
+
version: myzod2.literal(1),
|
|
138
|
+
pages: myzod2.object({
|
|
139
|
+
"_middleware.js": functionsManifestSchemaPageWeb.optional()
|
|
140
|
+
}).and(record2(myzod2.intersection(myzod2.partial(myzod2.omit(functionsManifestSchemaPageWeb, ["runtime"])), functionsManifestSchemaPage)))
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// src/schemas/manifests/prerender.ts
|
|
144
|
+
import myzod3 from "myzod";
|
|
145
|
+
function record3(schema) {
|
|
146
|
+
return myzod3.object({
|
|
147
|
+
[myzod3.keySignature]: schema
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
var prerenderManifestSchemaRoute = myzod3.object({
|
|
151
|
+
initialRevalidateSeconds: myzod3.number(),
|
|
152
|
+
srcRoute: myzod3.string(),
|
|
153
|
+
dataRoute: myzod3.string()
|
|
154
|
+
});
|
|
155
|
+
var prerenderManifestSchemaDynamicRoute = myzod3.object({
|
|
156
|
+
routeRegex: myzod3.string(),
|
|
157
|
+
fallback: myzod3.string().or(myzod3.null()),
|
|
158
|
+
dataRoute: myzod3.string(),
|
|
159
|
+
dataRouteRegex: myzod3.string()
|
|
160
|
+
});
|
|
161
|
+
var prerenderManifestSchema = myzod3.object({
|
|
162
|
+
version: myzod3.literal(3),
|
|
163
|
+
routes: record3(prerenderManifestSchemaRoute),
|
|
164
|
+
dynamicRoutes: record3(prerenderManifestSchemaDynamicRoute),
|
|
165
|
+
preview: myzod3.object({
|
|
166
|
+
previewModeId: myzod3.string().or(myzod3.null())
|
|
167
|
+
})
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// src/manifests.ts
|
|
171
|
+
function getPrerenderManifest(resolvedConfig, isrPages) {
|
|
172
|
+
var _a, _b;
|
|
173
|
+
const prerenderManifestDefault = (_a = resolvedConfig.vercel) == null ? void 0 : _a.prerenderManifest;
|
|
174
|
+
const routes = Object.entries((isrPages == null ? void 0 : isrPages.routes) ?? {}).reduce((acc, [key, val]) => {
|
|
175
|
+
var _a2, _b2, _c, _d, _e, _f, _g;
|
|
176
|
+
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);
|
|
177
|
+
assert(typeof srcRoute === "string", `\`[prerender-manifest] { srcRoute }\` is required for route ${key}`);
|
|
178
|
+
acc[key === "/" ? "/index" : key] = {
|
|
179
|
+
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,
|
|
180
|
+
srcRoute,
|
|
181
|
+
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) ?? ""
|
|
182
|
+
};
|
|
183
|
+
return acc;
|
|
184
|
+
}, {});
|
|
185
|
+
const uniqueRoutes = Array.from(new Set(Object.values(routes).map((r) => r.srcRoute)));
|
|
186
|
+
const dynamicRoutes = uniqueRoutes.reduce((acc, cur) => {
|
|
187
|
+
var _a2, _b2, _c, _d, _e, _f;
|
|
188
|
+
acc[cur] = {
|
|
189
|
+
routeRegex: "^" + cur + "$",
|
|
190
|
+
dataRoute: ((_b2 = (_a2 = prerenderManifestDefault == null ? void 0 : prerenderManifestDefault.dynamicRoutes) == null ? void 0 : _a2[cur]) == null ? void 0 : _b2.dataRoute) ?? "",
|
|
191
|
+
fallback: ((_d = (_c = prerenderManifestDefault == null ? void 0 : prerenderManifestDefault.dynamicRoutes) == null ? void 0 : _c[cur]) == null ? void 0 : _d.fallback) ?? null,
|
|
192
|
+
dataRouteRegex: ((_f = (_e = prerenderManifestDefault == null ? void 0 : prerenderManifestDefault.dynamicRoutes) == null ? void 0 : _e[cur]) == null ? void 0 : _f.dataRouteRegex) ?? ""
|
|
193
|
+
};
|
|
194
|
+
return acc;
|
|
195
|
+
}, {});
|
|
196
|
+
return prerenderManifestSchema.parse({
|
|
197
|
+
version: 3,
|
|
198
|
+
routes,
|
|
199
|
+
dynamicRoutes,
|
|
200
|
+
preview: {
|
|
201
|
+
previewModeId: ((_b = prerenderManifestDefault == null ? void 0 : prerenderManifestDefault.preview) == null ? void 0 : _b.previewModeId) ?? null
|
|
202
|
+
}
|
|
203
|
+
}, {
|
|
204
|
+
collectErrors: true
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
function getPrerenderManifestDestination(resolvedConfig) {
|
|
208
|
+
return path2.join(getOutput(resolvedConfig), "prerender-manifest.json");
|
|
209
|
+
}
|
|
210
|
+
function getRoutesManifest(resolvedConfig, ssr) {
|
|
211
|
+
var _a;
|
|
212
|
+
const routesManifest = (_a = resolvedConfig.vercel) == null ? void 0 : _a.routesManifest;
|
|
213
|
+
const allRewrites = [
|
|
214
|
+
...(ssr == null ? void 0 : ssr.rewrites) ?? [],
|
|
215
|
+
...(routesManifest == null ? void 0 : routesManifest.rewrites) ?? []
|
|
216
|
+
];
|
|
217
|
+
const allDynamicRoutes = [
|
|
218
|
+
...(ssr == null ? void 0 : ssr.dynamicRoutes) ?? [],
|
|
219
|
+
...(routesManifest == null ? void 0 : routesManifest.dynamicRoutes) ?? []
|
|
220
|
+
];
|
|
221
|
+
return routesManifestSchema.parse({
|
|
222
|
+
version: 3,
|
|
223
|
+
basePath: (routesManifest == null ? void 0 : routesManifest.basePath) ?? "/",
|
|
224
|
+
pages404: (routesManifest == null ? void 0 : routesManifest.pages404) ?? true,
|
|
225
|
+
dynamicRoutes: allDynamicRoutes.length > 0 ? allDynamicRoutes : void 0,
|
|
226
|
+
rewrites: allRewrites.length > 0 ? allRewrites : void 0,
|
|
227
|
+
redirects: routesManifest == null ? void 0 : routesManifest.redirects,
|
|
228
|
+
headers: routesManifest == null ? void 0 : routesManifest.headers
|
|
229
|
+
}, {
|
|
230
|
+
collectErrors: true
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
function getRoutesManifestDestination(resolvedConfig) {
|
|
234
|
+
return path2.join(getOutput(resolvedConfig), "routes-manifest.json");
|
|
235
|
+
}
|
|
236
|
+
function getFunctionsManifest(pages) {
|
|
237
|
+
return functionsManifestSchema.parse({
|
|
238
|
+
version: 1,
|
|
239
|
+
pages
|
|
240
|
+
}, {
|
|
241
|
+
collectErrors: true
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
function getFunctionsManifestDestination(resolvedConfig) {
|
|
245
|
+
return path2.join(getOutput(resolvedConfig), "functions-manifest.json");
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// src/build.ts
|
|
249
|
+
import glob from "fast-glob";
|
|
250
|
+
import path3 from "path";
|
|
251
|
+
import { build } from "esbuild";
|
|
252
|
+
import fs2 from "fs/promises";
|
|
253
|
+
function getPagesEndpoints(resolvedConfig) {
|
|
254
|
+
var _a;
|
|
255
|
+
const apiEndpoints = (((_a = resolvedConfig.vercel) == null ? void 0 : _a.pagesEndpoints) ?? []).map((p) => path3.isAbsolute(p) ? p : path3.resolve(getRoot(resolvedConfig), p));
|
|
256
|
+
return new Set(apiEndpoints);
|
|
257
|
+
}
|
|
258
|
+
function getApiEntries(resolvedConfig) {
|
|
259
|
+
var _a;
|
|
260
|
+
const pagesEndpoints = getPagesEndpoints(resolvedConfig);
|
|
261
|
+
const apiEntries = glob.sync(`${getRoot(resolvedConfig)}/api/**/*.*([a-zA-Z0-9])`).filter((filepath) => !path3.basename(filepath).startsWith("_"));
|
|
262
|
+
return apiEntries.reduce((entryPoints, filePath) => {
|
|
263
|
+
const outFilePath = pathRelativeToApi(filePath, resolvedConfig);
|
|
264
|
+
const parsed = path3.parse(outFilePath);
|
|
265
|
+
const alsoPage = pagesEndpoints.has(filePath);
|
|
266
|
+
const entry = {
|
|
267
|
+
source: filePath,
|
|
268
|
+
destination: [`api/${path3.join(parsed.dir, parsed.name)}`]
|
|
269
|
+
};
|
|
270
|
+
if (alsoPage) {
|
|
271
|
+
entry.destination.push(`${path3.join(parsed.dir, parsed.name)}`);
|
|
272
|
+
}
|
|
273
|
+
entryPoints.push(entry);
|
|
274
|
+
return entryPoints;
|
|
275
|
+
}, ((_a = resolvedConfig.vercel) == null ? void 0 : _a.additionalEndpoints) ?? []);
|
|
276
|
+
}
|
|
277
|
+
var standardBuildOptions = {
|
|
278
|
+
bundle: true,
|
|
279
|
+
target: "es2020",
|
|
280
|
+
format: "cjs",
|
|
281
|
+
platform: "node",
|
|
282
|
+
logLevel: "info",
|
|
283
|
+
minify: true
|
|
284
|
+
};
|
|
285
|
+
async function buildFn(resolvedConfig, entry, buildOptions) {
|
|
286
|
+
var _a, _b, _c, _d;
|
|
287
|
+
if (!Array.isArray(entry.destination)) {
|
|
288
|
+
entry.destination = [entry.destination];
|
|
289
|
+
}
|
|
290
|
+
assert(entry.destination.length > 0, `Endpoint ${typeof entry.source === "string" ? entry.source : "-"} does not have build destination`);
|
|
291
|
+
const [firstDestination, ...remainingDestinations] = entry.destination;
|
|
292
|
+
const pages = ((_b = (_a = resolvedConfig.vercel) == null ? void 0 : _a.functionsManifest) == null ? void 0 : _b.pages) ?? {};
|
|
293
|
+
const fnManifests = {};
|
|
294
|
+
const outfile = path3.join(getOutput(resolvedConfig, "server/pages"), firstDestination + ".js");
|
|
295
|
+
const options = Object.assign({}, standardBuildOptions, { outfile });
|
|
296
|
+
if (buildOptions) {
|
|
297
|
+
Object.assign(options, buildOptions);
|
|
298
|
+
}
|
|
299
|
+
if (!options.stdin) {
|
|
300
|
+
if (typeof entry.source === "string") {
|
|
301
|
+
options.entryPoints = [entry.source];
|
|
302
|
+
} else {
|
|
303
|
+
assert(typeof entry.source === "object", `\`{ source }\` must be a string or an object`);
|
|
304
|
+
assert(typeof entry.source.contents === "string", `\`{ contents }\` must be a string`);
|
|
305
|
+
options.stdin = entry.source;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
await build(options);
|
|
309
|
+
fnManifests[firstDestination + ".js"] = __spreadValues({
|
|
310
|
+
maxDuration: (_c = resolvedConfig.vercel) == null ? void 0 : _c.defaultMaxDuration
|
|
311
|
+
}, pages[firstDestination + ".js"]);
|
|
312
|
+
for (const dest of remainingDestinations) {
|
|
313
|
+
await fs2.mkdir(path3.join(getOutput(resolvedConfig, "server/pages"), path3.dirname(dest)), {
|
|
314
|
+
recursive: true
|
|
315
|
+
});
|
|
316
|
+
await fs2.copyFile(outfile, path3.join(getOutput(resolvedConfig, "server/pages"), dest + ".js"));
|
|
317
|
+
fnManifests[dest + ".js"] = __spreadValues({
|
|
318
|
+
maxDuration: (_d = resolvedConfig.vercel) == null ? void 0 : _d.defaultMaxDuration
|
|
319
|
+
}, pages[dest + ".js"] ?? pages[firstDestination + ".js"]);
|
|
320
|
+
}
|
|
321
|
+
return fnManifests;
|
|
322
|
+
}
|
|
323
|
+
async function buildApiEndpoints(resolvedConfig) {
|
|
324
|
+
const entries = getApiEntries(resolvedConfig);
|
|
325
|
+
const fnManifests = {};
|
|
326
|
+
for (const entry of entries) {
|
|
327
|
+
Object.assign(fnManifests, await buildFn(resolvedConfig, entry));
|
|
328
|
+
}
|
|
329
|
+
return fnManifests;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// src/prerender.ts
|
|
333
|
+
function execPrerender(resolvedConfig) {
|
|
334
|
+
var _a;
|
|
335
|
+
const prerender = (_a = resolvedConfig.vercel) == null ? void 0 : _a.prerender;
|
|
336
|
+
if (prerender === false) {
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
return prerender == null ? void 0 : prerender(resolvedConfig);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// src/index.ts
|
|
343
|
+
function vercelPlugin() {
|
|
344
|
+
let resolvedConfig;
|
|
345
|
+
return {
|
|
346
|
+
apply: "build",
|
|
347
|
+
name: "vite-plugin-vercel",
|
|
348
|
+
configResolved(config) {
|
|
349
|
+
resolvedConfig = config;
|
|
350
|
+
},
|
|
351
|
+
async buildStart() {
|
|
352
|
+
if (resolvedConfig.build.ssr)
|
|
353
|
+
return;
|
|
354
|
+
await cleanOutputDirectory(resolvedConfig);
|
|
355
|
+
},
|
|
356
|
+
async writeBundle() {
|
|
357
|
+
var _a;
|
|
358
|
+
if (!((_a = resolvedConfig.build) == null ? void 0 : _a.ssr)) {
|
|
359
|
+
await copyDistClientToOutputStatic(resolvedConfig);
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
const isrPages = await execPrerender(resolvedConfig);
|
|
363
|
+
const fnManifests = await buildApiEndpoints(resolvedConfig);
|
|
364
|
+
await generateFunctionsManifest(resolvedConfig, fnManifests);
|
|
365
|
+
await generateRoutesManifest(resolvedConfig, isrPages == null ? void 0 : isrPages.ssr);
|
|
366
|
+
await generatePrerenderManifest(resolvedConfig, isrPages == null ? void 0 : isrPages.isr);
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
async function copyDistClientToOutputStatic(resolvedConfig) {
|
|
371
|
+
await copyDir(getOutDir(resolvedConfig), getOutput(resolvedConfig, "static"));
|
|
372
|
+
}
|
|
373
|
+
async function cleanOutputDirectory(resolvedConfig) {
|
|
374
|
+
await fs3.rm(getOutput(resolvedConfig), {
|
|
375
|
+
recursive: true,
|
|
376
|
+
force: true
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
async function generatePrerenderManifest(resolvedConfig, isrPages) {
|
|
380
|
+
await fs3.writeFile(getPrerenderManifestDestination(resolvedConfig), JSON.stringify(getPrerenderManifest(resolvedConfig, isrPages), void 0, 2));
|
|
381
|
+
}
|
|
382
|
+
async function generateRoutesManifest(resolvedConfig, ssr) {
|
|
383
|
+
await fs3.writeFile(getRoutesManifestDestination(resolvedConfig), JSON.stringify(getRoutesManifest(resolvedConfig, ssr), void 0, 2));
|
|
384
|
+
}
|
|
385
|
+
async function generateFunctionsManifest(resolvedConfig, fnManifests) {
|
|
386
|
+
await fs3.writeFile(getFunctionsManifestDestination(resolvedConfig), JSON.stringify(getFunctionsManifest(fnManifests), void 0, 2));
|
|
387
|
+
}
|
|
388
|
+
function allPlugins() {
|
|
389
|
+
return [vercelPlugin()];
|
|
390
|
+
}
|
|
391
|
+
export {
|
|
392
|
+
allPlugins as default
|
|
393
|
+
};
|
package/index.d.ts
ADDED
package/package.json
CHANGED
|
@@ -1,7 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-vercel",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"module": "./dist/index.mjs",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist",
|
|
7
|
+
"*.d.ts"
|
|
8
|
+
],
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/index.mjs",
|
|
13
|
+
"require": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"types": "./index.d.ts",
|
|
17
|
+
"description": "Vercel adapter for vite",
|
|
18
|
+
"author": "Joël Charles <joel.charles91@gmail.com>",
|
|
19
|
+
"repository": "https://github.com/magne4000/vite-plugin-vercel",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"vite": "^2.8.1"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/node": "^17.0.21",
|
|
26
|
+
"@typescript-eslint/eslint-plugin": "^5.14.0",
|
|
27
|
+
"@typescript-eslint/parser": "^5.14.0",
|
|
28
|
+
"eslint": "^8.10.0",
|
|
29
|
+
"eslint-plugin-solid": "^0.4.4",
|
|
30
|
+
"tsup": "^5.12.0",
|
|
31
|
+
"typescript": "^4.6.2"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@brillout/libassert": "^0.5.4",
|
|
35
|
+
"esbuild": "^0.14.25",
|
|
36
|
+
"fast-glob": "^3.2.11",
|
|
37
|
+
"myzod": "^1.8.7"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsup",
|
|
41
|
+
"dev": "tsup --watch",
|
|
42
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
43
|
+
"lint:ts": "eslint . --max-warnings 0 --ignore-pattern dist"
|
|
44
|
+
},
|
|
45
|
+
"readme": "# vite-plugin-vercel\n\nThis is a wip Vercel adapter for [`vite`](https://vitejs.dev/).\n\n## Usage\n\nInstall as a dev dependency and add it to your Vite config like this:\n\n```ts\nimport { defineConfig } from 'vite';\nimport vercel from 'vite-plugin-vercel';\nimport ssr from 'vite-plugin-ssr';\n\nexport default defineConfig({\n plugins: [\n ssr(),\n vercel({\n dynamicRoutes: [\n {\n ssr: true,\n page: '/ssr',\n regex: '/((?!assets/)(?!api/).*)',\n },\n ],\n }),\n ],\n});\n```\n"
|
|
46
|
+
}
|
package/readme.md
CHANGED
|
@@ -1 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
# vite-plugin-vercel
|
|
2
|
+
|
|
3
|
+
This is a wip Vercel adapter for [`vite`](https://vitejs.dev/).
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
Install as a dev dependency and add it to your Vite config like this:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { defineConfig } from 'vite';
|
|
11
|
+
import vercel from 'vite-plugin-vercel';
|
|
12
|
+
import ssr from 'vite-plugin-ssr';
|
|
13
|
+
|
|
14
|
+
export default defineConfig({
|
|
15
|
+
plugins: [
|
|
16
|
+
ssr(),
|
|
17
|
+
vercel({
|
|
18
|
+
dynamicRoutes: [
|
|
19
|
+
{
|
|
20
|
+
ssr: true,
|
|
21
|
+
page: '/ssr',
|
|
22
|
+
regex: '/((?!assets/)(?!api/).*)',
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
}),
|
|
26
|
+
],
|
|
27
|
+
});
|
|
28
|
+
```
|