@vercel/backends 0.0.5 → 0.0.6

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/dist/index.js CHANGED
@@ -1,38 +1,18 @@
1
1
  import { createRequire } from "node:module";
2
2
  import { existsSync, lstatSync, readFileSync } from "fs";
3
3
  import { delimiter, dirname, join, relative } from "path";
4
- import { fileURLToPath } from "url";
5
- import { spawn } from "child_process";
6
- import { writeFile } from "fs/promises";
7
- import { createRequire as createRequire$1 } from "module";
8
- import { z } from "zod";
4
+ import { introspectApp } from "@vercel/introspection";
9
5
  import { nodeFileTrace } from "@vercel/nft";
6
+ import { join as join$1, relative as relative$1 } from "node:path";
7
+ import { existsSync as existsSync$1 } from "node:fs";
8
+ import { writeFile } from "node:fs/promises";
10
9
  import { build as build$1, findEntrypoint, getBuildSummary } from "@vercel/cervel";
11
10
 
12
11
  //#region rolldown:runtime
13
- var __create$1 = Object.create;
14
- var __defProp$1 = Object.defineProperty;
15
- var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
16
12
  var __getOwnPropNames$1 = Object.getOwnPropertyNames;
17
- var __getProtoOf$1 = Object.getPrototypeOf;
18
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
19
13
  var __commonJS$1 = (cb, mod) => function() {
20
14
  return mod || (0, cb[__getOwnPropNames$1(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
21
15
  };
22
- var __copyProps$1 = (to, from, except, desc) => {
23
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames$1(from), i = 0, n = keys.length, key; i < n; i++) {
24
- key = keys[i];
25
- if (!__hasOwnProp$1.call(to, key) && key !== except) __defProp$1(to, key, {
26
- get: ((k) => from[k]).bind(null, key),
27
- enumerable: !(desc = __getOwnPropDesc$1(from, key)) || desc.enumerable
28
- });
29
- }
30
- return to;
31
- };
32
- var __toESM$1 = (mod, isNodeMode, target) => (target = mod != null ? __create$1(__getProtoOf$1(mod)) : {}, __copyProps$1(isNodeMode || !mod || !mod.__esModule ? __defProp$1(target, "default", {
33
- value: mod,
34
- enumerable: true
35
- }) : target, mod));
36
16
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
37
17
 
38
18
  //#endregion
@@ -3734,10 +3714,10 @@ var require_dist$1 = /* @__PURE__ */ __commonJS$1({ "../build-utils/dist/index.j
3734
3714
  });
3735
3715
  }
3736
3716
  function _createSymlink(srcpath, dstpath, type, callback) {
3737
- symlinkPaths(srcpath, dstpath, (err, relative$1) => {
3717
+ symlinkPaths(srcpath, dstpath, (err, relative$2) => {
3738
3718
  if (err) return callback(err);
3739
- srcpath = relative$1.toDst;
3740
- symlinkType(relative$1.toCwd, type, (err2, type2) => {
3719
+ srcpath = relative$2.toDst;
3720
+ symlinkType(relative$2.toCwd, type, (err2, type2) => {
3741
3721
  if (err2) return callback(err2);
3742
3722
  const dir = path7.dirname(dstpath);
3743
3723
  pathExists(dir, (err3, dirExists) => {
@@ -3759,9 +3739,9 @@ var require_dist$1 = /* @__PURE__ */ __commonJS$1({ "../build-utils/dist/index.j
3759
3739
  if (stats && stats.isSymbolicLink()) {
3760
3740
  if (areIdentical(fs6.statSync(srcpath), fs6.statSync(dstpath))) return;
3761
3741
  }
3762
- const relative$1 = symlinkPathsSync(srcpath, dstpath);
3763
- srcpath = relative$1.toDst;
3764
- type = symlinkTypeSync(relative$1.toCwd, type);
3742
+ const relative$2 = symlinkPathsSync(srcpath, dstpath);
3743
+ srcpath = relative$2.toDst;
3744
+ type = symlinkTypeSync(relative$2.toCwd, type);
3765
3745
  const dir = path7.dirname(dstpath);
3766
3746
  if (fs6.existsSync(dir)) return fs6.symlinkSync(srcpath, dstpath, type);
3767
3747
  mkdirsSync(dir);
@@ -43573,9 +43553,9 @@ var require_dist$1 = /* @__PURE__ */ __commonJS$1({ "../build-utils/dist/index.j
43573
43553
  if (pad) {
43574
43554
  var need = width - c.length;
43575
43555
  if (need > 0) {
43576
- var z$1 = new Array(need + 1).join("0");
43577
- if (i < 0) c = "-" + z$1 + c.slice(1);
43578
- else c = z$1 + c;
43556
+ var z = new Array(need + 1).join("0");
43557
+ if (i < 0) c = "-" + z + c.slice(1);
43558
+ else c = z + c;
43579
43559
  }
43580
43560
  }
43581
43561
  }
@@ -44565,9 +44545,9 @@ var require_dist$1 = /* @__PURE__ */ __commonJS$1({ "../build-utils/dist/index.j
44565
44545
  if (pad) {
44566
44546
  var need = width - c.length;
44567
44547
  if (need > 0) {
44568
- var z$1 = new Array(need + 1).join("0");
44569
- if (i < 0) c = "-" + z$1 + c.slice(1);
44570
- else c = z$1 + c;
44548
+ var z = new Array(need + 1).join("0");
44549
+ if (i < 0) c = "-" + z + c.slice(1);
44550
+ else c = z + c;
44571
44551
  }
44572
44552
  }
44573
44553
  }
@@ -53467,7 +53447,7 @@ var require_dist$1 = /* @__PURE__ */ __commonJS$1({ "../build-utils/dist/index.j
53467
53447
  return {};
53468
53448
  }
53469
53449
  var NodejsLambda$1 = class extends Lambda {
53470
- constructor({ shouldAddHelpers, shouldAddSourcemapSupport, awsLambdaHandler, useWebApi,...opts }) {
53450
+ constructor({ shouldAddHelpers, shouldAddSourcemapSupport, awsLambdaHandler, useWebApi, ...opts }) {
53471
53451
  super(opts);
53472
53452
  this.launcherType = "Nodejs";
53473
53453
  this.shouldAddHelpers = shouldAddHelpers;
@@ -54959,7 +54939,7 @@ ${entrypointsForMessage}`);
54959
54939
 
54960
54940
  //#endregion
54961
54941
  //#region src/utils.ts
54962
- var import_dist$2 = /* @__PURE__ */ __toESM$1(require_dist$1(), 1);
54942
+ var import_dist$2 = require_dist$1();
54963
54943
  async function downloadInstallAndBundle(args) {
54964
54944
  const { entrypoint, files, workPath, meta, config, repoRootPath } = args;
54965
54945
  await (0, import_dist$2.download)(files, workPath, meta);
@@ -55007,106 +54987,9 @@ async function maybeExecBuildCommand(args, options) {
55007
54987
  return (0, import_dist$2.runPackageJsonScript)(options.entrypointFsDirname, ["build"], options.spawnEnv, args.config.projectSettings?.createdAt);
55008
54988
  }
55009
54989
 
55010
- //#endregion
55011
- //#region src/introspection/index.ts
55012
- const require$1 = createRequire$1(import.meta.url);
55013
- const introspectApp = async (args, rolldownResult) => {
55014
- const cjsLoaderPath = fileURLToPath(new URL("loaders/cjs.cjs", import.meta.url));
55015
- const esmLoaderPath = new URL("loaders/esm.js", import.meta.url).href;
55016
- const handlerPath = join(rolldownResult.dir, rolldownResult.handler);
55017
- let introspectionResult = {
55018
- frameworkSlug: "",
55019
- routes: []
55020
- };
55021
- await new Promise((resolvePromise) => {
55022
- try {
55023
- const child = spawn("node", [
55024
- "-r",
55025
- cjsLoaderPath,
55026
- "--import",
55027
- esmLoaderPath,
55028
- handlerPath
55029
- ], {
55030
- stdio: [
55031
- "pipe",
55032
- "pipe",
55033
- "pipe"
55034
- ],
55035
- cwd: rolldownResult.dir,
55036
- env: {
55037
- ...process.env,
55038
- ...args.meta?.env || {},
55039
- ...args.meta?.buildEnv || {}
55040
- }
55041
- });
55042
- child.stdout?.on("data", (data) => {
55043
- try {
55044
- const introspection = JSON.parse(data.toString());
55045
- introspectionResult = z.object({
55046
- frameworkSlug: z.string(),
55047
- routes: z.array(z.object({
55048
- src: z.string(),
55049
- dest: z.string(),
55050
- methods: z.array(z.string())
55051
- }))
55052
- }).parse(introspection);
55053
- } catch (error) {}
55054
- });
55055
- const timeout = setTimeout(() => {
55056
- child.kill("SIGTERM");
55057
- }, 2e3);
55058
- const timeout2 = setTimeout(() => {
55059
- child.kill("SIGKILL");
55060
- }, 3e3);
55061
- child.on("error", (err) => {
55062
- clearTimeout(timeout);
55063
- clearTimeout(timeout2);
55064
- console.log(`Loader error: ${err.message}`);
55065
- resolvePromise(void 0);
55066
- });
55067
- child.on("close", () => {
55068
- clearTimeout(timeout);
55069
- clearTimeout(timeout2);
55070
- resolvePromise(void 0);
55071
- });
55072
- } catch (error) {
55073
- resolvePromise(void 0);
55074
- }
55075
- });
55076
- const routes = [
55077
- { handle: "filesystem" },
55078
- ...introspectionResult.routes,
55079
- {
55080
- src: "/(.*)",
55081
- dest: "/"
55082
- }
55083
- ];
55084
- let version$1;
55085
- if (introspectionResult.frameworkSlug) {
55086
- const frameworkLibPath = require$1.resolve(`${introspectionResult.frameworkSlug}`, { paths: [rolldownResult.dir] });
55087
- const findNearestPackageJson = (dir) => {
55088
- const packageJsonPath = join(dir, "package.json");
55089
- if (existsSync(packageJsonPath)) return packageJsonPath;
55090
- const parentDir = dirname(dir);
55091
- if (parentDir === dir) return;
55092
- return findNearestPackageJson(parentDir);
55093
- };
55094
- const nearestPackageJsonPath = findNearestPackageJson(frameworkLibPath);
55095
- if (nearestPackageJsonPath) version$1 = require$1(nearestPackageJsonPath).version;
55096
- }
55097
- return {
55098
- routes,
55099
- files: rolldownResult.files,
55100
- framework: {
55101
- slug: introspectionResult.frameworkSlug,
55102
- version: version$1
55103
- }
55104
- };
55105
- };
55106
-
55107
54990
  //#endregion
55108
54991
  //#region src/node-file-trace.ts
55109
- var import_dist$1 = /* @__PURE__ */ __toESM$1(require_dist$1(), 1);
54992
+ var import_dist$1 = require_dist$1();
55110
54993
  const nodeFileTrace$1 = async (args, output) => {
55111
54994
  const { dir: outputDir, handler } = output;
55112
54995
  const entry = join(outputDir, handler);
@@ -55137,7 +55020,7 @@ const nodeFileTrace$1 = async (args, output) => {
55137
55020
 
55138
55021
  //#endregion
55139
55022
  //#region src/build.ts
55140
- const defaultOutputDirectory = join(".vercel", "node");
55023
+ const defaultOutputDirectory = join$1(".vercel", "node");
55141
55024
  const doBuild = async (args, downloadResult) => {
55142
55025
  const buildCommandResult = await maybeExecBuildCommand(args, downloadResult);
55143
55026
  const outputSetting = args.config.outputDirectory;
@@ -55146,8 +55029,8 @@ const doBuild = async (args, downloadResult) => {
55146
55029
  const isCervelCommand = buildCommand?.trim().startsWith("cervel");
55147
55030
  if (!outputSetting) {
55148
55031
  if (isCervelCommand) {
55149
- const cervelOutputDir = join(args.workPath, "dist");
55150
- if (existsSync(join(cervelOutputDir, ".cervel.json"))) {
55032
+ const cervelOutputDir = join$1(args.workPath, "dist");
55033
+ if (existsSync$1(join$1(cervelOutputDir, ".cervel.json"))) {
55151
55034
  const { handler: handler$2 } = await getBuildSummary(cervelOutputDir);
55152
55035
  return {
55153
55036
  dir: cervelOutputDir,
@@ -55157,10 +55040,10 @@ const doBuild = async (args, downloadResult) => {
55157
55040
  }
55158
55041
  throw new Error(`Build command "${buildCommand}" completed, but no output was found at ${cervelOutputDir}. Make sure your cervel command is configured correctly.`);
55159
55042
  }
55160
- const distDir = join(args.workPath, "dist");
55161
- if (existsSync(distDir)) {
55162
- const cervelJsonPath$1 = join(distDir, ".cervel.json");
55163
- if (existsSync(cervelJsonPath$1)) {
55043
+ const distDir = join$1(args.workPath, "dist");
55044
+ if (existsSync$1(distDir)) {
55045
+ const cervelJsonPath$1 = join$1(distDir, ".cervel.json");
55046
+ if (existsSync$1(cervelJsonPath$1)) {
55164
55047
  const { handler: handler$3 } = await getBuildSummary(distDir);
55165
55048
  return {
55166
55049
  dir: distDir,
@@ -55193,7 +55076,7 @@ const doBuild = async (args, downloadResult) => {
55193
55076
  tsPromise
55194
55077
  };
55195
55078
  }
55196
- const outputDir = join(args.workPath, outputSetting);
55079
+ const outputDir = join$1(args.workPath, outputSetting);
55197
55080
  if (!buildCommandResult) {
55198
55081
  const buildResult = await build$1({
55199
55082
  cwd: args.workPath,
@@ -55207,8 +55090,8 @@ const doBuild = async (args, downloadResult) => {
55207
55090
  tsPromise
55208
55091
  };
55209
55092
  }
55210
- const cervelJsonPath = join(outputDir, ".cervel.json");
55211
- if (existsSync(cervelJsonPath)) {
55093
+ const cervelJsonPath = join$1(outputDir, ".cervel.json");
55094
+ if (existsSync$1(cervelJsonPath)) {
55212
55095
  const { handler: handler$1 } = await getBuildSummary(outputDir);
55213
55096
  return {
55214
55097
  dir: outputDir,
@@ -55232,17 +55115,20 @@ const doBuild = async (args, downloadResult) => {
55232
55115
 
55233
55116
  //#endregion
55234
55117
  //#region src/index.ts
55235
- var import_dist = /* @__PURE__ */ __toESM$1(require_dist$1(), 1);
55118
+ var import_dist = require_dist$1();
55236
55119
  const version = 2;
55237
55120
  const build = async (args) => {
55238
55121
  const downloadResult = await downloadInstallAndBundle(args);
55239
55122
  const outputConfig = await doBuild(args, downloadResult);
55240
55123
  const { files } = await nodeFileTrace$1(args, outputConfig);
55241
- const { routes, framework } = await introspectApp(args, {
55124
+ const { routes, framework } = await introspectApp({
55242
55125
  ...outputConfig,
55243
- files
55126
+ env: {
55127
+ ...args.meta?.env ?? {},
55128
+ ...args.meta?.buildEnv ?? {}
55129
+ }
55244
55130
  });
55245
- const handler = relative(args.repoRootPath, join(outputConfig.dir, outputConfig.handler));
55131
+ const handler = relative$1(args.repoRootPath, join$1(outputConfig.dir, outputConfig.handler));
55246
55132
  const lambda = new import_dist.NodejsLambda({
55247
55133
  runtime: downloadResult.nodeVersion.runtime,
55248
55134
  handler,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/backends",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index.js",
6
6
  "homepage": "https://vercel.com/docs",
@@ -9,10 +9,7 @@
9
9
  "access": "public"
10
10
  },
11
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"
12
+ ".": "./dist/index.js"
16
13
  },
17
14
  "repository": {
18
15
  "type": "git",
@@ -20,29 +17,15 @@
20
17
  "directory": "packages/backends"
21
18
  },
22
19
  "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"
20
+ "dist"
36
21
  ],
37
22
  "dependencies": {
38
23
  "@vercel/nft": "0.30.1",
39
24
  "@vercel/static-config": "3.1.2",
40
25
  "fs-extra": "11.1.0",
41
- "path-to-regexp": "8.3.0",
42
26
  "rolldown": "1.0.0-beta.35",
43
- "ts-morph": "12.0.0",
44
- "zod": "3.22.4",
45
- "@vercel/cervel": "0.0.3"
27
+ "@vercel/cervel": "0.0.3",
28
+ "@vercel/introspection": "0.0.2"
46
29
  },
47
30
  "devDependencies": {
48
31
  "@types/express": "5.0.3",
package/dist/express.js DELETED
@@ -1,66 +0,0 @@
1
- import { pathToRegexp } from "path-to-regexp";
2
-
3
- //#region src/introspection/util.ts
4
- const setupCloseHandlers = (cb) => {
5
- const callCallback = () => {
6
- const result = cb();
7
- if (result) console.log(JSON.stringify(result));
8
- };
9
- process.on("SIGINT", callCallback);
10
- process.on("SIGTERM", callCallback);
11
- process.on("exit", callCallback);
12
- };
13
-
14
- //#endregion
15
- //#region src/introspection/express.ts
16
- let app = null;
17
- const handle = (expressModule) => {
18
- if (typeof expressModule === "function") {
19
- const originalCreateApp = expressModule;
20
- const createApp = (...args) => {
21
- app = originalCreateApp(...args);
22
- return app;
23
- };
24
- Object.setPrototypeOf(createApp, originalCreateApp);
25
- Object.assign(createApp, originalCreateApp);
26
- return createApp;
27
- }
28
- return expressModule;
29
- };
30
- setupCloseHandlers(() => {
31
- const routes = extractRoutes();
32
- if (routes.length > 0) return {
33
- frameworkSlug: "express",
34
- routes
35
- };
36
- });
37
- const extractRoutes = () => {
38
- if (!app) return [];
39
- const routes = [];
40
- const methods = [
41
- "all",
42
- "get",
43
- "post",
44
- "put",
45
- "delete",
46
- "patch",
47
- "options",
48
- "head"
49
- ];
50
- const router = app._router || app.router;
51
- for (const route of router.stack) if (route.route) {
52
- const m = [];
53
- for (const method of methods) if (route.route.methods[method]) m.push(method.toUpperCase());
54
- const { regexp } = pathToRegexp(route.route.path);
55
- if (route.route.path === "/") continue;
56
- routes.push({
57
- src: regexp.source,
58
- dest: route.route.path,
59
- methods: m
60
- });
61
- }
62
- return routes;
63
- };
64
-
65
- //#endregion
66
- export { handle };
package/dist/hono.js DELETED
@@ -1,52 +0,0 @@
1
- import { pathToRegexp } from "path-to-regexp";
2
-
3
- //#region src/introspection/util.ts
4
- const setupCloseHandlers = (cb) => {
5
- const callCallback = () => {
6
- const result = cb();
7
- if (result) console.log(JSON.stringify(result));
8
- };
9
- process.on("SIGINT", callCallback);
10
- process.on("SIGTERM", callCallback);
11
- process.on("exit", callCallback);
12
- };
13
-
14
- //#endregion
15
- //#region src/introspection/hono.ts
16
- const apps = [];
17
- const handle = (honoModule) => {
18
- const TrackedHono = class extends honoModule.Hono {
19
- constructor(...args) {
20
- super(...args);
21
- apps.push(this);
22
- }
23
- };
24
- return TrackedHono;
25
- };
26
- setupCloseHandlers(() => {
27
- const routes = extractRoutes();
28
- if (routes.length > 0) return {
29
- frameworkSlug: "hono",
30
- routes
31
- };
32
- });
33
- function extractRoutes() {
34
- const app = apps.sort((a, b) => b.routes.length - a.routes.length)[0];
35
- if (!app || !app.routes) return [];
36
- const routes = [];
37
- for (const route of app.routes) {
38
- const routePath = route.path;
39
- const method = route.method.toUpperCase();
40
- const { regexp } = pathToRegexp(routePath);
41
- if (routePath === "/") continue;
42
- routes.push({
43
- src: regexp.source,
44
- dest: routePath,
45
- methods: [method]
46
- });
47
- }
48
- return routes;
49
- }
50
-
51
- //#endregion
52
- export { handle };
@@ -1,140 +0,0 @@
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
-
28
- //#region src/introspection/util.ts
29
- const setupCloseHandlers = (cb) => {
30
- const callCallback = () => {
31
- const result = cb();
32
- if (result) console.log(JSON.stringify(result));
33
- };
34
- process.on("SIGINT", callCallback);
35
- process.on("SIGTERM", callCallback);
36
- process.on("exit", callCallback);
37
- };
38
-
39
- //#endregion
40
- //#region src/introspection/hono.ts
41
- const apps = [];
42
- const handle = (honoModule) => {
43
- const TrackedHono = class extends honoModule.Hono {
44
- constructor(...args) {
45
- super(...args);
46
- apps.push(this);
47
- }
48
- };
49
- return TrackedHono;
50
- };
51
- setupCloseHandlers(() => {
52
- const routes = extractRoutes$1();
53
- if (routes.length > 0) return {
54
- frameworkSlug: "hono",
55
- routes
56
- };
57
- });
58
- function extractRoutes$1() {
59
- const app$1 = apps.sort((a, b) => b.routes.length - a.routes.length)[0];
60
- if (!app$1 || !app$1.routes) return [];
61
- const routes = [];
62
- for (const route of app$1.routes) {
63
- const routePath = route.path;
64
- const method = route.method.toUpperCase();
65
- const { regexp } = (0, path_to_regexp.pathToRegexp)(routePath);
66
- if (routePath === "/") continue;
67
- routes.push({
68
- src: regexp.source,
69
- dest: routePath,
70
- methods: [method]
71
- });
72
- }
73
- return routes;
74
- }
75
-
76
- //#endregion
77
- //#region src/introspection/express.ts
78
- let app = null;
79
- const handle$1 = (expressModule) => {
80
- if (typeof expressModule === "function") {
81
- const originalCreateApp = expressModule;
82
- const createApp = (...args) => {
83
- app = originalCreateApp(...args);
84
- return app;
85
- };
86
- Object.setPrototypeOf(createApp, originalCreateApp);
87
- Object.assign(createApp, originalCreateApp);
88
- return createApp;
89
- }
90
- return expressModule;
91
- };
92
- setupCloseHandlers(() => {
93
- const routes = extractRoutes();
94
- if (routes.length > 0) return {
95
- frameworkSlug: "express",
96
- routes
97
- };
98
- });
99
- const extractRoutes = () => {
100
- if (!app) return [];
101
- const routes = [];
102
- const methods = [
103
- "all",
104
- "get",
105
- "post",
106
- "put",
107
- "delete",
108
- "patch",
109
- "options",
110
- "head"
111
- ];
112
- const router = app._router || app.router;
113
- for (const route of router.stack) if (route.route) {
114
- const m = [];
115
- for (const method of methods) if (route.route.methods[method]) m.push(method.toUpperCase());
116
- const { regexp } = (0, path_to_regexp.pathToRegexp)(route.route.path);
117
- if (route.route.path === "/") continue;
118
- routes.push({
119
- src: regexp.source,
120
- dest: route.route.path,
121
- methods: m
122
- });
123
- }
124
- return routes;
125
- };
126
-
127
- //#endregion
128
- //#region src/introspection/loaders/cjs.ts
129
- const originalRequire = module$1.default.prototype.require;
130
- module$1.default.prototype.require = function(id, ...args) {
131
- const result = originalRequire.apply(this, [id, ...args]);
132
- if (id === "express") return handle$1(result);
133
- if (id === "hono") return {
134
- ...result,
135
- Hono: handle(result)
136
- };
137
- return result;
138
- };
139
-
140
- //#endregion
@@ -1,7 +0,0 @@
1
- import { register } from "node:module";
2
-
3
- //#region src/introspection/loaders/esm.ts
4
- register(new URL("./hooks.js", import.meta.url), import.meta.url);
5
-
6
- //#endregion
7
- export { };
@@ -1,50 +0,0 @@
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 };
File without changes