Skip to content

Commit

Permalink
Improves dotnet dependency tree with case insensitive match (#1586)
Browse files Browse the repository at this point in the history
Signed-off-by: Prabhu Subramanian <[email protected]>
  • Loading branch information
prabhu authored Jan 21, 2025
1 parent eb3ed20 commit 34f2242
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 9 deletions.
6 changes: 5 additions & 1 deletion lib/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5986,7 +5986,11 @@ export function trimComponents(components) {
const keyCache = {};
const filteredComponents = [];
for (const comp of components) {
const key = comp.purl || comp["bom-ref"] || comp.name + comp.version;
const key = (
comp.purl ||
comp["bom-ref"] ||
comp.name + comp.version
).toLowerCase();
if (!keyCache[key]) {
keyCache[key] = comp;
} else {
Expand Down
34 changes: 30 additions & 4 deletions lib/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9431,17 +9431,43 @@ export function parseCsProjAssetsData(csProjData, assetsJsonFile) {
continue;
}
const targetNameVersion = `${nameOperatorVersion.name}/${nameOperatorVersion.version}`;

// skip if the dep is not in the targets for whatever reason
let nameToUse = nameOperatorVersion.name;
// Due to the difference in casing, we might arrive this case where a simple lookup doesn't succeed.
// Instead of skipping, let's work harder to find a match.
if (!csProjData.targets[frameworkTarget][targetNameVersion]) {
continue;
let matchFound = false;
for (const fkeys of Object.keys(
csProjData.targets[frameworkTarget],
)) {
const tmpParts = fkeys.split("/");
const tname = tmpParts[0];
const tversion = tmpParts[1];
if (
tname.toLowerCase() === nameOperatorVersion.name.toLowerCase() &&
tversion === nameOperatorVersion.version
) {
nameToUse = tname;
matchFound = true;
break;
}
}
if (!matchFound) {
if (DEBUG_MODE) {
console.log(
"Unable to match",
dependencyName,
"with a target name. The dependency tree will be imprecise.",
);
}
continue;
}
}

const dpurl = decodeURIComponent(
new PackageURL(
"nuget",
"",
nameOperatorVersion.name,
nameToUse,
nameOperatorVersion.version,
null,
null,
Expand Down
4 changes: 3 additions & 1 deletion lib/helpers/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ export function validateProps(bomJson) {
let isWorkspaceMode = false;
if (bomJson?.components) {
for (const comp of bomJson.components) {
if (!["library", "framework"].includes(comp.type)) {
continue;
}
if (!comp.properties) {
warningsList.push(`${comp["bom-ref"]} lacks properties.`);
} else {
Expand All @@ -296,7 +299,6 @@ export function validateProps(bomJson) {
}
}
if (
["library", "framework"].includes(comp.type) &&
isWorkspaceMode &&
!workspacePropFound &&
comp?.scope !== "optional"
Expand Down
2 changes: 1 addition & 1 deletion types/lib/cli/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion types/lib/helpers/utils.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion types/lib/helpers/validator.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 34f2242

Please sign in to comment.