Skip to content

Commit

Permalink
Add support for Bun
Browse files Browse the repository at this point in the history
  • Loading branch information
LitoMore committed Aug 18, 2024
1 parent 1965a6b commit 1c75e5c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"npm": ">=9",
"git": ">=2.11.0",
"yarn": ">=1.7.0",
"pnpm": ">=8"
"pnpm": ">=8",
"bun": ">=1"
},
"scripts": {
"test": "xo && ava"
Expand Down
14 changes: 9 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
- Warns about the possibility of extraneous files being published
- See exactly what will be executed with [preview mode](https://github.com/sindresorhus/np/issues/391), without pushing or publishing anything remotely
- Supports [GitHub Packages](https://github.com/features/packages)
- Supports npm 9+, Yarn (Classic and Berry), and pnpm 8+
- Supports npm 9+, Yarn (Classic and Berry), npm 8+, and Bun

### Why not

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

`package.json`

```json
{
"name": "superb-package",
Expand All @@ -122,6 +123,7 @@ For example, this configures `np` to use `unit-test` as a test script, and to us
```

`.np-config.json`

```json
{
"testScript": "unit-test",
Expand All @@ -130,18 +132,20 @@ For example, this configures `np` to use `unit-test` as a test script, and to us
```

`.np-config.js` or `.np-config.cjs`

```js
module.exports = {
testScript: 'unit-test',
contents: 'dist'
testScript: "unit-test",
contents: "dist",
};
```

`.np-config.mjs`

```js
export default {
testScript: 'unit-test',
contents: 'dist'
testScript: "unit-test",
contents: "dist",
};
```

Expand Down
15 changes: 15 additions & 0 deletions source/package-manager/configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,18 @@ export const yarnBerryConfig = {
throwOnExternalRegistry: true,
lockfiles: ['yarn.lock'],
};

/** @type {import('./types.d.ts').PackageManagerConfig} */
export const bunConfig = {
cli: 'bun',
id: 'bun',
installCommand: ['bun', ['install', '--frozen-lockfile']],
installCommandNoLockfile: ['bun', ['install', '--no-save']],
versionCommand: version => ['npm', ['version', version]],
// Bun doesn't support publishing, so we use npm instead
publishCommand: arguments_ => ['npm', arguments_],
// TODO: Bun doesn't support config get registry, this should be added in the future
getRegistryCommand: ['npm', ['config', 'get', 'registry']],
tagVersionPrefixCommand: ['npm', ['config', 'get', 'tag-version-prefix']],
lockfiles: ['bun.lockb'],
};
4 changes: 4 additions & 0 deletions source/package-manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ function configFromPackageManagerField(package_) {
return configs.yarnConfig;
}

if (packageManager === 'bun') {
return configs.bunConfig;
}

throw new Error(`Invalid package manager: ${package_.packageManager}`);
}

Expand Down

0 comments on commit 1c75e5c

Please sign in to comment.