honox 0.1.13 → 0.1.15

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.
@@ -151,25 +151,44 @@ 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
+ if (getIslandComponentName(root, resolution.id, options)) {
182
+ return resolution.id + insideIslandSuffix;
183
+ }
184
+ }
185
+ },
161
186
  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)) {
187
+ if (id.endsWith(insideIslandSuffix)) {
168
188
  return;
169
189
  }
170
- const match = id.match(/(\/islands\/.+?\.tsx$)|(\/routes\/.*\_[a-zA-Z0-9[-]+\.island\.tsx$)/);
171
- if (match) {
172
- const componentName = match[0];
190
+ const componentName = getIslandComponentName(root, id, options);
191
+ if (componentName) {
173
192
  const contents = await fs.readFile(id, "utf-8");
174
193
  const code = transformJsxTags(contents, componentName);
175
194
  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.15",
4
4
  "main": "dist/index.js",
5
5
  "type": "module",
6
6
  "scripts": {