Skip to content

Add support to bun package manager #26962

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

Merged
merged 3 commits into from
Jan 25, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/angular/cli/lib/config/workspace-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"packageManager": {
"description": "Specify which package manager tool to use.",
"type": "string",
"enum": ["npm", "cnpm", "yarn", "pnpm"]
"enum": ["npm", "cnpm", "yarn", "pnpm", "bun"]
},
"warnings": {
"description": "Control CLI specific console warnings",
Expand Down Expand Up @@ -101,7 +101,7 @@
"packageManager": {
"description": "Specify which package manager tool to use.",
"type": "string",
"enum": ["npm", "cnpm", "yarn", "pnpm"]
"enum": ["npm", "cnpm", "yarn", "pnpm", "bun"]
},
"warnings": {
"description": "Control CLI specific console warnings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"description": "The preferred package manager configuration files to use for registry settings.",
"type": "string",
"default": "npm",
"enum": ["npm", "yarn", "cnpm", "pnpm"]
"enum": ["npm", "yarn", "cnpm", "pnpm", "bun"]
}
},
"required": []
Expand Down
24 changes: 21 additions & 3 deletions packages/angular/cli/src/utilities/package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ export class PackageManagerUtils {
prefix: '--prefix',
noLockfile: '--no-lockfile',
};
case PackageManager.Bun:
return {
saveDev: '--development',
install: 'add',
installAll: 'install',
prefix: '--cwd',
noLockfile: '',
};
default:
return {
saveDev: '--save-dev',
Expand Down Expand Up @@ -218,14 +226,15 @@ export class PackageManagerUtils {
const hasNpmLock = this.hasLockfile(PackageManager.Npm);
const hasYarnLock = this.hasLockfile(PackageManager.Yarn);
const hasPnpmLock = this.hasLockfile(PackageManager.Pnpm);
const hasBunLock = this.hasLockfile(PackageManager.Bun);

// PERF NOTE: `this.getVersion` spawns the package a the child_process which can take around ~300ms at times.
// Therefore, we should only call this method when needed. IE: don't call `this.getVersion(PackageManager.Pnpm)` unless truly needed.
// The result of this method is not stored in a variable because it's memoized.

if (hasNpmLock) {
// Has NPM lock file.
if (!hasYarnLock && !hasPnpmLock && this.getVersion(PackageManager.Npm)) {
if (!hasYarnLock && !hasPnpmLock && !hasBunLock && this.getVersion(PackageManager.Npm)) {
// Only NPM lock file and NPM binary is available.
return PackageManager.Npm;
}
Expand All @@ -237,18 +246,24 @@ export class PackageManagerUtils {
} else if (hasPnpmLock && this.getVersion(PackageManager.Pnpm)) {
// PNPM lock file and PNPM binary is available.
return PackageManager.Pnpm;
} else if (hasBunLock && this.getVersion(PackageManager.Bun)) {
// Bun lock file and Bun binary is available.
return PackageManager.Bun;
}
}

if (!this.getVersion(PackageManager.Npm)) {
// Doesn't have NPM installed.
const hasYarn = !!this.getVersion(PackageManager.Yarn);
const hasPnpm = !!this.getVersion(PackageManager.Pnpm);
const hasBun = !!this.getVersion(PackageManager.Bun);

if (hasYarn && !hasPnpm) {
if (hasYarn && !hasPnpm && !hasBun) {
return PackageManager.Yarn;
} else if (!hasYarn && hasPnpm) {
} else if (hasPnpm && !hasYarn && !hasBun) {
return PackageManager.Pnpm;
} else if (hasBun && !hasYarn && !hasPnpm) {
return PackageManager.Bun;
}
}

Expand All @@ -266,6 +281,9 @@ export class PackageManagerUtils {
case PackageManager.Pnpm:
lockfileName = 'pnpm-lock.yaml';
break;
case PackageManager.Bun:
lockfileName = 'bun.lockb';
break;
case PackageManager.Npm:
default:
lockfileName = 'package-lock.json';
Expand Down
6 changes: 6 additions & 0 deletions packages/angular/create/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ yarn create @angular [project-name] [...options]
```
pnpm create @angular [project-name] [...options]
```

### bun

```
bun create @angular [project-name] [...options]
```
2 changes: 1 addition & 1 deletion packages/angular/create/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const hasPackageManagerArg = args.some((a) => a.startsWith('--package-manager'))
if (!hasPackageManagerArg) {
// Ex: yarn/1.22.18 npm/? node/v16.15.1 linux x64
const packageManager = process.env['npm_config_user_agent']?.split('/')[0];
if (packageManager && ['npm', 'pnpm', 'yarn', 'cnpm'].includes(packageManager)) {
if (packageManager && ['npm', 'pnpm', 'yarn', 'cnpm', 'bun'].includes(packageManager)) {
args.push('--package-manager', packageManager);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/schematics/angular/ng-new/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
"packageManager": {
"description": "The package manager used to install dependencies.",
"type": "string",
"enum": ["npm", "yarn", "pnpm", "cnpm"]
"enum": ["npm", "yarn", "pnpm", "cnpm", "bun"]
},
"standalone": {
"description": "Creates an application based upon the standalone API, without NgModules.",
Expand Down
2 changes: 1 addition & 1 deletion packages/schematics/angular/workspace/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"packageManager": {
"description": "The package manager used to install dependencies.",
"type": "string",
"enum": ["npm", "yarn", "pnpm", "cnpm"]
"enum": ["npm", "yarn", "pnpm", "cnpm", "bun"]
}
},
"required": ["name", "version"]
Expand Down