mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-23 22:17:00 +02:00
feat: support bun package manager in create-docusaurus
(#9241)
This commit is contained in:
parent
101e133f74
commit
13a8ba1528
4 changed files with 19 additions and 9 deletions
|
@ -31,7 +31,7 @@ program
|
||||||
.arguments('[siteName] [template] [rootDir]')
|
.arguments('[siteName] [template] [rootDir]')
|
||||||
.option(
|
.option(
|
||||||
'-p, --package-manager <manager>',
|
'-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(
|
.option(
|
||||||
'-s, --skip-install',
|
'-s, --skip-install',
|
||||||
|
|
|
@ -30,6 +30,7 @@ const lockfileNames = {
|
||||||
npm: 'package-lock.json',
|
npm: 'package-lock.json',
|
||||||
yarn: 'yarn.lock',
|
yarn: 'yarn.lock',
|
||||||
pnpm: 'pnpm-lock.yaml',
|
pnpm: 'pnpm-lock.yaml',
|
||||||
|
bun: 'bun.lockb',
|
||||||
};
|
};
|
||||||
|
|
||||||
type PackageManager = keyof typeof lockfileNames;
|
type PackageManager = keyof typeof lockfileNames;
|
||||||
|
@ -57,11 +58,12 @@ function findPackageManagerFromUserAgent(): PackageManager | undefined {
|
||||||
async function askForPackageManagerChoice(): Promise<PackageManager> {
|
async function askForPackageManagerChoice(): Promise<PackageManager> {
|
||||||
const hasYarn = shell.exec('yarn --version', {silent: true}).code === 0;
|
const hasYarn = shell.exec('yarn --version', {silent: true}).code === 0;
|
||||||
const hasPnpm = shell.exec('pnpm --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';
|
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))
|
.filter((p): p is string => Boolean(p))
|
||||||
.map((p) => ({title: p, value: p}));
|
.map((p) => ({title: p, value: p}));
|
||||||
|
|
||||||
|
@ -524,7 +526,11 @@ export default async function init(
|
||||||
logger.info`Installing dependencies with name=${pkgManager}...`;
|
logger.info`Installing dependencies with name=${pkgManager}...`;
|
||||||
if (
|
if (
|
||||||
shell.exec(
|
shell.exec(
|
||||||
pkgManager === 'yarn' ? 'yarn' : `${pkgManager} install --color always`,
|
pkgManager === 'yarn'
|
||||||
|
? 'yarn'
|
||||||
|
: pkgManager === 'bun'
|
||||||
|
? 'bun install'
|
||||||
|
: `${pkgManager} install --color always`,
|
||||||
{
|
{
|
||||||
env: {
|
env: {
|
||||||
...process.env,
|
...process.env,
|
||||||
|
@ -545,19 +551,21 @@ export default async function init(
|
||||||
}
|
}
|
||||||
|
|
||||||
const useNpm = pkgManager === 'npm';
|
const useNpm = pkgManager === 'npm';
|
||||||
|
const useBun = pkgManager === 'bun';
|
||||||
|
const useRunCommand = useNpm || useBun;
|
||||||
logger.success`Created name=${cdpath}.`;
|
logger.success`Created name=${cdpath}.`;
|
||||||
logger.info`Inside that directory, you can run several commands:
|
logger.info`Inside that directory, you can run several commands:
|
||||||
|
|
||||||
code=${`${pkgManager} start`}
|
code=${`${pkgManager} start`}
|
||||||
Starts the development server.
|
Starts the development server.
|
||||||
|
|
||||||
code=${`${pkgManager} ${useNpm ? 'run ' : ''}build`}
|
code=${`${pkgManager} ${useRunCommand ? 'run ' : ''}build`}
|
||||||
Bundles your website into static files for production.
|
Bundles your website into static files for production.
|
||||||
|
|
||||||
code=${`${pkgManager} ${useNpm ? 'run ' : ''}serve`}
|
code=${`${pkgManager} ${useRunCommand ? 'run ' : ''}serve`}
|
||||||
Serves the built website locally.
|
Serves the built website locally.
|
||||||
|
|
||||||
code=${`${pkgManager} deploy`}
|
code=${`${pkgManager} ${useRunCommand ? 'run ' : ''}deploy`}
|
||||||
Publishes the website to GitHub pages.
|
Publishes the website to GitHub pages.
|
||||||
|
|
||||||
We recommend that you begin by typing:
|
We recommend that you begin by typing:
|
||||||
|
|
|
@ -31,6 +31,7 @@ browserslist
|
||||||
browserstack
|
browserstack
|
||||||
buble
|
buble
|
||||||
builtins
|
builtins
|
||||||
|
bunx
|
||||||
caabernathy
|
caabernathy
|
||||||
cacheable
|
cacheable
|
||||||
callouts
|
callouts
|
||||||
|
@ -167,6 +168,7 @@ lifecycles
|
||||||
lighthouserc
|
lighthouserc
|
||||||
linkify
|
linkify
|
||||||
localizable
|
localizable
|
||||||
|
lockb
|
||||||
longpaths
|
longpaths
|
||||||
lorber
|
lorber
|
||||||
lowercased
|
lowercased
|
||||||
|
|
|
@ -47,10 +47,10 @@ Used when the template argument is a git repo. It needs to be one of:
|
||||||
|
|
||||||
### `-p, --package-manager` {#package-manager}
|
### `-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 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
|
- Interactive prompting, in case all heuristics are not present
|
||||||
|
|
||||||
### `-s, --skip-install` {#skip-install}
|
### `-s, --skip-install` {#skip-install}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue