@vercel/hono 0.0.20 → 0.0.22
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 +84 -32
- 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,49 +40,83 @@ __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*)?["']hono["']\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
|
return (0, import_node.build)({
|
|
50
61
|
...args,
|
|
51
|
-
|
|
62
|
+
// this is package.json, but we'll replace it with the return value of the entrypointCallback
|
|
63
|
+
// after install and build scripts have had a chance to run
|
|
64
|
+
entrypoint: "package.json",
|
|
52
65
|
considerBuildCommand: true,
|
|
53
|
-
entrypointCallback: (
|
|
54
|
-
return
|
|
66
|
+
entrypointCallback: async () => {
|
|
67
|
+
return entrypointCallback(args);
|
|
55
68
|
}
|
|
56
69
|
});
|
|
57
70
|
};
|
|
71
|
+
var entrypointCallback = async (args) => {
|
|
72
|
+
const mainPackageEntrypoint = findMainPackageEntrypoint(args.files);
|
|
73
|
+
const entrypointGlob = `{${validFilenames.map((entrypoint) => `${entrypoint}`).join(",")}}.{${validExtensions.join(",")}}`;
|
|
74
|
+
const dir = args.config.projectSettings?.outputDirectory?.replace(
|
|
75
|
+
/^\/+|\/+$/g,
|
|
76
|
+
""
|
|
77
|
+
);
|
|
78
|
+
if (dir) {
|
|
79
|
+
const entrypointFromOutputDir = findEntrypoint(
|
|
80
|
+
await (0, import_build_utils.glob)(entrypointGlob, (0, import_path.join)(args.workPath, dir))
|
|
81
|
+
);
|
|
82
|
+
if (entrypointFromOutputDir) {
|
|
83
|
+
return (0, import_path.join)(dir, entrypointFromOutputDir);
|
|
84
|
+
}
|
|
85
|
+
throw new Error(
|
|
86
|
+
`No entrypoint found in output directory: "${dir}". Searched for:
|
|
87
|
+
${entrypointsForMessage}`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
const files = await (0, import_build_utils.glob)(entrypointGlob, args.workPath);
|
|
91
|
+
const entrypointFromRoot = findEntrypoint(files);
|
|
92
|
+
if (entrypointFromRoot) {
|
|
93
|
+
return entrypointFromRoot;
|
|
94
|
+
}
|
|
95
|
+
if (mainPackageEntrypoint) {
|
|
96
|
+
const entrypointFromPackageJson = await (0, import_build_utils.glob)(
|
|
97
|
+
mainPackageEntrypoint,
|
|
98
|
+
args.workPath
|
|
99
|
+
);
|
|
100
|
+
if (entrypointFromPackageJson[mainPackageEntrypoint]) {
|
|
101
|
+
if (checkMatchesRegex(entrypointFromPackageJson[mainPackageEntrypoint])) {
|
|
102
|
+
return mainPackageEntrypoint;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
throw new Error(
|
|
107
|
+
`No entrypoint found. Searched for:
|
|
108
|
+
${entrypointsForMessage}`
|
|
109
|
+
);
|
|
110
|
+
};
|
|
58
111
|
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
112
|
const validEntrypoints = validFilenames.flatMap(
|
|
69
|
-
(filename) => validExtensions.map((extension) => `${filename
|
|
113
|
+
(filename) => validExtensions.map((extension) => `${filename}.${extension}`)
|
|
70
114
|
);
|
|
71
115
|
const entrypoints = validEntrypoints.filter((entrypoint2) => {
|
|
72
116
|
const matches = files[entrypoint2] !== void 0;
|
|
73
117
|
if (matches) {
|
|
74
118
|
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
|
-
}
|
|
119
|
+
return checkMatchesRegex(file);
|
|
85
120
|
}
|
|
86
121
|
return false;
|
|
87
122
|
});
|
|
@@ -91,15 +126,31 @@ var findEntrypoint = (files) => {
|
|
|
91
126
|
`Multiple entrypoints found: ${entrypoints.join(", ")}. Using ${entrypoint}.`
|
|
92
127
|
);
|
|
93
128
|
}
|
|
94
|
-
if (!entrypoint) {
|
|
95
|
-
const entrypointsForMessage = validFilenames.map((filename) => `- ${filename.join(import_path.sep)}.{${validExtensions.join(",")}}`).join("\n");
|
|
96
|
-
throw new Error(
|
|
97
|
-
`No valid entrypoint found. Valid entrypoints are:
|
|
98
|
-
${entrypointsForMessage}`
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
129
|
return entrypoint;
|
|
102
130
|
};
|
|
131
|
+
var checkMatchesRegex = (file) => {
|
|
132
|
+
const content = import_fs.default.readFileSync(file.fsPath, "utf-8");
|
|
133
|
+
const matchesContent = content.match(REGEX);
|
|
134
|
+
return matchesContent !== null;
|
|
135
|
+
};
|
|
136
|
+
var findMainPackageEntrypoint = (files) => {
|
|
137
|
+
const packageJson = files["package.json"];
|
|
138
|
+
if (packageJson) {
|
|
139
|
+
if (packageJson.type === "FileFsRef") {
|
|
140
|
+
const packageJsonContent = import_fs.default.readFileSync(packageJson.fsPath, "utf-8");
|
|
141
|
+
let packageJsonJson;
|
|
142
|
+
try {
|
|
143
|
+
packageJsonJson = JSON.parse(packageJsonContent);
|
|
144
|
+
} catch (_e) {
|
|
145
|
+
packageJsonJson = {};
|
|
146
|
+
}
|
|
147
|
+
if ("main" in packageJsonJson && typeof packageJsonJson.main === "string") {
|
|
148
|
+
return packageJsonJson.main;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return null;
|
|
153
|
+
};
|
|
103
154
|
|
|
104
155
|
// src/index.ts
|
|
105
156
|
var import_node2 = require("@vercel/node");
|
|
@@ -112,7 +163,7 @@ var shouldServe = async (opts) => {
|
|
|
112
163
|
return true;
|
|
113
164
|
};
|
|
114
165
|
var startDevServer = async (opts) => {
|
|
115
|
-
const entrypoint =
|
|
166
|
+
const entrypoint = await entrypointCallback(opts);
|
|
116
167
|
process.env.EXPERIMENTAL_NODE_TYPESCRIPT_ERRORS = "1";
|
|
117
168
|
return (0, import_node2.startDevServer)({
|
|
118
169
|
...opts,
|
|
@@ -122,6 +173,7 @@ var startDevServer = async (opts) => {
|
|
|
122
173
|
// Annotate the CommonJS export names for ESM import in node:
|
|
123
174
|
0 && (module.exports = {
|
|
124
175
|
build,
|
|
176
|
+
entrypointCallback,
|
|
125
177
|
findEntrypoint,
|
|
126
178
|
shouldServe,
|
|
127
179
|
startDevServer,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/hono",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.22",
|
|
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.21",
|
|
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",
|