@vercel/backends 0.0.4 → 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
  }
@@ -50556,7 +50536,8 @@ var require_dist$1 = /* @__PURE__ */ __commonJS$1({ "../build-utils/dist/index.j
50556
50536
  }
50557
50537
  var _custom;
50558
50538
  try {
50559
- _custom = eval("require('util').inspect").custom;
50539
+ const utilInspect = eval("require('util').inspect");
50540
+ _custom = utilInspect.custom;
50560
50541
  } catch (_) {}
50561
50542
  var _inspect = _custom || "inspect";
50562
50543
  var BoxedBigInt = class {
@@ -52854,13 +52835,13 @@ var require_dist$1 = /* @__PURE__ */ __commonJS$1({ "../build-utils/dist/index.j
52854
52835
  getPrettyError: () => getPrettyError,
52855
52836
  getProvidedRuntime: () => getProvidedRuntime,
52856
52837
  getScriptName: () => getScriptName,
52857
- getSpawnOptions: () => getSpawnOptions$1,
52858
52838
  getSupportedBunVersion: () => getSupportedBunVersion,
52859
52839
  getSupportedNodeVersion: () => getSupportedNodeVersion,
52860
52840
  getWriteableDirectory: () => getWritableDirectory,
52861
52841
  glob: () => glob,
52862
52842
  hardLinkDir: () => hardLinkDir,
52863
52843
  installDependencies: () => installDependencies,
52844
+ isBackendBuilder: () => isBackendBuilder,
52864
52845
  isBackendFramework: () => isBackendFramework,
52865
52846
  isBunVersion: () => isBunVersion,
52866
52847
  isDirectory: () => isDirectory,
@@ -52924,8 +52905,9 @@ var require_dist$1 = /* @__PURE__ */ __commonJS$1({ "../build-utils/dist/index.j
52924
52905
  var import_fs_extra = __toESM(require_lib());
52925
52906
  var import_multistream = __toESM(require_multistream());
52926
52907
  var import_path = __toESM(__require("path"));
52927
- var semaToPreventEMFILE = new (__toESM(require_async_sema())).default(20);
52928
- var file_fs_ref_default = class _FileFsRef {
52908
+ var import_async_sema = __toESM(require_async_sema());
52909
+ var semaToPreventEMFILE = new import_async_sema.default(20);
52910
+ var FileFsRef$1 = class _FileFsRef {
52929
52911
  constructor({ mode = 33188, contentType, fsPath, size }) {
52930
52912
  (0, import_assert2.default)(typeof mode === "number");
52931
52913
  (0, import_assert2.default)(typeof fsPath === "string");
@@ -52989,11 +52971,13 @@ var require_dist$1 = /* @__PURE__ */ __commonJS$1({ "../build-utils/dist/index.j
52989
52971
  });
52990
52972
  }
52991
52973
  };
52974
+ var file_fs_ref_default = FileFsRef$1;
52992
52975
  var import_assert3 = __toESM(__require("assert"));
52993
52976
  var import_node_fetch = __toESM(require_lib3());
52994
52977
  var import_multistream2 = __toESM(require_multistream());
52995
52978
  var import_async_retry = __toESM(require_lib4());
52996
- var semaToDownloadFromS3 = new (__toESM(require_async_sema())).default(5);
52979
+ var import_async_sema2 = __toESM(require_async_sema());
52980
+ var semaToDownloadFromS3 = new import_async_sema2.default(5);
52997
52981
  var BailableError = class extends Error {
52998
52982
  constructor(...args) {
52999
52983
  super(...args);
@@ -53463,7 +53447,7 @@ var require_dist$1 = /* @__PURE__ */ __commonJS$1({ "../build-utils/dist/index.j
53463
53447
  return {};
53464
53448
  }
53465
53449
  var NodejsLambda$1 = class extends Lambda {
53466
- constructor({ shouldAddHelpers, shouldAddSourcemapSupport, awsLambdaHandler, useWebApi,...opts }) {
53450
+ constructor({ shouldAddHelpers, shouldAddSourcemapSupport, awsLambdaHandler, useWebApi, ...opts }) {
53467
53451
  super(opts);
53468
53452
  this.launcherType = "Nodejs";
53469
53453
  this.shouldAddHelpers = shouldAddHelpers;
@@ -53904,23 +53888,6 @@ var require_dist$1 = /* @__PURE__ */ __commonJS$1({ "../build-utils/dist/index.j
53904
53888
  });
53905
53889
  return true;
53906
53890
  }
53907
- function getSpawnOptions$1(meta, nodeVersion) {
53908
- const opts = { env: cloneEnv(process.env) };
53909
- if (isBunVersion(nodeVersion)) return opts;
53910
- if (!meta.isDev) {
53911
- let found = false;
53912
- const pathSegments = (opts.env.PATH || process.env.PATH || "").split(import_path5.default.delimiter).map((segment) => {
53913
- if (/^\/node[0-9]+\/bin/.test(segment)) {
53914
- found = true;
53915
- return `/node${nodeVersion.major}/bin`;
53916
- }
53917
- return segment;
53918
- });
53919
- if (!found) pathSegments.unshift(`/node${nodeVersion.major}/bin`);
53920
- opts.env.PATH = pathSegments.filter(Boolean).join(import_path5.default.delimiter);
53921
- }
53922
- return opts;
53923
- }
53924
53891
  async function getNodeVersion$1(destPath, fallbackVersion = process.env.VERCEL_PROJECT_SETTINGS_NODE_VERSION, config = {}, meta = {}, availableVersions = getAvailableNodeVersions()) {
53925
53892
  if (config.bunVersion) return getSupportedBunVersion(config.bunVersion);
53926
53893
  const latestVersion = getLatestNodeVersion(availableVersions);
@@ -54942,7 +54909,16 @@ ${entrypointsForMessage}`);
54942
54909
  "hono",
54943
54910
  "h3",
54944
54911
  "nestjs",
54945
- "fastify"
54912
+ "fastify",
54913
+ "elysia"
54914
+ ];
54915
+ var BACKEND_BUILDERS = [
54916
+ "@vercel/express",
54917
+ "@vercel/hono",
54918
+ "@vercel/h3",
54919
+ "@vercel/nestjs",
54920
+ "@vercel/fastify",
54921
+ "@vercel/elysia"
54946
54922
  ];
54947
54923
  function isBackendFramework(framework) {
54948
54924
  if (!framework) return false;
@@ -54951,6 +54927,11 @@ ${entrypointsForMessage}`);
54951
54927
  function isExperimentalBackendsEnabled() {
54952
54928
  return process.env.VERCEL_EXPERIMENTAL_BACKENDS === "1" || process.env.VERCEL_EXPERIMENTAL_EXPRESS_BUILD === "1" || process.env.VERCEL_EXPERIMENTAL_HONO_BUILD === "1";
54953
54929
  }
54930
+ function isBackendBuilder(builder) {
54931
+ if (!builder) return false;
54932
+ const use = builder.use;
54933
+ return BACKEND_BUILDERS.includes(use);
54934
+ }
54954
54935
  function shouldUseExperimentalBackends(framework) {
54955
54936
  return isExperimentalBackendsEnabled() && isBackendFramework(framework);
54956
54937
  }
@@ -54958,19 +54939,18 @@ ${entrypointsForMessage}`);
54958
54939
 
54959
54940
  //#endregion
54960
54941
  //#region src/utils.ts
54961
- var import_dist$2 = /* @__PURE__ */ __toESM$1(require_dist$1(), 1);
54942
+ var import_dist$2 = require_dist$1();
54962
54943
  async function downloadInstallAndBundle(args) {
54963
54944
  const { entrypoint, files, workPath, meta, config, repoRootPath } = args;
54964
54945
  await (0, import_dist$2.download)(files, workPath, meta);
54965
54946
  const entrypointFsDirname = join(workPath, dirname(entrypoint));
54966
54947
  const nodeVersion = await (0, import_dist$2.getNodeVersion)(entrypointFsDirname, void 0, config, meta);
54967
- const spawnOpts = (0, import_dist$2.getSpawnOptions)(meta || {}, nodeVersion);
54968
54948
  const { cliType, lockfileVersion, packageJsonPackageManager, turboSupportsCorepackHome } = await (0, import_dist$2.scanParentDirs)(entrypointFsDirname, true, repoRootPath);
54969
- spawnOpts.env = (0, import_dist$2.getEnvForPackageManager)({
54949
+ const spawnEnv = (0, import_dist$2.getEnvForPackageManager)({
54970
54950
  cliType,
54971
54951
  lockfileVersion,
54972
54952
  packageJsonPackageManager,
54973
- env: spawnOpts.env || {},
54953
+ env: process.env,
54974
54954
  turboSupportsCorepackHome,
54975
54955
  projectCreatedAt: config.projectSettings?.createdAt
54976
54956
  });
@@ -54978,15 +54958,15 @@ async function downloadInstallAndBundle(args) {
54978
54958
  if (typeof installCommand === "string") if (installCommand.trim()) {
54979
54959
  console.log(`Running "install" command: \`${installCommand}\`...`);
54980
54960
  await (0, import_dist$2.execCommand)(installCommand, {
54981
- ...spawnOpts,
54961
+ env: spawnEnv,
54982
54962
  cwd: entrypointFsDirname
54983
54963
  });
54984
54964
  } else console.log(`Skipping "install" command...`);
54985
- else await (0, import_dist$2.runNpmInstall)(entrypointFsDirname, [], spawnOpts, meta, config.projectSettings?.createdAt);
54965
+ else await (0, import_dist$2.runNpmInstall)(entrypointFsDirname, [], { env: spawnEnv }, meta, config.projectSettings?.createdAt);
54986
54966
  return {
54987
54967
  entrypointFsDirname,
54988
54968
  nodeVersion,
54989
- spawnOpts
54969
+ spawnEnv
54990
54970
  };
54991
54971
  }
54992
54972
  async function maybeExecBuildCommand(args, options) {
@@ -54996,119 +54976,20 @@ async function maybeExecBuildCommand(args, options) {
54996
54976
  base: args.repoRootPath || args.workPath,
54997
54977
  start: args.workPath
54998
54978
  }).join(delimiter);
54999
- const env = {
55000
- ...options.spawnOpts.env,
55001
- PATH: `${nodeBinPath}${delimiter}${options.spawnOpts.env?.PATH || process.env.PATH}`
55002
- };
55003
54979
  return (0, import_dist$2.execCommand)(projectBuildCommand, {
55004
- ...options.spawnOpts,
55005
- env,
54980
+ env: {
54981
+ ...options.spawnEnv,
54982
+ PATH: `${nodeBinPath}${delimiter}${options.spawnEnv?.PATH || process.env.PATH}`
54983
+ },
55006
54984
  cwd: args.workPath
55007
54985
  });
55008
54986
  }
55009
- return (0, import_dist$2.runPackageJsonScript)(options.entrypointFsDirname, ["build"], options.spawnOpts, args.config.projectSettings?.createdAt);
54987
+ return (0, import_dist$2.runPackageJsonScript)(options.entrypointFsDirname, ["build"], options.spawnEnv, args.config.projectSettings?.createdAt);
55010
54988
  }
55011
54989
 
55012
- //#endregion
55013
- //#region src/introspection/index.ts
55014
- const require$1 = createRequire$1(import.meta.url);
55015
- const introspectApp = async (args, rolldownResult) => {
55016
- const cjsLoaderPath = fileURLToPath(new URL("loaders/cjs.cjs", import.meta.url));
55017
- const esmLoaderPath = new URL("loaders/esm.js", import.meta.url).href;
55018
- const handlerPath = join(rolldownResult.dir, rolldownResult.handler);
55019
- let introspectionResult = {
55020
- frameworkSlug: "",
55021
- routes: []
55022
- };
55023
- await new Promise((resolvePromise) => {
55024
- try {
55025
- const child = spawn("node", [
55026
- "-r",
55027
- cjsLoaderPath,
55028
- "--import",
55029
- esmLoaderPath,
55030
- handlerPath
55031
- ], {
55032
- stdio: [
55033
- "pipe",
55034
- "pipe",
55035
- "pipe"
55036
- ],
55037
- cwd: rolldownResult.dir,
55038
- env: {
55039
- ...process.env,
55040
- ...args.meta?.env || {},
55041
- ...args.meta?.buildEnv || {}
55042
- }
55043
- });
55044
- child.stdout?.on("data", (data) => {
55045
- try {
55046
- const introspection = JSON.parse(data.toString());
55047
- introspectionResult = z.object({
55048
- frameworkSlug: z.string(),
55049
- routes: z.array(z.object({
55050
- src: z.string(),
55051
- dest: z.string(),
55052
- methods: z.array(z.string())
55053
- }))
55054
- }).parse(introspection);
55055
- } catch (error) {}
55056
- });
55057
- const timeout = setTimeout(() => {
55058
- child.kill("SIGTERM");
55059
- }, 2e3);
55060
- const timeout2 = setTimeout(() => {
55061
- child.kill("SIGKILL");
55062
- }, 3e3);
55063
- child.on("error", (err) => {
55064
- clearTimeout(timeout);
55065
- clearTimeout(timeout2);
55066
- console.log(`Loader error: ${err.message}`);
55067
- resolvePromise(void 0);
55068
- });
55069
- child.on("close", () => {
55070
- clearTimeout(timeout);
55071
- clearTimeout(timeout2);
55072
- resolvePromise(void 0);
55073
- });
55074
- } catch (error) {
55075
- resolvePromise(void 0);
55076
- }
55077
- });
55078
- const routes = [
55079
- { handle: "filesystem" },
55080
- ...introspectionResult.routes,
55081
- {
55082
- src: "/(.*)",
55083
- dest: "/"
55084
- }
55085
- ];
55086
- let version$1;
55087
- if (introspectionResult.frameworkSlug) {
55088
- const frameworkLibPath = require$1.resolve(`${introspectionResult.frameworkSlug}`, { paths: [rolldownResult.dir] });
55089
- const findNearestPackageJson = (dir) => {
55090
- const packageJsonPath = join(dir, "package.json");
55091
- if (existsSync(packageJsonPath)) return packageJsonPath;
55092
- const parentDir = dirname(dir);
55093
- if (parentDir === dir) return;
55094
- return findNearestPackageJson(parentDir);
55095
- };
55096
- const nearestPackageJsonPath = findNearestPackageJson(frameworkLibPath);
55097
- if (nearestPackageJsonPath) version$1 = require$1(nearestPackageJsonPath).version;
55098
- }
55099
- return {
55100
- routes,
55101
- files: rolldownResult.files,
55102
- framework: {
55103
- slug: introspectionResult.frameworkSlug,
55104
- version: version$1
55105
- }
55106
- };
55107
- };
55108
-
55109
54990
  //#endregion
55110
54991
  //#region src/node-file-trace.ts
55111
- var import_dist$1 = /* @__PURE__ */ __toESM$1(require_dist$1(), 1);
54992
+ var import_dist$1 = require_dist$1();
55112
54993
  const nodeFileTrace$1 = async (args, output) => {
55113
54994
  const { dir: outputDir, handler } = output;
55114
54995
  const entry = join(outputDir, handler);
@@ -55139,7 +55020,7 @@ const nodeFileTrace$1 = async (args, output) => {
55139
55020
 
55140
55021
  //#endregion
55141
55022
  //#region src/build.ts
55142
- const defaultOutputDirectory = join(".vercel", "node");
55023
+ const defaultOutputDirectory = join$1(".vercel", "node");
55143
55024
  const doBuild = async (args, downloadResult) => {
55144
55025
  const buildCommandResult = await maybeExecBuildCommand(args, downloadResult);
55145
55026
  const outputSetting = args.config.outputDirectory;
@@ -55148,8 +55029,8 @@ const doBuild = async (args, downloadResult) => {
55148
55029
  const isCervelCommand = buildCommand?.trim().startsWith("cervel");
55149
55030
  if (!outputSetting) {
55150
55031
  if (isCervelCommand) {
55151
- const cervelOutputDir = join(args.workPath, "dist");
55152
- if (existsSync(join(cervelOutputDir, ".cervel.json"))) {
55032
+ const cervelOutputDir = join$1(args.workPath, "dist");
55033
+ if (existsSync$1(join$1(cervelOutputDir, ".cervel.json"))) {
55153
55034
  const { handler: handler$2 } = await getBuildSummary(cervelOutputDir);
55154
55035
  return {
55155
55036
  dir: cervelOutputDir,
@@ -55159,10 +55040,10 @@ const doBuild = async (args, downloadResult) => {
55159
55040
  }
55160
55041
  throw new Error(`Build command "${buildCommand}" completed, but no output was found at ${cervelOutputDir}. Make sure your cervel command is configured correctly.`);
55161
55042
  }
55162
- const distDir = join(args.workPath, "dist");
55163
- if (existsSync(distDir)) {
55164
- const cervelJsonPath$1 = join(distDir, ".cervel.json");
55165
- 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)) {
55166
55047
  const { handler: handler$3 } = await getBuildSummary(distDir);
55167
55048
  return {
55168
55049
  dir: distDir,
@@ -55195,7 +55076,7 @@ const doBuild = async (args, downloadResult) => {
55195
55076
  tsPromise
55196
55077
  };
55197
55078
  }
55198
- const outputDir = join(args.workPath, outputSetting);
55079
+ const outputDir = join$1(args.workPath, outputSetting);
55199
55080
  if (!buildCommandResult) {
55200
55081
  const buildResult = await build$1({
55201
55082
  cwd: args.workPath,
@@ -55209,8 +55090,8 @@ const doBuild = async (args, downloadResult) => {
55209
55090
  tsPromise
55210
55091
  };
55211
55092
  }
55212
- const cervelJsonPath = join(outputDir, ".cervel.json");
55213
- if (existsSync(cervelJsonPath)) {
55093
+ const cervelJsonPath = join$1(outputDir, ".cervel.json");
55094
+ if (existsSync$1(cervelJsonPath)) {
55214
55095
  const { handler: handler$1 } = await getBuildSummary(outputDir);
55215
55096
  return {
55216
55097
  dir: outputDir,
@@ -55234,17 +55115,20 @@ const doBuild = async (args, downloadResult) => {
55234
55115
 
55235
55116
  //#endregion
55236
55117
  //#region src/index.ts
55237
- var import_dist = /* @__PURE__ */ __toESM$1(require_dist$1(), 1);
55118
+ var import_dist = require_dist$1();
55238
55119
  const version = 2;
55239
55120
  const build = async (args) => {
55240
55121
  const downloadResult = await downloadInstallAndBundle(args);
55241
55122
  const outputConfig = await doBuild(args, downloadResult);
55242
55123
  const { files } = await nodeFileTrace$1(args, outputConfig);
55243
- const { routes, framework } = await introspectApp(args, {
55124
+ const { routes, framework } = await introspectApp({
55244
55125
  ...outputConfig,
55245
- files
55126
+ env: {
55127
+ ...args.meta?.env ?? {},
55128
+ ...args.meta?.buildEnv ?? {}
55129
+ }
55246
55130
  });
55247
- const handler = relative(args.repoRootPath, join(outputConfig.dir, outputConfig.handler));
55131
+ const handler = relative$1(args.repoRootPath, join$1(outputConfig.dir, outputConfig.handler));
55248
55132
  const lambda = new import_dist.NodejsLambda({
55249
55133
  runtime: downloadResult.nodeVersion.runtime,
55250
55134
  handler,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/backends",
3
- "version": "0.0.4",
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,36 +17,22 @@
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",
49
32
  "@types/fs-extra": "11",
50
33
  "@types/jest": "27.5.1",
51
34
  "@types/node": "22",
52
- "@vercel/build-utils": "12.2.2",
35
+ "@vercel/build-utils": "13.0.0",
53
36
  "execa": "3.2.0",
54
37
  "hono": "4.10.1",
55
38
  "jest-junit": "16.0.0",
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,141 +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
- 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
@@ -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