From cbc6f3b36353443cab125338c8d748fada53fb4a Mon Sep 17 00:00:00 2001 From: LitoMore Date: Sat, 23 Nov 2024 23:35:34 +0800 Subject: [PATCH] Add support for Bun (#756) Co-authored-by: Sindre Sorhus --- package.json | 3 ++- readme.md | 2 +- source/package-manager/configs.js | 15 +++++++++++++++ source/package-manager/index.js | 4 ++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 9757f62d..b276cab7 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "npm": ">=9", "git": ">=2.11.0", "yarn": ">=1.7.0", - "pnpm": ">=8" + "pnpm": ">=8", + "bun": ">=1" }, "scripts": { "test": "xo && ava" diff --git a/readme.md b/readme.md index c68ee7b5..22ba1d0e 100644 --- a/readme.md +++ b/readme.md @@ -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 diff --git a/source/package-manager/configs.js b/source/package-manager/configs.js index 05f9e23d..93afb59a 100644 --- a/source/package-manager/configs.js +++ b/source/package-manager/configs.js @@ -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. See https://github.com/oven-sh/bun/issues/5050 + publishCommand: arguments_ => ['npm', arguments_], + // TODO: Bun doesn't support config get registry, this should be added in the future. See https://github.com/oven-sh/bun/issues/7140 + getRegistryCommand: ['npm', ['config', 'get', 'registry']], + tagVersionPrefixCommand: ['npm', ['config', 'get', 'tag-version-prefix']], + lockfiles: ['bun.lockb'], +}; diff --git a/source/package-manager/index.js b/source/package-manager/index.js index 19279191..e779cb3c 100644 --- a/source/package-manager/index.js +++ b/source/package-manager/index.js @@ -46,6 +46,10 @@ function configFromPackageManagerField(package_) { return configs.yarnConfig; } + if (packageManager === 'bun') { + return configs.bunConfig; + } + throw new Error(`Invalid package manager: ${package_.packageManager}`); }