Skip to content

Commit

Permalink
Fix version ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
garronej committed Dec 7, 2021
1 parent 30ebebd commit 331734f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 6 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3471,7 +3471,7 @@ var NpmModuleVersion;
*/
function compare(v1, v2) {
const sign = (diff) => diff === 0 ? 0 : (diff < 0 ? -1 : 1);
const noUndefined = (n) => n !== null && n !== void 0 ? n : -1;
const noUndefined = (n) => n !== null && n !== void 0 ? n : Infinity;
for (const level of ["major", "minor", "patch", "betaPreRelease"]) {
if (noUndefined(v1[level]) !== noUndefined(v2[level])) {
return sign(noUndefined(v1[level]) - noUndefined(v2[level]));
Expand All @@ -3480,6 +3480,11 @@ var NpmModuleVersion;
return 0;
}
NpmModuleVersion.compare = compare;
/*
console.log(compare(parse("3.0.0-beta.3"), parse("3.0.0")) === -1 )
console.log(compare(parse("3.0.0-beta.3"), parse("3.0.0-beta.4")) === -1 )
console.log(compare(parse("3.0.0-beta.3"), parse("4.0.0")) === -1 )
*/
function bumpType(params) {
const versionAhead = parse(params.versionAheadStr);
const versionBehind = parse(params.versionBehindStr);
Expand Down
8 changes: 7 additions & 1 deletion src/tools/NpmModuleVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export namespace NpmModuleVersion {
export function compare(v1: NpmModuleVersion, v2: NpmModuleVersion): -1 | 0 | 1 {

const sign = (diff: number): -1 | 0 | 1 => diff === 0 ? 0 : (diff < 0 ? -1 : 1);
const noUndefined= (n: number | undefined)=> n ?? -1;
const noUndefined= (n: number | undefined)=> n ?? Infinity;

for (const level of ["major", "minor", "patch", "betaPreRelease"] as const) {
if (noUndefined(v1[level]) !== noUndefined(v2[level])) {
Expand All @@ -59,6 +59,12 @@ export namespace NpmModuleVersion {

}

/*
console.log(compare(parse("3.0.0-beta.3"), parse("3.0.0")) === -1 )
console.log(compare(parse("3.0.0-beta.3"), parse("3.0.0-beta.4")) === -1 )
console.log(compare(parse("3.0.0-beta.3"), parse("4.0.0")) === -1 )
*/

export function bumpType(
params: {
versionBehindStr: string;
Expand Down

0 comments on commit 331734f

Please sign in to comment.