@vercel/express 0.0.15 → 0.0.16
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 +56 -15
- package/package.json +1 -1
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
|
|
152
|
+
const allEntrypoints = validFilenames.flatMap(
|
|
123
153
|
(filename) => validExtensions.map((extension) => `${filename}.${extension}`)
|
|
124
154
|
);
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
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
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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: ${
|
|
173
|
+
`Multiple entrypoints found: ${entrypointsMatchingRegex.join(", ")}. Using ${entrypoint}.`
|
|
137
174
|
);
|
|
138
175
|
}
|
|
139
|
-
return
|
|
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
|