Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public void RecordDependencyGraphFromFile(string yamlFileContent, ISingleFileCom
// This includes all directly and transitively referenced dependencies.
foreach (var (pnpmDependencyPath, package) in yaml.Packages ?? Enumerable.Empty<KeyValuePair<string, Package>>())
{
// Ignore "file:" as these are local packages.
// Ignore "file:" and "link:" as these are local packages.
// Such local packages should only be referenced at the top level (via ProcessDependencyList) which also skips them or from other local packages (which this skips).
// There should be no cases where a non-local package references a local package, so skipping them here should not result in failed lookups below when adding all the graph references.
if (pnpmDependencyPath.StartsWith(PnpmConstants.PnpmFileDependencyPath))
if (pnpmDependencyPath.StartsWith(PnpmConstants.PnpmFileDependencyPath) || pnpmDependencyPath.StartsWith(PnpmConstants.PnpmLinkDependencyPath))
{
continue;
}
Expand All @@ -46,6 +46,12 @@ public void RecordDependencyGraphFromFile(string yamlFileContent, ISingleFileCom
{
foreach (var (name, version) in package.Dependencies ?? Enumerable.Empty<KeyValuePair<string, string>>())
{
// Ignore local packages.
if (this.pnpmParsingUtilities.IsLocalDependency(new KeyValuePair<string, string>(name, version)))
{
continue;
}

var pnpmDependencyPath = this.pnpmParsingUtilities.ReconstructPnpmDependencyPath(name, version);

// If this lookup fails, then pnpmDependencyPath was either parsed incorrectly or constructed incorrectly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public PnpmComponentDetectorFactory(

public override IEnumerable<ComponentType> SupportedComponentTypes { get; } = [ComponentType.Npm];

public override int Version { get; } = 8;
public override int Version { get; } = 9;

public override bool NeedsAutomaticRootDependencyCalculation => true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,57 @@ public async Task TestPnpmDetector_V6_RenamedAsync()
}
}

[TestMethod]
public async Task TestPnpmDetector_V6_IgnoresLinkAndFilePackageDependenciesAsync()
{
var yamlFile = @"
lockfileVersion: '6.0'
settings:
autoInstallPeers: true
excludeLinksFromLockfile: false
importers:
.:
dependencies:
pkg-a:
specifier: 1.0.0
version: 1.0.0
packages:
/[email protected]:
resolution: {integrity: sha512-mock=}
dependencies:
pkg-link: link:../pkg-link
pkg-file: file:../pkg-file
minimist: 1.2.8
dev: false
/[email protected]:
resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==}
dev: false
link:../pkg-link:
dev: false
file:../pkg-file:
dev: false
";

var (scanResult, componentRecorder) = await this.detectorTestUtility
.WithFile("pnpm-lock.yaml", yamlFile)
.ExecuteDetectorAsync();

scanResult.ResultCode.Should().Be(ProcessingResultCode.Success);

var detectedComponents = componentRecorder.GetDetectedComponents().ToList();
detectedComponents.Should().HaveCount(2);

var names = detectedComponents.Select(c => ((NpmComponent)c.Component).Name);
names.Should().BeEquivalentTo(["pkg-a", "minimist"]);

var pkgA = detectedComponents.Single(c => ((NpmComponent)c.Component).Name == "pkg-a");
var minimist = detectedComponents.Single(c => ((NpmComponent)c.Component).Name == "minimist");

var graph = componentRecorder.GetDependencyGraphsByLocation().Values.First();
graph.IsComponentExplicitlyReferenced(pkgA.Component.Id).Should().BeTrue();
graph.GetDependenciesForComponent(pkgA.Component.Id).Should().Contain(minimist.Component.Id);
}

[TestMethod]
public async Task TestPnpmDetector_V6_BadLockVersion_EmptyAsync()
{
Expand Down