honox 0.1.42 → 0.1.44
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/server/server.js +25 -8
- package/dist/server/utils/file.js +2 -2
- package/dist/vite/index.d.ts +9 -2
- package/dist/vite/index.js +14 -10
- package/package.json +1 -1
package/dist/server/server.js
CHANGED
|
@@ -17,7 +17,7 @@ const createApp = (options) => {
|
|
|
17
17
|
const getRootPath = (dir) => filePathToPath(dir.replace(rootRegExp, ""));
|
|
18
18
|
const app = options.app ?? new Hono();
|
|
19
19
|
const trailingSlash = options.trailingSlash ?? false;
|
|
20
|
-
const
|
|
20
|
+
const appliedMiddlewaresByDirectory = /* @__PURE__ */ new Map();
|
|
21
21
|
app.use(async function ShareContext(c, next) {
|
|
22
22
|
await contextStorage.run(c, () => next());
|
|
23
23
|
});
|
|
@@ -85,24 +85,41 @@ const createApp = (options) => {
|
|
|
85
85
|
const findMiddleware = (directory) => Object.keys(MIDDLEWARE_FILE).find(
|
|
86
86
|
(x) => new RegExp(escapeDir(directory) + "/_middleware.tsx?").test(x)
|
|
87
87
|
);
|
|
88
|
+
const isMiddlewareAppliedToAncestor = (middlewarePath, currentDir) => {
|
|
89
|
+
const dirParts = currentDir.split("/");
|
|
90
|
+
const ancestorDirs = [];
|
|
91
|
+
for (let i = dirParts.length - 1; i > 0; i--) {
|
|
92
|
+
ancestorDirs.push(dirParts.slice(0, i).join("/"));
|
|
93
|
+
}
|
|
94
|
+
return ancestorDirs.some(
|
|
95
|
+
(ancestorDir) => appliedMiddlewaresByDirectory.get(ancestorDir)?.has(middlewarePath)
|
|
96
|
+
);
|
|
97
|
+
};
|
|
88
98
|
let middlewareFile = findMiddleware(dir);
|
|
89
99
|
if (!middlewareFile) {
|
|
90
100
|
const dirParts = dir.split("/");
|
|
91
101
|
for (let i = dirParts.length - 1; i >= 0; i--) {
|
|
92
102
|
const parentDir = dirParts.slice(0, i).join("/");
|
|
93
|
-
|
|
94
|
-
|
|
103
|
+
if (!parentDir.includes(root)) {
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
const parentMiddleware = findMiddleware(parentDir);
|
|
107
|
+
if (!parentMiddleware) continue;
|
|
108
|
+
if (isMiddlewareAppliedToAncestor(parentMiddleware, dir)) continue;
|
|
109
|
+
middlewareFile = parentMiddleware;
|
|
110
|
+
break;
|
|
95
111
|
}
|
|
96
112
|
}
|
|
97
113
|
if (middlewareFile) {
|
|
98
114
|
const middleware = MIDDLEWARE_FILE[middlewareFile];
|
|
99
115
|
const middlewareDir = middlewareFile.replace("/_middleware.tsx", "").replace("/_middleware.ts", "");
|
|
100
|
-
const shouldApply = middlewareDir === dir ||
|
|
116
|
+
const shouldApply = middlewareDir === dir || dir.startsWith(middlewareDir + "/");
|
|
101
117
|
if (middleware.default && shouldApply) {
|
|
102
|
-
if (!appliedMiddleware.has(middlewareFile)) {
|
|
103
|
-
appliedMiddleware.add(middlewareFile);
|
|
104
|
-
}
|
|
105
118
|
subApp.use(...middleware.default);
|
|
119
|
+
if (!appliedMiddlewaresByDirectory.has(dir)) {
|
|
120
|
+
appliedMiddlewaresByDirectory.set(dir, /* @__PURE__ */ new Set());
|
|
121
|
+
}
|
|
122
|
+
appliedMiddlewaresByDirectory.get(dir)?.add(middlewareFile);
|
|
106
123
|
}
|
|
107
124
|
}
|
|
108
125
|
for (const [filename, route] of Object.entries(content)) {
|
|
@@ -151,7 +168,7 @@ const createApp = (options) => {
|
|
|
151
168
|
}
|
|
152
169
|
let rootPath = getRootPath(dir);
|
|
153
170
|
if (trailingSlash) {
|
|
154
|
-
rootPath =
|
|
171
|
+
rootPath = rootPath.endsWith("/") ? rootPath : rootPath + "/";
|
|
155
172
|
}
|
|
156
173
|
app.route(rootPath, subApp);
|
|
157
174
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const filePathToPath = (filePath) => {
|
|
2
|
-
filePath = filePath.replace(/\.tsx?$/g, "").replace(/\.mdx?$/g, "").replace(/^\/?index$/, "/").replace(/\/index$/, "").replace(/\[\.{3}.+\]/, "*").replace(/\((.+?)\)/g, "").replace(/\[(.+?)\]/g, ":$1").replace(
|
|
3
|
-
return
|
|
2
|
+
filePath = filePath.replace(/\.tsx?$/g, "").replace(/\.mdx?$/g, "").replace(/^\/?index$/, "/").replace(/\/index$/, "").replace(/\[\.{3}.+\]/, "*").replace(/\((.+?)\)/g, "").replace(/\[(.+?)\]/g, ":$1").replace(/\/\/+/g, "/");
|
|
3
|
+
return filePath.startsWith("/") ? filePath : "/" + filePath;
|
|
4
4
|
};
|
|
5
5
|
const groupByDirectory = (files) => {
|
|
6
6
|
const organizedFiles = {};
|
package/dist/vite/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { DevServerOptions } from '@hono/vite-dev-server';
|
|
2
|
-
export { defaultOptions as devServerDefaultOptions } from '@hono/vite-dev-server';
|
|
3
2
|
import { PluginOption } from 'vite';
|
|
4
3
|
import { ClientOptions } from './client.js';
|
|
5
4
|
import { IslandComponentsOptions } from './island-components.js';
|
|
@@ -14,6 +13,14 @@ type Options = {
|
|
|
14
13
|
external?: string[];
|
|
15
14
|
};
|
|
16
15
|
declare const defaultOptions: Options;
|
|
16
|
+
declare const devServerDefaultOptions: {
|
|
17
|
+
exclude: (string | RegExp)[];
|
|
18
|
+
handleHotUpdate: () => undefined;
|
|
19
|
+
entry: string;
|
|
20
|
+
export: string;
|
|
21
|
+
injectClientScript: boolean;
|
|
22
|
+
ignoreWatching: (string | RegExp)[];
|
|
23
|
+
};
|
|
17
24
|
declare function honox(options?: Options): PluginOption[];
|
|
18
25
|
|
|
19
|
-
export { honox as default, defaultOptions };
|
|
26
|
+
export { honox as default, defaultOptions, devServerDefaultOptions };
|
package/dist/vite/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import devServer, { defaultOptions as
|
|
1
|
+
import devServer, { defaultOptions as viteDevServerDefaultOptions } from "@hono/vite-dev-server";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import client from "./client.js";
|
|
4
4
|
import { injectImportingIslands } from "./inject-importing-islands.js";
|
|
@@ -8,21 +8,25 @@ const defaultOptions = {
|
|
|
8
8
|
islands: true,
|
|
9
9
|
entry: path.join(process.cwd(), "./app/server.ts")
|
|
10
10
|
};
|
|
11
|
+
const devServerDefaultOptions = {
|
|
12
|
+
...viteDevServerDefaultOptions,
|
|
13
|
+
exclude: [
|
|
14
|
+
...viteDevServerDefaultOptions.exclude,
|
|
15
|
+
/^\/app\/.+\.tsx?/,
|
|
16
|
+
/^\/favicon.ico/,
|
|
17
|
+
/^\/static\/.+/
|
|
18
|
+
],
|
|
19
|
+
handleHotUpdate: () => {
|
|
20
|
+
return void 0;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
11
23
|
function honox(options) {
|
|
12
24
|
const plugins = [];
|
|
13
25
|
const entry = options?.entry ?? defaultOptions.entry;
|
|
14
26
|
plugins.push(
|
|
15
27
|
devServer({
|
|
28
|
+
...devServerDefaultOptions,
|
|
16
29
|
entry,
|
|
17
|
-
exclude: [
|
|
18
|
-
...devServerDefaultOptions.exclude,
|
|
19
|
-
/^\/app\/.+\.tsx?/,
|
|
20
|
-
/^\/favicon.ico/,
|
|
21
|
-
/^\/static\/.+/
|
|
22
|
-
],
|
|
23
|
-
handleHotUpdate: () => {
|
|
24
|
-
return void 0;
|
|
25
|
-
},
|
|
26
30
|
...options?.devServer
|
|
27
31
|
})
|
|
28
32
|
);
|