vite-plugin-vercel 0.1.2 → 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)
@@ -38,8 +38,7 @@ export default defineConfig({
38
38
 
39
39
  ### Usage with vite-plugin-ssr
40
40
 
41
- [vite-plugin-ssr](https://vite-plugin-ssr.com/) will support this plugin when stable.
42
- In the meantime, you can add experimental support yourself.
41
+ [vite-plugin-ssr](https://vite-plugin-ssr.com/) is supported through [@magne4000/vite-plugin-vercel-ssr](/packages/vite-plugin-ssr/README.md) plugin.
43
42
 
44
43
  Install `@magne4000/vite-plugin-vercel-ssr` package, and update your vite config:
45
44
 
@@ -53,9 +52,6 @@ import vercelSsr from '@magne4000/vite-plugin-vercel-ssr';
53
52
  export default defineConfig(async ({ command, mode }) => {
54
53
  return {
55
54
  plugins: [ssr(), vercel(), vercelSsr()],
56
- build: {
57
- polyfillDynamicImport: false,
58
- },
59
55
  vercel: {
60
56
  // Tweak what you need, check TS definition for details
61
57
  },
package/dist/index.cjs CHANGED
@@ -1,38 +1,10 @@
1
+ "use strict";
1
2
  var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
6
  var __getProtoOf = Object.getPrototypeOf;
9
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
- var __spreadValues = (a, b) => {
13
- for (var prop in b || (b = {}))
14
- if (__hasOwnProp.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- if (__getOwnPropSymbols)
17
- for (var prop of __getOwnPropSymbols(b)) {
18
- if (__propIsEnum.call(b, prop))
19
- __defNormalProp(a, prop, b[prop]);
20
- }
21
- return a;
22
- };
23
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
- var __objRest = (source, exclude) => {
25
- var target = {};
26
- for (var prop in source)
27
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
28
- target[prop] = source[prop];
29
- if (source != null && __getOwnPropSymbols)
30
- for (var prop of __getOwnPropSymbols(source)) {
31
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
32
- target[prop] = source[prop];
33
- }
34
- return target;
35
- };
36
8
  var __export = (target, all) => {
37
9
  for (var name in all)
38
10
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -45,7 +17,10 @@ var __copyProps = (to, from, except, desc) => {
45
17
  }
46
18
  return to;
47
19
  };
48
- 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
+ ));
49
24
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
50
25
 
51
26
  // src/index.ts
@@ -54,37 +29,28 @@ __export(src_exports, {
54
29
  default: () => allPlugins
55
30
  });
56
31
  module.exports = __toCommonJS(src_exports);
57
- var import_promises5 = __toESM(require("fs/promises"), 1);
32
+ var import_promises4 = __toESM(require("fs/promises"), 1);
58
33
 
59
34
  // src/utils.ts
60
35
  var import_vite = require("vite");
61
36
  var import_path = __toESM(require("path"), 1);
62
- var import_promises = __toESM(require("fs/promises"), 1);
63
37
  function getRoot(config) {
64
38
  return (0, import_vite.normalizePath)(config.root || process.cwd());
65
39
  }
66
- function getOutDir(config, force) {
67
- const p = (0, import_vite.normalizePath)(config.build.outDir);
68
- if (!force)
69
- return p;
70
- return import_path.default.join(import_path.default.dirname(p), force);
71
- }
72
40
  function getOutput(config, suffix) {
73
41
  var _a, _b;
74
- 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
+ );
75
47
  }
76
- function pathRelativeToApi(filePath, config) {
77
- const root = getRoot(config);
78
- return (0, import_vite.normalizePath)(import_path.default.relative(import_path.default.join(root, "api"), filePath));
48
+ function getPublic(config) {
49
+ return import_path.default.join(getRoot(config), config.publicDir || "public");
79
50
  }
80
- async function copyDir(src, dest) {
81
- await import_promises.default.mkdir(dest, { recursive: true });
82
- const entries = await import_promises.default.readdir(src, { withFileTypes: true });
83
- for (const entry of entries) {
84
- const srcPath = import_path.default.join(src, entry.name);
85
- const destPath = import_path.default.join(dest, entry.name);
86
- entry.isDirectory() ? await copyDir(srcPath, destPath) : await import_promises.default.copyFile(srcPath, destPath);
87
- }
51
+ function pathRelativeTo(filePath, config, rel) {
52
+ const root = getRoot(config);
53
+ return (0, import_vite.normalizePath)(import_path.default.relative(import_path.default.join(root, rel), filePath));
88
54
  }
89
55
 
90
56
  // src/config.ts
@@ -92,60 +58,64 @@ var import_path2 = __toESM(require("path"), 1);
92
58
 
93
59
  // src/schemas/config/config.ts
94
60
  var import_zod = require("zod");
95
- var HasOrMissing = import_zod.z.array(import_zod.z.union([
96
- import_zod.z.object({
97
- type: import_zod.z.literal("host"),
98
- value: import_zod.z.string()
99
- }).strict(),
100
- import_zod.z.object({
101
- type: import_zod.z.literal("header"),
102
- key: import_zod.z.string(),
103
- value: import_zod.z.string().optional()
104
- }).strict(),
105
- import_zod.z.object({
106
- type: import_zod.z.literal("cookie"),
107
- key: import_zod.z.string(),
108
- value: import_zod.z.string().optional()
109
- }).strict(),
110
- import_zod.z.object({
111
- type: import_zod.z.literal("query"),
112
- key: import_zod.z.string(),
113
- value: import_zod.z.string().optional()
114
- }).strict()
115
- ])).optional();
116
- var vercelOutputConfigSchema = import_zod.z.object({
117
- version: import_zod.z.literal(3),
118
- routes: import_zod.z.array(import_zod.z.union([
61
+ var HasOrMissing = import_zod.z.array(
62
+ import_zod.z.union([
119
63
  import_zod.z.object({
120
- src: import_zod.z.string(),
121
- dest: import_zod.z.string().optional(),
122
- headers: import_zod.z.record(import_zod.z.string()).optional(),
123
- methods: import_zod.z.array(import_zod.z.string()).optional(),
124
- status: import_zod.z.number().int().positive().optional(),
125
- continue: import_zod.z.boolean().optional(),
126
- check: import_zod.z.boolean().optional(),
127
- missing: HasOrMissing,
128
- has: HasOrMissing,
129
- locale: import_zod.z.object({
130
- redirect: import_zod.z.record(import_zod.z.string()).optional(),
131
- cookie: import_zod.z.string().optional()
132
- }).strict().optional(),
133
- middlewarePath: import_zod.z.string().optional()
64
+ type: import_zod.z.literal("host"),
65
+ value: import_zod.z.string()
134
66
  }).strict(),
135
67
  import_zod.z.object({
136
- handle: import_zod.z.union([
137
- import_zod.z.literal("rewrite"),
138
- import_zod.z.literal("filesystem"),
139
- import_zod.z.literal("resource"),
140
- import_zod.z.literal("miss"),
141
- import_zod.z.literal("hit"),
142
- import_zod.z.literal("error")
143
- ]),
144
- src: import_zod.z.string().optional(),
145
- dest: import_zod.z.string().optional(),
146
- status: import_zod.z.number().optional()
68
+ type: import_zod.z.literal("header"),
69
+ key: import_zod.z.string(),
70
+ value: import_zod.z.string().optional()
71
+ }).strict(),
72
+ import_zod.z.object({
73
+ type: import_zod.z.literal("cookie"),
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("query"),
79
+ key: import_zod.z.string(),
80
+ value: import_zod.z.string().optional()
147
81
  }).strict()
148
- ])).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(),
149
119
  images: import_zod.z.object({
150
120
  sizes: import_zod.z.tuple([
151
121
  import_zod.z.number().int().positive(),
@@ -157,43 +127,79 @@ var vercelOutputConfigSchema = import_zod.z.object({
157
127
  dangerouslyAllowSVG: import_zod.z.boolean().optional(),
158
128
  contentSecurityPolicy: import_zod.z.string().optional()
159
129
  }).strict().optional(),
160
- wildcard: import_zod.z.array(import_zod.z.object({
161
- domain: import_zod.z.string(),
162
- value: import_zod.z.string()
163
- }).strict()).optional(),
164
- overrides: import_zod.z.record(import_zod.z.object({
165
- path: import_zod.z.string().optional(),
166
- contentType: import_zod.z.string().optional()
167
- }).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(),
168
142
  cache: import_zod.z.array(import_zod.z.string()).optional()
169
143
  }).strict();
170
144
 
171
145
  // src/config.ts
172
- var import_promises2 = __toESM(require("fs/promises"), 1);
146
+ var import_promises = __toESM(require("fs/promises"), 1);
173
147
  var import_routing_utils = require("@vercel/routing-utils");
174
- function getConfig(resolvedConfig, config) {
175
- var _a, _b, _c, _d, _e;
176
- const { routes } = (0, import_routing_utils.getTransformedRoutes)({
148
+ function reorderEnforce(arr) {
149
+ return [
150
+ ...arr.filter((r) => r.enforce === "pre"),
151
+ ...arr.filter((r) => !r.enforce),
152
+ ...arr.filter((r) => r.enforce === "post")
153
+ ];
154
+ }
155
+ function getConfig(resolvedConfig, rewrites, overrides) {
156
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
157
+ const _rewrites = [
158
+ ...((_a = resolvedConfig.vercel) == null ? void 0 : _a.rewrites) ?? [],
159
+ ...rewrites ?? []
160
+ ];
161
+ const { routes, error } = (0, import_routing_utils.getTransformedRoutes)({
177
162
  nowConfig: {
178
- cleanUrls: true
163
+ cleanUrls: ((_b = resolvedConfig.vercel) == null ? void 0 : _b.cleanUrls) ?? true,
164
+ trailingSlash: (_c = resolvedConfig.vercel) == null ? void 0 : _c.trailingSlash,
165
+ rewrites: reorderEnforce(_rewrites),
166
+ redirects: ((_d = resolvedConfig.vercel) == null ? void 0 : _d.redirects) ? reorderEnforce((_e = resolvedConfig.vercel) == null ? void 0 : _e.redirects) : void 0
179
167
  }
180
168
  });
181
- return vercelOutputConfigSchema.parse(__spreadProps(__spreadValues({
182
- version: 3
183
- }, (_a = resolvedConfig.vercel) == null ? void 0 : _a.config), {
169
+ if (error) {
170
+ throw error;
171
+ }
172
+ if (((_g = (_f = resolvedConfig.vercel) == null ? void 0 : _f.config) == null ? void 0 : _g.routes) && resolvedConfig.vercel.config.routes.length > 0) {
173
+ console.warn(
174
+ "It is discouraged to use `vercel.config.routes` to override routes. Prefer using `vercel.rewrites` and `vercel.redirects`."
175
+ );
176
+ }
177
+ return vercelOutputConfigSchema.parse({
178
+ version: 3,
179
+ ...(_h = resolvedConfig.vercel) == null ? void 0 : _h.config,
184
180
  routes: [
185
181
  ...routes ?? [],
186
- ...(config == null ? void 0 : config.routes) ?? [],
187
- ...((_c = (_b = resolvedConfig.vercel) == null ? void 0 : _b.config) == null ? void 0 : _c.routes) ?? []
182
+ ...((_j = (_i = resolvedConfig.vercel) == null ? void 0 : _i.config) == null ? void 0 : _j.routes) ?? []
188
183
  ],
189
- overrides: __spreadValues(__spreadValues({}, (_e = (_d = resolvedConfig.vercel) == null ? void 0 : _d.config) == null ? void 0 : _e.overrides), config == null ? void 0 : config.overrides)
190
- }));
184
+ overrides: {
185
+ ...(_l = (_k = resolvedConfig.vercel) == null ? void 0 : _k.config) == null ? void 0 : _l.overrides,
186
+ ...overrides
187
+ }
188
+ });
191
189
  }
192
190
  function getConfigDestination(resolvedConfig) {
193
191
  return import_path2.default.join(getOutput(resolvedConfig), "config.json");
194
192
  }
195
- async function writeConfig(resolvedConfig, config) {
196
- await import_promises2.default.writeFile(getConfigDestination(resolvedConfig), JSON.stringify(getConfig(resolvedConfig, config), void 0, 2), "utf-8");
193
+ async function writeConfig(resolvedConfig, rewrites, overrides) {
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
+ );
197
203
  }
198
204
 
199
205
  // src/build.ts
@@ -240,23 +246,35 @@ var vercelOutputVcConfigSchema = import_zod2.z.union([
240
246
  ]);
241
247
 
242
248
  // src/build.ts
243
- var import_promises3 = __toESM(require("fs/promises"), 1);
249
+ var import_promises2 = __toESM(require("fs/promises"), 1);
244
250
  function getAdditionalEndpoints(resolvedConfig) {
245
251
  var _a;
246
- return (((_a = resolvedConfig.vercel) == null ? void 0 : _a.additionalEndpoints) ?? []).map((e) => __spreadProps(__spreadValues({}, e), {
247
- destination: e.destination + ".func"
252
+ return (((_a = resolvedConfig.vercel) == null ? void 0 : _a.additionalEndpoints) ?? []).map((e) => ({
253
+ ...e,
254
+ addRoute: e.addRoute ?? true,
255
+ destination: import_path3.default.resolve("/", e.destination) + ".func"
248
256
  }));
249
257
  }
250
258
  function getEntries(resolvedConfig) {
251
259
  const apiEntries = import_fast_glob.default.sync(`${getRoot(resolvedConfig)}/api/**/*.*([a-zA-Z0-9])`).filter((filepath) => !import_path3.default.basename(filepath).startsWith("_"));
252
- return apiEntries.reduce((entryPoints, filePath) => {
253
- const outFilePath = pathRelativeToApi(filePath, resolvedConfig);
260
+ if (apiEntries.length > 0) {
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
+ );
264
+ }
265
+ const otherApiEntries = import_fast_glob.default.sync(`${getRoot(resolvedConfig)}/_api/**/*.*([a-zA-Z0-9])`).filter((filepath) => !import_path3.default.basename(filepath).startsWith("_"));
266
+ return [...apiEntries, ...otherApiEntries].reduce((entryPoints, filePath) => {
267
+ const outFilePath = pathRelativeTo(
268
+ filePath,
269
+ resolvedConfig,
270
+ filePath.includes("/_api/") ? "_api" : "api"
271
+ );
254
272
  const parsed = import_path3.default.parse(outFilePath);
255
- const entry = {
273
+ entryPoints.push({
256
274
  source: filePath,
257
- destination: `api/${import_path3.default.posix.join(parsed.dir, parsed.name)}.func`
258
- };
259
- entryPoints.push(entry);
275
+ destination: `api/${import_path3.default.posix.join(parsed.dir, parsed.name)}.func`,
276
+ addRoute: true
277
+ });
260
278
  return entryPoints;
261
279
  }, getAdditionalEndpoints(resolvedConfig));
262
280
  }
@@ -269,8 +287,15 @@ var standardBuildOptions = {
269
287
  minify: true
270
288
  };
271
289
  async function buildFn(resolvedConfig, entry, buildOptions) {
272
- assert(entry.destination.length > 0, `Endpoint ${typeof entry.source === "string" ? entry.source : "-"} does not have build destination`);
273
- 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
+ );
274
299
  const options = Object.assign({}, standardBuildOptions, { outfile });
275
300
  if (buildOptions) {
276
301
  Object.assign(options, buildOptions);
@@ -279,30 +304,63 @@ async function buildFn(resolvedConfig, entry, buildOptions) {
279
304
  if (typeof entry.source === "string") {
280
305
  options.entryPoints = [entry.source];
281
306
  } else {
282
- assert(typeof entry.source === "object", `\`{ source }\` must be a string or an object`);
283
- 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
+ );
284
315
  options.stdin = entry.source;
285
316
  }
286
317
  }
287
318
  await (0, import_esbuild.build)(options);
288
- await writeVcConfig(resolvedConfig, entry.destination);
319
+ await writeVcConfig(resolvedConfig, entry.destination, Boolean(entry.edge));
289
320
  }
290
- async function writeVcConfig(resolvedConfig, destination) {
321
+ async function writeVcConfig(resolvedConfig, destination, edge) {
291
322
  var _a;
292
- const vcConfig = import_path3.default.join(getOutput(resolvedConfig, "functions"), destination, ".vc-config.json");
293
- await import_promises3.default.writeFile(vcConfig, JSON.stringify(vercelOutputVcConfigSchema.parse({
294
- runtime: "nodejs16.x",
295
- handler: "index.js",
296
- maxDuration: (_a = resolvedConfig.vercel) == null ? void 0 : _a.defaultMaxDuration,
297
- launcherType: "Nodejs",
298
- shouldAddHelpers: true
299
- }), 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
+ );
348
+ }
349
+ function getSourceAndDestination(destination) {
350
+ if (destination.startsWith("api/")) {
351
+ return import_path3.default.posix.resolve("/", destination);
352
+ }
353
+ return import_path3.default.posix.resolve("/", destination, ":match*");
300
354
  }
301
355
  async function buildEndpoints(resolvedConfig) {
302
356
  const entries = getEntries(resolvedConfig);
303
357
  for (const entry of entries) {
304
358
  await buildFn(resolvedConfig, entry);
305
359
  }
360
+ return entries.filter((e) => e.addRoute !== false).map((e) => e.destination.replace(/\.func$/, "")).map((destination) => ({
361
+ source: getSourceAndDestination(destination),
362
+ destination: getSourceAndDestination(destination)
363
+ }));
306
364
  }
307
365
 
308
366
  // src/prerender.ts
@@ -319,7 +377,7 @@ var vercelOutputPrerenderConfigSchema = import_zod3.z.object({
319
377
  }).strict();
320
378
 
321
379
  // src/prerender.ts
322
- var import_promises4 = __toESM(require("fs/promises"), 1);
380
+ var import_promises3 = __toESM(require("fs/promises"), 1);
323
381
  function execPrerender(resolvedConfig) {
324
382
  var _a;
325
383
  const prerender = (_a = resolvedConfig.vercel) == null ? void 0 : _a.prerender;
@@ -331,40 +389,76 @@ function execPrerender(resolvedConfig) {
331
389
  var group = 1;
332
390
  async function writePrerenderConfig(resolvedConfig, destination, isr) {
333
391
  const parsed = import_path4.default.parse(destination);
334
- const outfile = import_path4.default.join(getOutput(resolvedConfig, "functions"), parsed.dir, parsed.name + ".prerender-config.json");
335
- await import_promises4.default.mkdir(import_path4.default.join(getOutput(resolvedConfig, "functions"), parsed.dir), { recursive: true });
336
- await import_promises4.default.writeFile(outfile, JSON.stringify(vercelOutputPrerenderConfigSchema.parse(__spreadValues({
337
- group: group++
338
- }, isr)), 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
+ );
339
413
  }
340
414
  function getPrerenderSymlinkInfo(resolvedConfig, destination, target) {
341
415
  const parsed = import_path4.default.parse(destination);
342
416
  const targetParsed = import_path4.default.parse(target);
343
417
  return {
344
- target: import_path4.default.join(getOutput(resolvedConfig, "functions"), targetParsed.dir, targetParsed.name + ".func"),
345
- 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
+ )
346
428
  };
347
429
  }
348
430
  async function buildPrerenderConfigs(resolvedConfig) {
349
431
  const isr = await getIsrConfig(resolvedConfig);
350
432
  const entries = Object.entries(isr);
351
433
  const rewrites = [];
352
- for (const _a of entries) {
353
- const [destination, _b] = _a, _c = _b, { symlink, route } = _c, isr2 = __objRest(_c, ["symlink", "route"]);
434
+ for (const [destination, { symlink, route, ...isr2 }] of entries) {
354
435
  await writePrerenderConfig(resolvedConfig, destination, isr2);
355
436
  if (symlink) {
356
- const info = getPrerenderSymlinkInfo(resolvedConfig, destination, symlink);
437
+ const info = getPrerenderSymlinkInfo(
438
+ resolvedConfig,
439
+ destination,
440
+ symlink
441
+ );
357
442
  await copyDir(info.target, info.link);
358
443
  }
359
444
  if (route) {
360
445
  rewrites.push({
361
- src: `(${route})`,
362
- dest: `${destination}/?__original_path=$1`
446
+ source: `(${route})`,
447
+ destination: `${destination}/?__original_path=$1`
363
448
  });
364
449
  }
365
450
  }
366
451
  return rewrites;
367
452
  }
453
+ async function copyDir(src, dest) {
454
+ await import_promises3.default.mkdir(dest, { recursive: true });
455
+ const entries = await import_promises3.default.readdir(src, { withFileTypes: true });
456
+ for (const entry of entries) {
457
+ const srcPath = import_path4.default.join(src, entry.name);
458
+ const destPath = import_path4.default.join(dest, entry.name);
459
+ entry.isDirectory() ? await copyDir(srcPath, destPath) : await import_promises3.default.copyFile(srcPath, destPath);
460
+ }
461
+ }
368
462
  async function getIsrConfig(resolvedConfig) {
369
463
  var _a;
370
464
  const isr = ((_a = resolvedConfig.vercel) == null ? void 0 : _a.isr) ?? {};
@@ -387,41 +481,42 @@ function vercelPlugin() {
387
481
  },
388
482
  async buildStart() {
389
483
  if (process.env.VERCEL_ENV === "production" && !process.env.ENABLE_VC_BUILD) {
390
- throw new Error("Missing ENABLE_VC_BUILD=1 to your environment variables in your project settings");
391
- }
392
- if (!resolvedConfig.build.ssr) {
393
- await cleanOutputDirectory(resolvedConfig);
394
- } else {
395
- await copyDistClientToOutputStatic(resolvedConfig);
484
+ throw new Error(
485
+ "Missing ENABLE_VC_BUILD=1 to your environment variables in your project settings"
486
+ );
396
487
  }
397
488
  },
398
489
  async writeBundle() {
399
490
  var _a;
400
- if (!((_a = resolvedConfig.build) == null ? void 0 : _a.ssr))
491
+ if (!((_a = resolvedConfig.build) == null ? void 0 : _a.ssr)) {
492
+ await cleanOutputDirectory(resolvedConfig);
401
493
  return;
402
- const userOverrides = await computeStaticHtmlOverrides(resolvedConfig);
494
+ }
403
495
  const overrides = await execPrerender(resolvedConfig);
404
- await buildEndpoints(resolvedConfig);
405
- const rewrites = await buildPrerenderConfigs(resolvedConfig);
406
- await writeConfig(resolvedConfig, {
407
- routes: [{ handle: "filesystem" }, ...rewrites],
408
- overrides: __spreadValues(__spreadValues({}, userOverrides), overrides)
496
+ const userOverrides = await computeStaticHtmlOverrides(resolvedConfig);
497
+ const rewrites = await buildEndpoints(resolvedConfig);
498
+ rewrites.push(...await buildPrerenderConfigs(resolvedConfig));
499
+ await writeConfig(resolvedConfig, rewrites, {
500
+ ...userOverrides,
501
+ ...overrides
409
502
  });
410
503
  }
411
504
  };
412
505
  }
413
- async function copyDistClientToOutputStatic(resolvedConfig) {
414
- await copyDir(getOutDir(resolvedConfig, "client"), getOutput(resolvedConfig, "static"));
415
- }
416
506
  async function cleanOutputDirectory(resolvedConfig) {
417
- await import_promises5.default.rm(getOutput(resolvedConfig), {
507
+ await import_promises4.default.rm(getOutput(resolvedConfig), {
418
508
  recursive: true,
419
509
  force: true
420
510
  });
421
511
  }
422
512
  async function computeStaticHtmlOverrides(resolvedConfig) {
423
513
  const staticAbsolutePath = getOutput(resolvedConfig, "static");
424
- const files = await getStaticHtmlFiles(resolvedConfig, staticAbsolutePath);
514
+ const files = await getStaticHtmlFiles(staticAbsolutePath);
515
+ const publicDir = getPublic(resolvedConfig);
516
+ const publicFiles = await getStaticHtmlFiles(publicDir);
517
+ files.push(
518
+ ...publicFiles.map((f) => f.replace(publicDir, staticAbsolutePath))
519
+ );
425
520
  return files.reduce((acc, curr) => {
426
521
  const relPath = import_path5.default.relative(staticAbsolutePath, curr);
427
522
  const parsed = import_path5.default.parse(relPath);
@@ -432,12 +527,17 @@ async function computeStaticHtmlOverrides(resolvedConfig) {
432
527
  return acc;
433
528
  }, {});
434
529
  }
435
- async function getStaticHtmlFiles(resolvedConfig, src) {
436
- const entries = await import_promises5.default.readdir(src, { withFileTypes: true });
530
+ async function getStaticHtmlFiles(src) {
531
+ try {
532
+ await import_promises4.default.stat(src);
533
+ } catch (e) {
534
+ return [];
535
+ }
536
+ const entries = await import_promises4.default.readdir(src, { withFileTypes: true });
437
537
  const htmlFiles = [];
438
538
  for (const entry of entries) {
439
539
  const srcPath = import_path5.default.join(src, entry.name);
440
- entry.isDirectory() ? htmlFiles.push(...await getStaticHtmlFiles(resolvedConfig, srcPath)) : srcPath.endsWith(".html") ? htmlFiles.push(srcPath) : void 0;
540
+ entry.isDirectory() ? htmlFiles.push(...await getStaticHtmlFiles(srcPath)) : srcPath.endsWith(".html") ? htmlFiles.push(srcPath) : void 0;
441
541
  }
442
542
  return htmlFiles;
443
543
  }