Skip to content

Node WithXYZPackageInstallation methods should WaitForCompletion before the configure callback #760

@afscrome

Description

@afscrome

Describe the bug

Currently the WithXYZPackageInstallation methods call WaitForCompletion after they have invoked the user provided configuration callback. This makes it difficult for a user to remove this wait behavior if they don't want it.

In my case, npm isntall for my app takes several minutes, so I don't want to block app startup based on it, but I do want to make npm install an optional thing that can be run by using WithExplicitStart(), and removing the blocking WaitForCompletion()

Regression

No response

Steps to reproduce

frontEnd.WithNpmPackageInstallation(configureInstaller: installer =>
   {
      installer.WithExplicitStart();

      var toRemove = frontEnd.Resource.Annotations.OfType<WaitAnnotation>()
         .Where(x => x.Resource == installer.Resource)
         .ToList();

      foreach (var annotation in toRemove)
      {
         frontEnd.Resource.Annotations.Remove(annotation);
      }
   });

To make this work today, you have to remove the annotation in an event callback

   frontEnd.WithNpmPackageInstallation(configureInstaller: installer =>
   {
      installer.WithExplicitStart();

      // WithNpmPackageInstallation calls WaitFor after invoking the `configureInstaller` callback, so we have to remove the WaitAnnotation in `BeforeStart`
      builder.Eventing.Subscribe<BeforeStartEvent>((evt, ct) =>
      {
         var toRemove = frontEnd.Resource.Annotations.OfType<WaitAnnotation>()
            .Where(x => x.Resource == installer.Resource)
            .ToList();

         foreach (var annotation in toRemove)
         {
            frontEnd.Resource.Annotations.Remove(annotation);
         }
         return Task.CompletedTask;
      });
   });

Expected behavior

I should be able to remove the WaitFor within the configureInstaller callback itself, and not need to plumb up additional lifecycle events.

Screenshots

No response

IDE and version

VS 2022

IDE version

Version 17.14.8

Nuget packages

<PackageReference Include="CommunityToolkit.Aspire.Hosting.NodeJS.Extensions" Version="9.6.0" />

Additional context

No response

Help us help you

Yes, I'd like to be assigned to work on this item

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions