Skip to content
5 changes: 3 additions & 2 deletions src/Aspire.Hosting.NodeJs/NodeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public static IResourceBuilder<ViteAppResource> AddViteApp(this IDistributedAppl
/// <param name="useCI">When true, use <code>npm ci</code>, otherwise use <code>npm install</code> when installing packages.</param>
/// <param name="configureInstaller">Configure the npm installer resource.</param>
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
public static IResourceBuilder<TResource> WithNpmPackageManager<TResource>(this IResourceBuilder<TResource> resource, bool useCI = false, Action<IResourceBuilder<NpmInstallerResource>>? configureInstaller = null) where TResource : NodeAppResource
public static IResourceBuilder<TResource> WithNpmPackageManager<TResource>(this IResourceBuilder<TResource> resource, bool useCI = false, Action<IResourceBuilder<NodeInstallerResource>>? configureInstaller = null) where TResource : NodeAppResource
{
resource.WithCommand("npm");
resource.WithAnnotation(new JavaScriptPackageManagerAnnotation("npm")
Expand All @@ -200,9 +200,10 @@ public static IResourceBuilder<TResource> WithNpmPackageManager<TResource>(this
if (!resource.ApplicationBuilder.ExecutionContext.IsPublishMode)
{
var installerName = $"{resource.Resource.Name}-npm-install";
var installer = new NpmInstallerResource(installerName, resource.Resource.WorkingDirectory);
var installer = new NodeInstallerResource(installerName, resource.Resource.WorkingDirectory);

var installerBuilder = resource.ApplicationBuilder.AddResource(installer)
.WithCommand("npm")
.WithArgs([useCI ? "ci" : "install"])
.WithParentRelationship(resource.Resource)
.ExcludeFromManifest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
namespace Aspire.Hosting.NodeJs;

/// <summary>
/// A resource that represents an npm package installer.
/// A resource that represents a package installer for a node app.
/// </summary>
/// <param name="name">The name of the resource.</param>
/// <param name="workingDirectory">The working directory to use for the command.</param>
public class NpmInstallerResource(string name, string workingDirectory)
: ExecutableResource(name, "npm", workingDirectory);
public class NodeInstallerResource(string name, string workingDirectory)
: ExecutableResource(name, "node", workingDirectory);
6 changes: 3 additions & 3 deletions tests/Aspire.Hosting.NodeJs.Tests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void ResourceBasedPackageInstallersAppearInApplicationModel()
Assert.Single(nodeResources);

// Verify all installer resources are present as separate resources
var npmInstallers = appModel.Resources.OfType<NpmInstallerResource>().ToList();
var npmInstallers = appModel.Resources.OfType<NodeInstallerResource>().ToList();

Assert.Single(npmInstallers);

Expand All @@ -51,7 +51,7 @@ public void ResourceBasedPackageInstallersAppearInApplicationModel()
Assert.Single(waitAnnotations);

var waitedResource = waitAnnotations.First().Resource;
Assert.True(waitedResource is NpmInstallerResource);
Assert.True(waitedResource is NodeInstallerResource);
}
}

Expand All @@ -66,7 +66,7 @@ public void InstallerResourcesHaveCorrectExecutableConfiguration()
using var app = builder.Build();
var appModel = app.Services.GetRequiredService<DistributedApplicationModel>();

var installer = Assert.Single(appModel.Resources.OfType<NpmInstallerResource>());
var installer = Assert.Single(appModel.Resources.OfType<NodeInstallerResource>());

// Verify it's configured as an ExecutableResource
Assert.IsAssignableFrom<ExecutableResource>(installer);
Expand Down
6 changes: 3 additions & 3 deletions tests/Aspire.Hosting.NodeJs.Tests/PackageInstallationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async Task WithNpmPackageManager_CanBeConfiguredWithInstallAndCIOptions()

var appModel = app.Services.GetRequiredService<DistributedApplicationModel>();
var nodeResources = appModel.Resources.OfType<NodeAppResource>().ToList();
var installerResources = appModel.Resources.OfType<NpmInstallerResource>().ToList();
var installerResources = appModel.Resources.OfType<NodeInstallerResource>().ToList();

Assert.Equal(2, nodeResources.Count);
Assert.Equal(2, installerResources.Count);
Expand Down Expand Up @@ -66,7 +66,7 @@ public void WithNpmPackageManager_ExcludedFromPublishMode()
Assert.Equal("npm", nodeResource.Command);

// Verify NO installer resource was created in publish mode
var installerResources = appModel.Resources.OfType<NpmInstallerResource>().ToList();
var installerResources = appModel.Resources.OfType<NodeInstallerResource>().ToList();
Assert.Empty(installerResources);

// Verify no wait annotations were added
Expand Down Expand Up @@ -94,7 +94,7 @@ public async Task WithNpmPackageManager_CanAcceptAdditionalArgs()
using var app = builder.Build();

var appModel = app.Services.GetRequiredService<DistributedApplicationModel>();
var installerResources = appModel.Resources.OfType<NpmInstallerResource>().ToList();
var installerResources = appModel.Resources.OfType<NodeInstallerResource>().ToList();

Assert.Equal(2, installerResources.Count);

Expand Down
4 changes: 2 additions & 2 deletions tests/Aspire.Hosting.NodeJs.Tests/ResourceCreationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public async Task WithNpmPackageManagerDefaultsToInstallCommand()
Assert.Equal("npm", nodeResource.Command);

// Verify the installer resource was created
var installerResource = Assert.Single(appModel.Resources.OfType<NpmInstallerResource>());
var installerResource = Assert.Single(appModel.Resources.OfType<NodeInstallerResource>());
Assert.Equal("test-app-npm-install", installerResource.Name);
Assert.Equal("npm", installerResource.Command);
var args = await installerResource.GetArgumentValuesAsync();
Expand Down Expand Up @@ -161,7 +161,7 @@ public async Task WithNpmPackageManagerCanUseCICommand()
Assert.Equal("npm", nodeResource.Command);

// Verify the installer resource was created with CI enabled
var installerResource = Assert.Single(appModel.Resources.OfType<NpmInstallerResource>());
var installerResource = Assert.Single(appModel.Resources.OfType<NodeInstallerResource>());
Assert.Equal("test-app-npm-install", installerResource.Name);
Assert.Equal("npm", installerResource.Command);
var args = await installerResource.GetArgumentValuesAsync();
Expand Down
Loading