@vercel/backends 0.0.5 → 0.0.7

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,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
  }
@@ -52855,6 +52835,7 @@ var require_dist$1 = /* @__PURE__ */ __commonJS$1({ "../build-utils/dist/index.j
52855
52835
  getPrettyError: () => getPrettyError,
52856
52836
  getProvidedRuntime: () => getProvidedRuntime,
52857
52837
  getScriptName: () => getScriptName,
52838
+ getSpawnOptions: () => getSpawnOptions$1,
52858
52839
  getSupportedBunVersion: () => getSupportedBunVersion,
52859
52840
  getSupportedNodeVersion: () => getSupportedNodeVersion,
52860
52841
  getWriteableDirectory: () => getWritableDirectory,
@@ -53908,6 +53889,23 @@ var require_dist$1 = /* @__PURE__ */ __commonJS$1({ "../build-utils/dist/index.j
53908
53889
  });
53909
53890
  return true;
53910
53891
  }
53892
+ function getSpawnOptions$1(meta, nodeVersion) {
53893
+ const opts = { env: cloneEnv(process.env) };
53894
+ if (isBunVersion(nodeVersion)) return opts;
53895
+ if (!meta.isDev) {
53896
+ let found = false;
53897
+ const pathSegments = (opts.env.PATH || process.env.PATH || "").split(import_path5.default.delimiter).map((segment) => {
53898
+ if (/^\/node[0-9]+\/bin/.test(segment)) {
53899
+ found = true;
53900
+ return `/node${nodeVersion.major}/bin`;
53901
+ }
53902
+ return segment;
53903
+ });
53904
+ if (!found) pathSegments.unshift(`/node${nodeVersion.major}/bin`);
53905
+ opts.env.PATH = pathSegments.filter(Boolean).join(import_path5.default.delimiter);
53906
+ }
53907
+ return opts;
53908
+ }
53911
53909
  async function getNodeVersion$1(destPath, fallbackVersion = process.env.VERCEL_PROJECT_SETTINGS_NODE_VERSION, config = {}, meta = {}, availableVersions = getAvailableNodeVersions()) {
53912
53910
  if (config.bunVersion) return getSupportedBunVersion(config.bunVersion);
53913
53911
  const latestVersion = getLatestNodeVersion(availableVersions);
@@ -54959,18 +54957,19 @@ ${entrypointsForMessage}`);
54959
54957
 
54960
54958
  //#endregion
54961
54959
  //#region src/utils.ts
54962
- var import_dist$2 = /* @__PURE__ */ __toESM$1(require_dist$1(), 1);
54960
+ var import_dist$2 = require_dist$1();
54963
54961
  async function downloadInstallAndBundle(args) {
54964
54962
  const { entrypoint, files, workPath, meta, config, repoRootPath } = args;
54965
54963
  await (0, import_dist$2.download)(files, workPath, meta);
54966
54964
  const entrypointFsDirname = join(workPath, dirname(entrypoint));
54967
54965
  const nodeVersion = await (0, import_dist$2.getNodeVersion)(entrypointFsDirname, void 0, config, meta);
54966
+ const spawnOpts = (0, import_dist$2.getSpawnOptions)(meta || {}, nodeVersion);
54968
54967
  const { cliType, lockfileVersion, packageJsonPackageManager, turboSupportsCorepackHome } = await (0, import_dist$2.scanParentDirs)(entrypointFsDirname, true, repoRootPath);
54969
- const spawnEnv = (0, import_dist$2.getEnvForPackageManager)({
54968
+ spawnOpts.env = (0, import_dist$2.getEnvForPackageManager)({
54970
54969
  cliType,
54971
54970
  lockfileVersion,
54972
54971
  packageJsonPackageManager,
54973
- env: process.env,
54972
+ env: spawnOpts.env || {},
54974
54973
  turboSupportsCorepackHome,
54975
54974
  projectCreatedAt: config.projectSettings?.createdAt
54976
54975
  });
@@ -54978,15 +54977,15 @@ async function downloadInstallAndBundle(args) {
54978
54977
  if (typeof installCommand === "string") if (installCommand.trim()) {
54979
54978
  console.log(`Running "install" command: \`${installCommand}\`...`);
54980
54979
  await (0, import_dist$2.execCommand)(installCommand, {
54981
- env: spawnEnv,
54980
+ ...spawnOpts,
54982
54981
  cwd: entrypointFsDirname
54983
54982
  });
54984
54983
  } else console.log(`Skipping "install" command...`);
54985
- else await (0, import_dist$2.runNpmInstall)(entrypointFsDirname, [], { env: spawnEnv }, meta, config.projectSettings?.createdAt);
54984
+ else await (0, import_dist$2.runNpmInstall)(entrypointFsDirname, [], spawnOpts, meta, config.projectSettings?.createdAt);
54986
54985
  return {
54987
54986
  entrypointFsDirname,
54988
54987
  nodeVersion,
54989
- spawnEnv
54988
+ spawnOpts
54990
54989
  };
54991
54990
  }
54992
54991
  async function maybeExecBuildCommand(args, options) {
@@ -54996,117 +54995,22 @@ async function maybeExecBuildCommand(args, options) {
54996
54995
  base: args.repoRootPath || args.workPath,
54997
54996
  start: args.workPath
54998
54997
  }).join(delimiter);
54998
+ const env = {
54999
+ ...options.spawnOpts.env,
55000
+ PATH: `${nodeBinPath}${delimiter}${options.spawnOpts.env?.PATH || process.env.PATH}`
55001
+ };
54999
55002
  return (0, import_dist$2.execCommand)(projectBuildCommand, {
55000
- env: {
55001
- ...options.spawnEnv,
55002
- PATH: `${nodeBinPath}${delimiter}${options.spawnEnv?.PATH || process.env.PATH}`
55003
- },
55003
+ ...options.spawnOpts,
55004
+ env,
55004
55005
  cwd: args.workPath
55005
55006
  });
55006
55007
  }
55007
- return (0, import_dist$2.runPackageJsonScript)(options.entrypointFsDirname, ["build"], options.spawnEnv, args.config.projectSettings?.createdAt);
55008
+ return (0, import_dist$2.runPackageJsonScript)(options.entrypointFsDirname, ["build"], options.spawnOpts, args.config.projectSettings?.createdAt);
55008
55009
  }
55009
55010
 
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
55011
  //#endregion
55108
55012
  //#region src/node-file-trace.ts
