-
Notifications
You must be signed in to change notification settings - Fork 51
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
feat: enable placing islands anywhere #176
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6513064
feat: enable placing islands anywhere
yusukebe 46b6f99
add e2e test
yusukebe 0cbcaf2
fixed path resolving
yusukebe ce47762
improve resolving paths
yusukebe 26733f2
add some tests
yusukebe 7201b4a
import only `.tsx` at the client
yusukebe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { PropsWithChildren } from 'hono/jsx' | ||
import { useState } from 'hono/jsx' | ||
|
||
export default function Counter({ | ||
children, | ||
initial = 0, | ||
}: PropsWithChildren<{ | ||
initial?: number | ||
}>) { | ||
const [count, setCount] = useState(initial) | ||
const increment = () => setCount(count + 1) | ||
return ( | ||
<div> | ||
<p>Count: {count}</p> | ||
<button onClick={increment}>Increment</button> | ||
{children} | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Counter from '../../components/$counter' | ||
|
||
export default function Interaction() { | ||
return ( | ||
<> | ||
<Counter initial={5} /> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { matchIslandComponentId } from './path' | ||
|
||
describe('matchIslandComponentId', () => { | ||
describe('match', () => { | ||
const paths = [ | ||
'/islands/counter.tsx', | ||
'/islands/directory/counter.tsx', | ||
'/routes/$counter.tsx', | ||
'/routes/directory/$counter.tsx', | ||
'/routes/_counter.island.tsx', | ||
'/routes/directory/_counter.island.tsx', | ||
'/$counter.tsx', | ||
'/directory/$counter.tsx', | ||
'/_counter.island.tsx', | ||
'/directory/_counter.island.tsx', | ||
] | ||
|
||
paths.forEach((path) => { | ||
it(`Should match ${path}`, () => { | ||
const match = matchIslandComponentId(path) | ||
expect(match).not.toBeNull() | ||
expect(match![0]).toBe(path) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('not match', () => { | ||
const paths = [ | ||
'/routes/directory/component.tsx', | ||
'/routes/directory/foo$component.tsx', | ||
'/routes/directory/foo_component.island.tsx', | ||
'/routes/directory/component.island.tsx', | ||
'/directory/islands/component.tsx', | ||
] | ||
|
||
paths.forEach((path) => { | ||
it(`Should not match ${path}`, () => { | ||
const match = matchIslandComponentId(path) | ||
expect(match).toBeNull() | ||
}) | ||
}) | ||
}) | ||
|
||
describe('not match - with `islandDir`', () => { | ||
const paths = ['/islands/component.tsx'] | ||
|
||
paths.forEach((path) => { | ||
it(`Should not match ${path}`, () => { | ||
const match = matchIslandComponentId(path, '/directory/islands') | ||
expect(match).toBeNull() | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Check if the name is a valid component name | ||
* | ||
* @param name - The name to check | ||
* @returns true if the name is a valid component name | ||
* @example | ||
* isComponentName('Badge') // true | ||
* isComponentName('BadgeComponent') // true | ||
* isComponentName('badge') // false | ||
* isComponentName('MIN') // false | ||
* isComponentName('Badge_Component') // false | ||
*/ | ||
export function isComponentName(name: string) { | ||
return /^[A-Z][A-Z0-9]*[a-z][A-Za-z0-9]*$/.test(name) | ||
} | ||
|
||
/** | ||
* Matches when id is the filename of Island component | ||
* | ||
* @param id - The id to match | ||
* @returns The result object if id is matched or null | ||
*/ | ||
export function matchIslandComponentId(id: string, islandDir: string = '/islands') { | ||
const regExp = new RegExp( | ||
`^${islandDir}\/.+?\.tsx$|.*\/(?:\_[a-zA-Z0-9-]+\.island\.tsx$|\\\$[a-zA-Z0-9-]+\.tsx$)` | ||
) | ||
return id.match(regExp) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has nothing to do with this PR change, In
matchIslandComponentId()
, only.tsx
matches (.ts does not), so I think only
.tsx` should be used here as well.https://github.com/honojs/honox/pull/176/files#diff-4b7b8acce4bb320abe3a28d1bb85d7ad346253af647225df7e62d19891192a27R25
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@usualoma
You are right! It should be only
.tsx
and it's not a problem if it does not support.ts
.