vite-plugin-vercel 3.0.1 → 4.0.0

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
@@ -33,7 +33,7 @@ __export(src_exports, {
33
33
  default: () => allPlugins
34
34
  });
35
35
  module.exports = __toCommonJS(src_exports);
36
- var import_promises4 = __toESM(require("fs/promises"), 1);
36
+ var import_promises5 = __toESM(require("fs/promises"), 1);
37
37
 
38
38
  // src/utils.ts
39
39
  var import_vite = require("vite");
@@ -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),
@@ -544,7 +548,7 @@ async function buildEndpoints(resolvedConfig) {
544
548
  }
545
549
 
546
550
  // src/prerender.ts
547
- var import_path4 = __toESM(require("path"), 1);
551
+ var import_path5 = __toESM(require("path"), 1);
548
552
 
549
553
  // src/schemas/config/prerender-config.ts
550
554
  var import_zod4 = require("zod");
@@ -557,7 +561,22 @@ var vercelOutputPrerenderConfigSchema = import_zod4.z.object({
557
561
  }).strict();
558
562
 
559
563
  // src/prerender.ts
564
+ var import_promises4 = __toESM(require("fs/promises"), 1);
565
+
566
+ // src/helpers.ts
560
567
  var import_promises3 = __toESM(require("fs/promises"), 1);
