Skip to content

Refactor Node.js package installers from lifecycle hooks to ExecutableResource #736

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

Merged
merged 9 commits into from
Jun 20, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 17, 2025

This PR refactors the Node.js package installers (npm, yarn, pnpm) from lifecycle hooks to ExecutableResource-based resources, providing better visibility and integration with the Aspire dashboard.

What Changed

Before

  • Package installation was handled by lifecycle hooks during BeforeStartAsync
  • No visibility into installation progress in the dashboard
  • Limited logging capabilities
  • Process management handled manually via Process.Start

After

  • Package installers are now proper ExecutableResource instances that inherit from ExecutableResource
  • They appear as separate child resources in the Aspire dashboard
  • Full console output visibility and real-time logging
  • DCP (Distributed Application Control Plane) handles process management
  • Parent-child relationships with WaitAnnotation ensure proper startup ordering

New Architecture

Created three new resource classes:

  • NpmInstallerResource - Supports both npm install and npm ci commands
  • YarnInstallerResource - Executes yarn install command
  • PnpmInstallerResource - Executes pnpm install command

Each installer resource:

  • Is created as a child of its parent Node.js app resource
  • Uses ResourceRelationshipAnnotation to establish parent-child relationships
  • Forces the parent to wait for completion via WaitAnnotation
  • Only runs during development (excluded from publish mode)
  • Appears in the dashboard with full console output visibility

API Compatibility

No breaking changes - existing APIs work exactly the same:

var builder = DistributedApplication.CreateBuilder();

// API remains unchanged - behavior is now resource-based
var viteApp = builder.AddViteApp("frontend", "./frontend")
    .WithNpmPackageInstallation(useCI: true);

var backendApp = builder.AddYarnApp("backend", "./backend")
    .WithYarnPackageInstallation();

Benefits

  • Dashboard Visibility: Installer resources appear as separate items with real-time console output
  • Better Error Handling: Failed installations prevent app startup (fail-fast behavior)
  • Improved Observability: Full integration with Aspire's logging and monitoring
  • Proper Resource Management: DCP handles process lifecycle instead of manual process management
  • Clear Dependencies: Visual representation of installation dependencies in the dashboard

Backward Compatibility

Legacy lifecycle hook classes are marked as [Obsolete] but remain functional:

  • NpmPackageInstallerLifecycleHook
  • YarnPackageInstallerLifecycleHook
  • PnpmPackageInstallerLifecycleHook
  • NodePackageInstaller

These will be removed in a future version.

Testing

Added comprehensive test coverage including:

  • Unit tests for installer resource properties and command generation
  • Integration tests for parent-child relationships and wait annotations
  • Cross-platform compatibility tests (Windows vs Unix commands)
  • Publish mode exclusion verification
  • Dashboard visibility integration tests

