vite-plugin-vercel 6.0.1 → 7.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/dist/index.cjs CHANGED
@@ -280,7 +280,6 @@ var vercelOutputVcConfigSchema = import_zod2.z.union([
280
280
 
281
281
  // src/build.ts
282
282
  var import_promises2 = __toESM(require("fs/promises"), 1);
283
- var import_eval = __toESM(require("eval"), 1);
284
283
 
285
284
  // src/schemas/exports.ts
286
285
  var import_zod3 = require("zod");
@@ -367,7 +366,11 @@ var standardBuildOptions = {
367
366
  "require-resolve-not-external": "verbose"
368
367
  },
369
368
  minify: false,
370
- plugins: []
369
+ plugins: [],
370
+ define: {
371
+ "process.env.NODE_ENV": '"production"',
372
+ "import.meta.env.NODE_ENV": '"production"'
373
+ }
371
374
  };
372
375
  async function buildFn(resolvedConfig, entry, buildOptions) {
373
376
  var _a;
@@ -514,39 +517,28 @@ var RE_BRACKETS = /^\[([^/]+)\]$/gm;
514
517
  function replaceBrackets(source) {
515
518
  return source.split("/").map((segment) => segment.replace(RE_BRACKETS, ":$1")).join("/");
516
519
  }
517
- async function removeDefaultExport(filepath) {
518
- const mod = await (0, import_magicast.loadFile)(filepath);
519
- try {
520
- delete mod.exports.default;
521
- } catch (_) {
522
- }
523
- return (0, import_magicast.generateCode)(mod).code;
520
+ function isPrimitive(test) {
521
+ return test !== Object(test);
522
+ }
523
+ function _eval(code) {
524
+ const func = new Function(`{ return function(){ return ${code} } };`);
525
+ return func.call(null).call(null);
526
+ }
527
+ function evalExport(exp) {
528
+ if (!exp) return;
529
+ const code = isPrimitive(exp) ? exp : (0, import_magicast.generateCode)(exp).code;
530
+ return _eval(code);
524
531
  }
525
532
  async function extractExports(filepath) {
526
- var _a;
527
533
  try {
528
- const contents = await removeDefaultExport(filepath);
529
- const buildOptions = {
530
- ...standardBuildOptions,
531
- format: "cjs",
532
- minify: false,
533
- write: false,
534
- legalComments: "none"
535
- };
536
- buildOptions.stdin = {
537
- sourcefile: filepath,
538
- contents,
539
- loader: filepath.endsWith(".ts") ? "ts" : filepath.endsWith(".tsx") ? "tsx" : filepath.endsWith(".js") ? "js" : filepath.endsWith(".jsx") ? "jsx" : "default",
540
- resolveDir: (0, import_path3.dirname)(filepath)
541
- };
542
- buildOptions.banner = {
543
- js: `const __filename = ${JSON.stringify(filepath)};
544
- const __dirname = ${JSON.stringify((0, import_path3.dirname)(filepath))};
545
- `
534
+ const mod = await (0, import_magicast.loadFile)(filepath);
535
+ const subject = {
536
+ edge: evalExport(mod.exports.edge),
537
+ headers: evalExport(mod.exports.headers),
538
+ streaming: evalExport(mod.exports.streaming),
539
+ isr: evalExport(mod.exports.isr)
546
540
  };
547
- const output = await (0, import_esbuild.build)(buildOptions);
548
- const bundle = new TextDecoder().decode((_a = output.outputFiles[0]) == null ? void 0 : _a.contents);
549
- return vercelEndpointExports.parse((0, import_eval.default)(bundle, filepath, {}, true));
541
+ return vercelEndpointExports.parse(subject);
550
542
  } catch (e) {
551
543
  console.warn(`Warning: failed to read exports of '${filepath}'`, e);
552
544
  }
@@ -840,25 +832,26 @@ async function getStaticHtmlFiles(src) {
840
832
  }
841
833
  return htmlFiles;
842
834
  }
843
- async function tryImportVpvv() {
835
+ async function tryImportVpvv(options) {
844
836
  try {
845
837
  await import("vike/plugin");
846
838
  const vpvv = await import("@vite-plugin-vercel/vike");
847
- return vpvv.default();
839
+ return vpvv.default(options);
848
840
  } catch (e) {
849
841
  try {
850
842
  await import("vite-plugin-ssr/plugin");
851
843
  const vpvv = await import("@vite-plugin-vercel/vike");
852
- return vpvv.default();
844
+ return vpvv.default(options);
853
845
  } catch (e2) {
854
846
  return null;
855
847
  }
856
848
  }
857
849
  }
858
850
  function allPlugins(options = {}) {
851
+ const { smart, ...rest } = options;
859
852
  return [
860
853
  vercelPluginCleanup(),
861
854
  vercelPlugin(),
862
- options.smart !== false ? tryImportVpvv() : null
855
+ smart !== false ? tryImportVpvv(rest) : null
863
856
  ];
864
857
  }
package/dist/index.d.cts CHANGED
@@ -678,8 +678,6 @@ interface ViteVercelApiEntry {
678
678
  streaming?: boolean;
679
679
  }
680
680
 
681
- declare function allPlugins(options?: {
682
- smart?: boolean;
683
- }): PluginOption[];
681
+ declare function allPlugins(options?: any): PluginOption[];
684
682
 
685
683
  export { type VercelOutputConfig, type VercelOutputIsr, type VercelOutputPrerenderConfig, type VercelOutputVcConfig, type ViteVercelApiEntry, type ViteVercelConfig, type ViteVercelPrerenderFn, type ViteVercelPrerenderRoute, type ViteVercelRedirect, type ViteVercelRewrite, allPlugins as default };
package/dist/index.d.ts CHANGED
@@ -678,8 +678,6 @@ interface ViteVercelApiEntry {
678
678
  streaming?: boolean;
679
679
  }
680
680
 
681
- declare function allPlugins(options?: {
682
- smart?: boolean;
683
- }): PluginOption[];
681
+ declare function allPlugins(options?: any): PluginOption[];
684
682
 
685
683
  export { type VercelOutputConfig, type VercelOutputIsr, type VercelOutputPrerenderConfig, type VercelOutputVcConfig, type ViteVercelApiEntry, type ViteVercelConfig, type ViteVercelPrerenderFn, type ViteVercelPrerenderRoute, type ViteVercelRedirect, type ViteVercelRewrite, allPlugins as default };
package/dist/index.js CHANGED
@@ -205,7 +205,7 @@ async function writeConfig(resolvedConfig, rewrites, overrides, headers) {
205
205
 
206
206
  // src/build.ts
207
207
  import glob from "fast-glob";
208
- import path3, { basename, dirname } from "path";
208
+ import path3, { basename } from "path";
209
209
  import { build } from "esbuild";
210
210
 
211
211
  // src/assert.ts
@@ -250,7 +250,6 @@ var vercelOutputVcConfigSchema = z2.union([
250
250
 
251
251
  // src/build.ts
252
252
  import fs2, { copyFile } from "fs/promises";
253
- import _eval from "eval";
254
253
 
255
254
  // src/schemas/exports.ts
256
255
  import { z as z3 } from "zod";
@@ -337,7 +336,11 @@ var standardBuildOptions = {
337
336
  "require-resolve-not-external": "verbose"
338
337
  },
339
338
  minify: false,
340
- plugins: []
339
+ plugins: [],
340
+ define: {
341
+ "process.env.NODE_ENV": '"production"',
342
+ "import.meta.env.NODE_ENV": '"production"'
343
+ }
341
344
  };
342
345
  async function buildFn(resolvedConfig, entry, buildOptions) {
343
346
  var _a;
@@ -484,39 +487,28 @@ var RE_BRACKETS = /^\[([^/]+)\]$/gm;
484
487
  function replaceBrackets(source) {
485
488
  return source.split("/").map((segment) => segment.replace(RE_BRACKETS, ":$1")).join("/");
486
489
  }
487
- async function removeDefaultExport(filepath) {
488
- const mod = await loadFile(filepath);
489
- try {
490
- delete mod.exports.default;
491
- } catch (_) {
492
- }
493
- return generateCode(mod).code;
490
+ function isPrimitive(test) {
491
+ return test !== Object(test);
492
+ }
493
+ function _eval(code) {
494
+ const func = new Function(`{ return function(){ return ${code} } };`);
495
+ return func.call(null).call(null);
496
+ }
497
+ function evalExport(exp) {
498
+ if (!exp) return;
499
+ const code = isPrimitive(exp) ? exp : generateCode(exp).code;
500
+ return _eval(code);
494
501
  }
495
502
  async function extractExports(filepath) {
496
- var _a;
497
503
  try {
498
- const contents = await removeDefaultExport(filepath);
499
- const buildOptions = {
500
- ...standardBuildOptions,
501
- format: "cjs",
502
- minify: false,
503
- write: false,
504
- legalComments: "none"
505
- };
506
- buildOptions.stdin = {
507
- sourcefile: filepath,
508
- contents,
509
- loader: filepath.endsWith(".ts") ? "ts" : filepath.endsWith(".tsx") ? "tsx" : filepath.endsWith(".js") ? "js" : filepath.endsWith(".jsx") ? "jsx" : "default",
510
- resolveDir: dirname(filepath)
511
- };
512
- buildOptions.banner = {
513
- js: `const __filename = ${JSON.stringify(filepath)};
514
- const __dirname = ${JSON.stringify(dirname(filepath))};
515
- `
504
+ const mod = await loadFile(filepath);
505
+ const subject = {
506
+ edge: evalExport(mod.exports.edge),
507
+ headers: evalExport(mod.exports.headers),
508
+ streaming: evalExport(mod.exports.streaming),
509
+ isr: evalExport(mod.exports.isr)
516
510
  };
517
- const output = await build(buildOptions);
518
- const bundle = new TextDecoder().decode((_a = output.outputFiles[0]) == null ? void 0 : _a.contents);
519
- return vercelEndpointExports.parse(_eval(bundle, filepath, {}, true));
511
+ return vercelEndpointExports.parse(subject);
520
512
  } catch (e) {
521
513
  console.warn(`Warning: failed to read exports of '${filepath}'`, e);
522
514
  }
@@ -810,26 +802,27 @@ async function getStaticHtmlFiles(src) {
810
802
  }
811
803
  return htmlFiles;
812
804
  }
813
- async function tryImportVpvv() {
805
+ async function tryImportVpvv(options) {
814
806
  try {
815
807
  await import("vike/plugin");
816
808
  const vpvv = await import("@vite-plugin-vercel/vike");
817
- return vpvv.default();
809
+ return vpvv.default(options);
818
810
  } catch (e) {
819
811
  try {
820
812
  await import("vite-plugin-ssr/plugin");
821
813
  const vpvv = await import("@vite-plugin-vercel/vike");
822
- return vpvv.default();
814
+ return vpvv.default(options);
823
815
  } catch (e2) {
824
816
  return null;
825
817
  }
826
818
  }
827
819
  }
828
820
  function allPlugins(options = {}) {
821
+ const { smart, ...rest } = options;
829
822
  return [
830
823
  vercelPluginCleanup(),
831
824
  vercelPlugin(),
832
- options.smart !== false ? tryImportVpvv() : null
825
+ smart !== false ? tryImportVpvv(rest) : null
833
826
  ];
834
827
  }
835
828
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-vercel",
3
- "version": "6.0.1",
3
+ "version": "7.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": "6.0.1"
25
+ "@vite-plugin-vercel/vike": "7.0.1"
26
26
  },
27
27
  "peerDependenciesMeta": {
28
28
  "@vite-plugin-vercel/vike": {
@@ -34,26 +34,25 @@
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/node": "^18.19.31",
37
- "@typescript-eslint/eslint-plugin": "^7.7.0",
38
- "@typescript-eslint/parser": "^7.7.0",
37
+ "@typescript-eslint/eslint-plugin": "^7.15.0",
38
+ "@typescript-eslint/parser": "^7.15.0",
39
39
  "eslint": "^8.57.0",
40
- "tsup": "^8.0.2",
41
- "typescript": "^5.4.5",
42
- "vike": "^0.4.171",
43
- "vite": "^5.2.10",
44
- "@vite-plugin-vercel/vike": "6.0.1"
40
+ "tsup": "^8.1.0",
41
+ "typescript": "^5.5.3",
42
+ "vike": "^0.4.178",
43
+ "vite": "^5.3.2",
44
+ "@vite-plugin-vercel/vike": "7.0.1"
45
45
  },
46
46
  "dependencies": {
47
47
  "@brillout/libassert": "^0.5.8",
48
- "@manypkg/find-root": "^2.2.1",
49
- "@vercel/build-utils": "^7.12.0",
50
- "@vercel/nft": "^0.26.4",
48
+ "@manypkg/find-root": "^2.2.2",
49
+ "@vercel/build-utils": "^8.2.2",
50
+ "@vercel/nft": "^0.27.2",
51
51
  "@vercel/routing-utils": "^3.1.0",
52
- "esbuild": "^0.20.2",
53
- "eval": "^0.1.8",
52
+ "esbuild": "^0.23.0",
54
53
  "fast-glob": "^3.3.2",
55
54
  "magicast": "^0.3.4",
56
- "zod": "^3.23.0"
55
+ "zod": "^3.23.8"
57
56
  },
58
57
  "scripts": {
59
58
  "build": "tsup",