honox 0.1.12 → 0.1.14
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/README.md
CHANGED
|
@@ -327,7 +327,7 @@ createClient()
|
|
|
327
327
|
If you want to add interactions to your page, create Island components. Islands components should be:
|
|
328
328
|
|
|
329
329
|
- Placed under `app/islands` directory or named with `_` prefix and `island.tsx` suffix like `_componentName.island.tsx`.
|
|
330
|
-
- Should `default
|
|
330
|
+
- Should `export default function`.
|
|
331
331
|
|
|
332
332
|
For example, you can write an interactive component such as the following counter:
|
|
333
333
|
|
|
@@ -4,6 +4,10 @@ import * as hono_types from 'hono/types';
|
|
|
4
4
|
|
|
5
5
|
declare const createApp: <E extends Env>(options?: Partial<{
|
|
6
6
|
ROUTES: Record<string, ({
|
|
7
|
+
default: hono.Hono<Env, hono_types.BlankSchema, "/">;
|
|
8
|
+
} & {
|
|
9
|
+
__importing_islands?: boolean | undefined;
|
|
10
|
+
}) | ({
|
|
7
11
|
default?: Function | undefined;
|
|
8
12
|
} & {
|
|
9
13
|
GET?: hono_types.H[] | undefined;
|
|
@@ -14,10 +18,6 @@ declare const createApp: <E extends Env>(options?: Partial<{
|
|
|
14
18
|
PATCH?: hono_types.H[] | undefined;
|
|
15
19
|
} & {
|
|
16
20
|
__importing_islands?: boolean | undefined;
|
|
17
|
-
}) | ({
|
|
18
|
-
default: hono.Hono<Env, hono_types.BlankSchema, "/">;
|
|
19
|
-
} & {
|
|
20
|
-
__importing_islands?: boolean | undefined;
|
|
21
21
|
})>;
|
|
22
22
|
RENDERER: Record<string, {
|
|
23
23
|
default: hono.MiddlewareHandler;
|
|
@@ -151,25 +151,42 @@ const transformJsxTags = (contents, componentName) => {
|
|
|
151
151
|
return code;
|
|
152
152
|
}
|
|
153
153
|
};
|
|
154
|
+
function getIslandComponentName(root, id, options) {
|
|
155
|
+
const defaultIsIsland = (id2) => {
|
|
156
|
+
const islandDirectoryPath = path.join(root, "app");
|
|
157
|
+
return path.resolve(id2).startsWith(islandDirectoryPath);
|
|
158
|
+
};
|
|
159
|
+
const matchIslandPath = options?.isIsland ?? defaultIsIsland;
|
|
160
|
+
if (!matchIslandPath(id)) {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
const match = id.match(/(\/islands\/.+?\.tsx$)|(\/routes\/.*\_[a-zA-Z0-9[-]+\.island\.tsx$)/);
|
|
164
|
+
if (!match) {
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
return match[0];
|
|
168
|
+
}
|
|
154
169
|
function islandComponents(options) {
|
|
170
|
+
const insideIslandSuffix = "?inside-island";
|
|
155
171
|
let root = "";
|
|
156
172
|
return {
|
|
157
173
|
name: "transform-island-components",
|
|
174
|
+
enforce: "pre",
|
|
158
175
|
configResolved: (config) => {
|
|
159
176
|
root = config.root;
|
|
160
177
|
},
|
|
178
|
+
async resolveId(source, importer) {
|
|
179
|
+
const resolution = await this.resolve(source, importer);
|
|
180
|
+
if (resolution && importer && getIslandComponentName(root, importer, options)) {
|
|
181
|
+
return resolution.id + insideIslandSuffix;
|
|
182
|
+
}
|
|
183
|
+
},
|
|
161
184
|
async load(id) {
|
|
162
|
-
|
|
163
|
-
const islandDirectoryPath = path.join(root, "app");
|
|
164
|
-
return path.resolve(id2).startsWith(islandDirectoryPath);
|
|
165
|
-
};
|
|
166
|
-
const matchIslandPath = options?.isIsland ?? defaultIsIsland;
|
|
167
|
-
if (!matchIslandPath(id)) {
|
|
185
|
+
if (id.endsWith(insideIslandSuffix)) {
|
|
168
186
|
return;
|
|
169
187
|
}
|
|
170
|
-
const
|
|
171
|
-
if (
|
|
172
|
-
const componentName = match[0];
|
|
188
|
+
const componentName = getIslandComponentName(root, id, options);
|
|
189
|
+
if (componentName) {
|
|
173
190
|
const contents = await fs.readFile(id, "utf-8");
|
|
174
191
|
const code = transformJsxTags(contents, componentName);
|
|
175
192
|
if (code) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "honox",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
"@babel/traverse": "^7.23.6",
|
|
107
107
|
"@babel/types": "^7.23.6",
|
|
108
108
|
"@hono/vite-dev-server": "^0.11.0",
|
|
109
|
-
"precinct": "^
|
|
109
|
+
"precinct": "^12.0.2"
|
|
110
110
|
},
|
|
111
111
|
"peerDependencies": {
|
|
112
112
|
"hono": ">=4.*"
|