docusaurus/packages/docusaurus-remark-plugin-npm2yarn
Jake Boone 549ab795c3
feat(plugin-npm2yarn): Add Bun to default tabs conversions (#10953)
* fix(plugin-npm2yarn): Add Bun as default to align with docs

* fix(plugin-npm2yarn): update test snapshot with bunx

* fix(plugin-npm2yarn): update test snapshot with bunx-create

* fix(plugin-npm2yarn): update screenshot to add pnpm and Bun

---------

Co-authored-by: Sébastien Lorber <slorber@users.noreply.github.com>
2025-03-11 09:37:01 +01:00
..
src feat(plugin-npm2yarn): Add Bun to default tabs conversions (#10953) 2025-03-11 09:37:01 +01:00
.npmignore misc: make copyUntypedFiles work for watch mode (#7445) 2022-05-18 19:18:32 +08:00
example.png feat(plugin-npm2yarn): Add Bun to default tabs conversions (#10953) 2025-03-11 09:37:01 +01:00
package.json chore: release Docusaurus 3.7.0 (#10812) 2025-01-03 18:11:21 +01:00
README.md feat(plugin-npm2yarn): Add Bun to default tabs conversions (#10953) 2025-03-11 09:37:01 +01:00
tsconfig.json chore: simplify TypeScript configs, use TS 5.5 configDir placeholder (#10256) 2024-07-01 17:34:40 +02:00

Remark plugin npm2yarn

Motivation:

Transforms npm bash command code blocks to Docusaurus tabs:

The following (remove the //):

// ```bash npm2yarn
// npm run build
// ```

Becomes:

npm2yarn tabs example

Note: it only works when used with Docusaurus themes that have the Tabs and TabItems components.

Install

npm install @docusaurus/remark-plugin-npm2yarn

It is a Remark plugin, not a Docusaurus plugin, so you have to install it as a Remark plugin in the config of your Docusaurus plugins.

module.exports = {
  presets: [
    [
      '@docusaurus/preset-classic',
      {
        docs: {
          // ...
          remarkPlugins: [
            [require('@docusaurus/remark-plugin-npm2yarn'), {sync: true}],
          ],
        },
        blog: {
          // ...
          remarkPlugins: [
            [require('@docusaurus/remark-plugin-npm2yarn'), {sync: true}],
          ],
        },
        pages: {
          // ...
          remarkPlugins: [
            [require('@docusaurus/remark-plugin-npm2yarn'), {sync: true}],
          ],
        },
        // ...
      },
    ],
  ],
  // ...
};

Options

Property Type Default Description
sync boolean false Syncing tab choices (Yarn and npm). See https://docusaurus.io/docs/markdown-features/#syncing-tab-choices for details.
converters array ['yarn', 'pnpm', 'bun'] The list of converters to use. The order of the converters is important, as the first converter will be used as the default choice.

Custom converters

In case you want to convert npm commands to something else than yarn, pnpm or bun, you can use custom converters:

type CustomConverter = [name: string, cb: (npmCode: string) => string];
{
  remarkPlugins: [
    [
      require('@docusaurus/remark-plugin-npm2yarn'),
      {
        sync: true,
        converters: [
          'yarn',
          'pnpm',
          'bun',
          ['Turbo', (code) => code.replace(/npm/g, 'turbo')],
        ],
      },
    ],
  ];
}