fix: coerce weird versions
Node.js CI / CI (push) Failing after 12s
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m14s

This commit is contained in:
2026-02-03 19:19:29 -08:00
parent df608370a4
commit 0dbedfe546
2 changed files with 37 additions and 4 deletions
+13 -4
View File
@@ -42,12 +42,14 @@ const isValidSemverRange = (version: string): boolean => {
};
/**
* Removes version prefixes for comparison.
* Removes version prefixes and coerces to valid semver.
* @param version - The version string to sanitise.
* @returns The cleaned version string.
* @returns The cleaned version string, or null if invalid.
*/
const cleanVersion = (version: string): string => {
return version.replace(/^[<=>^~]+/, "");
const cleanVersion = (version: string): string | null => {
const stripped = version.replace(/^[<=>^~]+/, "");
const coerced = semver.coerce(stripped);
return coerced?.version ?? null;
};
/**
@@ -66,6 +68,8 @@ const shouldUpdate = (
}
return semver.lt(currentVersion, latestVersion);
// eslint-disable-next-line capitalized-comments -- v8 coverage ignore directive must be lowercase
/* v8 ignore start -- @preserve */
} catch (error) {
void logger.error(
`Error comparing versions: ${currentVersion} vs ${latestVersion}`,
@@ -74,6 +78,8 @@ const shouldUpdate = (
);
return false;
}
// eslint-disable-next-line capitalized-comments -- v8 coverage ignore directive must be lowercase
/* v8 ignore stop -- @preserve */
};
/**
@@ -159,6 +165,9 @@ class DependencyAnalyzerService {
}
const cleanCurrentVersion = cleanVersion(currentVersion);
if (cleanCurrentVersion === null) {
return null;
}
if (shouldUpdate(cleanCurrentVersion, latestVersion)) {
return {