-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
Expose unified util to pack TypeScript plugins #5564
Comments
Made a proof-of-concept package: https://www.npmjs.com/package/@joshcena/docusaurus-plugin-utils |
Yes I totally agree with this idea and would be happy to have such util in core and use it internally (before exposing it to plugin authors a bit later). The |
@slorber Turns out that this is not that easy and probably requires playing with our infrastructure. If you look at my implementation: https://github.com/jc-verse/docusaurus-plugin-utils there are several things I'm not happy with:
|
If we don't expose this package publicly this shouldn't be a problem for internal usage, until we find a solution to provide to the community. At first I'd prefer to keep this package undocumented until we are sure it works well for us
Lerna will build according to the dependency graph. If the new package is listed in theme deps it will be build first. That's also why Lerna doesn't allow any dependency cycle otherwise it can't compute a build order.
For such package using JS doesn't feel like a big deal IMHO. It's better to have it in JS than do not have it 🤪
glob dir/** + forEach + format should work fine |
in teory we could use overrides for now, and bundle everything with babel in one go, but currently there is no way to apply this to every package, as there is no clear spit between server and client. I read somewhere proposal (maybe comment) about refactoring structure of all packages to:
Most packages currently follow rule: if theme than this is client, but there are exceptions to that, for example gtag.ts if we have clear folder boundaries for client/server code, i don't mind writing eslint rule that can enforce this :) |
Agree we should move into that direction and have client/server/common in each plugin. |
💥 Proposal
As more of the official packages are migrated to TS, I start to notice duplicated logic in the packing process, but not following this long process of compiling -> copying static assets -> double transpilation can cause some troubles.
The first one is less of a concern, although more likely to occur: when the theme folder contains
.css
files, they are not copied to the dist folder bytsc
, you would either need to transpile by babel withallExtensions: true
, or you would need to use thecopyUntypedFiles
script (which we use a lot—duplicated in every package). Neither is very convenient for a TS plugin developer. However, the plugin author cannot get away without using one of the two techniques, because missing.css
files would make the code not run at all.The second one can be more problematic. The TypeScript theme components are transpiled twice, once only with the types stripped and once to actual commonjs code. Now imagine the following case:
tsc
and distributed;This can go away unnoticed because for normal users who don't swizzle, the plugin runs correctly. The above case is very rare as of now, but can be likely in the future with a better plugin ecosystem. Also, many official plugins have their own theme components, and most of them are currently kept as JS to bypass this issue—still not optimal for TS-perfectionists like me. If we can expose a util to transpile the theme components to human-readable JS automatically, things would be a lot easier for the plugin authors.
I propose we have a
docusaurus-plugin build
command, meant to be used by plugin authors, which runs Babel and generates a nice directory structure automatically, maybe like this:We can use this internally to reduce the logic duplication, so it's better if it gets into this repo.
We may even provide a
docusaurus-plugin init
utility to scaffold a plugin package, just likedocusaurus init
.Have you read the Contributing Guidelines on issues?
Yes
Edit. Once #5816 lands, we don't need to transpile twice. Hence, the major focus of this tool shifts towards an ergonomic DX: hot reloading for CSS edits, type-checking integration, etc., than actually bundling & building.
The text was updated successfully, but these errors were encountered: