vite-plugin-vercel 0.0.1 → 0.0.4

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 CHANGED
@@ -1,5 +1,591 @@
1
- import { Plugin } from 'vite';
1
+ import { ResolvedConfig, Plugin } from 'vite';
2
+ import { StdinOptions, BuildOptions } from 'esbuild';
3
+ import { z } from 'zod';
4
+
5
+ declare const routesManifestDynamicRouteSchema: z.ZodObject<{
6
+ page: z.ZodString;
7
+ regex: z.ZodString;
8
+ routeKeys: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
9
+ namedRegex: z.ZodOptional<z.ZodString>;
10
+ }, "strict", z.ZodTypeAny, {
11
+ routeKeys?: Record<string, string> | undefined;
12
+ namedRegex?: string | undefined;
13
+ regex: string;
14
+ page: string;
15
+ }, {
16
+ routeKeys?: Record<string, string> | undefined;
17
+ namedRegex?: string | undefined;
18
+ regex: string;
19
+ page: string;
20
+ }>;
21
+ declare const routesManifestSchema: z.ZodObject<{
22
+ version: z.ZodLiteral<3>;
23
+ basePath: z.ZodString;
24
+ pages404: z.ZodBoolean;
25
+ redirects: z.ZodOptional<z.ZodArray<z.ZodObject<{
26
+ source: z.ZodString;
27
+ destination: z.ZodString;
28
+ statusCode: z.ZodEffects<z.ZodNumber, number, number>;
29
+ regex: z.ZodString;
30
+ }, "strict", z.ZodTypeAny, {
31
+ source: string;
32
+ destination: string;
33
+ statusCode: number;
34
+ regex: string;
35
+ }, {
36
+ source: string;
37
+ destination: string;
38
+ statusCode: number;
39
+ regex: string;
40
+ }>, "many">>;
41
+ headers: z.ZodOptional<z.ZodArray<z.ZodObject<{
42
+ source: z.ZodString;
43
+ headers: z.ZodArray<z.ZodObject<{
44
+ key: z.ZodString;
45
+ value: z.ZodString;
46
+ }, "strict", z.ZodTypeAny, {
47
+ value: string;
48
+ key: string;
49
+ }, {
50
+ value: string;
51
+ key: string;
52
+ }>, "many">;
53
+ regex: z.ZodString;
54
+ }, "strict", z.ZodTypeAny, {
55
+ source: string;
56
+ regex: string;
57
+ headers: {
58
+ value: string;
59
+ key: string;
60
+ }[];
61
+ }, {
62
+ source: string;
63
+ regex: string;
64
+ headers: {
65
+ value: string;
66
+ key: string;
67
+ }[];
68
+ }>, "many">>;
69
+ rewrites: z.ZodOptional<z.ZodArray<z.ZodObject<{
70
+ source: z.ZodString;
71
+ has: z.ZodOptional<z.ZodArray<z.ZodObject<{
72
+ key: z.ZodString;
73
+ value: z.ZodString;
74
+ type: z.ZodEnum<["header", "cookie", "host", "query"]>;
75
+ }, "strict", z.ZodTypeAny, {
76
+ value: string;
77
+ type: "header" | "cookie" | "host" | "query";
78
+ key: string;
79
+ }, {
80
+ value: string;
81
+ type: "header" | "cookie" | "host" | "query";
82
+ key: string;
83
+ }>, "many">>;
84
+ destination: z.ZodString;
85
+ regex: z.ZodString;
86
+ }, "strict", z.ZodTypeAny, {
87
+ has?: {
88
+ value: string;
89
+ type: "header" | "cookie" | "host" | "query";
90
+ key: string;
91
+ }[] | undefined;
92
+ source: string;
93
+ destination: string;
94
+ regex: string;
95
+ }, {
96
+ has?: {
97
+ value: string;
98
+ type: "header" | "cookie" | "host" | "query";
99
+ key: string;
100
+ }[] | undefined;
101
+ source: string;
102
+ destination: string;
103
+ regex: string;
104
+ }>, "many">>;
105
+ dynamicRoutes: z.ZodOptional<z.ZodArray<z.ZodObject<{
106
+ page: z.ZodString;
107
+ regex: z.ZodString;
108
+ routeKeys: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
109
+ namedRegex: z.ZodOptional<z.ZodString>;
110
+ }, "strict", z.ZodTypeAny, {
111
+ routeKeys?: Record<string, string> | undefined;
112
+ namedRegex?: string | undefined;
113
+ regex: string;
114
+ page: string;
115
+ }, {
116
+ routeKeys?: Record<string, string> | undefined;
117
+ namedRegex?: string | undefined;
118
+ regex: string;
119
+ page: string;
120
+ }>, "many">>;
121
+ }, "strict", z.ZodTypeAny, {
122
+ dynamicRoutes?: {
123
+ routeKeys?: Record<string, string> | undefined;
124
+ namedRegex?: string | undefined;
125
+ regex: string;
126
+ page: string;
127
+ }[] | undefined;
128
+ redirects?: {
129
+ source: string;
130
+ destination: string;
131
+ statusCode: number;
132
+ regex: string;
133
+ }[] | undefined;
134
+ headers?: {
135
+ source: string;
136
+ regex: string;
137
+ headers: {
138
+ value: string;
139
+ key: string;
140
+ }[];
141
+ }[] | undefined;
142
+ rewrites?: {
143
+ has?: {
144
+ value: string;
145
+ type: "header" | "cookie" | "host" | "query";
146
+ key: string;
147
+ }[] | undefined;
148
+ source: string;
149
+ destination: string;
150
+ regex: string;
151
+ }[] | undefined;
152
+ version: 3;
153
+ basePath: string;
154
+ pages404: boolean;
155
+ }, {
156
+ dynamicRoutes?: {
157
+ routeKeys?: Record<string, string> | undefined;
158
+ namedRegex?: string | undefined;
159
+ regex: string;
160
+ page: string;
161
+ }[] | undefined;
162
+ redirects?: {
163
+ source: string;
164
+ destination: string;
165
+ statusCode: number;
166
+ regex: string;
167
+ }[] | undefined;
168
+ headers?: {
169
+ source: string;
170
+ regex: string;
171
+ headers: {
172
+ value: string;
173
+ key: string;
174
+ }[];
175
+ }[] | undefined;
176
+ rewrites?: {
177
+ has?: {
178
+ value: string;
179
+ type: "header" | "cookie" | "host" | "query";
180
+ key: string;
181
+ }[] | undefined;
182
+ source: string;
183
+ destination: string;
184
+ regex: string;
185
+ }[] | undefined;
186
+ version: 3;
187
+ basePath: string;
188
+ pages404: boolean;
189
+ }>;
190
+ declare type RoutesManifest = z.infer<typeof routesManifestSchema>;
191
+ declare type RoutesManifestDynamicRoute = z.infer<typeof routesManifestDynamicRouteSchema>;
192
+ declare type RoutesManifestDefault = Partial<Omit<RoutesManifest, 'version'>>;
193
+
194
+ declare const functionsManifestSchema: z.ZodObject<{
195
+ version: z.ZodLiteral<1>;
196
+ pages: z.ZodIntersection<z.ZodObject<{
197
+ '_middleware.js': z.ZodOptional<z.ZodObject<z.extendShape<{
198
+ handler: z.ZodOptional<z.ZodString>;
199
+ regions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
200
+ maxDuration: z.ZodOptional<z.ZodNumber>;
201
+ memory: z.ZodOptional<z.ZodNumber>;
202
+ }, {
203
+ runtime: z.ZodLiteral<"web">;
204
+ env: z.ZodArray<z.ZodString, "many">;
205
+ files: z.ZodArray<z.ZodString, "many">;
206
+ name: z.ZodString;
207
+ page: z.ZodString;
208
+ regexp: z.ZodString;
209
+ sortingIndex: z.ZodNumber;
210
+ }>, "strict", z.ZodTypeAny, {
211
+ handler?: string | undefined;
212
+ regions?: string[] | undefined;
213
+ maxDuration?: number | undefined;
214
+ memory?: number | undefined;
215
+ env: string[];
216
+ page: string;
217
+ runtime: "web";
218
+ files: string[];
219
+ name: string;
220
+ regexp: string;
221
+ sortingIndex: number;
222
+ }, {
223
+ handler?: string | undefined;
224
+ regions?: string[] | undefined;
225
+ maxDuration?: number | undefined;
226
+ memory?: number | undefined;
227
+ env: string[];
228
+ page: string;
229
+ runtime: "web";
230
+ files: string[];
231
+ name: string;
232
+ regexp: string;
233
+ sortingIndex: number;
234
+ }>>;
235
+ }, "strip", z.ZodTypeAny, {
236
+ "_middleware.js"?: {
237
+ handler?: string | undefined;
238
+ regions?: string[] | undefined;
239
+ maxDuration?: number | undefined;
240
+ memory?: number | undefined;
241
+ env: string[];
242
+ page: string;
243
+ runtime: "web";
244
+ files: string[];
245
+ name: string;
246
+ regexp: string;
247
+ sortingIndex: number;
248
+ } | undefined;
249
+ }, {
250
+ "_middleware.js"?: {
251
+ handler?: string | undefined;
252
+ regions?: string[] | undefined;
253
+ maxDuration?: number | undefined;
254
+ memory?: number | undefined;
255
+ env: string[];
256
+ page: string;
257
+ runtime: "web";
258
+ files: string[];
259
+ name: string;
260
+ regexp: string;
261
+ sortingIndex: number;
262
+ } | undefined;
263
+ }>, z.ZodRecord<z.ZodString, z.ZodIntersection<z.ZodObject<{
264
+ env: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
265
+ page: z.ZodOptional<z.ZodString>;
266
+ handler: z.ZodOptional<z.ZodOptional<z.ZodString>>;
267
+ regions: z.ZodOptional<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
268
+ maxDuration: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
269
+ memory: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
270
+ files: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
271
+ name: z.ZodOptional<z.ZodString>;
272
+ regexp: z.ZodOptional<z.ZodString>;
273
+ sortingIndex: z.ZodOptional<z.ZodNumber>;
274
+ }, "strict", z.ZodTypeAny, {
275
+ env?: string[] | undefined;
276
+ page?: string | undefined;
277
+ handler?: string | undefined;
278
+ regions?: string[] | undefined;
279
+ maxDuration?: number | undefined;
280
+ memory?: number | undefined;
281
+ files?: string[] | undefined;
282
+ name?: string | undefined;
283
+ regexp?: string | undefined;
284
+ sortingIndex?: number | undefined;
285
+ }, {
286
+ env?: string[] | undefined;
287
+ page?: string | undefined;
288
+ handler?: string | undefined;
289
+ regions?: string[] | undefined;
290
+ maxDuration?: number | undefined;
291
+ memory?: number | undefined;
292
+ files?: string[] | undefined;
293
+ name?: string | undefined;
294
+ regexp?: string | undefined;
295
+ sortingIndex?: number | undefined;
296
+ }>, z.ZodObject<{
297
+ runtime: z.ZodOptional<z.ZodString>;
298
+ handler: z.ZodOptional<z.ZodString>;
299
+ regions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
300
+ maxDuration: z.ZodOptional<z.ZodNumber>;
301
+ memory: z.ZodOptional<z.ZodNumber>;
302
+ }, "strict", z.ZodTypeAny, {
303
+ runtime?: string | undefined;
304
+ handler?: string | undefined;
305
+ regions?: string[] | undefined;
306
+ maxDuration?: number | undefined;
307
+ memory?: number | undefined;
308
+ }, {
309
+ runtime?: string | undefined;
310
+ handler?: string | undefined;
311
+ regions?: string[] | undefined;
312
+ maxDuration?: number | undefined;
313
+ memory?: number | undefined;
314
+ }>>>>;
315
+ }, "strip", z.ZodTypeAny, {
316
+ version: 1;
317
+ pages: {
318
+ "_middleware.js"?: {
319
+ handler?: string | undefined;
320
+ regions?: string[] | undefined;
321
+ maxDuration?: number | undefined;
322
+ memory?: number | undefined;
323
+ env: string[];
324
+ page: string;
325
+ runtime: "web";
326
+ files: string[];
327
+ name: string;
328
+ regexp: string;
329
+ sortingIndex: number;
330
+ } | undefined;
331
+ } & Record<string, {
332
+ env?: string[] | undefined;
333
+ page?: string | undefined;
334
+ handler?: string | undefined;
335
+ regions?: string[] | undefined;
336
+ maxDuration?: number | undefined;
337
+ memory?: number | undefined;
338
+ files?: string[] | undefined;
339
+ name?: string | undefined;
340
+ regexp?: string | undefined;
341
+ sortingIndex?: number | undefined;
342
+ } & {
343
+ runtime?: string | undefined;
344
+ handler?: string | undefined;
345
+ regions?: string[] | undefined;
346
+ maxDuration?: number | undefined;
347
+ memory?: number | undefined;
348
+ }>;
349
+ }, {
350
+ version: 1;
351
+ pages: {
352
+ "_middleware.js"?: {
353
+ handler?: string | undefined;
354
+ regions?: string[] | undefined;
355
+ maxDuration?: number | undefined;
356
+ memory?: number | undefined;
357
+ env: string[];
358
+ page: string;
359
+ runtime: "web";
360
+ files: string[];
361
+ name: string;
362
+ regexp: string;
363
+ sortingIndex: number;
364
+ } | undefined;
365
+ } & Record<string, {
366
+ env?: string[] | undefined;
367
+ page?: string | undefined;
368
+ handler?: string | undefined;
369
+ regions?: string[] | undefined;
370
+ maxDuration?: number | undefined;
371
+ memory?: number | undefined;
372
+ files?: string[] | undefined;
373
+ name?: string | undefined;
374
+ regexp?: string | undefined;
375
+ sortingIndex?: number | undefined;
376
+ } & {
377
+ runtime?: string | undefined;
378
+ handler?: string | undefined;
379
+ regions?: string[] | undefined;
380
+ maxDuration?: number | undefined;
381
+ memory?: number | undefined;
382
+ }>;
383
+ }>;
384
+ declare type FunctionsManifest = z.infer<typeof functionsManifestSchema>;
385
+
386
+ declare const prerenderManifestSchemaRoute: z.ZodObject<{
387
+ initialRevalidateSeconds: z.ZodNumber;
388
+ srcRoute: z.ZodString;
389
+ dataRoute: z.ZodString;
390
+ }, "strict", z.ZodTypeAny, {
391
+ initialRevalidateSeconds: number;
392
+ srcRoute: string;
393
+ dataRoute: string;
394
+ }, {
395
+ initialRevalidateSeconds: number;
396
+ srcRoute: string;
397
+ dataRoute: string;
398
+ }>;
399
+ declare const prerenderManifestSchemaDynamicRoute: z.ZodObject<{
400
+ routeRegex: z.ZodString;
401
+ fallback: z.ZodUnion<[z.ZodString, z.ZodNull]>;
402
+ dataRoute: z.ZodString;
403
+ dataRouteRegex: z.ZodString;
404
+ }, "strict", z.ZodTypeAny, {
405
+ dataRoute: string;
406
+ routeRegex: string;
407
+ fallback: string | null;
408
+ dataRouteRegex: string;
409
+ }, {
410
+ dataRoute: string;
411
+ routeRegex: string;
412
+ fallback: string | null;
413
+ dataRouteRegex: string;
414
+ }>;
415
+ declare const prerenderManifestSchema: z.ZodObject<{
416
+ version: z.ZodLiteral<3>;
417
+ routes: z.ZodRecord<z.ZodString, z.ZodObject<{
418
+ initialRevalidateSeconds: z.ZodNumber;
419
+ srcRoute: z.ZodString;
420
+ dataRoute: z.ZodString;
421
+ }, "strict", z.ZodTypeAny, {
422
+ initialRevalidateSeconds: number;
423
+ srcRoute: string;
424
+ dataRoute: string;
425
+ }, {
426
+ initialRevalidateSeconds: number;
427
+ srcRoute: string;
428
+ dataRoute: string;
429
+ }>>;
430
+ dynamicRoutes: z.ZodRecord<z.ZodString, z.ZodObject<{
431
+ routeRegex: z.ZodString;
432
+ fallback: z.ZodUnion<[z.ZodString, z.ZodNull]>;
433
+ dataRoute: z.ZodString;
434
+ dataRouteRegex: z.ZodString;
435
+ }, "strict", z.ZodTypeAny, {
436
+ dataRoute: string;
437
+ routeRegex: string;
438
+ fallback: string | null;
439
+ dataRouteRegex: string;
440
+ }, {
441
+ dataRoute: string;
442
+ routeRegex: string;
443
+ fallback: string | null;
444
+ dataRouteRegex: string;
445
+ }>>;
446
+ preview: z.ZodObject<{
447
+ previewModeId: z.ZodUnion<[z.ZodString, z.ZodNull]>;
448
+ }, "strict", z.ZodTypeAny, {
449
+ previewModeId: string | null;
450
+ }, {
451
+ previewModeId: string | null;
452
+ }>;
453
+ }, "strict", z.ZodTypeAny, {
454
+ preview: {
455
+ previewModeId: string | null;
456
+ };
457
+ version: 3;
458
+ routes: Record<string, {
459
+ initialRevalidateSeconds: number;
460
+ srcRoute: string;
461
+ dataRoute: string;
462
+ }>;
463
+ dynamicRoutes: Record<string, {
464
+ dataRoute: string;
465
+ routeRegex: string;
466
+ fallback: string | null;
467
+ dataRouteRegex: string;
468
+ }>;
469
+ }, {
470
+ preview: {
471
+ previewModeId: string | null;
472
+ };
473
+ version: 3;
474
+ routes: Record<string, {
475
+ initialRevalidateSeconds: number;
476
+ srcRoute: string;
477
+ dataRoute: string;
478
+ }>;
479
+ dynamicRoutes: Record<string, {
480
+ dataRoute: string;
481
+ routeRegex: string;
482
+ fallback: string | null;
483
+ dataRouteRegex: string;
484
+ }>;
485
+ }>;
486
+ declare type PrerenderManifest = z.infer<typeof prerenderManifestSchema>;
487
+ declare type PrerenderManifestRoute = z.infer<typeof prerenderManifestSchemaRoute>;
488
+ declare type PrerenderManifestDynamicRoute = z.infer<typeof prerenderManifestSchemaDynamicRoute>;
489
+ declare type DeepPartial<T> = T extends Function ? T : T extends object ? {
490
+ [P in keyof T]?: DeepPartial<T[P]>;
491
+ } : T;
492
+ declare type PrerenderManifestDefault = DeepPartial<PrerenderManifest>;
493
+
494
+ interface ViteVercelConfig {
495
+ /**
496
+ * How long Functions should be allowed to run for every request in seconds.
497
+ * If left empty, default value for your plan will is used.
498
+ */
499
+ defaultMaxDuration?: number;
500
+ /**
501
+ * If ISR is supported, default revalidation time per-page can be overriden.
502
+ * A `prerender` function is necessary for ISR to work.
503
+ * Defaults to 86400 seconds (24h).
504
+ * @see {@link https://vercel.com/docs/concepts/next.js/incremental-static-regeneration}
505
+ */
506
+ initialRevalidateSeconds?: number;
507
+ /**
508
+ * Also known as Server Side Generation, or SSG.
509
+ * If present, must build static files in `.output/server/pages`.
510
+ * Can be set to `false` to disable prerendering completely.
511
+ */
512
+ prerender?: ViteVercelPrerenderFn | false;
513
+ /**
514
+ * By default, all `api/*` endpoints are compiled under `.ouput/server/pages/api`.
515
+ * If a file must also be compiled only under `.ouput/server/pages`, it should be added here.
516
+ *
517
+ * @example
518
+ * ```
519
+ * {
520
+ * pagesEndpoints: ['./api/page.ts']
521
+ * }
522
+ * ```
523
+ */
524
+ pagesEndpoints?: string[];
525
+ /**
526
+ * All provided endpoints will also be part of the build process.
527
+ * For instance, a framework can leverage this to have a generic ssr endpoint
528
+ * without requiring the user to write any code.
529
+ *
530
+ * @example
531
+ * ```
532
+ * {
533
+ * additionalEndpoints: [
534
+ * {
535
+ * // can also be an Object representing an esbuild StdinOptions
536
+ * source: '/path/to/file.ts',
537
+ * // relative to `.output/server/pages`, without extension
538
+ * destination: ['file', '/api/file'],
539
+ * }
540
+ * ]
541
+ * }
542
+ * ```
543
+ */
544
+ additionalEndpoints?: ViteVercelApiEntry[];
545
+ /**
546
+ * Advanced configuration to override funtions-manifest.json
547
+ * @see {@link https://vercel.com/docs/file-system-api#configuration/functions}
548
+ * @protected
549
+ */
550
+ functionsManifest?: Partial<Omit<FunctionsManifest, 'version'>>;
551
+ /**
552
+ * Advanced configuration to override routes-manifest.json
553
+ * @see {@link https://vercel.com/docs/file-system-api#configuration/routes}
554
+ * @protected
555
+ */
556
+ routesManifest?: RoutesManifestDefault;
557
+ /**
558
+ * Advanced configuration to override prerender-manifest.json
559
+ * @see {@link https://vercel.com/docs/file-system-api#configuration/pre-rendering}
560
+ * @protected
561
+ */
562
+ prerenderManifest?: PrerenderManifestDefault;
563
+ /**
564
+ * Defaults to `.output`. Mostly useful for testing prupose
565
+ * @protected
566
+ */
567
+ outDir?: string;
568
+ }
569
+ declare type ViteVercelPrerenderRoute = {
570
+ isr?: Pick<PrerenderManifestDefault, 'routes' | 'dynamicRoutes'>;
571
+ ssr?: Pick<RoutesManifestDefault, 'rewrites' | 'dynamicRoutes' | 'headers'>;
572
+ };
573
+ declare type ViteVercelPrerenderFn = (resolvedConfig: ResolvedConfig) => ViteVercelPrerenderRoute | Promise<ViteVercelPrerenderRoute>;
574
+ interface ViteVercelApiEntry {
575
+ /**
576
+ * Path to entry file, or stdin config
577
+ */
578
+ source: string | StdinOptions;
579
+ /**
580
+ * Relative to `.output/server/pages`, without extension
581
+ */
582
+ destination: string | string[];
583
+ /**
584
+ * Override esbuild options
585
+ */
586
+ buildOptions?: BuildOptions;
587
+ }
2
588
 
