vite-plugin-vercel 0.1.4 → 0.1.5

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/README.md CHANGED
@@ -14,7 +14,7 @@ Its purpose is to help you bundle your application in `.vercel` folder as suppor
14
14
  - see [`additionalEndpoints` config](/packages/vercel/src/types.ts#L54)
15
15
  - [x] [ISR/Prerender functions support](https://vercel.com/docs/build-output-api/v3#vercel-primitives/prerender-functions)
16
16
  - see [`isr` config](/packages/vercel/src/types.ts#L81). Also see implementation of [vite-plugin-ssr](/packages/vite-plugin-ssr/vite-plugin-ssr.ts) for example
17
- - [ ] [Edge functions support](https://vercel.com/docs/build-output-api/v3#vercel-primitives/edge-functions)
17
+ - [x] [Edge functions support](https://vercel.com/docs/build-output-api/v3#vercel-primitives/edge-functions)
18
18
  - [ ] [Images optimization support](https://vercel.com/docs/build-output-api/v3#build-output-configuration/supported-properties/images)
19
19
  - [ ] [Preview mode support](https://vercel.com/docs/build-output-api/v3#features/preview-mode)
20
20
  - [x] [Advanced config override](/packages/vercel/src/types.ts#L15)
package/dist/index.cjs CHANGED
@@ -17,7 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  }
18
18
  return to;
19
19
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
21
24
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
25
 
23
26
  // src/index.ts
@@ -36,7 +39,11 @@ function getRoot(config) {
36
39
  }
37
40
  function getOutput(config, suffix) {
38
41
  var _a, _b;
39
- return import_path.default.join(((_a = config.vercel) == null ? void 0 : _a.outDir) ? "" : getRoot(config), ((_b = config.vercel) == null ? void 0 : _b.outDir) ?? ".vercel/output", suffix ?? "");
42
+ return import_path.default.join(
43
+ ((_a = config.vercel) == null ? void 0 : _a.outDir) ? "" : getRoot(config),
44
+ ((_b = config.vercel) == null ? void 0 : _b.outDir) ?? ".vercel/output",
45
+ suffix ?? ""
46
+ );
40
47
  }
41
48
  function getPublic(config) {
42
49
  return import_path.default.join(getRoot(config), config.publicDir || "public");
@@ -51,60 +58,64 @@ var import_path2 = __toESM(require("path"), 1);
51
58
 
52
59
  // src/schemas/config/config.ts
53
60
  var import_zod = require("zod");
54
- var HasOrMissing = import_zod.z.array(import_zod.z.union([
55
- import_zod.z.object({
56
- type: import_zod.z.literal("host"),
57
- value: import_zod.z.string()
58
- }).strict(),
59
- import_zod.z.object({
60
- type: import_zod.z.literal("header"),
61
- key: import_zod.z.string(),
62
- value: import_zod.z.string().optional()
63
- }).strict(),
64
- import_zod.z.object({
65
- type: import_zod.z.literal("cookie"),
66
- key: import_zod.z.string(),
67
- value: import_zod.z.string().optional()
68
- }).strict(),
69
- import_zod.z.object({
70
- type: import_zod.z.literal("query"),
71
- key: import_zod.z.string(),
72
- value: import_zod.z.string().optional()
73
- }).strict()
74
- ])).optional();
75
- var vercelOutputConfigSchema = import_zod.z.object({
76
- version: import_zod.z.literal(3),
77
- routes: import_zod.z.array(import_zod.z.union([
61
+ var HasOrMissing = import_zod.z.array(
62
+ import_zod.z.union([
63
+ import_zod.z.object({
64
+ type: import_zod.z.literal("host"),
65
+ value: import_zod.z.string()
66
+ }).strict(),
67
+ import_zod.z.object({
68
+ type: import_zod.z.literal("header"),
69
+ key: import_zod.z.string(),
70
+ value: import_zod.z.string().optional()
71
+ }).strict(),
78
72
  import_zod.z.object({
79
- src: import_zod.z.string(),
80
- dest: import_zod.z.string().optional(),
81
- headers: import_zod.z.record(import_zod.z.string()).optional(),
82
- methods: import_zod.z.array(import_zod.z.string()).optional(),
83
- status: import_zod.z.number().int().positive().optional(),
84
- continue: import_zod.z.boolean().optional(),
85
- check: import_zod.z.boolean().optional(),
86
- missing: HasOrMissing,
87
- has: HasOrMissing,
88
- locale: import_zod.z.object({
89
- redirect: import_zod.z.record(import_zod.z.string()).optional(),
90
- cookie: import_zod.z.string().optional()
91
- }).strict().optional(),
92
- middlewarePath: import_zod.z.string().optional()
73
+ type: import_zod.z.literal("cookie"),
74
+ key: import_zod.z.string(),
75
+ value: import_zod.z.string().optional()
93
76
  }).strict(),
94
77
  import_zod.z.object({
95
- handle: import_zod.z.union([
96
- import_zod.z.literal("rewrite"),
97
- import_zod.z.literal("filesystem"),
98
- import_zod.z.literal("resource"),
99
- import_zod.z.literal("miss"),
100
- import_zod.z.literal("hit"),
101
- import_zod.z.literal("error")
102
- ]),
103
- src: import_zod.z.string().optional(),
104
- dest: import_zod.z.string().optional(),
105
- status: import_zod.z.number().optional()
78
+ type: import_zod.z.literal("query"),
79
+ key: import_zod.z.string(),
80
+ value: import_zod.z.string().optional()
106
81
  }).strict()
107
- ])).optional(),
82
+ ])
83
+ ).optional();
84
+ var vercelOutputConfigSchema = import_zod.z.object({
85
+ version: import_zod.z.literal(3),
86
+ routes: import_zod.z.array(
87
+ import_zod.z.union([
88
+ import_zod.z.object({
89
+ src: import_zod.z.string(),
90
+ dest: import_zod.z.string().optional(),
91
+ headers: import_zod.z.record(import_zod.z.string()).optional(),
92
+ methods: import_zod.z.array(import_zod.z.string()).optional(),
93
+ status: import_zod.z.number().int().positive().optional(),
94
+ continue: import_zod.z.boolean().optional(),
95
+ check: import_zod.z.boolean().optional(),
96
+ missing: HasOrMissing,
97
+ has: HasOrMissing,
98
+ locale: import_zod.z.object({
99
+ redirect: import_zod.z.record(import_zod.z.string()).optional(),
100
+ cookie: import_zod.z.string().optional()
101
+ }).strict().optional(),
102
+ middlewarePath: import_zod.z.string().optional()
103
+ }).strict(),
104
+ import_zod.z.object({
105
+ handle: import_zod.z.union([
106
+ import_zod.z.literal("rewrite"),
107
+ import_zod.z.literal("filesystem"),
108
+ import_zod.z.literal("resource"),
109
+ import_zod.z.literal("miss"),
110
+ import_zod.z.literal("hit"),
111
+ import_zod.z.literal("error")
112
+ ]),
113
+ src: import_zod.z.string().optional(),
114
+ dest: import_zod.z.string().optional(),
115
+ status: import_zod.z.number().optional()
116
+ }).strict()
117
+ ])
118
+ ).optional(),
108
119
  images: import_zod.z.object({
109
120
  sizes: import_zod.z.tuple([
110
121
  import_zod.z.number().int().positive(),
@@ -116,14 +127,18 @@ var vercelOutputConfigSchema = import_zod.z.object({
116
127
  dangerouslyAllowSVG: import_zod.z.boolean().optional(),
117
128
  contentSecurityPolicy: import_zod.z.string().optional()
118
129
  }).strict().optional(),
119
- wildcard: import_zod.z.array(import_zod.z.object({
120
- domain: import_zod.z.string(),
121
- value: import_zod.z.string()
122
- }).strict()).optional(),
123
- overrides: import_zod.z.record(import_zod.z.object({
124
- path: import_zod.z.string().optional(),
125
- contentType: import_zod.z.string().optional()
126
- }).strict()).optional(),
130
+ wildcard: import_zod.z.array(
131
+ import_zod.z.object({
132
+ domain: import_zod.z.string(),
133
+ value: import_zod.z.string()
134
+ }).strict()
135
+ ).optional(),
136
+ overrides: import_zod.z.record(
137
+ import_zod.z.object({
138
+ path: import_zod.z.string().optional(),
139
+ contentType: import_zod.z.string().optional()
140
+ }).strict()
141
+ ).optional(),
127
142
  cache: import_zod.z.array(import_zod.z.string()).optional()
128
143
  }).strict();
129
144
 
@@ -155,7 +170,9 @@ function getConfig(resolvedConfig, rewrites, overrides) {
155
170
  throw error;
156
171
  }
157
172
  if (((_g = (_f = resolvedConfig.vercel) == null ? void 0 : _f.config) == null ? void 0 : _g.routes) && resolvedConfig.vercel.config.routes.length > 0) {
158
- console.warn("It is discouraged to use `vercel.config.routes` to override routes. Prefer using `vercel.rewrites` and `vercel.redirects`.");
173
+ console.warn(
174
+ "It is discouraged to use `vercel.config.routes` to override routes. Prefer using `vercel.rewrites` and `vercel.redirects`."
175
+ );
159
176
  }
160
177
  return vercelOutputConfigSchema.parse({
161
178
  version: 3,
@@ -174,7 +191,15 @@ function getConfigDestination(resolvedConfig) {
174
191
  return import_path2.default.join(getOutput(resolvedConfig), "config.json");
175
192
  }
176
193
  async function writeConfig(resolvedConfig, rewrites, overrides) {
177
- await import_promises.default.writeFile(getConfigDestination(resolvedConfig), JSON.stringify(getConfig(resolvedConfig, rewrites, overrides), void 0, 2), "utf-8");
194
+ await import_promises.default.writeFile(
195
+ getConfigDestination(resolvedConfig),
196
+ JSON.stringify(
197
+ getConfig(resolvedConfig, rewrites, overrides),
198
+ void 0,
199
+ 2
200
+ ),
201
+ "utf-8"
202
+ );
178
203
  }
179
204
 
180
205
  // src/build.ts
@@ -233,11 +258,17 @@ function getAdditionalEndpoints(resolvedConfig) {
233
258
  function getEntries(resolvedConfig) {
234
259
  const apiEntries = import_fast_glob.default.sync(`${getRoot(resolvedConfig)}/api/**/*.*([a-zA-Z0-9])`).filter((filepath) => !import_path3.default.basename(filepath).startsWith("_"));
235
260
  if (apiEntries.length > 0) {
236
- console.warn("@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.");
261
+ console.warn(
262
+ "@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."
263
+ );
237
264
  }
238
265
  const otherApiEntries = import_fast_glob.default.sync(`${getRoot(resolvedConfig)}/_api/**/*.*([a-zA-Z0-9])`).filter((filepath) => !import_path3.default.basename(filepath).startsWith("_"));
239
266
  return [...apiEntries, ...otherApiEntries].reduce((entryPoints, filePath) => {
240
- const outFilePath = pathRelativeTo(filePath, resolvedConfig, filePath.includes("/_api/") ? "_api" : "api");
267
+ const outFilePath = pathRelativeTo(
268
+ filePath,
269
+ resolvedConfig,
270
+ filePath.includes("/_api/") ? "_api" : "api"
271
+ );
241
272
  const parsed = import_path3.default.parse(outFilePath);
242
273
  entryPoints.push({
243
274
  source: filePath,
@@ -256,8 +287,15 @@ var standardBuildOptions = {
256
287
  minify: true
257
288
  };
258
289
  async function buildFn(resolvedConfig, entry, buildOptions) {
259
- assert(entry.destination.length > 0, `Endpoint ${typeof entry.source === "string" ? entry.source : "-"} does not have build destination`);
260
- const outfile = import_path3.default.join(getOutput(resolvedConfig, "functions"), entry.destination, "index.js");
290
+ assert(
291
+ entry.destination.length > 0,
292
+ `Endpoint ${typeof entry.source === "string" ? entry.source : "-"} does not have build destination`
293
+ );
294
+ const outfile = import_path3.default.join(
295
+ getOutput(resolvedConfig, "functions"),
296
+ entry.destination,
297
+ "index.js"
298
+ );
261
299
  const options = Object.assign({}, standardBuildOptions, { outfile });
262
300
  if (buildOptions) {
263
301
  Object.assign(options, buildOptions);
@@ -266,24 +304,47 @@ async function buildFn(resolvedConfig, entry, buildOptions) {
266
304
  if (typeof entry.source === "string") {
267
305
  options.entryPoints = [entry.source];
268
306
  } else {
269
- assert(typeof entry.source === "object", `\`{ source }\` must be a string or an object`);
270
- assert(typeof entry.source.contents === "string", `\`{ contents }\` must be a string`);
307
+ assert(
308
+ typeof entry.source === "object",
309
+ `\`{ source }\` must be a string or an object`
310
+ );
311
+ assert(
312
+ typeof entry.source.contents === "string",
313
+ `\`{ contents }\` must be a string`
314
+ );
271
315
  options.stdin = entry.source;
272
316
  }
273
317
  }
274
318
  await (0, import_esbuild.build)(options);
275
- await writeVcConfig(resolvedConfig, entry.destination);
319
+ await writeVcConfig(resolvedConfig, entry.destination, Boolean(entry.edge));
276
320
  }
277
- async function writeVcConfig(resolvedConfig, destination) {
321
+ async function writeVcConfig(resolvedConfig, destination, edge) {
278
322
  var _a;
279
- const vcConfig = import_path3.default.join(getOutput(resolvedConfig, "functions"), destination, ".vc-config.json");
280
- await import_promises2.default.writeFile(vcConfig, JSON.stringify(vercelOutputVcConfigSchema.parse({
281
- runtime: "nodejs16.x",
282
- handler: "index.js",
283
- maxDuration: (_a = resolvedConfig.vercel) == null ? void 0 : _a.defaultMaxDuration,
284
- launcherType: "Nodejs",
285
- shouldAddHelpers: true
286
- }), void 0, 2), "utf-8");
323
+ const vcConfig = import_path3.default.join(
324
+ getOutput(resolvedConfig, "functions"),
325
+ destination,
326
+ ".vc-config.json"
327
+ );
328
+ await import_promises2.default.writeFile(
329
+ vcConfig,
330
+ JSON.stringify(
331
+ vercelOutputVcConfigSchema.parse(
332
+ edge ? {
333
+ runtime: "edge",
334
+ entrypoint: "index.js"
335
+ } : {
336
+ runtime: "nodejs16.x",
337
+ handler: "index.js",
338
+ maxDuration: (_a = resolvedConfig.vercel) == null ? void 0 : _a.defaultMaxDuration,
339
+ launcherType: "Nodejs",
340
+ shouldAddHelpers: true
341
+ }
342
+ ),
343
+ void 0,
344
+ 2
345
+ ),
346
+ "utf-8"
347
+ );
287
348
  }
288
349
  function getSourceAndDestination(destination) {
289
350
  if (destination.startsWith("api/")) {
@@ -328,19 +389,42 @@ function execPrerender(resolvedConfig) {
328
389
  var group = 1;
329
390
  async function writePrerenderConfig(resolvedConfig, destination, isr) {
330
391
  const parsed = import_path4.default.parse(destination);
331
- const outfile = import_path4.default.join(getOutput(resolvedConfig, "functions"), parsed.dir, parsed.name + ".prerender-config.json");
332
- await import_promises3.default.mkdir(import_path4.default.join(getOutput(resolvedConfig, "functions"), parsed.dir), { recursive: true });
333
- await import_promises3.default.writeFile(outfile, JSON.stringify(vercelOutputPrerenderConfigSchema.parse({
334
- group: group++,
335
- ...isr
336
- }), void 0, 2), "utf-8");
392
+ const outfile = import_path4.default.join(
393
+ getOutput(resolvedConfig, "functions"),
394
+ parsed.dir,
395
+ parsed.name + ".prerender-config.json"
396
+ );
397
+ await import_promises3.default.mkdir(
398
+ import_path4.default.join(getOutput(resolvedConfig, "functions"), parsed.dir),
399
+ { recursive: true }
400
+ );
401
+ await import_promises3.default.writeFile(
402
+ outfile,
403
+ JSON.stringify(
404
+ vercelOutputPrerenderConfigSchema.parse({
405
+ group: group++,
406
+ ...isr
407
+ }),
408
+ void 0,
409
+ 2
410
+ ),
411
+ "utf-8"
412
+ );
337
413
  }
338
414
  function getPrerenderSymlinkInfo(resolvedConfig, destination, target) {
339
415
  const parsed = import_path4.default.parse(destination);
340
416
  const targetParsed = import_path4.default.parse(target);
341
417
  return {
342
- target: import_path4.default.join(getOutput(resolvedConfig, "functions"), targetParsed.dir, targetParsed.name + ".func"),
343
- link: import_path4.default.join(getOutput(resolvedConfig, "functions"), parsed.dir, parsed.name + ".func")
418
+ target: import_path4.default.join(
419
+ getOutput(resolvedConfig, "functions"),
420
+ targetParsed.dir,
421
+ targetParsed.name + ".func"
422
+ ),
423
+ link: import_path4.default.join(
424
+ getOutput(resolvedConfig, "functions"),
425
+ parsed.dir,
426
+ parsed.name + ".func"
427
+ )
344
428
  };
345
429
  }
346
430
  async function buildPrerenderConfigs(resolvedConfig) {
@@ -350,7 +434,11 @@ async function buildPrerenderConfigs(resolvedConfig) {
350
434
  for (const [destination, { symlink, route, ...isr2 }] of entries) {
351
435
  await writePrerenderConfig(resolvedConfig, destination, isr2);
352
436
  if (symlink) {
353
- const info = getPrerenderSymlinkInfo(resolvedConfig, destination, symlink);
437
+ const info = getPrerenderSymlinkInfo(
438
+ resolvedConfig,
439
+ destination,
440
+ symlink
441
+ );
354
442
  await copyDir(info.target, info.link);
355
443
  }
356
444
  if (route) {
@@ -393,7 +481,9 @@ function vercelPlugin() {
393
481
  },
394
482
  async buildStart() {
395
483
  if (process.env.VERCEL_ENV === "production" && !process.env.ENABLE_VC_BUILD) {
396
- throw new Error("Missing ENABLE_VC_BUILD=1 to your environment variables in your project settings");
484
+ throw new Error(
485
+ "Missing ENABLE_VC_BUILD=1 to your environment variables in your project settings"
486
+ );
397
487
  }
398
488
  },
399
489
  async writeBundle() {
@@ -424,7 +514,9 @@ async function computeStaticHtmlOverrides(resolvedConfig) {
424
514
  const files = await getStaticHtmlFiles(staticAbsolutePath);
425
515
  const publicDir = getPublic(resolvedConfig);
426
516
  const publicFiles = await getStaticHtmlFiles(publicDir);
427
- files.push(...publicFiles.map((f) => f.replace(publicDir, staticAbsolutePath)));
517
+ files.push(
518
+ ...publicFiles.map((f) => f.replace(publicDir, staticAbsolutePath))
519
+ );
428
520
  return files.reduce((acc, curr) => {
429
521
  const relPath = import_path5.default.relative(staticAbsolutePath, curr);
430
522
  const parsed = import_path5.default.parse(relPath);
package/dist/index.d.ts CHANGED
@@ -592,7 +592,7 @@ interface ViteVercelConfig {
592
592
  */
593
593
  isr?: Record<string, VercelOutputIsr> | (() => Promise<Record<string, VercelOutputIsr>> | Record<string, VercelOutputIsr>);
594
594
  /**
595
- * Defaults to `.vercel/output`. Mostly useful for testing prupose
595
+ * Defaults to `.vercel/output`. Mostly useful for testing purpose
596
596
  * @protected
597
597
  */
598
598
  outDir?: string;
@@ -624,6 +624,10 @@ interface ViteVercelApiEntry {
624
624
  * Set to `false` to disable
625
625
  */
626
626
  addRoute?: boolean;
627
+ /**
628
+ * Set to `true` to mark this function as an Edge Function
629
+ */
630
+ edge?: boolean;
627
631
  }
628
632
 
629
633
  declare function allPlugins(): Plugin[];
package/dist/index.js CHANGED
@@ -9,7 +9,11 @@ function getRoot(config) {
9
9
  }
10
10
  function getOutput(config, suffix) {
11
11
  var _a, _b;
12
- return path.join(((_a = config.vercel) == null ? void 0 : _a.outDir) ? "" : getRoot(config), ((_b = config.vercel) == null ? void 0 : _b.outDir) ?? ".vercel/output", suffix ?? "");
12
+ return path.join(
13
+ ((_a = config.vercel) == null ? void 0 : _a.outDir) ? "" : getRoot(config),
14
+ ((_b = config.vercel) == null ? void 0 : _b.outDir) ?? ".vercel/output",
15
+ suffix ?? ""
16
+ );
13
17
  }
14
18
  function getPublic(config) {
15
19
  return path.join(getRoot(config), config.publicDir || "public");
@@ -24,60 +28,64 @@ import path2 from "path";
24
28
 
25
29
  // src/schemas/config/config.ts
26
30
  import { z } from "zod";
27
- var HasOrMissing = z.array(z.union([
28
- z.object({
29
- type: z.literal("host"),
30
- value: z.string()
31
- }).strict(),
32
- z.object({
33
- type: z.literal("header"),
34
- key: z.string(),
35
- value: z.string().optional()
36
- }).strict(),
37
- z.object({
38
- type: z.literal("cookie"),
39
- key: z.string(),
40
- value: z.string().optional()
41
- }).strict(),
42
- z.object({
43
- type: z.literal("query"),
44
- key: z.string(),
45
- value: z.string().optional()
46
- }).strict()
47
- ])).optional();
48
- var vercelOutputConfigSchema = z.object({
49
- version: z.literal(3),
50
- routes: z.array(z.union([
31
+ var HasOrMissing = z.array(
32
+ z.union([
33
+ z.object({
34
+ type: z.literal("host"),
35
+ value: z.string()
36
+ }).strict(),
37
+ z.object({
38
+ type: z.literal("header"),
39
+ key: z.string(),
40
+ value: z.string().optional()
41
+ }).strict(),
51
42
  z.object({
52
- src: z.string(),
53
- dest: z.string().optional(),
54
- headers: z.record(z.string()).optional(),
55
- methods: z.array(z.string()).optional(),
56
- status: z.number().int().positive().optional(),
57
- continue: z.boolean().optional(),
58
- check: z.boolean().optional(),
59
- missing: HasOrMissing,
60
- has: HasOrMissing,
61
- locale: z.object({
62
- redirect: z.record(z.string()).optional(),
63
- cookie: z.string().optional()
64
- }).strict().optional(),
65
- middlewarePath: z.string().optional()
43
+ type: z.literal("cookie"),
44
+ key: z.string(),
45
+ value: z.string().optional()
66
46
  }).strict(),
67
47
  z.object({
68
- handle: z.union([
69
- z.literal("rewrite"),
70
- z.literal("filesystem"),
71
- z.literal("resource"),
72
- z.literal("miss"),
73
- z.literal("hit"),
74
- z.literal("error")
75
- ]),
76
- src: z.string().optional(),
77
- dest: z.string().optional(),
78
- status: z.number().optional()
48
+ type: z.literal("query"),
49
+ key: z.string(),
50
+ value: z.string().optional()
79
51
  }).strict()
80
- ])).optional(),
52
+ ])
53
+ ).optional();
54
+ var vercelOutputConfigSchema = z.object({
55
+ version: z.literal(3),
56
+ routes: z.array(
57
+ z.union([
58
+ z.object({
59
+ src: z.string(),
60
+ dest: z.string().optional(),
61
+ headers: z.record(z.string()).optional(),
62
+ methods: z.array(z.string()).optional(),
63
+ status: z.number().int().positive().optional(),
64
+ continue: z.boolean().optional(),
65
+ check: z.boolean().optional(),
66
+ missing: HasOrMissing,
67
+ has: HasOrMissing,
68
+ locale: z.object({
69
+ redirect: z.record(z.string()).optional(),
70
+ cookie: z.string().optional()
71
+ }).strict().optional(),
72
+ middlewarePath: z.string().optional()
73
+ }).strict(),
74
+ z.object({
75
+ handle: z.union([
76
+ z.literal("rewrite"),
77
+ z.literal("filesystem"),
78
+ z.literal("resource"),
79
+ z.literal("miss"),
80
+ z.literal("hit"),
81
+ z.literal("error")
82
+ ]),
83
+ src: z.string().optional(),
84
+ dest: z.string().optional(),
85
+ status: z.number().optional()
86
+ }).strict()
87
+ ])
88
+ ).optional(),
81
89
  images: z.object({
82
90
  sizes: z.tuple([
83
91
  z.number().int().positive(),
@@ -89,14 +97,18 @@ var vercelOutputConfigSchema = z.object({
89
97
  dangerouslyAllowSVG: z.boolean().optional(),
90
98
  contentSecurityPolicy: z.string().optional()
91
99
  }).strict().optional(),
92
- wildcard: z.array(z.object({
93
- domain: z.string(),
94
- value: z.string()
95
- }).strict()).optional(),
96
- overrides: z.record(z.object({
97
- path: z.string().optional(),
98
- contentType: z.string().optional()
99
- }).strict()).optional(),
100
+ wildcard: z.array(
101
+ z.object({
102
+ domain: z.string(),
103
+ value: z.string()
104
+ }).strict()
105
+ ).optional(),
106
+ overrides: z.record(
107
+ z.object({
108
+ path: z.string().optional(),
109
+ contentType: z.string().optional()
110
+ }).strict()
111
+ ).optional(),
100
112
  cache: z.array(z.string()).optional()
101
113
  }).strict();
102
114
 
@@ -128,7 +140,9 @@ function getConfig(resolvedConfig, rewrites, overrides) {
128
140
  throw error;
129
141
  }
130
142
  if (((_g = (_f = resolvedConfig.vercel) == null ? void 0 : _f.config) == null ? void 0 : _g.routes) && resolvedConfig.vercel.config.routes.length > 0) {
131
- console.warn("It is discouraged to use `vercel.config.routes` to override routes. Prefer using `vercel.rewrites` and `vercel.redirects`.");
143
+ console.warn(
144
+ "It is discouraged to use `vercel.config.routes` to override routes. Prefer using `vercel.rewrites` and `vercel.redirects`."
145
+ );
132
146
  }
133
147
  return vercelOutputConfigSchema.parse({
134
148
  version: 3,
@@ -147,7 +161,15 @@ function getConfigDestination(resolvedConfig) {
147
161
  return path2.join(getOutput(resolvedConfig), "config.json");
148
162
  }
149
163
  async function writeConfig(resolvedConfig, rewrites, overrides) {
150
- await fs.writeFile(getConfigDestination(resolvedConfig), JSON.stringify(getConfig(resolvedConfig, rewrites, overrides), void 0, 2), "utf-8");
164
+ await fs.writeFile(
165
+ getConfigDestination(resolvedConfig),
166
+ JSON.stringify(
167
+ getConfig(resolvedConfig, rewrites, overrides),
168
+ void 0,
169
+ 2
170
+ ),
171
+ "utf-8"
172
+ );
151
173
  }
152
174
 
153
175
  // src/build.ts
@@ -206,11 +228,17 @@ function getAdditionalEndpoints(resolvedConfig) {
206
228
  function getEntries(resolvedConfig) {
207
229
  const apiEntries = glob.sync(`${getRoot(resolvedConfig)}/api/**/*.*([a-zA-Z0-9])`).filter((filepath) => !path3.basename(filepath).startsWith("_"));
208
230
  if (apiEntries.length > 0) {
209
- console.warn("@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.");
231
+ console.warn(
232
+ "@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."
233
+ );
210
234
  }
211
235
  const otherApiEntries = glob.sync(`${getRoot(resolvedConfig)}/_api/**/*.*([a-zA-Z0-9])`).filter((filepath) => !path3.basename(filepath).startsWith("_"));
212
236
  return [...apiEntries, ...otherApiEntries].reduce((entryPoints, filePath) => {
213
- const outFilePath = pathRelativeTo(filePath, resolvedConfig, filePath.includes("/_api/") ? "_api" : "api");
237
+ const outFilePath = pathRelativeTo(
238
+ filePath,
239
+ resolvedConfig,
240
+ filePath.includes("/_api/") ? "_api" : "api"
241
+ );
214
242
  const parsed = path3.parse(outFilePath);
215
243
  entryPoints.push({
216
244
  source: filePath,
@@ -229,8 +257,15 @@ var standardBuildOptions = {
229
257
  minify: true
230
258
  };
231
259
  async function buildFn(resolvedConfig, entry, buildOptions) {
232
- assert(entry.destination.length > 0, `Endpoint ${typeof entry.source === "string" ? entry.source : "-"} does not have build destination`);
233
- const outfile = path3.join(getOutput(resolvedConfig, "functions"), entry.destination, "index.js");
260
+ assert(
261
+ entry.destination.length > 0,
262
+ `Endpoint ${typeof entry.source === "string" ? entry.source : "-"} does not have build destination`
263
+ );
264
+ const outfile = path3.join(
265
+ getOutput(resolvedConfig, "functions"),
266
+ entry.destination,
267
+ "index.js"
268
+ );
234
269
  const options = Object.assign({}, standardBuildOptions, { outfile });
235
270
  if (buildOptions) {
236
271
  Object.assign(options, buildOptions);
@@ -239,24 +274,47 @@ async function buildFn(resolvedConfig, entry, buildOptions) {
239
274
  if (typeof entry.source === "string") {
240
275
  options.entryPoints = [entry.source];
241
276
  } else {
242
- assert(typeof entry.source === "object", `\`{ source }\` must be a string or an object`);
243
- assert(typeof entry.source.contents === "string", `\`{ contents }\` must be a string`);
277
+ assert(
278
+ typeof entry.source === "object",
279
+ `\`{ source }\` must be a string or an object`
280
+ );
281
+ assert(
282
+ typeof entry.source.contents === "string",
283
+ `\`{ contents }\` must be a string`
284
+ );
244
285
  options.stdin = entry.source;
245
286
  }
246
287
  }
247
288
  await build(options);
248
- await writeVcConfig(resolvedConfig, entry.destination);
289
+ await writeVcConfig(resolvedConfig, entry.destination, Boolean(entry.edge));
249
290
  }
250
- async function writeVcConfig(resolvedConfig, destination) {
291
+ async function writeVcConfig(resolvedConfig, destination, edge) {
251
292
  var _a;
252
- const vcConfig = path3.join(getOutput(resolvedConfig, "functions"), destination, ".vc-config.json");
253
- await fs2.writeFile(vcConfig, JSON.stringify(vercelOutputVcConfigSchema.parse({
254
- runtime: "nodejs16.x",
255
- handler: "index.js",
256
- maxDuration: (_a = resolvedConfig.vercel) == null ? void 0 : _a.defaultMaxDuration,
257
- launcherType: "Nodejs",
258
- shouldAddHelpers: true
259
- }), void 0, 2), "utf-8");
293
+ const vcConfig = path3.join(
294
+ getOutput(resolvedConfig, "functions"),
295
+ destination,
296
+ ".vc-config.json"
297
+ );
298
+ await fs2.writeFile(
299
+ vcConfig,
300
+ JSON.stringify(
301
+ vercelOutputVcConfigSchema.parse(
302
+ edge ? {
303
+ runtime: "edge",
304
+ entrypoint: "index.js"
305
+ } : {
306
+ runtime: "nodejs16.x",
307
+ handler: "index.js",
308
+ maxDuration: (_a = resolvedConfig.vercel) == null ? void 0 : _a.defaultMaxDuration,
309
+ launcherType: "Nodejs",
310
+ shouldAddHelpers: true
311
+ }
312
+ ),
313
+ void 0,
314
+ 2
315
+ ),
316
+ "utf-8"
317
+ );
260
318
  }
261
319
  function getSourceAndDestination(destination) {
262
320
  if (destination.startsWith("api/")) {
@@ -301,19 +359,42 @@ function execPrerender(resolvedConfig) {
301
359
  var group = 1;
302
360
  async function writePrerenderConfig(resolvedConfig, destination, isr) {
303
361
  const parsed = path4.parse(destination);
304
- const outfile = path4.join(getOutput(resolvedConfig, "functions"), parsed.dir, parsed.name + ".prerender-config.json");
305
- await fs3.mkdir(path4.join(getOutput(resolvedConfig, "functions"), parsed.dir), { recursive: true });
306
- await fs3.writeFile(outfile, JSON.stringify(vercelOutputPrerenderConfigSchema.parse({
307
- group: group++,
308
- ...isr
309
- }), void 0, 2), "utf-8");
362
+ const outfile = path4.join(
363
+ getOutput(resolvedConfig, "functions"),
364
+ parsed.dir,
365
+ parsed.name + ".prerender-config.json"
366
+ );
367
+ await fs3.mkdir(
368
+ path4.join(getOutput(resolvedConfig, "functions"), parsed.dir),
369
+ { recursive: true }
370
+ );
371
+ await fs3.writeFile(
372
+ outfile,
373
+ JSON.stringify(
374
+ vercelOutputPrerenderConfigSchema.parse({
375
+ group: group++,
376
+ ...isr
377
+ }),
378
+ void 0,
379
+ 2
380
+ ),
381
+ "utf-8"
382
+ );
310
383
  }
311
384
  function getPrerenderSymlinkInfo(resolvedConfig, destination, target) {
312
385
  const parsed = path4.parse(destination);
313
386
  const targetParsed = path4.parse(target);
314
387
  return {
315
- target: path4.join(getOutput(resolvedConfig, "functions"), targetParsed.dir, targetParsed.name + ".func"),
316
- link: path4.join(getOutput(resolvedConfig, "functions"), parsed.dir, parsed.name + ".func")
388
+ target: path4.join(
389
+ getOutput(resolvedConfig, "functions"),
390
+ targetParsed.dir,
391
+ targetParsed.name + ".func"
392
+ ),
393
+ link: path4.join(
394
+ getOutput(resolvedConfig, "functions"),
395
+ parsed.dir,
396
+ parsed.name + ".func"
397
+ )
317
398
  };
318
399
  }
319
400
  async function buildPrerenderConfigs(resolvedConfig) {
@@ -323,7 +404,11 @@ async function buildPrerenderConfigs(resolvedConfig) {
323
404
  for (const [destination, { symlink, route, ...isr2 }] of entries) {
324
405
  await writePrerenderConfig(resolvedConfig, destination, isr2);
325
406
  if (symlink) {
326
- const info = getPrerenderSymlinkInfo(resolvedConfig, destination, symlink);
407
+ const info = getPrerenderSymlinkInfo(
408
+ resolvedConfig,
409
+ destination,
410
+ symlink
411
+ );
327
412
  await copyDir(info.target, info.link);
328
413
  }
329
414
  if (route) {
@@ -366,7 +451,9 @@ function vercelPlugin() {
366
451
  },
367
452
  async buildStart() {
368
453
  if (process.env.VERCEL_ENV === "production" && !process.env.ENABLE_VC_BUILD) {
369
- throw new Error("Missing ENABLE_VC_BUILD=1 to your environment variables in your project settings");
454
+ throw new Error(
455
+ "Missing ENABLE_VC_BUILD=1 to your environment variables in your project settings"
456
+ );
370
457
  }
371
458
  },
372
459
  async writeBundle() {
@@ -397,7 +484,9 @@ async function computeStaticHtmlOverrides(resolvedConfig) {
397
484
  const files = await getStaticHtmlFiles(staticAbsolutePath);
398
485
  const publicDir = getPublic(resolvedConfig);
399
486
  const publicFiles = await getStaticHtmlFiles(publicDir);
400
- files.push(...publicFiles.map((f) => f.replace(publicDir, staticAbsolutePath)));
487
+ files.push(
488
+ ...publicFiles.map((f) => f.replace(publicDir, staticAbsolutePath))
489
+ );
401
490
  return files.reduce((acc, curr) => {
402
491
  const relPath = path5.relative(staticAbsolutePath, curr);
403
492
  const parsed = path5.parse(relPath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-vercel",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -23,20 +23,20 @@
23
23
  "vite": "^3.0.0"
24
24
  },
25
25
  "devDependencies": {
26
- "@types/node": "^16.11.45",
27
- "@typescript-eslint/eslint-plugin": "^5.31.0",
28
- "@typescript-eslint/parser": "^5.31.0",
29
- "eslint": "^8.20.0",
30
- "tsup": "^6.2.0",
26
+ "@types/node": "^16.11.47",
27
+ "@typescript-eslint/eslint-plugin": "^5.33.0",
28
+ "@typescript-eslint/parser": "^5.33.0",
29
+ "eslint": "^8.21.0",
30
+ "tsup": "^6.2.1",
31
31
  "typescript": "^4.7.4",
32
- "vite": "^3.0.3"
32
+ "vite": "^3.0.5"
33
33
  },
34
34
  "dependencies": {
35
35
  "@brillout/libassert": "^0.5.8",
36
36
  "@vercel/routing-utils": "^1.13.5",
37
- "esbuild": "^0.14.50",
37
+ "esbuild": "^0.14.54",
38
38
  "fast-glob": "^3.2.11",
39
- "zod": "^3.17.10"
39
+ "zod": "^3.18.0"
40
40
  },
41
41
  "scripts": {
42
42
  "build": "tsup",