-
-
Notifications
You must be signed in to change notification settings - Fork 355
fix: correctly detect type info in badge #2173
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
Open
gameroman
wants to merge
38
commits into
npmx-dev:main
Choose a base branch
from
gameroman:fix-types-badge
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+717
−130
Open
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
4f08506
fix: correctly detect type info in badge
gameroman cdb8b16
Revert "fix: correctly detect type info in badge"
gameroman 42a0f22
feat: ai sloppity slop
gameroman 715a3d7
feat: more ai slop
gameroman 39e2967
Update [...pkg].get.ts
gameroman 3bc3166
fix
gameroman 7b62d5c
fix
gameroman c8a6737
Update package-analysis.ts
gameroman dc6d15d
Update [...pkg].get.ts
gameroman b93882b
fix
gameroman 4eb0b00
fix
gameroman 9c87ae2
Update [...pkg].get.ts
gameroman 8626a61
wip
gameroman c6fc74e
wip
gameroman 4550a9e
fix
gameroman 5781426
[autofix.ci] apply automated fixes
autofix-ci[bot] 33a2c90
Update [...pkg].get.ts
gameroman b419292
Update [...pkg].get.ts
gameroman 79ded64
[autofix.ci] apply automated fixes
autofix-ci[bot] 2377c31
[autofix.ci] apply automated fixes (attempt 2/3)
autofix-ci[bot] 751f137
Update [...pkg].get.ts
gameroman 04b30cc
wip
gameroman dc849ad
Update badge.spec.ts
gameroman d6fc700
Update badge.spec.ts
gameroman ff2c385
test: add types badge e2e test
gameroman 85a9b25
test: add another types badge e2e test
gameroman e350ac7
[autofix.ci] apply automated fixes
autofix-ci[bot] a9c3974
Update nano-stringify-object.json
gameroman ab75cdf
update fixture
gameroman 2ecefd9
[autofix.ci] apply automated fixes
autofix-ci[bot] 21eca0e
fix
gameroman 6516aa5
Merge branch 'fix-types-badge' of https://github.com/gameroman/npmx.d…
gameroman 27e560d
fix: do something weird
gameroman 1e742e6
fix: use a proper fixture
gameroman 8000756
Update cache.ts
gameroman 27cbf5c
Update cache.ts
gameroman d5c01ff
Update badge.spec.ts
gameroman f636f05
refactor: url.parse
ghostdevv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| import { getLatestVersion } from 'fast-npm-meta' | ||
| import { flattenFileTree } from '#server/utils/import-resolver' | ||
| import type { ExtendedPackageJson, TypesPackageInfo } from '#shared/utils/package-analysis' | ||
|
|
||
| /** | ||
| * Fetch the file tree from jsDelivr API. | ||
| * Returns a nested tree structure of all files in the package. | ||
|
|
@@ -83,3 +87,62 @@ export async function getPackageFileTree( | |
| tree, | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Fetch @types package info including deprecation status using fast-npm-meta. | ||
| * Returns undefined if the package doesn't exist. | ||
| */ | ||
| async function fetchTypesPackageInfo(packageName: string): Promise<TypesPackageInfo | undefined> { | ||
| const result = await getLatestVersion(packageName, { metadata: true, throw: false }) | ||
| if ('error' in result) { | ||
| return undefined | ||
| } | ||
| return { | ||
| packageName, | ||
| deprecated: result.deprecated, | ||
| } | ||
| } | ||
|
|
||
| interface AnalysisPackageJson extends ExtendedPackageJson { | ||
| readme?: string | ||
| } | ||
|
|
||
| export async function fetchPackageWithTypesAndFiles( | ||
| packageName: string, | ||
| version?: string, | ||
| ): Promise<{ | ||
| pkg: AnalysisPackageJson | ||
| typesPackage?: TypesPackageInfo | ||
| files?: Set<string> | ||
| }> { | ||
| // Fetch main package data | ||
| const encodedName = encodePackageName(packageName) | ||
| const versionSuffix = version ? `/${version}` : '/latest' | ||
|
|
||
| const pkg = await $fetch<AnalysisPackageJson>(`${NPM_REGISTRY}/${encodedName}${versionSuffix}`) | ||
|
|
||
| let typesPackage: TypesPackageInfo | undefined | ||
| let files: Set<string> | undefined | ||
|
|
||
| // Only attempt to fetch @types + file tree when the package doesn't ship its own types | ||
| if (!hasBuiltInTypes(pkg)) { | ||
| const typesPkgName = getTypesPackageName(packageName) | ||
| const resolvedVersion = pkg.version ?? version ?? 'latest' | ||
|
|
||
| // Fetch both in parallel — they're independent | ||
| const [typesResult, fileTreeResult] = await Promise.allSettled([ | ||
| fetchTypesPackageInfo(typesPkgName), | ||
| getPackageFileTree(packageName, resolvedVersion), | ||
| ]) | ||
|
|
||
| if (typesResult.status === 'fulfilled') { | ||
| typesPackage = typesResult.value | ||
| } | ||
|
|
||
| if (fileTreeResult.status === 'fulfilled') { | ||
| files = flattenFileTree(fileTreeResult.value.tree) | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| return { pkg, typesPackage, files } | ||
| } | ||
|
Comment on lines
+110
to
+148
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. can we reuse logic from other pages/endpoints? e.g. |
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.