Skip to content

Commit

Permalink
Sort versions based on semver (#12)
Browse files Browse the repository at this point in the history
* Sort versions based on semver

Signed-off-by: Marcos Candeia <[email protected]>

* Remove console.log

Signed-off-by: Marcos Candeia <[email protected]>

---------

Signed-off-by: Marcos Candeia <[email protected]>
  • Loading branch information
mcandeia authored Sep 14, 2024
1 parent 20819e6 commit d4c7a2a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/registry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// copied from https://deno.land/x/[email protected]
// under MIT License.

import { compare, parse } from "@std/semver";

/**
* A constructor type for creating a RegistryUrl instance.
* @typedef {new (url: string) => RegistryUrl} RegistryCtor
Expand Down Expand Up @@ -278,7 +281,9 @@ export class Jsr implements RegistryUrl {
);
}

const versions = Object.keys(json.versions).sort().reverse();
const versions = Object.keys(json.versions).sort((vsrA, vsrB) =>
compare(parse(vsrB), parse(vsrA))
);
JSR_CACHE.set(name, versions);
return versions;
} catch (err) {
Expand Down

0 comments on commit d4c7a2a

Please sign in to comment.