Skip to content

Commit 0491b91

Browse files
committed
fix: error related to npm defaulting when only bun and yarn exist
1 parent bb0a0b1 commit 0491b91

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ team.
161161

162162
By default, patch-package checks whether you use npm, yarn or bun based on
163163
which lockfile you have. If you have multiple lockfiles, it uses npm by
164-
default. Set this option to override that default and always use yarn.
164+
default (in cases where npm is not available, it will resort to yarn). Set
165+
this option to override that default and always use yarn.
165166

166167
- `--use-bun`
167168

src/detectPackageManager.ts

+17
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ deleting the conflicting lockfile if you don't need it
4545
)
4646
}
4747

48+
function printSelectingDefaultYarnMessage() {
49+
console.info(
50+
`${chalk.bold(
51+
"patch-package",
52+
)}: you have both yarn.lock and bun.lockb lockfiles
53+
Defaulting to using ${chalk.bold("yarn")}
54+
You can override this setting by passing --use-bun, or
55+
deleting yarn.lock if you don't need it
56+
`,
57+
)
58+
}
59+
4860
function checkForYarnOverride(overridePackageManager: PackageManager | null) {
4961
if (overridePackageManager === "yarn") {
5062
printNoYarnLockfileError()
@@ -86,6 +98,11 @@ export const detectPackageManager = (
8698
if (overridePackageManager) {
8799
return overridePackageManager
88100
}
101+
if (!packageLockExists && !shrinkWrapExists) {
102+
// The only case where we don't want to default to npm is when we have both yarn and bun lockfiles.
103+
printSelectingDefaultYarnMessage()
104+
return "yarn"
105+
}
89106
printSelectingDefaultMessage()
90107
return shrinkWrapExists ? "npm-shrinkwrap" : "npm"
91108
} else if (packageLockExists || shrinkWrapExists) {

src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ Usage:
200200
201201
By default, patch-package checks whether you use npm, yarn or bun based on
202202
which lockfile you have. If you have multiple lockfiles, it uses npm by
203-
default. Set this option to override that default and always use yarn.
203+
default (in cases where npm is not available, it will resort to yarn). Set
204+
this option to override that default and always use yarn.
204205
205206
${chalk.bold("--use-bun")}
206207

0 commit comments

Comments
 (0)