Skip to content

Commit 1c75e5c

Browse files
committed
Add support for Bun
1 parent 1965a6b commit 1c75e5c

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
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

+9-5
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

@@ -111,6 +111,7 @@ Currently, these are the flags you can configure:
111111
For example, this configures `np` to use `unit-test` as a test script, and to use `dist` as the subdirectory to publish:
112112

113113
`package.json`
114+
114115
```json
115116
{
116117
"name": "superb-package",
@@ -122,6 +123,7 @@ For example, this configures `np` to use `unit-test` as a test script, and to us
122123
```
123124

124125
`.np-config.json`
126+
125127
```json
126128
{
127129
"testScript": "unit-test",
@@ -130,18 +132,20 @@ For example, this configures `np` to use `unit-test` as a test script, and to us
130132
```
131133

132134
`.np-config.js` or `.np-config.cjs`
135+
133136
```js
134137
module.exports = {
135-
testScript: 'unit-test',
136-
contents: 'dist'
138+
testScript: "unit-test",
139+
contents: "dist",
137140
};
138141
```
139142

140143
`.np-config.mjs`
144+
141145
```js
142146
export default {
143-
testScript: 'unit-test',
144-
contents: 'dist'
147+
testScript: "unit-test",
148+
contents: "dist",
145149
};
146150
```
147151

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
64+
publishCommand: arguments_ => ['npm', arguments_],
65+
// TODO: Bun doesn't support config get registry, this should be added in the future
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)