-
Notifications
You must be signed in to change notification settings - Fork 1
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
RFC: Option validation approach for themes and plugins #8
Comments
|
There are two possible behavior to handle validation error:-
|
Hi, Why open the issue on this fork, and not on the main repo?
What do you mean by static? That it wouldn't be a lifecycle method? I think we should validate options/config as soon as possible, possibly even before instanciating the plugin. In client-redirects I do this in the plugin instanciation but sooner could be great.
I'd rather fail fast by default. We can be less strict later if users complain. |
Not sure, but I think themes also use this codepath, so it can be good enough for both plugins/themes/presets. for One thing that could be handy is also provide a way to normalize the plugin options. Sometimes, we want to allow the user to pass partial options, but for the internal plugin code, it may not be the most convenient to deal with an options object that can be See for example https://github.com/facebook/docusaurus/blob/master/packages/docusaurus-plugin-client-redirects/src/normalizePluginOptions.ts I think we should generalize the pattern in some kind of "preprocessing" step, where you validate/transform raw user input into sanitized/normalized/convenient options object. |
Thank you very much for your advice! :)
Yes, we were thinking of using a non-lifecycle method.
Got it! We'll try to model the validation and normalization after the client-redirects plugin, and look for a way to validate the plugins even earlier. Also, we'll put our RFCs on the main repo next time! 😅 |
💥 Proposal
Rationale
In view of the migration CLI command in facebook#2267 and the reasons explained in facebook#2878, it would be useful to have option validation for
docusaurus.config.js
. In this RFC, we hope to get feedback on an approach to validate options for themes and plugins before we start implementing it.Option validation for plugins
To validate the user’s options for plugins, we can create a
validateOptions
method for each plugin. This method takes in the user’splugins
options and validates it with Yup.validateOptions
will be called (inpackages/docusaurus/src/server/plugins/init.ts
) and it will return an actionable error message for the user if the input does not match the correct format forplugins
(or its Typescript types).Option validation for themes
For themes, we can create a
validateOptions
method that takes in the user’sthemes
options, and avalidateConfig
method that takes in the user’sthemeConfig
. Similarly, both methods will validate their input with Yup.validateOptions
andvalidateConfig
will be called (inpackages/docusaurus/src/server/index.ts
) and return an actionable error message if the user’s input does not match the correct format forthemes
orthemeConfig
respectively.Have you read the Contributing Guidelines on issues?
Yes
The text was updated successfully, but these errors were encountered: