honox 0.1.13 → 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.
@@ -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
- const defaultIsIsland = (id2) => {
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 match = id.match(/(\/islands\/.+?\.tsx$)|(\/routes\/.*\_[a-zA-Z0-9[-]+\.island\.tsx$)/);
171
- if (match) {
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.13",
3
+ "version": "0.1.14",
4
4
  "main": "dist/index.js",
5
5
  "type": "module",
6
6
  "scripts": {