11import { marked } from 'marked' ;
22import DOMPurify from 'dompurify' ;
3- import semver from 'semver' ;
3+ import coerce from 'semver/functions/coerce' ;
4+ import gte from 'semver/functions/gte' ;
5+ import lte from 'semver/functions/lte' ;
6+ import valid from 'semver/functions/valid' ;
47
58/**
69 * @param {import('$lib/types').Task } t1
710 * @param {import('$lib/types').Task } t2
811 * @returns {-1|0|1 }
912 */
1013export function greatestVersionAsc ( t1 , t2 ) {
11- const semverValidationOptions = {
12- loose : true ,
13- includePrerelease : true
14- } ;
15- const t1Version = semver . valid ( t1 . version , semverValidationOptions ) ;
16- const t2Version = semver . valid ( t2 . version , semverValidationOptions ) ;
14+ const t1Version = validateVersion ( t1 . version ) ;
15+ const t2Version = validateVersion ( t2 . version ) ;
1716 if ( t1Version !== null && t2Version !== null ) {
18- const t1VersionLt = semver . lte ( t1Version , t2Version ) ;
17+ const t1VersionLt = lte ( t1Version , t2Version ) ;
1918 return t1VersionLt ? - 1 : 1 ;
2019 }
2120 return 0 ;
@@ -27,19 +26,32 @@ export function greatestVersionAsc(t1, t2) {
2726 * @returns {-1|0|1 }
2827 */
2928export function greatestVersionDesc ( t1 , t2 ) {
30- const semverValidationOptions = {
31- loose : true ,
32- includePrerelease : true
33- } ;
34- const t1Version = semver . valid ( t1 . version , semverValidationOptions ) ;
35- const t2Version = semver . valid ( t2 . version , semverValidationOptions ) ;
29+ const t1Version = validateVersion ( t1 . version ) ;
30+ const t2Version = validateVersion ( t2 . version ) ;
3631 if ( t1Version !== null && t2Version !== null ) {
37- const t1VersionGt = semver . gte ( t1Version , t2Version ) ;
32+ const t1VersionGt = gte ( t1Version , t2Version ) ;
3833 return t1VersionGt ? - 1 : 1 ;
3934 }
4035 return 0 ;
4136}
4237
38+ const semverValidationOptions = {
39+ loose : true ,
40+ includePrerelease : true
41+ } ;
42+
43+ /**
44+ * @param {string } version
45+ * @returns {string | null }
46+ */
47+ function validateVersion ( version ) {
48+ return (
49+ valid ( version , semverValidationOptions ) ||
50+ valid ( coerce ( version ) , semverValidationOptions ) ||
51+ null
52+ ) ;
53+ }
54+
4355/**
4456 * @param {import('$lib/types').Task } t1
4557 * @param {import('$lib/types').Task } t2
0 commit comments