Skip to content

Commit

Permalink
Fix dotnet project.assets dependency tree (#638)
Browse files Browse the repository at this point in the history
* track package versions by framework

Signed-off-by: Robert Liias <[email protected]>

* Expand package name regex

Signed-off-by: Robert Liias <[email protected]>

* Add previously missing root pkg dependencies to the tests

Signed-off-by: Robert Liias <[email protected]>

---------

Signed-off-by: Robert Liias <[email protected]>
  • Loading branch information
robaliias authored Oct 15, 2023
1 parent 812725a commit 38c1ef2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 4 additions & 4 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4702,7 +4702,7 @@ export const parseCsProjAssetsData = async function (csProjData) {
// extract name, operator, version from .NET package representation
// like "NLog >= 4.5.0"
function extractNameOperatorVersion(inputStr) {
const extractNameOperatorVersion = /([\w.]+)\s*([><=!]+)\s*([\d.]+)/;
const extractNameOperatorVersion = /([\w.-]+)\s*([><=!]+)\s*([\d.]+)/;
const match = inputStr.match(extractNameOperatorVersion);

if (match) {
Expand Down Expand Up @@ -4813,7 +4813,7 @@ export const parseCsProjAssetsData = async function (csProjData) {
}
}
pkgList.push(pkg);
pkgNameVersionMap[name] = version;
pkgNameVersionMap[name + framework] = version;
pkgAddedMap[name] = true;
}
}
Expand All @@ -4830,10 +4830,10 @@ export const parseCsProjAssetsData = async function (csProjData) {
if (dependencies) {
for (const p of Object.keys(dependencies)) {
// This condition is not required for assets json that are well-formed.
if (!pkgNameVersionMap[p]) {
if (!pkgNameVersionMap[p + framework]) {
continue;
}
let dversion = pkgNameVersionMap[p];
let dversion = pkgNameVersionMap[p + framework];
const ipurl = decodeURIComponent(
new PackageURL("nuget", "", p, dversion, null, null).toString()
);
Expand Down
3 changes: 3 additions & 0 deletions utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,9 @@ test("parse project.assets.json", async () => {
expect(dep_list["dependenciesList"][0]).toEqual({
dependsOn: [
"pkg:nuget/[email protected]",
"pkg:nuget/[email protected]",
"pkg:nuget/[email protected]",
"pkg:nuget/[email protected]",
"pkg:nuget/[email protected]",
"pkg:nuget/[email protected]",
"pkg:nuget/[email protected]",
Expand Down

0 comments on commit 38c1ef2

Please sign in to comment.