568
+ var import_path4 = __toESM(require("path"), 1);
569
+ async function copyDir(src, dest) {
570
+ await import_promises3.default.mkdir(dest, { recursive: true });
571
+ const entries = await import_promises3.default.readdir(src, { withFileTypes: true });
572
+ for (const entry of entries) {
573
+ const srcPath = import_path4.default.join(src, entry.name);
574
+ const destPath = import_path4.default.join(dest, entry.name);
575
+ entry.isDirectory() ? await copyDir(srcPath, destPath) : await import_promises3.default.copyFile(srcPath, destPath);
576
+ }
577
+ }
578
+
579
+ // src/prerender.ts
561
580
  function execPrerender(resolvedConfig) {
562
581
  var _a;
563
582
  const prerender = (_a = resolvedConfig.vercel) == null ? void 0 : _a.prerender;
@@ -568,17 +587,17 @@ function execPrerender(resolvedConfig) {
568
587
  }
569
588
  var group = 1;
570
589
  async function writePrerenderConfig(resolvedConfig, destination, isr) {
571
- const parsed = import_path4.default.parse(destination);
572
- const outfile = import_path4.default.join(
590
+ const parsed = import_path5.default.parse(destination);
591
+ const outfile = import_path5.default.join(
573
592
  getOutput(resolvedConfig, "functions"),
574
593
  parsed.dir,
575
594
  parsed.name + ".prerender-config.json"
576
595
  );
577
- await import_promises3.default.mkdir(
578
- import_path4.default.join(getOutput(resolvedConfig, "functions"), parsed.dir),
596
+ await import_promises4.default.mkdir(
597
+ import_path5.default.join(getOutput(resolvedConfig, "functions"), parsed.dir),
579
598
  { recursive: true }
580
599
  );
581
- await import_promises3.default.writeFile(
600
+ await import_promises4.default.writeFile(
582
601
  outfile,
583
602
  JSON.stringify(
584
603
  vercelOutputPrerenderConfigSchema.parse({
@@ -592,15 +611,15 @@ async function writePrerenderConfig(resolvedConfig, destination, isr) {
592
611
  );
593
612
  }
594
613
  function getPrerenderSymlinkInfo(resolvedConfig, destination, target) {
595
- const parsed = import_path4.default.parse(destination);
596
- const targetParsed = import_path4.default.parse(target);
614
+ const parsed = import_path5.default.parse(destination);
615
+ const targetParsed = import_path5.default.parse(target);
597
616
  return {
598
- target: import_path4.default.join(
617
+ target: import_path5.default.join(
599
618
  getOutput(resolvedConfig, "functions"),
600
619
  targetParsed.dir,
601
620
  targetParsed.name + ".func"
602
621
  ),
603
- link: import_path4.default.join(
622
+ link: import_path5.default.join(
604
623
  getOutput(resolvedConfig, "functions"),
605
624
  parsed.dir,
606
625
  parsed.name + ".func"
@@ -634,15 +653,6 @@ async function buildPrerenderConfigs(resolvedConfig, extractedIsr) {
634
653
  }
635
654
  return rewrites;
636
655
  }
637
- async function copyDir(src, dest) {
638
- await import_promises3.default.mkdir(dest, { recursive: true });
639
- const entries = await import_promises3.default.readdir(src, { withFileTypes: true });
640
- for (const entry of entries) {
641
- const srcPath = import_path4.default.join(src, entry.name);
642
- const destPath = import_path4.default.join(dest, entry.name);
643
- entry.isDirectory() ? await copyDir(srcPath, destPath) : await import_promises3.default.copyFile(srcPath, destPath);
644
- }
645
- }
646
656
  async function getIsrConfig(resolvedConfig) {
647
657
  var _a;
648
658
  const isr = ((_a = resolvedConfig.vercel) == null ? void 0 : _a.isr) ?? {};
@@ -653,7 +663,7 @@ async function getIsrConfig(resolvedConfig) {
653
663
  }
654
664
 
655
665
  // src/index.ts
656
- var import_path5 = __toESM(require("path"), 1);
666
+ var import_path6 = __toESM(require("path"), 1);
657
667
  function vercelPlugin() {
658
668
  let resolvedConfig;
659
669
  let vikeFound = false;
@@ -662,10 +672,15 @@ function vercelPlugin() {
662
672
  name: "vite-plugin-vercel",
663
673
  enforce: "post",
664
674
  configResolved(config) {
675
+ var _a;
665
676
  resolvedConfig = config;
666
677
  vikeFound = resolvedConfig.plugins.some(
667
678
  (p) => p.name.match("^vite-plugin-ssr:|^vike:")
668
679
  );
680
+ if (typeof ((_a = resolvedConfig.vercel) == null ? void 0 : _a.distContainsOnlyStatic) === "undefined") {
681
+ resolvedConfig.vercel ??= {};
682
+ resolvedConfig.vercel.distContainsOnlyStatic = !vikeFound;
683
+ }
669
684
  },
670
685
  async writeBundle() {
671
686
  var _a;
@@ -688,15 +703,25 @@ function vercelPlugin() {
688
703
  },
689
704
  headers
690
705
  );
706
+ await copyDistToStatic(resolvedConfig);
691
707
  }
692
708
  };
693
709
  }
694
710
  async function cleanOutputDirectory(resolvedConfig) {
695
- await import_promises4.default.rm(getOutput(resolvedConfig), {
711
+ await import_promises5.default.rm(getOutput(resolvedConfig), {
696
712
  recursive: true,
697
713
  force: true
698
714
  });
699
- await import_promises4.default.mkdir(getOutput(resolvedConfig), { recursive: true });
715
+ await import_promises5.default.mkdir(getOutput(resolvedConfig), { recursive: true });
716
+ }
717
+ async function copyDistToStatic(resolvedConfig) {
718
+ var _a;
719
+ if ((_a = resolvedConfig.vercel) == null ? void 0 : _a.distContainsOnlyStatic) {
720
+ await copyDir(
721
+ resolvedConfig.build.outDir,
722
+ getOutput(resolvedConfig, "static")
723
+ );
724
+ }
700
725
  }
701
726
  async function computeStaticHtmlOverrides(resolvedConfig) {
702
727
  const staticAbsolutePath = getOutput(resolvedConfig, "static");
@@ -707,9 +732,9 @@ async function computeStaticHtmlOverrides(resolvedConfig) {
707
732
  ...publicFiles.map((f) => f.replace(publicDir, staticAbsolutePath))
708
733
  );
709
734
  return files.reduce((acc, curr) => {
710
- const relPath = import_path5.default.relative(staticAbsolutePath, curr);
711
- const parsed = import_path5.default.parse(relPath);
712
- const pathJoined = import_path5.default.join(parsed.dir, parsed.name);
735
+ const relPath = import_path6.default.relative(staticAbsolutePath, curr);
736
+ const parsed = import_path6.default.parse(relPath);
737
+ const pathJoined = import_path6.default.join(parsed.dir, parsed.name);
713
738
  acc[relPath] = {
714
739
  path: pathJoined
715
740
  };
@@ -718,14 +743,14 @@ async function computeStaticHtmlOverrides(resolvedConfig) {
718
743
  }
719
744
  async function getStaticHtmlFiles(src) {
720
745
  try {
721
- await import_promises4.default.stat(src);
746
+ await import_promises5.default.stat(src);
722
747
  } catch (e) {
723
748
  return [];
724
749
  }
725
- const entries = await import_promises4.default.readdir(src, { withFileTypes: true });
750
+ const entries = await import_promises5.default.readdir(src, { withFileTypes: true });
726
751
  const htmlFiles = [];
727
752
  for (const entry of entries) {
728
- const srcPath = import_path5.default.join(src, entry.name);
753
+ const srcPath = import_path6.default.join(src, entry.name);
729
754
  entry.isDirectory() ? htmlFiles.push(...await getStaticHtmlFiles(srcPath)) : srcPath.endsWith(".html") ? htmlFiles.push(srcPath) : void 0;
730
755
  }
731
756
  return htmlFiles;
package/dist/index.d.cts CHANGED
@@ -607,6 +607,13 @@ interface ViteVercelConfig {
607
607
  * @protected
608
608
  */
609
609
  outDir?: string;
610
+ /**
611
+ * By default, Vite generates static files under `dist` folder.
612
+ * But usually, when used through a Framework, such as Vike,
613
+ * this folder can contain anything, requiring custom integration.
614
+ * Set this to false is you create a plugin for a Framework.
615
+ */
616
+ distContainsOnlyStatic?: boolean;
610
617
  }
611
618
  interface VercelOutputIsr extends VercelOutputPrerenderConfig {
612
619
  symlink?: string;
package/dist/index.d.ts CHANGED
@@ -607,6 +607,13 @@ interface ViteVercelConfig {
607
607
  * @protected
608
608
  */
609
609
  outDir?: string;
610
+ /**
611
+ * By default, Vite generates static files under `dist` folder.
612
+ * But usually, when used through a Framework, such as Vike,
613
+ * this folder can contain anything, requiring custom integration.
614
+ * Set this to false is you create a plugin for a Framework.
615
+ */
616
+ distContainsOnlyStatic?: boolean;
610
617
  }
611
618
  interface VercelOutputIsr extends VercelOutputPrerenderConfig {
612
619
  symlink?: string;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/index.ts
2
- import fs4 from "fs/promises";
2
+ import fs5 from "fs/promises";
3
3
 
4
4
  // src/utils.ts
5
5
  import { normalizePath } from "vite";
@@ -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),
@@ -514,7 +518,7 @@ async function buildEndpoints(resolvedConfig) {
514
518
  }
515
519
 
516
520
  // src/prerender.ts
517
- import path4 from "path";
521
+ import path5 from "path";
518
522
 
519
523
  // src/schemas/config/prerender-config.ts
520
524
  import { z as z4 } from "zod";
@@ -527,7 +531,22 @@ var vercelOutputPrerenderConfigSchema = z4.object({
527
531
  }).strict();
528
532
 
529
533
  // src/prerender.ts
534
+ import fs4 from "fs/promises";
535
+
536
+ // src/helpers.ts
530
537
  import fs3 from "fs/promises";
538
+ import path4 from "path";
539
+ async function copyDir(src, dest) {
540
+ await fs3.mkdir(dest, { recursive: true });
541
+ const entries = await fs3.readdir(src, { withFileTypes: true });
542
+ for (const entry of entries) {
543
+ const srcPath = path4.join(src, entry.name);
544
+ const destPath = path4.join(dest, entry.name);
545
+ entry.isDirectory() ? await copyDir(srcPath, destPath) : await fs3.copyFile(srcPath, destPath);
546
+ }
547
+ }
548
+
549
+ // src/prerender.ts
531
550
  function execPrerender(resolvedConfig) {
532
551
  var _a;
533
552
  const prerender = (_a = resolvedConfig.vercel) == null ? void 0 : _a.prerender;
@@ -538,17 +557,17 @@ function execPrerender(resolvedConfig) {
538
557
  }
539
558
  var group = 1;
540
559
  async function writePrerenderConfig(resolvedConfig, destination, isr) {
541
- const parsed = path4.parse(destination);
542
- const outfile = path4.join(
560
+ const parsed = path5.parse(destination);
561
+ const outfile = path5.join(
543
562
  getOutput(resolvedConfig, "functions"),
544
563
  parsed.dir,
545
564
  parsed.name + ".prerender-config.json"
546
565
  );
547
- await fs3.mkdir(
548
- path4.join(getOutput(resolvedConfig, "functions"), parsed.dir),
566
+ await fs4.mkdir(
567
+ path5.join(getOutput(resolvedConfig, "functions"), parsed.dir),
549
568
  { recursive: true }
550
569
  );
551
- await fs3.writeFile(
570
+ await fs4.writeFile(
552
571
  outfile,
553
572
  JSON.stringify(
554
573
  vercelOutputPrerenderConfigSchema.parse({
@@ -562,15 +581,15 @@ async function writePrerenderConfig(resolvedConfig, destination, isr) {
562
581
  );
563
582
  }
564
583
  function getPrerenderSymlinkInfo(resolvedConfig, destination, target) {
565
- const parsed = path4.parse(destination);
566
- const targetParsed = path4.parse(target);
584
+ const parsed = path5.parse(destination);
585
+ const targetParsed = path5.parse(target);
567
586
  return {
568
- target: path4.join(
587
+ target: path5.join(
569
588
  getOutput(resolvedConfig, "functions"),
570
589
  targetParsed.dir,
571
590
  targetParsed.name + ".func"
572
591
  ),
573
- link: path4.join(
592
+ link: path5.join(
574
593
  getOutput(resolvedConfig, "functions"),
575
594
  parsed.dir,
576
595
  parsed.name + ".func"
@@ -604,15 +623,6 @@ async function buildPrerenderConfigs(resolvedConfig, extractedIsr) {
604
623
  }
605
624
  return rewrites;
606
625
  }
607
- async function copyDir(src, dest) {
608
- await fs3.mkdir(dest, { recursive: true });
609
- const entries = await fs3.readdir(src, { withFileTypes: true });
610
- for (const entry of entries) {
611
- const srcPath = path4.join(src, entry.name);
612
- const destPath = path4.join(dest, entry.name);
613
- entry.isDirectory() ? await copyDir(srcPath, destPath) : await fs3.copyFile(srcPath, destPath);
614
- }
615
- }
616
626
  async function getIsrConfig(resolvedConfig) {
617
627
  var _a;
618
628
  const isr = ((_a = resolvedConfig.vercel) == null ? void 0 : _a.isr) ?? {};
@@ -623,7 +633,7 @@ async function getIsrConfig(resolvedConfig) {
623
633
  }
624
634
 
625
635
  // src/index.ts
626
- import path5 from "path";
636
+ import path6 from "path";
627
637
  function vercelPlugin() {
628
638
  let resolvedConfig;
629
639
  let vikeFound = false;
@@ -632,10 +642,15 @@ function vercelPlugin() {
632
642
  name: "vite-plugin-vercel",
633
643
  enforce: "post",
634
644
  configResolved(config) {
645
+ var _a;
635
646
  resolvedConfig = config;
636
647
  vikeFound = resolvedConfig.plugins.some(
637
648
  (p) => p.name.match("^vite-plugin-ssr:|^vike:")
638
649
  );
650
+ if (typeof ((_a = resolvedConfig.vercel) == null ? void 0 : _a.distContainsOnlyStatic) === "undefined") {
651
+ resolvedConfig.vercel ??= {};
652
+ resolvedConfig.vercel.distContainsOnlyStatic = !vikeFound;
653
+ }
639
654
  },
640
655
  async writeBundle() {
641
656
  var _a;
@@ -658,15 +673,25 @@ function vercelPlugin() {
658
673
  },
659
674
  headers
660
675
  );
676
+ await copyDistToStatic(resolvedConfig);
661
677
  }
662
678
  };
663
679
  }
664
680
  async function cleanOutputDirectory(resolvedConfig) {
665
- await fs4.rm(getOutput(resolvedConfig), {
681
+ await fs5.rm(getOutput(resolvedConfig), {
666
682
  recursive: true,
667
683
  force: true
668
684
  });
669
- await fs4.mkdir(getOutput(resolvedConfig), { recursive: true });
685
+ await fs5.mkdir(getOutput(resolvedConfig), { recursive: true });
686
+ }
687
+ async function copyDistToStatic(resolvedConfig) {
688
+ var _a;
689
+ if ((_a = resolvedConfig.vercel) == null ? void 0 : _a.distContainsOnlyStatic) {
690
+ await copyDir(
691
+ resolvedConfig.build.outDir,
692
+ getOutput(resolvedConfig, "static")
693
+ );
694
+ }
670
695
  }
671
696
  async function computeStaticHtmlOverrides(resolvedConfig) {
672
697
  const staticAbsolutePath = getOutput(resolvedConfig, "static");
@@ -677,9 +702,9 @@ async function computeStaticHtmlOverrides(resolvedConfig) {
677
702
  ...publicFiles.map((f) => f.replace(publicDir, staticAbsolutePath))
678
703
  );
679
704
  return files.reduce((acc, curr) => {
680
- const relPath = path5.relative(staticAbsolutePath, curr);
681
- const parsed = path5.parse(relPath);
682
- const pathJoined = path5.join(parsed.dir, parsed.name);
705
+ const relPath = path6.relative(staticAbsolutePath, curr);
706
+ const parsed = path6.parse(relPath);
707
+ const pathJoined = path6.join(parsed.dir, parsed.name);
683
708
  acc[relPath] = {
684
709
  path: pathJoined
685
710
  };
@@ -688,14 +713,14 @@ async function computeStaticHtmlOverrides(resolvedConfig) {
688
713
  }
689
714
  async function getStaticHtmlFiles(src) {
690
715
  try {
691
- await fs4.stat(src);
716
+ await fs5.stat(src);
692
717
  } catch (e) {
693
718
  return [];
694
719
  }
695
- const entries = await fs4.readdir(src, { withFileTypes: true });
720
+ const entries = await fs5.readdir(src, { withFileTypes: true });
696
721
  const htmlFiles = [];
697
722
  for (const entry of entries) {
698
- const srcPath = path5.join(src, entry.name);
723
+ const srcPath = path6.join(src, entry.name);
699
724
  entry.isDirectory() ? htmlFiles.push(...await getStaticHtmlFiles(srcPath)) : srcPath.endsWith(".html") ? htmlFiles.push(srcPath) : void 0;
700
725
  }
701
726
  return htmlFiles;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-vercel",
3
- "version": "3.0.1",
3
+ "version": "4.0.0",
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.0"
26
26
  },
27
27
  "peerDependenciesMeta": {
28
28
  "@vite-plugin-vercel/vike": {
@@ -33,21 +33,21 @@
33
33
  }
34
34
  },
35
35
  "devDependencies": {
36
- "@types/node": "^16.18.71",
37
- "@typescript-eslint/eslint-plugin": "^6.19.0",
38
- "@typescript-eslint/parser": "^6.19.0",
36
+ "@types/node": "^16.18.76",
37
+ "@typescript-eslint/eslint-plugin": "^6.19.1",
38
+ "@typescript-eslint/parser": "^6.19.1",
39
39
  "eslint": "^8.56.0",
40
40
  "tsup": "^8.0.1",
41
41
  "typescript": "^5.3.3",
42
- "vike": "^0.4.157",
43
- "vite": "^5.0.11",
44
- "@vite-plugin-vercel/vike": "3.0.1"
42
+ "vike": "^0.4.160",
43
+ "vite": "^5.0.12",
44
+ "@vite-plugin-vercel/vike": "4.0.0"
45
45
  },
46
46
  "dependencies": {
47
47
  "@brillout/libassert": "^0.5.8",
48
- "@vercel/build-utils": "^7.5.0",
48
+ "@vercel/build-utils": "^7.5.1",
49
49
  "@vercel/routing-utils": "^3.1.0",
50
- "esbuild": "^0.19.11",
50
+ "esbuild": "^0.19.12",
51
51
  "eval": "^0.1.8",
52
52
  "fast-glob": "^3.3.2",
53
53
  "magicast": "^0.3.3",