Skip to content

Instantly share code, notes, and snippets.

@radist2s
Last active March 17, 2024 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radist2s/a4485bd3fcf0c8d659844a3abb22527e to your computer and use it in GitHub Desktop.
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.
{
// ...
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