-
Notifications
You must be signed in to change notification settings - Fork 733
Refactor NodeJs Integration #12530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor NodeJs Integration #12530
Conversation
- Obsolete AddNpmApp. - Add JavaScriptAppResource and AddJavaScriptApp extension method - Refactor AddViteApp to be a specialization of AddJavaScriptApp - Replace NodeInstallerResource with JavaScriptInstallerResource - Add JavaScriptPackageManagerAnnotation to handle different package managers - Replace JavaScriptRunCommandAnnotation with JavaScriptRunScriptAnnotation - Replace JavaScriptBuildCommandAnnotation with JavaScriptBuildScriptAnnotation Contributes to dotnet#8350
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12530Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12530" |
There was a problem hiding this 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 PR refactors Node.js application hosting in Aspire by renaming core types and introducing a new AddJavaScriptApp method as the primary API for JavaScript applications. The refactoring establishes a cleaner type hierarchy with JavaScriptAppResource as the base class for both Node.js and Vite applications.
Key Changes:
- Introduces
AddJavaScriptAppas the main entry point for JavaScript apps, withAddNpmAppnow obsoleted - Renames resource types from
NodeAppResource/NodeInstallerResourcetoJavaScriptAppResource/JavaScriptInstallerResource - Refactors package manager annotations from storing executable commands to storing script configurations
- Updates default install commands to use
npm ciin publish mode instead ofnpm install - Adds
WithContainerFilesSourceextension method for configuring container file paths
Reviewed Changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Aspire.Hosting.NodeJs/JavaScriptAppResource.cs | New base resource class for JavaScript applications with service discovery and container files support |
| src/Aspire.Hosting.NodeJs/NodeAppResource.cs | Updated to inherit from JavaScriptAppResource instead of ExecutableResource |
| src/Aspire.Hosting.NodeJs/ViteAppResource.cs | Updated to inherit from JavaScriptAppResource, removed IResourceWithContainerFiles (now on base) |
| src/Aspire.Hosting.NodeJs/NodeExtensions.cs | Major refactoring: added AddJavaScriptApp, obsoleted AddNpmApp, refactored package manager configuration |
| src/Aspire.Hosting.NodeJs/JavaScriptPackageManagerAnnotation.cs | New annotation to track package manager executable and script command |
| src/Aspire.Hosting.NodeJs/JavaScriptRunScriptAnnotation.cs | New annotation for run scripts (replaces JavaScriptRunCommandAnnotation) |
| src/Aspire.Hosting.NodeJs/JavaScriptBuildScriptAnnotation.cs | New annotation for build scripts (replaces JavaScriptBuildCommandAnnotation) |
| src/Aspire.Hosting.NodeJs/JavaScriptInstallCommandAnnotation.cs | Simplified to only store args (command now in JavaScriptPackageManagerAnnotation) |
| src/Aspire.Hosting.NodeJs/JavaScriptInstallerResource.cs | Renamed from NodeInstallerResource |
| src/Aspire.Hosting/ResourceBuilderExtensions.cs | Added WithContainerFilesSource extension method |
| tests/* | Comprehensive test updates to use new API and verify new behavior |
| playground/* | Updated sample applications to use new AddJavaScriptApp API |
| templates/* | Removed explicit WithNpm(install: true) call (now default behavior) |
playground/AspireWithJavaScript/AspireJavaScript.AppHost/AppHost.cs
Outdated
Show resolved
Hide resolved
| { | ||
| // Arguments to the executable often contain physical paths that are not valid in the container | ||
| // Clear them out so that the container can be set up with the correct arguments | ||
| existingBuilder.WithArgs(c => c.Args.Clear()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@davidfowl - this test was failing before this change -
aspire/tests/Aspire.Hosting.Tests/PublishAsDockerfileTests.cs
Lines 148 to 207 in 2717f1b
| public async Task PublishAsDockerFileConfigureContainer() | |
| { | |
| var builder = TestDistributedApplicationBuilder.Create(DistributedApplicationOperation.Publish); | |
| using var tempDir = CreateDirectoryWithDockerFile(); | |
| var path = tempDir.Path; | |
| var secret = builder.AddParameter("secret", secret: true); | |
| var frontend = builder.AddNpmApp("frontend", path, "watch") | |
| .WithArgs("/usr/foo") | |
| .PublishAsDockerFile(c => | |
| { | |
| c.WithBuildSecret("buildSecret", secret); | |
| c.WithArgs("/app"); | |
| c.WithVolume("vol", "/app/node_modules"); | |
| }); | |
| // There should be an equivalent container resource with the same name | |
| // as the npm app resource. | |
| var containerResource = Assert.Single(builder.Resources.OfType<ContainerResource>()); | |
| Assert.Equal("frontend", containerResource.Name); | |
| var manifest = await ManifestUtils.GetManifest(frontend.Resource, manifestDirectory: path).DefaultTimeout(); | |
| var expected = | |
| $$""" | |
| { | |
| "type": "container.v1", | |
| "build": { | |
| "context": ".", | |
| "dockerfile": "Dockerfile", | |
| "secrets": { | |
| "buildSecret": { | |
| "type": "env", | |
| "value": "{secret.value}" | |
| } | |
| } | |
| }, | |
| "args": [ | |
| "/app" | |
| ], | |
| "volumes": [ | |
| { | |
| "name": "vol", | |
| "target": "/app/node_modules", | |
| "readOnly": false | |
| } | |
| ], | |
| "env": { | |
| "NODE_ENV": "{{builder.Environment.EnvironmentName.ToLowerInvariant()}}" | |
| } | |
| } | |
| """; | |
| var actual = manifest.ToString(); | |
| Assert.Equal(expected, actual, ignoreLineEndingDifferences: true, ignoreWhiteSpaceDifferences: true); | |
| } |
The issue is that AddJavaScriptApp calls PublishAsDockerFile, then the test calls WithArgs and then PublishAsDockerFile again. The args in the WithArgs call wasn't getting cleared.
Clarified npm install command requirement for clean install.
|
@eerhardt We should default to |
|
/backport to release/13.0 |
|
Started backporting to release/13.0: https://github.com/dotnet/aspire/actions/runs/18970941140 |
Description
Refactor JavaScript Integration
Contributes to #8350
Checklist
<remarks />and<code />elements on your triple slash comments?