@vercel/hono 0.0.3 → 0.0.5

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