@vercel/backends 0.0.26 → 0.0.28

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.
@@ -1,7 +1,7 @@
1
1
  import { pathToRegexp } from "path-to-regexp";
2
2
  import { debug } from "@vercel/build-utils";
3
3
 
4
- //#region src/introspection/util.ts
4
+ //#region src/rolldown/util.ts
5
5
  const BEGIN_INTROSPECTION_RESULT = "\n__VERCEL_INTROSPECTION_BEGIN__\n";
6
6
  const END_INTROSPECTION_RESULT = "\n__VERCEL_INTROSPECTION_END__\n";
7
7
  const setupCloseHandlers = (cb) => {
@@ -33,7 +33,6 @@ const handle = (expressModule) => {
33
33
  setupCloseHandlers(() => {
34
34
  const { routes, additionalFolders, additionalDeps } = extractRoutes();
35
35
  if (routes.length > 0) return {
36
- frameworkSlug: "express",
37
36
  routes,
38
37
  additionalFolders,
39
38
  additionalDeps
@@ -1,7 +1,7 @@
1
1
  import { pathToRegexp } from "path-to-regexp";
2
2
  import { debug } from "@vercel/build-utils";
3
3
 
4
- //#region src/introspection/util.ts
4
+ //#region src/rolldown/util.ts
5
5
  const BEGIN_INTROSPECTION_RESULT = "\n__VERCEL_INTROSPECTION_BEGIN__\n";
6
6
  const END_INTROSPECTION_RESULT = "\n__VERCEL_INTROSPECTION_END__\n";
7
7
  const setupCloseHandlers = (cb) => {
@@ -28,10 +28,7 @@ const handle = (honoModule) => {
28
28
  };
29
29
  setupCloseHandlers(() => {
30
30
  const routes = extractRoutes();
31
- if (routes.length > 0) return {
32
- frameworkSlug: "hono",
33
- routes
34
- };
31
+ if (routes.length > 0) return { routes };
35
32
  });
36
33
  function extractRoutes() {
37
34
  const app = apps.sort((a, b) => b.routes.length - a.routes.length)[0];
@@ -26,7 +26,7 @@ module$1 = __toESM(module$1);
26
26
  let path_to_regexp = require("path-to-regexp");
27
27
  let __vercel_build_utils = require("@vercel/build-utils");
28
28
 
29
- //#region src/introspection/util.ts
29
+ //#region src/rolldown/util.ts
30
30
  const BEGIN_INTROSPECTION_RESULT = "\n__VERCEL_INTROSPECTION_BEGIN__\n";
31
31
  const END_INTROSPECTION_RESULT = "\n__VERCEL_INTROSPECTION_END__\n";
32
32
  const setupCloseHandlers = (cb) => {
@@ -53,10 +53,7 @@ const handle = (honoModule) => {
53
53
  };
54
54
  setupCloseHandlers(() => {
55
55
  const routes = extractRoutes$1();
56
- if (routes.length > 0) return {
57
- frameworkSlug: "hono",
58
- routes
59
- };
56
+ if (routes.length > 0) return { routes };
60
57
  });
61
58
  function extractRoutes$1() {
62
59
  const app$1 = apps.sort((a, b) => b.routes.length - a.routes.length)[0];
@@ -99,7 +96,6 @@ const handle$1 = (expressModule) => {
99
96
  setupCloseHandlers(() => {
100
97
  const { routes, additionalFolders, additionalDeps } = extractRoutes();
101
98
  if (routes.length > 0) return {
102
- frameworkSlug: "express",
103
99
  routes,
104
100
  additionalFolders,
105
101
  additionalDeps
@@ -0,0 +1,208 @@
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 node_module = require("node:module");
25
+ node_module = __toESM(node_module);
26
+ let node_path = require("node:path");
27
+ node_path = __toESM(node_path);
28
+ let node_fs = require("node:fs");
29
+ let path_to_regexp = require("path-to-regexp");
30
+ let __vercel_build_utils = require("@vercel/build-utils");
31
+
32
+ //#region src/rolldown/util.ts
33
+ const BEGIN_INTROSPECTION_RESULT = "\n__VERCEL_INTROSPECTION_BEGIN__\n";
34
+ const END_INTROSPECTION_RESULT = "\n__VERCEL_INTROSPECTION_END__\n";
35
+ const setupCloseHandlers = (cb) => {
36
+ const callCallback = () => {
37
+ const result = cb();
38
+ if (result) console.log(`${BEGIN_INTROSPECTION_RESULT}${JSON.stringify(result)}${END_INTROSPECTION_RESULT}`);
39
+ };
40
+ process.on("SIGINT", callCallback);
41
+ process.on("SIGTERM", callCallback);
42
+ process.on("exit", callCallback);
43
+ };
44
+
45
+ //#endregion
46
+ //#region src/introspection/hono.ts
47
+ const apps = [];
48
+ const handle = (honoModule) => {
49
+ const TrackedHono = class extends honoModule.Hono {
50
+ constructor(...args) {
51
+ super(...args);
52
+ apps.push(this);
53
+ }
54
+ };
55
+ return TrackedHono;
56
+ };
57
+ setupCloseHandlers(() => {
58
+ const routes = extractRoutes$1();
59
+ if (routes.length > 0) return { routes };
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
+ routes,
103
+ additionalFolders,
104
+ additionalDeps
105
+ };
106
+ });
107
+ const extractRoutes = () => {
108
+ if (!app) return {
109
+ routes: [],
110
+ additionalFolders: [],
111
+ additionalDeps: []
112
+ };
113
+ const additionalFolders = [];
114
+ const additionalDeps = [];
115
+ const routes = [];
116
+ const methods = [
117
+ "all",
118
+ "get",
119
+ "post",
120
+ "put",
121
+ "delete",
122
+ "patch",
123
+ "options",
124
+ "head"
125
+ ];
126
+ const router = app._router || app.router;
127
+ if ("settings" in app) {
128
+ if ("views" in app.settings && typeof app.settings.views === "string") additionalFolders.push(app.settings.views);
129
+ if ("view engine" in app.settings && typeof app.settings["view engine"] === "string") additionalDeps.push(app.settings["view engine"]);
130
+ }
131
+ for (const route of router.stack) if (route.route) {
132
+ const m = [];
133
+ for (const method of methods) if (route.route.methods[method]) m.push(method.toUpperCase());
134
+ try {
135
+ const { regexp } = (0, path_to_regexp.pathToRegexp)(route.route.path);
136
+ if (route.route.path === "/") continue;
137
+ routes.push({
138
+ src: regexp.source,
139
+ dest: route.route.path,
140
+ methods: m
141
+ });
142
+ } catch (e) {
143
+ const message = e instanceof Error ? e.message : "Unknown error";
144
+ (0, __vercel_build_utils.debug)(`Error extracting routes for ${route.route.path}: ${message}`);
145
+ }
146
+ }
147
+ return {
148
+ routes,
149
+ additionalFolders,
150
+ additionalDeps
151
+ };
152
+ };
153
+
154
+ //#endregion
155
+ //#region src/rolldown/cjs-hooks.ts
156
+ /**
157
+ * CJS preload script that intercepts require() calls.
158
+ * - Check tmpDir first for files
159
+ * - Map bare specifiers from tmpDir to repoRootPath
160
+ * - Wrap hono/express modules with instrumentation
161
+ */
162
+ const repoRootPath = process.env.VERCEL_INTROSPECTION_REPO_ROOT_PATH;
163
+ const tmpDirEnv = process.env.VERCEL_INTROSPECTION_TMP_DIR;
164
+ if (!repoRootPath || !tmpDirEnv) throw new Error("VERCEL_INTROSPECTION_REPO_ROOT_PATH and VERCEL_INTROSPECTION_TMP_DIR must be set");
165
+ const tmpDir = (0, node_fs.realpathSync)(tmpDirEnv);
166
+ const wrappedModules = /* @__PURE__ */ new Map();
167
+ const originalResolveFilename = node_module.default._resolveFilename;
168
+ node_module.default._resolveFilename = function(request, parent, isMain, options) {
169
+ if (request.startsWith(".") && parent?.filename) {
170
+ const parentDir = node_path.default.dirname(parent.filename);
171
+ const resolvedPath = node_path.default.resolve(parentDir, request);
172
+ if ((0, node_fs.existsSync)(resolvedPath) && (0, node_fs.statSync)(resolvedPath).isFile()) return resolvedPath;
173
+ }
174
+ if (!request.startsWith(".") && !request.startsWith("/") && parent?.filename?.startsWith(tmpDir)) {
175
+ const relativeToTmp = node_path.default.relative(tmpDir, parent.filename);
176
+ const mappedParentPath = node_path.default.join(repoRootPath, relativeToTmp);
177
+ const fakeParent = {
178
+ ...parent,
179
+ filename: mappedParentPath,
180
+ paths: node_module.default._nodeModulePaths(node_path.default.dirname(mappedParentPath))
181
+ };
182
+ return originalResolveFilename.call(this, request, fakeParent, isMain, options);
183
+ }
184
+ return originalResolveFilename.call(this, request, parent, isMain, options);
185
+ };
186
+ const originalLoad = node_module.default._load;
187
+ node_module.default._load = function(request, parent, isMain) {
188
+ const result = originalLoad.call(this, request, parent, isMain);
189
+ if (request === "hono") {
190
+ if (wrappedModules.has("hono")) return wrappedModules.get("hono");
191
+ const TrackedHono = handle(result);
192
+ const wrapped = {
193
+ ...result,
194
+ Hono: TrackedHono
195
+ };
196
+ wrappedModules.set("hono", wrapped);
197
+ return wrapped;
198
+ }
199
+ if (request === "express") {
200
+ if (wrappedModules.has("express")) return wrappedModules.get("express");
201
+ const wrapped = handle$1(result);
202
+ wrappedModules.set("express", wrapped);
203
+ return wrapped;
204
+ }
205
+ return result;
206
+ };
207
+
208
+ //#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/rolldown/esm.ts
4
+ register(new URL("./hooks.mjs", import.meta.url), import.meta.url);
5
+
6
+ //#endregion
7
+ export { };
@@ -0,0 +1,27 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ //#region src/rolldown/hooks.d.ts
3
+ interface ResolveContext {
4
+ parentURL?: string;
5
+ conditions?: string[];
6
+ importAttributes?: Record<string, string>;
7
+ }
8
+ interface ResolveResult {
9
+ url: string;
10
+ shortCircuit?: boolean;
11
+ format?: string;
12
+ }
13
+ interface LoadContext {
14
+ format?: string;
15
+ importAttributes?: Record<string, string>;
16
+ }
17
+ interface LoadResult {
18
+ format: string;
19
+ source?: string | Buffer;
20
+ shortCircuit?: boolean;
21
+ }
22
+ type NextResolve = (specifier: string, context: ResolveContext) => Promise<ResolveResult>;
23
+ type NextLoad = (url: string, context: LoadContext) => Promise<LoadResult>;
24
+ declare function resolve(specifier: string, context: ResolveContext, nextResolve: NextResolve): Promise<ResolveResult>;
25
+ declare function load(url: string, context: LoadContext, nextLoad: NextLoad): Promise<LoadResult>;
26
+ //#endregion
27
+ export { load, resolve };
@@ -0,0 +1,84 @@
1
+ import { fileURLToPath, pathToFileURL } from "node:url";
2
+ import { dirname, join, relative } from "node:path";
3
+ import { existsSync, realpathSync, statSync } from "node:fs";
4
+
5
+ //#region src/rolldown/hooks.ts
6
+ const getRequiredEnv = (key) => {
7
+ const value = process.env[key];
8
+ if (!value) throw new Error(`${key} is not set`);
9
+ return value;
10
+ };
11
+ const repoRootPath = getRequiredEnv("VERCEL_INTROSPECTION_REPO_ROOT_PATH");
12
+ const handlerPath = getRequiredEnv("VERCEL_INTROSPECTION_HANDLER");
13
+ const handlerBuilt = getRequiredEnv("VERCEL_INTROSPECTION_HANDLER_BUILT");
14
+ const tmpDir = realpathSync(getRequiredEnv("VERCEL_INTROSPECTION_TMP_DIR"));
15
+ let honoUrl = null;
16
+ let expressUrl = null;
17
+ async function resolve(specifier, context, nextResolve) {
18
+ let specifierAsPath = null;
19
+ try {
20
+ specifierAsPath = fileURLToPath(specifier);
21
+ } catch {}
22
+ if (specifierAsPath === handlerPath) return {
23
+ url: pathToFileURL(join(tmpDir, handlerBuilt)).href,
24
+ shortCircuit: true
25
+ };
26
+ if (specifier.startsWith(".") && context.parentURL) {
27
+ const resolvedPath = join(dirname(fileURLToPath(context.parentURL)), specifier);
28
+ if (existsSync(resolvedPath) && statSync(resolvedPath).isFile()) return {
29
+ url: pathToFileURL(resolvedPath).href,
30
+ shortCircuit: true
31
+ };
32
+ }
33
+ if (!specifier.startsWith(".") && !specifier.startsWith("/") && !specifier.startsWith("file:") && context.parentURL) {
34
+ const parentPath = fileURLToPath(context.parentURL);
35
+ if (parentPath.startsWith(tmpDir)) {
36
+ const mappedParent = join(repoRootPath, relative(tmpDir, parentPath));
37
+ const result = await nextResolve(specifier, {
38
+ ...context,
39
+ parentURL: pathToFileURL(mappedParent).href
40
+ });
41
+ if (specifier === "hono") honoUrl = result.url;
42
+ else if (specifier === "express") expressUrl = result.url;
43
+ return result;
44
+ }
45
+ }
46
+ return nextResolve(specifier, context);
47
+ }
48
+ async function load(url, context, nextLoad) {
49
+ if (honoUrl === url) {
50
+ const pathToHonoExtract = new URL("../introspection/hono.mjs", import.meta.url);
51
+ return {
52
+ format: "module",
53
+ source: `
54
+ import { handle } from ${JSON.stringify(pathToHonoExtract.toString())};
55
+ import * as originalHono from ${JSON.stringify(url + "?original")};
56
+
57
+ export * from ${JSON.stringify(url + "?original")};
58
+ export const Hono = handle(originalHono);
59
+ `,
60
+ shortCircuit: true
61
+ };
62
+ }
63
+ if (expressUrl === url) {
64
+ const pathToExpressExtract = new URL("../introspection/express.mjs", import.meta.url);
65
+ return {
66
+ format: "module",
67
+ source: `
68
+ import { handle } from ${JSON.stringify(pathToExpressExtract.toString())};
69
+ import originalExpress from ${JSON.stringify(url + "?original")};
70
+
71
+ const extendedExpress = handle(originalExpress);
72
+
73
+ export * from ${JSON.stringify(url + "?original")};
74
+ export default extendedExpress;
75
+ `,
76
+ shortCircuit: true
77
+ };
78
+ }
79
+ if (url.endsWith("?original")) return nextLoad(url, context);
80
+ return nextLoad(url, context);
81
+ }
82
+
83
+ //#endregion
84
+ export { load, resolve };
@@ -0,0 +1,16 @@
1
+ import { BuildOptions, Files, Span } from "@vercel/build-utils";
2
+
3
+ //#region src/rolldown/index.d.ts
4
+ declare const rolldown: (args: Pick<BuildOptions, 'entrypoint' | 'workPath' | 'repoRootPath'> & {
5
+ span?: Span;
6
+ }) => Promise<{
7
+ files: Files;
8
+ handler: string;
9
+ framework: {
10
+ slug: string;
11
+ version: string;
12
+ };
13
+ localBuildFiles: Set<string>;
14
+ }>;
15
+ //#endregion
16
+ export { rolldown };