Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 12 additions & 5 deletions app/composables/usePackageComparison.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
installSize?: {
selfSize: number
totalSize: number
directDepCount: number
dependencyCount: number
Comment thread
shamilkotta marked this conversation as resolved.
}
analysis?: PackageAnalysisResponse
Expand Down Expand Up @@ -188,7 +189,7 @@
const existing = cache.value.get(name)
if (existing) {
const updated = new Map(cache.value)
updated.set(name, { ...existing, installSize })

Check failure on line 192 in app/composables/usePackageComparison.ts

View workflow job for this annotation

GitHub Actions / test

Property 'directDepCount' is missing in type '{ selfSize: number; totalSize: number; dependencyCount: number; }' but required in type '{ selfSize: number; totalSize: number; directDepCount: number; dependencyCount: number; }'.
cache.value = updated
}
} catch {
Expand Down Expand Up @@ -361,11 +362,11 @@

case 'dependencies':
if (!data.installSize) return null
const depCount = data.installSize.dependencyCount
const directDepCount = data.installSize.directDepCount
return {
raw: depCount,
display: String(depCount),
status: depCount > 50 ? 'warning' : 'neutral',
raw: directDepCount,
display: String(directDepCount),
status: directDepCount > 50 ? 'warning' : 'neutral',
}

case 'deprecated':
Expand All @@ -380,7 +381,13 @@

// Coming soon facets
case 'totalDependencies':
return null
if (!data.installSize) return null
const depCount = data.installSize.dependencyCount
return {
raw: depCount,
display: String(depCount),
status: depCount > 50 ? 'warning' : 'neutral',
}
Comment on lines +385 to +391
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Include totalDependencies in the install-size loading check.
This facet now depends on install-size, but isFacetLoading (Line 231) still omits it, so the UI can show a non-loading state whilst data is pending.

Proposed fix
-    return facet === 'installSize' || facet === 'dependencies'
+    return facet === 'installSize' || facet === 'dependencies' || facet === 'totalDependencies'
🧰 Tools
🪛 Biome (2.3.13)

[error] 385-385: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Safe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


default:
return null
Expand Down
7 changes: 6 additions & 1 deletion server/utils/install-size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export interface InstallSizeResult {
selfSize: number
/** Total unpacked size including all dependencies (bytes) */
totalSize: number
/** Number of direct dependencies */
directDepCount: number
/** Number of dependencies (including transitive) */
dependencyCount: number
/** Breakdown of dependency sizes */
Expand All @@ -34,7 +36,7 @@ export interface DependencySize {
*/
export const calculateInstallSize = defineCachedFunction(
async (name: string, version: string): Promise<InstallSizeResult> => {
const resolved = await resolveDependencyTree(name, version)
const resolved = await resolveDependencyTree(name, version, { trackDepth: true })

// Separate self from dependencies
const selfKey = `${name}@${version}`
Expand All @@ -45,6 +47,7 @@ export const calculateInstallSize = defineCachedFunction(
const dependencies: DependencySize[] = []
let totalSize = selfSize
let dependencyCount = 0
let directDepCount = 0

for (const [key, dep] of resolved) {
if (key === selfKey) continue
Expand All @@ -57,6 +60,7 @@ export const calculateInstallSize = defineCachedFunction(
})
totalSize += dep.size
dependencyCount++
if (dep.depth === 'direct') directDepCount++
}

// Sort by size descending
Expand All @@ -67,6 +71,7 @@ export const calculateInstallSize = defineCachedFunction(
version,
selfSize,
totalSize,
directDepCount,
dependencyCount,
dependencies,
}
Expand Down
1 change: 0 additions & 1 deletion shared/types/comparison.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export const FACET_INFO: Record<ComparisonFacet, Omit<FacetInfo, 'id'>> = {
},
totalDependencies: {
category: 'performance',
comingSoon: true,
},
// Health
downloads: {
Expand Down
Loading