11import { compare , prerelease , valid } from 'semver'
22
33export interface InstallSizeDiff {
4+ direction : 'increase' | 'decrease'
45 comparisonVersion : string
56 sizeRatio : number
67 sizeIncrease : number
@@ -15,6 +16,8 @@ export interface InstallSizeDiff {
1516
1617const SIZE_INCREASE_THRESHOLD = 0.25
1718const DEP_INCREASE_THRESHOLD = 5
19+ const SIZE_DECREASE_THRESHOLD = 0.2
20+ const DEP_DECREASE_THRESHOLD = 3
1821
1922function getComparisonVersion ( pkg : SlimPackument , resolvedVersion : string ) : string | null {
2023 const isCurrentPrerelease = prerelease ( resolvedVersion ) !== null
@@ -91,12 +94,23 @@ export function useInstallSizeDiff(
9194 previous . totalSize > 0 ? ( current . totalSize - previous . totalSize ) / previous . totalSize : 0
9295 const depDiff = current . dependencyCount - previous . dependencyCount
9396
94- const sizeThresholdExceeded = sizeRatio > SIZE_INCREASE_THRESHOLD
95- const depThresholdExceeded = depDiff > DEP_INCREASE_THRESHOLD
97+ const increaseSize = sizeRatio > SIZE_INCREASE_THRESHOLD
98+ const increaseDeps = depDiff > DEP_INCREASE_THRESHOLD
99+ const decreaseSize = sizeRatio < - SIZE_DECREASE_THRESHOLD
100+ const decreaseDeps = depDiff < - DEP_DECREASE_THRESHOLD
96101
97- if ( ! sizeThresholdExceeded && ! depThresholdExceeded ) return null
102+ const isIncrease = increaseSize || increaseDeps
103+ const isDecrease =
104+ ! isIncrease && sizeRatio <= 0 && depDiff <= 0 && ( decreaseSize || decreaseDeps )
105+
106+ if ( ! isIncrease && ! isDecrease ) return null
107+
108+ const direction : 'increase' | 'decrease' = isIncrease ? 'increase' : 'decrease'
109+ const sizeThresholdExceeded = isIncrease ? increaseSize : decreaseSize
110+ const depThresholdExceeded = isIncrease ? increaseDeps : decreaseDeps
98111
99112 return {
113+ direction,
100114 comparisonVersion : cv ,
101115 sizeRatio,
102116 sizeIncrease : current . totalSize - previous . totalSize ,
0 commit comments