Skip to content

Ignore package.json engines.node when generating Dockerfiles#16295

Merged
davidfowl merged 2 commits intomainfrom
issue-15874-node-image-generation
Apr 20, 2026
Merged

Ignore package.json engines.node when generating Dockerfiles#16295
davidfowl merged 2 commits intomainfrom
issue-15874-node-image-generation

Conversation

@davidfowl
Copy link
Copy Markdown
Contributor

@davidfowl davidfowl commented Apr 18, 2026

Description

This fixes the Node Dockerfile version selection bug in #15874.

Before this change, Aspire read package.json engines.node and treated the first parsed major version as the generated Dockerfile base image version. That made compatibility ranges like >=18.0.0 produce node: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:

  • explicit WithDockerfileBaseImage(...) / withDockerfileBaseImage(...) overrides still win
  • pinned toolchain files (.nvmrc, .node-version, and .tool-versions) are treated as authoritative
  • .tool-versions parsing now tokenizes on any whitespace so tab-delimited entries continue to work
  • package.json engines.node is no longer used for Dockerfile base image selection because it is compatibility metadata rather than a deployment image pin
  • when no toolchain pin is present, generated Dockerfiles fall back to Aspire's preferred default Node major (22)

The test updates remove the old engines.node expectation and add regression coverage that:

  • package.json engines.node does not override the default image when no toolchain pin exists
  • tab-delimited .tool-versions entries still drive Dockerfile Node image selection

Dependencies: 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

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

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>
Copilot AI review requested due to automatic review settings April 18, 2026 04:02
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 18, 2026

🚀 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/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 16295

Or

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

Copy link
Copy Markdown
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

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(...) ?? DefaultNodeVersion to always resolving via pinned toolchain files first, otherwise defaulting to Node 22.
  • Remove package.json engines.node parsing from Node version detection logic.
  • Update tests by removing the assertion that engines.node influences 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

Comment thread tests/Aspire.Hosting.JavaScript.Tests/AddViteAppTests.cs
Comment thread src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs
@davidfowl davidfowl added the breaking-change Issue or PR that represents a breaking API or functional change over a prerelease. label Apr 18, 2026
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>
@github-actions
Copy link
Copy Markdown
Contributor

🎬 CLI E2E Test Recordings — 72 recordings uploaded (commit fb75ba6)

