-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged pnpm6 experiment into pnpm detector (#1145)
* merged pnpm6 into pnpm detector * bump version and make the factory method private * name of type * improved logging * added telemetry record for pnpm, and other minor updates to methods for conciseness * standardize the invalid version telemetry object * removed invalid version file
- Loading branch information
1 parent
9c3b0d5
commit 393db47
Showing
12 changed files
with
393 additions
and
419 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
...crosoft.ComponentDetection.Common/Telemetry/Records/InvalidParseVersionTelemetryRecord.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace Microsoft.ComponentDetection.Common.Telemetry.Records; | ||
|
||
public class InvalidParseVersionTelemetryRecord : BaseDetectionTelemetryRecord | ||
{ | ||
public override string RecordName => "InvalidParseVersion"; | ||
|
||
public string DetectorId { get; set; } | ||
|
||
public string FilePath { get; set; } | ||
|
||
public string Version { get; set; } | ||
|
||
public string MaxVersion { get; set; } | ||
} |
10 changes: 0 additions & 10 deletions
10
src/Microsoft.ComponentDetection.Common/Telemetry/Records/PipReportVersionTelemetryRecord.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/Microsoft.ComponentDetection.Detectors/pnpm/IPnpmDetector.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace Microsoft.ComponentDetection.Detectors.Pnpm; | ||
|
||
using Microsoft.ComponentDetection.Contracts; | ||
|
||
/// <summary> | ||
/// Interface that represents a version of the pnpm detector. | ||
/// </summary> | ||
public interface IPnpmDetector | ||
{ | ||
/// <summary> | ||
/// Parses a yaml file content in pnmp format into the dependecy graph. | ||
/// </summary> | ||
/// <param name="yamlFileContent">Content of the yaml file that contains the pnpm dependencies.</param> | ||
/// <param name="singleFileComponentRecorder">Component recorder to which to write the dependency graph.</param> | ||
public void RecordDependencyGraphFromFile(string yamlFileContent, ISingleFileComponentRecorder singleFileComponentRecorder); | ||
} |
58 changes: 58 additions & 0 deletions
58
src/Microsoft.ComponentDetection.Detectors/pnpm/Pnpm5Detector.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
namespace Microsoft.ComponentDetection.Detectors.Pnpm; | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.ComponentDetection.Contracts; | ||
|
||
public class Pnpm5Detector : IPnpmDetector | ||
{ | ||
public const string MajorVersion = "5"; | ||
|
||
public void RecordDependencyGraphFromFile(string yamlFileContent, ISingleFileComponentRecorder singleFileComponentRecorder) | ||
{ | ||
var yaml = PnpmParsingUtilities.DeserializePnpmYamlV5File(yamlFileContent); | ||
|
||
foreach (var packageKeyValue in yaml.Packages ?? Enumerable.Empty<KeyValuePair<string, Package>>()) | ||
{ | ||
// Ignore file: as these are local packages. | ||
if (packageKeyValue.Key.StartsWith("file:")) | ||
{ | ||
continue; | ||
} | ||
|
||
var parentDetectedComponent = PnpmParsingUtilities.CreateDetectedComponentFromPnpmPathV5(pnpmPackagePath: packageKeyValue.Key); | ||
var isDevDependency = packageKeyValue.Value != null && PnpmParsingUtilities.IsPnpmPackageDevDependency(packageKeyValue.Value); | ||
singleFileComponentRecorder.RegisterUsage(parentDetectedComponent, isDevelopmentDependency: isDevDependency); | ||
parentDetectedComponent = singleFileComponentRecorder.GetComponent(parentDetectedComponent.Component.Id); | ||
|
||
if (packageKeyValue.Value.Dependencies != null) | ||
{ | ||
foreach (var dependency in packageKeyValue.Value.Dependencies) | ||
{ | ||
// Ignore local packages. | ||
if (PnpmParsingUtilities.IsLocalDependency(dependency)) | ||
{ | ||
continue; | ||
} | ||
|
||
var childDetectedComponent = PnpmParsingUtilities.CreateDetectedComponentFromPnpmPathV5( | ||
pnpmPackagePath: PnpmParsingUtilities.CreatePnpmPackagePathFromDependencyV5(dependency.Key, dependency.Value)); | ||
|
||
// Older code used the root's dev dependency value. We're leaving this null until we do a second pass to look at each components' top level referrers. | ||
singleFileComponentRecorder.RegisterUsage(childDetectedComponent, parentComponentId: parentDetectedComponent.Component.Id, isDevelopmentDependency: null); | ||
} | ||
} | ||
} | ||
|
||
// PNPM doesn't know at the time of RegisterUsage being called for a dependency whether something is a dev dependency or not, so after building up the graph we look at top level referrers. | ||
foreach (var component in singleFileComponentRecorder.GetDetectedComponents()) | ||
{ | ||
var graph = singleFileComponentRecorder.DependencyGraph; | ||
var explicitReferences = graph.GetExplicitReferencedDependencyIds(component.Key); | ||
foreach (var explicitReference in explicitReferences) | ||
{ | ||
singleFileComponentRecorder.RegisterUsage(component.Value, isDevelopmentDependency: graph.IsDevelopmentDependency(explicitReference)); | ||
} | ||
} | ||
} | ||
} |
73 changes: 4 additions & 69 deletions
73
....Detectors/pnpm/Pnpm6ComponentDetector.cs → ...Detection.Detectors/pnpm/Pnpm6Detector.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 0 additions & 128 deletions
128
src/Microsoft.ComponentDetection.Detectors/pnpm/PnpmComponentDetector.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.