Last active
March 17, 2024 19:14
-
-
Save radist2s/a4485bd3fcf0c8d659844a3abb22527e to your computer and use it in GitHub Desktop.
Adds `npx` and `npm exec --call` support to `@docusaurus/remark-plugin-npm2yarn` plugin.
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
{ | |
// ... | |
docs: { | |
remarkPlugins: [ | |
[ | |
require('@docusaurus/remark-plugin-npm2yarn'), | |
{ | |
sync: true, | |
converters: [ | |
[ | |
'yarn', | |
(code) => { | |
if (code.match(getNpxWithYarnRegExp())) return code.replace(getNpxWithYarnRegExp(), 'yarn exec'); | |
if (code.match(getNpmExecRegExp())) return code.replace(getNpmExecRegExp(), 'yarn exec'); | |
return npmToYarn(code, 'yarn'); | |
}, | |
], | |
[ | |
'pnpm', | |
(code) => { | |
if (code.match(getNpxWithYarnRegExp())) return code.replace(getNpxWithYarnRegExp(), 'pnpm exec'); | |
if (code.match(getNpmExecRegExp())) return code.replace(getNpmExecRegExp(), 'pnpm exec'); | |
return npmToYarn(code, 'pnpm'); | |
}, | |
], | |
], | |
}, | |
], | |
], | |
}, | |
} | |
function getNpxWithYarnRegExp() { | |
return /\bnpx\b/g; | |
} | |
function getNpmExecRegExp() { | |
return /\bnpm exec (?:-c|--call)\b/g; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment