Skip to content
Merged
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
25 changes: 11 additions & 14 deletions services/apps/packages_worker/src/nuget/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ function isPrerelease(version: string): boolean {
return version.includes('-')
}

// NuGet stamps unlisted versions with 1900-01-01T00:00:00Z as a sentinel — treat as absent.
function parsePublishedDate(published: string | undefined): Date | null {
if (!published) return null
const date = new Date(published)
return !isNaN(date.getTime()) && date.getUTCFullYear() > 1900 ? date : null
}
Comment thread
mbani01 marked this conversation as resolved.

const SCM_HOSTS = ['github.com', 'gitlab.com', 'bitbucket.org']

function normalizeRepoUrl(url: string | undefined): string | null {
Expand Down Expand Up @@ -105,25 +112,15 @@ export function normalizeNuGetPackage(
status = 'active'
}

// NuGet stamps unlisted versions with 1900-01-01T00:00:00Z as a sentinel — exclude them.
const publishedDates = allEntries
.filter((e) => e.published)
.map((e) => new Date(e.published as string))
.filter((d) => !isNaN(d.getTime()) && d.getUTCFullYear() > 1900)
.map((e) => parsePublishedDate(e.published))
.filter((d): d is Date => d !== null)
.sort((a, b) => a.getTime() - b.getTime())

const firstReleaseAt = publishedDates.length > 0 ? publishedDates[0] : null

const latestEntry4Date = latestListedEntry ?? latestEntry
const latestReleaseAtRaw = latestEntry4Date?.published
? new Date(latestEntry4Date.published)
: null
const latestReleaseAt =
latestReleaseAtRaw &&
!isNaN(latestReleaseAtRaw.getTime()) &&
latestReleaseAtRaw.getUTCFullYear() > 1900
? latestReleaseAtRaw
: null
const latestReleaseAt = parsePublishedDate(latestEntry4Date?.published)

const totalDownloads = searchResult?.totalDownloads ?? 0

Expand All @@ -144,7 +141,7 @@ export function normalizeNuGetPackage(
const { licenses: vLicenses } = parseLicense(entry.licenseExpression, entry.licenseUrl)
return {
number: ver,
publishedAt: entry.published ? new Date(entry.published) : null,
publishedAt: parsePublishedDate(entry.published),
isLatest: ver === latestVersion,
isPrerelease: isPrerelease(ver),
isYanked: entry.listed === false,
Expand Down
Loading