Skip to content

Commit 7e1b07a

Browse files
committed
fix: improve tilde constraint handling in Composer
Fixed the tilde constraint logic to properly handle different constraint levels: - ~1.2.3 allows only patch updates within 1.2.x - ~1.2 allows minor/patch updates within 1.x.x - ~1 allows minor/patch updates within 1.x.x This matches the test logic and ensures correct constraint-based filtering.
1 parent f06e2ba commit 7e1b07a

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/registry/registry-client.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -635,17 +635,26 @@ export class RegistryClient {
635635
const currentMinor = this.getMinorVersion(pkg.version)
636636
const latestMinor = this.getMinorVersion(pkg.latest)
637637

638-
// ~1.2 allows patch updates within 1.2.x
639-
if (constraint.includes('.')) {
638+
// ~1.2.3 allows patch updates within 1.2.x
639+
// ~1.2 allows minor and patch updates within 1.x.x
640+
const constraintParts = constraint.replace('~', '').split('.')
641+
if (constraintParts.length >= 3) {
642+
// ~1.2.3 - only allow patches in same minor version
640643
if (currentMajor !== latestMajor || currentMinor !== latestMinor) {
641-
this.logger.info(`Skipping ${pkg.name}: version change not allowed by ~x.y constraint`)
642-
continue // Skip if not within same minor version
644+
this.logger.info(`Skipping ${pkg.name}: version change not allowed by ~x.y.z constraint`)
645+
continue
646+
}
647+
} else if (constraintParts.length >= 2) {
648+
// ~1.2 - allow minor/patch in same major version
649+
if (currentMajor !== latestMajor) {
650+
this.logger.info(`Skipping ${pkg.name}: major version change not allowed by ~x.y constraint`)
651+
continue
643652
}
644653
} else {
645-
// ~1 allows minor and patch updates within 1.x.x
654+
// ~1 - allow minor/patch in same major version
646655
if (currentMajor !== latestMajor) {
647656
this.logger.info(`Skipping ${pkg.name}: major version change not allowed by ~x constraint`)
648-
continue // Skip if not within same major version
657+
continue
649658
}
650659
}
651660
}

0 commit comments

Comments
 (0)