Skip to content

Commit

Permalink
Add --use-bun to create-next-app
Browse files Browse the repository at this point in the history
  • Loading branch information
colinhacks committed Aug 2, 2023
1 parent 5c0e489 commit 3e088e9
Show file tree
Hide file tree
Showing 7 changed files with 5,504 additions and 4,951 deletions.
4 changes: 4 additions & 0 deletions docs/02-app/02-api-reference/06-create-next-app.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ Options:

Explicitly tell the CLI to bootstrap the app using Yarn

--use-bun

Explicitly tell the CLI to bootstrap the app using Bun

-e, --example [name]|[github-url]

An example to bootstrap the app with. You can use an example name
Expand Down
4 changes: 4 additions & 0 deletions packages/create-next-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ Options:

Explicitly tell the CLI to bootstrap the app using Yarn

--use-bun

Explicitly tell the CLI to bootstrap the app using Bun

-e, --example [name]|[github-url]

An example to bootstrap the app with. You can use an example name
Expand Down
6 changes: 5 additions & 1 deletion packages/create-next-app/helpers/get-pkg-manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type PackageManager = 'npm' | 'pnpm' | 'yarn'
export type PackageManager = 'npm' | 'pnpm' | 'yarn' | 'bun'

export function getPkgManager(): PackageManager {
const userAgent = process.env.npm_config_user_agent || ''
Expand All @@ -11,5 +11,9 @@ export function getPkgManager(): PackageManager {
return 'pnpm'
}

if (userAgent.startsWith('bun')) {
return 'bun'
}

return 'npm'
}
6 changes: 6 additions & 0 deletions packages/create-next-app/helpers/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function install(
let args: string[]
let command = packageManager
const useYarn = packageManager === 'yarn'
const useBun = packageManager === 'bun'

if (dependencies && dependencies.length) {
/**
Expand All @@ -57,6 +58,11 @@ export function install(
args.push('--cwd', root)
if (devDependencies) args.push('--dev')
args.push(...dependencies)
} else if (useBun) {
args = ['add', '--exact']
args.push('--cwd', root)
if (devDependencies) args.push('--development')
args.push(...dependencies)
} else {
/**
* Call `(p)npm install [--save|--save-dev] ...`.
Expand Down
11 changes: 11 additions & 0 deletions packages/create-next-app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ const program = new Commander.Command(packageJson.name)
`
Explicitly tell the CLI to bootstrap the application using Yarn
`
)
.option(
'--use-bun',
`
Explicitly tell the CLI to bootstrap the application using Bun
`
)
.option(
Expand Down Expand Up @@ -143,6 +150,8 @@ const packageManager = !!program.useNpm
? 'pnpm'
: !!program.useYarn
? 'yarn'
: !!program.useBun
? 'bun'
: getPkgManager()

async function run(): Promise<void> {
Expand Down Expand Up @@ -461,6 +470,8 @@ async function notifyUpdate(): Promise<void> {
? 'yarn global add create-next-app'
: packageManager === 'pnpm'
? 'pnpm add -g create-next-app'
: packageManager === 'bun'
? 'bun add -g create-next-app'
: 'npm i -g create-next-app'

console.log(
Expand Down
Loading

0 comments on commit 3e088e9

Please sign in to comment.