vite-plugin-vercel 8.0.0 → 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 -376
- package/dist/index.d.cts +44 -38
- package/dist/index.d.ts +44 -38
- package/dist/index.js +340 -375
- package/index.d.ts +4 -4
- package/package.json +13 -16
package/dist/index.cjs
CHANGED
|
@@ -34,207 +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
|
|
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");
|
|
237
46
|
var import_esbuild = require("esbuild");
|
|
47
|
+
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
48
|
+
var import_magicast = require("magicast");
|
|
238
49
|
|
|
239
50
|
// src/assert.ts
|
|
240
51
|
var import_libassert = require("@brillout/libassert");
|
|
@@ -248,83 +59,111 @@ function assert(condition, errorMessage) {
|
|
|
248
59
|
}
|
|
249
60
|
|
|
250
61
|
// src/schemas/config/vc-config.ts
|
|
251
|
-
var
|
|
252
|
-
var vercelOutputEdgeVcConfigSchema =
|
|
253
|
-
runtime:
|
|
254
|
-
entrypoint:
|
|
255
|
-
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()
|
|
256
67
|
}).strict();
|
|
257
|
-
var vercelOutputServerlessVcConfigSchema =
|
|
258
|
-
runtime:
|
|
259
|
-
handler:
|
|
260
|
-
memory:
|
|
261
|
-
maxDuration:
|
|
262
|
-
environment:
|
|
263
|
-
regions:
|
|
264
|
-
supportsWrapper:
|
|
265
|
-
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()
|
|
266
77
|
}).strict();
|
|
267
78
|
var vercelOutputServerlessNodeVcConfigSchema = vercelOutputServerlessVcConfigSchema.extend({
|
|
268
|
-
launcherType:
|
|
269
|
-
shouldAddHelpers:
|
|
270
|
-
shouldAddSourcemapSupport:
|
|
271
|
-
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()
|
|
272
83
|
}).strict();
|
|
273
|
-
var vercelOutputVcConfigSchema =
|
|
84
|
+
var vercelOutputVcConfigSchema = import_zod.z.union([
|
|
274
85
|
vercelOutputEdgeVcConfigSchema,
|
|
275
86
|
vercelOutputServerlessVcConfigSchema,
|
|
276
87
|
vercelOutputServerlessNodeVcConfigSchema
|
|
277
88
|
]);
|
|
278
89
|
|
|
279
|
-
// src/build.ts
|
|
280
|
-
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
281
|
-
|
|
282
90
|
// src/schemas/exports.ts
|
|
283
|
-
var
|
|
284
|
-
var vercelEndpointExports =
|
|
285
|
-
edge:
|
|
286
|
-
headers:
|
|
287
|
-
streaming:
|
|
288
|
-
isr:
|
|
289
|
-
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))
|
|
290
98
|
}).optional()
|
|
291
99
|
});
|
|
292
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
|
+
|
|
293
122
|
// src/build.ts
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
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) => ({
|
|
300
140
|
...e,
|
|
301
|
-
|
|
141
|
+
route: e.route ?? true,
|
|
302
142
|
// path.resolve removes the trailing slash if any
|
|
303
|
-
destination:
|
|
143
|
+
destination: `${import_node_path2.default.posix.resolve("/", e.destination)}.func`
|
|
304
144
|
}));
|
|
305
145
|
}
|
|
306
|
-
function getEntries(resolvedConfig) {
|
|
307
|
-
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("_"));
|
|
308
148
|
if (apiEntries.length > 0) {
|
|
309
149
|
console.warn(
|
|
310
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."
|
|
311
151
|
);
|
|
312
152
|
}
|
|
313
|
-
const otherApiEntries = import_fast_glob.default.sync(`${getRoot(resolvedConfig)}/_api/**/*.*([a-zA-Z0-9])`).filter((filepath) => !
|
|
314
|
-
return [...apiEntries, ...otherApiEntries].reduce(
|
|
315
|
-
|
|
316
|
-
filePath,
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
}, 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
|
+
);
|
|
328
167
|
}
|
|
329
168
|
var edgeWasmPlugin = {
|
|
330
169
|
name: "edge-wasm-vercel",
|
|
@@ -379,35 +218,21 @@ async function buildFn(resolvedConfig, entry, buildOptions) {
|
|
|
379
218
|
Object.assign(options, buildOptions);
|
|
380
219
|
}
|
|
381
220
|
const filename = entry.edge || options.format === "cjs" ? "index.js" : "index.mjs";
|
|
382
|
-
const outfile =
|
|
383
|
-
getOutput(resolvedConfig, "functions"),
|
|
384
|
-
entry.destination,
|
|
385
|
-
filename
|
|
386
|
-
);
|
|
221
|
+
const outfile = import_node_path2.default.join(getOutput(resolvedConfig, "functions"), entry.destination, filename);
|
|
387
222
|
Object.assign(options, { outfile });
|
|
388
223
|
if (!options.stdin) {
|
|
389
224
|
if (typeof entry.source === "string") {
|
|
390
225
|
options.entryPoints = [entry.source];
|
|
391
226
|
} else {
|
|
392
|
-
assert(
|
|
393
|
-
|
|
394
|
-
`\`{ source }\` must be a string or an object`
|
|
395
|
-
);
|
|
396
|
-
assert(
|
|
397
|
-
typeof entry.source.contents === "string",
|
|
398
|
-
`\`{ contents }\` must be a string`
|
|
399
|
-
);
|
|
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");
|
|
400
229
|
options.stdin = entry.source;
|
|
401
230
|
}
|
|
402
231
|
}
|
|
403
232
|
if (entry.edge) {
|
|
404
|
-
options.
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
"module",
|
|
408
|
-
"import",
|
|
409
|
-
"require"
|
|
410
|
-
];
|
|
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"];
|
|
411
236
|
options.plugins?.push(edgeWasmPlugin);
|
|
412
237
|
options.format = "esm";
|
|
413
238
|
} else if (options.format === "esm") {
|
|
@@ -422,9 +247,9 @@ const __dirname = VPV_dirname(__filename);
|
|
|
422
247
|
};
|
|
423
248
|
}
|
|
424
249
|
const ctx = { found: false, index: "" };
|
|
425
|
-
options.plugins
|
|
250
|
+
options.plugins?.push(vercelOgPlugin(ctx));
|
|
426
251
|
const output = await (0, import_esbuild.build)(options);
|
|
427
|
-
if (typeof entry.source
|
|
252
|
+
if (typeof entry.source === "string") {
|
|
428
253
|
let base = resolvedConfig.root;
|
|
429
254
|
try {
|
|
430
255
|
const dir = await (0, import_find_root.findRoot)(resolvedConfig.root);
|
|
@@ -451,18 +276,14 @@ const __dirname = VPV_dirname(__filename);
|
|
|
451
276
|
});
|
|
452
277
|
return result.outputFiles[0].text;
|
|
453
278
|
}
|
|
454
|
-
return
|
|
279
|
+
return import_promises.default.readFile(filepath, "utf-8");
|
|
455
280
|
}
|
|
456
281
|
});
|
|
457
282
|
for (const file of fileList) {
|
|
458
|
-
if (reasons.has(file) && reasons.get(file)
|
|
459
|
-
await (0,
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
getOutput(resolvedConfig, "functions"),
|
|
463
|
-
entry.destination,
|
|
464
|
-
(0, import_path3.basename)(file)
|
|
465
|
-
)
|
|
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))
|
|
466
287
|
);
|
|
467
288
|
}
|
|
468
289
|
}
|
|
@@ -474,13 +295,9 @@ const __dirname = VPV_dirname(__filename);
|
|
|
474
295
|
return output;
|
|
475
296
|
}
|
|
476
297
|
async function writeVcConfig(resolvedConfig, destination, filename, options) {
|
|
477
|
-
const vcConfig =
|
|
478
|
-
getOutput(resolvedConfig, "functions"),
|
|
479
|
-
destination,
|
|
480
|
-
".vc-config.json"
|
|
481
|
-
);
|
|
298
|
+
const vcConfig = import_node_path2.default.join(getOutput(resolvedConfig, "functions"), destination, ".vc-config.json");
|
|
482
299
|
const nodeVersion = await (0, import_build_utils.getNodeVersion)(getOutput(resolvedConfig));
|
|
483
|
-
await
|
|
300
|
+
await import_promises.default.writeFile(
|
|
484
301
|
vcConfig,
|
|
485
302
|
JSON.stringify(
|
|
486
303
|
vercelOutputVcConfigSchema.parse(
|
|
@@ -504,9 +321,9 @@ async function writeVcConfig(resolvedConfig, destination, filename, options) {
|
|
|
504
321
|
}
|
|
505
322
|
function getSourceAndDestination(destination) {
|
|
506
323
|
if (destination.startsWith("api/")) {
|
|
507
|
-
return
|
|
324
|
+
return import_node_path2.default.posix.resolve("/", destination);
|
|
508
325
|
}
|
|
509
|
-
return
|
|
326
|
+
return import_node_path2.default.posix.resolve("/", destination, ":match*");
|
|
510
327
|
}
|
|
511
328
|
var RE_BRACKETS = /^\[([^/]+)\]$/gm;
|
|
512
329
|
function replaceBrackets(source) {
|
|
@@ -539,7 +356,7 @@ async function extractExports(filepath) {
|
|
|
539
356
|
}
|
|
540
357
|
}
|
|
541
358
|
async function buildEndpoints(resolvedConfig) {
|
|
542
|
-
const entries = getEntries(resolvedConfig);
|
|
359
|
+
const entries = await getEntries(resolvedConfig);
|
|
543
360
|
for (const entry of entries) {
|
|
544
361
|
if (typeof entry.source === "string") {
|
|
545
362
|
const exports2 = await extractExports(entry.source);
|
|
@@ -563,6 +380,9 @@ async function buildEndpoints(resolvedConfig) {
|
|
|
563
380
|
`isr configuration should be defined either in the endpoint itself or through Vite config, not both ('${entry.source}')`
|
|
564
381
|
);
|
|
565
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
|
+
}
|
|
566
386
|
if (exports2.isr) {
|
|
567
387
|
entry.isr = exports2.isr;
|
|
568
388
|
}
|
|
@@ -573,21 +393,36 @@ async function buildEndpoints(resolvedConfig) {
|
|
|
573
393
|
}
|
|
574
394
|
await buildFn(resolvedConfig, entry);
|
|
575
395
|
}
|
|
576
|
-
const isrEntries = entries.filter((e) => e.isr).map(
|
|
577
|
-
(e) => [
|
|
578
|
-
e.destination.replace(/\.func$/, ""),
|
|
579
|
-
{ expiration: e.isr.expiration }
|
|
580
|
-
]
|
|
581
|
-
);
|
|
396
|
+
const isrEntries = entries.filter((e) => e.isr).map((e) => [e.destination.replace(/\.func$/, ""), { expiration: e.isr?.expiration }]);
|
|
582
397
|
return {
|
|
583
|
-
rewrites: entries.filter((e) =>
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
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
|
+
}),
|
|
587
422
|
isr: Object.fromEntries(isrEntries),
|
|
588
423
|
headers: entries.filter((e) => e.headers).map((e) => ({
|
|
589
|
-
source:
|
|
590
|
-
headers: Object.entries(e.headers).map(([key, value]) => ({
|
|
424
|
+
source: `/${e.destination.replace(/\.func$/, "")}`,
|
|
425
|
+
headers: Object.entries(e.headers ?? {}).map(([key, value]) => ({
|
|
591
426
|
key,
|
|
592
427
|
value
|
|
593
428
|
}))
|
|
@@ -595,36 +430,198 @@ async function buildEndpoints(resolvedConfig) {
|
|
|
595
430
|
};
|
|
596
431
|
}
|
|
597
432
|
|
|
598
|
-
// src/
|
|
599
|
-
var
|
|
433
|
+
// src/config.ts
|
|
434
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
600
435
|
|
|
601
|
-
// src/schemas/config/
|
|
602
|
-
var
|
|
603
|
-
var
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
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()
|
|
609
517
|
}).strict();
|
|
610
518
|
|
|
611
|
-
// src/
|
|
612
|
-
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
|
+
}
|
|
613
596
|
|
|
614
597
|
// src/helpers.ts
|
|
615
598
|
var import_promises3 = __toESM(require("fs/promises"), 1);
|
|
616
|
-
var
|
|
599
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
617
600
|
async function copyDir(src, dest) {
|
|
618
601
|
await import_promises3.default.mkdir(dest, { recursive: true });
|
|
619
602
|
const entries = await import_promises3.default.readdir(src, { withFileTypes: true });
|
|
620
603
|
for (const entry of entries) {
|
|
621
|
-
const srcPath =
|
|
622
|
-
const destPath =
|
|
604
|
+
const srcPath = import_node_path4.default.join(src, entry.name);
|
|
605
|
+
const destPath = import_node_path4.default.join(dest, entry.name);
|
|
623
606
|
entry.isDirectory() ? await copyDir(srcPath, destPath) : await import_promises3.default.copyFile(srcPath, destPath);
|
|
624
607
|
}
|
|
625
608
|
}
|
|
626
609
|
|
|
627
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);
|
|
628
625
|
function execPrerender(resolvedConfig) {
|
|
629
626
|
const prerender = resolvedConfig.vercel?.prerender;
|
|
630
627
|
if (prerender === false) {
|
|
@@ -634,16 +631,9 @@ function execPrerender(resolvedConfig) {
|
|
|
634
631
|
}
|
|
635
632
|
var group = 1;
|
|
636
633
|
async function writePrerenderConfig(resolvedConfig, destination, isr) {
|
|
637
|
-
const parsed =
|
|
638
|
-
const outfile =
|
|
639
|
-
|
|
640
|
-
parsed.dir,
|
|
641
|
-
parsed.name + ".prerender-config.json"
|
|
642
|
-
);
|
|
643
|
-
await import_promises4.default.mkdir(
|
|
644
|
-
import_path5.default.join(getOutput(resolvedConfig, "functions"), parsed.dir),
|
|
645
|
-
{ recursive: true }
|
|
646
|
-
);
|
|
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 });
|
|
647
637
|
await import_promises4.default.writeFile(
|
|
648
638
|
outfile,
|
|
649
639
|
JSON.stringify(
|
|
@@ -658,37 +648,21 @@ async function writePrerenderConfig(resolvedConfig, destination, isr) {
|
|
|
658
648
|
);
|
|
659
649
|
}
|
|
660
650
|
function getPrerenderSymlinkInfo(resolvedConfig, destination, target) {
|
|
661
|
-
const parsed =
|
|
662
|
-
const targetParsed =
|
|
651
|
+
const parsed = import_node_path5.default.parse(destination);
|
|
652
|
+
const targetParsed = import_node_path5.default.parse(target);
|
|
663
653
|
return {
|
|
664
|
-
target:
|
|
665
|
-
|
|
666
|
-
targetParsed.dir,
|
|
667
|
-
targetParsed.name + ".func"
|
|
668
|
-
),
|
|
669
|
-
link: import_path5.default.join(
|
|
670
|
-
getOutput(resolvedConfig, "functions"),
|
|
671
|
-
parsed.dir,
|
|
672
|
-
parsed.name + ".func"
|
|
673
|
-
)
|
|
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`)
|
|
674
656
|
};
|
|
675
657
|
}
|
|
676
658
|
async function buildPrerenderConfigs(resolvedConfig, extractedIsr) {
|
|
677
|
-
const isr = Object.assign(
|
|
678
|
-
{},
|
|
679
|
-
extractedIsr,
|
|
680
|
-
await getIsrConfig(resolvedConfig)
|
|
681
|
-
);
|
|
659
|
+
const isr = Object.assign({}, extractedIsr, await getIsrConfig(resolvedConfig));
|
|
682
660
|
const entries = Object.entries(isr);
|
|
683
661
|
const rewrites = [];
|
|
684
662
|
for (const [destination, { symlink, route, ...isr2 }] of entries) {
|
|
685
663
|
await writePrerenderConfig(resolvedConfig, destination, isr2);
|
|
686
664
|
if (symlink) {
|
|
687
|
-
const info = getPrerenderSymlinkInfo(
|
|
688
|
-
resolvedConfig,
|
|
689
|
-
destination,
|
|
690
|
-
symlink
|
|
691
|
-
);
|
|
665
|
+
const info = getPrerenderSymlinkInfo(resolvedConfig, destination, symlink);
|
|
692
666
|
await copyDir(info.target, info.link);
|
|
693
667
|
}
|
|
694
668
|
if (route) {
|
|
@@ -709,7 +683,6 @@ async function getIsrConfig(resolvedConfig) {
|
|
|
709
683
|
}
|
|
710
684
|
|
|
711
685
|
// src/index.ts
|
|
712
|
-
var import_path6 = __toESM(require("path"), 1);
|
|
713
686
|
function vercelPluginCleanup() {
|
|
714
687
|
let resolvedConfig;
|
|
715
688
|
return {
|
|
@@ -739,9 +712,7 @@ function vercelPlugin() {
|
|
|
739
712
|
enforce: "post",
|
|
740
713
|
configResolved(config) {
|
|
741
714
|
resolvedConfig = config;
|
|
742
|
-
vikeFound = resolvedConfig.plugins.some(
|
|
743
|
-
(p) => p.name.match("^vite-plugin-ssr:|^vike:")
|
|
744
|
-
);
|
|
715
|
+
vikeFound = resolvedConfig.plugins.some((p) => p.name.match("^vite-plugin-ssr:|^vike:"));
|
|
745
716
|
if (typeof resolvedConfig.vercel?.distContainsOnlyStatic === "undefined") {
|
|
746
717
|
resolvedConfig.vercel ??= {};
|
|
747
718
|
resolvedConfig.vercel.distContainsOnlyStatic = !vikeFound;
|
|
@@ -783,10 +754,7 @@ async function cleanOutputDirectory(resolvedConfig) {
|
|
|
783
754
|
}
|
|
784
755
|
async function copyDistToStatic(resolvedConfig) {
|
|
785
756
|
if (resolvedConfig.vercel?.distContainsOnlyStatic) {
|
|
786
|
-
await copyDir(
|
|
787
|
-
resolvedConfig.build.outDir,
|
|
788
|
-
getOutput(resolvedConfig, "static")
|
|
789
|
-
);
|
|
757
|
+
await copyDir(resolvedConfig.build.outDir, getOutput(resolvedConfig, "static"));
|
|
790
758
|
}
|
|
791
759
|
}
|
|
792
760
|
async function computeStaticHtmlOverrides(resolvedConfig) {
|
|
@@ -794,18 +762,19 @@ async function computeStaticHtmlOverrides(resolvedConfig) {
|
|
|
794
762
|
const files = await getStaticHtmlFiles(staticAbsolutePath);
|
|
795
763
|
const publicDir = getPublic(resolvedConfig);
|
|
796
764
|
const publicFiles = await getStaticHtmlFiles(publicDir);
|
|
797
|
-
files.push(
|
|
798
|
-
|
|
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
|
+
{}
|
|
799
777
|
);
|
|
800
|
-
return files.reduce((acc, curr) => {
|
|
801
|
-
const relPath = import_path6.default.relative(staticAbsolutePath, curr);
|
|
802
|
-
const parsed = import_path6.default.parse(relPath);
|
|
803
|
-
const pathJoined = import_path6.default.join(parsed.dir, parsed.name);
|
|
804
|
-
acc[relPath] = {
|
|
805
|
-
path: pathJoined
|
|
806
|
-
};
|
|
807
|
-
return acc;
|
|
808
|
-
}, {});
|
|
809
778
|
}
|
|
810
779
|
async function getStaticHtmlFiles(src) {
|
|
811
780
|
try {
|
|
@@ -816,7 +785,7 @@ async function getStaticHtmlFiles(src) {
|
|
|
816
785
|
const entries = await import_promises5.default.readdir(src, { withFileTypes: true });
|
|
817
786
|
const htmlFiles = [];
|
|
818
787
|
for (const entry of entries) {
|
|
819
|
-
const srcPath =
|
|
788
|
+
const srcPath = import_node_path6.default.join(src, entry.name);
|
|
820
789
|
entry.isDirectory() ? htmlFiles.push(...await getStaticHtmlFiles(srcPath)) : srcPath.endsWith(".html") ? htmlFiles.push(srcPath) : void 0;
|
|
821
790
|
}
|
|
822
791
|
return htmlFiles;
|
|
@@ -838,9 +807,5 @@ async function tryImportVpvv(options) {
|
|
|
838
807
|
}
|
|
839
808
|
function allPlugins(options = {}) {
|
|
840
809
|
const { smart, ...rest } = options;
|
|
841
|
-
return [
|
|
842
|
-
vercelPluginCleanup(),
|
|
843
|
-
vercelPlugin(),
|
|
844
|
-
smart !== false ? tryImportVpvv(rest) : null
|
|
845
|
-
];
|
|
810
|
+
return [vercelPluginCleanup(), vercelPlugin(), smart !== false ? tryImportVpvv(rest) : null];
|
|
846
811
|
}
|