vite-plugin-vercel 3.0.0 → 3.0.2

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");
@@ -544,7 +544,7 @@ async function buildEndpoints(resolvedConfig) {
544
544
  }
545
545
 
546
546
  // src/prerender.ts
547
- var import_path4 = __toESM(require("path"), 1);
547
+ var import_path5 = __toESM(require("path"), 1);
548
548
 
549
549
  // src/schemas/config/prerender-config.ts
550
550
  var import_zod4 = require("zod");
@@ -557,7 +557,22 @@ var vercelOutputPrerenderConfigSchema = import_zod4.z.object({
557
557
  }).strict();
558
558
 
559
559
  // src/prerender.ts
560
+ var import_promises4 = __toESM(require("fs/promises"), 1);
561
+
562
+ // src/helpers.ts
560
563
  var import_promises3 = __toESM(require("fs/promises"), 1);
564
+ var import_path4 = __toESM(require("path"), 1);
565
+ async function copyDir(src, dest) {
566
+ await import_promises3.default.mkdir(dest, { recursive: true });
567
+ const entries = await import_promises3.default.readdir(src, { withFileTypes: true });
568
+ for (const entry of entries) {
569
+ const srcPath = import_path4.default.join(src, entry.name);
570
+ const destPath = import_path4.default.join(dest, entry.name);
571
+ entry.isDirectory() ? await copyDir(srcPath, destPath) : await import_promises3.default.copyFile(srcPath, destPath);
572
+ }
573
+ }
574
+
575
+ // src/prerender.ts
561
576
  function execPrerender(resolvedConfig) {
562
577
  var _a;
563
578
  const prerender = (_a = resolvedConfig.vercel) == null ? void 0 : _a.prerender;
@@ -568,17 +583,17 @@ function execPrerender(resolvedConfig) {
568
583
  }
569
584
  var group = 1;
570
585
  async function writePrerenderConfig(resolvedConfig, destination, isr) {
571
- const parsed = import_path4.default.parse(destination);
572
- const outfile = import_path4.default.join(
586
+ const parsed = import_path5.default.parse(destination);
587
+ const outfile = import_path5.default.join(
573
588
  getOutput(resolvedConfig, "functions"),
574
589
  parsed.dir,
575
590
  parsed.name + ".prerender-config.json"
576
591
  );
577
- await import_promises3.default.mkdir(
578
- import_path4.default.join(getOutput(resolvedConfig, "functions"), parsed.dir),
592
+ await import_promises4.default.mkdir(
593
+ import_path5.default.join(getOutput(resolvedConfig, "functions"), parsed.dir),
579
594
  { recursive: true }
580
595
  );
581
- await import_promises3.default.writeFile(
596
+ await import_promises4.default.writeFile(
582
597
  outfile,
583
598
  JSON.stringify(
584
599
  vercelOutputPrerenderConfigSchema.parse({
@@ -592,15 +607,15 @@ async function writePrerenderConfig(resolvedConfig, destination, isr) {
592
607
  );
593
608
  }
594
609
  function getPrerenderSymlinkInfo(resolvedConfig, destination, target) {
595
- const parsed = import_path4.default.parse(destination);
596
- const targetParsed = import_path4.default.parse(target);
610
+ const parsed = import_path5.default.parse(destination);
611
+ const targetParsed = import_path5.default.parse(target);
597
612
  return {
598
- target: import_path4.default.join(
613
+ target: import_path5.default.join(
599
614
  getOutput(resolvedConfig, "functions"),
600
615
  targetParsed.dir,
601
616
  targetParsed.name + ".func"
602
617
  ),
603
- link: import_path4.default.join(
618
+ link: import_path5.default.join(
604
619
  getOutput(resolvedConfig, "functions"),
605
620
  parsed.dir,
606
621
  parsed.name + ".func"
@@ -634,15 +649,6 @@ async function buildPrerenderConfigs(resolvedConfig, extractedIsr) {
634
649
  }
635
650
  return rewrites;
636
651
  }
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
652
  async function getIsrConfig(resolvedConfig) {
647
653
  var _a;
648
654
  const isr = ((_a = resolvedConfig.vercel) == null ? void 0 : _a.isr) ?? {};
@@ -653,7 +659,7 @@ async function getIsrConfig(resolvedConfig) {
653
659
  }
654
660
 
655
661
  // src/index.ts
656
- var import_path5 = __toESM(require("path"), 1);
662
+ var import_path6 = __toESM(require("path"), 1);
657
663
  function vercelPlugin() {
658
664
  let resolvedConfig;
659
665
  let vikeFound = false;
@@ -662,10 +668,15 @@ function vercelPlugin() {
662
668
  name: "vite-plugin-vercel",
663
669
  enforce: "post",
664
670
  configResolved(config) {
671
+ var _a;
665
672
  resolvedConfig = config;
666
673
  vikeFound = resolvedConfig.plugins.some(
667
674
  (p) => p.name.match("^vite-plugin-ssr:|^vike:")
668
675
  );
676
+ if (typeof ((_a = resolvedConfig.vercel) == null ? void 0 : _a.distContainsOnlyStatic) === "undefined") {
677
+ resolvedConfig.vercel ??= {};
678
+ resolvedConfig.vercel.distContainsOnlyStatic = !vikeFound;
679
+ }
669
680
  },
670
681
  async writeBundle() {
671
682
  var _a;
@@ -688,15 +699,25 @@ function vercelPlugin() {
688
699
  },
689
700
  headers
690
701
  );
702
+ await copyDistToStatic(resolvedConfig);
691
703
  }
692
704
  };
693
705
  }
694
706
  async function cleanOutputDirectory(resolvedConfig) {
695
- await import_promises4.default.rm(getOutput(resolvedConfig), {
707
+ await import_promises5.default.rm(getOutput(resolvedConfig), {
696
708
  recursive: true,
697
709
  force: true
698
710
  });
699
- await import_promises4.default.mkdir(getOutput(resolvedConfig), { recursive: true });
711
+ await import_promises5.default.mkdir(getOutput(resolvedConfig), { recursive: true });
712
+ }
713
+ async function copyDistToStatic(resolvedConfig) {
714
+ var _a;
715
+ if ((_a = resolvedConfig.vercel) == null ? void 0 : _a.distContainsOnlyStatic) {
716
+ await copyDir(
717
+ resolvedConfig.build.outDir,
718
+ getOutput(resolvedConfig, "static")
719
+ );
720
+ }
700
721
  }
701
722
  async function computeStaticHtmlOverrides(resolvedConfig) {
702
723
  const staticAbsolutePath = getOutput(resolvedConfig, "static");
@@ -707,9 +728,9 @@ async function computeStaticHtmlOverrides(resolvedConfig) {
707
728
  ...publicFiles.map((f) => f.replace(publicDir, staticAbsolutePath))
708
729
  );
709
730
  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);
731
+ const relPath = import_path6.default.relative(staticAbsolutePath, curr);
732
+ const parsed = import_path6.default.parse(relPath);
733
+ const pathJoined = import_path6.default.join(parsed.dir, parsed.name);
713
734
  acc[relPath] = {
714
735
  path: pathJoined
715
736
  };
@@ -718,14 +739,14 @@ async function computeStaticHtmlOverrides(resolvedConfig) {
718
739
  }
719
740
  async function getStaticHtmlFiles(src) {
720
741
  try {
721
- await import_promises4.default.stat(src);
742
+ await import_promises5.default.stat(src);
722
743
  } catch (e) {
723
744
  return [];
724
745
  }
725
- const entries = await import_promises4.default.readdir(src, { withFileTypes: true });
746
+ const entries = await import_promises5.default.readdir(src, { withFileTypes: true });
726
747
  const htmlFiles = [];
727
748
  for (const entry of entries) {
728
- const srcPath = import_path5.default.join(src, entry.name);
749
+ const srcPath = import_path6.default.join(src, entry.name);
729
750
  entry.isDirectory() ? htmlFiles.push(...await getStaticHtmlFiles(srcPath)) : srcPath.endsWith(".html") ? htmlFiles.push(srcPath) : void 0;
730
751
  }
731
752
  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";
@@ -514,7 +514,7 @@ async function buildEndpoints(resolvedConfig) {
514
514
  }
515
515
 
516
516
  // src/prerender.ts
517
- import path4 from "path";
517
+ import path5 from "path";
518
518
 
519
519
  // src/schemas/config/prerender-config.ts
520
520
  import { z as z4 } from "zod";
@@ -527,7 +527,22 @@ var vercelOutputPrerenderConfigSchema = z4.object({
527
527
  }).strict();
528
528
 
529
529
  // src/prerender.ts
530
+ import fs4 from "fs/promises";
531
+
532
+ // src/helpers.ts
530
533
  import fs3 from "fs/promises";
534
+ import path4 from "path";
535
+ async function copyDir(src, dest) {
536
+ await fs3.mkdir(dest, { recursive: true });
537
+ const entries = await fs3.readdir(src, { withFileTypes: true });
538
+ for (const entry of entries) {
539
+ const srcPath = path4.join(src, entry.name);
540
+ const destPath = path4.join(dest, entry.name);
541
+ entry.isDirectory() ? await copyDir(srcPath, destPath) : await fs3.copyFile(srcPath, destPath);
542
+ }
543
+ }
544
+
545
+ // src/prerender.ts
531
546
  function execPrerender(resolvedConfig) {
532
547
  var _a;
533
548
  const prerender = (_a = resolvedConfig.vercel) == null ? void 0 : _a.prerender;
@@ -538,17 +553,17 @@ function execPrerender(resolvedConfig) {
538
553
  }
539
554
  var group = 1;
540
555
  async function writePrerenderConfig(resolvedConfig, destination, isr) {
541
- const parsed = path4.parse(destination);
542
- const outfile = path4.join(
556
+ const parsed = path5.parse(destination);
557
+ const outfile = path5.join(
543
558
  getOutput(resolvedConfig, "functions"),
544
559
  parsed.dir,
545
560
  parsed.name + ".prerender-config.json"
546
561
  );
547
- await fs3.mkdir(
548
- path4.join(getOutput(resolvedConfig, "functions"), parsed.dir),
562
+ await fs4.mkdir(
563
+ path5.join(getOutput(resolvedConfig, "functions"), parsed.dir),
549
564
  { recursive: true }
550
565
  );
551
- await fs3.writeFile(
566
+ await fs4.writeFile(
552
567
  outfile,
553
568
  JSON.stringify(
554
569
  vercelOutputPrerenderConfigSchema.parse({
@@ -562,15 +577,15 @@ async function writePrerenderConfig(resolvedConfig, destination, isr) {
562
577
  );
563
578
  }
564
579
  function getPrerenderSymlinkInfo(resolvedConfig, destination, target) {
565
- const parsed = path4.parse(destination);
566
- const targetParsed = path4.parse(target);
580
+ const parsed = path5.parse(destination);
581
+ const targetParsed = path5.parse(target);
567
582
  return {
568
- target: path4.join(
583
+ target: path5.join(
569
584
  getOutput(resolvedConfig, "functions"),
570
585
  targetParsed.dir,
571
586
  targetParsed.name + ".func"
572
587
  ),
573
- link: path4.join(
588
+ link: path5.join(
574
589
  getOutput(resolvedConfig, "functions"),
575
590
  parsed.dir,
576
591
  parsed.name + ".func"
@@ -604,15 +619,6 @@ async function buildPrerenderConfigs(resolvedConfig, extractedIsr) {
604
619
  }
605
620
  return rewrites;
606
621
  }
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
622
  async function getIsrConfig(resolvedConfig) {
617
623
  var _a;
618
624
  const isr = ((_a = resolvedConfig.vercel) == null ? void 0 : _a.isr) ?? {};
@@ -623,7 +629,7 @@ async function getIsrConfig(resolvedConfig) {
623
629
  }
624
630
 
625
631
  // src/index.ts
626
- import path5 from "path";
632
+ import path6 from "path";
627
633
  function vercelPlugin() {
628
634
  let resolvedConfig;
629
635
  let vikeFound = false;
@@ -632,10 +638,15 @@ function vercelPlugin() {
632
638
  name: "vite-plugin-vercel",
633
639
  enforce: "post",
634
640
  configResolved(config) {
641
+ var _a;
635
642
  resolvedConfig = config;
636
643
  vikeFound = resolvedConfig.plugins.some(
637
644
  (p) => p.name.match("^vite-plugin-ssr:|^vike:")
638
645
  );
646
+ if (typeof ((_a = resolvedConfig.vercel) == null ? void 0 : _a.distContainsOnlyStatic) === "undefined") {
647
+ resolvedConfig.vercel ??= {};
648
+ resolvedConfig.vercel.distContainsOnlyStatic = !vikeFound;
649
+ }
639
650
  },
640
651
  async writeBundle() {
641
652
  var _a;
@@ -658,15 +669,25 @@ function vercelPlugin() {
658
669
  },
659
670
  headers
660
671
  );
672
+ await copyDistToStatic(resolvedConfig);
661
673
  }
662
674
  };
663
675
  }
664
676
  async function cleanOutputDirectory(resolvedConfig) {
665
- await fs4.rm(getOutput(resolvedConfig), {
677
+ await fs5.rm(getOutput(resolvedConfig), {
666
678
  recursive: true,
667
679
  force: true
668
680
  });
669
- await fs4.mkdir(getOutput(resolvedConfig), { recursive: true });
681
+ await fs5.mkdir(getOutput(resolvedConfig), { recursive: true });
682
+ }
683
+ async function copyDistToStatic(resolvedConfig) {
684
+ var _a;
685
+ if ((_a = resolvedConfig.vercel) == null ? void 0 : _a.distContainsOnlyStatic) {
686
+ await copyDir(
687
+ resolvedConfig.build.outDir,
688
+ getOutput(resolvedConfig, "static")
689
+ );
690
+ }
670
691
  }
671
692
  async function computeStaticHtmlOverrides(resolvedConfig) {
672
693
  const staticAbsolutePath = getOutput(resolvedConfig, "static");
@@ -677,9 +698,9 @@ async function computeStaticHtmlOverrides(resolvedConfig) {
677
698
  ...publicFiles.map((f) => f.replace(publicDir, staticAbsolutePath))
678
699
  );
679
700
  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);
701
+ const relPath = path6.relative(staticAbsolutePath, curr);
702
+ const parsed = path6.parse(relPath);
703
+ const pathJoined = path6.join(parsed.dir, parsed.name);
683
704
  acc[relPath] = {
684
705
  path: pathJoined
685
706
  };
@@ -688,14 +709,14 @@ async function computeStaticHtmlOverrides(resolvedConfig) {
688
709
  }
689
710
  async function getStaticHtmlFiles(src) {
690
711
  try {
691
- await fs4.stat(src);
712
+ await fs5.stat(src);
692
713
  } catch (e) {
693
714
  return [];
694
715
  }
695
- const entries = await fs4.readdir(src, { withFileTypes: true });
716
+ const entries = await fs5.readdir(src, { withFileTypes: true });
696
717
  const htmlFiles = [];
697
718
  for (const entry of entries) {
698
- const srcPath = path5.join(src, entry.name);
719
+ const srcPath = path6.join(src, entry.name);
699
720
  entry.isDirectory() ? htmlFiles.push(...await getStaticHtmlFiles(srcPath)) : srcPath.endsWith(".html") ? htmlFiles.push(srcPath) : void 0;
700
721
  }
701
722
  return htmlFiles;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-vercel",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -21,8 +21,8 @@
21
21
  "license": "MIT",
22
22
  "peerDependencies": {
23
23
  "vike": "*",
24
- "vite": "^4.2.0",
25
- "@vite-plugin-vercel/vike": "3.0.0"
24
+ "vite": "^4.4 || ^5.0.2",
25
+ "@vite-plugin-vercel/vike": "3.0.1"
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.0"
42
+ "vike": "^0.4.160",
43
+ "vite": "^5.0.12",
44
+ "@vite-plugin-vercel/vike": "3.0.1"
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",