MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / compareVersions

Function compareVersions

src/upgrade/index.ts:169–181  ·  view source on GitHub ↗
(a: string, b: string)

Source from the content-addressed store, hash-verified

167
168/** Returns >0 if a>b, <0 if a<b, 0 if equal. Throws on unparseable input. */
169export function compareVersions(a: string, b: string): number {
170 const sa = parseSemver(a);
171 const sb = parseSemver(b);
172 if (!sa || !sb) throw new Error(`cannot compare versions: "${a}" vs "${b}"`);
173 if (sa.major !== sb.major) return sa.major - sb.major;
174 if (sa.minor !== sb.minor) return sa.minor - sb.minor;
175 if (sa.patch !== sb.patch) return sa.patch - sb.patch;
176 // A prerelease is "less than" its release (1.0.0-rc < 1.0.0).
177 if (sa.pre && !sb.pre) return -1;
178 if (!sa.pre && sb.pre) return 1;
179 if (sa.pre && sb.pre) return sa.pre < sb.pre ? -1 : sa.pre > sb.pre ? 1 : 0;
180 return 0;
181}
182
183export function isUpdateAvailable(current: string, latest: string): boolean {
184 try {

Callers 3

upgrade.test.tsFile · 0.90
isUpdateAvailableFunction · 0.85
verifyResolvedVersionFunction · 0.85

Calls 1

parseSemverFunction · 0.85

Tested by

no test coverage detected