vite-plugin-vercel 9.0.6 → 10.0.0-beta.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/README.md +31 -168
- package/dist/api.d.ts +55 -0
- package/dist/api.js +9 -0
- package/dist/chunk-CR7Q2T4Q.js +75 -0
- package/dist/chunk-OCCU6UM5.js +33 -0
- package/dist/chunk-UTQ72LMT.js +13 -0
- package/dist/chunk-YN5MUEL2.js +34 -0
- package/dist/index.d.ts +8 -691
- package/dist/index.js +698 -685
- package/dist/types-BjqDHPFV.d.ts +121 -0
- package/dist/universal-middleware-dev.d.ts +17 -0
- package/dist/universal-middleware-dev.js +24 -0
- package/dist/universal-middleware-prod.d.ts +12 -0
- package/dist/universal-middleware-prod.js +20 -0
- package/dist/utils.d.ts +23 -0
- package/dist/utils.js +81 -0
- package/index.d.ts +0 -8
- package/package.json +29 -32
- package/dist/index.cjs +0 -829
- package/dist/index.d.cts +0 -694
|
@@ -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
|
+
interface VercelEntryOptions {
|
|
78
|
+
/**
|
|
79
|
+
* Relative to `.vercel/output/functions`, without extension
|
|
80
|
+
*/
|
|
81
|
+
destination?: string;
|
|
82
|
+
/**
|
|
83
|
+
* If `true`, guesses route for the function, and adds it to config.json (mimics defaults Vercel behavior).
|
|
84
|
+
* If a string is provided, it will be equivalent to a `rewrites` rule.
|
|
85
|
+
* Set to `false` to disable
|
|
86
|
+
*/
|
|
87
|
+
route?: string | boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Ensures that the route is added before or after others
|
|
90
|
+
*/
|
|
91
|
+
enforce?: "post" | "pre";
|
|
92
|
+
/**
|
|
93
|
+
* Set to `true` to mark this function as an Edge Function
|
|
94
|
+
*/
|
|
95
|
+
edge?: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Additional headers
|
|
98
|
+
*/
|
|
99
|
+
headers?: Record<string, string> | null;
|
|
100
|
+
/**
|
|
101
|
+
* ISR config
|
|
102
|
+
*/
|
|
103
|
+
isr?: VercelOutputIsr;
|
|
104
|
+
/**
|
|
105
|
+
* When true, the Serverless Function will stream the response to the client
|
|
106
|
+
*/
|
|
107
|
+
streaming?: boolean;
|
|
108
|
+
/**
|
|
109
|
+
* When true, do not build output files for this entry
|
|
110
|
+
*/
|
|
111
|
+
disabled?: boolean;
|
|
112
|
+
}
|
|
113
|
+
declare module "@photonjs/core" {
|
|
114
|
+
namespace Photon {
|
|
115
|
+
interface EntryBase {
|
|
116
|
+
vercel?: VercelEntryOptions;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export type { ViteVercelConfig as V, ViteVercelRewrite as a, ViteVercelRedirect as b };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="@photonjs/core" />
|
|
2
|
+
|
|
3
|
+
import './types-BjqDHPFV.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,24 @@
|
|
|
1
|
+
// src/photon/universal-middleware-dev.ts
|
|
2
|
+
import { enhance, MiddlewareOrder } from "@universal-middleware/core";
|
|
3
|
+
var applyVercelHeaders = (_request, context) => {
|
|
4
|
+
console.log(_request.url, context);
|
|
5
|
+
const headers = context.photon?.handler?.vercel?.headers ?? context.photon?.server?.vercel?.headers;
|
|
6
|
+
if (!headers) return;
|
|
7
|
+
return (response) => {
|
|
8
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
9
|
+
response.headers.set(key, value);
|
|
10
|
+
}
|
|
11
|
+
return response;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
var universal_middleware_dev_default = [
|
|
15
|
+
enhance(applyVercelHeaders, {
|
|
16
|
+
name: "vercel:headers",
|
|
17
|
+
immutable: true,
|
|
18
|
+
order: MiddlewareOrder.HEADER_MANAGEMENT
|
|
19
|
+
})
|
|
20
|
+
];
|
|
21
|
+
export {
|
|
22
|
+
applyVercelHeaders,
|
|
23
|
+
universal_middleware_dev_default as default
|
|
24
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="@photonjs/core" />
|
|
2
|
+
|
|
3
|
+
import './types-BjqDHPFV.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,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getOriginalRequest
|
|
3
|
+
} from "./chunk-YN5MUEL2.js";
|
|
4
|
+
|
|
5
|
+
// src/photon/universal-middleware-prod.ts
|
|
6
|
+
import { enhance } from "@universal-middleware/core";
|
|
7
|
+
var overrideVercelRequest = (request) => {
|
|
8
|
+
Object.assign(request, getOriginalRequest(request));
|
|
9
|
+
};
|
|
10
|
+
var universal_middleware_prod_default = [
|
|
11
|
+
enhance(overrideVercelRequest, {
|
|
12
|
+
name: "vercel:request",
|
|
13
|
+
immutable: true,
|
|
14
|
+
order: Number.MIN_SAFE_INTEGER
|
|
15
|
+
})
|
|
16
|
+
];
|
|
17
|
+
export {
|
|
18
|
+
universal_middleware_prod_default as default,
|
|
19
|
+
overrideVercelRequest
|
|
20
|
+
};
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference types="@photonjs/core" />
|
|
2
|
+
|
|
3
|
+
import './types-BjqDHPFV.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,81 @@
|
|
|
1
|
+
import {
|
|
2
|
+
entryToRou3
|
|
3
|
+
} from "./chunk-OCCU6UM5.js";
|
|
4
|
+
import "./chunk-UTQ72LMT.js";
|
|
5
|
+
import {
|
|
6
|
+
getOriginalRequest
|
|
7
|
+
} from "./chunk-YN5MUEL2.js";
|
|
8
|
+
|
|
9
|
+
// src/utils/fs-entries.ts
|
|
10
|
+
import path from "path";
|
|
11
|
+
import glob from "fast-glob";
|
|
12
|
+
import { generateCode, loadFile } from "magicast";
|
|
13
|
+
import { normalizePath } from "vite";
|
|
14
|
+
import { vercelEndpointExports } from "@vite-plugin-vercel/schemas";
|
|
15
|
+
async function getEntriesFromFs(dir, { destination = dir, tryParseExports = true }) {
|
|
16
|
+
const normalizedDir = normalizePath(dir);
|
|
17
|
+
destination = normalizePath(destination);
|
|
18
|
+
const apiEntries = glob.sync(`${path.posix.resolve(normalizedDir)}/**/*.?(m)[jt]s?(x)`).filter((filepath) => !path.basename(filepath).startsWith("_"));
|
|
19
|
+
const entryPoints = {};
|
|
20
|
+
for (const filePath of apiEntries) {
|
|
21
|
+
const outFilePath = pathRelativeTo(filePath, normalizedDir);
|
|
22
|
+
const parsed = path.posix.parse(outFilePath);
|
|
23
|
+
let xports;
|
|
24
|
+
if (tryParseExports) {
|
|
25
|
+
xports = await extractExports(filePath);
|
|
26
|
+
}
|
|
27
|
+
const key = path.posix.join(destination, parsed.dir, parsed.name);
|
|
28
|
+
const entry = {
|
|
29
|
+
id: filePath,
|
|
30
|
+
name: key,
|
|
31
|
+
type: "universal-handler",
|
|
32
|
+
compositionMode: "isolated",
|
|
33
|
+
vercel: {
|
|
34
|
+
route: true,
|
|
35
|
+
destination: key,
|
|
36
|
+
edge: xports?.edge,
|
|
37
|
+
isr: xports?.isr,
|
|
38
|
+
headers: xports?.headers,
|
|
39
|
+
streaming: xports?.streaming
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
entry.route = entryToRou3(entry)[0];
|
|
43
|
+
entryPoints[key] = entry;
|
|
44
|
+
}
|
|
45
|
+
return entryPoints;
|
|
46
|
+
}
|
|
47
|
+
async function extractExports(filepath) {
|
|
48
|
+
try {
|
|
49
|
+
const mod = await loadFile(filepath);
|
|
50
|
+
const subject = {
|
|
51
|
+
edge: evalExport(mod.exports.edge),
|
|
52
|
+
headers: evalExport(mod.exports.headers),
|
|
53
|
+
streaming: evalExport(mod.exports.streaming),
|
|
54
|
+
isr: evalExport(mod.exports.isr)
|
|
55
|
+
};
|
|
56
|
+
return vercelEndpointExports.parse(subject);
|
|
57
|
+
} catch (e) {
|
|
58
|
+
console.warn(`Warning: failed to read exports of '${filepath}'`, e);
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function pathRelativeTo(filePath, rel) {
|
|
63
|
+
return normalizePath(path.relative(normalizePath(path.resolve(rel)), path.resolve(filePath)));
|
|
64
|
+
}
|
|
65
|
+
function isPrimitive(test) {
|
|
66
|
+
return test !== Object(test);
|
|
67
|
+
}
|
|
68
|
+
function _eval(code) {
|
|
69
|
+
const func = new Function(`{ return function(){ return ${code} } };`);
|
|
70
|
+
return func.call(null).call(null);
|
|
71
|
+
}
|
|
72
|
+
function evalExport(exp) {
|
|
73
|
+
if (!exp) return;
|
|
74
|
+
const code = isPrimitive(exp) ? exp : generateCode(exp).code;
|
|
75
|
+
return _eval(code);
|
|
76
|
+
}
|
|
77
|
+
export {
|
|
78
|
+
extractExports,
|
|
79
|
+
getEntriesFromFs,
|
|
80
|
+
getOriginalRequest
|
|
81
|
+
};
|
package/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,59 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-vercel",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.0-beta.0",
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
17
|
"types": "./index.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
|
-
"
|
|
28
|
-
"vite": "^4.4 || ^5.0.2 || ^6",
|
|
29
|
-
"@vite-plugin-vercel/vike": "9.0.5"
|
|
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": "^
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
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": "^
|
|
50
|
-
"@
|
|
51
|
-
"@
|
|
52
|
-
"@
|
|
53
|
-
"
|
|
54
|
-
"
|
|
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
|
-
"
|
|
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",
|