Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It would be nice to place islands anywhere, not just in routes and islands directories. #159

Closed
liltechnomancer opened this issue Apr 25, 2024 · 4 comments · Fixed by #176

Comments

@liltechnomancer
Copy link

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch honox@0.1.15 for the project I'm working on.

I wanted to be able to place islands anywhere not just within route and islands

Here is the diff that solved my problem:

This should probably be done in a more elegant way, but I wanted to provide what worked for me.
If you like the idea, I can make the commits to add config options or something to allow for this.

diff --git a/node_modules/honox/dist/vite/inject-importing-islands.js b/node_modules/honox/dist/vite/inject-importing-islands.js
index 78c7d0f..47a28aa 100644
--- a/node_modules/honox/dist/vite/inject-importing-islands.js
+++ b/node_modules/honox/dist/vite/inject-importing-islands.js
@@ -8,7 +8,7 @@ import { IMPORTING_ISLANDS_ID } from "../constants.js";
 const generate = _generate.default ?? _generate;
 async function injectImportingIslands() {
   const isIslandRegex = new RegExp(/(\/islands\/|\_[a-zA-Z0-9[-]+\.island\.[tj]sx$)/);
-  const fileRegex = new RegExp(/(routes|_renderer|_error|_404)\/.*\.[tj]sx$/);
+  const fileRegex = new RegExp(/(.|routes|_renderer|_error|_404)\/.*\.[tj]sx$/);
   const cache = {};
   const walkDependencyTree = async (baseFile, dependencyFile) => {
     const depPath = dependencyFile ? path.join(path.dirname(baseFile), dependencyFile) + ".tsx" : baseFile;
@@ -37,8 +37,10 @@ async function injectImportingIslands() {
       }
       const hasIslandsImport = (await walkDependencyTree(id)).flat().some((x) => isIslandRegex.test(normalizePath(x)));
       if (!hasIslandsImport) {
+        
         return;
       }
+
       const ast = parse(sourceCode, {
         sourceType: "module",
         plugins: ["jsx", "typescript"]
diff --git a/node_modules/honox/dist/vite/island-components.js b/node_modules/honox/dist/vite/island-components.js
index eb99b62..8998758 100644
--- a/node_modules/honox/dist/vite/island-components.js
+++ b/node_modules/honox/dist/vite/island-components.js
@@ -157,10 +157,11 @@ function getIslandComponentName(root, id, options) {
     return path.resolve(id2).startsWith(islandDirectoryPath);
   };
   const matchIslandPath = options?.isIsland ?? defaultIsIsland;
+  
   if (!matchIslandPath(id)) {    
     return null;
   }
-  const match = id.match(/(\/islands\/.+?\.tsx$)|(\/routes\/.*\_[a-zA-Z0-9[-]+\.island\.tsx$)/);
+  const match = id.match(/(\/islands\/.+?\.tsx$)|(\/app\/.*\_[a-zA-Z0-9[-]+\.island\.tsx$)/);
   if (!match) {    
     return null;
   }

This issue body was partially generated by patch-package.

@yusukebe
Copy link
Member

yusukebe commented May 1, 2024

Hi @liltechnomancer

Sorry for the delayed response. Yes. This should be fixed. If Some PR will be merged, I can work on it! Thanks.

@liltechnomancer
Copy link
Author

@yusukebe No need to apologize, thanks for all the amazing work!

@yusukebe
Copy link
Member

yusukebe commented May 8, 2024

Hi @liltechnomancer

I will create the PR by referring to your code. Can I make you a co-author for the PR?

@liltechnomancer
Copy link
Author

If you would like! That would be cool 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants