Skip to content

Commit a4dcefa

Browse files
committed
fix(shared): preserve omitted components in zero-major caret ranges
Co-authored-by: GPT-6.1 Sol (Codex)
1 parent 701e13c commit a4dcefa

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎packages/shared/src/semver.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ describe("semver helpers", () => {
5959
});
6060

6161
it("honors caret range upper bounds for zero-major versions", () => {
62+
expect(satisfiesSemverRange("0.5.0", "^0")).toBe(true);
63+
expect(satisfiesSemverRange("0.0.4", "^0.0")).toBe(true);
64+
expect(satisfiesSemverRange("1.0.0", "^0")).toBe(false);
65+
expect(satisfiesSemverRange("0.1.0", "^0.0")).toBe(false);
6266
expect(satisfiesSemverRange("0.2.3", "^0.2.3")).toBe(true);
6367
expect(satisfiesSemverRange("0.2.9", "^0.2.3")).toBe(true);
6468
expect(satisfiesSemverRange("0.3.0", "^0.2.3")).toBe(false);
@@ -74,6 +78,8 @@ describe("semver helpers", () => {
7478
expect(source).toContain("function satisfiesSemverRange");
7579
expect(source).not.toContain(": string");
7680
expect(source).not.toContain(": boolean");
81+
expect(recreated("0.5.0", "^0")).toBe(true);
82+
expect(recreated("0.0.4", "^0.0")).toBe(true);
7783
expect(recreated("24.10.0", ">=24.10")).toBe(true);
7884
expect(recreated("24.9.9", ">=24.10")).toBe(false);
7985
});

‎packages/shared/src/semver.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,10 @@ export const satisfiesSemverRange: (rawVersion: string, range: string) => boolea
198198
if (compared < 0) {
199199
return false;
200200
}
201-
if (target.major > 0) {
201+
if (target.major > 0 || targetMatch[2] === undefined) {
202202
return version.major === target.major;
203203
}
204-
if (target.minor > 0) {
204+
if (target.minor > 0 || targetMatch[3] === undefined) {
205205
return version.major === 0 && version.minor === target.minor;
206206
}
207207
return version.major === 0 && version.minor === 0 && version.patch === target.patch;

0 commit comments

Comments
 (0)