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

fix(v2): avoid duplicated imports in npm2yarn plugin #4964

Merged
merged 2 commits into from
Jun 15, 2021
Merged

Conversation

lex111
Copy link
Contributor

@lex111 lex111 commented Jun 14, 2021

Motivation

Resolves #4544

Currently, we cannot use @docusaurus/remark-plugin-npm2yarn plugin in document that already imports Tabs/TabItem components. This is because the plugin imports them no matter what they can already be imported in mdx doc file.

image

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Put the following code into any md file and try to start site.

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

```bash npm2yarn
  $ npm install --global docusaurus
```

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.)

@lex111 lex111 added the pr: bug fix This PR fixes a bug in a past release. label Jun 14, 2021
@lex111 lex111 requested a review from slorber as a code owner June 14, 2021 11:54
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Jun 14, 2021
const transformer = (node) => {
if (node.type === 'import' && node.value.includes('@theme/Tabs')) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I intentionally check import only one Tabs component, because I think that using TabItem without importing Tabs makes no sense at all, so we can omit checking these two components.

@netlify
Copy link

netlify bot commented Jun 14, 2021

✔️ [V2]

🔨 Explore the source changes: 9f56fcc

🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/60c7c5f78174610007a355fc

😎 Browse the preview: https://deploy-preview-4964--docusaurus-2.netlify.app

@github-actions
Copy link

github-actions bot commented Jun 14, 2021

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 64
🟢 Accessibility 97
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 95

Lighthouse ran on https://deploy-preview-4964--docusaurus-2.netlify.app/

@github-actions
Copy link

github-actions bot commented Jun 14, 2021

Size Change: +46 B (0%)

Total Size: 621 kB

Filename Size Change
website/build/blog/2017/12/14/introducing-docusaurus/index.html 62.2 kB +46 B (0%)
ℹ️ View Unchanged
Filename Size Change
website/build/assets/css/styles.********.css 87.8 kB 0 B
website/build/assets/js/main.********.js 444 kB 0 B
website/build/docs/introduction/index.html 235 B 0 B
website/build/index.html 27 kB 0 B

compressed-size-action

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.

Thanks, LGTM!

@@ -0,0 +1,7 @@
import Tabs from '@theme/Tabs';
Copy link
Collaborator

Choose a reason for hiding this comment

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

will it work if you use npm2yarn above the imports?

I think it will but I'd suggest adding usage of npm2yarn above/under the imports just to be 100% sure :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, done it.

@slorber
Copy link
Collaborator

slorber commented Jun 15, 2021

thanks 👍

@slorber slorber merged commit ace285b into master Jun 15, 2021
@slorber slorber deleted the lex111/iss4544 branch August 17, 2021 18:03
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: bug fix This PR fixes a bug in a past release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@docusaurus/remark-plugin-npm2yarn redundant imports
3 participants