vite-plugin-vercel 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -284,13 +284,40 @@ function getEntries(resolvedConfig) {
284
284
  return entryPoints;
285
285
  }, getAdditionalEndpoints(resolvedConfig));
286
286
  }
287
+ var wasmPlugin = {
288
+ name: "wasm",
289
+ setup(build2) {
290
+ build2.onResolve({ filter: /\.wasm/ }, (args) => {
291
+ return {
292
+ path: args.path.replace(/\.wasm\?module$/i, ".wasm"),
293
+ external: true
294
+ };
295
+ });
296
+ }
297
+ };
298
+ var vercelOgPlugin = (ctx) => {
299
+ return {
300
+ name: "vercel-og",
301
+ setup(build2) {
302
+ build2.onResolve({ filter: /@vercel\/og/ }, () => {
303
+ ctx.found = true;
304
+ return void 0;
305
+ });
306
+ build2.onLoad({ filter: /@vercel\/og/ }, (args) => {
307
+ ctx.index = args.path;
308
+ return void 0;
309
+ });
310
+ }
311
+ };
312
+ };
287
313
  var standardBuildOptions = {
288
314
  bundle: true,
289
315
  target: "es2020",
290
316
  format: "cjs",
291
317
  platform: "node",
292
318
  logLevel: "info",
293
- minify: true
319
+ minify: true,
320
+ plugins: [wasmPlugin]
294
321
  };
295
322
  async function buildFn(resolvedConfig, entry, buildOptions) {
296
323
  assert(
@@ -329,8 +356,25 @@ async function buildFn(resolvedConfig, entry, buildOptions) {
329
356
  "import",
330
357
  "require"
331
358
  ];
359
+ options.format = "esm";
332
360
  }
361
+ const ctx = { found: false, index: "" };
362
+ options.plugins.push(vercelOgPlugin(ctx));
333
363
  await (0, import_esbuild.build)(options);
364
+ if (ctx.found && ctx.index) {
365
+ const dir = (0, import_path3.dirname)(ctx.index);
366
+ const externalFiles = await (0, import_fast_glob.default)(`${dir}/*.{ttf,wasm}`);
367
+ for (const f of externalFiles) {
368
+ await (0, import_promises2.copyFile)(
369
+ f,
370
+ import_path3.default.join(
371
+ getOutput(resolvedConfig, "functions"),
372
+ entry.destination,
373
+ (0, import_path3.basename)(f)
374
+ )
375
+ );
376
+ }
377
+ }
334
378
  await writeVcConfig(resolvedConfig, entry.destination, Boolean(entry.edge));
335
379
  }
336
380
  async function writeVcConfig(resolvedConfig, destination, edge) {
package/dist/index.js CHANGED
@@ -175,7 +175,7 @@ async function writeConfig(resolvedConfig, rewrites, overrides) {
175
175
 
176
176
  // src/build.ts
177
177
  import glob from "fast-glob";
178
- import path3 from "path";
178
+ import path3, { basename, dirname } from "path";
179
179
  import { build } from "esbuild";
180
180
 
181
181
  // src/assert.ts
@@ -217,7 +217,7 @@ var vercelOutputVcConfigSchema = z2.union([
217
217
  ]);
218
218
 
219
219
  // src/build.ts
220
- import fs2 from "fs/promises";
220
+ import fs2, { copyFile } from "fs/promises";
221
221
  function getAdditionalEndpoints(resolvedConfig) {
222
222
  var _a;
223
223
  return (((_a = resolvedConfig.vercel) == null ? void 0 : _a.additionalEndpoints) ?? []).map((e) => ({
@@ -250,13 +250,40 @@ function getEntries(resolvedConfig) {
250
250
  return entryPoints;
251
251
  }, getAdditionalEndpoints(resolvedConfig));
252
252
  }
253
+ var wasmPlugin = {
254
+ name: "wasm",
255
+ setup(build2) {
256
+ build2.onResolve({ filter: /\.wasm/ }, (args) => {
257
+ return {
258
+ path: args.path.replace(/\.wasm\?module$/i, ".wasm"),
259
+ external: true
260
+ };
261
+ });
262
+ }
263
+ };
264
+ var vercelOgPlugin = (ctx) => {
265
+ return {
266
+ name: "vercel-og",
267
+ setup(build2) {
268
+ build2.onResolve({ filter: /@vercel\/og/ }, () => {
269
+ ctx.found = true;
270
+ return void 0;
271
+ });
272
+ build2.onLoad({ filter: /@vercel\/og/ }, (args) => {
273
+ ctx.index = args.path;
274
+ return void 0;
275
+ });
276
+ }
277
+ };
278
+ };
253
279
  var standardBuildOptions = {
254
280
  bundle: true,
255
281
  target: "es2020",
256
282
  format: "cjs",
257
283
  platform: "node",
258
284
  logLevel: "info",
259
- minify: true
285
+ minify: true,
286
+ plugins: [wasmPlugin]
260
287
  };
261
288
  async function buildFn(resolvedConfig, entry, buildOptions) {
262
289
  assert(
@@ -295,8 +322,25 @@ async function buildFn(resolvedConfig, entry, buildOptions) {
295
322
  "import",
296
323
  "require"
297
324
  ];
325
+ options.format = "esm";
298
326
  }
327
+ const ctx = { found: false, index: "" };
328
+ options.plugins.push(vercelOgPlugin(ctx));
299
329
  await build(options);
330
+ if (ctx.found && ctx.index) {
331
+ const dir = dirname(ctx.index);
332
+ const externalFiles = await glob(`${dir}/*.{ttf,wasm}`);
333
+ for (const f of externalFiles) {
334
+ await copyFile(
335
+ f,
336
+ path3.join(
337
+ getOutput(resolvedConfig, "functions"),
338
+ entry.destination,
339
+ basename(f)
340
+ )
341
+ );
342
+ }
343
+ }
300
344
  await writeVcConfig(resolvedConfig, entry.destination, Boolean(entry.edge));
301
345
  }
302
346
  async function writeVcConfig(resolvedConfig, destination, edge) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-vercel",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",