3
589
  declare function allPlugins(): Plugin[];
4
590
 
5
- export { allPlugins as default };
591
+ export { FunctionsManifest, PrerenderManifest, PrerenderManifestDefault, PrerenderManifestDynamicRoute, PrerenderManifestRoute, RoutesManifest, RoutesManifestDefault, RoutesManifestDynamicRoute, ViteVercelApiEntry, ViteVercelConfig, ViteVercelPrerenderFn, ViteVercelPrerenderRoute, allPlugins as default };
package/dist/index.js CHANGED
@@ -93,108 +93,97 @@ function assert(condition, errorMessage) {
93
93
  }
94
94
 
95
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
- });
96
+ var import_zod = require("zod");
97
+ var routesManifestRedirectSchema = import_zod.z.object({
98
+ source: import_zod.z.string(),
99
+ destination: import_zod.z.string(),
100
+ statusCode: import_zod.z.number().refine((n) => [301, 302, 307, 308].includes(n)),
101
+ regex: import_zod.z.string()
102
+ }).strict();
103
+ var routesManifestHeaderSchema = import_zod.z.object({
104
+ source: import_zod.z.string(),
105
+ headers: import_zod.z.array(import_zod.z.object({
106
+ key: import_zod.z.string(),
107
+ value: import_zod.z.string()
108
+ }).strict()),
109
+ regex: import_zod.z.string()
110
+ }).strict();
111
+ var routesManifestRewriteSchema = import_zod.z.object({
112
+ source: import_zod.z.string(),
113
+ has: import_zod.z.array(import_zod.z.object({
114
+ key: import_zod.z.string(),
115
+ value: import_zod.z.string(),
116
+ type: import_zod.z.enum(["header", "cookie", "host", "query"])
117
+ }).strict()).optional(),
118
+ destination: import_zod.z.string(),
119
+ regex: import_zod.z.string()
120
+ }).strict();
121
+ var routesManifestDynamicRouteSchema = import_zod.z.object({
122
+ page: import_zod.z.string(),
123
+ regex: import_zod.z.string(),
124
+ routeKeys: import_zod.z.record(import_zod.z.string()).optional(),
125
+ namedRegex: import_zod.z.string().optional()
126
+ }).strict();
127
+ var routesManifestSchema = import_zod.z.object({
128
+ version: import_zod.z.literal(3),
129
+ basePath: import_zod.z.string().regex(/^\/.*/),
130
+ pages404: import_zod.z.boolean(),
131
+ redirects: import_zod.z.array(routesManifestRedirectSchema).optional(),
132
+ headers: import_zod.z.array(routesManifestHeaderSchema).optional(),
133
+ rewrites: import_zod.z.array(routesManifestRewriteSchema).optional(),
134
+ dynamicRoutes: import_zod.z.array(routesManifestDynamicRouteSchema).optional()
135
+ }).strict();
141
136
 
