Skip to content

Commit

Permalink
Merge pull request #21808 from abpframework/auto-merge/rel-9-0/3353
Browse files Browse the repository at this point in the history
Merge branch prerel-9.1 with rel-9.0
  • Loading branch information
maliming authored Jan 3, 2025
2 parents 9a8caef + 0fedc51 commit fcbebbb
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public async Task InstallLibsAsync(string directory)

if (!NpmHelper.IsYarnAvailable())
{
Logger.LogWarning("YARN is not installed, which may cause package inconsistency, please use YARN instead of NPM. visit https://classic.yarnpkg.com/lang/en/docs/install/ and install YARN");
Logger.LogWarning("YARN is not installed, which may cause package inconsistency. ABP uses 'npx yarn <command>' behind the scenes to prevent possible inconsistencies.");
}

Logger.LogInformation($"Found {projectPaths.Count} projects.");
Expand All @@ -66,14 +66,7 @@ public async Task InstallLibsAsync(string directory)
// angular
if (projectPath.EndsWith("angular.json"))
{
if (NpmHelper.IsYarnAvailable())
{
NpmHelper.RunYarn(projectDirectory);
}
else
{
NpmHelper.RunNpmInstall(projectDirectory, "--legacy-peer-deps");
}
NpmHelper.RunYarn(projectDirectory);
}

// MVC or BLAZOR SERVER
Expand All @@ -86,14 +79,7 @@ public async Task InstallLibsAsync(string directory)
continue;
}

if (NpmHelper.IsYarnAvailable())
{
NpmHelper.RunYarn(projectDirectory);
}
else
{
NpmHelper.RunNpmInstall(projectDirectory, "--no-audit");
}
NpmHelper.RunYarn(projectDirectory);

await CleanAndCopyResources(projectDirectory);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ protected virtual async Task RunInstallLibsAsync(string fileDirectory)
protected virtual void RunYarn(string fileDirectory)
{
Logger.LogInformation($"Running Yarn on {fileDirectory}");
CmdHelper.RunCmd($"yarn", fileDirectory);
CmdHelper.RunCmd($"npx yarn", fileDirectory);
}

protected virtual void RunNpmInstall(string fileDirectory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public async Task AddAngularPackageAsync(string directory, NpmPackageInfo npmPac
using (DirectoryHelper.ChangeCurrentDirectory(directory))
{
Logger.LogInformation("yarn add " + npmPackage.Name + versionPostfix);
CmdHelper.RunCmd("yarn add " + npmPackage.Name + versionPostfix);
CmdHelper.RunCmd("npx yarn add " + npmPackage.Name + versionPostfix);
}
}
else
Expand Down Expand Up @@ -130,7 +130,7 @@ public async Task AddMvcPackageAsync(string directory, NpmPackageInfo npmPackage
using (DirectoryHelper.ChangeCurrentDirectory(directory))
{
Logger.LogInformation("yarn add " + npmPackage.Name + versionPostfix);
CmdHelper.RunCmd("yarn add " + npmPackage.Name + versionPostfix);
CmdHelper.RunCmd("npx yarn add " + npmPackage.Name + versionPostfix);

if (skipInstallingLibs)
{
Expand Down Expand Up @@ -158,7 +158,7 @@ public async Task RemoveMvcPackageAsync(string directory, NpmPackageInfo npmPack
using (DirectoryHelper.ChangeCurrentDirectory(directory))
{
Logger.LogInformation("yarn remove " + npmPackage.Name);
CmdHelper.RunCmd("yarn remove " + npmPackage.Name);
CmdHelper.RunCmd("npx yarn remove " + npmPackage.Name);

if (skipInstallingLibs)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,11 @@ private void AddPackage(List<string> packageJsonFilePaths, string package, strin
return;
}

var yarnAvailable = NpmHelper.IsYarnAvailable();
foreach (var packageJsonFilePath in packageJsonFilePaths)
{
var directory = Path.GetDirectoryName(packageJsonFilePath).EnsureEndsWith(Path.DirectorySeparatorChar);
if (yarnAvailable)
{
NpmHelper.YarnAddPackage(package, version, directory);
}
else
{
NpmHelper.NpmInstallPackage(package, version, directory);
}

NpmHelper.YarnAddPackage(package, version, directory);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public bool IsYarnAvailable()
return version > SemanticVersion.Parse("1.20.0");
}

[Obsolete("This method is deprecated. Use 'RunYarn' instead (it uses 'npx', so there is no need for 'yarn' to be globally installed.")]
public void RunNpmInstall(string directory, params string[] args)
{
Logger.LogInformation($"Running npm install on {directory}");
Expand All @@ -58,9 +59,10 @@ public void RunNpmInstall(string directory, params string[] args)
public void RunYarn(string directory)
{
Logger.LogInformation($"Running Yarn on {directory}");
CmdHelper.RunCmd($"yarn", directory);
CmdHelper.RunCmd($"npx yarn", directory);
}

[Obsolete("This method is deprecated. Use 'YarnAddPackage' instead (it uses 'npx', so there is no need for 'yarn' to be globally installed.")]
public void NpmInstallPackage(string package, string version, string directory)
{
var packageVersion = !string.IsNullOrWhiteSpace(version) ? $"@{version}" : string.Empty;
Expand All @@ -70,7 +72,7 @@ public void NpmInstallPackage(string package, string version, string directory)
public void YarnAddPackage(string package, string version, string directory)
{
var packageVersion = !string.IsNullOrWhiteSpace(version) ? $"@{version}" : string.Empty;
CmdHelper.RunCmd("yarn add " + package + packageVersion, workingDirectory: directory);
CmdHelper.RunCmd("npx yarn add " + package + packageVersion, workingDirectory: directory);
}

public string GetInstalledNpmPackages()
Expand Down

0 comments on commit fcbebbb

Please sign in to comment.