From e61f3fabf480c49e719fccaea6582749bd293e06 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Wed, 20 Jan 2021 17:16:06 +0300 Subject: [PATCH 1/2] NpmPackagesUpdater: RemoveWarningsFromVersionShowOutput resolves https://github.com/abpframework/abp/issues/7345 --- .../ProjectModification/NpmPackagesUpdater.cs | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs index d8571843fe7..7694e9acfbf 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs @@ -345,11 +345,37 @@ protected virtual void RunNpmInstall(string fileDirectory) protected virtual List GetPackageVersionList(JProperty package) { - var versionListAsJson = CmdHelper.RunCmdAndGetOutput($"npm show {package.Name} versions"); + var output = CmdHelper.RunCmdAndGetOutput($"npm show {package.Name} versions --json"); + + var versionListAsJson = RemoveWarningsFromVersionShowOutput(output); + return JsonConvert.DeserializeObject(versionListAsJson) .OrderByDescending(SemanticVersion.Parse, new VersionComparer()).ToList(); } + protected virtual string RemoveWarningsFromVersionShowOutput(string output) + { + var lines = output.Replace(Environment.NewLine, "\n").Replace("\n", Environment.NewLine).SplitToLines(); + var resultLines = new List(); + + var warningSectionEnded = false; + + foreach (var line in lines) + { + if (line.TrimEnd() == "[") + { + warningSectionEnded = true; + } + + if (warningSectionEnded) + { + resultLines.Add(line); + } + } + + return string.Join(Environment.NewLine, resultLines); + } + protected virtual bool SpecifiedVersionExists(string version, JProperty package) { var versionList = GetPackageVersionList(package); From fa1457a793b05677ff6f6855de80c331295f0830 Mon Sep 17 00:00:00 2001 From: Alper Ebicoglu Date: Thu, 21 Jan 2021 18:47:10 +0300 Subject: [PATCH 2/2] refactor RemoveWarningsFromVersionShowOutput --- .../ProjectModification/NpmPackagesUpdater.cs | 25 +++---------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs index 7694e9acfbf..8fc800c1464 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs @@ -347,33 +347,16 @@ protected virtual List GetPackageVersionList(JProperty package) { var output = CmdHelper.RunCmdAndGetOutput($"npm show {package.Name} versions --json"); - var versionListAsJson = RemoveWarningsFromVersionShowOutput(output); + var versionListAsJson = ExtractVersions(output); return JsonConvert.DeserializeObject(versionListAsJson) .OrderByDescending(SemanticVersion.Parse, new VersionComparer()).ToList(); } - protected virtual string RemoveWarningsFromVersionShowOutput(string output) + protected virtual string ExtractVersions(string output) { - var lines = output.Replace(Environment.NewLine, "\n").Replace("\n", Environment.NewLine).SplitToLines(); - var resultLines = new List(); - - var warningSectionEnded = false; - - foreach (var line in lines) - { - if (line.TrimEnd() == "[") - { - warningSectionEnded = true; - } - - if (warningSectionEnded) - { - resultLines.Add(line); - } - } - - return string.Join(Environment.NewLine, resultLines); + var arrayStart = output.IndexOf('['); + return output.Substring(arrayStart, output.IndexOf(']') - arrayStart + 1); } protected virtual bool SpecifiedVersionExists(string version, JProperty package)