View recordings
Test Recording
AddPackageInteractiveWhileAppHostRunningDetached ▶️ View Recording
AddPackageWhileAppHostRunningDetached ▶️ View Recording
AgentCommands_AllHelpOutputs_AreCorrect ▶️ View Recording
AgentInitCommand_DefaultSelection_InstallsSkillOnly ▶️ View Recording
AgentInitCommand_MigratesDeprecatedConfig ▶️ View Recording
AspireAddPackageVersionToDirectoryPackagesProps ▶️ View Recording
AspireUpdateRemovesAppHostPackageVersionFromDirectoryPackagesProps ▶️ View Recording
Banner_DisplayedOnFirstRun ▶️ View Recording
Banner_DisplayedWithExplicitFlag ▶️ View Recording
Banner_NotDisplayedWithNoLogoFlag ▶️ View Recording
CertificatesClean_RemovesCertificates ▶️ View Recording
CertificatesTrust_WithNoCert_CreatesAndTrustsCertificate ▶️ View Recording
CertificatesTrust_WithUntrustedCert_TrustsCertificate ▶️ View Recording
ConfigSetGet_CreatesNestedJsonFormat ▶️ View Recording
CreateAndRunAspireStarterProject ▶️ View Recording
CreateAndRunAspireStarterProjectWithBundle ▶️ View Recording
CreateAndRunEmptyAppHostProject ▶️ View Recording
CreateAndRunJavaEmptyAppHostProject ▶️ View Recording
CreateAndRunJsReactProject ▶️ View Recording
CreateAndRunPythonReactProject ▶️ View Recording
CreateAndRunTypeScriptEmptyAppHostProject ▶️ View Recording
CreateAndRunTypeScriptStarterProject ▶️ View Recording
CreateJavaAppHostWithViteApp ▶️ View Recording
CreateTypeScriptAppHostWithViteApp ▶️ View Recording
DashboardRunWithOtelTracesReturnsNoTraces ▶️ View Recording
DeployK8sBasicApiService ▶️ View Recording
DeployK8sWithGarnet ▶️ View Recording
DeployK8sWithMongoDB ▶️ View Recording
DeployK8sWithMySql ▶️ View Recording
DeployK8sWithPostgres ▶️ View Recording
DeployK8sWithRabbitMQ ▶️ View Recording
DeployK8sWithRedis ▶️ View Recording
DeployK8sWithSqlServer ▶️ View Recording
DeployK8sWithValkey ▶️ View Recording
DeployTypeScriptAppToKubernetes ▶️ View Recording
DescribeCommandResolvesReplicaNames ▶️ View Recording
DescribeCommandShowsRunningResources ▶️ View Recording
DetachFormatJsonProducesValidJson ▶️ View Recording
DetachFormatJsonProducesValidJsonWhenRestartingExistingInstance ▶️ View Recording
DoListStepsShowsPipelineSteps ▶️ View Recording
DoctorCommand_DetectsDeprecatedAgentConfig ▶️ View Recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View Recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View Recording
GlobalMigration_HandlesCommentsAndTrailingCommas ▶️ View Recording
GlobalMigration_HandlesMalformedLegacyJson ▶️ View Recording
GlobalMigration_PreservesAllValueTypes ▶️ View Recording
GlobalMigration_SkipsWhenNewConfigExists ▶️ View Recording
GlobalSettings_MigratedFromLegacyFormat ▶️ View Recording
InitTypeScriptAppHost_AugmentsExistingViteRepoAtRoot ▶️ View Recording
InvalidAppHostPathWithComments_IsHealedOnRun ▶️ View Recording
LegacySettingsMigration_AdjustsRelativeAppHostPath ▶️ View Recording
LogsCommandShowsResourceLogs ▶️ View Recording
OtelLogsReturnsStructuredLogsFromStarterApp ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording
PsFormatJsonOutputsOnlyJsonToStdout ▶️ View Recording
PublishWithConfigureEnvFileUpdatesEnvOutput ▶️ View Recording
PublishWithDockerComposeServiceCallbackSucceeds ▶️ View Recording
PublishWithoutOutputPathUsesAppHostDirectoryDefault ▶️ View Recording
RestoreGeneratesSdkFiles ▶️ View Recording
RestoreRefreshesGeneratedSdkAfterAddingIntegration ▶️ View Recording
RestoreSupportsConfigOnlyHelperPackageAndCrossPackageTypes ▶️ View Recording
RunFromParentDirectory_UsesExistingConfigNearAppHost ▶️ View Recording
SecretCrudOnDotNetAppHost ▶️ View Recording
SecretCrudOnTypeScriptAppHost ▶️ View Recording
StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels ▶️ View Recording
StartAndWaitForTypeScriptSqlServerAppHostWithNativeAssets ▶️ View Recording
StopAllAppHostsFromAppHostDirectory ▶️ View Recording
StopAllAppHostsFromUnrelatedDirectory ▶️ View Recording
StopNonInteractiveMultipleAppHostsShowsError ▶️ View Recording
StopNonInteractiveSingleAppHost ▶️ View Recording
StopWithNoRunningAppHostExitsSuccessfully ▶️ View Recording
UnAwaitedChainsCompileWithAutoResolvePromises ▶️ View Recording

📹 Recordings uploaded automatically from CI run #24596593940

Copy link
Copy Markdown
Member

@JamesNK JamesNK left a comment

Choose a reason for hiding this comment

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

Clean, focused change. No bugs, security issues, correctness errors, or convention violations found.

  • Refactoring from nullable DetectNodeVersion to ResolveNodeVersion + TryDetectPinnedNodeVersion is sound
  • .tool-versions whitespace fix correctly handles tabs and mixed whitespace
  • engines.node removal is intentional and properly labeled as breaking change
  • Test coverage includes tab-delimited .tool-versions regression and engines.node ignore verification

@davidfowl davidfowl merged commit 2fbe120 into main Apr 20, 2026
284 checks passed
@github-actions github-actions bot added this to the 13.3 milestone Apr 20, 2026
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.

Auto-generated Dockerfile uses outdated Node.js version from engines field

4 participants