vite-plugin-vercel 9.0.7 → 10.0.0-beta.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.
@@ -0,0 +1,121 @@
1
+ /// <reference types="@photonjs/core" />
2
+
3
+ import { Photon } from '@photonjs/core';
4
+ import { Rewrite, Header, Redirect } from '@vercel/routing-utils';
5
+ import { VercelOutputPrerenderConfig, VercelOutputConfig } from '@vite-plugin-vercel/schemas';
6
+
7
+ type ViteVercelRewrite = Rewrite & {
8
+ enforce?: "pre" | "post";
9
+ };
10
+ type ViteVercelRedirect = Redirect & {
11
+ enforce?: "pre" | "post";
12
+ };
13
+ interface ViteVercelConfig {
14
+ /**
15
+ * How long Functions should be allowed to run for every request, in seconds.
16
+ * If left empty, default value for your plan will be used.
17
+ */
18
+ defaultMaxDuration?: number;
19
+ /**
20
+ * Default expiration time (in seconds) for prerender functions.
21
+ * Defaults to 86400 seconds (24h).
22
+ * @see {@link https://vercel.com/docs/concepts/next.js/incremental-static-regeneration}
23
+ * @see {@link https://vercel.com/docs/build-output-api/v3#vercel-primitives/prerender-functions/configuration}
24
+ */
25
+ expiration?: number;
26
+ /**
27
+ * @see {@link https://vercel.com/docs/projects/project-configuration#rewrites}
28
+ */
29
+ rewrites?: ViteVercelRewrite[];
30
+ /**
31
+ * @see {@link https://vercel.com/docs/projects/project-configuration#headers}
32
+ * @beta
33
+ */
34
+ headers?: Header[];
35
+ /**
36
+ * @see {@link https://vercel.com/docs/projects/project-configuration#redirects}
37
+ */
38
+ redirects?: ViteVercelRedirect[];
39
+ /**
40
+ * @see {@link https://vercel.com/docs/projects/project-configuration#cleanurls}
41
+ */
42
+ cleanUrls?: boolean;
43
+ /**
44
+ * @see {@link https://vercel.com/docs/projects/project-configuration#trailingslash}
45
+ */
46
+ trailingSlash?: boolean;
47
+ /**
48
+ * When true, the Serverless Function will stream the response to the client.
49
+ * @see {@link https://vercel.com/docs/build-output-api/v3/primitives#serverless-function-configuration}
50
+ */
51
+ defaultSupportsResponseStreaming?: boolean;
52
+ /**
53
+ * Use `getEntriesFromFs` for mapping your filesystem routes to entries.
54
+ * If you are interfacing this plugin with a framework, entries can also be added through the Photon API
55
+ */
56
+ entries?: Record<string, Photon.EntryUniversalHandler>;
57
+ /**
58
+ * TODO
59
+ */
60
+ server?: Photon.EntryServer;
61
+ /**
62
+ * Advanced configuration to override .vercel/output/config.json
63
+ * @see {@link https://vercel.com/docs/build-output-api/v3/configuration#configuration}
64
+ * @protected
65
+ */
66
+ config?: Partial<Omit<VercelOutputConfig, "version">>;
67
+ /**
68
+ * Defaults to `.vercel/output`. Mostly useful for testing purpose
69
+ * @protected
70
+ */
71
+ outDir?: string;
72
+ }
73
+ interface VercelOutputIsr extends VercelOutputPrerenderConfig {
74
+ symlink?: string;
75
+ route?: string;
76
+ }
77
+ /**
78
+ * Keys are path relative to .vercel/output/static directory
79
+ */
80
+ type ViteVercelRouteOverrides = VercelOutputConfig["overrides"];
81
+ interface VercelEntryOptions {
82
+ /**
83
+ * Relative to `.vercel/output/functions`, without extension
84
+ */
85
+ destination?: string;
86
+ /**
87
+ * If `true`, guesses route for the function, and adds it to config.json (mimics defaults Vercel behavior).
88
+ * If a string is provided, it will be equivalent to a `rewrites` rule.
89
+ * Set to `false` to disable
90
+ */
91
+ route?: string | boolean;
92
+ /**
93
+ * Ensures that the route is added before or after others
94
+ */
95
+ enforce?: "post" | "pre";
96
+ /**
97
+ * Set to `true` to mark this function as an Edge Function
98
+ */
99
+ edge?: boolean;
100
+ /**
101
+ * Additional headers
102
+ */
103
+ headers?: Record<string, string> | null;
104
+ /**
105
+ * ISR config
106
+ */
107
+ isr?: VercelOutputIsr;
108
+ /**
109
+ * When true, the Serverless Function will stream the response to the client
110
+ */
111
+ streaming?: boolean;
112
+ }
113
+ declare module "@photonjs/core" {
114
+ namespace Photon {
115
+ interface EntryBase {
116
+ vercel?: VercelEntryOptions;
117
+ }
118
+ }
119
+ }
120
+
121
+ export type { VercelEntryOptions, VercelOutputIsr, ViteVercelConfig, ViteVercelRedirect, ViteVercelRewrite, ViteVercelRouteOverrides };
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ import "./chunk-6F4PWJZI.js";
@@ -0,0 +1,17 @@
1
+ /// <reference types="@photonjs/core" />
2
+
3
+ import './types.js';
4
+ import { UniversalMiddleware } from '@universal-middleware/core';
5
+ import { Photon } from '@photonjs/core';
6
+ import '@vercel/routing-utils';
7
+ import '@vite-plugin-vercel/schemas';
8
+
9
+ declare const applyVercelHeaders: UniversalMiddleware<Universal.Context & {
10
+ photon?: {
11
+ handler?: Photon.EntryUniversalHandler;
12
+ server?: Photon.EntryServer;
13
+ };
14
+ }>;
15
+ declare const _default: UniversalMiddleware[];
16
+
17
+ export { applyVercelHeaders, _default as default };
@@ -0,0 +1,26 @@
1
+ import "./chunk-6F4PWJZI.js";
2
+
3
+ // src/photon/universal-middleware-dev.ts
4
+ import { enhance, MiddlewareOrder } from "@universal-middleware/core";
5
+ var applyVercelHeaders = (_request, context) => {
6
+ console.log(_request.url, context);
7
+ const headers = context.photon?.handler?.vercel?.headers ?? context.photon?.server?.vercel?.headers;
8
+ if (!headers) return;
9
+ return (response) => {
10
+ for (const [key, value] of Object.entries(headers)) {
11
+ response.headers.set(key, value);
12
+ }
13
+ return response;
14
+ };
15
+ };
16
+ var universal_middleware_dev_default = [
17
+ enhance(applyVercelHeaders, {
18
+ name: "vercel:headers",
19
+ immutable: true,
20
+ order: MiddlewareOrder.HEADER_MANAGEMENT
21
+ })
22
+ ];
23
+ export {
24
+ applyVercelHeaders,
25
+ universal_middleware_dev_default as default
26
+ };
@@ -0,0 +1,12 @@
1
+ /// <reference types="@photonjs/core" />
2
+
3
+ import './types.js';
4
+ import { UniversalMiddleware } from '@universal-middleware/core';
5
+ import '@photonjs/core';
6
+ import '@vercel/routing-utils';
7
+ import '@vite-plugin-vercel/schemas';
8
+
9
+ declare const overrideVercelRequest: UniversalMiddleware;
10
+ declare const _default: UniversalMiddleware[];
11
+
12
+ export { _default as default, overrideVercelRequest };
@@ -0,0 +1,21 @@
1
+ import {
2
+ getOriginalRequest
3
+ } from "./chunk-YN5MUEL2.js";
4
+ import "./chunk-6F4PWJZI.js";
5
+
6
+ // src/photon/universal-middleware-prod.ts
7
+ import { enhance } from "@universal-middleware/core";
8
+ var overrideVercelRequest = (request) => {
9
+ Object.assign(request, getOriginalRequest(request));
10
+ };
11
+ var universal_middleware_prod_default = [
12
+ enhance(overrideVercelRequest, {
13
+ name: "vercel:request",
14
+ immutable: true,
15
+ order: Number.MIN_SAFE_INTEGER
16
+ })
17
+ ];
18
+ export {
19
+ universal_middleware_prod_default as default,
20
+ overrideVercelRequest
21
+ };
@@ -0,0 +1,23 @@
1
+ /// <reference types="@photonjs/core" />
2
+
3
+ import './types.js';
4
+ import { Photon } from '@photonjs/core';
5
+ import '@vercel/routing-utils';
6
+ import '@vite-plugin-vercel/schemas';
7
+
8
+ declare function getEntriesFromFs(dir: string, { destination, tryParseExports }: {
9
+ destination?: string | undefined;
10
+ tryParseExports?: boolean | undefined;
11
+ }): Promise<Record<string, Photon.EntryUniversalHandler>>;
12
+ declare function extractExports(filepath: string): Promise<{
13
+ edge?: boolean | undefined;
14
+ headers?: Record<string, string> | undefined;
15
+ streaming?: boolean | undefined;
16
+ isr?: {
17
+ expiration: number | false;
18
+ } | undefined;
19
+ } | null>;
20
+
21
+ declare function getOriginalRequest(request: Request): Request;
22
+
23
+ export { extractExports, getEntriesFromFs, getOriginalRequest };
package/dist/utils.js ADDED
@@ -0,0 +1,82 @@
1
+ import {
2
+ entryToRou3
3
+ } from "./chunk-OCCU6UM5.js";
4
+ import "./chunk-UTQ72LMT.js";
5
+ import {
6
+ getOriginalRequest
7
+ } from "./chunk-YN5MUEL2.js";
8
+ import "./chunk-6F4PWJZI.js";
9
+
10
+ // src/utils/fs-entries.ts
11
+ import path from "path";
12
+ import glob from "fast-glob";
13
+ import { generateCode, loadFile } from "magicast";
14
+ import { normalizePath } from "vite";
15
+ import { vercelEndpointExports } from "@vite-plugin-vercel/schemas";
16
+ async function getEntriesFromFs(dir, { destination = dir, tryParseExports = true }) {
17
+ const normalizedDir = normalizePath(dir);
18
+ destination = normalizePath(destination);
19
+ const apiEntries = glob.sync(`${path.posix.resolve(normalizedDir)}/**/*.?(m)[jt]s?(x)`).filter((filepath) => !path.basename(filepath).startsWith("_"));
20
+ const entryPoints = {};
21
+ for (const filePath of apiEntries) {
22
+ const outFilePath = pathRelativeTo(filePath, normalizedDir);
23
+ const parsed = path.posix.parse(outFilePath);
24
+ let xports;
25
+ if (tryParseExports) {
26
+ xports = await extractExports(filePath);
27
+ }
28
+ const key = path.posix.join(destination, parsed.dir, parsed.name);
29
+ const entry = {
30
+ id: filePath,
31
+ name: key,
32
+ type: "universal-handler",
33
+ compositionMode: "isolated",
34
+ vercel: {
35
+ route: true,
36
+ destination: key,
37
+ edge: xports?.edge,
38
+ isr: xports?.isr,
39
+ headers: xports?.headers,
40
+ streaming: xports?.streaming
41
+ }
42
+ };
43
+ entry.route = entryToRou3(entry)[0];
44
+ entryPoints[key] = entry;
45
+ }
46
+ return entryPoints;
47
+ }
48
+ async function extractExports(filepath) {
49
+ try {
50
+ const mod = await loadFile(filepath);
51
+ const subject = {
52
+ edge: evalExport(mod.exports.edge),
53
+ headers: evalExport(mod.exports.headers),
54
+ streaming: evalExport(mod.exports.streaming),
55
+ isr: evalExport(mod.exports.isr)
56
+ };
57
+ return vercelEndpointExports.parse(subject);
58
+ } catch (e) {
59
+ console.warn(`Warning: failed to read exports of '${filepath}'`, e);
60
+ return null;
61
+ }
62
+ }
63
+ function pathRelativeTo(filePath, rel) {
64
+ return normalizePath(path.relative(normalizePath(path.resolve(rel)), path.resolve(filePath)));
65
+ }
66
+ function isPrimitive(test) {
67
+ return test !== Object(test);
68
+ }
69
+ function _eval(code) {
70
+ const func = new Function(`{ return function(){ return ${code} } };`);
71
+ return func.call(null).call(null);
72
+ }
73
+ function evalExport(exp) {
74
+ if (!exp) return;
75
+ const code = isPrimitive(exp) ? exp : generateCode(exp).code;
76
+ return _eval(code);
77
+ }
78
+ export {
79
+ extractExports,
80
+ getEntriesFromFs,
81
+ getOriginalRequest
82
+ };
package/package.json CHANGED
@@ -1,59 +1,56 @@
1
1
  {
2
2
  "name": "vite-plugin-vercel",
3
- "version": "9.0.7",
3
+ "version": "10.0.0-beta.1",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
7
7
  "*.d.ts"
8
8
  ],
