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

polish(v2): use npm-to-yarn for the npm2yarn remark plugin #2428

Merged
merged 5 commits into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@docusaurus/preset-classic": "^2.0.0-alpha.48",
"classnames": "^2.2.6",
"color": "^3.1.2",
"npm-to-yarn": "^1.0.0-2",
"react": "^16.8.4",
"react-dom": "^16.8.4"
},
Expand Down
18 changes: 4 additions & 14 deletions website/src/plugins/remark-npm2yarn.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,10 @@
* LICENSE file in the root directory of this source tree.
*/

// This is a very naive implementation of converting npm commands to yarn commands
// Works well for our use case since we only use either 'npm install', or 'npm run <something>'
// Its impossible to convert it right since some commands at npm are not available in yarn and vice/versa
const convertNpmToYarn = npmCode => {
// global install: 'npm i' -> 'yarn'
return (
npmCode
.replace(/^npm i$/gm, 'yarn')
// install: 'npm install --save foo' -> 'yarn add foo'
.replace(/npm install --save/gm, 'yarn add')
// run command: 'npm run start' -> 'yarn run start'
.replace(/npm run/gm, 'yarn run')
);
};
const npmToYarn = require('npm-to-yarn');

// E.g. global install: 'npm i' -> 'yarn'
const convertNpmToYarn = npmCode => npmToYarn(npmCode, 'yarn');

const transformNode = node => {
const npmCode = node.value;
Expand Down