-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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: shorthands for themes/plugins/presets configuration #5930
Conversation
✔️ [V2] 🔨 Explore the source changes: ddd3385 🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/61aa4e160eaabc0007784aa3 😎 Browse the preview: https://deploy-preview-5930--docusaurus-2.netlify.app |
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-5930--docusaurus-2.netlify.app/ |
I indexed plugins by type to identify plugin and theme aliases. This affected |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks cool
A little POC using our own website will help us see if it's working
Actually in the next commit I'll apply this same engine for presets, and I thought about using the I really care about automated tests, but emulating a Node package resolve is very complex, and I would end up mocking too much and the test would practically be a snapshot over the resolve attempts (asserting mapping a string with some prefixes). |
Hmm, just replacing all the names in our docusaurus.config.js is fine |
Do you think that the preset part should be applied in a separate PR? By that I mean accepting, for instance, |
Yes—I haven't reviewed the impl in detail, but I think it would be trivial to add and weird to not |
Just executed with another project and the theme resolution is working now. |
@Josh-Cena, could you help me identifying why the E2E didn't work? |
Hey @fsmaia FYI your approach didn't work well with swizzling because of how our swizzling script tries to resolve theme names through the config. To simplify things (I may revisit that script in the future, the setup looks convoluted) I refactored your code to resolve the module names directly after loading the plugin config. The diff also looks much cleaner this way. |
Amazing! Big thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, LGTM, just did some little modifications
// eslint-disable-next-line no-restricted-syntax | ||
for (const module of modulePatterns) { | ||
try { | ||
moduleRequire.resolve(module); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok for that.
Throwing exceptions has a runtime cost, but it's probably not very important here.
I don't know if there's a fail-safe way to resolve a module in nodejs but if there is one, that would be preferable.
@@ -24,7 +24,7 @@ const dogfoodingPluginInstances = [ | |||
], | |||
|
|||
[ | |||
'@docusaurus/plugin-content-blog', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
going to dogfood other forms of plugin names here, it's the purpose of dogfooding to have a variety of settings ;)
website/docs/configuration.md
Outdated
| --- | --- | | ||
| `awesome` | `docusaurus-plugin-awesome` | | ||
| `sitemap` | [`@docusaurus/plugin-sitemap`](./api/plugins/plugin-sitemap.md) | | ||
| `@joshcena` | `@joshcena/docusaurus-plugin` (the only possible resolution!) | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replacing with @mycompany
which is more likely to happen and less confusing for docs readers
@@ -66,15 +125,15 @@ module.exports = { | |||
// ... | |||
plugins: [ | |||
[ | |||
'@docusaurus/plugin-content-blog', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just thinking out loud but maybe we'll want in a future to just be able to use "blog"?
The "content-blog" thing is a bit weird for the users IMHO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quite similarly I'm not fan of the complexity of our i18n paths, I wish we could just have i18n/fr/blog
).toThrowErrorMatchingInlineSnapshot(` | ||
"Docusaurus was unable to resolve the \\"@docusaurus/plugin-content-doc\\" plugin. Make sure one of the following packages are installed: | ||
- @docusaurus/plugin-content-doc | ||
- @docusaurus/docusaurus-plugin-plugin-content-doc" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: added this test, but this resolve name looks a bit weird.
I'll still merge, but if you feel we should do something about it 🤷♂️ feel free to open another PR
Motivation
See #5883
Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
require.resolve
(as it won't be physically installed), or then add a demo plugin in the fixture package.json file)