@vercel/backends 0.0.3
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/LICENSE +202 -0
- package/dist/express.js +66 -0
- package/dist/hono.js +52 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +55265 -0
- package/dist/loaders/cjs.cjs +141 -0
- package/dist/loaders/esm.js +7 -0
- package/dist/loaders/hooks.js +50 -0
- package/package.json +66 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
let module$1 = require("module");
|
|
25
|
+
module$1 = __toESM(module$1);
|
|
26
|
+
let path_to_regexp = require("path-to-regexp");
|
|
27
|
+
path_to_regexp = __toESM(path_to_regexp);
|
|
28
|
+
|
|
29
|
+
//#region src/introspection/util.ts
|
|
30
|
+
const setupCloseHandlers = (cb) => {
|
|
31
|
+
const callCallback = () => {
|
|
32
|
+
const result = cb();
|
|
33
|
+
if (result) console.log(JSON.stringify(result));
|
|
34
|
+
};
|
|
35
|
+
process.on("SIGINT", callCallback);
|
|
36
|
+
process.on("SIGTERM", callCallback);
|
|
37
|
+
process.on("exit", callCallback);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/introspection/hono.ts
|
|
42
|
+
const apps = [];
|
|
43
|
+
const handle = (honoModule) => {
|
|
44
|
+
const TrackedHono = class extends honoModule.Hono {
|
|
45
|
+
constructor(...args) {
|
|
46
|
+
super(...args);
|
|
47
|
+
apps.push(this);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
return TrackedHono;
|
|
51
|
+
};
|
|
52
|
+
setupCloseHandlers(() => {
|
|
53
|
+
const routes = extractRoutes$1();
|
|
54
|
+
if (routes.length > 0) return {
|
|
55
|
+
frameworkSlug: "hono",
|
|
56
|
+
routes
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
function extractRoutes$1() {
|
|
60
|
+
const app$1 = apps.sort((a, b) => b.routes.length - a.routes.length)[0];
|
|
61
|
+
if (!app$1 || !app$1.routes) return [];
|
|
62
|
+
const routes = [];
|
|
63
|
+
for (const route of app$1.routes) {
|
|
64
|
+
const routePath = route.path;
|
|
65
|
+
const method = route.method.toUpperCase();
|
|
66
|
+
const { regexp } = (0, path_to_regexp.pathToRegexp)(routePath);
|
|
67
|
+
if (routePath === "/") continue;
|
|
68
|
+
routes.push({
|
|
69
|
+
src: regexp.source,
|
|
70
|
+
dest: routePath,
|
|
71
|
+
methods: [method]
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return routes;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/introspection/express.ts
|
|
79
|
+
let app = null;
|
|
80
|
+
const handle$1 = (expressModule) => {
|
|
81
|
+
if (typeof expressModule === "function") {
|
|
82
|
+
const originalCreateApp = expressModule;
|
|
83
|
+
const createApp = (...args) => {
|
|
84
|
+
app = originalCreateApp(...args);
|
|
85
|
+
return app;
|
|
86
|
+
};
|
|
87
|
+
Object.setPrototypeOf(createApp, originalCreateApp);
|
|
88
|
+
Object.assign(createApp, originalCreateApp);
|
|
89
|
+
return createApp;
|
|
90
|
+
}
|
|
91
|
+
return expressModule;
|
|
92
|
+
};
|
|
93
|
+
setupCloseHandlers(() => {
|
|
94
|
+
const routes = extractRoutes();
|
|
95
|
+
if (routes.length > 0) return {
|
|
96
|
+
frameworkSlug: "express",
|
|
97
|
+
routes
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
const extractRoutes = () => {
|
|
101
|
+
if (!app) return [];
|
|
102
|
+
const routes = [];
|
|
103
|
+
const methods = [
|
|
104
|
+
"all",
|
|
105
|
+
"get",
|
|
106
|
+
"post",
|
|
107
|
+
"put",
|
|
108
|
+
"delete",
|
|
109
|
+
"patch",
|
|
110
|
+
"options",
|
|
111
|
+
"head"
|
|
112
|
+
];
|
|
113
|
+
const router = app._router || app.router;
|
|
114
|
+
for (const route of router.stack) if (route.route) {
|
|
115
|
+
const m = [];
|
|
116
|
+
for (const method of methods) if (route.route.methods[method]) m.push(method.toUpperCase());
|
|
117
|
+
const { regexp } = (0, path_to_regexp.pathToRegexp)(route.route.path);
|
|
118
|
+
if (route.route.path === "/") continue;
|
|
119
|
+
routes.push({
|
|
120
|
+
src: regexp.source,
|
|
121
|
+
dest: route.route.path,
|
|
122
|
+
methods: m
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
return routes;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region src/introspection/loaders/cjs.ts
|
|
130
|
+
const originalRequire = module$1.default.prototype.require;
|
|
131
|
+
module$1.default.prototype.require = function(id, ...args) {
|
|
132
|
+
const result = originalRequire.apply(this, [id, ...args]);
|
|
133
|
+
if (id === "express") return handle$1(result);
|
|
134
|
+
if (id === "hono") return {
|
|
135
|
+
...result,
|
|
136
|
+
Hono: handle(result)
|
|
137
|
+
};
|
|
138
|
+
return result;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
//#endregion
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
//#region src/introspection/loaders/hooks.ts
|
|
2
|
+
let honoUrl = null;
|
|
3
|
+
let expressUrl = null;
|
|
4
|
+
async function resolve(specifier, context, nextResolve) {
|
|
5
|
+
const result = await nextResolve(specifier, context);
|
|
6
|
+
if (specifier === "hono") honoUrl = result.url;
|
|
7
|
+
else if (specifier === "express") expressUrl = result.url;
|
|
8
|
+
return result;
|
|
9
|
+
}
|
|
10
|
+
async function load(url, context, nextLoad) {
|
|
11
|
+
const result = await nextLoad(url, context);
|
|
12
|
+
if (expressUrl === url) {
|
|
13
|
+
const pathToExpressExtract = new URL("../express.js", import.meta.url);
|
|
14
|
+
return {
|
|
15
|
+
format: "module",
|
|
16
|
+
source: `
|
|
17
|
+
import { handle} from ${JSON.stringify(pathToExpressExtract.toString())};
|
|
18
|
+
import originalExpress from ${JSON.stringify(url + "?original")};
|
|
19
|
+
|
|
20
|
+
const extendedExpress = handle(originalExpress);
|
|
21
|
+
|
|
22
|
+
export * from ${JSON.stringify(url + "?original")};
|
|
23
|
+
export default extendedExpress;
|
|
24
|
+
`,
|
|
25
|
+
shortCircuit: true
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
if (honoUrl === url) {
|
|
29
|
+
const pathToHonoExtract = new URL("../hono.js", import.meta.url);
|
|
30
|
+
return {
|
|
31
|
+
format: "module",
|
|
32
|
+
source: `
|
|
33
|
+
import { handle } from ${JSON.stringify(pathToHonoExtract.toString())};
|
|
34
|
+
import * as originalHono from ${JSON.stringify(url + "?original")};
|
|
35
|
+
|
|
36
|
+
export * from ${JSON.stringify(url + "?original")};
|
|
37
|
+
export const Hono = handle(originalHono);
|
|
38
|
+
`,
|
|
39
|
+
shortCircuit: true
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
if (url.endsWith("?original")) {
|
|
43
|
+
const originalUrl = url.replace("?original", "");
|
|
44
|
+
if (originalUrl === honoUrl || originalUrl === expressUrl) return result;
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
export { load, resolve };
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vercel/backends",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"homepage": "https://vercel.com/docs",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": "./dist/index.js",
|
|
13
|
+
"./loaders/cjs": "./dist/loaders/cjs.js",
|
|
14
|
+
"./loaders/esm": "./dist/loaders/esm.js",
|
|
15
|
+
"./loaders/hooks": "./dist/loaders/hooks.js"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/vercel/vercel.git",
|
|
20
|
+
"directory": "packages/backends"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"package.json",
|
|
25
|
+
"express-loader.js",
|
|
26
|
+
"express-loader.mjs",
|
|
27
|
+
"express-loader-register.mjs",
|
|
28
|
+
"express-loader-hooks.mjs",
|
|
29
|
+
"express-introspection-source.js",
|
|
30
|
+
"hono-loader.js",
|
|
31
|
+
"hono-loader-hooks.js",
|
|
32
|
+
"universal-loader.js",
|
|
33
|
+
"universal-loader-cjs.js",
|
|
34
|
+
"universal-loader-esm.mjs",
|
|
35
|
+
"universal-loader-hooks.mjs"
|
|
36
|
+
],
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@vercel/nft": "0.30.1",
|
|
39
|
+
"@vercel/static-config": "3.1.2",
|
|
40
|
+
"fs-extra": "11.1.0",
|
|
41
|
+
"path-to-regexp": "8.3.0",
|
|
42
|
+
"rolldown": "1.0.0-beta.35",
|
|
43
|
+
"ts-morph": "12.0.0",
|
|
44
|
+
"tsdown": "0.15.6",
|
|
45
|
+
"zod": "3.22.4",
|
|
46
|
+
"@vercel/cervel": "0.0.2"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/express": "5.0.3",
|
|
50
|
+
"@types/fs-extra": "11",
|
|
51
|
+
"@types/jest": "27.5.1",
|
|
52
|
+
"@types/node": "22",
|
|
53
|
+
"@vercel/build-utils": "12.2.0",
|
|
54
|
+
"execa": "3.2.0",
|
|
55
|
+
"hono": "4.10.1",
|
|
56
|
+
"jest-junit": "16.0.0",
|
|
57
|
+
"vite": "^5.1.6",
|
|
58
|
+
"vitest": "^2.0.1"
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"build": "tsdown",
|
|
62
|
+
"vitest-run": "vitest -c ../../vitest.config.mts",
|
|
63
|
+
"vitest-unit": "glob --absolute 'test/unit/**/*.test.ts' 'test/unit/**/*.test.mts'",
|
|
64
|
+
"type-check": "tsc --noEmit"
|
|
65
|
+
}
|
|
66
|
+
}
|