From e836929fe419f7de4e54c01dea0a678fbc53e641 Mon Sep 17 00:00:00 2001 From: Stephen Zhou Date: Sat, 13 Jul 2024 18:06:59 +0800 Subject: [PATCH] fix: support x.y.z --- src/diagnostic/index.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/diagnostic/index.ts b/src/diagnostic/index.ts index 72f8fee..909b55e 100644 --- a/src/diagnostic/index.ts +++ b/src/diagnostic/index.ts @@ -28,7 +28,6 @@ export async function updateDiagnostic(document: vscode.TextDocument) { if (!configuration.depsVersionCheck.enable) return; if ( - document.uri.fsPath.includes('node_modules') || !path.basename(document.uri.fsPath).includes('package.json') || document.languageId !== 'json' ) @@ -44,12 +43,19 @@ export async function updateDiagnostic(document: vscode.TextDocument) { const parsed = getParsedByString(text); async function checkDependency(key: string) { + const nodePath = key.split('.'); + if (nodePath.length === 0) return; + + let dependencies: Record = packageJSON; + nodePath.forEach((node) => { + dependencies = dependencies[node] ?? {}; + }); await Promise.all( - Object.entries(packageJSON[key] ?? {}).map(async ([name, version]) => { + Object.entries(dependencies).map(async ([name, version]) => { if (typeof version !== 'string') return; const location = getLocation(parsed, { - path: [key, name], + path: [...nodePath, name], }); if (!location.start || !location.end) return;