Skip to content

Commit b38a4b5

Browse files
committed
fix: include storybook data in slim packument
1 parent 49c2c0d commit b38a4b5

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

app/composables/npm/usePackage.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ export function transformPackument(
120120
license = license.type
121121
}
122122

123+
// Extract storybook field from the requested version (custom package.json field)
124+
const requestedPkgVersion = requestedVersion ? pkg.versions[requestedVersion] : null
125+
const rawStorybook = requestedPkgVersion?.storybook
126+
const storybook =
127+
rawStorybook && typeof rawStorybook === 'object' && 'url' in rawStorybook
128+
? (rawStorybook as { title?: string; url: string })
129+
: undefined
130+
123131
return {
124132
'_id': pkg._id,
125133
'_rev': pkg._rev,
@@ -134,6 +142,7 @@ export function transformPackument(
134142
'keywords': pkg.keywords,
135143
'repository': pkg.repository,
136144
'bugs': pkg.bugs,
145+
...(storybook && { storybook }),
137146
'requestedVersion': versionData,
138147
'versions': filteredVersions,
139148
'securityVersions': securityVersions,

app/pages/package/[[org]]/[name].vue

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,13 @@ const { data: readmeData } = useLazyFetch<ReadmeResponse>(
109109
{ default: () => ({ html: '', mdExists: false, playgroundLinks: [], toc: [] }) },
110110
)
111111
112-
const { data: packageJson } = useLazyFetch<{ storybook?: { title: string; url: string } }>(() => {
113-
const version = requestedVersion.value ?? 'latest'
114-
return `https://cdn.jsdelivr.net/npm/${packageName.value}@${version}/package.json`
115-
})
116-
117112
const playgroundLinks = computed(() => [
118113
...readmeData.value.playgroundLinks,
119114
// Libraries with a storybook field in package.json contain a link to their deployed playground
120-
...(packageJson.value?.storybook
115+
...(pkg.value?.storybook
121116
? [
122117
{
123-
url: packageJson.value.storybook.url,
118+
url: pkg.value.storybook.url,
124119
provider: 'storybook',
125120
providerName: 'Storybook',
126121
label: 'Storybook',

shared/types/npm-registry.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export interface SlimPackument {
8383
'keywords'?: string[]
8484
'repository'?: { type?: string; url?: string; directory?: string }
8585
'bugs'?: { url?: string; email?: string }
86+
'storybook'?: { title?: string; url: string }
8687
/** current version */
8788
'requestedVersion': SlimPackumentVersion | null
8889
/** Only includes dist-tag versions (with installScripts info added per version) */

0 commit comments

Comments
 (0)