aspire icon indicating copy to clipboard operation
aspire copied to clipboard

Add installation validation with user notifications for JavaScript package managers

Open Copilot opened this issue 4 months ago • 1 comments

Description

Adds installation validation for Node.js and JavaScript package managers (npm, yarn, pnpm) following the same pattern from #12787 for Python/uv. When commands are missing, users see notifications with installation links rather than cryptic errors.

Shared Infrastructure

  • Added CoalescingAsyncOperation.cs and RequiredCommandValidator.cs references from src/Shared/ as internal shared source
  • Compiled into project via <Compile Include="$(SharedDir)..."> references

Validation Managers

Created four installation managers extending RequiredCommandValidator:

  • NodeInstallationManager - validates node command
  • NpmInstallationManager - validates npm command
  • YarnInstallationManager - validates yarn command
  • PnpmInstallationManager - validates pnpm command

Each provides EnsureInstalledAsync(bool throwOnFailure = true) and help links to installation docs.

Integration Points

Service Registration:

  • NodeInstallationManager in: AddNodeApp, AddJavaScriptApp, AddViteApp
  • Package manager validators in: WithNpm, WithYarn, WithPnpm

Validation Hooks:

  • Added OnBeforeResourceStarted hook on JavaScriptInstallerResource
  • Node validation runs first (all package managers require Node)
  • Package manager validation runs based on configured manager (npm/yarn/pnpm)
  • Uses throwOnFailure: false to show notifications without altering natural error flow

Behavior

When a command is missing:

  1. Warning logged
  2. Notification shown via IInteractionService with installation link
  3. App continues startup and fails naturally with original error
  4. Existing error behavior preserved

Example notification:

Missing command: node
Required command 'node' was not found. See installation instructions for more details.
[Installation instructions] → https://nodejs.org/en/download/

Checklist

  • Is this feature complete?
    • [x] Yes. Ready to ship.
    • [ ] No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • [x] Yes
    • [ ] No
  • Did you add public API?
    • [ ] Yes
    • [x] No
  • Does the change make any security assumptions or guarantees?
    • [ ] Yes
    • [x] No
  • Does the change require an update in our Aspire docs?
    • [ ] Yes
    • [x] No
Original prompt

Make the same change in https://github.com/dotnet/aspire/pull/12787 but for Aspire.Hosting.JavaScript. yarn, npm, pnpm and node.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot avatar Nov 08 '25 17:11 Copilot

🚀 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 -- 12840

Or

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

github-actions[bot] avatar Nov 08 '25 19:11 github-actions[bot]