-
-
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(v2): Extract npm2yarn plugin #3469
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
45df6a3
chore(v2): add dependency
fanny a8077a8
test(v2): Add npm2yarn tests
fanny 46c6c63
feat(v2): Move npm2yarn to a new remark plugin
fanny fe7507f
Merge branch 'master' into fanny/extract-npm2yarn-plugin
slorber 0a98a6e
remark npm2yarn plugin => ready to release
slorber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Remark plugin npm2yarn | ||
|
||
## Motivation: | ||
|
||
Transforms npm bash command code blocks to Docusaurus tabs: | ||
|
||
The following (remove the `//`): | ||
|
||
````bash | ||
// ```bash npm2yarn | ||
// npm run build | ||
// ``` | ||
```` | ||
|
||
Becomes: | ||
|
||
![npm2yarn tabs example](./example.png) | ||
|
||
**Note**: it only works when used with Docusaurus themes that have the `Tabs` and `TabItems` components. | ||
|
||
## Install | ||
|
||
```bash | ||
npm install @docusaurus/remark-plugin-npm2yarn` | ||
``` | ||
|
||
It is a Remark plugin, **not a Docusaurus plugin**, so you have to install it as a Remark plugin in the config of your Docusaurus plugins. | ||
|
||
```js | ||
module.exports = { | ||
presets: [ | ||
[ | ||
'@docusaurus/preset-classic', | ||
{ | ||
docs: { | ||
// ... | ||
remarkPlugins: [require('@docusaurus/remark-plugin-npm2yarn')], | ||
}, | ||
blog: { | ||
// ... | ||
remarkPlugins: [require('@docusaurus/remark-plugin-npm2yarn')], | ||
}, | ||
pages: { | ||
// ... | ||
remarkPlugins: [require('@docusaurus/remark-plugin-npm2yarn')], | ||
}, | ||
// ... | ||
}, | ||
], | ||
], | ||
// ... | ||
}; | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "@docusaurus/remark-plugin-npm2yarn", | ||
"version": "2.0.0-alpha.65", | ||
"description": "Remark plugin for convert npm commands to yarn as tabs", | ||
"main": "src/index.js", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"npm-to-yarn": "^1.0.1" | ||
}, | ||
"devDependencies": { | ||
"remark": "^12.0.0", | ||
"remark-mdx": "^1.5.8", | ||
"to-vfile": "^6.0.0" | ||
}, | ||
"peerDependencies": { | ||
"react": "^16.8.4", | ||
"react-dom": "^16.8.4" | ||
}, | ||
"engines": { | ||
"node": ">=10.15.1" | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
packages/docusaurus-remark-plugin-npm2yarn/src/__tests__/__snapshots__/index.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`npm2yarn plugin test: installation file 1`] = ` | ||
"import Tabs from '@theme/Tabs'; | ||
import TabItem from '@theme/TabItem'; | ||
|
||
<Tabs defaultValue=\\"npm\\" values={[ | ||
{ label: 'npm', value: 'npm', }, | ||
{ label: 'Yarn', value: 'yarn', }, | ||
]} | ||
> | ||
<TabItem value=\\"npm\\"> | ||
|
||
\`\`\`bash | ||
$ npm install --global docusaurus | ||
\`\`\` | ||
|
||
</TabItem> | ||
<TabItem value=\\"yarn\\"> | ||
|
||
\`\`\`bash | ||
$ yarn add --global docusaurus | ||
\`\`\` | ||
|
||
</TabItem> | ||
</Tabs> | ||
" | ||
`; | ||
|
||
exports[`npm2yarn plugin test: language was not setted 1`] = ` | ||
"\`\`\`npm2yarn | ||
npm install --save docusaurus-plugin-name | ||
\`\`\` | ||
|
||
\`\`\`bash | ||
npm install --save docusaurus-plugin-name | ||
\`\`\` | ||
|
||
\`\`\`shell | ||
npm install --save docusaurus-plugin-name | ||
\`\`\` | ||
" | ||
`; | ||
|
||
exports[`npm2yarn plugin test: plugin file 1`] = ` | ||
"import Tabs from '@theme/Tabs'; | ||
import TabItem from '@theme/TabItem'; | ||
|
||
## Installing a plugin | ||
|
||
A plugin is usually a npm package, so you install them like other npm packages using npm. | ||
|
||
<Tabs defaultValue=\\"npm\\" values={[ | ||
{ label: 'npm', value: 'npm', }, | ||
{ label: 'Yarn', value: 'yarn', }, | ||
]} | ||
> | ||
<TabItem value=\\"npm\\"> | ||
|
||
\`\`\`bash | ||
npm install --save docusaurus-plugin-name | ||
\`\`\` | ||
|
||
</TabItem> | ||
<TabItem value=\\"yarn\\"> | ||
|
||
\`\`\`bash | ||
yarn add docusaurus-plugin-name | ||
\`\`\` | ||
|
||
</TabItem> | ||
</Tabs> | ||
" | ||
`; |
3 changes: 3 additions & 0 deletions
3
packages/docusaurus-remark-plugin-npm2yarn/src/__tests__/fixtures/installation.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```bash npm2yarn | ||
$ npm install --global docusaurus | ||
``` |
7 changes: 7 additions & 0 deletions
7
packages/docusaurus-remark-plugin-npm2yarn/src/__tests__/fixtures/plugin.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## Installing a plugin | ||
|
||
A plugin is usually a npm package, so you install them like other npm packages using npm. | ||
|
||
```bash npm2yarn | ||
npm install --save docusaurus-plugin-name | ||
``` |
11 changes: 11 additions & 0 deletions
11
...saurus-remark-plugin-npm2yarn/src/__tests__/fixtures/syntax-not-properly-set.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
```npm2yarn | ||
npm install --save docusaurus-plugin-name | ||
``` | ||
|
||
```bash | ||
npm install --save docusaurus-plugin-name | ||
``` | ||
|
||
```shell | ||
npm install --save docusaurus-plugin-name | ||
``` |
53 changes: 53 additions & 0 deletions
53
packages/docusaurus-remark-plugin-npm2yarn/src/__tests__/index.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
/* eslint-disable no-param-reassign */ | ||
|
||
import remark from 'remark'; | ||
import npm2yarn from '../index'; | ||
import vfile from 'to-vfile'; | ||
import {join, relative} from 'path'; | ||
import mdx from 'remark-mdx'; | ||
|
||
const staticDir = `./${relative(process.cwd(), join(__dirname, 'fixtures'))}`; | ||
|
||
const processFixture = async (name, options) => { | ||
const path = join(__dirname, 'fixtures', `${name}.md`); | ||
const file = await vfile.read(path); | ||
const result = await remark() | ||
.use(mdx) | ||
.use(npm2yarn, {...options, filePath: path}) | ||
.process(file); | ||
|
||
return result.toString(); | ||
}; | ||
|
||
describe('npm2yarn plugin', () => { | ||
test('test: installation file', async () => { | ||
const result = await processFixture('installation', { | ||
staticDir, | ||
}); | ||
|
||
expect(result).toMatchSnapshot(); | ||
}); | ||
|
||
test('test: plugin file', async () => { | ||
const result = await processFixture('plugin', { | ||
staticDir, | ||
}); | ||
|
||
expect(result).toMatchSnapshot(); | ||
}); | ||
|
||
test('test: language was not setted', async () => { | ||
const result = await processFixture('syntax-not-properly-set', { | ||
staticDir, | ||
}); | ||
|
||
expect(result).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this really needed for docusaurus-mdx-loader ?
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, not needed :)
do you want to submit a PR?
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.
Sure