142
137
  // 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({
138
+ var import_zod2 = require("zod");
139
+ var functionsManifestSchemaPage = import_zod2.z.object({
140
+ runtime: import_zod2.z.string().optional(),
141
+ handler: import_zod2.z.string().optional(),
142
+ regions: import_zod2.z.array(import_zod2.z.string()).optional(),
143
+ maxDuration: import_zod2.z.number().min(1).max(900).optional(),
144
+ memory: import_zod2.z.number().min(128).max(3008).optional()
145
+ }).strict();
146
+ var functionsManifestSchemaPageWeb = functionsManifestSchemaPage.omit({
147
+ runtime: true
148
+ }).merge(import_zod2.z.object({
149
+ runtime: import_zod2.z.literal("web"),
150
+ env: import_zod2.z.array(import_zod2.z.string()),
151
+ files: import_zod2.z.array(import_zod2.z.string()),
152
+ name: import_zod2.z.string(),
153
+ page: import_zod2.z.string(),
154
+ regexp: import_zod2.z.string(),
155
+ sortingIndex: import_zod2.z.number()
156
+ }).strict());
157
+ var functionsManifestSchema = import_zod2.z.object({
158
+ version: import_zod2.z.literal(1),
159
+ pages: import_zod2.z.object({
168
160
  "_middleware.js": functionsManifestSchemaPageWeb.optional()
169
- }).and(record2(import_myzod2.default.intersection(import_myzod2.default.partial(import_myzod2.default.omit(functionsManifestSchemaPageWeb, ["runtime"])), functionsManifestSchemaPage)))
161
+ }).and(import_zod2.z.record(import_zod2.z.intersection(functionsManifestSchemaPageWeb.omit({
162
+ runtime: true
163
+ }).partial(), functionsManifestSchemaPage)))
170
164
  });
171
165
 
172
166
  // 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
- });
167
+ var import_zod3 = require("zod");
168
+ var prerenderManifestSchemaRoute = import_zod3.z.object({
169
+ initialRevalidateSeconds: import_zod3.z.number(),
170
+ srcRoute: import_zod3.z.string(),
171
+ dataRoute: import_zod3.z.string()
172
+ }).strict();
173
+ var prerenderManifestSchemaDynamicRoute = import_zod3.z.object({
174
+ routeRegex: import_zod3.z.string(),
175
+ fallback: import_zod3.z.string().or(import_zod3.z.null()),
176
+ dataRoute: import_zod3.z.string(),
177
+ dataRouteRegex: import_zod3.z.string()
178
+ }).strict();
179
+ var prerenderManifestSchema = import_zod3.z.object({
180
+ version: import_zod3.z.literal(3),
181
+ routes: import_zod3.z.record(prerenderManifestSchemaRoute),
182
+ dynamicRoutes: import_zod3.z.record(prerenderManifestSchemaDynamicRoute),
183
+ preview: import_zod3.z.object({
184
+ previewModeId: import_zod3.z.string().or(import_zod3.z.null())
185
+ }).strict()
186
+ }).strict();
198
187
 
199
188
  // src/manifests.ts
200
189
  function getPrerenderManifest(resolvedConfig, isrPages) {
@@ -211,14 +200,17 @@ function getPrerenderManifest(resolvedConfig, isrPages) {
211
200
  };
212
201
  return acc;
213
202
  }, {});
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) ?? ""
203
+ const dynamicRoutes = Object.entries((isrPages == null ? void 0 : isrPages.dynamicRoutes) ?? {}).reduce((acc, [key, val]) => {
204
+ var _a2;
205
+ const override = (_a2 = prerenderManifestDefault == null ? void 0 : prerenderManifestDefault.dynamicRoutes) == null ? void 0 : _a2[key];
206
+ const routeRegex = (val == null ? void 0 : val.routeRegex) ?? (override == null ? void 0 : override.routeRegex);
207
+ const fallback = (val == null ? void 0 : val.fallback) === null || typeof (val == null ? void 0 : val.fallback) === "string" ? val == null ? void 0 : val.fallback : (override == null ? void 0 : override.fallback) === null || typeof (override == null ? void 0 : override.fallback) === "string" ? override == null ? void 0 : override.fallback : null;
208
+ assert(routeRegex, `\`[prerender-manifest] { routeRegex }\` is required for route ${key}`);
209
+ acc[key] = {
210
+ routeRegex,
211
+ fallback,
212
+ dataRoute: (val == null ? void 0 : val.dataRoute) ?? (override == null ? void 0 : override.dataRoute) ?? "",
213
+ dataRouteRegex: (val == null ? void 0 : val.dataRouteRegex) ?? (override == null ? void 0 : override.dataRouteRegex) ?? ""
222
214
  };
223
215
  return acc;
224
216
  }, {});
@@ -229,8 +221,6 @@ function getPrerenderManifest(resolvedConfig, isrPages) {
229
221
  preview: {
230
222
  previewModeId: ((_b = prerenderManifestDefault == null ? void 0 : prerenderManifestDefault.preview) == null ? void 0 : _b.previewModeId) ?? null
231
223
  }
232
- }, {
233
- collectErrors: true
234
224
  });
235
225
  }
236
226
  function getPrerenderManifestDestination(resolvedConfig) {
@@ -240,12 +230,16 @@ function getRoutesManifest(resolvedConfig, ssr) {
240
230
  var _a;
241
231
  const routesManifest = (_a = resolvedConfig.vercel) == null ? void 0 : _a.routesManifest;
242
232
  const allRewrites = [
243
- ...(ssr == null ? void 0 : ssr.rewrites) ?? [],
244
- ...(routesManifest == null ? void 0 : routesManifest.rewrites) ?? []
233
+ ...(routesManifest == null ? void 0 : routesManifest.rewrites) ?? [],
234
+ ...(ssr == null ? void 0 : ssr.rewrites) ?? []
245
235
  ];
246
236
  const allDynamicRoutes = [
247
- ...(ssr == null ? void 0 : ssr.dynamicRoutes) ?? [],
248
- ...(routesManifest == null ? void 0 : routesManifest.dynamicRoutes) ?? []
237
+ ...(routesManifest == null ? void 0 : routesManifest.dynamicRoutes) ?? [],
238
+ ...(ssr == null ? void 0 : ssr.dynamicRoutes) ?? []
239
+ ];
240
+ const allHeaders = [
241
+ ...(routesManifest == null ? void 0 : routesManifest.headers) ?? [],
242
+ ...(ssr == null ? void 0 : ssr.headers) ?? []
249
243
  ];
250
244
  return routesManifestSchema.parse({
251
245
  version: 3,
@@ -254,9 +248,7 @@ function getRoutesManifest(resolvedConfig, ssr) {
254
248
  dynamicRoutes: allDynamicRoutes.length > 0 ? allDynamicRoutes : void 0,
255
249
  rewrites: allRewrites.length > 0 ? allRewrites : void 0,
256
250
  redirects: routesManifest == null ? void 0 : routesManifest.redirects,
257
- headers: routesManifest == null ? void 0 : routesManifest.headers
258
- }, {
259
- collectErrors: true
251
+ headers: allHeaders.length > 0 ? allHeaders : void 0
260
252
  });
261
253
  }
262
254
  function getRoutesManifestDestination(resolvedConfig) {
@@ -266,8 +258,6 @@ function getFunctionsManifest(pages) {
266
258
  return functionsManifestSchema.parse({
267
259
  version: 1,
268
260
  pages
269
- }, {
270
- collectErrors: true
271
261
  });
272
262
  }
273
263
  function getFunctionsManifestDestination(resolvedConfig) {
@@ -374,20 +364,24 @@ function vercelPlugin() {
374
364
  return {
375
365
  apply: "build",
376
366
  name: "vite-plugin-vercel",
367
+ enforce: "post",
377
368
  configResolved(config) {
378
369
  resolvedConfig = config;
379
370
  },
380
371
  async buildStart() {
381
- if (resolvedConfig.build.ssr)
382
- return;
383
- await cleanOutputDirectory(resolvedConfig);
372
+ if (process.env.VERCEL_ENV === "production" && !process.env.ENABLE_FILE_SYSTEM_API) {
373
+ throw new Error("Missing ENABLE_FILE_SYSTEM_API=1 to your environment variables in your project settings");
374
+ }
375
+ if (!resolvedConfig.build.ssr) {
376
+ await cleanOutputDirectory(resolvedConfig);
377
+ } else {
378
+ await copyDistClientToOutputStatic(resolvedConfig);
379
+ }
384
380
  },
385
381
  async writeBundle() {
386
382
  var _a;
387
- if (!((_a = resolvedConfig.build) == null ? void 0 : _a.ssr)) {
388
- await copyDistClientToOutputStatic(resolvedConfig);
383
+ if (!((_a = resolvedConfig.build) == null ? void 0 : _a.ssr))
389
384
  return;
390
- }
391
385
  const isrPages = await execPrerender(resolvedConfig);
392
386
  const fnManifests = await buildApiEndpoints(resolvedConfig);
393
387
  await generateFunctionsManifest(resolvedConfig, fnManifests);
@@ -397,7 +391,7 @@ function vercelPlugin() {
397
391
  };
398
392
  }
399
393
  async function copyDistClientToOutputStatic(resolvedConfig) {
400
- await copyDir(getOutDir(resolvedConfig), getOutput(resolvedConfig, "static"));
394
+ await copyDir(getOutDir(resolvedConfig, "client"), getOutput(resolvedConfig, "static"));
401
395
  }
402
396
  async function cleanOutputDirectory(resolvedConfig) {
403
397
  await import_promises3.default.rm(getOutput(resolvedConfig), {
package/dist/index.mjs CHANGED
@@ -64,108 +64,97 @@ function assert(condition, errorMessage) {
64
64
  }
65
65
 
66
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
- });
67
+ import { z } from "zod";
68
+ var routesManifestRedirectSchema = z.object({
69
+ source: z.string(),
70
+ destination: z.string(),
71
+ statusCode: z.number().refine((n) => [301, 302, 307, 308].includes(n)),
72
+ regex: z.string()
73
+ }).strict();
74
+ var routesManifestHeaderSchema = z.object({
75
+ source: z.string(),
76
+ headers: z.array(z.object({
77
+ key: z.string(),
78
+ value: z.string()
79
+ }).strict()),
80
+ regex: z.string()
81
+ }).strict();
82
+ var routesManifestRewriteSchema = z.object({
83
+ source: z.string(),
84
+ has: z.array(z.object({
85
+ key: z.string(),
86
+ value: z.string(),
87
+ type: z.enum(["header", "cookie", "host", "query"])
88
+ }).strict()).optional(),
89
+ destination: z.string(),
90
+ regex: z.string()
91
+ }).strict();
92
+ var routesManifestDynamicRouteSchema = z.object({
93
+ page: z.string(),
94
+ regex: z.string(),
95
+ routeKeys: z.record(z.string()).optional(),
96
+ namedRegex: z.string().optional()
97
+ }).strict();
98
+ var routesManifestSchema = z.object({
99
+ version: z.literal(3),
100
+ basePath: z.string().regex(/^\/.*/),
101
+ pages404: z.boolean(),
102
+ redirects: z.array(routesManifestRedirectSchema).optional(),
103
+ headers: z.array(routesManifestHeaderSchema).optional(),
104
+ rewrites: z.array(routesManifestRewriteSchema).optional(),
105
+ dynamicRoutes: z.array(routesManifestDynamicRouteSchema).optional()
106
+ }).strict();
112
107
 
113
108
  // 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({
109
+ import { z as z2 } from "zod";
110
+ var functionsManifestSchemaPage = z2.object({
111
+ runtime: z2.string().optional(),
112
+ handler: z2.string().optional(),
113
+ regions: z2.array(z2.string()).optional(),
114
+ maxDuration: z2.number().min(1).max(900).optional(),
115
+ memory: z2.number().min(128).max(3008).optional()
116
+ }).strict();
117
+ var functionsManifestSchemaPageWeb = functionsManifestSchemaPage.omit({
118
+ runtime: true
119
+ }).merge(z2.object({
120
+ runtime: z2.literal("web"),
121
+ env: z2.array(z2.string()),
122
+ files: z2.array(z2.string()),
123
+ name: z2.string(),
124
+ page: z2.string(),
125
+ regexp: z2.string(),
126
+ sortingIndex: z2.number()
127
+ }).strict());
128
+ var functionsManifestSchema = z2.object({
129
+ version: z2.literal(1),
130
+ pages: z2.object({
139
131
  "_middleware.js": functionsManifestSchemaPageWeb.optional()
140
- }).and(record2(myzod2.intersection(myzod2.partial(myzod2.omit(functionsManifestSchemaPageWeb, ["runtime"])), functionsManifestSchemaPage)))
132
+ }).and(z2.record(z2.intersection(functionsManifestSchemaPageWeb.omit({
133
+ runtime: true
134
+ }).partial(), functionsManifestSchemaPage)))
141
135
  });
142
136
 
143
137
  // 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
- });
138
+ import { z as z3 } from "zod";
139
+ var prerenderManifestSchemaRoute = z3.object({
140
+ initialRevalidateSeconds: z3.number(),
141
+ srcRoute: z3.string(),
142
+ dataRoute: z3.string()
143
+ }).strict();
144
+ var prerenderManifestSchemaDynamicRoute = z3.object({
145
+ routeRegex: z3.string(),
146
+ fallback: z3.string().or(z3.null()),
147
+ dataRoute: z3.string(),
148
+ dataRouteRegex: z3.string()
149
+ }).strict();
150
+ var prerenderManifestSchema = z3.object({
151
+ version: z3.literal(3),
152
+ routes: z3.record(prerenderManifestSchemaRoute),
153
+ dynamicRoutes: z3.record(prerenderManifestSchemaDynamicRoute),
154
+ preview: z3.object({
155
+ previewModeId: z3.string().or(z3.null())
156
+ }).strict()
157
+ }).strict();
169
158
 
170
159
  // src/manifests.ts
171
160
  function getPrerenderManifest(resolvedConfig, isrPages) {
@@ -182,14 +171,17 @@ function getPrerenderManifest(resolvedConfig, isrPages) {
182
171
  };
183
172
  return acc;
184
173
  }, {});
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) ?? ""
174
+ const dynamicRoutes = Object.entries((isrPages == null ? void 0 : isrPages.dynamicRoutes) ?? {}).reduce((acc, [key, val]) => {
175
+ var _a2;
176
+ const override = (_a2 = prerenderManifestDefault == null ? void 0 : prerenderManifestDefault.dynamicRoutes) == null ? void 0 : _a2[key];
177
+ const routeRegex = (val == null ? void 0 : val.routeRegex) ?? (override == null ? void 0 : override.routeRegex);
178
+ const fallback = (val == null ? void 0 : val.fallback) === null || typeof (val == null ? void 0 : val.fallback) === "string" ? val == null ? void 0 : val.fallback : (override == null ? void 0 : override.fallback) === null || typeof (override == null ? void 0 : override.fallback) === "string" ? override == null ? void 0 : override.fallback : null;
179
+ assert(routeRegex, `\`[prerender-manifest] { routeRegex }\` is required for route ${key}`);
180
+ acc[key] = {
181
+ routeRegex,
182
+ fallback,
183
+ dataRoute: (val == null ? void 0 : val.dataRoute) ?? (override == null ? void 0 : override.dataRoute) ?? "",
184
+ dataRouteRegex: (val == null ? void 0 : val.dataRouteRegex) ?? (override == null ? void 0 : override.dataRouteRegex) ?? ""
193
185
  };
194
186
  return acc;
195
187
  }, {});
@@ -200,8 +192,6 @@ function getPrerenderManifest(resolvedConfig, isrPages) {
200
192
  preview: {
201
193
  previewModeId: ((_b = prerenderManifestDefault == null ? void 0 : prerenderManifestDefault.preview) == null ? void 0 : _b.previewModeId) ?? null
202
194
  }
203
- }, {
204
- collectErrors: true
205
195
  });
206
196
  }
207
197
  function getPrerenderManifestDestination(resolvedConfig) {
@@ -211,12 +201,16 @@ function getRoutesManifest(resolvedConfig, ssr) {
211
201
  var _a;
212
202
  const routesManifest = (_a = resolvedConfig.vercel) == null ? void 0 : _a.routesManifest;
213
203
  const allRewrites = [
214
- ...(ssr == null ? void 0 : ssr.rewrites) ?? [],
215
- ...(routesManifest == null ? void 0 : routesManifest.rewrites) ?? []
204
+ ...(routesManifest == null ? void 0 : routesManifest.rewrites) ?? [],
205
+ ...(ssr == null ? void 0 : ssr.rewrites) ?? []
216
206
  ];
217
207
  const allDynamicRoutes = [
218
- ...(ssr == null ? void 0 : ssr.dynamicRoutes) ?? [],
219
- ...(routesManifest == null ? void 0 : routesManifest.dynamicRoutes) ?? []
208
+ ...(routesManifest == null ? void 0 : routesManifest.dynamicRoutes) ?? [],
209
+ ...(ssr == null ? void 0 : ssr.dynamicRoutes) ?? []
210
+ ];
211
+ const allHeaders = [
212
+ ...(routesManifest == null ? void 0 : routesManifest.headers) ?? [],
213
+ ...(ssr == null ? void 0 : ssr.headers) ?? []
220
214
  ];
221
215
  return routesManifestSchema.parse({
222
216
  version: 3,
@@ -225,9 +219,7 @@ function getRoutesManifest(resolvedConfig, ssr) {
225
219
  dynamicRoutes: allDynamicRoutes.length > 0 ? allDynamicRoutes : void 0,
226
220
  rewrites: allRewrites.length > 0 ? allRewrites : void 0,
227
221
  redirects: routesManifest == null ? void 0 : routesManifest.redirects,
228
- headers: routesManifest == null ? void 0 : routesManifest.headers
229
- }, {
230
- collectErrors: true
222
+ headers: allHeaders.length > 0 ? allHeaders : void 0
231
223
  });
232
224
  }
233
225
  function getRoutesManifestDestination(resolvedConfig) {
@@ -237,8 +229,6 @@ function getFunctionsManifest(pages) {
237
229
  return functionsManifestSchema.parse({
238
230
  version: 1,
239
231
  pages
240
- }, {
241
- collectErrors: true
242
232
  });
243
233
  }
244
234
  function getFunctionsManifestDestination(resolvedConfig) {
@@ -345,20 +335,24 @@ function vercelPlugin() {
345
335
  return {
346
336
  apply: "build",
347
337
  name: "vite-plugin-vercel",
338
+ enforce: "post",
348
339
  configResolved(config) {
349
340
  resolvedConfig = config;
350
341
  },
351
342
  async buildStart() {
352
- if (resolvedConfig.build.ssr)
353
- return;
354
- await cleanOutputDirectory(resolvedConfig);
343
+ if (process.env.VERCEL_ENV === "production" && !process.env.ENABLE_FILE_SYSTEM_API) {
344
+ throw new Error("Missing ENABLE_FILE_SYSTEM_API=1 to your environment variables in your project settings");
345
+ }
346
+ if (!resolvedConfig.build.ssr) {
347
+ await cleanOutputDirectory(resolvedConfig);
348
+ } else {
349
+ await copyDistClientToOutputStatic(resolvedConfig);
350
+ }
355
351
  },
356
352
  async writeBundle() {
357
353
  var _a;
358
- if (!((_a = resolvedConfig.build) == null ? void 0 : _a.ssr)) {
359
- await copyDistClientToOutputStatic(resolvedConfig);
354
+ if (!((_a = resolvedConfig.build) == null ? void 0 : _a.ssr))
360
355
  return;
361
- }
362
356
  const isrPages = await execPrerender(resolvedConfig);
363
357
  const fnManifests = await buildApiEndpoints(resolvedConfig);
364
358
  await generateFunctionsManifest(resolvedConfig, fnManifests);
@@ -368,7 +362,7 @@ function vercelPlugin() {
368
362
  };
369
363
  }
370
364
  async function copyDistClientToOutputStatic(resolvedConfig) {
371
- await copyDir(getOutDir(resolvedConfig), getOutput(resolvedConfig, "static"));
365
+ await copyDir(getOutDir(resolvedConfig, "client"), getOutput(resolvedConfig, "static"));
372
366
  }
373
367
  async function cleanOutputDirectory(resolvedConfig) {
374
368
  await fs3.rm(getOutput(resolvedConfig), {
package/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- import { ViteVercelConfig } from './src/types';
1
+ import { ViteVercelConfig } from './dist';
2
2
 
3
3
  export * from './dist';
4
- export * from './src/types';
5
4
  export { default } from './dist';
6
5
 
7
6
  declare module 'vite' {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-vercel",
3
- "version": "0.0.1",
3
+ "version": "0.0.4",
4
4
  "module": "./dist/index.mjs",
5
5
  "files": [
6
6
  "dist",
@@ -34,7 +34,7 @@
34
34
  "@brillout/libassert": "^0.5.4",
35
35
  "esbuild": "^0.14.25",
36
36
  "fast-glob": "^3.2.11",
37
- "myzod": "^1.8.7"
37
+ "zod": "^3.14.2"
38
38
  },
39
39
  "scripts": {
40
40
  "build": "tsup",