diff --git a/packages/create-docusaurus/bin/index.js b/packages/create-docusaurus/bin/index.js index be5e14f68965..6228ba8a0524 100755 --- a/packages/create-docusaurus/bin/index.js +++ b/packages/create-docusaurus/bin/index.js @@ -31,7 +31,7 @@ program .arguments('[siteName] [template] [rootDir]') .option( '-p, --package-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', diff --git a/packages/create-docusaurus/src/index.ts b/packages/create-docusaurus/src/index.ts index a4fba1214132..f41121d686f7 100755 --- a/packages/create-docusaurus/src/index.ts +++ b/packages/create-docusaurus/src/index.ts @@ -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 { 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: diff --git a/project-words.txt b/project-words.txt index e93b272812d8..635b97d04b91 100644 --- a/project-words.txt +++ b/project-words.txt @@ -31,6 +31,7 @@ browserslist browserstack buble builtins +bunx caabernathy cacheable callouts @@ -167,6 +168,7 @@ lifecycles lighthouserc linkify localizable +lockb longpaths lorber lowercased diff --git a/website/docs/api/misc/create-docusaurus.mdx b/website/docs/api/misc/create-docusaurus.mdx index b4dc0491e4a8..587fc51da928 100644 --- a/website/docs/api/misc/create-docusaurus.mdx +++ b/website/docs/api/misc/create-docusaurus.mdx @@ -47,10 +47,10 @@ Used when the template argument is a git repo. It needs to be one of: ### `-p, --package-manager` {#package-manager} -Value should be one of `npm`, `yarn`, or `pnpm`. If it's not explicitly provided, Docusaurus will infer one based on: +Value should be one of `npm`, `yarn`, `pnpm`, or `bun`. If it's not explicitly provided, Docusaurus will infer one based on: - The lockfile already present in the CWD (e.g. if you are setting up website in an existing project) -- The command used to invoke `create-docusaurus` (e.g. `npm init`, `npx`, `yarn create`, etc.) +- The command used to invoke `create-docusaurus` (e.g. `npm init`, `npx`, `yarn create`, `bunx`, etc.) - Interactive prompting, in case all heuristics are not present ### `-s, --skip-install` {#skip-install}