Skip to content

Commit

Permalink
fix: error related to npm defaulting when only bun and yarn exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Strengthless committed Sep 10, 2023
1 parent bb0a0b1 commit 0491b91
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ team.

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

- `--use-bun`

Expand Down
17 changes: 17 additions & 0 deletions src/detectPackageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ deleting the conflicting lockfile if you don't need it
)
}

function printSelectingDefaultYarnMessage() {
console.info(
`${chalk.bold(
"patch-package",
)}: you have both yarn.lock and bun.lockb lockfiles
Defaulting to using ${chalk.bold("yarn")}
You can override this setting by passing --use-bun, or
deleting yarn.lock if you don't need it
`,
)
}

function checkForYarnOverride(overridePackageManager: PackageManager | null) {
if (overridePackageManager === "yarn") {
printNoYarnLockfileError()
Expand Down Expand Up @@ -86,6 +98,11 @@ export const detectPackageManager = (
if (overridePackageManager) {
return overridePackageManager
}
if (!packageLockExists && !shrinkWrapExists) {
// The only case where we don't want to default to npm is when we have both yarn and bun lockfiles.
printSelectingDefaultYarnMessage()
return "yarn"
}
printSelectingDefaultMessage()
return shrinkWrapExists ? "npm-shrinkwrap" : "npm"
} else if (packageLockExists || shrinkWrapExists) {
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ Usage:
By default, patch-package checks whether you use npm, yarn or bun based on
which lockfile you have. If you have multiple lockfiles, it uses npm by
default. Set this option to override that default and always use yarn.
default (in cases where npm is not available, it will resort to yarn). Set
this option to override that default and always use yarn.
${chalk.bold("--use-bun")}
Expand Down

0 comments on commit 0491b91

Please sign in to comment.