1- import type { DependencyInfo } from '#types/extractor'
2- import type { ParsedVersion } from '#utils/version'
3- import type { DiagnosticRule , NodeDiagnosticInfo } from '..'
1+ import type { DiagnosticRule } from '..'
42import { npmxPackageUrl } from '#utils/links'
3+ import { resolveUpgradeTargetVersion } from '#utils/upgrade'
54import { formatUpgradeVersion } from '#utils/version'
6- import gt from 'semver/functions/gt'
7- import lte from 'semver/functions/lte'
8- import prerelease from 'semver/functions/prerelease'
95import { DiagnosticSeverity , Uri } from 'vscode'
106
11- function createUpgradeDiagnostic ( dep : DependencyInfo , parsed : ParsedVersion , target : string ) : NodeDiagnosticInfo {
7+ export const checkUpgrade : DiagnosticRule = ( { dep, pkg, parsed, exactVersion } ) => {
8+ if ( ! parsed || ! exactVersion )
9+ return
10+
11+ const target = resolveUpgradeTargetVersion ( pkg , exactVersion )
12+ if ( ! target )
13+ return
14+
1215 return {
1316 node : dep . versionNode ,
1417 severity : DiagnosticSeverity . Hint ,
@@ -19,30 +22,3 @@ function createUpgradeDiagnostic(dep: DependencyInfo, parsed: ParsedVersion, tar
1922 } ,
2023 }
2124}
22-
23- export const checkUpgrade : DiagnosticRule = ( { dep, pkg, parsed, exactVersion } ) => {
24- if ( ! parsed || ! exactVersion )
25- return
26-
27- if ( Object . hasOwn ( pkg . distTags , exactVersion ) )
28- return
29-
30- const { latest } = pkg . distTags
31- if ( gt ( latest , exactVersion ) )
32- return createUpgradeDiagnostic ( dep , parsed , latest )
33-
34- const currentPreId = prerelease ( exactVersion ) ?. [ 0 ]
35- if ( currentPreId == null )
36- return
37-
38- for ( const [ tag , tagVersion ] of Object . entries ( pkg . distTags ) ) {
39- if ( tag === 'latest' )
40- continue
41- if ( prerelease ( tagVersion ) ?. [ 0 ] !== currentPreId )
42- continue
43- if ( lte ( tagVersion , exactVersion ) )
44- continue
45-
46- return createUpgradeDiagnostic ( dep , parsed , tagVersion )
47- }
48- }
0 commit comments