-
-
Notifications
You must be signed in to change notification settings - Fork 275
feat: add storybook playground link #1624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
49c2c0d
b38a4b5
26feb38
39259f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -120,6 +120,14 @@ export function transformPackument( | |||||||||||||||||||||
| license = license.type | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Extract storybook field from the requested version (custom package.json field) | ||||||||||||||||||||||
| const requestedPkgVersion = requestedVersion ? pkg.versions[requestedVersion] : null | ||||||||||||||||||||||
| const rawStorybook = requestedPkgVersion?.storybook | ||||||||||||||||||||||
| const storybook = | ||||||||||||||||||||||
| rawStorybook && typeof rawStorybook === 'object' && 'url' in rawStorybook | ||||||||||||||||||||||
| ? ({ url: rawStorybook.url } as { url: string }) | ||||||||||||||||||||||
| : undefined | ||||||||||||||||||||||
|
Comment on lines
126
to
129
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The type assertion on line 128 types 🛡️ Proposed fix — validate that `url` is a non-empty string const storybook =
- rawStorybook && typeof rawStorybook === 'object' && 'url' in rawStorybook
- ? (rawStorybook as { title?: string; url: string })
+ rawStorybook && typeof rawStorybook === 'object'
+ && typeof (rawStorybook as Record<string, unknown>)['url'] === 'string'
+ && ((rawStorybook as Record<string, unknown>)['url'] as string).length > 0
+ ? (rawStorybook as { title?: string; url: string })
: undefined📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| return { | ||||||||||||||||||||||
| '_id': pkg._id, | ||||||||||||||||||||||
| '_rev': pkg._rev, | ||||||||||||||||||||||
|
|
@@ -134,6 +142,7 @@ export function transformPackument( | |||||||||||||||||||||
| 'keywords': pkg.keywords, | ||||||||||||||||||||||
| 'repository': pkg.repository, | ||||||||||||||||||||||
| 'bugs': pkg.bugs, | ||||||||||||||||||||||
| ...(storybook && { storybook }), | ||||||||||||||||||||||
| 'requestedVersion': versionData, | ||||||||||||||||||||||
| 'versions': filteredVersions, | ||||||||||||||||||||||
| 'securityVersions': securityVersions, | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,6 +83,7 @@ export interface SlimPackument { | |
| 'keywords'?: string[] | ||
| 'repository'?: { type?: string; url?: string; directory?: string } | ||
| 'bugs'?: { url?: string; email?: string } | ||
| 'storybook'?: { url: string } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # Locate usePackage.ts and npm-registry.ts files
fd -t f "usePackage\\.ts" -o "npm-registry\\.ts"Repository: npmx-dev/npmx.dev Length of output: 212 🏁 Script executed: # Locate usePackage.ts and npm-registry.ts files
fd -t f "usePackage\.ts"
fd -t f "npm-registry\.ts"Repository: npmx-dev/npmx.dev Length of output: 123 🏁 Script executed: # Get context around line 86 in npm-registry.ts
wc -l shared/types/npm-registry.tsRepository: npmx-dev/npmx.dev Length of output: 93 🏁 Script executed: # Read npm-registry.ts around line 86 to see the full type definition
sed -n '70,105p' shared/types/npm-registry.tsRepository: npmx-dev/npmx.dev Length of output: 1375 🏁 Script executed: # Get file size of usePackage.ts
wc -l app/composables/npm/usePackage.tsRepository: npmx-dev/npmx.dev Length of output: 98 🏁 Script executed: # Read entire usePackage.ts
cat -n app/composables/npm/usePackage.tsRepository: npmx-dev/npmx.dev Length of output: 7211 The guard at line 127 only checks property existence, not that The condition rawStorybook && typeof rawStorybook === 'object' && typeof rawStorybook.url === 'string' |
||
| /** current version */ | ||
| 'requestedVersion': SlimPackumentVersion | null | ||
| /** Only includes dist-tag versions (with installScripts info added per version) */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 712
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 43
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 6995
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 291
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 613
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 5135
🏁 Script executed:
cat -n shared/types/npm-registry.ts | head -60Repository: npmx-dev/npmx.dev
Length of output: 2619
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 1421
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 269
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 1133
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 43
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 3876
🏁 Script executed:
rg "'storybook'" --type ts -B 5 -A 3 shared/types/npm-registry.tsRepository: npmx-dev/npmx.dev
Length of output: 433
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 1497
🏁 Script executed:
rg "interface PackumentVersion|type PackumentVersion" --type ts -A 10 -B 2Repository: npmx-dev/npmx.dev
Length of output: 1118
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 1917
🏁 Script executed:
rg "PackumentVersionWithoutAttestations\[" --type ts -A 3 -B 3Repository: npmx-dev/npmx.dev
Length of output: 606
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 103
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 2073
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 5709
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 90
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 43
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 43
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 214
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 1563
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 43
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 117
🏁 Script executed:
rg "storybook" --type ts -B 5 -A 5 app/composables/npm/usePackage.tsRepository: npmx-dev/npmx.dev
Length of output: 896
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 122
🏁 Script executed:
cat tsconfig.json | head -40Repository: npmx-dev/npmx.dev
Length of output: 380
🏁 Script executed:
rg "\"strict\"|\"noImplicitAny\"" tsconfig.jsonRepository: npmx-dev/npmx.dev
Length of output: 43
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 553
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 2090
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 43
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 717
🏁 Script executed:
rg "// Extract storybook" --type ts -B 2 -A 15Repository: npmx-dev/npmx.dev
Length of output: 1282
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 1497
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 1408
Add type-safe accessor for undeclared
storybookfield.requestedPkgVersionis typed asPackumentVersion(fromshared/types/npm-registry.ts), which does not declare astorybookproperty. Although this is a custom package.json field that the code intentionally extracts, accessing it without proper typing creates a type safety violation. Use bracket notation with a type assertion to safely access custom fields:Proposed fix
Additionally, the guard at line 127 checks only for key presence (
'url' in rawStorybook), not value validity. Theurlproperty could benull,undefined, or an empty string, making the downstream type assertion unsafe. Strengthen the validation:const storybook = rawStorybook && typeof rawStorybook === 'object' && 'url' in rawStorybook + && typeof (rawStorybook as { url?: unknown }).url === 'string' + && (rawStorybook as { url: string }).url.length > 0 ? ({ url: rawStorybook.url } as { url: string }) : undefined📝 Committable suggestion