Skip to content

Commit b3e2067

Browse files
committed
feat(@angular/cli): add support to bun package manager
This commit adds support to use `bun` as a package manager. Closes #26837
1 parent bac79d4 commit b3e2067

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

packages/angular/cli/lib/config/workspace-schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"packageManager": {
4848
"description": "Specify which package manager tool to use.",
4949
"type": "string",
50-
"enum": ["npm", "cnpm", "yarn", "pnpm"]
50+
"enum": ["npm", "cnpm", "yarn", "pnpm", "bun"]
5151
},
5252
"warnings": {
5353
"description": "Control CLI specific console warnings",
@@ -101,7 +101,7 @@
101101
"packageManager": {
102102
"description": "Specify which package manager tool to use.",
103103
"type": "string",
104-
"enum": ["npm", "cnpm", "yarn", "pnpm"]
104+
"enum": ["npm", "cnpm", "yarn", "pnpm", "bun"]
105105
},
106106
"warnings": {
107107
"description": "Control CLI specific console warnings",

packages/angular/cli/src/commands/update/schematic/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"description": "The preferred package manager configuration files to use for registry settings.",
5858
"type": "string",
5959
"default": "npm",
60-
"enum": ["npm", "yarn", "cnpm", "pnpm"]
60+
"enum": ["npm", "yarn", "cnpm", "pnpm", "bun"]
6161
}
6262
},
6363
"required": []

packages/angular/cli/src/utilities/package-manager.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,14 @@ export class PackageManagerUtils {
141141
prefix: '--prefix',
142142
noLockfile: '--no-lockfile',
143143
};
144+
case PackageManager.Bun:
145+
return {
146+
saveDev: '--development',
147+
install: 'add',
148+
installAll: 'install',
149+
prefix: '--cwd',
150+
noLockfile: '',
151+
};
144152
default:
145153
return {
146154
saveDev: '--save-dev',
@@ -218,14 +226,15 @@ export class PackageManagerUtils {
218226
const hasNpmLock = this.hasLockfile(PackageManager.Npm);
219227
const hasYarnLock = this.hasLockfile(PackageManager.Yarn);
220228
const hasPnpmLock = this.hasLockfile(PackageManager.Pnpm);
229+
const hasBunLock = this.hasLockfile(PackageManager.Bun);
221230

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

226235
if (hasNpmLock) {
227236
// Has NPM lock file.
228-
if (!hasYarnLock && !hasPnpmLock && this.getVersion(PackageManager.Npm)) {
237+
if (!hasYarnLock && !hasPnpmLock && !hasBunLock && this.getVersion(PackageManager.Npm)) {
229238
// Only NPM lock file and NPM binary is available.
230239
return PackageManager.Npm;
231240
}
@@ -237,18 +246,24 @@ export class PackageManagerUtils {
237246
} else if (hasPnpmLock && this.getVersion(PackageManager.Pnpm)) {
238247
// PNPM lock file and PNPM binary is available.
239248
return PackageManager.Pnpm;
249+
} else if (hasBunLock && this.getVersion(PackageManager.Bun)) {
250+
// Bun lock file and Bun binary is available.
251+
return PackageManager.Bun;
240252
}
241253
}
242254

243255
if (!this.getVersion(PackageManager.Npm)) {
244256
// Doesn't have NPM installed.
245257
const hasYarn = !!this.getVersion(PackageManager.Yarn);
246258
const hasPnpm = !!this.getVersion(PackageManager.Pnpm);
259+
const hasBun = !!this.getVersion(PackageManager.Bun);
247260

248-
if (hasYarn && !hasPnpm) {
261+
if (hasYarn && !hasPnpm && !hasBun) {
249262
return PackageManager.Yarn;
250-
} else if (!hasYarn && hasPnpm) {
263+
} else if (hasPnpm && !hasYarn && !hasBun) {
251264
return PackageManager.Pnpm;
265+
} else if (hasBun && !hasYarn && !hasPnpm) {
266+
return PackageManager.Bun;
252267
}
253268
}
254269

@@ -266,6 +281,9 @@ export class PackageManagerUtils {
266281
case PackageManager.Pnpm:
267282
lockfileName = 'pnpm-lock.yaml';
268283
break;
284+
case PackageManager.Bun:
285+
lockfileName = 'bun.lockb';
286+
break;
269287
case PackageManager.Npm:
270288
default:
271289
lockfileName = 'package-lock.json';

0 commit comments

Comments
 (0)