honox 0.1.21 → 0.1.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.
@@ -49,6 +49,7 @@ const createApp = (options) => {
49
49
  paths.sort((a, b) => a.split("/").length - b.split("/").length);
50
50
  return paths;
51
51
  };
52
+ const errorHandlerMap = {};
52
53
  for (const map of routesMap) {
53
54
  for (const [dir, content] of Object.entries(map)) {
54
55
  const subApp = new Hono();
@@ -105,7 +106,16 @@ const createApp = (options) => {
105
106
  });
106
107
  }
107
108
  }
108
- applyError(subApp, dir, errorMap);
109
+ const errorHandler = getErrorHandler(dir, errorMap);
110
+ if (errorHandler) {
111
+ errorHandlerMap[dir] = errorHandler;
112
+ }
113
+ for (const [path, errorHandler2] of Object.entries(errorHandlerMap)) {
114
+ const regExp = new RegExp(`^${path}`);
115
+ if (regExp.test(dir) && errorHandler2) {
116
+ subApp.onError(errorHandler2);
117
+ }
118
+ }
109
119
  let rootPath = getRootPath(dir);
110
120
  if (trailingSlash) {
111
121
  rootPath = /\/$/.test(rootPath) ? rootPath : rootPath + "/";
@@ -143,20 +153,23 @@ function applyNotFound(app, dir, map) {
143
153
  }
144
154
  }
145
155
  }
146
- function applyError(app, dir, map) {
156
+ function getErrorHandler(dir, map) {
147
157
  for (const [mapDir, content] of Object.entries(map)) {
148
158
  if (dir === mapDir) {
149
159
  const errorFile = content[ERROR_FILENAME];
150
160
  if (errorFile) {
151
- const errorHandler = errorFile.default;
152
- app.onError(async (error, c) => {
153
- const importingIslands = errorFile[IMPORTING_ISLANDS_ID];
154
- if (importingIslands) {
155
- c.set(IMPORTING_ISLANDS_ID, importingIslands);
156
- }
157
- c.status(500);
158
- return errorHandler(error, c);
159
- });
161
+ const matchedErrorHandler = errorFile.default;
162
+ if (matchedErrorHandler) {
163
+ const errorHandler = async (error, c) => {
164
+ const importingIslands = errorFile[IMPORTING_ISLANDS_ID];
165
+ if (importingIslands) {
166
+ c.set(IMPORTING_ISLANDS_ID, importingIslands);
167
+ }
168
+ c.status(500);
169
+ return matchedErrorHandler(error, c);
170
+ };
171
+ return errorHandler;
172
+ }
160
173
  }
161
174
  }
162
175
  }
@@ -19,8 +19,8 @@ const createApp = (options) => {
19
19
  }),
20
20
  ROUTES: options?.ROUTES ?? import.meta.glob(
21
21
  [
22
- "/app/routes/**/!(_*|*.test|*.spec).(ts|tsx|md|mdx)",
23
- "/app/routes/.well-known/!(_*|*.test|*.spec).(ts|tsx|md|mdx)"
22
+ "/app/routes/**/!(_*|$*|*.test|*.spec).(ts|tsx|md|mdx)",
23
+ "/app/routes/.well-known/!(_*|$*|*.test|*.spec).(ts|tsx|md|mdx)"
24
24
  ],
25
25
  {
26
26
  eager: true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "honox",
3
- "version": "0.1.21",
3
+ "version": "0.1.22",
4
4
  "main": "dist/index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -112,7 +112,7 @@
112
112
  "@babel/parser": "^7.23.6",
113
113
  "@babel/traverse": "^7.23.6",
114
114
  "@babel/types": "^7.23.6",
115
- "@hono/vite-dev-server": "^0.12.1",
115
+ "@hono/vite-dev-server": "^0.12.2",
116
116
  "jsonc-parser": "^3.2.1",
117
117
  "precinct": "^12.0.2"
118
118
  },