From d17f8a84fb6a95f2280b8b2d8b58c82547d857ec Mon Sep 17 00:00:00 2001 From: LitoMore Date: Sun, 18 Aug 2024 11:48:40 +0800 Subject: [PATCH 1/3] Add support for Bun --- 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 d57d95a4..377fd970 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..d9d4e687 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 + 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'], +}; 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}`); } From 061b747bb08ced713275d91f76a16be0e3fe6ba4 Mon Sep 17 00:00:00 2001 From: LitoMore Date: Sun, 18 Aug 2024 11:59:15 +0800 Subject: [PATCH 2/3] Add related issues link --- source/package-manager/configs.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/package-manager/configs.js b/source/package-manager/configs.js index d9d4e687..47a0e7b0 100644 --- a/source/package-manager/configs.js +++ b/source/package-manager/configs.js @@ -60,9 +60,9 @@ export const bunConfig = { 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 + // 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 + // 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'], From 92d8145735352bf56f46dfe01996ba36c5222025 Mon Sep 17 00:00:00 2001 From: LitoMore Date: Sun, 18 Aug 2024 12:01:02 +0800 Subject: [PATCH 3/3] Tweaks --- source/package-manager/configs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/package-manager/configs.js b/source/package-manager/configs.js index 47a0e7b0..93afb59a 100644 --- a/source/package-manager/configs.js +++ b/source/package-manager/configs.js @@ -60,7 +60,7 @@ export const bunConfig = { 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. + // 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']],