Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/create-docusaurus/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
20 changes: 14 additions & 6 deletions packages/create-docusaurus/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}));

Expand Down Expand Up @@ -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,
Expand All @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions project-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ browserslist
browserstack
buble
builtins
bunx
caabernathy
cacheable
callouts
Expand Down Expand Up @@ -167,6 +168,7 @@ lifecycles
lighthouserc
linkify
localizable
lockb
longpaths
lorber
lowercased
Expand Down
4 changes: 2 additions & 2 deletions website/docs/api/misc/create-docusaurus.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down