9
- "main": "./dist/index.cjs",
10
9
  "module": "./dist/index.js",
11
10
  "exports": {
12
- ".": {
13
- "types": "./index.d.ts",
14
- "import": "./dist/index.js",
15
- "require": "./dist/index.cjs"
16
- },
11
+ ".": "./dist/index.js",
12
+ "./universal-middleware": "./dist/universal-middleware-prod.js",
13
+ "./universal-middleware/dev": "./dist/universal-middleware-dev.js",
14
+ "./utils": "./dist/utils.js",
15
+ "./api": "./dist/api.js",
17
16
  "./types": {
18
- "types": "./index.d.ts"
17
+ "types": "./dist/types.d.ts"
19
18
  }
20
19
  },
21
- "types": "./index.d.ts",
22
20
  "description": "Vercel adapter for vite",
23
21
  "author": "Joël Charles <joel.charles91@gmail.com>",
24
22
  "repository": "https://github.com/magne4000/vite-plugin-vercel",
25
23
  "license": "MIT",
26
24
  "peerDependencies": {
27
- "vike": "*",
28
- "vite": "^4.4 || ^5.0.2 || ^6",
29
- "@vite-plugin-vercel/vike": "9.0.6"
30
- },
31
- "peerDependenciesMeta": {
32
- "@vite-plugin-vercel/vike": {
33
- "optional": true
34
- },
35
- "vike": {
36
- "optional": true
37
- }
25
+ "vite": ">=7.1"
38
26
  },
39
27
  "devDependencies": {
40
- "@types/node": "^18.19.54",
41
- "tsup": "^8.3.5",
42
- "typescript": "^5.6.3",
43
- "vike": "^0.4.229",
44
- "vite": "^6.3.5",
45
- "@vite-plugin-vercel/vike": "9.0.6"
28
+ "@types/node": "^20.19.13",
29
+ "@universal-middleware/express": "^0.4.19",
30
+ "@vercel/node": "^5.3.21",
31
+ "rollup": "^4.50.1",
32
+ "tsup": "^8.5.0",
33
+ "typescript": "^5.9.2",
34
+ "vite": "^7.1.5"
46
35
  },
47
36
  "dependencies": {
48
37
  "@brillout/libassert": "^0.5.8",
49
- "@manypkg/find-root": "^2.2.3",
50
- "@vercel/build-utils": "^8.4.12",
51
- "@vercel/nft": "^0.27.6",
52
- "@vercel/routing-utils": "^3.1.0",
53
- "esbuild": "^0.24.0",
54
- "fast-glob": "^3.3.2",
38
+ "@manypkg/find-root": "^3.1.0",
39
+ "@photonjs/core": "^0.0.13",
40
+ "@photonjs/runtime": "^0.0.10",
41
+ "@universal-middleware/core": "^0.4.10",
42
+ "@universal-middleware/vercel": "^0.4.22",
43
+ "@vercel/build-utils": "^12.1.0",
44
+ "@vercel/nft": "^0.30.1",
45
+ "@vercel/routing-utils": "^5.1.1",
46
+ "convert-route": "^0.1.1",
47
+ "esbuild": "^0.25.9",
48
+ "fast-glob": "^3.3.3",
55
49
  "magicast": "^0.3.5",
56
- "zod": "^3.23.8"
50
+ "path-to-regexp": "^8.3.0",
51
+ "strip-ansi": "^7.1.2",
52
+ "vite-plugin-wasm": "^3.5.0",
53
+ "@vite-plugin-vercel/schemas": "^1.0.0"
57
54
  },
58
55
  "scripts": {
59
56
  "build": "tsup",