diff --git a/nuspec/nuget/Cake.Npm.nuspec b/nuspec/nuget/Cake.Npm.nuspec index 8d5b067..97953d6 100644 --- a/nuspec/nuget/Cake.Npm.nuspec +++ b/nuspec/nuget/Cake.Npm.nuspec @@ -14,7 +14,7 @@ false cake npm cake-addin cake-build cake-contrib - https://github.com/cake-contrib/Cake.Npm/releases/tag/4.0.0 + https://github.com/cake-contrib/Cake.Npm/releases/tag/5.0.0 diff --git a/src/Cake.Npm.Tests/AddUser/NpmAddUserFixture.cs b/src/Cake.Npm.Tests/AddUser/NpmAddUserFixture.cs index efd81aa..3a05582 100644 --- a/src/Cake.Npm.Tests/AddUser/NpmAddUserFixture.cs +++ b/src/Cake.Npm.Tests/AddUser/NpmAddUserFixture.cs @@ -1,7 +1,7 @@ -using Cake.Npm.AddUser; - -namespace Cake.Npm.Tests.AddUser +namespace Cake.Npm.Tests.AddUser { + using Cake.Npm.AddUser; + internal class NpmAddUserFixture : NpmFixture { public NpmAddUserFixture() diff --git a/src/Cake.Npm.Tests/AddUser/NpmAddUserTests.cs b/src/Cake.Npm.Tests/AddUser/NpmAddUserTests.cs index c5d0b02..42e3a0b 100644 --- a/src/Cake.Npm.Tests/AddUser/NpmAddUserTests.cs +++ b/src/Cake.Npm.Tests/AddUser/NpmAddUserTests.cs @@ -1,9 +1,9 @@ -using System; -using Xunit; -using Cake.Npm.AddUser; - -namespace Cake.Npm.Tests.AddUser +namespace Cake.Npm.Tests.AddUser { + using System; + using Xunit; + using Cake.Npm.AddUser; + public class NpmAddUserTests { public sealed class TheAddUserMethod diff --git a/src/Cake.Npm.Tests/Ci/NpmCiToolFixture.cs b/src/Cake.Npm.Tests/Ci/NpmCiToolFixture.cs index 9433886..6cbdad5 100644 --- a/src/Cake.Npm.Tests/Ci/NpmCiToolFixture.cs +++ b/src/Cake.Npm.Tests/Ci/NpmCiToolFixture.cs @@ -1,7 +1,7 @@ -using Cake.Npm.Ci; - -namespace Cake.Npm.Tests.Ci +namespace Cake.Npm.Tests.Ci { + using Cake.Npm.Ci; + internal sealed class NpmCiToolFixture : NpmFixture { public NpmCiToolFixture() diff --git a/src/Cake.Npm.Tests/Ci/NpmCiToolTests.cs b/src/Cake.Npm.Tests/Ci/NpmCiToolTests.cs index c5b9e1f..3a277c9 100644 --- a/src/Cake.Npm.Tests/Ci/NpmCiToolTests.cs +++ b/src/Cake.Npm.Tests/Ci/NpmCiToolTests.cs @@ -1,10 +1,10 @@ -using System; -using Cake.Core.Diagnostics; -using Cake.Npm.Ci; -using Xunit; - -namespace Cake.Npm.Tests.Ci +namespace Cake.Npm.Tests.Ci { + using System; + using Cake.Core.Diagnostics; + using Cake.Npm.Ci; + using Xunit; + public class NpmCiToolTests { public sealed class TheAutomatedInstallMethod diff --git a/src/Cake.Npm.Tests/Install/NpmInstallerFixture.cs b/src/Cake.Npm.Tests/Install/NpmInstallerFixture.cs index f99f42b..d438ff6 100644 --- a/src/Cake.Npm.Tests/Install/NpmInstallerFixture.cs +++ b/src/Cake.Npm.Tests/Install/NpmInstallerFixture.cs @@ -1,7 +1,7 @@ -using Cake.Npm.Install; - -namespace Cake.Npm.Tests.Install +namespace Cake.Npm.Tests.Install { + using Cake.Npm.Install; + internal sealed class NpmInstallerFixture : NpmFixture { public NpmInstallerFixture() diff --git a/src/Cake.Npm.Tests/Install/NpmInstallerTests.cs b/src/Cake.Npm.Tests/Install/NpmInstallerTests.cs index c852e8e..5dbbc90 100644 --- a/src/Cake.Npm.Tests/Install/NpmInstallerTests.cs +++ b/src/Cake.Npm.Tests/Install/NpmInstallerTests.cs @@ -1,10 +1,10 @@ -using System; -using Cake.Core.Diagnostics; -using Xunit; -using Cake.Npm.Install; - -namespace Cake.Npm.Tests.Install +namespace Cake.Npm.Tests.Install { + using System; + using Cake.Core.Diagnostics; + using Xunit; + using Cake.Npm.Install; + public class NpmInstallerTests { public sealed class TheInstallMethod diff --git a/src/Cake.Npm.Tests/Set/NpmSetToolFixture.cs b/src/Cake.Npm.Tests/Set/NpmSetToolFixture.cs index 89ce94b..55184ea 100644 --- a/src/Cake.Npm.Tests/Set/NpmSetToolFixture.cs +++ b/src/Cake.Npm.Tests/Set/NpmSetToolFixture.cs @@ -1,7 +1,7 @@ -using Cake.Npm.Set; - -namespace Cake.Npm.Tests.Set +namespace Cake.Npm.Tests.Set { + using Cake.Npm.Set; + internal sealed class NpmSetToolFixture : NpmFixture { public NpmSetToolFixture() diff --git a/src/Cake.Npm.Tests/Set/NpmSetToolTests.cs b/src/Cake.Npm.Tests/Set/NpmSetToolTests.cs index 3f02669..5002f3e 100644 --- a/src/Cake.Npm.Tests/Set/NpmSetToolTests.cs +++ b/src/Cake.Npm.Tests/Set/NpmSetToolTests.cs @@ -1,9 +1,9 @@ -using Cake.Npm.Set; -using Shouldly; -using Xunit; - -namespace Cake.Npm.Tests.Set +namespace Cake.Npm.Tests.Set { + using Cake.Npm.Set; + using Shouldly; + using Xunit; + public class NpmSetToolTests { public sealed class TheSetMethod diff --git a/src/Cake.Npm.Tests/Update/NpmUpdateToolFixture.cs b/src/Cake.Npm.Tests/Update/NpmUpdateToolFixture.cs index 12191b7..f3e4447 100644 --- a/src/Cake.Npm.Tests/Update/NpmUpdateToolFixture.cs +++ b/src/Cake.Npm.Tests/Update/NpmUpdateToolFixture.cs @@ -1,7 +1,7 @@ -using Cake.Npm.Update; - -namespace Cake.Npm.Tests.Update +namespace Cake.Npm.Tests.Update { + using Cake.Npm.Update; + internal sealed class NpmUpdateToolFixture : NpmFixture { public NpmUpdateToolFixture() diff --git a/src/Cake.Npm.Tests/Update/NpmUpdateToolTests.cs b/src/Cake.Npm.Tests/Update/NpmUpdateToolTests.cs index c8700a1..0cbbabb 100644 --- a/src/Cake.Npm.Tests/Update/NpmUpdateToolTests.cs +++ b/src/Cake.Npm.Tests/Update/NpmUpdateToolTests.cs @@ -1,8 +1,8 @@ -using Cake.Npm.Update; -using Xunit; - -namespace Cake.Npm.Tests.Update +namespace Cake.Npm.Tests.Update { + using Cake.Npm.Update; + using Xunit; + public class NpmUpdateToolTests { public sealed class TheUpdateMethod diff --git a/src/Cake.Npm.Tests/Version/NpmVersionToolFixture.cs b/src/Cake.Npm.Tests/Version/NpmVersionToolFixture.cs index f0b42da..3b62306 100644 --- a/src/Cake.Npm.Tests/Version/NpmVersionToolFixture.cs +++ b/src/Cake.Npm.Tests/Version/NpmVersionToolFixture.cs @@ -1,8 +1,8 @@ -using System.Text; -using Cake.Npm.Version; - -namespace Cake.Npm.Tests.Version +namespace Cake.Npm.Tests.Version { + using System.Text; + using Cake.Npm.Version; + internal sealed class NpmVersionToolFixture : NpmFixture { public NpmVersionToolFixture() diff --git a/src/Cake.Npm.Tests/Version/NpmVersionToolTests.cs b/src/Cake.Npm.Tests/Version/NpmVersionToolTests.cs index b97507a..ba05060 100644 --- a/src/Cake.Npm.Tests/Version/NpmVersionToolTests.cs +++ b/src/Cake.Npm.Tests/Version/NpmVersionToolTests.cs @@ -1,9 +1,9 @@ -using Cake.Core; -using Shouldly; -using Xunit; - -namespace Cake.Npm.Tests.Version +namespace Cake.Npm.Tests.Version { + using Cake.Core; + using Shouldly; + using Xunit; + public class NpmVersionToolTests { public sealed class TheVersionMethod @@ -40,8 +40,8 @@ public void Should_Add_Mandatory_Arguments() [Fact] public void Should_Determine_Version_From_StandardOutput() { - string[] versionInfo = new[] - { + string[] versionInfo = + [ "{", " npm: '5.8.0',", " ares: '1.10.1-DEV',", @@ -66,7 +66,7 @@ public void Should_Determine_Version_From_StandardOutput() "│ Run npm i -g npm to update │", "│ │", "╰─────────────────────────────────────╯" - }; + ]; // Given var fixture = new NpmVersionToolFixture(); diff --git a/src/Cake.Npm.Tests/ViewVersion/NpmViewVersionToolTests.cs b/src/Cake.Npm.Tests/ViewVersion/NpmViewVersionToolTests.cs index ce664fa..d5e83e0 100644 --- a/src/Cake.Npm.Tests/ViewVersion/NpmViewVersionToolTests.cs +++ b/src/Cake.Npm.Tests/ViewVersion/NpmViewVersionToolTests.cs @@ -100,7 +100,7 @@ public void Should_Return_Version_From_StandardOutput() const string version = "1.1.0"; // Given - fixture.ProcessRunner.Process.SetStandardOutput(new[] { version }); + fixture.ProcessRunner.Process.SetStandardOutput([version]); // When fixture.Run(); diff --git a/src/Cake.Npm/AddUser/NpmAddUser.cs b/src/Cake.Npm/AddUser/NpmAddUser.cs index 4465611..6f4219d 100644 --- a/src/Cake.Npm/AddUser/NpmAddUser.cs +++ b/src/Cake.Npm/AddUser/NpmAddUser.cs @@ -9,25 +9,18 @@ /// /// Tool for adding a user registry account. /// - public class NpmAddUser : NpmTool + /// The file system. + /// The environment. + /// The process runner. + /// The tool locator. + /// Cake log instance. + public class NpmAddUser( + IFileSystem fileSystem, + ICakeEnvironment environment, + IProcessRunner processRunner, + IToolLocator tools, + ICakeLog log) : NpmTool(fileSystem, environment, processRunner, tools, log) { - /// - /// Initializes a new instance of the class. - /// - /// The file system. - /// The environment. - /// The process runner. - /// The tool locator. - /// Cake log instance. - public NpmAddUser( - IFileSystem fileSystem, - ICakeEnvironment environment, - IProcessRunner processRunner, - IToolLocator tools, - ICakeLog log) - : base(fileSystem, environment, processRunner, tools, log) - { - } /// /// Adds a user from the specified settings. @@ -35,10 +28,7 @@ public NpmAddUser( /// The settings. public void AddUser(NpmAddUserSettings settings) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); RunCore(settings); } diff --git a/src/Cake.Npm/AddUser/NpmAddUserSettingsExtensions.cs b/src/Cake.Npm/AddUser/NpmAddUserSettingsExtensions.cs index abf1103..0bfa92e 100644 --- a/src/Cake.Npm/AddUser/NpmAddUserSettingsExtensions.cs +++ b/src/Cake.Npm/AddUser/NpmAddUserSettingsExtensions.cs @@ -15,10 +15,7 @@ public static class NpmAddUserSettingsExtensions /// The instance with set to . public static NpmAddUserSettings ForRegistry(this NpmAddUserSettings settings, Uri registry) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); settings.Registry = registry ?? throw new ArgumentNullException(nameof(registry)); return settings; @@ -32,11 +29,8 @@ public static NpmAddUserSettings ForRegistry(this NpmAddUserSettings settings, U /// The instance with added to . public static NpmAddUserSettings ForScope(this NpmAddUserSettings settings, string scope) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } - + ArgumentNullException.ThrowIfNull(settings); + if (string.IsNullOrWhiteSpace(scope)) { throw new ArgumentNullException(nameof(scope)); @@ -57,10 +51,7 @@ public static NpmAddUserSettings ForScope(this NpmAddUserSettings settings, stri /// The instance with AlwaysAuth set to true. public static NpmAddUserSettings AlwaysAuthenticate(this NpmAddUserSettings settings) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); settings.AlwaysAuth = true; return settings; @@ -74,11 +65,8 @@ public static NpmAddUserSettings AlwaysAuthenticate(this NpmAddUserSettings sett /// The instance with added to . public static NpmAddUserSettings UsingAuthentication(this NpmAddUserSettings settings, AuthType authType) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } - + ArgumentNullException.ThrowIfNull(settings); + settings.AuthType = authType; return settings; } diff --git a/src/Cake.Npm/AddinInformation.cs b/src/Cake.Npm/AddinInformation.cs index d55d869..bead09a 100644 --- a/src/Cake.Npm/AddinInformation.cs +++ b/src/Cake.Npm/AddinInformation.cs @@ -1,8 +1,8 @@ -using System.Reflection; -using Cake.Core.Diagnostics; - namespace Cake.Npm { + using System.Reflection; + using Cake.Core.Diagnostics; + /// /// Helper to log addin version information /// diff --git a/src/Cake.Npm/BumpVersion/NpmBumpVersionSettingsExtensions.cs b/src/Cake.Npm/BumpVersion/NpmBumpVersionSettingsExtensions.cs index 9d96ce9..419c1cb 100644 --- a/src/Cake.Npm/BumpVersion/NpmBumpVersionSettingsExtensions.cs +++ b/src/Cake.Npm/BumpVersion/NpmBumpVersionSettingsExtensions.cs @@ -15,10 +15,7 @@ public static class NpmBumpVersionSettingsExtensions /// The instance with set. public static NpmBumpVersionSettings WithForce(this NpmBumpVersionSettings settings, bool force = true) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); settings.Force = force; return settings; @@ -32,10 +29,7 @@ public static NpmBumpVersionSettings WithForce(this NpmBumpVersionSettings setti /// The instance with set. public static NpmBumpVersionSettings WithCommitMessage(this NpmBumpVersionSettings settings, string message) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); settings.CommitMessage = message; return settings; @@ -49,10 +43,7 @@ public static NpmBumpVersionSettings WithCommitMessage(this NpmBumpVersionSettin /// The instance with set. public static NpmBumpVersionSettings WithVersion(this NpmBumpVersionSettings settings, string version) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); settings.Version = version; return settings; diff --git a/src/Cake.Npm/BumpVersion/NpmBumpVersionTool.cs b/src/Cake.Npm/BumpVersion/NpmBumpVersionTool.cs index 1d8ca52..ce1dbd1 100644 --- a/src/Cake.Npm/BumpVersion/NpmBumpVersionTool.cs +++ b/src/Cake.Npm/BumpVersion/NpmBumpVersionTool.cs @@ -10,25 +10,18 @@ /// /// Tool for bumping the version. /// - public class NpmBumpVersionTool : NpmTool + /// The file system. + /// The environment. + /// The process runner. + /// The tool locator. + /// Cake log instance. + public class NpmBumpVersionTool( + IFileSystem fileSystem, + ICakeEnvironment environment, + IProcessRunner processRunner, + IToolLocator tools, + ICakeLog log) : NpmTool(fileSystem, environment, processRunner, tools, log) { - /// - /// Initializes a new instance of the class. - /// - /// The file system. - /// The environment. - /// The process runner. - /// The tool locator. - /// Cake log instance. - public NpmBumpVersionTool( - IFileSystem fileSystem, - ICakeEnvironment environment, - IProcessRunner processRunner, - IToolLocator tools, - ICakeLog log) - : base(fileSystem, environment, processRunner, tools, log) - { - } /// /// Calls npm version to bump a version. @@ -36,10 +29,7 @@ public NpmBumpVersionTool( /// The settings. public void BumpVersion(NpmBumpVersionSettings settings) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); RunCore(settings); } diff --git a/src/Cake.Npm/Ci/NpmCiSettings.cs b/src/Cake.Npm/Ci/NpmCiSettings.cs index 16eecc0..616873c 100644 --- a/src/Cake.Npm/Ci/NpmCiSettings.cs +++ b/src/Cake.Npm/Ci/NpmCiSettings.cs @@ -1,9 +1,9 @@ -using Cake.Core; -using Cake.Core.IO; -using System; - -namespace Cake.Npm.Ci +namespace Cake.Npm.Ci { + using Cake.Core; + using Cake.Core.IO; + using System; + /// /// Contains settings used by . /// diff --git a/src/Cake.Npm/Ci/NpmCiSettingsExtensions.cs b/src/Cake.Npm/Ci/NpmCiSettingsExtensions.cs index 8813cd9..6e025e4 100644 --- a/src/Cake.Npm/Ci/NpmCiSettingsExtensions.cs +++ b/src/Cake.Npm/Ci/NpmCiSettingsExtensions.cs @@ -1,9 +1,6 @@ -using Cake.Npm.Ci; - -namespace Cake.Npm.Ci +namespace Cake.Npm.Ci { using System; - using Core; /// /// Extensions for . @@ -18,10 +15,7 @@ public static class NpmCiSettingsExtensions /// The instance with set to true. public static NpmCiSettings ForProduction(this NpmCiSettings settings) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); settings.Production = true; return settings; @@ -35,10 +29,7 @@ public static NpmCiSettings ForProduction(this NpmCiSettings settings) /// The instance with set to . public static NpmCiSettings FromRegistry(this NpmCiSettings settings, Uri registry) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); settings.Registry = registry ?? throw new ArgumentNullException(nameof(registry)); return settings; diff --git a/src/Cake.Npm/Ci/NpmCiTool.cs b/src/Cake.Npm/Ci/NpmCiTool.cs index 57ae770..dd678bf 100644 --- a/src/Cake.Npm/Ci/NpmCiTool.cs +++ b/src/Cake.Npm/Ci/NpmCiTool.cs @@ -9,25 +9,18 @@ /// /// Tool for installing all npm packages for a project from package-lock.json. /// - public class NpmCiTool : NpmTool + /// The file system. + /// The environment. + /// The process runner. + /// The tool locator. + /// Cake log instance. + public class NpmCiTool( + IFileSystem fileSystem, + ICakeEnvironment environment, + IProcessRunner processRunner, + IToolLocator tools, + ICakeLog log) : NpmTool(fileSystem, environment, processRunner, tools, log) { - /// - /// Initializes a new instance of the class. - /// - /// The file system. - /// The environment. - /// The process runner. - /// The tool locator. - /// Cake log instance. - public NpmCiTool( - IFileSystem fileSystem, - ICakeEnvironment environment, - IProcessRunner processRunner, - IToolLocator tools, - ICakeLog log) - : base(fileSystem, environment, processRunner, tools, log) - { - } /// /// Installs all npm packages from the specified settings. @@ -35,10 +28,7 @@ public NpmCiTool( /// The settings. public void Install(NpmCiSettings settings) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); RunCore(settings); } diff --git a/src/Cake.Npm/Install/NpmInstallSettings.cs b/src/Cake.Npm/Install/NpmInstallSettings.cs index 25ef762..a9d7c96 100644 --- a/src/Cake.Npm/Install/NpmInstallSettings.cs +++ b/src/Cake.Npm/Install/NpmInstallSettings.cs @@ -11,7 +11,7 @@ /// public class NpmInstallSettings : NpmSettings { - private readonly List _packages = new(); + private readonly List _packages = []; /// /// Initializes a new instance of the class. diff --git a/src/Cake.Npm/Install/NpmInstallSettingsExtensions.cs b/src/Cake.Npm/Install/NpmInstallSettingsExtensions.cs index 6888bea..d6ba7ef 100644 --- a/src/Cake.Npm/Install/NpmInstallSettingsExtensions.cs +++ b/src/Cake.Npm/Install/NpmInstallSettingsExtensions.cs @@ -16,10 +16,7 @@ public static class NpmInstallSettingsExtensions /// The instance with set to true. public static NpmInstallSettings WithForce(this NpmInstallSettings settings) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); return settings.WithForce(true); } @@ -31,10 +28,7 @@ public static NpmInstallSettings WithForce(this NpmInstallSettings settings) /// The instance with set to false. public static NpmInstallSettings WithoutForce(this NpmInstallSettings settings) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); return settings.WithForce(false); } @@ -48,10 +42,7 @@ public static NpmInstallSettings WithoutForce(this NpmInstallSettings settings) /// The instance with set to . public static NpmInstallSettings WithForce(this NpmInstallSettings settings, bool value) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); settings.Force = value; return settings; @@ -64,10 +55,7 @@ public static NpmInstallSettings WithForce(this NpmInstallSettings settings, boo /// The instance with set to true. public static NpmInstallSettings InstallGlobally(this NpmInstallSettings settings) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); settings.Global = true; return settings; @@ -80,10 +68,7 @@ public static NpmInstallSettings InstallGlobally(this NpmInstallSettings setting /// The instance with set to false. public static NpmInstallSettings InstallLocally(this NpmInstallSettings settings) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); settings.Global = false; return settings; @@ -96,10 +81,7 @@ public static NpmInstallSettings InstallLocally(this NpmInstallSettings settings /// The instance with set to true. public static NpmInstallSettings ForProduction(this NpmInstallSettings settings) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); settings.Production = true; return settings; @@ -112,10 +94,7 @@ public static NpmInstallSettings ForProduction(this NpmInstallSettings settings) /// The instance with set to true. public static NpmInstallSettings WithoutOptionalDependencies(this NpmInstallSettings settings) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); return settings.WithNoOptional(true); } @@ -127,10 +106,7 @@ public static NpmInstallSettings WithoutOptionalDependencies(this NpmInstallSett /// The instance with set to false. public static NpmInstallSettings WithOptionalDependencies(this NpmInstallSettings settings) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); return settings.WithNoOptional(false); } @@ -143,10 +119,7 @@ public static NpmInstallSettings WithOptionalDependencies(this NpmInstallSetting /// The instance with set to . public static NpmInstallSettings WithNoOptional(this NpmInstallSettings settings, bool value) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); settings.NoOptional = value; return settings; @@ -160,15 +133,9 @@ public static NpmInstallSettings WithNoOptional(this NpmInstallSettings settings /// The instance with added to . public static NpmInstallSettings AddPackage(this NpmInstallSettings settings, Uri url) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); - if (url == null) - { - throw new ArgumentNullException(nameof(url)); - } + ArgumentNullException.ThrowIfNull(url); if (!url.IsAbsoluteUri) { @@ -187,10 +154,7 @@ public static NpmInstallSettings AddPackage(this NpmInstallSettings settings, Ur /// The instance with added to . public static NpmInstallSettings AddPackage(this NpmInstallSettings settings, string packageName) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); if (string.IsNullOrWhiteSpace(packageName)) { @@ -209,10 +173,7 @@ public static NpmInstallSettings AddPackage(this NpmInstallSettings settings, st /// The instance with added to . public static NpmInstallSettings AddPackage(this NpmInstallSettings settings, string packageName, string versionOrTag) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); if (string.IsNullOrWhiteSpace(packageName)) { @@ -236,10 +197,7 @@ public static NpmInstallSettings AddPackage(this NpmInstallSettings settings, st /// The instance with added to . public static NpmInstallSettings AddScopedPackage(this NpmInstallSettings settings, string packageName, string scope) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); if (string.IsNullOrWhiteSpace(packageName)) { @@ -264,10 +222,7 @@ public static NpmInstallSettings AddScopedPackage(this NpmInstallSettings settin /// The instance with added to . public static NpmInstallSettings AddPackage(this NpmInstallSettings settings, string packageName, string scope, string versionOrTag) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); if (string.IsNullOrWhiteSpace(packageName)) { @@ -309,10 +264,7 @@ public static NpmInstallSettings AddPackage(this NpmInstallSettings settings, st /// The instance with set to . public static NpmInstallSettings FromRegistry(this NpmInstallSettings settings, Uri registry) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); settings.Registry = registry ?? throw new ArgumentNullException(nameof(registry)); return settings; diff --git a/src/Cake.Npm/Install/NpmInstaller.cs b/src/Cake.Npm/Install/NpmInstaller.cs index 9419832..02681a6 100644 --- a/src/Cake.Npm/Install/NpmInstaller.cs +++ b/src/Cake.Npm/Install/NpmInstaller.cs @@ -9,25 +9,18 @@ /// /// Tool for installing npm modules. /// - public class NpmInstaller : NpmTool + /// The file system. + /// The environment. + /// The process runner. + /// The tool locator. + /// Cake log instance. + public class NpmInstaller( + IFileSystem fileSystem, + ICakeEnvironment environment, + IProcessRunner processRunner, + IToolLocator tools, + ICakeLog log) : NpmTool(fileSystem, environment, processRunner, tools, log) { - /// - /// Initializes a new instance of the class. - /// - /// The file system. - /// The environment. - /// The process runner. - /// The tool locator. - /// Cake log instance. - public NpmInstaller( - IFileSystem fileSystem, - ICakeEnvironment environment, - IProcessRunner processRunner, - IToolLocator tools, - ICakeLog log) - : base(fileSystem, environment, processRunner, tools, log) - { - } /// /// Installs a npm package from the specified settings. @@ -35,10 +28,7 @@ public NpmInstaller( /// The settings. public void Install(NpmInstallSettings settings) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); RunCore(settings); } diff --git a/src/Cake.Npm/NpmAddUserAliases.cs b/src/Cake.Npm/NpmAddUserAliases.cs index d58fb27..cc301d8 100644 --- a/src/Cake.Npm/NpmAddUserAliases.cs +++ b/src/Cake.Npm/NpmAddUserAliases.cs @@ -53,15 +53,9 @@ public static class NpmAddUserAliases [CakeAliasCategory("AddUser")] public static void NpmAddUser(this ICakeContext context, Action configurator) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); - if (configurator == null) - { - throw new ArgumentNullException(nameof(configurator)); - } + ArgumentNullException.ThrowIfNull(configurator); var settings = new NpmAddUserSettings(); configurator(settings); @@ -134,15 +128,9 @@ public static void NpmAddUser(this ICakeContext context, Action configurator) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); - if (configurator == null) - { - throw new ArgumentNullException(nameof(configurator)); - } + ArgumentNullException.ThrowIfNull(configurator); var settings = new NpmBumpVersionSettings(); configurator(settings); @@ -92,15 +83,9 @@ public static void NpmBumpVersion(this ICakeContext context, Action configurator) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); - if (configurator == null) - { - throw new ArgumentNullException(nameof(configurator)); - } + ArgumentNullException.ThrowIfNull(configurator); var settings = new NpmCiSettings(); configurator(settings); @@ -89,15 +80,9 @@ public static void NpmCi(this ICakeContext context, Action config [CakeAliasCategory("Ci")] public static void NpmCi(this ICakeContext context, NpmCiSettings settings) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); AddinInformation.LogVersionInformation(context.Log); var ciTool = new NpmCiTool(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools, context.Log); diff --git a/src/Cake.Npm/NpmInstallAliases.cs b/src/Cake.Npm/NpmInstallAliases.cs index 045e6b0..bef363f 100644 --- a/src/Cake.Npm/NpmInstallAliases.cs +++ b/src/Cake.Npm/NpmInstallAliases.cs @@ -27,11 +27,8 @@ public static class NpmInstallAliases [CakeAliasCategory("Install")] public static void NpmInstall(this ICakeContext context) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } - + ArgumentNullException.ThrowIfNull(context); + context.NpmInstall(new NpmInstallSettings()); } @@ -51,10 +48,7 @@ public static void NpmInstall(this ICakeContext context) [CakeAliasCategory("Install")] public static void NpmInstall(this ICakeContext context, params string[] packages) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); var settings = new NpmInstallSettings(); foreach (var packageName in packages) @@ -109,15 +103,9 @@ public static void NpmInstall(this ICakeContext context, params string[] package [CakeAliasCategory("Install")] public static void NpmInstall(this ICakeContext context, Action configurator) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); - if (configurator == null) - { - throw new ArgumentNullException(nameof(configurator)); - } + ArgumentNullException.ThrowIfNull(configurator); var settings = new NpmInstallSettings(); configurator(settings); @@ -191,15 +179,9 @@ public static void NpmInstall(this ICakeContext context, Action /// Npm Pack aliases /// @@ -31,10 +31,7 @@ public static class NpmPackAliases [CakeAliasCategory("Pack")] public static IEnumerable NpmPack(this ICakeContext context) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); return context.NpmPack(new NpmPackSettings()); } @@ -58,10 +55,7 @@ public static IEnumerable NpmPack(this ICakeContext context) [CakeAliasCategory("Pack")] public static IEnumerable NpmPack(this ICakeContext context, string source) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); if (String.IsNullOrWhiteSpace(source)) { @@ -88,15 +82,9 @@ public static IEnumerable NpmPack(this ICakeContext context, string so [CakeAliasCategory("Pack")] public static IEnumerable NpmPack(this ICakeContext context, Action configurator) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); - if (configurator == null) - { - throw new ArgumentNullException(nameof(configurator)); - } + ArgumentNullException.ThrowIfNull(configurator); var settings = new NpmPackSettings(); configurator(settings); @@ -126,15 +114,9 @@ public static IEnumerable NpmPack(this ICakeContext context, Action NpmPack(this ICakeContext context, NpmPackSettings settings) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); AddinInformation.LogVersionInformation(context.Log); diff --git a/src/Cake.Npm/NpmPruneAliases.cs b/src/Cake.Npm/NpmPruneAliases.cs index d32047d..3b94a2b 100644 --- a/src/Cake.Npm/NpmPruneAliases.cs +++ b/src/Cake.Npm/NpmPruneAliases.cs @@ -1,11 +1,10 @@ -using System; -using System.Collections.Generic; -using Cake.Core; -using Cake.Core.Annotations; -using Cake.Npm.Prune; - namespace Cake.Npm { + using Cake.Core; + using Cake.Core.Annotations; + using Cake.Npm.Prune; + using System; + /// /// Npm Prune aliases /// @@ -29,10 +28,7 @@ public static class NpmPruneAliases [CakeAliasCategory("Prune")] public static void NpmPrune(this ICakeContext context) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); context.NpmPrune(new NpmPruneSettings()); } @@ -54,15 +50,9 @@ public static void NpmPrune(this ICakeContext context) [CakeAliasCategory("Prune")] public static void NpmPrune(this ICakeContext context, Action configurator) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); - if (configurator == null) - { - throw new ArgumentNullException(nameof(configurator)); - } + ArgumentNullException.ThrowIfNull(configurator); var settings = new NpmPruneSettings(); configurator(settings); @@ -91,15 +81,9 @@ public static void NpmPrune(this ICakeContext context, Action [CakeAliasCategory("Prune")] public static void NpmPrune(this ICakeContext context, NpmPruneSettings settings) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); AddinInformation.LogVersionInformation(context.Log); diff --git a/src/Cake.Npm/NpmPublishAliases.cs b/src/Cake.Npm/NpmPublishAliases.cs index 853c409..4f0c605 100644 --- a/src/Cake.Npm/NpmPublishAliases.cs +++ b/src/Cake.Npm/NpmPublishAliases.cs @@ -1,10 +1,10 @@ -using System; -using Cake.Core; -using Cake.Core.Annotations; -using Cake.Npm.Publish; - -namespace Cake.Npm +namespace Cake.Npm { + using System; + using Cake.Core; + using Cake.Core.Annotations; + using Cake.Npm.Publish; + /// /// Npm publish aliases. /// @@ -27,10 +27,7 @@ public static class NpmPublishAliases [CakeAliasCategory("Publish")] public static void NpmPublish(this ICakeContext context) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); context.NpmPublish(new NpmPublishSettings()); } @@ -53,10 +50,7 @@ public static void NpmPublish(this ICakeContext context) [CakeAliasCategory("Publish")] public static void NpmPublish(this ICakeContext context, string source) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); if (String.IsNullOrWhiteSpace(source)) { @@ -82,15 +76,9 @@ public static void NpmPublish(this ICakeContext context, string source) [CakeAliasCategory("Publish")] public static void NpmPublish(this ICakeContext context, Action configurator) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); - if (configurator == null) - { - throw new ArgumentNullException(nameof(configurator)); - } + ArgumentNullException.ThrowIfNull(configurator); var settings = new NpmPublishSettings(); configurator(settings); @@ -119,15 +107,9 @@ public static void NpmPublish(this ICakeContext context, Action /// Npm Rebuild aliases /// @@ -47,10 +47,7 @@ public static void NpmRebuild(this ICakeContext context) [CakeAliasCategory("Rebuild")] public static void NpmRebuild(this ICakeContext context, params string[] packages) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); var settings = new NpmRebuildSettings(); foreach (var packageName in packages) @@ -87,10 +84,7 @@ public static void NpmRebuild(this ICakeContext context, params string[] package [CakeAliasCategory("Rebuild")] public static void NpmRebuild(this ICakeContext context, Action configurator) { - if (configurator == null) - { - throw new ArgumentNullException(nameof(configurator)); - } + ArgumentNullException.ThrowIfNull(configurator); var settings = new NpmRebuildSettings(); configurator.Invoke(settings); @@ -131,15 +125,9 @@ public static void NpmRebuild(this ICakeContext context, Action /// Npm RunScript aliases /// @@ -30,10 +30,7 @@ public static class NpmRunScriptAliases [CakeAliasCategory("Run-Script")] public static void NpmRunScript(this ICakeContext context, string scriptName) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); if (String.IsNullOrWhiteSpace(scriptName)) { @@ -64,20 +61,14 @@ public static void NpmRunScript(this ICakeContext context, string scriptName) [CakeAliasCategory("Run-Script")] public static void NpmRunScript(this ICakeContext context, string scriptName, IEnumerable arguments) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); if (String.IsNullOrWhiteSpace(scriptName)) { throw new ArgumentNullException(nameof(scriptName)); } - if (arguments == null) - { - throw new ArgumentNullException(nameof(arguments)); - } + ArgumentNullException.ThrowIfNull(arguments); var settings = new NpmRunScriptSettings { @@ -110,20 +101,14 @@ public static void NpmRunScript(this ICakeContext context, string scriptName, IE [CakeAliasCategory("Run-Script")] public static void NpmRunScript(this ICakeContext context, string scriptName, Action configurator) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); if (String.IsNullOrWhiteSpace(scriptName)) { throw new ArgumentNullException(nameof(scriptName)); } - if (configurator == null) - { - throw new ArgumentNullException(nameof(configurator)); - } + ArgumentNullException.ThrowIfNull(configurator); var settings = new NpmRunScriptSettings { ScriptName = scriptName }; configurator(settings); @@ -153,15 +138,9 @@ public static void NpmRunScript(this ICakeContext context, string scriptName, Ac [CakeAliasCategory("Run-Script")] public static void NpmRunScript(this ICakeContext context, NpmRunScriptSettings settings) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); AddinInformation.LogVersionInformation(context.Log); diff --git a/src/Cake.Npm/NpmSetAliases.cs b/src/Cake.Npm/NpmSetAliases.cs index fac3968..f66efe4 100644 --- a/src/Cake.Npm/NpmSetAliases.cs +++ b/src/Cake.Npm/NpmSetAliases.cs @@ -30,11 +30,8 @@ public static class NpmSetAliases [CakeAliasCategory("Set")] public static void NpmSet(this ICakeContext context, string key, string value, bool global = false) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } - + ArgumentNullException.ThrowIfNull(context); + context.NpmSet(new NpmSetSettings() { Key = key, @@ -60,15 +57,9 @@ public static void NpmSet(this ICakeContext context, string key, string value, b [CakeAliasCategory("Set")] public static void NpmSet(this ICakeContext context, Action configurator) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); - if (configurator == null) - { - throw new ArgumentNullException(nameof(configurator)); - } + ArgumentNullException.ThrowIfNull(configurator); var settings = new NpmSetSettings(); configurator(settings); @@ -95,15 +86,9 @@ public static void NpmSet(this ICakeContext context, Action conf [CakeAliasCategory("Set")] public static void NpmSet(this ICakeContext context, NpmSetSettings settings) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); AddinInformation.LogVersionInformation(context.Log); var tool = new NpmSetTool(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools, context.Log); diff --git a/src/Cake.Npm/NpmSettings.cs b/src/Cake.Npm/NpmSettings.cs index b5461d2..5708eaa 100644 --- a/src/Cake.Npm/NpmSettings.cs +++ b/src/Cake.Npm/NpmSettings.cs @@ -10,18 +10,9 @@ /// /// Npm tool settings. /// - public abstract class NpmSettings: ToolSettings + /// Command to run. + public abstract class NpmSettings(string command) : ToolSettings { - /// - /// Initializes a new instance of the class. - /// - /// Command to run. - protected NpmSettings(string command) - { - Command = command; - RedirectStandardError = false; - RedirectStandardOutput = false; - } /// /// Gets or sets the log level which should be used to run the npm command. @@ -35,7 +26,7 @@ protected NpmSettings(string command) /// To retrieve and process the standard error output /// needs to be set. /// - public bool RedirectStandardError { get; set; } + public bool RedirectStandardError { get; set; } = false; /// /// Gets or sets an action to retrieve and process standard error output. @@ -52,7 +43,7 @@ protected NpmSettings(string command) /// To retrieve and process the standard error output /// needs to be set. /// - public bool RedirectStandardOutput { get; set; } + public bool RedirectStandardOutput { get; set; } = false; /// /// Gets or sets an action to retrieve and process standard output. @@ -70,7 +61,7 @@ protected NpmSettings(string command) /// /// Gets the command which should be run. /// - protected string Command { get; private set; } + protected string Command { get; private set; } = command; /// /// Evaluates the settings and writes them to . diff --git a/src/Cake.Npm/NpmSettingsExtensions.cs b/src/Cake.Npm/NpmSettingsExtensions.cs index 7e9c957..941000a 100644 --- a/src/Cake.Npm/NpmSettingsExtensions.cs +++ b/src/Cake.Npm/NpmSettingsExtensions.cs @@ -16,10 +16,7 @@ public static class NpmSettingsExtensions /// The instance with set to . public static NpmSettings WithLogLevel(this NpmSettings settings, NpmLogLevel logLevel) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); settings.LogLevel = logLevel; @@ -34,10 +31,7 @@ public static NpmSettings WithLogLevel(this NpmSettings settings, NpmLogLevel lo /// The instance with set to . public static NpmSettings FromPath(this NpmSettings settings, DirectoryPath path) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); settings.WorkingDirectory = path ?? throw new ArgumentNullException(nameof(path)); @@ -52,10 +46,7 @@ public static NpmSettings FromPath(this NpmSettings settings, DirectoryPath path /// The instance with set to . public static NpmSettings SetRedirectedStandardErrorHandler(this NpmSettings settings, Action standardErrorAction) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); settings.StandardErrorAction = standardErrorAction ?? throw new ArgumentNullException(nameof(standardErrorAction)); @@ -70,10 +61,7 @@ public static NpmSettings SetRedirectedStandardErrorHandler(this NpmSettings set /// The instance with set to . public static NpmSettings SetRedirectedStandardOutputHandler(this NpmSettings settings, Action standardOutputAction) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); settings.StandardOutputAction = standardOutputAction ?? throw new ArgumentNullException(nameof(standardOutputAction)); diff --git a/src/Cake.Npm/NpmTool.cs b/src/Cake.Npm/NpmTool.cs index 1151e17..02ef65d 100644 --- a/src/Cake.Npm/NpmTool.cs +++ b/src/Cake.Npm/NpmTool.cs @@ -11,28 +11,20 @@ /// Base class for all npm tools. /// /// The settings type. - public abstract class NpmTool: Tool + /// The file system. + /// The environment. + /// The process runner. + /// The tool locator. + /// Cake log instance. + public abstract class NpmTool( + IFileSystem fileSystem, + ICakeEnvironment environment, + IProcessRunner processRunner, + IToolLocator tools, + ICakeLog log) : Tool(fileSystem, environment, processRunner, tools) where TSettings : NpmSettings { - private readonly ICakeLog _log; - - /// - /// Initializes a new instance of the class. - /// - /// The file system. - /// The environment. - /// The process runner. - /// The tool locator. - /// Cake log instance. - protected NpmTool( - IFileSystem fileSystem, - ICakeEnvironment environment, - IProcessRunner processRunner, - IToolLocator tools, - ICakeLog log) : base(fileSystem, environment, processRunner, tools) - { - _log = log; - } + private readonly ICakeLog _log = log; /// /// Cake log instance. @@ -60,7 +52,7 @@ protected sealed override string GetToolName() /// The tool executable name. protected sealed override IEnumerable GetToolExecutableNames() { - return new[] { "npm.cmd", "npm" }; + return ["npm.cmd", "npm"]; } /// @@ -80,10 +72,7 @@ protected void RunCore(TSettings settings) /// Action which should be executed after running npm. null for no action. protected void RunCore(TSettings settings, ProcessSettings processSettings, Action postAction) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); if (!settings.CakeVerbosityLevel.HasValue) { diff --git a/src/Cake.Npm/NpmUpdateAliases.cs b/src/Cake.Npm/NpmUpdateAliases.cs index ec33397..156639c 100644 --- a/src/Cake.Npm/NpmUpdateAliases.cs +++ b/src/Cake.Npm/NpmUpdateAliases.cs @@ -27,11 +27,8 @@ public static class NpmUpdateAliases [CakeAliasCategory("Update")] public static void NpmUpdate(this ICakeContext context) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } - + ArgumentNullException.ThrowIfNull(context); + context.NpmUpdate(new NpmUpdateSettings()); } @@ -51,15 +48,9 @@ public static void NpmUpdate(this ICakeContext context) [CakeAliasCategory("Update")] public static void NpmUpdate(this ICakeContext context, Action configurator) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); - if (configurator == null) - { - throw new ArgumentNullException(nameof(configurator)); - } + ArgumentNullException.ThrowIfNull(configurator); var settings = new NpmUpdateSettings(); configurator(settings); @@ -84,15 +75,9 @@ public static void NpmUpdate(this ICakeContext context, Action configurator) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); - if (configurator == null) - { - throw new ArgumentNullException(nameof(configurator)); - } + ArgumentNullException.ThrowIfNull(configurator); var settings = new NpmVersionSettings(); configurator(settings); @@ -93,15 +84,9 @@ public static string NpmVersion(this ICakeContext context, Action configurator) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); - if (configurator == null) - { - throw new ArgumentNullException(nameof(configurator)); - } + ArgumentNullException.ThrowIfNull(configurator); var settings = new NpmViewVersionSettings(); configurator(settings); @@ -98,15 +89,9 @@ public static string NpmViewVersion(this ICakeContext context, ActionThe instance with set to . public static NpmPackSettings FromSource(this NpmPackSettings settings, string source) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); if (string.IsNullOrWhiteSpace(source)) { diff --git a/src/Cake.Npm/Pack/NpmPacker.cs b/src/Cake.Npm/Pack/NpmPacker.cs index be9c19f..838a8f2 100644 --- a/src/Cake.Npm/Pack/NpmPacker.cs +++ b/src/Cake.Npm/Pack/NpmPacker.cs @@ -11,25 +11,18 @@ /// /// Tool for packaging npm modules. /// - public class NpmPacker : NpmTool + /// The file system. + /// The environment. + /// The process runner. + /// The tool locator. + /// Cake log instance. + public class NpmPacker( + IFileSystem fileSystem, + ICakeEnvironment environment, + IProcessRunner processRunner, + IToolLocator tools, + ICakeLog log) : NpmTool(fileSystem, environment, processRunner, tools, log) { - /// - /// Initializes a new instance of the class. - /// - /// The file system. - /// The environment. - /// The process runner. - /// The tool locator. - /// Cake log instance. - public NpmPacker( - IFileSystem fileSystem, - ICakeEnvironment environment, - IProcessRunner processRunner, - IToolLocator tools, - ICakeLog log) - : base(fileSystem, environment, processRunner, tools, log) - { - } /// /// Creates a npm package from the specified settings. @@ -38,10 +31,7 @@ public NpmPacker( /// List of created packages. public IEnumerable Pack(NpmPackSettings settings) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); var processSettings = new ProcessSettings { diff --git a/src/Cake.Npm/Prune/NpmPruneRunner.cs b/src/Cake.Npm/Prune/NpmPruneRunner.cs index d186b25..0b50ff8 100644 --- a/src/Cake.Npm/Prune/NpmPruneRunner.cs +++ b/src/Cake.Npm/Prune/NpmPruneRunner.cs @@ -9,25 +9,18 @@ /// /// Tool for running npm scripts. /// - public class NpmPruneRunner : NpmTool + /// The file system. + /// The environment. + /// The process runner. + /// The tool locator. + /// Cake log instance. + public class NpmPruneRunner( + IFileSystem fileSystem, + ICakeEnvironment environment, + IProcessRunner processRunner, + IToolLocator tools, + ICakeLog log) : NpmTool(fileSystem, environment, processRunner, tools, log) { - /// - /// Initializes a new instance of the class. - /// - /// The file system. - /// The environment. - /// The process runner. - /// The tool locator. - /// Cake log instance. - public NpmPruneRunner( - IFileSystem fileSystem, - ICakeEnvironment environment, - IProcessRunner processRunner, - IToolLocator tools, - ICakeLog log) - : base(fileSystem, environment, processRunner, tools, log) - { - } /// /// Runs a npm script with the specified settings. @@ -35,10 +28,7 @@ public NpmPruneRunner( /// The settings. public void Prune(NpmPruneSettings settings) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); RunCore(settings); } diff --git a/src/Cake.Npm/Prune/NpmPruneSettings.cs b/src/Cake.Npm/Prune/NpmPruneSettings.cs index 27e78dd..f531949 100644 --- a/src/Cake.Npm/Prune/NpmPruneSettings.cs +++ b/src/Cake.Npm/Prune/NpmPruneSettings.cs @@ -10,7 +10,7 @@ /// public class NpmPruneSettings : NpmSettings { - private readonly List _packages = new(); + private readonly List _packages = []; /// /// Initializes a new instance of the class. diff --git a/src/Cake.Npm/Prune/NpmPruneSettingsExtensions.cs b/src/Cake.Npm/Prune/NpmPruneSettingsExtensions.cs index 4daec58..01e9432 100644 --- a/src/Cake.Npm/Prune/NpmPruneSettingsExtensions.cs +++ b/src/Cake.Npm/Prune/NpmPruneSettingsExtensions.cs @@ -25,10 +25,7 @@ public static NpmPruneSettings ForProduction(this NpmPruneSettings settings) /// The instance with set to . public static NpmPruneSettings ForProduction(this NpmPruneSettings settings, bool production) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); settings.Production = production; return settings; @@ -54,10 +51,7 @@ public static NpmPruneSettings AddPackage(this NpmPruneSettings settings, string /// The instance with the package added to . public static NpmPruneSettings AddPackage(this NpmPruneSettings settings, string packageName, string scope) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); if (string.IsNullOrWhiteSpace(packageName)) { @@ -97,10 +91,7 @@ public static NpmPruneSettings DryRun(this NpmPruneSettings settings) /// The instance with set to . public static NpmPruneSettings DryRun(this NpmPruneSettings settings, bool dryRun) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); settings.DryRun = dryRun; return settings; @@ -124,10 +115,7 @@ public static NpmPruneSettings Json(this NpmPruneSettings settings) /// The instance with set to . public static NpmPruneSettings Json(this NpmPruneSettings settings, bool json) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); settings.Json = json; return settings; diff --git a/src/Cake.Npm/Publish/NpmPublishSettingsExtensions.cs b/src/Cake.Npm/Publish/NpmPublishSettingsExtensions.cs index 40c9a62..20ed86f 100644 --- a/src/Cake.Npm/Publish/NpmPublishSettingsExtensions.cs +++ b/src/Cake.Npm/Publish/NpmPublishSettingsExtensions.cs @@ -17,10 +17,7 @@ public static class NpmPublishSettingsExtensions /// The instance with set to . public static NpmPublishSettings FromSource(this NpmPublishSettings settings, string source) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); if (string.IsNullOrWhiteSpace(source)) { @@ -40,10 +37,7 @@ public static NpmPublishSettings FromSource(this NpmPublishSettings settings, st /// The instance with set to . public static NpmPublishSettings WithTag(this NpmPublishSettings settings, string tag) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); if (string.IsNullOrWhiteSpace(tag)) { @@ -63,10 +57,7 @@ public static NpmPublishSettings WithTag(this NpmPublishSettings settings, strin /// The instance with set to . public static NpmPublishSettings WithAccess(this NpmPublishSettings settings, NpmPublishAccess access) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); settings.Access = access; @@ -81,10 +72,7 @@ public static NpmPublishSettings WithAccess(this NpmPublishSettings settings, Np /// The instance with set to . public static NpmPublishSettings ToRegistry(this NpmPublishSettings settings, Uri registry) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); settings.Registry = registry ?? throw new ArgumentNullException(nameof(registry)); diff --git a/src/Cake.Npm/Publish/NpmPublisher.cs b/src/Cake.Npm/Publish/NpmPublisher.cs index e213d75..a3ca156 100644 --- a/src/Cake.Npm/Publish/NpmPublisher.cs +++ b/src/Cake.Npm/Publish/NpmPublisher.cs @@ -9,25 +9,18 @@ /// /// Tool for publishing npm modules. /// - public class NpmPublisher : NpmTool + /// The file system. + /// The environment. + /// The process runner. + /// The tool locator. + /// Cake log instance. + public class NpmPublisher( + IFileSystem fileSystem, + ICakeEnvironment environment, + IProcessRunner processRunner, + IToolLocator tools, + ICakeLog log) : NpmTool(fileSystem, environment, processRunner, tools, log) { - /// - /// Initializes a new instance of the class. - /// - /// The file system. - /// The environment. - /// The process runner. - /// The tool locator. - /// Cake log instance. - public NpmPublisher( - IFileSystem fileSystem, - ICakeEnvironment environment, - IProcessRunner processRunner, - IToolLocator tools, - ICakeLog log) - : base(fileSystem, environment, processRunner, tools, log) - { - } /// /// Publishes a npm package based on the specified settings. @@ -35,10 +28,7 @@ public NpmPublisher( /// The settings. public void Publish(NpmPublishSettings settings) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); RunCore(settings); } diff --git a/src/Cake.Npm/Rebuild/NpmRebuildSettings.cs b/src/Cake.Npm/Rebuild/NpmRebuildSettings.cs index 6e9280b..0df4db1 100644 --- a/src/Cake.Npm/Rebuild/NpmRebuildSettings.cs +++ b/src/Cake.Npm/Rebuild/NpmRebuildSettings.cs @@ -9,7 +9,7 @@ /// public class NpmRebuildSettings : NpmSettings { - private readonly List _packages = new(); + private readonly List _packages = []; /// /// Initializes a new instance of the class. diff --git a/src/Cake.Npm/Rebuild/NpmRebuildSettingsExtensions.cs b/src/Cake.Npm/Rebuild/NpmRebuildSettingsExtensions.cs index 78b39d1..eb52ab1 100644 --- a/src/Cake.Npm/Rebuild/NpmRebuildSettingsExtensions.cs +++ b/src/Cake.Npm/Rebuild/NpmRebuildSettingsExtensions.cs @@ -15,10 +15,7 @@ public static class NpmRebuildSettingsExtensions /// The instance with added to . public static NpmRebuildSettings AddPackage(this NpmRebuildSettings settings, string packageName) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); if (string.IsNullOrWhiteSpace(packageName)) { @@ -37,10 +34,7 @@ public static NpmRebuildSettings AddPackage(this NpmRebuildSettings settings, st /// The instance with added to . public static NpmRebuildSettings AddScopedPackage(this NpmRebuildSettings settings, string packageName, string scope) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); if (string.IsNullOrWhiteSpace(packageName)) { diff --git a/src/Cake.Npm/Rebuild/NpmRebuilder.cs b/src/Cake.Npm/Rebuild/NpmRebuilder.cs index c7c89b0..524e8fa 100644 --- a/src/Cake.Npm/Rebuild/NpmRebuilder.cs +++ b/src/Cake.Npm/Rebuild/NpmRebuilder.cs @@ -9,25 +9,18 @@ /// /// Tool for rebuilding npm modules. /// - public class NpmRebuilder : NpmTool + /// The file system. + /// The environment. + /// The process runner. + /// The tool locator. + /// Cake log instance. + public class NpmRebuilder( + IFileSystem fileSystem, + ICakeEnvironment environment, + IProcessRunner processRunner, + IToolLocator tools, + ICakeLog log) : NpmTool(fileSystem, environment, processRunner, tools, log) { - /// - /// Initializes a new instance of the class. - /// - /// The file system. - /// The environment. - /// The process runner. - /// The tool locator. - /// Cake log instance. - public NpmRebuilder( - IFileSystem fileSystem, - ICakeEnvironment environment, - IProcessRunner processRunner, - IToolLocator tools, - ICakeLog log) - : base (fileSystem, environment, processRunner, tools, log) - { - } /// /// Rebuilds a npm package from the specified settings. @@ -35,10 +28,7 @@ public NpmRebuilder( /// public void Rebuild(NpmRebuildSettings settings) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); RunCore(settings); } diff --git a/src/Cake.Npm/RunScript/NpmRunScriptSettings.cs b/src/Cake.Npm/RunScript/NpmRunScriptSettings.cs index eb17a3d..65a39a4 100644 --- a/src/Cake.Npm/RunScript/NpmRunScriptSettings.cs +++ b/src/Cake.Npm/RunScript/NpmRunScriptSettings.cs @@ -11,7 +11,7 @@ /// public class NpmRunScriptSettings : NpmSettings { - private readonly List _arguments = new(); + private readonly List _arguments = []; /// /// Initializes a new instance of the class. diff --git a/src/Cake.Npm/RunScript/NpmRunScriptSettingsExtensions.cs b/src/Cake.Npm/RunScript/NpmRunScriptSettingsExtensions.cs index 291db29..54d3080 100644 --- a/src/Cake.Npm/RunScript/NpmRunScriptSettingsExtensions.cs +++ b/src/Cake.Npm/RunScript/NpmRunScriptSettingsExtensions.cs @@ -15,10 +15,7 @@ public static class NpmRunScriptSettingsExtensions /// The instance with set to . public static NpmRunScriptSettings WithArguments(this NpmRunScriptSettings settings, string arguments) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); if (string.IsNullOrWhiteSpace(arguments)) { diff --git a/src/Cake.Npm/RunScript/NpmScriptRunner.cs b/src/Cake.Npm/RunScript/NpmScriptRunner.cs index c60f78d..5e73b94 100644 --- a/src/Cake.Npm/RunScript/NpmScriptRunner.cs +++ b/src/Cake.Npm/RunScript/NpmScriptRunner.cs @@ -9,25 +9,18 @@ /// /// Tool for running npm scripts. /// - public class NpmScriptRunner : NpmTool + /// The file system. + /// The environment. + /// The process runner. + /// The tool locator. + /// Cake log instance. + public class NpmScriptRunner( + IFileSystem fileSystem, + ICakeEnvironment environment, + IProcessRunner processRunner, + IToolLocator tools, + ICakeLog log) : NpmTool(fileSystem, environment, processRunner, tools, log) { - /// - /// Initializes a new instance of the class. - /// - /// The file system. - /// The environment. - /// The process runner. - /// The tool locator. - /// Cake log instance. - public NpmScriptRunner( - IFileSystem fileSystem, - ICakeEnvironment environment, - IProcessRunner processRunner, - IToolLocator tools, - ICakeLog log) - : base(fileSystem, environment, processRunner, tools, log) - { - } /// /// Runs a npm script with the specified settings. @@ -35,10 +28,7 @@ public NpmScriptRunner( /// The settings. public void RunScript(NpmRunScriptSettings settings) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); RunCore(settings); } diff --git a/src/Cake.Npm/Set/NpmSetSettings.cs b/src/Cake.Npm/Set/NpmSetSettings.cs index c2feadd..1b7eb13 100644 --- a/src/Cake.Npm/Set/NpmSetSettings.cs +++ b/src/Cake.Npm/Set/NpmSetSettings.cs @@ -1,9 +1,9 @@ -using Cake.Core; -using Cake.Core.IO; -using System; - -namespace Cake.Npm.Set +namespace Cake.Npm.Set { + using Cake.Core; + using Cake.Core.IO; + using System; + /// /// Contains settings used by . /// diff --git a/src/Cake.Npm/Set/NpmSetSettingsExtensions.cs b/src/Cake.Npm/Set/NpmSetSettingsExtensions.cs index 5d01dbe..34a790e 100644 --- a/src/Cake.Npm/Set/NpmSetSettingsExtensions.cs +++ b/src/Cake.Npm/Set/NpmSetSettingsExtensions.cs @@ -15,10 +15,7 @@ public static class NpmSetSettingsExtensions /// The instance with set to . public static NpmSetSettings ForKey(this NpmSetSettings settings, string key) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); if (string.IsNullOrWhiteSpace(key)) { @@ -37,10 +34,7 @@ public static NpmSetSettings ForKey(this NpmSetSettings settings, string key) /// The instance with set to . public static NpmSetSettings WithValue(this NpmSetSettings settings, string value) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); if (string.IsNullOrWhiteSpace(value)) { diff --git a/src/Cake.Npm/Set/NpmSetTool.cs b/src/Cake.Npm/Set/NpmSetTool.cs index 3dc00dd..14e3047 100644 --- a/src/Cake.Npm/Set/NpmSetTool.cs +++ b/src/Cake.Npm/Set/NpmSetTool.cs @@ -1,35 +1,27 @@ -using System.Linq; - -namespace Cake.Npm.Set +namespace Cake.Npm.Set { + using System.Linq; using System; - using Core; - using Core.Diagnostics; - using Core.IO; - using Core.Tooling; + using Cake.Core; + using Cake.Core.Diagnostics; + using Cake.Core.IO; + using Cake.Core.Tooling; /// /// Tool for installing all npm packages for a project from package-lock.json. /// - public class NpmSetTool : NpmTool + /// The file system. + /// The environment. + /// The process runner. + /// The tool locator. + /// Cake log instance. + public class NpmSetTool( + IFileSystem fileSystem, + ICakeEnvironment environment, + IProcessRunner processRunner, + IToolLocator tools, + ICakeLog log) : NpmTool(fileSystem, environment, processRunner, tools, log) { - /// - /// Initializes a new instance of the class. - /// - /// The file system. - /// The environment. - /// The process runner. - /// The tool locator. - /// Cake log instance. - public NpmSetTool( - IFileSystem fileSystem, - ICakeEnvironment environment, - IProcessRunner processRunner, - IToolLocator tools, - ICakeLog log) - : base(fileSystem, environment, processRunner, tools, log) - { - } /// /// Sets a configuration key/value @@ -37,10 +29,7 @@ public NpmSetTool( /// The settings public void Set(NpmSetSettings settings) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); RunCore(settings); } diff --git a/src/Cake.Npm/Update/NpmUpdateSettings.cs b/src/Cake.Npm/Update/NpmUpdateSettings.cs index 84e3cfd..60d7dea 100644 --- a/src/Cake.Npm/Update/NpmUpdateSettings.cs +++ b/src/Cake.Npm/Update/NpmUpdateSettings.cs @@ -1,8 +1,8 @@ -using Cake.Core; -using Cake.Core.IO; - -namespace Cake.Npm.Update +namespace Cake.Npm.Update { + using Cake.Core; + using Cake.Core.IO; + /// /// Contains settings used by . /// diff --git a/src/Cake.Npm/Update/NpmUpdateSettingsExtensions.cs b/src/Cake.Npm/Update/NpmUpdateSettingsExtensions.cs index a9adcfa..a0af0a3 100644 --- a/src/Cake.Npm/Update/NpmUpdateSettingsExtensions.cs +++ b/src/Cake.Npm/Update/NpmUpdateSettingsExtensions.cs @@ -14,10 +14,7 @@ public static class NpmUpdateSettingsExtensions /// The instance with set to true. public static NpmUpdateSettings UpdateGlobalPackages(this NpmUpdateSettings settings) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); settings.Global = true; return settings; diff --git a/src/Cake.Npm/Update/NpmUpdateTool.cs b/src/Cake.Npm/Update/NpmUpdateTool.cs index 70cc848..cc8c66d 100644 --- a/src/Cake.Npm/Update/NpmUpdateTool.cs +++ b/src/Cake.Npm/Update/NpmUpdateTool.cs @@ -9,25 +9,18 @@ /// /// Tool for installing all npm packages for a project from package-lock.json. /// - public class NpmUpdateTool : NpmTool + /// The file system. + /// The environment. + /// The process runner. + /// The tool locator. + /// Cake log instance. + public class NpmUpdateTool( + IFileSystem fileSystem, + ICakeEnvironment environment, + IProcessRunner processRunner, + IToolLocator tools, + ICakeLog log) : NpmTool(fileSystem, environment, processRunner, tools, log) { - /// - /// Initializes a new instance of the class. - /// - /// The file system. - /// The environment. - /// The process runner. - /// The tool locator. - /// Cake log instance. - public NpmUpdateTool( - IFileSystem fileSystem, - ICakeEnvironment environment, - IProcessRunner processRunner, - IToolLocator tools, - ICakeLog log) - : base(fileSystem, environment, processRunner, tools, log) - { - } /// /// Updates all npm packages. @@ -35,10 +28,7 @@ public NpmUpdateTool( /// The settings. public void Update(NpmUpdateSettings settings) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); RunCore(settings); } diff --git a/src/Cake.Npm/Version/NpmVersionSettings.cs b/src/Cake.Npm/Version/NpmVersionSettings.cs index 4c07ec0..1d784be 100644 --- a/src/Cake.Npm/Version/NpmVersionSettings.cs +++ b/src/Cake.Npm/Version/NpmVersionSettings.cs @@ -1,7 +1,4 @@ -using Cake.Core; -using Cake.Core.IO; - -namespace Cake.Npm.Version +namespace Cake.Npm.Version { /// /// Contains settings used by . diff --git a/src/Cake.Npm/Version/NpmVersionTool.cs b/src/Cake.Npm/Version/NpmVersionTool.cs index 877abb0..6e20986 100644 --- a/src/Cake.Npm/Version/NpmVersionTool.cs +++ b/src/Cake.Npm/Version/NpmVersionTool.cs @@ -1,36 +1,28 @@ -using System.Linq; -using System.Text.RegularExpressions; - -namespace Cake.Npm.Version +namespace Cake.Npm.Version { + using System.Linq; + using System.Text.RegularExpressions; using System; - using Core; - using Core.Diagnostics; - using Core.IO; - using Core.Tooling; + using Cake.Core; + using Cake.Core.Diagnostics; + using Cake.Core.IO; + using Cake.Core.Tooling; /// /// Tool for installing all npm packages for a project from package-lock.json. /// - public class NpmVersionTool : NpmTool + /// The file system. + /// The environment. + /// The process runner. + /// The tool locator. + /// Cake log instance. + public partial class NpmVersionTool( + IFileSystem fileSystem, + ICakeEnvironment environment, + IProcessRunner processRunner, + IToolLocator tools, + ICakeLog log) : NpmTool(fileSystem, environment, processRunner, tools, log) { - /// - /// Initializes a new instance of the class. - /// - /// The file system. - /// The environment. - /// The process runner. - /// The tool locator. - /// Cake log instance. - public NpmVersionTool( - IFileSystem fileSystem, - ICakeEnvironment environment, - IProcessRunner processRunner, - IToolLocator tools, - ICakeLog log) - : base(fileSystem, environment, processRunner, tools, log) - { - } /// /// Installs all npm packages from the specified settings. @@ -38,10 +30,7 @@ public NpmVersionTool( /// The settings. public string Version(NpmVersionSettings settings) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); var versionString = string.Empty; @@ -51,7 +40,7 @@ public string Version(NpmVersionSettings settings) if (processOutput?.Any() ?? false) { var output = string.Join(Environment.NewLine, processOutput); - var match = Regex.Match(output, "(?npm): '(?.*)'"); + var match = VersionRegex().Match(output); if (match.Success) { versionString = match.Groups["version"].Value; @@ -61,5 +50,8 @@ public string Version(NpmVersionSettings settings) return versionString; } + + [GeneratedRegex("(?npm): '(?.*)'")] + private static partial Regex VersionRegex(); } } diff --git a/src/Cake.Npm/ViewVersion/NpmViewVersionSettingsExtensions.cs b/src/Cake.Npm/ViewVersion/NpmViewVersionSettingsExtensions.cs index 628bf28..1838b1a 100644 --- a/src/Cake.Npm/ViewVersion/NpmViewVersionSettingsExtensions.cs +++ b/src/Cake.Npm/ViewVersion/NpmViewVersionSettingsExtensions.cs @@ -16,10 +16,7 @@ public static class NpmViewVersionSettingsExtensions /// The instance with set. public static NpmViewVersionSettings ForPackage(this NpmViewVersionSettings settings, string package) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); settings.Package = package; return settings; diff --git a/src/Cake.Npm/ViewVersion/NpmViewVersionTool.cs b/src/Cake.Npm/ViewVersion/NpmViewVersionTool.cs index 6e4a619..6ceb7db 100644 --- a/src/Cake.Npm/ViewVersion/NpmViewVersionTool.cs +++ b/src/Cake.Npm/ViewVersion/NpmViewVersionTool.cs @@ -11,25 +11,18 @@ /// /// Tool for viewing npm package versions. /// - public class NpmViewVersionTool : NpmTool + /// The file system. + /// The environment. + /// The process runner. + /// The tool locator. + /// Cake log instance. + public class NpmViewVersionTool( + IFileSystem fileSystem, + ICakeEnvironment environment, + IProcessRunner processRunner, + IToolLocator tools, + ICakeLog log) : NpmTool(fileSystem, environment, processRunner, tools, log) { - /// - /// Initializes a new instance of the class. - /// - /// The file system. - /// The environment. - /// The process runner. - /// The tool locator. - /// Cake log instance. - public NpmViewVersionTool( - IFileSystem fileSystem, - ICakeEnvironment environment, - IProcessRunner processRunner, - IToolLocator tools, - ICakeLog log) - : base(fileSystem, environment, processRunner, tools, log) - { - } /// /// Views the package version from the specified settings. @@ -37,10 +30,7 @@ public NpmViewVersionTool( /// The settings. public string Version(NpmViewVersionSettings settings) { - if (settings == null) - { - throw new ArgumentNullException(nameof(settings)); - } + ArgumentNullException.ThrowIfNull(settings); var versionString = string.Empty;