vite-plugin-vercel 3.0.2 → 4.0.1

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
@@ -4,6 +4,19 @@ Vercel adapter for [Vite](https://vitejs.dev/).
4
4
 
5
5
  Bundle your Vite application as supported by [Vercel Output API (v3)](https://vercel.com/docs/build-output-api/v3).
6
6
 
7
+ ## Install
8
+ ```bash
9
+ npm i -D vite-plugin-vercel
10
+ ```
11
+ ```bash
12
+ yarn add -D vite-plugin-vercel
13
+ ```
14
+ ```bash
15
+ pnpm add -D vite-plugin-vercel
16
+ ```
17
+ ```bash
18
+ bun add -D vite-plugin-vercel
19
+ ```
7
20
  ## Features
8
21
 
9
22
  - [x] [SSG/Static files](https://vercel.com/docs/build-output-api/v3/primitives#static-files)
package/dist/index.cjs CHANGED
@@ -458,6 +458,10 @@ function getSourceAndDestination(destination) {
458
458
  }
459
459
  return import_path3.default.posix.resolve("/", destination, ":match*");
460
460
  }
461
+ var RE_BRACKETS = /^\[([^/]+)\]$/gm;
462
+ function replaceBrackets(source) {
463
+ return source.split("/").map((segment) => segment.replace(RE_BRACKETS, ":$1")).join("/");
464
+ }
461
465
  async function removeDefaultExport(filepath) {
462
466
  const mod = await (0, import_magicast.loadFile)(filepath);
463
467
  try {
@@ -529,7 +533,7 @@ async function buildEndpoints(resolvedConfig) {
529
533
  );
530
534
  return {
531
535
  rewrites: entries.filter((e) => e.addRoute !== false).map((e) => e.destination.replace(/\.func$/, "")).map((destination) => ({
532
- source: getSourceAndDestination(destination),
536
+ source: replaceBrackets(getSourceAndDestination(destination)),
533
537
  destination: getSourceAndDestination(destination)
534
538
  })),
535
539
  isr: Object.fromEntries(isrEntries),
@@ -660,6 +664,27 @@ async function getIsrConfig(resolvedConfig) {
660
664
 
661
665
  // src/index.ts
662
666
  var import_path6 = __toESM(require("path"), 1);
667
+ function vercelPluginCleanup() {
668
+ let resolvedConfig;
669
+ return {
670
+ apply: "build",
671
+ name: "vite-plugin-vercel:cleanup",
672
+ enforce: "pre",
673
+ configResolved(config) {
674
+ resolvedConfig = config;
675
+ },
676
+ writeBundle: {
677
+ order: "pre",
678
+ sequential: true,
679
+ async handler() {
680
+ var _a;
681
+ if (!((_a = resolvedConfig.build) == null ? void 0 : _a.ssr)) {
682
+ await cleanOutputDirectory(resolvedConfig);
683
+ }
684
+ }
685
+ }
686
+ };
687
+ }
663
688
  function vercelPlugin() {
664
689
  let resolvedConfig;
665
690
  let vikeFound = false;
@@ -678,28 +703,31 @@ function vercelPlugin() {
678
703
  resolvedConfig.vercel.distContainsOnlyStatic = !vikeFound;
679
704
  }
680
705
  },
681
- async writeBundle() {
682
- var _a;
683
- if (!((_a = resolvedConfig.build) == null ? void 0 : _a.ssr)) {
684
- await cleanOutputDirectory(resolvedConfig);
685
- if (vikeFound) {
686
- return;
706
+ writeBundle: {
707
+ order: "post",
708
+ sequential: true,
709
+ async handler() {
710
+ var _a;
711
+ if (!((_a = resolvedConfig.build) == null ? void 0 : _a.ssr)) {
712
+ if (vikeFound) {
713
+ return;
714
+ }
687
715
  }
716
+ const overrides = await execPrerender(resolvedConfig);
717
+ const userOverrides = await computeStaticHtmlOverrides(resolvedConfig);
718
+ const { rewrites, isr, headers } = await buildEndpoints(resolvedConfig);
719
+ rewrites.push(...await buildPrerenderConfigs(resolvedConfig, isr));
720
+ await writeConfig(
721
+ resolvedConfig,
722
+ rewrites,
723
+ {
724
+ ...userOverrides,
725
+ ...overrides
726
+ },
727
+ headers
728
+ );
729
+ await copyDistToStatic(resolvedConfig);
688
730
  }
689
- const overrides = await execPrerender(resolvedConfig);
690
- const userOverrides = await computeStaticHtmlOverrides(resolvedConfig);
691
- const { rewrites, isr, headers } = await buildEndpoints(resolvedConfig);
692
- rewrites.push(...await buildPrerenderConfigs(resolvedConfig, isr));
693
- await writeConfig(
694
- resolvedConfig,
695
- rewrites,
696
- {
697
- ...userOverrides,
698
- ...overrides
699
- },
700
- headers
701
- );
702
- await copyDistToStatic(resolvedConfig);
703
731
  }
704
732
  };
705
733
  }
@@ -767,5 +795,9 @@ async function tryImportVpvv() {
767
795
  }
768
796
  }
769
797
  function allPlugins(options = {}) {
770
- return [vercelPlugin(), options.smart !== false ? tryImportVpvv() : null];
798
+ return [
799
+ vercelPluginCleanup(),
800
+ vercelPlugin(),
801
+ options.smart !== false ? tryImportVpvv() : null
802
+ ];
771
803
  }
package/dist/index.d.cts CHANGED
@@ -438,22 +438,22 @@ declare const vercelOutputVcConfigSchema: z.ZodUnion<[z.ZodObject<{
438
438
  environment: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
439
439
  regions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
440
440
  }, "strict", z.ZodTypeAny, {
441
- runtime: string;
442
441
  handler: string;
442
+ runtime: string;
443
443
  memory?: number | undefined;
444
444
  maxDuration?: number | undefined;
445
445
  environment?: Record<string, string> | undefined;
446
446
  regions?: string[] | undefined;
447
447
  }, {
448
- runtime: string;
449
448
  handler: string;
449
+ runtime: string;
450
450
  memory?: number | undefined;
451
451
  maxDuration?: number | undefined;
452
452
  environment?: Record<string, string> | undefined;
453
453
  regions?: string[] | undefined;
454
454
  }>, z.ZodObject<{
455
- runtime: z.ZodString;
456
455
  handler: z.ZodString;
456
+ runtime: z.ZodString;
457
457
  memory: z.ZodOptional<z.ZodNumber>;
458
458
  maxDuration: z.ZodOptional<z.ZodNumber>;
459
459
  environment: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
@@ -463,8 +463,8 @@ declare const vercelOutputVcConfigSchema: z.ZodUnion<[z.ZodObject<{
463
463
  shouldAddSourcemapSupport: z.ZodOptional<z.ZodBoolean>;
464
464
  awsLambdaHandler: z.ZodOptional<z.ZodString>;
465
465
  }, "strict", z.ZodTypeAny, {
466
- runtime: string;
467
466
  handler: string;
467
+ runtime: string;
468
468
  launcherType: "Nodejs";
469
469
  memory?: number | undefined;
470
470
  maxDuration?: number | undefined;
@@ -474,8 +474,8 @@ declare const vercelOutputVcConfigSchema: z.ZodUnion<[z.ZodObject<{
474
474
  shouldAddSourcemapSupport?: boolean | undefined;
475
475
  awsLambdaHandler?: string | undefined;
476
476
  }, {
477
- runtime: string;
478
477
  handler: string;
478
+ runtime: string;
479
479
  launcherType: "Nodejs";
480
480
  memory?: number | undefined;
481
481
  maxDuration?: number | undefined;
package/dist/index.d.ts CHANGED
@@ -438,22 +438,22 @@ declare const vercelOutputVcConfigSchema: z.ZodUnion<[z.ZodObject<{
438
438
  environment: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
439
439
  regions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
440
440
  }, "strict", z.ZodTypeAny, {
441
- runtime: string;
442
441
  handler: string;
442
+ runtime: string;
443
443
  memory?: number | undefined;
444
444
  maxDuration?: number | undefined;
445
445
  environment?: Record<string, string> | undefined;
446
446
  regions?: string[] | undefined;
447
447
  }, {
448
- runtime: string;
449
448
  handler: string;
449
+ runtime: string;
450
450
  memory?: number | undefined;
451
451
  maxDuration?: number | undefined;
452
452
  environment?: Record<string, string> | undefined;
453
453
  regions?: string[] | undefined;
454
454
  }>, z.ZodObject<{
455
- runtime: z.ZodString;
456
455
  handler: z.ZodString;
456
+ runtime: z.ZodString;
457
457
  memory: z.ZodOptional<z.ZodNumber>;
458
458
  maxDuration: z.ZodOptional<z.ZodNumber>;
459
459
  environment: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
@@ -463,8 +463,8 @@ declare const vercelOutputVcConfigSchema: z.ZodUnion<[z.ZodObject<{
463
463
  shouldAddSourcemapSupport: z.ZodOptional<z.ZodBoolean>;
464
464
  awsLambdaHandler: z.ZodOptional<z.ZodString>;
465
465
  }, "strict", z.ZodTypeAny, {
466
- runtime: string;
467
466
  handler: string;
467
+ runtime: string;
468
468
  launcherType: "Nodejs";
469
469
  memory?: number | undefined;
470
470
  maxDuration?: number | undefined;
@@ -474,8 +474,8 @@ declare const vercelOutputVcConfigSchema: z.ZodUnion<[z.ZodObject<{
474
474
  shouldAddSourcemapSupport?: boolean | undefined;
475
475
  awsLambdaHandler?: string | undefined;
476
476
  }, {
477
- runtime: string;
478
477
  handler: string;
478
+ runtime: string;
479
479
  launcherType: "Nodejs";
480
480
  memory?: number | undefined;
481
481
  maxDuration?: number | undefined;
package/dist/index.js CHANGED
@@ -428,6 +428,10 @@ function getSourceAndDestination(destination) {
428
428
  }
429
429
  return path3.posix.resolve("/", destination, ":match*");
430
430
  }
431
+ var RE_BRACKETS = /^\[([^/]+)\]$/gm;
432
+ function replaceBrackets(source) {
433
+ return source.split("/").map((segment) => segment.replace(RE_BRACKETS, ":$1")).join("/");
434
+ }
431
435
  async function removeDefaultExport(filepath) {
432
436
  const mod = await loadFile(filepath);
433
437
  try {
@@ -499,7 +503,7 @@ async function buildEndpoints(resolvedConfig) {
499
503
  );
500
504
  return {
501
505
  rewrites: entries.filter((e) => e.addRoute !== false).map((e) => e.destination.replace(/\.func$/, "")).map((destination) => ({
502
- source: getSourceAndDestination(destination),
506
+ source: replaceBrackets(getSourceAndDestination(destination)),
503
507
  destination: getSourceAndDestination(destination)
504
508
  })),
505
509
  isr: Object.fromEntries(isrEntries),
@@ -630,6 +634,27 @@ async function getIsrConfig(resolvedConfig) {
630
634
 
631
635
  // src/index.ts
632
636
  import path6 from "path";
637
+ function vercelPluginCleanup() {
638
+ let resolvedConfig;
639
+ return {
640
+ apply: "build",
641
+ name: "vite-plugin-vercel:cleanup",
642
+ enforce: "pre",
643
+ configResolved(config) {
644
+ resolvedConfig = config;
645
+ },
646
+ writeBundle: {
647
+ order: "pre",
648
+ sequential: true,
649
+ async handler() {
650
+ var _a;
651
+ if (!((_a = resolvedConfig.build) == null ? void 0 : _a.ssr)) {
652
+ await cleanOutputDirectory(resolvedConfig);
653
+ }
654
+ }
655
+ }
656
+ };
657
+ }
633
658
  function vercelPlugin() {
634
659
  let resolvedConfig;
635
660
  let vikeFound = false;
@@ -648,28 +673,31 @@ function vercelPlugin() {
648
673
  resolvedConfig.vercel.distContainsOnlyStatic = !vikeFound;
649
674
  }
650
675
  },
651
- async writeBundle() {
652
- var _a;
653
- if (!((_a = resolvedConfig.build) == null ? void 0 : _a.ssr)) {
654
- await cleanOutputDirectory(resolvedConfig);
655
- if (vikeFound) {
656
- return;
676
+ writeBundle: {
677
+ order: "post",
678
+ sequential: true,
679
+ async handler() {
680
+ var _a;
681
+ if (!((_a = resolvedConfig.build) == null ? void 0 : _a.ssr)) {
682
+ if (vikeFound) {
683
+ return;
684
+ }
657
685
  }
686
+ const overrides = await execPrerender(resolvedConfig);
687
+ const userOverrides = await computeStaticHtmlOverrides(resolvedConfig);
688
+ const { rewrites, isr, headers } = await buildEndpoints(resolvedConfig);
689
+ rewrites.push(...await buildPrerenderConfigs(resolvedConfig, isr));
690
+ await writeConfig(
691
+ resolvedConfig,
692
+ rewrites,
693
+ {
694
+ ...userOverrides,
695
+ ...overrides
696
+ },
697
+ headers
698
+ );
699
+ await copyDistToStatic(resolvedConfig);
658
700
  }
659
- const overrides = await execPrerender(resolvedConfig);
660
- const userOverrides = await computeStaticHtmlOverrides(resolvedConfig);
661
- const { rewrites, isr, headers } = await buildEndpoints(resolvedConfig);
662
- rewrites.push(...await buildPrerenderConfigs(resolvedConfig, isr));
663
- await writeConfig(
664
- resolvedConfig,
665
- rewrites,
666
- {
667
- ...userOverrides,
668
- ...overrides
669
- },
670
- headers
671
- );
672
- await copyDistToStatic(resolvedConfig);
673
701
  }
674
702
  };
675
703
  }
@@ -737,7 +765,11 @@ async function tryImportVpvv() {
737
765
  }
738
766
  }
739
767
  function allPlugins(options = {}) {
740
- return [vercelPlugin(), options.smart !== false ? tryImportVpvv() : null];
768
+ return [
769
+ vercelPluginCleanup(),
770
+ vercelPlugin(),
771
+ options.smart !== false ? tryImportVpvv() : null
772
+ ];
741
773
  }
742
774
  export {
743
775
  allPlugins as default
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-vercel",
3
- "version": "3.0.2",
3
+ "version": "4.0.1",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -22,7 +22,7 @@
22
22
  "peerDependencies": {
23
23
  "vike": "*",
24
24
  "vite": "^4.4 || ^5.0.2",
25
- "@vite-plugin-vercel/vike": "3.0.1"
25
+ "@vite-plugin-vercel/vike": "4.0.1"
26
26
  },
27
27
  "peerDependenciesMeta": {
28
28
  "@vite-plugin-vercel/vike": {
@@ -41,7 +41,7 @@
41
41
  "typescript": "^5.3.3",
42
42
  "vike": "^0.4.160",
43
43
  "vite": "^5.0.12",
44
- "@vite-plugin-vercel/vike": "3.0.1"
44
+ "@vite-plugin-vercel/vike": "4.0.1"
45
45
  },
46
46
  "dependencies": {
47
47
  "@brillout/libassert": "^0.5.8",