mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-06 10:20:09 +02:00
fix(npm-to-yarn): add missing npm-to-yarn converter for Bun (#10803)
This commit is contained in:
parent
56ccf19063
commit
9800180f57
4 changed files with 46 additions and 4 deletions
|
@ -63,11 +63,11 @@ module.exports = {
|
|||
| 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'` | The list of converters to use. The order of the converters is important, as the first converter will be used as the default choice. |
|
||||
| `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` or `pnpm`, you can use custom converters:
|
||||
In case you want to convert npm commands to something else than `yarn`, `pnpm` or `bun`, you can use custom converters:
|
||||
|
||||
```ts
|
||||
type CustomConverter = [name: string, cb: (npmCode: string) => string];
|
||||
|
@ -83,6 +83,7 @@ type CustomConverter = [name: string, cb: (npmCode: string) => string];
|
|||
converters: [
|
||||
'yarn',
|
||||
'pnpm',
|
||||
'bun',
|
||||
['Turbo', (code) => code.replace(/npm/g, 'turbo')],
|
||||
],
|
||||
},
|
||||
|
|
|
@ -145,6 +145,30 @@ npm install --save docusaurus-plugin-name
|
|||
"
|
||||
`;
|
||||
|
||||
exports[`npm2yarn plugin work with bun converter 1`] = `
|
||||
"import Tabs from '@theme/Tabs'
|
||||
import TabItem from '@theme/TabItem'
|
||||
|
||||
## Installing a plugin
|
||||
|
||||
A plugin is usually a npm package, so you install them like other npm packages using npm.
|
||||
|
||||
<Tabs>
|
||||
<TabItem value="npm">
|
||||
\`\`\`bash
|
||||
npm install --save docusaurus-plugin-name
|
||||
\`\`\`
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="bun" label="Bun">
|
||||
\`\`\`bash
|
||||
bun add docusaurus-plugin-name
|
||||
\`\`\`
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`npm2yarn plugin work with custom converter 1`] = `
|
||||
"import Tabs from '@theme/Tabs'
|
||||
import TabItem from '@theme/TabItem'
|
||||
|
|
|
@ -109,6 +109,12 @@ describe('npm2yarn plugin', () => {
|
|||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('work with bun converter', async () => {
|
||||
const result = await processFixture('plugin', {converters: ['bun']});
|
||||
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('work with custom converter', async () => {
|
||||
const result = await processFixture('plugin', {
|
||||
converters: [['Turbo', (code) => code.replace(/npm/g, 'turbo')]],
|
||||
|
|
|
@ -20,7 +20,7 @@ import type {Transformer} from 'unified';
|
|||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
type Plugin<T> = any; // TODO fix this asap
|
||||
|
||||
type KnownConverter = 'yarn' | 'pnpm';
|
||||
type KnownConverter = 'yarn' | 'pnpm' | 'bun';
|
||||
|
||||
type CustomConverter = [name: string, cb: (npmCode: string) => string];
|
||||
|
||||
|
@ -90,7 +90,7 @@ const transformNode = (
|
|||
code: npmToYarn(npmCode, converter),
|
||||
node,
|
||||
value: converter,
|
||||
label: converter === 'yarn' ? 'Yarn' : converter,
|
||||
label: getLabelForConverter(converter),
|
||||
});
|
||||
}
|
||||
const [converterName, converterFn] = converter;
|
||||
|
@ -101,6 +101,17 @@ const transformNode = (
|
|||
});
|
||||
}
|
||||
|
||||
function getLabelForConverter(converter: KnownConverter) {
|
||||
switch (converter) {
|
||||
case 'yarn':
|
||||
return 'Yarn';
|
||||
case 'bun':
|
||||
return 'Bun';
|
||||
default:
|
||||
return converter;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
{
|
||||
type: 'mdxJsxFlowElement',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue