ds-pack / babel-plugin-docs

A babel plugin for collecting documentation on components and hooks
2 stars 0 forks source link

๐Ÿ—บ๏ธ Roadmap to 1.0 #14

Open hamlim opened 3 years ago

hamlim commented 3 years ago

Starting to write down some thoughts on what it would take to get this package to it's 1.0 release.

I've been digging back into the codebase as of late, and I'm starting to see some cracks in the design of hijacking the babel-plugin architecture to collect this metadata. I still think babel visitors are the right way to capture this information, but I don't think we need to do the collection work as part of babel transpiling the source code.

More on why we shouldn't do this during babel transpilation... The TL;DR is that we can't guarantee that our plugin will run before any others, so for example if the source project is running the transform-runtime plugin, we may see additional imports for the runtime helpers in the output which might be fine, but there could also be other changes to the code that we don't want to capture.

So if we're not doing this work during babel transpilation, when should we do it? My current thinking is that we should recommend that projects run it in parallel with Babel, or at least run it before they publish so library consumers can pull in the metadata after installing the package.

Does this mean we need to re-write the whole thing? Not necessarily ๐Ÿ™‚ See architecture below.

Architecture

Babel visitors still feels like the right approach to capturing this metadata (mostly because I can't think of an alternative to them that I know enough about ๐Ÿ˜„ ), luckily it's fairly easy to setup a node script that can traverse files with babel.

From a high level view, the new architecture may look like:

We may want to consider chunking up this work, and distributing across workers if possible (see architecture from https://github.com/ds-pack/ast-crawler for inspiration).

hamlim commented 3 years ago

One thought, may want to change the repo/project name if we're no longer doing this work within a babel plugin ๐Ÿ˜„

hamlim commented 3 years ago

We'll also want to account for TypeScript types for components and hooks as well, so we should aim to have #1 resolved as well