Skip to content

Commit d5bfb5b

Browse files
committed
Fix "object Object" shown in Licence field and on OG image
https://npmx.dev/package/g
1 parent bf0c8f7 commit d5bfb5b

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

app/composables/npm/usePackage.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ function transformPackument(pkg: Packument, requestedVersion?: string | null): S
6969
if (pkg.time[v]) filteredTime[v] = pkg.time[v]
7070
}
7171

72+
// Normalize license field
73+
let license = pkg.license
74+
if (license && typeof license === 'object' && 'type' in license) {
75+
license = license.type
76+
}
77+
7278
return {
7379
'_id': pkg._id,
7480
'_rev': pkg._rev,
@@ -78,7 +84,7 @@ function transformPackument(pkg: Packument, requestedVersion?: string | null): S
7884
'time': filteredTime,
7985
'maintainers': pkg.maintainers,
8086
'author': pkg.author,
81-
'license': pkg.license,
87+
'license': license,
8288
'homepage': pkg.homepage,
8389
'keywords': pkg.keywords,
8490
'repository': pkg.repository,

shared/types/npm-registry.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@
66
* @see https://github.com/npm/registry/blob/main/docs/REGISTRY-API.md
77
*/
88

9-
import type { PackumentVersion } from '@npm/types'
9+
import type { Packument as PackumentWithLicenceBug, PackumentVersion } from '@npm/types'
1010
import type { ReadmeResponse } from './readme'
1111

1212
// Re-export official npm types for packument/manifest
13-
export type {
14-
Packument,
15-
PackumentVersion,
16-
Manifest,
17-
ManifestVersion,
18-
PackageJSON,
19-
} from '@npm/types'
13+
export type { PackumentVersion, Manifest, ManifestVersion, PackageJSON } from '@npm/types'
14+
15+
export type Packument = Omit<PackumentWithLicenceBug, 'license'> & {
16+
// Fix for license field being incorrectly typed in @npm/types
17+
license?: string | { type: string; url?: string }
18+
}
2019

2120
/** Install scripts info (preinstall, install, postinstall) */
2221
export interface InstallScriptsInfo {

0 commit comments

Comments
 (0)