11import type { DependencyInfo , ValidNode } from '#types/extractor'
22import type { PackageInfo } from '#utils/api/package'
33import type { ParsedVersion } from '#utils/version'
4+ import type { Engines } from 'fast-npm-meta'
45import type { Awaitable } from 'reactive-vscode'
56import type { Diagnostic , TextDocument } from 'vscode'
67import { useActiveExtractor } from '#composables/active-extractor'
@@ -14,6 +15,7 @@ import { languages } from 'vscode'
1415import { displayName } from '../../generated-meta'
1516import { checkDeprecation } from './rules/deprecation'
1617import { checkDistTag } from './rules/dist-tag'
18+ import { checkEngineMismatch } from './rules/engine-mismatch'
1719import { checkReplacement } from './rules/replacement'
1820import { checkUpgrade } from './rules/upgrade'
1921import { checkVulnerability } from './rules/vulnerability'
@@ -23,6 +25,7 @@ export interface DiagnosticContext {
2325 pkg : PackageInfo
2426 parsed : ParsedVersion | null
2527 exactVersion : string | null
28+ engines : Engines | undefined
2629}
2730
2831export interface NodeDiagnosticInfo extends Omit < Diagnostic , 'range' | 'source' > {
@@ -45,6 +48,8 @@ export function useDiagnostics() {
4548 rules . push ( checkDeprecation )
4649 if ( config . diagnostics . distTag )
4750 rules . push ( checkDistTag )
51+ if ( config . diagnostics . engineMismatch )
52+ rules . push ( checkEngineMismatch )
4853 if ( config . diagnostics . replacement )
4954 rules . push ( checkReplacement )
5055 if ( config . diagnostics . vulnerability )
@@ -83,6 +88,7 @@ export function useDiagnostics() {
8388 const targetVersion = document . version
8489
8590 const dependencies = extractor . getDependenciesInfo ( root )
91+ const engines = extractor . getEngines ?.( root )
8692 const diagnostics : Diagnostic [ ] = [ ]
8793
8894 for ( const dep of dependencies ) {
@@ -103,7 +109,7 @@ export function useDiagnostics() {
103109
104110 for ( const rule of rules ) {
105111 try {
106- const diagnostic = await rule ( { dep, pkg, parsed, exactVersion } )
112+ const diagnostic = await rule ( { dep, pkg, parsed, exactVersion, engines } )
107113 if ( isDocumentChanged ( document , targetUri , targetVersion ) )
108114 return
109115 if ( ! diagnostic )
0 commit comments