Skip to content

Conversation

@eerhardt
Copy link
Member

@eerhardt eerhardt commented Oct 31, 2025

Description

  • Obsolete the existing AddNodeApp that takes a file path only
  • Introduce a new AddNodeApp that takes a directory path and a file path relative to that directory
  • Includes a default Dockerfile for the Node application
  • Add Npm package manager support if the directory contains a package.json file

Fix #8350

Checklist

@github-actions
Copy link
Contributor

github-actions bot commented Oct 31, 2025

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12538

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12538"

@eerhardt eerhardt mentioned this pull request Oct 31, 2025
7 tasks
@eerhardt eerhardt force-pushed the AddNodeAppRefactor branch 2 times, most recently from 76bf405 to e3dc209 Compare October 31, 2025 12:12
- Obsolete the existing AddNodeApp that takes a file path only
- Introduce a new AddNodeApp that takes a directory path and a file path relative to that directory
- Includes a default Dockerfile for the Node application
- Add Npm package manager support if the directory contains a package.json file
@eerhardt eerhardt added the breaking-change Issue or PR that represents a breaking API or functional change over a prerelease. label Oct 31, 2025
@eerhardt eerhardt marked this pull request as ready for review October 31, 2025 12:31
@eerhardt eerhardt requested a review from mitchdenny as a code owner October 31, 2025 12:31
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request refactors the Node.js application hosting API in Aspire to separate the application directory from the script path, improving clarity and consistency. The PR changes the default run script from "start" to "dev" and adds support for custom run script arguments.

Key Changes:

  • Introduces a new AddNodeApp overload that takes separate appDirectory and scriptPath parameters, marking the old signature as obsolete
  • Changes the default run script from "start" to "dev" for AddJavaScriptApp
  • Adds WithRunScript extension method to support custom script arguments
  • Automatically configures npm as the package manager when package.json exists

Reviewed Changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Aspire.Hosting.NodeJs/NodeExtensions.cs Added new AddNodeApp overload with improved API design, marked old overload as obsolete, changed default run script to "dev", enhanced WithRunScript to support arguments
src/Aspire.Hosting.NodeJs/Aspire.Hosting.NodeJs.csproj Added OverloadResolutionPriorityAttribute to project for C# overload resolution
tests/Aspire.Hosting.Tests/DistributedApplicationTests.cs Updated test to use new AddNodeApp API signature with separate directory and script parameters
tests/Aspire.Hosting.NodeJs.Tests/PackageInstallationTests.cs Updated tests to expect "dev" as default script, added test for WithRunScript with custom arguments, minor formatting fix
tests/Aspire.Hosting.NodeJs.Tests/NodeJsPublicApiTests.cs Updated tests to use new AddNodeApp API signature
tests/Aspire.Hosting.NodeJs.Tests/NodeAppFixture.cs Updated fixture to use new AddNodeApp API signature
tests/Aspire.Hosting.NodeJs.Tests/AddNodeAppTests.cs Added comprehensive tests for new API behavior including Dockerfile generation and npm detection
playground/AspireWithJavaScript/AspireJavaScript.NodeApp/* Added new sample Node.js application with Express server, package.json, and HTML frontend
playground/AspireWithJavaScript/AspireJavaScript.AppHost/AppHost.cs Updated existing apps to explicitly use "start" script and added new Node.js app with "dev" script
Files not reviewed (1)
  • playground/AspireWithJavaScript/AspireJavaScript.NodeApp/package-lock.json: Language not supported
Comments suppressed due to low confidence (1)

src/Aspire.Hosting.NodeJs/NodeExtensions.cs:28

  • Corrected grammar: 'Node should available' should be 'Node should be available'. This appears in the obsoleted method documentation as well.
    /// Adds a node application to the application model. Node should available on the PATH.

Copy link
Member

@IEvangelist IEvangelist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Use multi-stage build.
Set NODE_ENV.
Expose the port.
Use a non-root user.
.Copy(".", ".");

var builderStage = dockerfileContext.Builder
.From($"node:{nodeVersion}-slim", "build")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidfowl @mitchdenny - if we decided to use -alpine by default, the size reduces by about 100MB.

Using the playground app I added, sizes are:

  • Current: 334 MB
  • Combining all steps into a single stage: 349 MB
  • Using node:22-alpine: 237 MB

Should we default to that instead? And if someone needs a different base image, we can add support for defining the base image via an annotation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with -alpine by default. We will allow people to change the base image with an annotation.

@eerhardt
Copy link
Member Author

/backport to release/13.0

@github-actions
Copy link
Contributor

Started backporting to release/13.0: https://github.com/dotnet/aspire/actions/runs/18982618551

@eerhardt eerhardt merged commit cadf510 into dotnet:main Oct 31, 2025
582 of 585 checks passed
@eerhardt eerhardt deleted the AddNodeAppRefactor branch October 31, 2025 19:08
@dotnet-policy-service dotnet-policy-service bot added this to the 13.0 milestone Oct 31, 2025
@davidfowl
Copy link
Member

Tested and it works!

@robrich
Copy link

robrich commented Oct 31, 2025

This fixes many parts of #8350. But it doesn't fix .WithHttpOtelCollector(). Browser apps need to use HTTP and can't use gRPC for OTEL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-change Issue or PR that represents a breaking API or functional change over a prerelease.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make Aspire better for client-side JavaScript developers.

4 participants