Skip to content

Commit

Permalink
fix(core): fixed issue with version ordering now uses semver (#1058)
Browse files Browse the repository at this point in the history
* fix(core): fixed issue with version ordering now uses semver

* Create giant-colts-carry.md
  • Loading branch information
boyney123 authored Dec 19, 2024
1 parent 1206b58 commit eb01981
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/giant-colts-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@eventcatalog/core": patch
---

fix(core): fixed issue with version ordering now uses semver
15 changes: 12 additions & 3 deletions eventcatalog/src/utils/collections/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { CollectionTypes } from '@types';
import type { CollectionEntry } from 'astro:content';
import { coerce, satisfies as satisfiesRange } from 'semver';
import { coerce, satisfies as satisfiesRange, compare } from 'semver';

export const getPreviousVersion = (version: string, versions: string[]) => {
const index = versions.indexOf(version);
Expand All @@ -22,8 +22,17 @@ export const getVersionForCollectionItem = (
.filter((i) => i.data.id === item.data.id)
.map((i) => i.data.version)
.sort();
const versions = [...new Set(allVersionsForItem)].reverse();
const latestVersion = versions[0];

// unique versions
const versions = [...new Set(allVersionsForItem)];

// Use semver to order the versions
const orderedVersions = versions.sort((a, b) => {
return compare(b, a);
});

const latestVersion = orderedVersions[0];

return { versions, latestVersion };
};

Expand Down

0 comments on commit eb01981

Please sign in to comment.