Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): fixed issue with version ordering now uses semver #1058

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading