Skip to content

Commit

Permalink
polish(v2): use npm-to-yarn for the npm2yarn remark plugin (facebook#…
Browse files Browse the repository at this point in the history
…2428)

* Use npm-to-yarn for the Bash npm2yarn Remark plugin

* Update npm-to-yarn version with fix

* Update npm-to-yarn yet another time to fix another -g/--global bug

* Update remark-npm2yarn.js

Co-authored-by: Yangshun Tay <[email protected]>
  • Loading branch information
nebrelbug and yangshun authored Mar 24, 2020
1 parent 55188ed commit a8a4fe4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
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

0 comments on commit a8a4fe4

Please sign in to comment.