Skip to content

Commit cbc6f3b

Browse files
Add support for Bun (#756)
Co-authored-by: Sindre Sorhus <[email protected]>
1 parent 8fdac0c commit cbc6f3b

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"npm": ">=9",
1313
"git": ">=2.11.0",
1414
"yarn": ">=1.7.0",
15-
"pnpm": ">=8"
15+
"pnpm": ">=8",
16+
"bun": ">=1"
1617
},
1718
"scripts": {
1819
"test": "xo && ava"

readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
- Warns about the possibility of extraneous files being published
2626
- See exactly what will be executed with [preview mode](https://github.com/sindresorhus/np/issues/391), without pushing or publishing anything remotely
2727
- Supports [GitHub Packages](https://github.com/features/packages)
28-
- Supports npm 9+, Yarn (Classic and Berry), and pnpm 8+
28+
- Supports npm 9+, Yarn (Classic and Berry), npm 8+, and Bun
2929

3030
### Why not
3131

source/package-manager/configs.js

+15
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,18 @@ export const yarnBerryConfig = {
5252
throwOnExternalRegistry: true,
5353
lockfiles: ['yarn.lock'],
5454
};
55+
56+
/** @type {import('./types.d.ts').PackageManagerConfig} */
57+
export const bunConfig = {
58+
cli: 'bun',
59+
id: 'bun',
60+
installCommand: ['bun', ['install', '--frozen-lockfile']],
61+
installCommandNoLockfile: ['bun', ['install', '--no-save']],
62+
versionCommand: version => ['npm', ['version', version]],
63+
// Bun doesn't support publishing, so we use npm instead. See https://github.com/oven-sh/bun/issues/5050
64+
publishCommand: arguments_ => ['npm', arguments_],
65+
// TODO: Bun doesn't support config get registry, this should be added in the future. See https://github.com/oven-sh/bun/issues/7140
66+
getRegistryCommand: ['npm', ['config', 'get', 'registry']],
67+
tagVersionPrefixCommand: ['npm', ['config', 'get', 'tag-version-prefix']],
68+
lockfiles: ['bun.lockb'],
69+
};

source/package-manager/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ function configFromPackageManagerField(package_) {
4646
return configs.yarnConfig;
4747
}
4848

49+
if (packageManager === 'bun') {
50+
return configs.bunConfig;
51+
}
52+
4953
throw new Error(`Invalid package manager: ${package_.packageManager}`);
5054
}
5155

0 commit comments

Comments
 (0)