@vercel/express 0.0.15 → 0.0.17

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.
Files changed (2) hide show
  1. package/dist/index.js +56 -15
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -33,6 +33,7 @@ __export(src_exports, {
33
33
  build: () => build,
34
34
  entrypointCallback: () => entrypointCallback,
35
35
  findEntrypoint: () => findEntrypoint,
36
+ require_: () => require_,
36
37
  shouldServe: () => shouldServe,
37
38
  startDevServer: () => startDevServer,
38
39
  version: () => version
@@ -42,8 +43,10 @@ module.exports = __toCommonJS(src_exports);
42
43
  // src/build.ts
43
44
  var import_build_utils = require("@vercel/build-utils");
44
45
  var import_node = require("@vercel/node");
46
+ var import_module = require("module");
45
47
  var import_path = require("path");
46
48
  var import_fs = __toESM(require("fs"));
49
+ var frameworkName = "express";
47
50
  var REGEX = /(?:from|require|import)\s*(?:\(\s*)?["']express["']\s*(?:\))?/g;
48
51
  var validFilenames = [
49
52
  "app",
@@ -53,6 +56,7 @@ var validFilenames = [
53
56
  "src/index",
54
57
  "src/server"
55
58
  ];
59
+ var require_ = (0, import_module.createRequire)(__filename);
56
60
  var validExtensions = ["js", "cjs", "mjs", "ts", "cts", "mts"];
57
61
  var entrypointsForMessage = validFilenames.map((filename) => `- ${filename}.{${validExtensions.join(",")}}`).join("\n");
58
62
  var build = async (args) => {
@@ -76,6 +80,21 @@ var build = async (args) => {
76
80
  return entrypointCallback(args);
77
81
  }
78
82
  });
83
+ let version2 = void 0;
84
+ try {
85
+ const resolved = require_.resolve(`${frameworkName}/package.json`, {
86
+ paths: [args.workPath]
87
+ });
88
+ const expressVersion = require_(resolved).version;
89
+ if (expressVersion) {
90
+ version2 = expressVersion;
91
+ }
92
+ } catch (e) {
93
+ }
94
+ res.output.framework = {
95
+ slug: frameworkName,
96
+ version: version2
97
+ };
79
98
  return res;
80
99
  };
81
100
  var entrypointCallback = async (args) => {
@@ -86,19 +105,22 @@ var entrypointCallback = async (args) => {
86
105
  ""
87
106
  );
88
107
  if (dir) {
89
- const entrypointFromOutputDir = findEntrypoint(
90
- await (0, import_build_utils.glob)(entrypointGlob, (0, import_path.join)(args.workPath, dir))
91
- );
108
+ const { entrypoint: entrypointFromOutputDir, entrypointsNotMatchingRegex: entrypointsNotMatchingRegex2 } = findEntrypoint(await (0, import_build_utils.glob)(entrypointGlob, (0, import_path.join)(args.workPath, dir)));
92
109
  if (entrypointFromOutputDir) {
93
110
  return (0, import_path.join)(dir, entrypointFromOutputDir);
94
111
  }
112
+ if (entrypointsNotMatchingRegex2.length > 0) {
113
+ throw new Error(
114
+ `No entrypoint found which imports express. Found possible ${pluralize("entrypoint", entrypointsNotMatchingRegex2.length)}: ${entrypointsNotMatchingRegex2.join(", ")}`
115
+ );
116
+ }
95
117
  throw new Error(
96
118
  `No entrypoint found in output directory: "${dir}". Searched for:
97
119
  ${entrypointsForMessage}`
98
120
  );
99
121
  }
100
122
  const files = await (0, import_build_utils.glob)(entrypointGlob, args.workPath);
101
- const entrypointFromRoot = findEntrypoint(files);
123
+ const { entrypoint: entrypointFromRoot, entrypointsNotMatchingRegex } = findEntrypoint(files);
102
124
  if (entrypointFromRoot) {
103
125
  return entrypointFromRoot;
104
126
  }
@@ -113,30 +135,48 @@ ${entrypointsForMessage}`
113
135
  }
114
136
  }
115
137
  }
138
+ if (entrypointsNotMatchingRegex.length > 0) {
139
+ throw new Error(
140
+ `No entrypoint found which imports express. Found possible ${pluralize("entrypoint", entrypointsNotMatchingRegex.length)}: ${entrypointsNotMatchingRegex.join(", ")}`
141
+ );
142
+ }
116
143
  throw new Error(
117
- `No entrypoint found. Searched for:
144
+ `No entrypoint found. Searched for:
118
145
  ${entrypointsForMessage}`
119
146
  );
120
147
  };
148
+ function pluralize(word, count) {
149
+ return count === 1 ? word : `${word}s`;
150
+ }
121
151
  var findEntrypoint = (files) => {
122
- const validEntrypoints = validFilenames.flatMap(
152
+ const allEntrypoints = validFilenames.flatMap(
123
153
  (filename) => validExtensions.map((extension) => `${filename}.${extension}`)
124
154
  );
125
- const entrypoints = validEntrypoints.filter((entrypoint2) => {
126
- const matches = files[entrypoint2] !== void 0;
127
- if (matches) {
155
+ const possibleEntrypointsInFiles = allEntrypoints.filter((entrypoint2) => {
156
+ return files[entrypoint2] !== void 0;
157
+ });
158
+ const entrypointsMatchingRegex = possibleEntrypointsInFiles.filter(
159
+ (entrypoint2) => {
128
160
  const file = files[entrypoint2];
129
161
  return checkMatchesRegex(file);
130
162
  }
131
- return false;
132
- });
133
- const entrypoint = entrypoints[0];
134
- if (entrypoints.length > 1) {
163
+ );
164
+ const entrypointsNotMatchingRegex = possibleEntrypointsInFiles.filter(
165
+ (entrypoint2) => {
166
+ const file = files[entrypoint2];
167
+ return !checkMatchesRegex(file);
168
+ }
169
+ );
170
+ const entrypoint = entrypointsMatchingRegex[0];
171
+ if (entrypointsMatchingRegex.length > 1) {
135
172
  console.warn(
136
- `Multiple entrypoints found: ${entrypoints.join(", ")}. Using ${entrypoint}.`
173
+ `Multiple entrypoints found: ${entrypointsMatchingRegex.join(", ")}. Using ${entrypoint}.`
137
174
  );
138
175
  }
139
- return entrypoint;
176
+ return {
177
+ entrypoint,
178
+ entrypointsNotMatchingRegex
179
+ };
140
180
  };
141
181
  var checkMatchesRegex = (file) => {
142
182
  const content = import_fs.default.readFileSync(file.fsPath, "utf-8");
@@ -186,6 +226,7 @@ var startDevServer = async (opts) => {
186
226
  build,
187
227
  entrypointCallback,
188
228
  findEntrypoint,
229
+ require_,
189
230
  shouldServe,
190
231
  startDevServer,
191
232
  version
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/express",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index.js",
6
6
  "homepage": "https://vercel.com/docs",
@@ -18,7 +18,7 @@
18
18
  ],
19
19
  "dependencies": {
20
20
  "@vercel/static-config": "3.1.2",
21
- "@vercel/node": "5.3.22",
21
+ "@vercel/node": "5.3.23",
22
22
  "ts-morph": "12.0.0"
23
23
  },
24
24
  "devDependencies": {