diff --git a/website/package.json b/website/package.json index 15b5d33e9857..40e85185588c 100644 --- a/website/package.json +++ b/website/package.json @@ -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" }, diff --git a/website/src/plugins/remark-npm2yarn.js b/website/src/plugins/remark-npm2yarn.js index 5f4ffb47df6d..6092da7b7181 100644 --- a/website/src/plugins/remark-npm2yarn.js +++ b/website/src/plugins/remark-npm2yarn.js @@ -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 ' -// 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;