From ce140d2ca3e1412e39a4fb3031dcc05c80575597 Mon Sep 17 00:00:00 2001 From: kerenr-jfrog Date: Sun, 20 Apr 2025 17:06:21 +0300 Subject: [PATCH] perform load npm projects async --- JFrogVSExtension/UI/Panel/Tree/TreeViewModel.cs | 2 +- JFrogVSExtension/Utils/Util.cs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/JFrogVSExtension/UI/Panel/Tree/TreeViewModel.cs b/JFrogVSExtension/UI/Panel/Tree/TreeViewModel.cs index 3b57b1c..9715ed7 100644 --- a/JFrogVSExtension/UI/Panel/Tree/TreeViewModel.cs +++ b/JFrogVSExtension/UI/Panel/Tree/TreeViewModel.cs @@ -92,7 +92,7 @@ public async Task LoadAsync(RefreshType refreshType, HashSet severitie // Load projects from output. Project[] nugetProjects = Util.LoadNugetProjects(returnedText); - Project[] npmProjects = Util.LoadNpmProjects(); + Project[] npmProjects = await Util.LoadNpmProjectsAsync(); Projects projects = new Projects { diff --git a/JFrogVSExtension/Utils/Util.cs b/JFrogVSExtension/Utils/Util.cs index 80b1810..1071f37 100644 --- a/JFrogVSExtension/Utils/Util.cs +++ b/JFrogVSExtension/Utils/Util.cs @@ -27,7 +27,7 @@ public static Project[] LoadNugetProjects(String output) return projects.NugetProjects; } - public static Project[] LoadNpmProjects() + public async static Task LoadNpmProjectsAsync() { var npmProjects = new List(); var packageJsonPaths = Directory.GetFiles(Directory.GetCurrentDirectory(), "package.json", SearchOption.AllDirectories); @@ -38,7 +38,7 @@ public static Project[] LoadNpmProjects() { continue; } - var project = LoadNpmProject(packageJsonPath); + var project = await LoadNpmProjectAsync(packageJsonPath); if (project != null) { npmProjects.Add(project); @@ -47,15 +47,15 @@ public static Project[] LoadNpmProjects() return npmProjects.ToArray(); } - private static Project LoadNpmProject(string packageJsonPath) + private async static Task LoadNpmProjectAsync(string packageJsonPath) { try { var fileInfo = new FileInfo(packageJsonPath); // Run npm ls to get the dependencies tree. The /C for the process to quit without waiting for a user's interruption. - var npmProjectTree = GetProcessOutputAsync("cmd.exe", "/C npm ls --json --all --long --package-lock-only", fileInfo.DirectoryName); + var npmProjectTree = await GetProcessOutputAsync("cmd.exe", "/C npm ls --json --all --long --package-lock-only", fileInfo.DirectoryName); - var npmProj = JsonConvert.DeserializeObject(npmProjectTree.Result); + var npmProj = JsonConvert.DeserializeObject(npmProjectTree); var project = new Project() {