Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion app/composables/npm/usePackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion app/composables/usePackageComparison.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ export function usePackageComparison(packageNames: MaybeRefOrGetter<string[]>) {
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],
Expand Down
16 changes: 8 additions & 8 deletions shared/types/npm-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<PackumentWithoutLicenseObjects, 'license'> & {
// 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 {
Expand Down
Loading