Skip to content

Experiments not properly recording dev dependencies for NPM #611

@melotic

Description

@melotic

The NPM detectors record components with the following function:

public static DetectedComponent AddOrUpdateDetectedComponent(
ISingleFileComponentRecorder singleFileComponentRecorder,
TypedComponent component,
bool isDevDependency,
string parentComponentId = null,
bool isExplicitReferencedDependency = false)
{
var newComponent = new DetectedComponent(component);
singleFileComponentRecorder.RegisterUsage(newComponent, isExplicitReferencedDependency, parentComponentId, isDevDependency);
return singleFileComponentRecorder.GetComponent(component.Id);
}

newComponent should have the DevelopmentDependency property set to true, but it is not. However, dev dependencies are still properly registered. When the graph is created, the dev dependency info is propagated:

private void AddComponentToGraph(
string location,
DetectedComponent detectedComponent,
bool isExplicitReferencedDependency,
string parentComponentId,
bool? isDevelopmentDependency,
DependencyScope? dependencyScope)
{
var componentNode = new DependencyGraph.ComponentRefNode
{
Id = detectedComponent.Component.Id,
IsExplicitReferencedDependency = isExplicitReferencedDependency,
IsDevelopmentDependency = isDevelopmentDependency,
DependencyScope = dependencyScope,
};
this.DependencyGraph.AddComponent(componentNode, parentComponentId);
}

So, the dependency graph has the proper value, but the component recorder's DetectedComponent, which is used for experiments, does not have DevelopmentDependency set.

I'm not entirely sure this applies to just NPM, I think all DetectedComponents don't properly have the development dependency flag set. Perhaps the ComponentRecorder should handle this automatically.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions