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

feat: Enable to export named component by adding component-export attribute #163

Merged
merged 8 commits into from
May 4, 2024

Conversation

usualoma
Copy link
Member

fixes #156

Use the component-export mentioned in isseu to wrap an export matching the following name as an island component.

https://github.com/honojs/honox/compare/main...usualoma:honox:feat/export-named-component?expand=1#diff-dbf4bfe9bdc2ab09701d7f99d62aa69e45740919b350c8166aebe64daa3fdd54R39-R41

@usualoma usualoma force-pushed the feat/export-named-component branch 4 times, most recently from b181921 to 55a180a Compare May 3, 2024 01:12
@usualoma usualoma force-pushed the feat/export-named-component branch from 55a180a to ab23d39 Compare May 3, 2024 02:25
@usualoma usualoma marked this pull request as ready for review May 3, 2024 02:28
@usualoma
Copy link
Member Author

usualoma commented May 3, 2024

@yusukebe Would you please review?

} from '@babel/types'
import { parse as parseJsonc } from 'jsonc-parser'
// eslint-disable-next-line node/no-extraneous-import
import type { Plugin } from 'vite'

function addSSRCheck(funcName: string, componentName: string) {
function isComponentName(name: string) {
return /^[A-Z]/.test(name) && /[a-z]/.test(name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the component name is /^[A-Z][A-Za-z0-9]+/. What do you think?

Copy link
Member Author

@usualoma usualoma May 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't explain it well enough.

I wanted to exclude capital-only exports from the island component, didn't I? What do you think?

export const LIMIT = 10;.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, but it is certainly better not to include _. I prefer something like this.

/^[A-Z][A-Za-z0-9]*[a-z][A-Za-z0-9]*$/

I will change it to this later. Wait a minute.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about 130c642?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@usualoma

How about 130c642?

Good! I'd like to go with it.

How about writing the test? I want to have a test, though it's simple logic. But, I don't have any good idea where we should put it. Exporting isComponentName and writing test in src/vite/island-components.test.ts? Or creating src/vite/utils.ts and putting the logic into it? Do you have any thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8365f1b added!

I think what you are trying to say is that "whether to treat it as a component or not is a very important external specification, so it should be an independent test, both to confirm the implementation and to explain it to the user".

For me, 8365f1b seems sufficient, but if I were to go further, I would suggest that it should be independent, as you say, as follows.

Or creating src/vite/utils.ts and putting the logic into it

Opinion me, please.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, fix typo 35aa726

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whether to treat it as a component or not is a very important external specification, so it should be an independent test, both to confirm the implementation and to explain it to the user

Yes! Exactly. Thank you for saying what I wanted to say!

8365f1b is good for me. This covers all patterns and shows the specification. Let's go with it. Sorry for taking your time.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish I had been aware of this from the beginning, but I am sorry for taking up so much of your time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worry! Thank you for the great PR! I'll release the new version tomorrow!

@yusukebe
Copy link
Member

yusukebe commented May 3, 2024

@usualoma

Thanks. I've left one comment!

@usualoma usualoma force-pushed the feat/export-named-component branch from 2078c4e to 130c642 Compare May 4, 2024 12:14
Copy link
Member

@yusukebe yusukebe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@yusukebe
Copy link
Member

yusukebe commented May 4, 2024

@usualoma

Thank you! Let's land it.

@yusukebe yusukebe merged commit 9445d71 into honojs:main May 4, 2024
2 checks passed
@usualoma usualoma deleted the feat/export-named-component branch May 4, 2024 13:52
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 this pull request may close these issues.

Support named export not only default in Islands
2 participants