Skip to content

Commit

Permalink
fix: handling of pre-v0.1 when coercing implicit peer dependencies to…
Browse files Browse the repository at this point in the history
… minor

Previously, monoweave would throw an error if coerceImplicitPeerDependency was set to minor and a workspace peer dependency was pre-v0.1. This is because the version 0.0.x would get coerced to 0.0.0 resulting in the SemVer range of ^0.0.0. This range does not match anything, resulting in invalid peer dependencies. Related to yarnpkg/berry#5841.
  • Loading branch information
noahnu committed Mar 8, 2024
1 parent 909b6b6 commit e3df391
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@
},
"packageManager": "[email protected]+sha256.f3cc0eda8e5560e529c7147565b30faa43b4e472d90e8634d7134a37c7f59781",
"resolutions": {
"istanbul-lib-coverage": "patch:istanbul-lib-coverage@npm%3A3.2.0#./.yarn/patches/istanbul-lib-coverage-npm-3.2.0-93f84b2c8c.patch",
"@yarnpkg/core@npm:^4.0.3": "patch:@yarnpkg/core@npm%3A4.0.3#~/.yarn/patches/@yarnpkg-core-npm-4.0.3-6d77cb8f39.patch",
"@yarnpkg/core@npm:^4.0.2": "patch:@yarnpkg/core@npm%3A4.0.3#~/.yarn/patches/@yarnpkg-core-npm-4.0.3-6d77cb8f39.patch"
"istanbul-lib-coverage": "patch:istanbul-lib-coverage@npm%3A3.2.0#./.yarn/patches/istanbul-lib-coverage-npm-3.2.0-93f84b2c8c.patch"
}
}
4 changes: 4 additions & 0 deletions packages/io/src/patchPackageJsons.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ describe('Patch Package Manifests', () => {
['patch', '2.3.4', '2.3.4'],
['minor', '2.3.4', '2.3.0'],
['major', '2.3.4', '2.0.0'],
['minor', '0.0.5', '0.0.5'], // can't coerce pre-0.1 down (with minor)
['minor', '0.1.5', '0.1.0'],
['minor', '1.0.5', '1.0.0'],
['major', '0.5.0', '0.5.0'], // can't coerce pre-v1 down (with major)
] as const)(
'rounds down peer dependency to nearest %s',
async (strategy, fromVersion, expectedVersion) => {
Expand Down
8 changes: 6 additions & 2 deletions packages/io/src/patchPackageJsons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ const patchPackageJsons = async ({
if (coerceTo !== 'patch') {
const depVersion = semver.parse(dependencyVersion)
if (depVersion && !depVersion.prerelease.length) {
depVersion.patch = 0
if (coerceTo === 'major') depVersion.minor = 0
if (depVersion.minor || depVersion.major) {
depVersion.patch = 0
}
if (coerceTo === 'major' && depVersion.major) {
depVersion.minor = 0
}
dependencyVersion = depVersion.format()
}
}
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5686,7 +5686,7 @@ __metadata:
languageName: node
linkType: hard

"@yarnpkg/core@npm:4.0.3":
"@yarnpkg/core@npm:4.0.3, @yarnpkg/core@npm:^4.0.2, @yarnpkg/core@npm:^4.0.3":
version: 4.0.3
resolution: "@yarnpkg/core@npm:4.0.3"
dependencies:
Expand Down

0 comments on commit e3df391

Please sign in to comment.