Skip to content

Support debugging nodejs applications with the aspire vscode extension #11694

@Meir017

Description

@Meir017

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

When using the Aspire.Hosting.NodeJs library we should be able to debug nodejs apps

Describe the solution you'd like

have https://github.com/dotnet/aspire/blob/main/src/Aspire.Hosting.NodeJs/NodeExtensions.cs call the WithVSCodeDebugSupport method on the builder (probaby with null for requiredExtensionId since nodejs is built-in)

Additional context

something like this:

    public static IResourceBuilder<NodeAppResource> AddNodeApp(this IDistributedApplicationBuilder builder, [ResourceName] string name, string scriptPath, string? workingDirectory = null, string[]? args = null)
    {
        ArgumentNullException.ThrowIfNull(builder);
        ArgumentException.ThrowIfNullOrEmpty(name);
        ArgumentException.ThrowIfNullOrEmpty(scriptPath);

        args ??= [];
        string[] effectiveArgs = [scriptPath, .. args];
        workingDirectory ??= Path.GetDirectoryName(scriptPath)!;
        workingDirectory = PathNormalizer.NormalizePathForCurrentPlatform(Path.Combine(builder.AppHostDirectory, workingDirectory));

        var resource = new NodeAppResource(name, "node", workingDirectory);

        var resourceBuilder = builder.AddResource(resource)
                      .WithNodeDefaults()
                      .WithArgs(effectiveArgs);
        
-        return builder.AddResource(resource)
+        // Add VS Code debug support
+       return resourceBuilder.WithVSCodeDebugSupport(Path.Join(workingDirectory, scriptPath),
+           "node",                   // Debug adapter ID
+           null,                     // built-in extension
+           ctx => ctx.Args.RemoveAt(0); // The first argument when running from command line is the entrypoint file
+       );
    }

similar to this

resourceBuilder.WithVSCodeDebugSupport(Path.Join(appDirectory, scriptPath), "python", "ms-python.python", ctx =>
{
ctx.Args.RemoveAt(0); // The first argument when running from command line is the entrypoint file.
});

FYI @adamint

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions