@vercel/hono 0.0.23 → 0.0.24

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 +67 -16
  2. 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 = "hono";
47
50
  var REGEX = /(?:from|require|import)\s*(?:\(\s*)?["']hono["']\s*(?:\))?/g;
48
51
  var validFilenames = [
49
52
  "app",
@@ -53,12 +56,22 @@ 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) => {
59
63
  process.env.EXPERIMENTAL_NODE_TYPESCRIPT_ERRORS = "1";
60
- return (0, import_node.build)({
64
+ const includeFiles = ["views/**/*"];
65
+ const includeFilesFromConfig = args.config.includeFiles;
66
+ if (includeFilesFromConfig) {
67
+ includeFiles.push(...includeFilesFromConfig);
68
+ }
69
+ const res = await (0, import_node.build)({
61
70
  ...args,
71
+ config: {
72
+ ...args.config,
73
+ includeFiles
74
+ },
62
75
  // this is package.json, but we'll replace it with the return value of the entrypointCallback
63
76
  // after install and build scripts have had a chance to run
64
77
  entrypoint: "package.json",
@@ -67,6 +80,22 @@ var build = async (args) => {
67
80
  return entrypointCallback(args);
68
81
  }
69
82
  });
83
+ let version2 = void 0;
84
+ try {
85
+ const resolved = require_.resolve(`${frameworkName}/package.json`, {
86
+ paths: [args.workPath]
87
+ });
88
+ const honoVersion = require_(resolved).version;
89
+ if (honoVersion) {
90
+ version2 = honoVersion;
91
+ }
92
+ } catch (e) {
93
+ }
94
+ res.output.framework = {
95
+ name: frameworkName,
96
+ version: version2
97
+ };
98
+ return res;
70
99
  };
71
100
  var entrypointCallback = async (args) => {
72
101
  const mainPackageEntrypoint = findMainPackageEntrypoint(args.files);
@@ -76,19 +105,22 @@ var entrypointCallback = async (args) => {
76
105
  ""
77
106
  );
78
107
  if (dir) {
79
- const entrypointFromOutputDir = findEntrypoint(
80
- await (0, import_build_utils.glob)(entrypointGlob, (0, import_path.join)(args.workPath, dir))
81
- );
108
+ const { entrypoint: entrypointFromOutputDir, entrypointsNotMatchingRegex: entrypointsNotMatchingRegex2 } = findEntrypoint(await (0, import_build_utils.glob)(entrypointGlob, (0, import_path.join)(args.workPath, dir)));
82
109
  if (entrypointFromOutputDir) {
83
110
  return (0, import_path.join)(dir, entrypointFromOutputDir);
84
111
  }
112
+ if (entrypointsNotMatchingRegex2.length > 0) {
113
+ throw new Error(
114
+ `No entrypoint found which imports hono. Found possible ${pluralize("entrypoint", entrypointsNotMatchingRegex2.length)}: ${entrypointsNotMatchingRegex2.join(", ")}`
115
+ );
116
+ }
85
117
  throw new Error(
86
118
  `No entrypoint found in output directory: "${dir}". Searched for:
87
119
  ${entrypointsForMessage}`
88
120
  );
89
121
  }
90
122
  const files = await (0, import_build_utils.glob)(entrypointGlob, args.workPath);
91
- const entrypointFromRoot = findEntrypoint(files);
123
+ const { entrypoint: entrypointFromRoot, entrypointsNotMatchingRegex } = findEntrypoint(files);
92
124
  if (entrypointFromRoot) {
93
125
  return entrypointFromRoot;
94
126
  }
@@ -103,30 +135,48 @@ ${entrypointsForMessage}`
103
135
  }
104
136
  }
105
137
  }
138
+ if (entrypointsNotMatchingRegex.length > 0) {
139
+ throw new Error(
140
+ `No entrypoint found which imports hono. Found possible ${pluralize("entrypoint", entrypointsNotMatchingRegex.length)}: ${entrypointsNotMatchingRegex.join(", ")}`
141
+ );
142
+ }
106
143
  throw new Error(
107
- `No entrypoint found. Searched for:
144
+ `No entrypoint found. Searched for:
108
145
  ${entrypointsForMessage}`
109
146
  );
110
147
  };
148
+ function pluralize(word, count) {
149
+ return count === 1 ? word : `${word}s`;
150
+ }
111
151
  var findEntrypoint = (files) => {
112
- const validEntrypoints = validFilenames.flatMap(
152
+ const allEntrypoints = validFilenames.flatMap(
113
153
  (filename) => validExtensions.map((extension) => `${filename}.${extension}`)
114
154
  );
115
- const entrypoints = validEntrypoints.filter((entrypoint2) => {
116
- const matches = files[entrypoint2] !== void 0;
117
- if (matches) {
155
+ const possibleEntrypointsInFiles = allEntrypoints.filter((entrypoint2) => {
156
+ return files[entrypoint2] !== void 0;
157
+ });
158
+ const entrypointsMatchingRegex = possibleEntrypointsInFiles.filter(
159
+ (entrypoint2) => {
118
160
  const file = files[entrypoint2];
119
161
  return checkMatchesRegex(file);
120
162
  }
121
- return false;
122
- });
123
- const entrypoint = entrypoints[0];
124
- 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) {
125
172
  console.warn(
126
- `Multiple entrypoints found: ${entrypoints.join(", ")}. Using ${entrypoint}.`
173
+ `Multiple entrypoints found: ${entrypointsMatchingRegex.join(", ")}. Using ${entrypoint}.`
127
174
  );
128
175
  }
129
- return entrypoint;
176
+ return {
177
+ entrypoint,
178
+ entrypointsNotMatchingRegex
179
+ };
130
180
  };
131
181
  var checkMatchesRegex = (file) => {
132
182
  const content = import_fs.default.readFileSync(file.fsPath, "utf-8");
@@ -175,6 +225,7 @@ var startDevServer = async (opts) => {
175
225
  build,
176
226
  entrypointCallback,
177
227
  findEntrypoint,
228
+ require_,
178
229
  shouldServe,
179
230
  startDevServer,
180
231
  version
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/hono",
3
- "version": "0.0.23",
3
+ "version": "0.0.24",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index.js",
6
6
  "homepage": "https://vercel.com/docs",