@vercel/express 0.0.12 → 0.0.13
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 +95 -36
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
build: () => build,
|
|
34
|
+
entrypointCallback: () => entrypointCallback,
|
|
34
35
|
findEntrypoint: () => findEntrypoint,
|
|
35
36
|
shouldServe: () => shouldServe,
|
|
36
37
|
startDevServer: () => startDevServer,
|
|
@@ -39,52 +40,93 @@ __export(src_exports, {
|
|
|
39
40
|
module.exports = __toCommonJS(src_exports);
|
|
40
41
|
|
|
41
42
|
// src/build.ts
|
|
43
|
+
var import_build_utils = require("@vercel/build-utils");
|
|
42
44
|
var import_node = require("@vercel/node");
|
|
43
45
|
var import_path = require("path");
|
|
44
46
|
var import_fs = __toESM(require("fs"));
|
|
45
47
|
var REGEX = /(?:from|require|import)\s*(?:\(\s*)?["']express["']\s*(?:\))?/g;
|
|
48
|
+
var validFilenames = [
|
|
49
|
+
"app",
|
|
50
|
+
"index",
|
|
51
|
+
"server",
|
|
52
|
+
"src/app",
|
|
53
|
+
"src/index",
|
|
54
|
+
"src/server"
|
|
55
|
+
];
|
|
56
|
+
var validExtensions = ["js", "cjs", "mjs", "ts", "cts", "mts"];
|
|
57
|
+
var entrypointsForMessage = validFilenames.map((filename) => `- ${filename}.{${validExtensions.join(",")}}`).join("\n");
|
|
46
58
|
var build = async (args) => {
|
|
47
|
-
const entrypoint = findEntrypoint(args.files);
|
|
48
59
|
process.env.EXPERIMENTAL_NODE_TYPESCRIPT_ERRORS = "1";
|
|
49
|
-
|
|
60
|
+
const includeFiles = ["views/**/*"];
|
|
61
|
+
const includeFilesFromConfig = args.config.includeFiles;
|
|
62
|
+
if (includeFilesFromConfig) {
|
|
63
|
+
includeFiles.push(...includeFilesFromConfig);
|
|
64
|
+
}
|
|
65
|
+
const res = await (0, import_node.build)({
|
|
50
66
|
...args,
|
|
51
|
-
|
|
67
|
+
config: {
|
|
68
|
+
...args.config,
|
|
69
|
+
includeFiles
|
|
70
|
+
},
|
|
71
|
+
// this is package.json, but we'll replace it with the return value of the entrypointCallback
|
|
72
|
+
// after install and build scripts have had a chance to run
|
|
73
|
+
entrypoint: "package.json",
|
|
52
74
|
considerBuildCommand: true,
|
|
53
|
-
entrypointCallback: (
|
|
54
|
-
return
|
|
75
|
+
entrypointCallback: async () => {
|
|
76
|
+
return entrypointCallback(args);
|
|
55
77
|
}
|
|
56
78
|
});
|
|
79
|
+
return res;
|
|
80
|
+
};
|
|
81
|
+
var entrypointCallback = async (args) => {
|
|
82
|
+
const mainPackageEntrypoint = findMainPackageEntrypoint(args.files);
|
|
83
|
+
const entrypointGlob = `{${validFilenames.map((entrypoint) => `${entrypoint}`).join(",")}}.{${validExtensions.join(",")}}`;
|
|
84
|
+
const dir = args.config.projectSettings?.outputDirectory?.replace(
|
|
85
|
+
/^\/+|\/+$/g,
|
|
86
|
+
""
|
|
87
|
+
);
|
|
88
|
+
if (dir) {
|
|
89
|
+
const entrypointFromOutputDir = findEntrypoint(
|
|
90
|
+
await (0, import_build_utils.glob)(entrypointGlob, (0, import_path.join)(args.workPath, dir))
|
|
91
|
+
);
|
|
92
|
+
if (entrypointFromOutputDir) {
|
|
93
|
+
return (0, import_path.join)(dir, entrypointFromOutputDir);
|
|
94
|
+
}
|
|
95
|
+
throw new Error(
|
|
96
|
+
`No entrypoint found in output directory: "${dir}". Searched for:
|
|
97
|
+
${entrypointsForMessage}`
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
const files = await (0, import_build_utils.glob)(entrypointGlob, args.workPath);
|
|
101
|
+
const entrypointFromRoot = findEntrypoint(files);
|
|
102
|
+
if (entrypointFromRoot) {
|
|
103
|
+
return entrypointFromRoot;
|
|
104
|
+
}
|
|
105
|
+
if (mainPackageEntrypoint) {
|
|
106
|
+
const entrypointFromPackageJson = await (0, import_build_utils.glob)(
|
|
107
|
+
mainPackageEntrypoint,
|
|
108
|
+
args.workPath
|
|
109
|
+
);
|
|
110
|
+
if (entrypointFromPackageJson[mainPackageEntrypoint]) {
|
|
111
|
+
if (checkMatchesRegex(entrypointFromPackageJson[mainPackageEntrypoint])) {
|
|
112
|
+
return mainPackageEntrypoint;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
throw new Error(
|
|
117
|
+
`No entrypoint found. Searched for:
|
|
118
|
+
${entrypointsForMessage}`
|
|
119
|
+
);
|
|
57
120
|
};
|
|
58
121
|
var findEntrypoint = (files) => {
|
|
59
|
-
const validFilenames = [
|
|
60
|
-
["app"],
|
|
61
|
-
["index"],
|
|
62
|
-
["server"],
|
|
63
|
-
["src", "app"],
|
|
64
|
-
["src", "index"],
|
|
65
|
-
["src", "server"]
|
|
66
|
-
];
|
|
67
|
-
const validExtensions = ["js", "cjs", "mjs", "ts", "cts", "mts"];
|
|
68
122
|
const validEntrypoints = validFilenames.flatMap(
|
|
69
|
-
(filename) => validExtensions.map((extension) => `${filename
|
|
123
|
+
(filename) => validExtensions.map((extension) => `${filename}.${extension}`)
|
|
70
124
|
);
|
|
71
125
|
const entrypoints = validEntrypoints.filter((entrypoint2) => {
|
|
72
126
|
const matches = files[entrypoint2] !== void 0;
|
|
73
127
|
if (matches) {
|
|
74
128
|
const file = files[entrypoint2];
|
|
75
|
-
|
|
76
|
-
const content = file.data.toString();
|
|
77
|
-
const matchesContent = content.match(REGEX);
|
|
78
|
-
return matchesContent !== null;
|
|
79
|
-
}
|
|
80
|
-
if (file.type === "FileFsRef") {
|
|
81
|
-
const content = import_fs.default.readFileSync(file.fsPath, "utf-8");
|
|
82
|
-
const matchesContent = content.match(REGEX);
|
|
83
|
-
return matchesContent !== null;
|
|
84
|
-
}
|
|
85
|
-
if (file.type === "FileRef") {
|
|
86
|
-
return true;
|
|
87
|
-
}
|
|
129
|
+
return checkMatchesRegex(file);
|
|
88
130
|
}
|
|
89
131
|
return false;
|
|
90
132
|
});
|
|
@@ -94,15 +136,31 @@ var findEntrypoint = (files) => {
|
|
|
94
136
|
`Multiple entrypoints found: ${entrypoints.join(", ")}. Using ${entrypoint}.`
|
|
95
137
|
);
|
|
96
138
|
}
|
|
97
|
-
if (!entrypoint) {
|
|
98
|
-
const entrypointsForMessage = validFilenames.map((filename) => `- ${filename.join(import_path.sep)}.{${validExtensions.join(",")}}`).join("\n");
|
|
99
|
-
throw new Error(
|
|
100
|
-
`No valid entrypoint found. Valid entrypoints are:
|
|
101
|
-
${entrypointsForMessage}`
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
139
|
return entrypoint;
|
|
105
140
|
};
|
|
141
|
+
var checkMatchesRegex = (file) => {
|
|
142
|
+
const content = import_fs.default.readFileSync(file.fsPath, "utf-8");
|
|
143
|
+
const matchesContent = content.match(REGEX);
|
|
144
|
+
return matchesContent !== null;
|
|
145
|
+
};
|
|
146
|
+
var findMainPackageEntrypoint = (files) => {
|
|
147
|
+
const packageJson = files["package.json"];
|
|
148
|
+
if (packageJson) {
|
|
149
|
+
if (packageJson.type === "FileFsRef") {
|
|
150
|
+
const packageJsonContent = import_fs.default.readFileSync(packageJson.fsPath, "utf-8");
|
|
151
|
+
let packageJsonJson;
|
|
152
|
+
try {
|
|
153
|
+
packageJsonJson = JSON.parse(packageJsonContent);
|
|
154
|
+
} catch (_e) {
|
|
155
|
+
packageJsonJson = {};
|
|
156
|
+
}
|
|
157
|
+
if ("main" in packageJsonJson && typeof packageJsonJson.main === "string") {
|
|
158
|
+
return packageJsonJson.main;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return null;
|
|
163
|
+
};
|
|
106
164
|
|
|
107
165
|
// src/index.ts
|
|
108
166
|
var import_node2 = require("@vercel/node");
|
|
@@ -115,7 +173,7 @@ var shouldServe = async (opts) => {
|
|
|
115
173
|
return true;
|
|
116
174
|
};
|
|
117
175
|
var startDevServer = async (opts) => {
|
|
118
|
-
const entrypoint =
|
|
176
|
+
const entrypoint = await entrypointCallback(opts);
|
|
119
177
|
process.env.EXPERIMENTAL_NODE_TYPESCRIPT_ERRORS = "1";
|
|
120
178
|
return (0, import_node2.startDevServer)({
|
|
121
179
|
...opts,
|
|
@@ -125,6 +183,7 @@ var startDevServer = async (opts) => {
|
|
|
125
183
|
// Annotate the CommonJS export names for ESM import in node:
|
|
126
184
|
0 && (module.exports = {
|
|
127
185
|
build,
|
|
186
|
+
entrypointCallback,
|
|
128
187
|
findEntrypoint,
|
|
129
188
|
shouldServe,
|
|
130
189
|
startDevServer,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/express",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"homepage": "https://vercel.com/docs",
|
|
@@ -18,13 +18,13 @@
|
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@vercel/static-config": "3.1.2",
|
|
21
|
-
"@vercel/node": "5.3.
|
|
21
|
+
"@vercel/node": "5.3.20",
|
|
22
22
|
"ts-morph": "12.0.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/jest": "27.5.1",
|
|
26
26
|
"@types/node": "14.18.33",
|
|
27
|
-
"@vercel/build-utils": "12.
|
|
27
|
+
"@vercel/build-utils": "12.1.0",
|
|
28
28
|
"execa": "3.2.0",
|
|
29
29
|
"fs-extra": "11.1.0",
|
|
30
30
|
"jest-junit": "16.0.0",
|