vite-plugin-vercel 8.0.1 → 9.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/dist/index.cjs +341 -380
- package/dist/index.d.cts +44 -38
- package/dist/index.d.ts +44 -38
- package/dist/index.js +339 -378
- package/index.d.ts +4 -4
- package/package.json +10 -13
package/dist/index.cjs
CHANGED
|
@@ -34,208 +34,18 @@ __export(src_exports, {
|
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(src_exports);
|
|
36
36
|
var import_promises5 = __toESM(require("fs/promises"), 1);
|
|
37
|
-
|
|
38
|
-
// src/utils.ts
|
|
39
|
-
var import_vite = require("vite");
|
|
40
|
-
var import_path = __toESM(require("path"), 1);
|
|
41
|
-
function getRoot(config) {
|
|
42
|
-
return (0, import_vite.normalizePath)(config.root || process.cwd());
|
|
43
|
-
}
|
|
44
|
-
function getOutput(config, suffix) {
|
|
45
|
-
return import_path.default.join(
|
|
46
|
-
config.vercel?.outDir ? "" : getRoot(config),
|
|
47
|
-
config.vercel?.outDir ?? ".vercel/output",
|
|
48
|
-
suffix ?? ""
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
function getPublic(config) {
|
|
52
|
-
return import_path.default.join(getRoot(config), config.publicDir || "public");
|
|
53
|
-
}
|
|
54
|
-
function pathRelativeTo(filePath, config, rel) {
|
|
55
|
-
const root = getRoot(config);
|
|
56
|
-
return (0, import_vite.normalizePath)(
|
|
57
|
-
import_path.default.relative((0, import_vite.normalizePath)(import_path.default.join(root, rel)), filePath)
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// src/config.ts
|
|
62
|
-
var import_path2 = __toESM(require("path"), 1);
|
|
63
|
-
|
|
64
|
-
// src/schemas/config/config.ts
|
|
65
|
-
var import_zod = require("zod");
|
|
66
|
-
var HasOrMissing = import_zod.z.array(
|
|
67
|
-
import_zod.z.union([
|
|
68
|
-
import_zod.z.object({
|
|
69
|
-
type: import_zod.z.literal("host"),
|
|
70
|
-
value: import_zod.z.string()
|
|
71
|
-
}).strict(),
|
|
72
|
-
import_zod.z.object({
|
|
73
|
-
type: import_zod.z.literal("header"),
|
|
74
|
-
key: import_zod.z.string(),
|
|
75
|
-
value: import_zod.z.string().optional()
|
|
76
|
-
}).strict(),
|
|
77
|
-
import_zod.z.object({
|
|
78
|
-
type: import_zod.z.literal("cookie"),
|
|
79
|
-
key: import_zod.z.string(),
|
|
80
|
-
value: import_zod.z.string().optional()
|
|
81
|
-
}).strict(),
|
|
82
|
-
import_zod.z.object({
|
|
83
|
-
type: import_zod.z.literal("query"),
|
|
84
|
-
key: import_zod.z.string(),
|
|
85
|
-
value: import_zod.z.string().optional()
|
|
86
|
-
}).strict()
|
|
87
|
-
])
|
|
88
|
-
).optional();
|
|
89
|
-
var vercelOutputConfigSchema = import_zod.z.object({
|
|
90
|
-
version: import_zod.z.literal(3),
|
|
91
|
-
routes: import_zod.z.array(
|
|
92
|
-
import_zod.z.union([
|
|
93
|
-
import_zod.z.object({
|
|
94
|
-
src: import_zod.z.string(),
|
|
95
|
-
dest: import_zod.z.string().optional(),
|
|
96
|
-
headers: import_zod.z.record(import_zod.z.string()).optional(),
|
|
97
|
-
methods: import_zod.z.array(import_zod.z.string()).optional(),
|
|
98
|
-
status: import_zod.z.number().int().positive().optional(),
|
|
99
|
-
continue: import_zod.z.boolean().optional(),
|
|
100
|
-
check: import_zod.z.boolean().optional(),
|
|
101
|
-
missing: HasOrMissing,
|
|
102
|
-
has: HasOrMissing,
|
|
103
|
-
locale: import_zod.z.object({
|
|
104
|
-
redirect: import_zod.z.record(import_zod.z.string()).optional(),
|
|
105
|
-
cookie: import_zod.z.string().optional()
|
|
106
|
-
}).strict().optional(),
|
|
107
|
-
middlewarePath: import_zod.z.string().optional()
|
|
108
|
-
}).strict(),
|
|
109
|
-
import_zod.z.object({
|
|
110
|
-
handle: import_zod.z.union([
|
|
111
|
-
import_zod.z.literal("rewrite"),
|
|
112
|
-
import_zod.z.literal("filesystem"),
|
|
113
|
-
import_zod.z.literal("resource"),
|
|
114
|
-
import_zod.z.literal("miss"),
|
|
115
|
-
import_zod.z.literal("hit"),
|
|
116
|
-
import_zod.z.literal("error")
|
|
117
|
-
]),
|
|
118
|
-
src: import_zod.z.string().optional(),
|
|
119
|
-
dest: import_zod.z.string().optional(),
|
|
120
|
-
status: import_zod.z.number().optional()
|
|
121
|
-
}).strict()
|
|
122
|
-
])
|
|
123
|
-
).optional(),
|
|
124
|
-
images: import_zod.z.object({
|
|
125
|
-
sizes: import_zod.z.tuple([
|
|
126
|
-
import_zod.z.number().int().positive(),
|
|
127
|
-
import_zod.z.number().int().positive()
|
|
128
|
-
]),
|
|
129
|
-
domains: import_zod.z.array(import_zod.z.string()).nonempty().optional(),
|
|
130
|
-
minimumCacheTTL: import_zod.z.number().int().positive().optional(),
|
|
131
|
-
formats: import_zod.z.union([import_zod.z.literal("image/avif"), import_zod.z.literal("image/webp")]).array().nonempty().optional(),
|
|
132
|
-
dangerouslyAllowSVG: import_zod.z.boolean().optional(),
|
|
133
|
-
contentSecurityPolicy: import_zod.z.string().optional()
|
|
134
|
-
}).strict().optional(),
|
|
135
|
-
wildcard: import_zod.z.array(
|
|
136
|
-
import_zod.z.object({
|
|
137
|
-
domain: import_zod.z.string(),
|
|
138
|
-
value: import_zod.z.string()
|
|
139
|
-
}).strict()
|
|
140
|
-
).optional(),
|
|
141
|
-
overrides: import_zod.z.record(
|
|
142
|
-
import_zod.z.object({
|
|
143
|
-
path: import_zod.z.string().optional(),
|
|
144
|
-
contentType: import_zod.z.string().optional()
|
|
145
|
-
}).strict()
|
|
146
|
-
).optional(),
|
|
147
|
-
cache: import_zod.z.array(import_zod.z.string()).optional()
|
|
148
|
-
}).strict();
|
|
149
|
-
|
|
150
|
-
// src/config.ts
|
|
151
|
-
var import_promises = __toESM(require("fs/promises"), 1);
|
|
152
|
-
var import_routing_utils = require("@vercel/routing-utils");
|
|
153
|
-
function reorderEnforce(arr) {
|
|
154
|
-
return [
|
|
155
|
-
...arr.filter((r) => r.enforce === "pre"),
|
|
156
|
-
...arr.filter((r) => !r.enforce),
|
|
157
|
-
...arr.filter((r) => r.enforce === "post")
|
|
158
|
-
];
|
|
159
|
-
}
|
|
160
|
-
function getConfig(resolvedConfig, rewrites, overrides, headers) {
|
|
161
|
-
const _rewrites = [
|
|
162
|
-
// User provided config always comes first
|
|
163
|
-
...resolvedConfig.vercel?.rewrites ?? [],
|
|
164
|
-
...rewrites ?? []
|
|
165
|
-
];
|
|
166
|
-
const { routes, error } = (0, import_routing_utils.getTransformedRoutes)({
|
|
167
|
-
cleanUrls: resolvedConfig.vercel?.cleanUrls ?? true,
|
|
168
|
-
trailingSlash: resolvedConfig.vercel?.trailingSlash,
|
|
169
|
-
rewrites: reorderEnforce(_rewrites),
|
|
170
|
-
redirects: resolvedConfig.vercel?.redirects ? reorderEnforce(resolvedConfig.vercel?.redirects) : void 0,
|
|
171
|
-
headers
|
|
172
|
-
});
|
|
173
|
-
if (error) {
|
|
174
|
-
throw error;
|
|
175
|
-
}
|
|
176
|
-
if (resolvedConfig.vercel?.config?.routes && resolvedConfig.vercel.config.routes.length > 0 && !resolvedConfig.vercel.config.routes.every(
|
|
177
|
-
(r) => "continue" in r && r.continue
|
|
178
|
-
)) {
|
|
179
|
-
console.warn(
|
|
180
|
-
'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 `vercel.config.routes` to override routes. Prefer using `vercel.rewrites` and `vercel.redirects`.'
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
let userRoutes = [];
|
|
184
|
-
let buildRoutes = [];
|
|
185
|
-
if (resolvedConfig.vercel?.config?.routes) {
|
|
186
|
-
const norm = (0, import_routing_utils.normalizeRoutes)(resolvedConfig.vercel.config.routes);
|
|
187
|
-
if (norm.error) {
|
|
188
|
-
throw norm.error;
|
|
189
|
-
}
|
|
190
|
-
userRoutes = norm.routes ?? [];
|
|
191
|
-
}
|
|
192
|
-
if (routes) {
|
|
193
|
-
const norm = (0, import_routing_utils.normalizeRoutes)(routes);
|
|
194
|
-
if (norm.error) {
|
|
195
|
-
throw norm.error;
|
|
196
|
-
}
|
|
197
|
-
buildRoutes = norm.routes ?? [];
|
|
198
|
-
}
|
|
199
|
-
const cleanRoutes = (0, import_routing_utils.mergeRoutes)({
|
|
200
|
-
userRoutes,
|
|
201
|
-
builds: [
|
|
202
|
-
{
|
|
203
|
-
use: "@vercel/node",
|
|
204
|
-
entrypoint: "index.js",
|
|
205
|
-
routes: buildRoutes
|
|
206
|
-
}
|
|
207
|
-
]
|
|
208
|
-
});
|
|
209
|
-
return vercelOutputConfigSchema.parse({
|
|
210
|
-
version: 3,
|
|
211
|
-
...resolvedConfig.vercel?.config,
|
|
212
|
-
routes: cleanRoutes,
|
|
213
|
-
overrides: {
|
|
214
|
-
...resolvedConfig.vercel?.config?.overrides,
|
|
215
|
-
...overrides
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
function getConfigDestination(resolvedConfig) {
|
|
220
|
-
return import_path2.default.join(getOutput(resolvedConfig), "config.json");
|
|
221
|
-
}
|
|
222
|
-
async function writeConfig(resolvedConfig, rewrites, overrides, headers) {
|
|
223
|
-
await import_promises.default.writeFile(
|
|
224
|
-
getConfigDestination(resolvedConfig),
|
|
225
|
-
JSON.stringify(
|
|
226
|
-
getConfig(resolvedConfig, rewrites, overrides, headers),
|
|
227
|
-
void 0,
|
|
228
|
-
2
|
|
229
|
-
),
|
|
230
|
-
"utf-8"
|
|
231
|
-
);
|
|
232
|
-
}
|
|
37
|
+
var import_node_path6 = __toESM(require("path"), 1);
|
|
233
38
|
|
|
234
39
|
// src/build.ts
|
|
235
|
-
var
|
|
236
|
-
var
|
|
237
|
-
var
|
|
40
|
+
var import_promises = __toESM(require("fs/promises"), 1);
|
|
41
|
+
var import_node_module = require("module");
|
|
42
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
43
|
+
var import_find_root = require("@manypkg/find-root");
|
|
44
|
+
var import_build_utils = require("@vercel/build-utils");
|
|
45
|
+
var import_nft = require("@vercel/nft");
|
|
238
46
|
var import_esbuild = require("esbuild");
|
|
47
|
+
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
48
|
+
var import_magicast = require("magicast");
|
|
239
49
|
|
|
240
50
|
// src/assert.ts
|
|
241
51
|
var import_libassert = require("@brillout/libassert");
|
|
@@ -249,83 +59,111 @@ function assert(condition, errorMessage) {
|
|
|
249
59
|
}
|
|
250
60
|
|
|
251
61
|
// src/schemas/config/vc-config.ts
|
|
252
|
-
var
|
|
253
|
-
var vercelOutputEdgeVcConfigSchema =
|
|
254
|
-
runtime:
|
|
255
|
-
entrypoint:
|
|
256
|
-
envVarsInUse:
|
|
62
|
+
var import_zod = require("zod");
|
|
63
|
+
var vercelOutputEdgeVcConfigSchema = import_zod.z.object({
|
|
64
|
+
runtime: import_zod.z.literal("edge"),
|
|
65
|
+
entrypoint: import_zod.z.string(),
|
|
66
|
+
envVarsInUse: import_zod.z.array(import_zod.z.string()).optional()
|
|
257
67
|
}).strict();
|
|
258
|
-
var vercelOutputServerlessVcConfigSchema =
|
|
259
|
-
runtime:
|
|
260
|
-
handler:
|
|
261
|
-
memory:
|
|
262
|
-
maxDuration:
|
|
263
|
-
environment:
|
|
264
|
-
regions:
|
|
265
|
-
supportsWrapper:
|
|
266
|
-
supportsResponseStreaming:
|
|
68
|
+
var vercelOutputServerlessVcConfigSchema = import_zod.z.object({
|
|
69
|
+
runtime: import_zod.z.string(),
|
|
70
|
+
handler: import_zod.z.string(),
|
|
71
|
+
memory: import_zod.z.number().int().min(128).max(3008).optional(),
|
|
72
|
+
maxDuration: import_zod.z.number().int().positive().optional(),
|
|
73
|
+
environment: import_zod.z.record(import_zod.z.string()).optional(),
|
|
74
|
+
regions: import_zod.z.array(import_zod.z.string()).optional(),
|
|
75
|
+
supportsWrapper: import_zod.z.boolean().optional(),
|
|
76
|
+
supportsResponseStreaming: import_zod.z.boolean().optional()
|
|
267
77
|
}).strict();
|
|
268
78
|
var vercelOutputServerlessNodeVcConfigSchema = vercelOutputServerlessVcConfigSchema.extend({
|
|
269
|
-
launcherType:
|
|
270
|
-
shouldAddHelpers:
|
|
271
|
-
shouldAddSourcemapSupport:
|
|
272
|
-
awsLambdaHandler:
|
|
79
|
+
launcherType: import_zod.z.literal("Nodejs"),
|
|
80
|
+
shouldAddHelpers: import_zod.z.boolean().optional(),
|
|
81
|
+
shouldAddSourcemapSupport: import_zod.z.boolean().optional(),
|
|
82
|
+
awsLambdaHandler: import_zod.z.string().optional()
|
|
273
83
|
}).strict();
|
|
274
|
-
var vercelOutputVcConfigSchema =
|
|
84
|
+
var vercelOutputVcConfigSchema = import_zod.z.union([
|
|
275
85
|
vercelOutputEdgeVcConfigSchema,
|
|
276
86
|
vercelOutputServerlessVcConfigSchema,
|
|
277
87
|
vercelOutputServerlessNodeVcConfigSchema
|
|
278
88
|
]);
|
|
279
89
|
|
|
280
|
-
// src/build.ts
|
|
281
|
-
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
282
|
-
|
|
283
90
|
// src/schemas/exports.ts
|
|
284
|
-
var
|
|
285
|
-
var vercelEndpointExports =
|
|
286
|
-
edge:
|
|
287
|
-
headers:
|
|
288
|
-
streaming:
|
|
289
|
-
isr:
|
|
290
|
-
expiration:
|
|
91
|
+
var import_zod2 = require("zod");
|
|
92
|
+
var vercelEndpointExports = import_zod2.z.object({
|
|
93
|
+
edge: import_zod2.z.boolean().optional(),
|
|
94
|
+
headers: import_zod2.z.record(import_zod2.z.string()).optional(),
|
|
95
|
+
streaming: import_zod2.z.boolean().optional(),
|
|
96
|
+
isr: import_zod2.z.object({
|
|
97
|
+
expiration: import_zod2.z.number().or(import_zod2.z.literal(false))
|
|
291
98
|
}).optional()
|
|
292
99
|
});
|
|
293
100
|
|
|
101
|
+
// src/utils.ts
|
|
102
|
+
var import_vite = require("vite");
|
|
103
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
104
|
+
function getRoot(config) {
|
|
105
|
+
return (0, import_vite.normalizePath)(config.root || process.cwd());
|
|
106
|
+
}
|
|
107
|
+
function getOutput(config, suffix) {
|
|
108
|
+
return import_node_path.default.join(
|
|
109
|
+
config.vercel?.outDir ? "" : getRoot(config),
|
|
110
|
+
config.vercel?.outDir ?? ".vercel/output",
|
|
111
|
+
suffix ?? ""
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
function getPublic(config) {
|
|
115
|
+
return import_node_path.default.join(getRoot(config), config.publicDir || "public");
|
|
116
|
+
}
|
|
117
|
+
function pathRelativeTo(filePath, config, rel) {
|
|
118
|
+
const root = getRoot(config);
|
|
119
|
+
return (0, import_vite.normalizePath)(import_node_path.default.relative((0, import_vite.normalizePath)(import_node_path.default.join(root, rel)), filePath));
|
|
120
|
+
}
|
|
121
|
+
|
|
294
122
|
// src/build.ts
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
123
|
+
async function getAdditionalEndpoints(resolvedConfig) {
|
|
124
|
+
const userEndpoints = [];
|
|
125
|
+
if (Array.isArray(resolvedConfig.vercel?.additionalEndpoints)) {
|
|
126
|
+
for (const endpoint of resolvedConfig.vercel.additionalEndpoints) {
|
|
127
|
+
if (typeof endpoint === "function") {
|
|
128
|
+
const res = await endpoint();
|
|
129
|
+
if (Array.isArray(res)) {
|
|
130
|
+
userEndpoints.push(...res);
|
|
131
|
+
} else {
|
|
132
|
+
userEndpoints.push(res);
|
|
133
|
+
}
|
|
134
|
+
} else {
|
|
135
|
+
userEndpoints.push(endpoint);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return userEndpoints.map((e) => ({
|
|
301
140
|
...e,
|
|
302
|
-
|
|
141
|
+
route: e.route ?? true,
|
|
303
142
|
// path.resolve removes the trailing slash if any
|
|
304
|
-
destination:
|
|
143
|
+
destination: `${import_node_path2.default.posix.resolve("/", e.destination)}.func`
|
|
305
144
|
}));
|
|
306
145
|
}
|
|
307
|
-
function getEntries(resolvedConfig) {
|
|
308
|
-
const apiEntries = import_fast_glob.default.sync(`${getRoot(resolvedConfig)}/api/**/*.*([a-zA-Z0-9])`).filter((filepath) => !
|
|
146
|
+
async function getEntries(resolvedConfig) {
|
|
147
|
+
const apiEntries = import_fast_glob.default.sync(`${getRoot(resolvedConfig)}/api/**/*.*([a-zA-Z0-9])`).filter((filepath) => !import_node_path2.default.basename(filepath).startsWith("_"));
|
|
309
148
|
if (apiEntries.length > 0) {
|
|
310
149
|
console.warn(
|
|
311
150
|
"@vercel/build is currently force building /api files itself, with no way to disable it. In order to avoid double compilation, you should temporarily rename /api to /_api while using this plugin. /_api functions are compiled under .vercel/output/functions/api/*.func as if they were in /api."
|
|
312
151
|
);
|
|
313
152
|
}
|
|
314
|
-
const otherApiEntries = import_fast_glob.default.sync(`${getRoot(resolvedConfig)}/_api/**/*.*([a-zA-Z0-9])`).filter((filepath) => !
|
|
315
|
-
return [...apiEntries, ...otherApiEntries].reduce(
|
|
316
|
-
|
|
317
|
-
filePath,
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
}, getAdditionalEndpoints(resolvedConfig));
|
|
153
|
+
const otherApiEntries = import_fast_glob.default.sync(`${getRoot(resolvedConfig)}/_api/**/*.*([a-zA-Z0-9])`).filter((filepath) => !import_node_path2.default.basename(filepath).startsWith("_"));
|
|
154
|
+
return [...apiEntries, ...otherApiEntries].reduce(
|
|
155
|
+
(entryPoints, filePath) => {
|
|
156
|
+
const outFilePath = pathRelativeTo(filePath, resolvedConfig, filePath.includes("/_api/") ? "_api" : "api");
|
|
157
|
+
const parsed = import_node_path2.default.posix.parse(outFilePath);
|
|
158
|
+
entryPoints.push({
|
|
159
|
+
source: filePath,
|
|
160
|
+
destination: `api/${import_node_path2.default.posix.join(parsed.dir, parsed.name)}.func`,
|
|
161
|
+
route: true
|
|
162
|
+
});
|
|
163
|
+
return entryPoints;
|
|
164
|
+
},
|
|
165
|
+
await getAdditionalEndpoints(resolvedConfig)
|
|
166
|
+
);
|
|
329
167
|
}
|
|
330
168
|
var edgeWasmPlugin = {
|
|
331
169
|
name: "edge-wasm-vercel",
|
|
@@ -380,38 +218,21 @@ async function buildFn(resolvedConfig, entry, buildOptions) {
|
|
|
380
218
|
Object.assign(options, buildOptions);
|
|
381
219
|
}
|
|
382
220
|
const filename = entry.edge || options.format === "cjs" ? "index.js" : "index.mjs";
|
|
383
|
-
const outfile =
|
|
384
|
-
getOutput(resolvedConfig, "functions"),
|
|
385
|
-
entry.destination,
|
|
386
|
-
filename
|
|
387
|
-
);
|
|
221
|
+
const outfile = import_node_path2.default.join(getOutput(resolvedConfig, "functions"), entry.destination, filename);
|
|
388
222
|
Object.assign(options, { outfile });
|
|
389
223
|
if (!options.stdin) {
|
|
390
224
|
if (typeof entry.source === "string") {
|
|
391
225
|
options.entryPoints = [entry.source];
|
|
392
226
|
} else {
|
|
393
|
-
assert(
|
|
394
|
-
|
|
395
|
-
`\`{ source }\` must be a string or an object`
|
|
396
|
-
);
|
|
397
|
-
assert(
|
|
398
|
-
typeof entry.source.contents === "string",
|
|
399
|
-
`\`{ contents }\` must be a string`
|
|
400
|
-
);
|
|
227
|
+
assert(typeof entry.source === "object", "`{ source }` must be a string or an object");
|
|
228
|
+
assert(typeof entry.source.contents === "string", "`{ contents }` must be a string");
|
|
401
229
|
options.stdin = entry.source;
|
|
402
230
|
}
|
|
403
231
|
}
|
|
404
232
|
if (entry.edge) {
|
|
405
|
-
|
|
406
|
-
options.external = [...
|
|
407
|
-
options.conditions = [
|
|
408
|
-
"edge-light",
|
|
409
|
-
"worker",
|
|
410
|
-
"browser",
|
|
411
|
-
"module",
|
|
412
|
-
"import",
|
|
413
|
-
"require"
|
|
414
|
-
];
|
|
233
|
+
options.platform = void 0;
|
|
234
|
+
options.external = [...import_node_module.builtinModules, ...import_node_module.builtinModules.map((m) => `node:${m}`)];
|
|
235
|
+
options.conditions = ["edge-light", "worker", "browser", "module", "import", "require"];
|
|
415
236
|
options.plugins?.push(edgeWasmPlugin);
|
|
416
237
|
options.format = "esm";
|
|
417
238
|
} else if (options.format === "esm") {
|
|
@@ -426,9 +247,9 @@ const __dirname = VPV_dirname(__filename);
|
|
|
426
247
|
};
|
|
427
248
|
}
|
|
428
249
|
const ctx = { found: false, index: "" };
|
|
429
|
-
options.plugins
|
|
250
|
+
options.plugins?.push(vercelOgPlugin(ctx));
|
|
430
251
|
const output = await (0, import_esbuild.build)(options);
|
|
431
|
-
if (typeof entry.source
|
|
252
|
+
if (typeof entry.source === "string") {
|
|
432
253
|
let base = resolvedConfig.root;
|
|
433
254
|
try {
|
|
434
255
|
const dir = await (0, import_find_root.findRoot)(resolvedConfig.root);
|
|
@@ -455,18 +276,14 @@ const __dirname = VPV_dirname(__filename);
|
|
|
455
276
|
});
|
|
456
277
|
return result.outputFiles[0].text;
|
|
457
278
|
}
|
|
458
|
-
return
|
|
279
|
+
return import_promises.default.readFile(filepath, "utf-8");
|
|
459
280
|
}
|
|
460
281
|
});
|
|
461
282
|
for (const file of fileList) {
|
|
462
|
-
if (reasons.has(file) && reasons.get(file)
|
|
463
|
-
await (0,
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
getOutput(resolvedConfig, "functions"),
|
|
467
|
-
entry.destination,
|
|
468
|
-
(0, import_path3.basename)(file)
|
|
469
|
-
)
|
|
283
|
+
if (reasons.has(file) && reasons.get(file)?.type.includes("asset") && !file.endsWith(".js") && !file.endsWith(".cjs") && !file.endsWith(".mjs") && !file.endsWith("package.json")) {
|
|
284
|
+
await (0, import_promises.copyFile)(
|
|
285
|
+
import_node_path2.default.join(base, file),
|
|
286
|
+
import_node_path2.default.join(getOutput(resolvedConfig, "functions"), entry.destination, (0, import_node_path2.basename)(file))
|
|
470
287
|
);
|
|
471
288
|
}
|
|
472
289
|
}
|
|
@@ -478,13 +295,9 @@ const __dirname = VPV_dirname(__filename);
|
|
|
478
295
|
return output;
|
|
479
296
|
}
|
|
480
297
|
async function writeVcConfig(resolvedConfig, destination, filename, options) {
|
|
481
|
-
const vcConfig =
|
|
482
|
-
getOutput(resolvedConfig, "functions"),
|
|
483
|
-
destination,
|
|
484
|
-
".vc-config.json"
|
|
485
|
-
);
|
|
298
|
+
const vcConfig = import_node_path2.default.join(getOutput(resolvedConfig, "functions"), destination, ".vc-config.json");
|
|
486
299
|
const nodeVersion = await (0, import_build_utils.getNodeVersion)(getOutput(resolvedConfig));
|
|
487
|
-
await
|
|
300
|
+
await import_promises.default.writeFile(
|
|
488
301
|
vcConfig,
|
|
489
302
|
JSON.stringify(
|
|
490
303
|
vercelOutputVcConfigSchema.parse(
|
|
@@ -508,9 +321,9 @@ async function writeVcConfig(resolvedConfig, destination, filename, options) {
|
|
|
508
321
|
}
|
|
509
322
|
function getSourceAndDestination(destination) {
|
|
510
323
|
if (destination.startsWith("api/")) {
|
|
511
|
-
return
|
|
324
|
+
return import_node_path2.default.posix.resolve("/", destination);
|
|
512
325
|
}
|
|
513
|
-
return
|
|
326
|
+
return import_node_path2.default.posix.resolve("/", destination, ":match*");
|
|
514
327
|
}
|
|
515
328
|
var RE_BRACKETS = /^\[([^/]+)\]$/gm;
|
|
516
329
|
function replaceBrackets(source) {
|
|
@@ -543,7 +356,7 @@ async function extractExports(filepath) {
|
|
|
543
356
|
}
|
|
544
357
|
}
|
|
545
358
|
async function buildEndpoints(resolvedConfig) {
|
|
546
|
-
const entries = getEntries(resolvedConfig);
|
|
359
|
+
const entries = await getEntries(resolvedConfig);
|
|
547
360
|
for (const entry of entries) {
|
|
548
361
|
if (typeof entry.source === "string") {
|
|
549
362
|
const exports2 = await extractExports(entry.source);
|
|
@@ -567,6 +380,9 @@ async function buildEndpoints(resolvedConfig) {
|
|
|
567
380
|
`isr configuration should be defined either in the endpoint itself or through Vite config, not both ('${entry.source}')`
|
|
568
381
|
);
|
|
569
382
|
}
|
|
383
|
+
if ((entry.isr !== void 0 || exports2.isr !== void 0) && (entry.edge !== void 0 || exports2.edge !== void 0)) {
|
|
384
|
+
throw new Error(`isr cannot be enabled for edge functions ('${entry.source}')`);
|
|
385
|
+
}
|
|
570
386
|
if (exports2.isr) {
|
|
571
387
|
entry.isr = exports2.isr;
|
|
572
388
|
}
|
|
@@ -577,21 +393,36 @@ async function buildEndpoints(resolvedConfig) {
|
|
|
577
393
|
}
|
|
578
394
|
await buildFn(resolvedConfig, entry);
|
|
579
395
|
}
|
|
580
|
-
const isrEntries = entries.filter((e) => e.isr).map(
|
|
581
|
-
(e) => [
|
|
582
|
-
e.destination.replace(/\.func$/, ""),
|
|
583
|
-
{ expiration: e.isr.expiration }
|
|
584
|
-
]
|
|
585
|
-
);
|
|
396
|
+
const isrEntries = entries.filter((e) => e.isr).map((e) => [e.destination.replace(/\.func$/, ""), { expiration: e.isr?.expiration }]);
|
|
586
397
|
return {
|
|
587
|
-
rewrites: entries.filter((e) =>
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
398
|
+
rewrites: entries.filter((e) => {
|
|
399
|
+
if (e.addRoute === void 0 && e.route !== void 0) {
|
|
400
|
+
return e.route !== false;
|
|
401
|
+
}
|
|
402
|
+
if (e.addRoute !== void 0 && e.route === void 0) {
|
|
403
|
+
return e.addRoute !== false;
|
|
404
|
+
}
|
|
405
|
+
if (e.addRoute !== void 0 && e.route !== void 0) {
|
|
406
|
+
throw new Error("Cannot use both `route` and `addRoute` in `additionalEndpoints`");
|
|
407
|
+
}
|
|
408
|
+
return true;
|
|
409
|
+
}).map((e) => {
|
|
410
|
+
const destination = e.destination.replace(/\.func$/, "");
|
|
411
|
+
if (typeof e.route === "string") {
|
|
412
|
+
return {
|
|
413
|
+
source: `(${e.route})`,
|
|
414
|
+
destination: `${destination}/?__original_path=$1`
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
return {
|
|
418
|
+
source: replaceBrackets(getSourceAndDestination(destination)),
|
|
419
|
+
destination: getSourceAndDestination(destination)
|
|
420
|
+
};
|
|
421
|
+
}),
|
|
591
422
|
isr: Object.fromEntries(isrEntries),
|
|
592
423
|
headers: entries.filter((e) => e.headers).map((e) => ({
|
|
593
|
-
source:
|
|
594
|
-
headers: Object.entries(e.headers).map(([key, value]) => ({
|
|
424
|
+
source: `/${e.destination.replace(/\.func$/, "")}`,
|
|
425
|
+
headers: Object.entries(e.headers ?? {}).map(([key, value]) => ({
|
|
595
426
|
key,
|
|
596
427
|
value
|
|
597
428
|
}))
|
|
@@ -599,36 +430,198 @@ async function buildEndpoints(resolvedConfig) {
|
|
|
599
430
|
};
|
|
600
431
|
}
|
|
601
432
|
|
|
602
|
-
// src/
|
|
603
|
-
var
|
|
433
|
+
// src/config.ts
|
|
434
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
604
435
|
|
|
605
|
-
// src/schemas/config/
|
|
606
|
-
var
|
|
607
|
-
var
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
436
|
+
// src/schemas/config/config.ts
|
|
437
|
+
var import_zod3 = require("zod");
|
|
438
|
+
var HasOrMissing = import_zod3.z.array(
|
|
439
|
+
import_zod3.z.union([
|
|
440
|
+
import_zod3.z.object({
|
|
441
|
+
type: import_zod3.z.literal("host"),
|
|
442
|
+
value: import_zod3.z.string()
|
|
443
|
+
}).strict(),
|
|
444
|
+
import_zod3.z.object({
|
|
445
|
+
type: import_zod3.z.literal("header"),
|
|
446
|
+
key: import_zod3.z.string(),
|
|
447
|
+
value: import_zod3.z.string().optional()
|
|
448
|
+
}).strict(),
|
|
449
|
+
import_zod3.z.object({
|
|
450
|
+
type: import_zod3.z.literal("cookie"),
|
|
451
|
+
key: import_zod3.z.string(),
|
|
452
|
+
value: import_zod3.z.string().optional()
|
|
453
|
+
}).strict(),
|
|
454
|
+
import_zod3.z.object({
|
|
455
|
+
type: import_zod3.z.literal("query"),
|
|
456
|
+
key: import_zod3.z.string(),
|
|
457
|
+
value: import_zod3.z.string().optional()
|
|
458
|
+
}).strict()
|
|
459
|
+
])
|
|
460
|
+
).optional();
|
|
461
|
+
var vercelOutputConfigSchema = import_zod3.z.object({
|
|
462
|
+
version: import_zod3.z.literal(3),
|
|
463
|
+
routes: import_zod3.z.array(
|
|
464
|
+
import_zod3.z.union([
|
|
465
|
+
import_zod3.z.object({
|
|
466
|
+
src: import_zod3.z.string(),
|
|
467
|
+
dest: import_zod3.z.string().optional(),
|
|
468
|
+
headers: import_zod3.z.record(import_zod3.z.string()).optional(),
|
|
469
|
+
methods: import_zod3.z.array(import_zod3.z.string()).optional(),
|
|
470
|
+
status: import_zod3.z.number().int().positive().optional(),
|
|
471
|
+
continue: import_zod3.z.boolean().optional(),
|
|
472
|
+
check: import_zod3.z.boolean().optional(),
|
|
473
|
+
missing: HasOrMissing,
|
|
474
|
+
has: HasOrMissing,
|
|
475
|
+
locale: import_zod3.z.object({
|
|
476
|
+
redirect: import_zod3.z.record(import_zod3.z.string()).optional(),
|
|
477
|
+
cookie: import_zod3.z.string().optional()
|
|
478
|
+
}).strict().optional(),
|
|
479
|
+
middlewarePath: import_zod3.z.string().optional()
|
|
480
|
+
}).strict(),
|
|
481
|
+
import_zod3.z.object({
|
|
482
|
+
handle: import_zod3.z.union([
|
|
483
|
+
import_zod3.z.literal("rewrite"),
|
|
484
|
+
import_zod3.z.literal("filesystem"),
|
|
485
|
+
import_zod3.z.literal("resource"),
|
|
486
|
+
import_zod3.z.literal("miss"),
|
|
487
|
+
import_zod3.z.literal("hit"),
|
|
488
|
+
import_zod3.z.literal("error")
|
|
489
|
+
]),
|
|
490
|
+
src: import_zod3.z.string().optional(),
|
|
491
|
+
dest: import_zod3.z.string().optional(),
|
|
492
|
+
status: import_zod3.z.number().optional()
|
|
493
|
+
}).strict()
|
|
494
|
+
])
|
|
495
|
+
).optional(),
|
|
496
|
+
images: import_zod3.z.object({
|
|
497
|
+
sizes: import_zod3.z.tuple([import_zod3.z.number().int().positive(), import_zod3.z.number().int().positive()]),
|
|
498
|
+
domains: import_zod3.z.array(import_zod3.z.string()).nonempty().optional(),
|
|
499
|
+
minimumCacheTTL: import_zod3.z.number().int().positive().optional(),
|
|
500
|
+
formats: import_zod3.z.union([import_zod3.z.literal("image/avif"), import_zod3.z.literal("image/webp")]).array().nonempty().optional(),
|
|
501
|
+
dangerouslyAllowSVG: import_zod3.z.boolean().optional(),
|
|
502
|
+
contentSecurityPolicy: import_zod3.z.string().optional()
|
|
503
|
+
}).strict().optional(),
|
|
504
|
+
wildcard: import_zod3.z.array(
|
|
505
|
+
import_zod3.z.object({
|
|
506
|
+
domain: import_zod3.z.string(),
|
|
507
|
+
value: import_zod3.z.string()
|
|
508
|
+
}).strict()
|
|
509
|
+
).optional(),
|
|
510
|
+
overrides: import_zod3.z.record(
|
|
511
|
+
import_zod3.z.object({
|
|
512
|
+
path: import_zod3.z.string().optional(),
|
|
513
|
+
contentType: import_zod3.z.string().optional()
|
|
514
|
+
}).strict()
|
|
515
|
+
).optional(),
|
|
516
|
+
cache: import_zod3.z.array(import_zod3.z.string()).optional()
|
|
613
517
|
}).strict();
|
|
614
518
|
|
|
615
|
-
// src/
|
|
616
|
-
var
|
|
519
|
+
// src/config.ts
|
|
520
|
+
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
521
|
+
var import_routing_utils = require("@vercel/routing-utils");
|
|
522
|
+
function reorderEnforce(arr) {
|
|
523
|
+
return [
|
|
524
|
+
...arr.filter((r) => r.enforce === "pre"),
|
|
525
|
+
...arr.filter((r) => !r.enforce),
|
|
526
|
+
...arr.filter((r) => r.enforce === "post")
|
|
527
|
+
];
|
|
528
|
+
}
|
|
529
|
+
function getConfig(resolvedConfig, rewrites, overrides, headers) {
|
|
530
|
+
const _rewrites = [
|
|
531
|
+
// User provided config always comes first
|
|
532
|
+
...resolvedConfig.vercel?.rewrites ?? [],
|
|
533
|
+
...rewrites ?? []
|
|
534
|
+
];
|
|
535
|
+
const { routes, error } = (0, import_routing_utils.getTransformedRoutes)({
|
|
536
|
+
cleanUrls: resolvedConfig.vercel?.cleanUrls ?? true,
|
|
537
|
+
trailingSlash: resolvedConfig.vercel?.trailingSlash,
|
|
538
|
+
rewrites: reorderEnforce(_rewrites),
|
|
539
|
+
redirects: resolvedConfig.vercel?.redirects ? reorderEnforce(resolvedConfig.vercel?.redirects) : void 0,
|
|
540
|
+
headers
|
|
541
|
+
});
|
|
542
|
+
if (error) {
|
|
543
|
+
throw error;
|
|
544
|
+
}
|
|
545
|
+
if (resolvedConfig.vercel?.config?.routes && resolvedConfig.vercel.config.routes.length > 0 && !resolvedConfig.vercel.config.routes.every((r) => "continue" in r && r.continue)) {
|
|
546
|
+
console.warn(
|
|
547
|
+
'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 `vercel.config.routes` to override routes. Prefer using `vercel.rewrites` and `vercel.redirects`.'
|
|
548
|
+
);
|
|
549
|
+
}
|
|
550
|
+
let userRoutes = [];
|
|
551
|
+
let buildRoutes = [];
|
|
552
|
+
if (resolvedConfig.vercel?.config?.routes) {
|
|
553
|
+
const norm = (0, import_routing_utils.normalizeRoutes)(resolvedConfig.vercel.config.routes);
|
|
554
|
+
if (norm.error) {
|
|
555
|
+
throw norm.error;
|
|
556
|
+
}
|
|
557
|
+
userRoutes = norm.routes ?? [];
|
|
558
|
+
}
|
|
559
|
+
if (routes) {
|
|
560
|
+
const norm = (0, import_routing_utils.normalizeRoutes)(routes);
|
|
561
|
+
if (norm.error) {
|
|
562
|
+
throw norm.error;
|
|
563
|
+
}
|
|
564
|
+
buildRoutes = norm.routes ?? [];
|
|
565
|
+
}
|
|
566
|
+
const cleanRoutes = (0, import_routing_utils.mergeRoutes)({
|
|
567
|
+
userRoutes,
|
|
568
|
+
builds: [
|
|
569
|
+
{
|
|
570
|
+
use: "@vercel/node",
|
|
571
|
+
entrypoint: "index.js",
|
|
572
|
+
routes: buildRoutes
|
|
573
|
+
}
|
|
574
|
+
]
|
|
575
|
+
});
|
|
576
|
+
return vercelOutputConfigSchema.parse({
|
|
577
|
+
version: 3,
|
|
578
|
+
...resolvedConfig.vercel?.config,
|
|
579
|
+
routes: cleanRoutes,
|
|
580
|
+
overrides: {
|
|
581
|
+
...resolvedConfig.vercel?.config?.overrides,
|
|
582
|
+
...overrides
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
function getConfigDestination(resolvedConfig) {
|
|
587
|
+
return import_node_path3.default.join(getOutput(resolvedConfig), "config.json");
|
|
588
|
+
}
|
|
589
|
+
async function writeConfig(resolvedConfig, rewrites, overrides, headers) {
|
|
590
|
+
await import_promises2.default.writeFile(
|
|
591
|
+
getConfigDestination(resolvedConfig),
|
|
592
|
+
JSON.stringify(getConfig(resolvedConfig, rewrites, overrides, headers), void 0, 2),
|
|
593
|
+
"utf-8"
|
|
594
|
+
);
|
|
595
|
+
}
|
|
617
596
|
|
|
618
597
|
// src/helpers.ts
|
|
619
598
|
var import_promises3 = __toESM(require("fs/promises"), 1);
|
|
620
|
-
var
|
|
599
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
621
600
|
async function copyDir(src, dest) {
|
|
622
601
|
await import_promises3.default.mkdir(dest, { recursive: true });
|
|
623
602
|
const entries = await import_promises3.default.readdir(src, { withFileTypes: true });
|
|
624
603
|
for (const entry of entries) {
|
|
625
|
-
const srcPath =
|
|
626
|
-
const destPath =
|
|
604
|
+
const srcPath = import_node_path4.default.join(src, entry.name);
|
|
605
|
+
const destPath = import_node_path4.default.join(dest, entry.name);
|
|
627
606
|
entry.isDirectory() ? await copyDir(srcPath, destPath) : await import_promises3.default.copyFile(srcPath, destPath);
|
|
628
607
|
}
|
|
629
608
|
}
|
|
630
609
|
|
|
631
610
|
// src/prerender.ts
|
|
611
|
+
var import_node_path5 = __toESM(require("path"), 1);
|
|
612
|
+
|
|
613
|
+
// src/schemas/config/prerender-config.ts
|
|
614
|
+
var import_zod4 = require("zod");
|
|
615
|
+
var vercelOutputPrerenderConfigSchema = import_zod4.z.object({
|
|
616
|
+
expiration: import_zod4.z.union([import_zod4.z.number().int().positive(), import_zod4.z.literal(false)]),
|
|
617
|
+
group: import_zod4.z.number().int().optional(),
|
|
618
|
+
bypassToken: import_zod4.z.string().optional(),
|
|
619
|
+
fallback: import_zod4.z.string().optional(),
|
|
620
|
+
allowQuery: import_zod4.z.array(import_zod4.z.string()).optional()
|
|
621
|
+
}).strict();
|
|
622
|
+
|
|
623
|
+
// src/prerender.ts
|
|
624
|
+
var import_promises4 = __toESM(require("fs/promises"), 1);
|
|
632
625
|
function execPrerender(resolvedConfig) {
|
|
633
626
|
const prerender = resolvedConfig.vercel?.prerender;
|
|
634
627
|
if (prerender === false) {
|
|
@@ -638,16 +631,9 @@ function execPrerender(resolvedConfig) {
|
|
|
638
631
|
}
|
|
639
632
|
var group = 1;
|
|
640
633
|
async function writePrerenderConfig(resolvedConfig, destination, isr) {
|
|
641
|
-
const parsed =
|
|
642
|
-
const outfile =
|
|
643
|
-
|
|
644
|
-
parsed.dir,
|
|
645
|
-
parsed.name + ".prerender-config.json"
|
|
646
|
-
);
|
|
647
|
-
await import_promises4.default.mkdir(
|
|
648
|
-
import_path5.default.join(getOutput(resolvedConfig, "functions"), parsed.dir),
|
|
649
|
-
{ recursive: true }
|
|
650
|
-
);
|
|
634
|
+
const parsed = import_node_path5.default.parse(destination);
|
|
635
|
+
const outfile = import_node_path5.default.join(getOutput(resolvedConfig, "functions"), parsed.dir, `${parsed.name}.prerender-config.json`);
|
|
636
|
+
await import_promises4.default.mkdir(import_node_path5.default.join(getOutput(resolvedConfig, "functions"), parsed.dir), { recursive: true });
|
|
651
637
|
await import_promises4.default.writeFile(
|
|
652
638
|
outfile,
|
|
653
639
|
JSON.stringify(
|
|
@@ -662,37 +648,21 @@ async function writePrerenderConfig(resolvedConfig, destination, isr) {
|
|
|
662
648
|
);
|
|
663
649
|
}
|
|
664
650
|
function getPrerenderSymlinkInfo(resolvedConfig, destination, target) {
|
|
665
|
-
const parsed =
|
|
666
|
-
const targetParsed =
|
|
651
|
+
const parsed = import_node_path5.default.parse(destination);
|
|
652
|
+
const targetParsed = import_node_path5.default.parse(target);
|
|
667
653
|
return {
|
|
668
|
-
target:
|
|
669
|
-
|
|
670
|
-
targetParsed.dir,
|
|
671
|
-
targetParsed.name + ".func"
|
|
672
|
-
),
|
|
673
|
-
link: import_path5.default.join(
|
|
674
|
-
getOutput(resolvedConfig, "functions"),
|
|
675
|
-
parsed.dir,
|
|
676
|
-
parsed.name + ".func"
|
|
677
|
-
)
|
|
654
|
+
target: import_node_path5.default.join(getOutput(resolvedConfig, "functions"), targetParsed.dir, `${targetParsed.name}.func`),
|
|
655
|
+
link: import_node_path5.default.join(getOutput(resolvedConfig, "functions"), parsed.dir, `${parsed.name}.func`)
|
|
678
656
|
};
|
|
679
657
|
}
|
|
680
658
|
async function buildPrerenderConfigs(resolvedConfig, extractedIsr) {
|
|
681
|
-
const isr = Object.assign(
|
|
682
|
-
{},
|
|
683
|
-
extractedIsr,
|
|
684
|
-
await getIsrConfig(resolvedConfig)
|
|
685
|
-
);
|
|
659
|
+
const isr = Object.assign({}, extractedIsr, await getIsrConfig(resolvedConfig));
|
|
686
660
|
const entries = Object.entries(isr);
|
|
687
661
|
const rewrites = [];
|
|
688
662
|
for (const [destination, { symlink, route, ...isr2 }] of entries) {
|
|
689
663
|
await writePrerenderConfig(resolvedConfig, destination, isr2);
|
|
690
664
|
if (symlink) {
|
|
691
|
-
const info = getPrerenderSymlinkInfo(
|
|
692
|
-
resolvedConfig,
|
|
693
|
-
destination,
|
|
694
|
-
symlink
|
|
695
|
-
);
|
|
665
|
+
const info = getPrerenderSymlinkInfo(resolvedConfig, destination, symlink);
|
|
696
666
|
await copyDir(info.target, info.link);
|
|
697
667
|
}
|
|
698
668
|
if (route) {
|
|
@@ -713,7 +683,6 @@ async function getIsrConfig(resolvedConfig) {
|
|
|
713
683
|
}
|
|
714
684
|
|
|
715
685
|
// src/index.ts
|
|
716
|
-
var import_path6 = __toESM(require("path"), 1);
|
|
717
686
|
function vercelPluginCleanup() {
|
|
718
687
|
let resolvedConfig;
|
|
719
688
|
return {
|
|
@@ -743,9 +712,7 @@ function vercelPlugin() {
|
|
|
743
712
|
enforce: "post",
|
|
744
713
|
configResolved(config) {
|
|
745
714
|
resolvedConfig = config;
|
|
746
|
-
vikeFound = resolvedConfig.plugins.some(
|
|
747
|
-
(p) => p.name.match("^vite-plugin-ssr:|^vike:")
|
|
748
|
-
);
|
|
715
|
+
vikeFound = resolvedConfig.plugins.some((p) => p.name.match("^vite-plugin-ssr:|^vike:"));
|
|
749
716
|
if (typeof resolvedConfig.vercel?.distContainsOnlyStatic === "undefined") {
|
|
750
717
|
resolvedConfig.vercel ??= {};
|
|
751
718
|
resolvedConfig.vercel.distContainsOnlyStatic = !vikeFound;
|
|
@@ -787,10 +754,7 @@ async function cleanOutputDirectory(resolvedConfig) {
|
|
|
787
754
|
}
|
|
788
755
|
async function copyDistToStatic(resolvedConfig) {
|
|
789
756
|
if (resolvedConfig.vercel?.distContainsOnlyStatic) {
|
|
790
|
-
await copyDir(
|
|
791
|
-
resolvedConfig.build.outDir,
|
|
792
|
-
getOutput(resolvedConfig, "static")
|
|
793
|
-
);
|
|
757
|
+
await copyDir(resolvedConfig.build.outDir, getOutput(resolvedConfig, "static"));
|
|
794
758
|
}
|
|
795
759
|
}
|
|
796
760
|
async function computeStaticHtmlOverrides(resolvedConfig) {
|
|
@@ -798,18 +762,19 @@ async function computeStaticHtmlOverrides(resolvedConfig) {
|
|
|
798
762
|
const files = await getStaticHtmlFiles(staticAbsolutePath);
|
|
799
763
|
const publicDir = getPublic(resolvedConfig);
|
|
800
764
|
const publicFiles = await getStaticHtmlFiles(publicDir);
|
|
801
|
-
files.push(
|
|
802
|
-
|
|
765
|
+
files.push(...publicFiles.map((f) => f.replace(publicDir, staticAbsolutePath)));
|
|
766
|
+
return files.reduce(
|
|
767
|
+
(acc, curr) => {
|
|
768
|
+
const relPath = import_node_path6.default.relative(staticAbsolutePath, curr);
|
|
769
|
+
const parsed = import_node_path6.default.parse(relPath);
|
|
770
|
+
const pathJoined = import_node_path6.default.join(parsed.dir, parsed.name);
|
|
771
|
+
acc[relPath] = {
|
|
772
|
+
path: pathJoined
|
|
773
|
+
};
|
|
774
|
+
return acc;
|
|
775
|
+
},
|
|
776
|
+
{}
|
|
803
777
|
);
|
|
804
|
-
return files.reduce((acc, curr) => {
|
|
805
|
-
const relPath = import_path6.default.relative(staticAbsolutePath, curr);
|
|
806
|
-
const parsed = import_path6.default.parse(relPath);
|
|
807
|
-
const pathJoined = import_path6.default.join(parsed.dir, parsed.name);
|
|
808
|
-
acc[relPath] = {
|
|
809
|
-
path: pathJoined
|
|
810
|
-
};
|
|
811
|
-
return acc;
|
|
812
|
-
}, {});
|
|
813
778
|
}
|
|
814
779
|
async function getStaticHtmlFiles(src) {
|
|
815
780
|
try {
|
|
@@ -820,7 +785,7 @@ async function getStaticHtmlFiles(src) {
|
|
|
820
785
|
const entries = await import_promises5.default.readdir(src, { withFileTypes: true });
|
|
821
786
|
const htmlFiles = [];
|
|
822
787
|
for (const entry of entries) {
|
|
823
|
-
const srcPath =
|
|
788
|
+
const srcPath = import_node_path6.default.join(src, entry.name);
|
|
824
789
|
entry.isDirectory() ? htmlFiles.push(...await getStaticHtmlFiles(srcPath)) : srcPath.endsWith(".html") ? htmlFiles.push(srcPath) : void 0;
|
|
825
790
|
}
|
|
826
791
|
return htmlFiles;
|
|
@@ -842,9 +807,5 @@ async function tryImportVpvv(options) {
|
|
|
842
807
|
}
|
|
843
808
|
function allPlugins(options = {}) {
|
|
844
809
|
const { smart, ...rest } = options;
|
|
845
|
-
return [
|
|
846
|
-
vercelPluginCleanup(),
|
|
847
|
-
vercelPlugin(),
|
|
848
|
-
smart !== false ? tryImportVpvv(rest) : null
|
|
849
|
-
];
|
|
810
|
+
return [vercelPluginCleanup(), vercelPlugin(), smart !== false ? tryImportVpvv(rest) : null];
|
|
850
811
|
}
|