polish(v2): use npm-to-yarn for the npm2yarn remark plugin (#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 <tay.yang.shun@gmail.com>
This commit is contained in:
Ben Gubler 2020-03-23 18:53:48 -06:00 committed by GitHub
parent 55188ed0a1
commit a8a4fe467a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 14 deletions

View file

@ -14,6 +14,7 @@
"@docusaurus/preset-classic": "^2.0.0-alpha.48", "@docusaurus/preset-classic": "^2.0.0-alpha.48",
"classnames": "^2.2.6", "classnames": "^2.2.6",
"color": "^3.1.2", "color": "^3.1.2",
"npm-to-yarn": "^1.0.0-2",
"react": "^16.8.4", "react": "^16.8.4",
"react-dom": "^16.8.4" "react-dom": "^16.8.4"
}, },

View file

@ -5,20 +5,10 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
// This is a very naive implementation of converting npm commands to yarn commands const npmToYarn = require('npm-to-yarn');
// 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 // E.g. global install: 'npm i' -> 'yarn'
const convertNpmToYarn = npmCode => { const convertNpmToYarn = npmCode => npmToYarn(npmCode, 'yarn');
// 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 transformNode = node => { const transformNode = node => {
const npmCode = node.value; const npmCode = node.value;