Ignore package.json engines.node when generating Dockerfiles#16295
Merged
Ignore package.json engines.node when generating Dockerfiles#16295
Conversation
Generated JavaScript Dockerfiles now treat pinned toolchain files (.nvmrc, .node-version, and .tool-versions) as authoritative for Node image selection and otherwise fall back to the preferred default Node major. package.json engines.node remains compatibility metadata rather than a deployment image pin. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 16295Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 16295" |
Contributor
There was a problem hiding this comment.
Pull request overview
Updates JavaScript Dockerfile generation to stop using package.json engines.node for Node base-image selection, relying instead on explicit overrides and pinned toolchain files, with a fallback to Aspire’s default Node major.
Changes:
- Switch base image selection from
DetectNodeVersion(...) ?? DefaultNodeVersionto always resolving via pinned toolchain files first, otherwise defaulting to Node22. - Remove
package.jsonengines.nodeparsing from Node version detection logic. - Update tests by removing the assertion that
engines.nodeinfluences the generated Dockerfile base image.
Show a summary per file
| File | Description |
|---|---|
| tests/Aspire.Hosting.JavaScript.Tests/AddViteAppTests.cs | Removes the test that expected package.json engines.node to affect generated Dockerfile base image selection. |
| src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs | Refactors Node version selection to ignore package.json and only use pinned toolchain files, otherwise defaulting to Node 22. |
Copilot's findings
- Files reviewed: 2/2 changed files
- Comments generated: 2
Make .tool-versions parsing tolerant of tab-delimited entries and add regression coverage for the review feedback: package.json engines.node remains ignored when no pinned toolchain file exists, and tab-separated .tool-versions entries still drive the generated Dockerfile base image. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
🎬 CLI E2E Test Recordings — 72 recordings uploaded (commit View recordings
📹 Recordings uploaded automatically from CI run #24596593940 |
mitchdenny
approved these changes
Apr 20, 2026
JamesNK
approved these changes
Apr 20, 2026
Member
JamesNK
left a comment
There was a problem hiding this comment.
Clean, focused change. No bugs, security issues, correctness errors, or convention violations found.
- Refactoring from nullable
DetectNodeVersiontoResolveNodeVersion+TryDetectPinnedNodeVersionis sound .tool-versionswhitespace fix correctly handles tabs and mixed whitespaceengines.noderemoval is intentional and properly labeled as breaking change- Test coverage includes tab-delimited
.tool-versionsregression andengines.nodeignore verification
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This fixes the Node Dockerfile version selection bug in #15874.
Before this change, Aspire read
package.jsonengines.nodeand treated the first parsed major version as the generated Dockerfile base image version. That made compatibility ranges like>=18.0.0producenode:18-*, which reflects the minimum compatible major rather than an intended deployment pin and can leave generated images on older runtimes.This change switches generated JavaScript Dockerfiles to a buildpacks-style policy:
WithDockerfileBaseImage(...)/withDockerfileBaseImage(...)overrides still win.nvmrc,.node-version, and.tool-versions) are treated as authoritative.tool-versionsparsing now tokenizes on any whitespace so tab-delimited entries continue to workpackage.jsonengines.nodeis no longer used for Dockerfile base image selection because it is compatibility metadata rather than a deployment image pin22)The test updates remove the old
engines.nodeexpectation and add regression coverage that:package.jsonengines.nodedoes not override the default image when no toolchain pin exists.tool-versionsentries still drive Dockerfile Node image selectionDependencies: none.
Validation:
./dotnet.sh test tests/Aspire.Hosting.JavaScript.Tests/Aspire.Hosting.JavaScript.Tests.csproj -tl:off -- --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"Fixes #15874
Checklist
<remarks />and<code />elements on your triple slash comments?aspire.devissue: