Skip to content

Commit

Permalink
feat: fixing logic that missed certain cases of bad prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
dotkas committed Nov 17, 2023
1 parent 7fa37d4 commit 9c8a9c1
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 1,067 deletions.
26 changes: 15 additions & 11 deletions lib/nuget-parser/parsers/dotnet-core-v2-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ interface DotnetPackage {
}

// Dependencies that starts with these are discarded
export const FILTERED_DEPENDENCY_PREFIX = ['runtime'];
export const FILTERED_DEPENDENCY_PREFIX = [
// `runtime` and `runtime.native` are a bit of a hot topic, see more https://github.com/dotnet/core/issues/7568.
// For our case, we are already creating the correct dependencies and their respective runtime version numbers based
// of our runtime resolution logic. So a dependency will already be `System.Net.Http@8.0.0` if running on .NET 8, thus
// removing the need for a `runtime.native.System.Net.Http@8.0.0` as well. From our investigation these runtime native
// dependencies are causing noise for the customers and are not of interested.
'runtime',
];

// The list of top level dependencies and transitive dependencies differ based on the target runtime we've defined.
// In the generated dependency file created by the `dotnet` CLI, this is organized by the target framework moniker (TFM).
Expand Down Expand Up @@ -72,6 +79,13 @@ function recursivelyPopulateNodes(
const name = depNode[0];
const version = depNode[1];

// Ignore packages with specific prefixes, which for one reason or the other are no interesting and pollutes the
// graph. Refer to comments on the individual elements in the ignore list for more information.
if (FILTERED_DEPENDENCY_PREFIX.some((prefix) => name.startsWith(prefix))) {
debug(`${name} matched a prefix we ignore, not adding to graph`);
continue;
}

const childNode = {
...targetDeps[`${name}/${version}`],
name,
Expand Down Expand Up @@ -179,16 +193,6 @@ function buildGraph(
targetFrameworkDependencies,
).reduce((acc, entry) => {
const [nameWithVersion, pkg] = entry;

// Ignore packages with specific prefixes, which for one reason or the other are no interesting and pollutes the graph.
if (
FILTERED_DEPENDENCY_PREFIX.some((prefix) =>
nameWithVersion.startsWith(prefix),
)
) {
return acc;
}

return { ...acc, [nameWithVersion]: pkg };
}, {});

Expand Down
132 changes: 0 additions & 132 deletions test/fixtures/dotnetcore/dotnet_6/expected_depgraph.json
Original file line number Diff line number Diff line change
Expand Up @@ -208,20 +208,6 @@
"version": "6.0.0"
}
},
{
"id": "runtime.native.System@4.3.0",
"info": {
"name": "runtime.native.System",
"version": "4.3.0"
}
},
{
"id": "runtime.native.System.IO.Compression@4.3.0",
"info": {
"name": "runtime.native.System.IO.Compression",
"version": "4.3.0"
}
},
{
"id": "System.IO.Compression.ZipFile@6.0.0",
"info": {
Expand Down Expand Up @@ -355,20 +341,6 @@
"version": "6.0.0"
}
},
{
"id": "runtime.native.System.Security.Cryptography.OpenSsl@4.3.0",
"info": {
"name": "runtime.native.System.Security.Cryptography.OpenSsl",
"version": "4.3.0"
}
},
{
"id": "runtime.native.System.Security.Cryptography.Apple@4.3.0",
"info": {
"name": "runtime.native.System.Security.Cryptography.Apple",
"version": "4.3.0"
}
},
{
"id": "System.Security.Cryptography.OpenSsl@6.0.0",
"info": {
Expand Down Expand Up @@ -397,13 +369,6 @@
"version": "6.0.0"
}
},
{
"id": "runtime.native.System.Net.Http@4.3.0",
"info": {
"name": "runtime.native.System.Net.Http",
"version": "4.3.0"
}
},
{
"id": "System.Net.Sockets@6.0.0",
"info": {
Expand Down Expand Up @@ -1195,12 +1160,6 @@
},
{
"nodeId": "System.Threading.Tasks@4.3.0:pruned"
},
{
"nodeId": "runtime.native.System@4.3.0"
},
{
"nodeId": "runtime.native.System.IO.Compression@4.3.0"
}
]
},
Expand Down Expand Up @@ -1314,16 +1273,6 @@
}
}
},
{
"nodeId": "runtime.native.System@4.3.0",
"pkgId": "runtime.native.System@4.3.0",
"deps": []
},
{
"nodeId": "runtime.native.System.IO.Compression@4.3.0",
"pkgId": "runtime.native.System.IO.Compression@4.3.0",
"deps": []
},
{
"nodeId": "System.IO.Compression.ZipFile@4.3.0",
"pkgId": "System.IO.Compression.ZipFile@6.0.0",
Expand Down Expand Up @@ -1711,15 +1660,6 @@
},
{
"nodeId": "System.Threading.Tasks@4.3.0:pruned"
},
{
"nodeId": "runtime.native.System@4.3.0:pruned"
},
{
"nodeId": "runtime.native.System.Net.Http@4.3.0:pruned"
},
{
"nodeId": "runtime.native.System.Security.Cryptography.OpenSsl@4.3.0:pruned"
}
]
},
Expand Down Expand Up @@ -1835,12 +1775,6 @@
},
{
"nodeId": "System.Text.Encoding@4.3.0:pruned"
},
{
"nodeId": "runtime.native.System.Security.Cryptography.Apple@4.3.0"
},
{
"nodeId": "runtime.native.System.Security.Cryptography.OpenSsl@4.3.0:pruned"
}
]
},
Expand Down Expand Up @@ -1898,9 +1832,6 @@
},
{
"nodeId": "System.Text.Encoding@4.3.0:pruned"
},
{
"nodeId": "runtime.native.System.Security.Cryptography.OpenSsl@4.3.0"
}
]
},
Expand Down Expand Up @@ -1941,11 +1872,6 @@
}
]
},
{
"nodeId": "runtime.native.System.Security.Cryptography.OpenSsl@4.3.0",
"pkgId": "runtime.native.System.Security.Cryptography.OpenSsl@4.3.0",
"deps": []
},
{
"nodeId": "System.Security.Cryptography.Primitives@4.3.0:pruned",
"pkgId": "System.Security.Cryptography.Primitives@6.0.0",
Expand All @@ -1956,21 +1882,6 @@
}
}
},
{
"nodeId": "runtime.native.System.Security.Cryptography.Apple@4.3.0",
"pkgId": "runtime.native.System.Security.Cryptography.Apple@4.3.0",
"deps": []
},
{
"nodeId": "runtime.native.System.Security.Cryptography.OpenSsl@4.3.0:pruned",
"pkgId": "runtime.native.System.Security.Cryptography.OpenSsl@4.3.0",
"deps": [],
"info": {
"labels": {
"pruned": "true"
}
}
},
{
"nodeId": "System.Security.Cryptography.Encoding@4.3.0:pruned",
"pkgId": "System.Security.Cryptography.Encoding@6.0.0",
Expand Down Expand Up @@ -2020,9 +1931,6 @@
},
{
"nodeId": "System.Text.Encoding@4.3.0:pruned"
},
{
"nodeId": "runtime.native.System.Security.Cryptography.OpenSsl@4.3.0:pruned"
}
]
},
Expand Down Expand Up @@ -2115,15 +2023,6 @@
},
{
"nodeId": "System.Threading@4.3.0:pruned"
},
{
"nodeId": "runtime.native.System@4.3.0:pruned"
},
{
"nodeId": "runtime.native.System.Net.Http@4.3.0"
},
{
"nodeId": "runtime.native.System.Security.Cryptography.OpenSsl@4.3.0:pruned"
}
]
},
Expand Down Expand Up @@ -2231,31 +2130,6 @@
}
}
},
{
"nodeId": "runtime.native.System@4.3.0:pruned",
"pkgId": "runtime.native.System@4.3.0",
"deps": [],
"info": {
"labels": {
"pruned": "true"
}
}
},
{
"nodeId": "runtime.native.System.Net.Http@4.3.0",
"pkgId": "runtime.native.System.Net.Http@4.3.0",
"deps": []
},
{
"nodeId": "runtime.native.System.Net.Http@4.3.0:pruned",
"pkgId": "runtime.native.System.Net.Http@4.3.0",
"deps": [],
"info": {
"labels": {
"pruned": "true"
}
}
},
{
"nodeId": "System.Net.Primitives@4.3.0:pruned",
"pkgId": "System.Net.Primitives@6.0.0",
Expand Down Expand Up @@ -2331,9 +2205,6 @@
},
{
"nodeId": "System.Threading@4.3.0:pruned"
},
{
"nodeId": "runtime.native.System@4.3.0:pruned"
}
]
},
Expand Down Expand Up @@ -2740,9 +2611,6 @@
},
{
"nodeId": "System.Threading@4.3.0:pruned"
},
{
"nodeId": "runtime.native.System@4.3.0:pruned"
}
]
},
Expand Down
Loading

0 comments on commit 9c8a9c1

Please sign in to comment.