Fixes #732.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • aka.ms
    • Triggering command: curl -I -sSL --retry 5 --retry-delay 2 --connect-timeout 15 REDACTED (dns block)
  • cflvsblobprodcus383.vsblob.vsassets.io
    • Triggering command: dotnet restore --ignore-failed-sources (dns block)
  • dnceng.pkgs.visualstudio.com
    • Triggering command: dotnet build src/CommunityToolkit.Aspire.Hosting.NodeJS.Extensions/CommunityToolkit.Aspire.Hosting.NodeJS.Extensions.csproj (dns block)
    • Triggering command: dotnet test tests/CommunityToolkit.Aspire.Hosting.NodeJS.Extensions.Tests/CommunityToolkit.Aspire.Hosting.NodeJS.Extensions.Tests.csproj --no-restore --verbosity minimal (dns block)
    • Triggering command: dotnet restore --ignore-failed-sources (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 4 commits June 17, 2025 04:18
Co-authored-by: aaronpowell <434140+aaronpowell@users.noreply.github.com>
…proach

Co-authored-by: aaronpowell <434140+aaronpowell@users.noreply.github.com>
…usion

Co-authored-by: aaronpowell <434140+aaronpowell@users.noreply.github.com>
…stallers

Co-authored-by: aaronpowell <434140+aaronpowell@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Refactor Node package installers to be a resource Refactor Node.js package installers from lifecycle hooks to ExecutableResource Jun 17, 2025
@Copilot Copilot AI requested a review from aaronpowell June 17, 2025 04:26
Copilot finished work on behalf of aaronpowell June 17, 2025 04:26
@aaronpowell aaronpowell marked this pull request as ready for review June 17, 2025 05:19
@aaronpowell aaronpowell added this to the 9.6 milestone Jun 18, 2025
Copy link
Contributor

Code Coverage

Package Line Rate Branch Rate Complexity Health
CommunityToolkit.Aspire.EventStore 100% 100% 46
CommunityToolkit.Aspire.GoFeatureFlag 100% 97% 74
CommunityToolkit.Aspire.Hosting.ActiveMQ 80% 40% 100
CommunityToolkit.Aspire.Hosting.ActiveMQ.MassTransit 1% 0% 14
CommunityToolkit.Aspire.Hosting.Adminer 73% 50% 20
CommunityToolkit.Aspire.Hosting.Azure.Dapr 67% 50% 828
CommunityToolkit.Aspire.Hosting.Azure.Dapr.Redis 97% 88% 36
CommunityToolkit.Aspire.Hosting.Azure.DataApiBuilder 100% 100% 22
CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps 84% 50% 28
CommunityToolkit.Aspire.Hosting.Bun 82% 71% 54
CommunityToolkit.Aspire.Hosting.Dapr 63% 51% 724
CommunityToolkit.Aspire.Hosting.DbGate 94% 50% 18
CommunityToolkit.Aspire.Hosting.Deno 84% 75% 72
CommunityToolkit.Aspire.Hosting.EventStore 94% 100% 18
CommunityToolkit.Aspire.Hosting.GoFeatureFlag 93% 50% 18
CommunityToolkit.Aspire.Hosting.Golang 90% 70% 24
CommunityToolkit.Aspire.Hosting.Java 69% 72% 120
CommunityToolkit.Aspire.Hosting.k6 58% 12% 20
CommunityToolkit.Aspire.Hosting.LavinMQ 78% 50% 18
CommunityToolkit.Aspire.Hosting.LavinMQ.MassTransit 1% 0% 14
CommunityToolkit.Aspire.Hosting.MailPit 91% 50% 14
CommunityToolkit.Aspire.Hosting.Meilisearch 73% 57% 50
CommunityToolkit.Aspire.Hosting.Minio 93% 75% 48
CommunityToolkit.Aspire.Hosting.MongoDB.Extensions 96% 83% 36
CommunityToolkit.Aspire.Hosting.MySql.Extensions 100% 88% 76
CommunityToolkit.Aspire.Hosting.Ngrok 52% 35% 82
CommunityToolkit.Aspire.Hosting.NodeJS.Extensions 46% 46% 124
CommunityToolkit.Aspire.Hosting.Ollama 67% 70% 174
CommunityToolkit.Aspire.Hosting.PapercutSmtp 92% 50% 10
CommunityToolkit.Aspire.Hosting.PostgreSQL.Extensions 98% 88% 92
CommunityToolkit.Aspire.Hosting.Python.Extensions 68% 55% 90
CommunityToolkit.Aspire.Hosting.RavenDB 63% 49% 136
CommunityToolkit.Aspire.Hosting.Redis.Extensions 100% 80% 40
CommunityToolkit.Aspire.Hosting.Rust 94% 83% 16
CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects 76% 64% 154
CommunityToolkit.Aspire.Hosting.Sqlite 96% 91% 54
CommunityToolkit.Aspire.Hosting.SqlServer.Extensions 100% 85% 76
CommunityToolkit.Aspire.MassTransit.RabbitMQ 100% 100% 30
CommunityToolkit.Aspire.Meilisearch 97% 92% 68
CommunityToolkit.Aspire.Microsoft.Data.Sqlite 37% 27% 194
CommunityToolkit.Aspire.Microsoft.EntityFrameworkCore.Sqlite 51% 50% 92
CommunityToolkit.Aspire.Minio.Client 73% 59% 88
CommunityToolkit.Aspire.OllamaSharp 71% 64% 98
CommunityToolkit.Aspire.RavenDB.Client 90% 79% 158
Summary 71% (6683 / 9396) 59% (2108 / 3592) 4268

Minimum allowed line rate is 60%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor Node package installers to be a resource
2 participants