-
Notifications
You must be signed in to change notification settings - Fork 106
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
Experiment with react-docgen #190
Conversation
I added some context on our Vite plugin work to #2, I'd be curious if custom handlers receive a TypeScript AST in this implementation. |
I think my thoughts were to provide at least some support for now. It's definitely possible to get |
We now have support for react-docgen-typescript thanks to @joshwooding. I think it's maybe worth also supporting this option, for those not using typescript. If there's interest, I'll clean this up and get it ready for review/merge. |
@IanVS non-TS user here weighing in from the peanut gallery. I definitely think this should be supported for those that choose not to use TS, I think that's a pretty common use case and all these tools support both TS and non-TS projects in them. |
Thanks @reintroducing. I'll work on this a bit. We may find a better way in the future, but it would be good to support folks for now, and this is pretty close to being ready I think. |
Thanks @IanVS for your work -- definitely a feature I'm missing as well after switching from Webpack to the Vite plugin. This would be worth mentioning in the "Known Issues" section in the README. |
@reintroducing and @sebastienbarre thanks for the nudges. I've opened #299 which I think is a better approach to add support for react-docgen, if you'd like to keep an eye on that one. |
@IanVS thank you! i've gone ahead and subscribed to that PR, appreciate your work on this. |
Fixes #103 Closes #190 Fixes #2 This takes a slightly different approach from #190. Instead of using a babel transform, this creates a vite plugin, similar to the vue-docgen plugin, but based on the babel-plugin-react-docgen. This gives us the chance to rely directly on react-docgen, without needing another package in between, and it avoids being accidentally overwritten if users replace our @vitejs/plugin-react with their own config. This new vite plugin is not configurable like the babel plugin is, but I'm not certain those configurations are necessary in the first place. If we hear from users that it's something they need, we can find a way to make them customizable, but I prefer to avoid extra options if possible. This version does not create a global list of all the docs, like the babel plugin does (`DOC_GEN_COLLECTION_NAME`). I looked through the storybook source, and it doesn't seem like anything still relies on it, so I think it's just a legacy detail for now that we can probably avoid supporting. I've updated the react example to demonstrate the use of the plugin, so feel free to check this out there.
This is a similar experiment to #167, but using
@ianvs/babel-plugin-react-docgen@5.0.0-alpha.0
so we can try out the 6.0.0-alpha.0 version of react-docgen.A few things I notice, which @ewlsh also pointed out in #2 (comment):
union
React.FC
is not handled correctlyreact-codegen-typescript
does, but having the actual type seems nicer than the type alias name.signature
, which doesn't really help much.Despite these limitations, it might be worth thinking about moving forward in this direction to at least get some kind of support, though. Ideally, we'd give an option to also use something like
react-codegen-typescript
, but this seems like maybe a good start.