55109
- var import_dist$1 = /* @__PURE__ */ __toESM$1(require_dist$1(), 1);
55013
+ var import_dist$1 = require_dist$1();
55110
55014
  const nodeFileTrace$1 = async (args, output) => {
55111
55015
  const { dir: outputDir, handler } = output;
55112
55016
  const entry = join(outputDir, handler);
@@ -55137,7 +55041,7 @@ const nodeFileTrace$1 = async (args, output) => {
55137
55041
 
55138
55042
  //#endregion
55139
55043
  //#region src/build.ts
55140
- const defaultOutputDirectory = join(".vercel", "node");
55044
+ const defaultOutputDirectory = join$1(".vercel", "node");
55141
55045
  const doBuild = async (args, downloadResult) => {
55142
55046
  const buildCommandResult = await maybeExecBuildCommand(args, downloadResult);
55143
55047
  const outputSetting = args.config.outputDirectory;
@@ -55146,8 +55050,8 @@ const doBuild = async (args, downloadResult) => {
55146
55050
  const isCervelCommand = buildCommand?.trim().startsWith("cervel");
55147
55051
  if (!outputSetting) {
55148
55052
  if (isCervelCommand) {
55149
- const cervelOutputDir = join(args.workPath, "dist");
55150
- if (existsSync(join(cervelOutputDir, ".cervel.json"))) {
55053
+ const cervelOutputDir = join$1(args.workPath, "dist");
55054
+ if (existsSync$1(join$1(cervelOutputDir, ".cervel.json"))) {
55151
55055
  const { handler: handler$2 } = await getBuildSummary(cervelOutputDir);
55152
55056
  return {
55153
55057
  dir: cervelOutputDir,
@@ -55157,10 +55061,10 @@ const doBuild = async (args, downloadResult) => {
55157
55061
  }
55158
55062
  throw new Error(`Build command "${buildCommand}" completed, but no output was found at ${cervelOutputDir}. Make sure your cervel command is configured correctly.`);
55159
55063
  }
55160
- const distDir = join(args.workPath, "dist");
55161
- if (existsSync(distDir)) {
55162
- const cervelJsonPath$1 = join(distDir, ".cervel.json");
55163
- if (existsSync(cervelJsonPath$1)) {
55064
+ const distDir = join$1(args.workPath, "dist");
55065
+ if (existsSync$1(distDir)) {
55066
+ const cervelJsonPath$1 = join$1(distDir, ".cervel.json");
55067
+ if (existsSync$1(cervelJsonPath$1)) {
55164
55068
  const { handler: handler$3 } = await getBuildSummary(distDir);
55165
55069
  return {
55166
55070
  dir: distDir,
@@ -55193,7 +55097,7 @@ const doBuild = async (args, downloadResult) => {
55193
55097
  tsPromise
55194
55098
  };
55195
55099
  }
55196
- const outputDir = join(args.workPath, outputSetting);
55100
+ const outputDir = join$1(args.workPath, outputSetting);
55197
55101
  if (!buildCommandResult) {
55198
55102
  const buildResult = await build$1({
55199
55103
  cwd: args.workPath,
@@ -55207,8 +55111,8 @@ const doBuild = async (args, downloadResult) => {
55207
55111
  tsPromise
55208
55112
  };
55209
55113
  }
55210
- const cervelJsonPath = join(outputDir, ".cervel.json");
55211
- if (existsSync(cervelJsonPath)) {
55114
+ const cervelJsonPath = join$1(outputDir, ".cervel.json");
55115
+ if (existsSync$1(cervelJsonPath)) {
55212
55116
  const { handler: handler$1 } = await getBuildSummary(outputDir);
55213
55117
  return {
55214
55118
  dir: outputDir,
@@ -55232,17 +55136,20 @@ const doBuild = async (args, downloadResult) => {
55232
55136
 
55233
55137
  //#endregion
55234
55138
  //#region src/index.ts
55235
- var import_dist = /* @__PURE__ */ __toESM$1(require_dist$1(), 1);
55139
+ var import_dist = require_dist$1();
55236
55140
  const version = 2;
55237
55141
  const build = async (args) => {
55238
55142
  const downloadResult = await downloadInstallAndBundle(args);
55239
55143
  const outputConfig = await doBuild(args, downloadResult);
55240
55144
  const { files } = await nodeFileTrace$1(args, outputConfig);
55241
- const { routes, framework } = await introspectApp(args, {
55145
+ const { routes, framework } = await introspectApp({
55242
55146
  ...outputConfig,
55243
- files
55147
+ env: {
55148
+ ...args.meta?.env ?? {},
55149
+ ...args.meta?.buildEnv ?? {}
55150
+ }
55244
55151
  });
55245
- const handler = relative(args.repoRootPath, join(outputConfig.dir, outputConfig.handler));
55152
+ const handler = relative$1(args.repoRootPath, join$1(outputConfig.dir, outputConfig.handler));
55246
55153
  const lambda = new import_dist.NodejsLambda({
55247
55154
  runtime: downloadResult.nodeVersion.runtime,
55248
55155
  handler,
package/package.json CHANGED
@@ -1,18 +1,16 @@
1
1
  {
2
2
  "name": "@vercel/backends",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "license": "Apache-2.0",
5
- "main": "./dist/index.js",
5
+ "main": "./dist/index.mjs",
6
6
  "homepage": "https://vercel.com/docs",
7
7
  "type": "module",
8
8
  "publishConfig": {
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.mjs",
13
+ "./package.json": "./package.json"
16
14
  },
17
15
  "repository": {
18
16
  "type": "git",
@@ -20,43 +18,31 @@
20
18
  "directory": "packages/backends"
21
19
  },
22
20
  "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"
21
+ "dist"
36
22
  ],
37
23
  "dependencies": {
38
24
  "@vercel/nft": "0.30.1",
39
25
  "@vercel/static-config": "3.1.2",
40
26
  "fs-extra": "11.1.0",
41
- "path-to-regexp": "8.3.0",
42
27
  "rolldown": "1.0.0-beta.35",
43
- "ts-morph": "12.0.0",
44
- "zod": "3.22.4",
45
- "@vercel/cervel": "0.0.3"
28
+ "@vercel/cervel": "0.0.3",
29
+ "@vercel/introspection": "0.0.2"
46
30
  },
47
31
  "devDependencies": {
48
32
  "@types/express": "5.0.3",
49
33
  "@types/fs-extra": "11",
50
34
  "@types/jest": "27.5.1",
51
35
  "@types/node": "22",
52
- "@vercel/build-utils": "13.0.0",
36
+ "@vercel/build-utils": "13.0.1",
53
37
  "execa": "3.2.0",
54
38
  "hono": "4.10.1",
55
39
  "jest-junit": "16.0.0",
56
- "tsdown": "0.15.6",
40
+ "tsdown": "0.16.3",
57
41
  "vite": "^5.1.6",
58
42
  "vitest": "^2.0.1"
59
43
  },
44
+ "module": "./dist/index.mjs",
45
+ "types": "./dist/index.d.mts",
60
46
  "scripts": {
61
47
  "build": "tsdown",
62
48
  "vitest-run": "vitest -c ../../vitest.config.mts",
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