@vercel/backends 0.0.23 → 0.0.25

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,4 @@
1
+ //#region src/introspection/express.d.ts
2
+ declare const handle: (expressModule: any) => any;
3
+ //#endregion
4
+ export { handle };
@@ -0,0 +1,90 @@
1
+ import { pathToRegexp } from "path-to-regexp";
2
+ import { debug } from "@vercel/build-utils";
3
+
4
+ //#region src/introspection/util.ts
5
+ const BEGIN_INTROSPECTION_RESULT = "\n__VERCEL_INTROSPECTION_BEGIN__\n";
6
+ const END_INTROSPECTION_RESULT = "\n__VERCEL_INTROSPECTION_END__\n";
7
+ const setupCloseHandlers = (cb) => {
8
+ const callCallback = () => {
9
+ const result = cb();
10
+ if (result) console.log(`${BEGIN_INTROSPECTION_RESULT}${JSON.stringify(result)}${END_INTROSPECTION_RESULT}`);
11
+ };
12
+ process.on("SIGINT", callCallback);
13
+ process.on("SIGTERM", callCallback);
14
+ process.on("exit", callCallback);
15
+ };
16
+
17
+ //#endregion
18
+ //#region src/introspection/express.ts
19
+ let app = null;
20
+ const handle = (expressModule) => {
21
+ if (typeof expressModule === "function") {
22
+ const originalCreateApp = expressModule;
23
+ const createApp = (...args) => {
24
+ app = originalCreateApp(...args);
25
+ return app;
26
+ };
27
+ Object.setPrototypeOf(createApp, originalCreateApp);
28
+ Object.assign(createApp, originalCreateApp);
29
+ return createApp;
30
+ }
31
+ return expressModule;
32
+ };
33
+ setupCloseHandlers(() => {
34
+ const { routes, additionalFolders, additionalDeps } = extractRoutes();
35
+ if (routes.length > 0) return {
36
+ frameworkSlug: "express",
37
+ routes,
38
+ additionalFolders,
39
+ additionalDeps
40
+ };
41
+ });
42
+ const extractRoutes = () => {
43
+ if (!app) return {
44
+ routes: [],
45
+ additionalFolders: [],
46
+ additionalDeps: []
47
+ };
48
+ const additionalFolders = [];
49
+ const additionalDeps = [];
50
+ const routes = [];
51
+ const methods = [
52
+ "all",
53
+ "get",
54
+ "post",
55
+ "put",
56
+ "delete",
57
+ "patch",
58
+ "options",
59
+ "head"
60
+ ];
61
+ const router = app._router || app.router;
62
+ if ("settings" in app) {
63
+ if ("views" in app.settings && typeof app.settings.views === "string") additionalFolders.push(app.settings.views);
64
+ if ("view engine" in app.settings && typeof app.settings["view engine"] === "string") additionalDeps.push(app.settings["view engine"]);
65
+ }
66
+ for (const route of router.stack) if (route.route) {
67
+ const m = [];
68
+ for (const method of methods) if (route.route.methods[method]) m.push(method.toUpperCase());
69
+ try {
70
+ const { regexp } = pathToRegexp(route.route.path);
71
+ if (route.route.path === "/") continue;
72
+ routes.push({
73
+ src: regexp.source,
74
+ dest: route.route.path,
75
+ methods: m
76
+ });
77
+ } catch (e) {
78
+ const message = e instanceof Error ? e.message : "Unknown error";
79
+ debug(`Error extracting routes for ${route.route.path}: ${message}`);
80
+ }
81
+ }
82
+ return {
83
+ routes,
84
+ additionalFolders,
85
+ additionalDeps
86
+ };
87
+ };
88
+
89
+ //#endregion
90
+ export { handle };
@@ -0,0 +1,9 @@
1
+ //#region src/introspection/hono.d.ts
2
+ declare const handle: (honoModule: any) => {
3
+ new (...args: any[]): {
4
+ [x: string]: any;
5
+ };
6
+ [x: string]: any;
7
+ };
8
+ //#endregion
9
+ export { handle };
@@ -0,0 +1,59 @@
1
+ import { pathToRegexp } from "path-to-regexp";
2
+ import { debug } from "@vercel/build-utils";
3
+
4
+ //#region src/introspection/util.ts
5
+ const BEGIN_INTROSPECTION_RESULT = "\n__VERCEL_INTROSPECTION_BEGIN__\n";
6
+ const END_INTROSPECTION_RESULT = "\n__VERCEL_INTROSPECTION_END__\n";
7
+ const setupCloseHandlers = (cb) => {
8
+ const callCallback = () => {
9
+ const result = cb();
10
+ if (result) console.log(`${BEGIN_INTROSPECTION_RESULT}${JSON.stringify(result)}${END_INTROSPECTION_RESULT}`);
11
+ };
12
+ process.on("SIGINT", callCallback);
13
+ process.on("SIGTERM", callCallback);
14
+ process.on("exit", callCallback);
15
+ };
16
+
17
+ //#endregion
18
+ //#region src/introspection/hono.ts
19
+ const apps = [];
20
+ const handle = (honoModule) => {
21
+ const TrackedHono = class extends honoModule.Hono {
22
+ constructor(...args) {
23
+ super(...args);
24
+ apps.push(this);
25
+ }
26
+ };
27
+ return TrackedHono;
28
+ };
29
+ setupCloseHandlers(() => {
30
+ const routes = extractRoutes();
31
+ if (routes.length > 0) return {
32
+ frameworkSlug: "hono",
33
+ routes
34
+ };
35
+ });
36
+ function extractRoutes() {
37
+ const app = apps.sort((a, b) => b.routes.length - a.routes.length)[0];
38
+ if (!app || !app.routes) return [];
39
+ const routes = [];
40
+ for (const route of app.routes) {
41
+ const routePath = route.path;
42
+ const method = route.method.toUpperCase();
43
+ try {
44
+ const { regexp } = pathToRegexp(routePath);
45
+ if (routePath === "/") continue;
46
+ routes.push({
47
+ src: regexp.source,
48
+ dest: routePath,
49
+ methods: [method]
50
+ });
51
+ } catch (e) {
52
+ debug(`Error extracting routes for ${routePath}: ${e instanceof Error ? e.message : "Unknown error"}`);
53
+ }
54
+ }
55
+ return routes;
56
+ }
57
+
58
+ //#endregion
59
+ export { handle };
@@ -0,0 +1,168 @@
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
+ let __vercel_build_utils = require("@vercel/build-utils");
28
+
29
+ //#region src/introspection/util.ts
30
+ const BEGIN_INTROSPECTION_RESULT = "\n__VERCEL_INTROSPECTION_BEGIN__\n";
31
+ const END_INTROSPECTION_RESULT = "\n__VERCEL_INTROSPECTION_END__\n";
32
+ const setupCloseHandlers = (cb) => {
33
+ const callCallback = () => {
34
+ const result = cb();
35
+ if (result) console.log(`${BEGIN_INTROSPECTION_RESULT}${JSON.stringify(result)}${END_INTROSPECTION_RESULT}`);
36
+ };
37
+ process.on("SIGINT", callCallback);
38
+ process.on("SIGTERM", callCallback);
39
+ process.on("exit", callCallback);
40
+ };
41
+
42
+ //#endregion
43
+ //#region src/introspection/hono.ts
44
+ const apps = [];
45
+ const handle = (honoModule) => {
46
+ const TrackedHono = class extends honoModule.Hono {
47
+ constructor(...args) {
48
+ super(...args);
49
+ apps.push(this);
50
+ }
51
+ };
52
+ return TrackedHono;
53
+ };
54
+ setupCloseHandlers(() => {
55
+ const routes = extractRoutes$1();
56
+ if (routes.length > 0) return {
57
+ frameworkSlug: "hono",
58
+ routes
59
+ };
60
+ });
61
+ function extractRoutes$1() {
62
+ const app$1 = apps.sort((a, b) => b.routes.length - a.routes.length)[0];
63
+ if (!app$1 || !app$1.routes) return [];
64
+ const routes = [];
65
+ for (const route of app$1.routes) {
66
+ const routePath = route.path;
67
+ const method = route.method.toUpperCase();
68
+ try {
69
+ const { regexp } = (0, path_to_regexp.pathToRegexp)(routePath);
70
+ if (routePath === "/") continue;
71
+ routes.push({
72
+ src: regexp.source,
73
+ dest: routePath,
74
+ methods: [method]
75
+ });
76
+ } catch (e) {
77
+ (0, __vercel_build_utils.debug)(`Error extracting routes for ${routePath}: ${e instanceof Error ? e.message : "Unknown error"}`);
78
+ }
79
+ }
80
+ return routes;
81
+ }
82
+
83
+ //#endregion
84
+ //#region src/introspection/express.ts
85
+ let app = null;
86
+ const handle$1 = (expressModule) => {
87
+ if (typeof expressModule === "function") {
88
+ const originalCreateApp = expressModule;
89
+ const createApp = (...args) => {
90
+ app = originalCreateApp(...args);
91
+ return app;
92
+ };
93
+ Object.setPrototypeOf(createApp, originalCreateApp);
94
+ Object.assign(createApp, originalCreateApp);
95
+ return createApp;
96
+ }
97
+ return expressModule;
98
+ };
99
+ setupCloseHandlers(() => {
100
+ const { routes, additionalFolders, additionalDeps } = extractRoutes();
101
+ if (routes.length > 0) return {
102
+ frameworkSlug: "express",
103
+ routes,
104
+ additionalFolders,
105
+ additionalDeps
106
+ };
107
+ });
108
+ const extractRoutes = () => {
109
+ if (!app) return {
110
+ routes: [],
111
+ additionalFolders: [],
112
+ additionalDeps: []
113
+ };
114
+ const additionalFolders = [];
115
+ const additionalDeps = [];
116
+ const routes = [];
117
+ const methods = [
118
+ "all",
119
+ "get",
120
+ "post",
121
+ "put",
122
+ "delete",
123
+ "patch",
124
+ "options",
125
+ "head"
126
+ ];
127
+ const router = app._router || app.router;
128
+ if ("settings" in app) {
129
+ if ("views" in app.settings && typeof app.settings.views === "string") additionalFolders.push(app.settings.views);
130
+ if ("view engine" in app.settings && typeof app.settings["view engine"] === "string") additionalDeps.push(app.settings["view engine"]);
131
+ }
132
+ for (const route of router.stack) if (route.route) {
133
+ const m = [];
134
+ for (const method of methods) if (route.route.methods[method]) m.push(method.toUpperCase());
135
+ try {
136
+ const { regexp } = (0, path_to_regexp.pathToRegexp)(route.route.path);
137
+ if (route.route.path === "/") continue;
138
+ routes.push({
139
+ src: regexp.source,
140
+ dest: route.route.path,
141
+ methods: m
142
+ });
143
+ } catch (e) {
144
+ const message = e instanceof Error ? e.message : "Unknown error";
145
+ (0, __vercel_build_utils.debug)(`Error extracting routes for ${route.route.path}: ${message}`);
146
+ }
147
+ }
148
+ return {
149
+ routes,
150
+ additionalFolders,
151
+ additionalDeps
152
+ };
153
+ };
154
+
155
+ //#endregion
156
+ //#region src/introspection/loaders/cjs.ts
157
+ const originalRequire = module$1.default.prototype.require;
158
+ module$1.default.prototype.require = function(id, ...args) {
159
+ const result = originalRequire.apply(this, [id, ...args]);
160
+ if (id === "express") return handle$1(result);
161
+ if (id === "hono") return {
162
+ ...result,
163
+ Hono: handle(result)
164
+ };
165
+ return result;
166
+ };
167
+
168
+ //#endregion
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,7 @@
1
+ import { register } from "node:module";
2
+
3
+ //#region src/introspection/loaders/esm.ts
4
+ register(new URL("./hooks.mjs", import.meta.url), import.meta.url);
5
+
6
+ //#endregion
7
+ export { };
@@ -0,0 +1,5 @@
1
+ //#region src/introspection/loaders/hooks.d.ts
2
+ declare function resolve(specifier: string, context: any, nextResolve: any): Promise<any>;
3
+ declare function load(url: string, context: any, nextLoad: (url: string, context: any) => Promise<any>): Promise<any>;
4
+ //#endregion
5
+ export { load, resolve };
@@ -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.mjs", 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.mjs", 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 };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,7 @@
1
+ import { register } from "node:module";
2
+
3
+ //#region src/introspection/loaders/rolldown-esm.ts
4
+ register(new URL("./rolldown-hooks.mjs", import.meta.url), import.meta.url);
5
+
6
+ //#endregion
7
+ export { };
@@ -0,0 +1,31 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ //#region src/introspection/loaders/rolldown-hooks.d.ts
3
+ declare function resolve(specifier: string, context: {
4
+ parentURL?: string;
5
+ }, nextResolve: (specifier: string, context: {
6
+ parentURL?: string;
7
+ }) => Promise<{
8
+ url: string;
9
+ }>): Promise<{
10
+ url: string;
11
+ } | {
12
+ url: string;
13
+ shortCircuit: boolean;
14
+ }>;
15
+ declare function load(url: string, context: {
16
+ format?: string;
17
+ }, nextLoad: (url: string, context: {
18
+ format?: string;
19
+ }) => Promise<{
20
+ format: string;
21
+ source: string | Buffer;
22
+ }>): Promise<{
23
+ format: string;
24
+ source: string | Buffer;
25
+ } | {
26
+ format: string;
27
+ source: string;
28
+ shortCircuit: boolean;
29
+ }>;
30
+ //#endregion
31
+ export { load, resolve };