Skip to content
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(v2): Extract npm2yarn plugin #3469

Merged
merged 5 commits into from Oct 15, 2020
Merged

Conversation

fanny
Copy link
Contributor

@fanny fanny commented Sep 21, 2020

Motivation

I would like to extract our npm2yarn plugin to the mdx loader. Why am I doing this? A couple of months ago, I tried to implement the plugin in CRA they demonstrated interest in use the plugin, and other users like react-navigation are using as well. But doing as a copy-paste version from ours.

Have you read the Contributing Guidelines on pull requests?

yes

Test Plan

(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work. Bonus points for screenshots and videos!)
yarn test

Related PRs

(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)

@docusaurus-bot
Copy link
Contributor

docusaurus-bot commented Sep 21, 2020

Deploy preview for docusaurus-2 ready!

Built with commit 0a98a6e

https://deploy-preview-3469--docusaurus-2.netlify.app

Copy link
Contributor

@lex111 lex111 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we really should include this feature in the core. This is a pretty specific thing. 🤔
Wouldn't it be better if this is published as an npm package outside of Docusaurus core?

@fanny
Copy link
Contributor Author

fanny commented Sep 21, 2020

The feature of tabs is ours. I don't know if it's still valuable outside.

@lex111
Copy link
Contributor

lex111 commented Sep 21, 2020

Not exactly, because the tabs are feature of a theme, not the core. For this reason, it is best to place this tabs extension in a separate npm package.

@fanny
Copy link
Contributor Author

fanny commented Sep 21, 2020

Like a docusaurus plugin outside of the core, right?

But why? I'm trying to understand your idea

@lex111
Copy link
Contributor

lex111 commented Sep 21, 2020 via email

@fanny
Copy link
Contributor Author

fanny commented Sep 23, 2020

Sounds good. I'll wait @slorber return from PTO, to receive a final feedback.

@slorber slorber added the pr: new feature This PR adds a new API or behavior. label Sep 28, 2020
@slorber
Copy link
Collaborator

slorber commented Sep 28, 2020

As we are based on JS, React, MDX etc, it's probably ok to include features slightly biased to JS usage, as many docusaurus sites document frontend projects, as long as it does not harm or add too much clutter for other documentation usecases. This usecase seems fine to me.

Maintaining a plugin that we use on Docusaurus site outside of Docusaurus repo can be annoying, as it adds friction for maintenance and refactorings, particularly if the owner (Fanny?) becomes inactive for some reason.

@lex111 is right that tabs is a theme feature, so adding this plugin by default in core (I mean mdx loader) seems bad. We are lucky that both classic and bootstrap themes support tabs so CI does not fail, but if community builds a theme without tabs, this plugin would make the site fail. Maybe we should add the ability for a theme to register global remark/rehype plugins? Not sure how this can be done properly.

However this feature is already opt-in due to its specific syntax '''bash npm2yarn, so I guess it's pretty safe to make it global, despite not working with all possible future themes. To fail, user would have to choose a theme that has no tabs support + use the specific npm2yarn code block syntax (unlikely).


What I suggest is that we publish the plugin as @docusaurus/remark-plugin-npm2yarn, document it as an optional plugin that the user would have to add to the remarkPlugins array if he wants npm/yarn tabs support if its theme support it (likely to be true), instead of enabling it by default in mdx loader.

Later, we could look for a way to enable this plugin by default on classic/bootstrap presets/themes, as we know in such case that it is safe to use.

What do you think?

@fanny
Copy link
Contributor Author

fanny commented Oct 1, 2020

What I suggest is that we publish the plugin as @docusaurus/remark-plugin-npm2yarn, document it as an optional plugin that the user would have to add to the remarkPlugins array if he wants npm/yarn tabs support if its theme support it (likely to be true), instead of enabling it by default in mdx loader.

I agree with you, I didn't think in the possibility that the tabs feature couldn't used. That said, this option, seems secure for me.

@slorber
Copy link
Collaborator

slorber commented Oct 12, 2020

Hi @fanny

Do you want to work on the changes we agreed on, or can I finish and merge your PR?

@fanny
Copy link
Contributor Author

fanny commented Oct 12, 2020

Hey, I can finish. I was waiting for @lex111 comments.

@lex111
Copy link
Contributor

lex111 commented Oct 12, 2020

@fanny apologies for the silence on this. Of course @slorber's suggestion is just great, let's do so!

@fanny fanny requested a review from slorber as a code owner October 13, 2020 11:57
Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost good, just an important details 🤪 this does not work.

You didn't actually use the plugin you just created, because you still use the local site plugin in the config:

remarkPlugins: [require('./src/plugins/remark-npm2yarn')],

We should remove this local plugin, and change the config to use the new remark plugin:

remarkPlugins: ["@docusaurus/remark-plugin-npm2yarn"],

(maybe require() is still required, don't know)

Without a new lifecycle like getRemarkPlugins or something, we currently don't have a way to make a docusaurus plugin provide a remark plugin that will be used for all other plugins reading markdown files.

I suggest to keep it simple for now (and publish a remark plugin, not a docusaurus plugin), but in the future we'd rather figure out such an API, so that adding "@docusaurus/plugin-npm2yarn" would enable the npm2yarn feature for all plugins (docs, pages, blog...).

return {
name: 'docusaurus-remark-plugin-npm2yarn',
getClientModules() {
return [path.resolve(__dirname, './npm2yarn/index.js')];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this will work in practice.

We currently don't have any lifecycle method to add a remark plugin to the mdx loader in a generic way.

For now, this package should be a simple remark plugin, not a docusaurus plugin (until we figure this out). We'll use it in the conf by providing it in the remark plugin array.

"license": "MIT",
"dependencies": {
"npm-to-yarn": "^1.0.0-2",
"@docusaurus/mdx-loader": "2.0.0-alpha.65"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably not needed

@fanny
Copy link
Contributor Author

fanny commented Oct 14, 2020

Ops, I understood wrong, so in this case, could you finish? I don't know if I will have time

@slorber
Copy link
Collaborator

slorber commented Oct 15, 2020

sure, will do that :)

@slorber
Copy link
Collaborator

slorber commented Oct 15, 2020

ready to merge, thanks ;)

@slorber slorber merged commit 4760e12 into master Oct 15, 2020
@@ -17,6 +17,7 @@
"@docusaurus/utils": "2.0.0-alpha.65",
"@mdx-js/mdx": "^1.5.8",
"@mdx-js/react": "^1.5.8",
"npm-to-yarn": "^1.0.0-2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really needed for docusaurus-mdx-loader ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, not needed :)
do you want to submit a PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

@slorber slorber deleted the fanny/extract-npm2yarn-plugin branch August 17, 2021 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: new feature This PR adds a new API or behavior.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants