@vercel/hono 0.0.4 → 0.0.6

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 +60 -27
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -21,45 +21,30 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
23
  build: () => build,
24
+ findEntrypoint: () => findEntrypoint,
25
+ shim: () => shim,
26
+ shouldServe: () => shouldServe,
27
+ startDevServer: () => startDevServer,
24
28
  version: () => version
25
29
  });
26
30
  module.exports = __toCommonJS(src_exports);
27
31
 
28
32
  // src/build.ts
29
33
  var import_node = require("@vercel/node");
30
- var build = async ({
31
- files,
32
- workPath,
33
- config,
34
- meta = {}
35
- }) => {
36
- const validEntrypoints = [
37
- "index.ts",
38
- "index.js",
39
- "index.mjs",
40
- "index.cjs",
41
- "src/index.ts",
42
- "src/index.js",
43
- "src/index.mjs",
44
- "src/index.cjs"
45
- ];
46
- const entrypoint = validEntrypoints.find((path) => files[path] !== void 0);
47
- if (!entrypoint) {
48
- throw new Error("No valid entrypoint found");
49
- }
34
+ var build = async (args) => {
35
+ const entrypoint = findEntrypoint(args.files);
50
36
  return (0, import_node.build)({
37
+ ...args,
51
38
  entrypoint,
52
- files,
53
- shim,
54
- workPath,
55
39
  useWebApi: true,
56
- config,
57
- meta
40
+ shim
58
41
  });
59
42
  };
60
- var shim = (handler) => `
61
- import app from "./${handler}";
43
+ var shim = (handler, relativePathToHandler = ".") => `
44
+ // @ts-ignore
45
+ import app from "${relativePathToHandler}/${handler}";
62
46
 
47
+ // @ts-ignore
63
48
  const handle = async (request) => {
64
49
  return app.fetch(request);
65
50
  };
@@ -71,11 +56,59 @@ export const DELETE = handle;
71
56
  export const PATCH = handle;
72
57
  export const OPTIONS = handle;
73
58
  export const HEAD = handle;`;
59
+ var findEntrypoint = (files) => {
60
+ const validEntrypoints = [
61
+ "server.ts",
62
+ "server.js",
63
+ "index.ts",
64
+ "index.js",
65
+ "index.mjs",
66
+ "index.cjs",
67
+ "src/index.ts",
68
+ "src/index.js",
69
+ "src/index.mjs",
70
+ "src/index.cjs"
71
+ ];
72
+ const entrypoint = validEntrypoints.find((path) => files[path] !== void 0);
73
+ if (!entrypoint) {
74
+ throw new Error("No valid entrypoint found");
75
+ }
76
+ return entrypoint;
77
+ };
74
78
 
75
79
  // src/index.ts
80
+ var import_node2 = require("@vercel/node");
81
+ var import_promises = require("fs/promises");
82
+ var import_path = require("path");
76
83
  var version = 3;
84
+ var shouldServe = async (opts) => {
85
+ const requestPath = opts.requestPath.replace(/\/$/, "");
86
+ if (requestPath.startsWith("api")) {
87
+ return false;
88
+ }
89
+ return true;
90
+ };
91
+ var startDevServer = async (opts) => {
92
+ const entrypoint = findEntrypoint(opts.files);
93
+ const entrypointExtension = entrypoint.split(".").pop();
94
+ const shimString = shim(entrypoint, "../..");
95
+ const shimEntrypoint = `.vercel/dev/shim.${entrypointExtension}`;
96
+ const shimEntrypointPath = (0, import_path.join)(opts.workPath, shimEntrypoint);
97
+ const shimEntrypointDir = (0, import_path.dirname)(shimEntrypointPath);
98
+ await (0, import_promises.rm)(shimEntrypointDir, { force: true, recursive: true });
99
+ await (0, import_promises.mkdir)(shimEntrypointDir, { recursive: true });
100
+ await (0, import_promises.writeFile)(shimEntrypointPath, shimString);
101
+ return (0, import_node2.startDevServer)({
102
+ ...opts,
103
+ entrypoint: shimEntrypoint
104
+ });
105
+ };
77
106
  // Annotate the CommonJS export names for ESM import in node:
78
107
  0 && (module.exports = {
79
108
  build,
109
+ findEntrypoint,
110
+ shim,
111
+ shouldServe,
112
+ startDevServer,
80
113
  version
81
114
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/hono",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index.js",
6
6
  "homepage": "https://vercel.com/docs",
@@ -15,7 +15,7 @@
15
15
  ],
16
16
  "dependencies": {
17
17
  "@vercel/static-config": "3.1.1",
18
- "@vercel/node": "5.3.7",
18
+ "@vercel/node": "5.3.8",
19
19
  "ts-morph": "12.0.0"
20
20
  },
21
21
  "devDependencies": {