feat: support bun package manager in create-docusaurus (#9241)

This commit is contained in:
Colin McDonnell 2023-08-24 05:49:03 -07:00 committed by GitHub
parent 101e133f74
commit 13a8ba1528
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 9 deletions

View file

@ -31,7 +31,7 @@ program
.arguments('[siteName] [template] [rootDir]')
.option(
'-p, --package-manager <manager>',
'The package manager used to install dependencies. One of yarn, npm, and pnpm.',
'The package manager used to install dependencies. One of yarn, npm, pnpm, and bun.',
)
.option(
'-s, --skip-install',

View file

@ -30,6 +30,7 @@ const lockfileNames = {
npm: 'package-lock.json',
yarn: 'yarn.lock',
pnpm: 'pnpm-lock.yaml',
bun: 'bun.lockb',
};
type PackageManager = keyof typeof lockfileNames;
@ -57,11 +58,12 @@ function findPackageManagerFromUserAgent(): PackageManager | undefined {
async function askForPackageManagerChoice(): Promise<PackageManager> {
const hasYarn = shell.exec('yarn --version', {silent: true}).code === 0;
const hasPnpm = shell.exec('pnpm --version', {silent: true}).code === 0;
const hasBun = shell.exec('bun --version', {silent: true}).code === 0;
if (!hasYarn && !hasPnpm) {
if (!hasYarn && !hasPnpm && !hasBun) {
return 'npm';
}
const choices = ['npm', hasYarn && 'yarn', hasPnpm && 'pnpm']
const choices = ['npm', hasYarn && 'yarn', hasPnpm && 'pnpm', hasBun && 'bun']
.filter((p): p is string => Boolean(p))
.map((p) => ({title: p, value: p}));
@ -524,7 +526,11 @@ export default async function init(
logger.info`Installing dependencies with name=${pkgManager}...`;
if (
shell.exec(
pkgManager === 'yarn' ? 'yarn' : `${pkgManager} install --color always`,
pkgManager === 'yarn'
? 'yarn'
: pkgManager === 'bun'
? 'bun install'
: `${pkgManager} install --color always`,
{
env: {
...process.env,
@ -545,19 +551,21 @@ export default async function init(
}
const useNpm = pkgManager === 'npm';
const useBun = pkgManager === 'bun';
const useRunCommand = useNpm || useBun;
logger.success`Created name=${cdpath}.`;
logger.info`Inside that directory, you can run several commands:
code=${`${pkgManager} start`}
Starts the development server.
code=${`${pkgManager} ${useNpm ? 'run ' : ''}build`}
code=${`${pkgManager} ${useRunCommand ? 'run ' : ''}build`}
Bundles your website into static files for production.
code=${`${pkgManager} ${useNpm ? 'run ' : ''}serve`}
code=${`${pkgManager} ${useRunCommand ? 'run ' : ''}serve`}
Serves the built website locally.
code=${`${pkgManager} deploy`}
code=${`${pkgManager} ${useRunCommand ? 'run ' : ''}deploy`}
Publishes the website to GitHub pages.
We recommend that you begin by typing: