diff --git a/app/composables/npm/usePackage.ts b/app/composables/npm/usePackage.ts index b8bcc2329b..e0d900f504 100644 --- a/app/composables/npm/usePackage.ts +++ b/app/composables/npm/usePackage.ts @@ -69,6 +69,12 @@ function transformPackument(pkg: Packument, requestedVersion?: string | null): S if (pkg.time[v]) filteredTime[v] = pkg.time[v] } + // Normalize license field + let license = pkg.license + if (license && typeof license === 'object' && 'type' in license) { + license = license.type + } + return { '_id': pkg._id, '_rev': pkg._rev, @@ -78,7 +84,7 @@ function transformPackument(pkg: Packument, requestedVersion?: string | null): S 'time': filteredTime, 'maintainers': pkg.maintainers, 'author': pkg.author, - 'license': pkg.license, + 'license': license, 'homepage': pkg.homepage, 'keywords': pkg.keywords, 'repository': pkg.repository, diff --git a/app/composables/usePackageComparison.ts b/app/composables/usePackageComparison.ts index 690bff4da3..d7ade7fded 100644 --- a/app/composables/usePackageComparison.ts +++ b/app/composables/usePackageComparison.ts @@ -152,7 +152,10 @@ export function usePackageComparison(packageNames: MaybeRefOrGetter) { severity: vulnsSeverity, }, metadata: { - license: pkgData.license, + license: + typeof pkgData.license === 'object' && 'type' in pkgData.license + ? pkgData.license.type + : pkgData.license, // Use version-specific publish time, NOT time.modified (which can be // updated by metadata changes like maintainer additions) lastUpdated: pkgData.time?.[latestVersion], diff --git a/shared/types/npm-registry.ts b/shared/types/npm-registry.ts index 40cab9baa6..f0652d8f6b 100644 --- a/shared/types/npm-registry.ts +++ b/shared/types/npm-registry.ts @@ -6,17 +6,17 @@ * @see https://github.com/npm/registry/blob/main/docs/REGISTRY-API.md */ -import type { PackumentVersion } from '@npm/types' +import type { Packument as PackumentWithoutLicenseObjects, PackumentVersion } from '@npm/types' import type { ReadmeResponse } from './readme' // Re-export official npm types for packument/manifest -export type { - Packument, - PackumentVersion, - Manifest, - ManifestVersion, - PackageJSON, -} from '@npm/types' +export type { PackumentVersion, Manifest, ManifestVersion, PackageJSON } from '@npm/types' + +// TODO: Remove this type override when @npm/types fixes the license field typing +export type Packument = Omit & { + // Fix for license field being incorrectly typed in @npm/types + license?: string | { type: string; url?: string } +} /** Install scripts info (preinstall, install, postinstall) */ export interface InstallScriptsInfo {