Skip to content

Commit

Permalink
fix: issue paths for non-prod deps
Browse files Browse the repository at this point in the history
  • Loading branch information
gabidobo committed Feb 26, 2023
1 parent 772793f commit ad1049a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ const getReport = async ({
packageGraph,
onProgress: (message) => onProgress({type: 'update', stage: 'vulnerabilities', message}),
});

if (!includeDev) {
dependencyVulnerabilities = (dependencyVulnerabilities || []).filter((issue) =>
(issue?.findings?.sources || []).find(({flags}) => flags.prod),
);
}
} catch (error) {
errors.push(error);
}
Expand Down Expand Up @@ -141,9 +147,7 @@ const getReport = async ({

return {
dependencyGraph: dGraph,
dependencyVulnerabilities: (dependencyVulnerabilities || []).filter(
({findings: {affects}}) => affects.length,
),
dependencyVulnerabilities,
rootVulnerabilities,
licenseUsage,
licenseIssues,
Expand Down
12 changes: 9 additions & 3 deletions src/issues/utils.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
const https = require('https');
const semverSatisfies = require('semver/functions/satisfies');
const {aggregateDependencies} = require('../charts/utils');

const getPathsForPackage = (packageGraph, packageName, semver) => {
const parse = (node, currentPath = [], depth = 0, seenNodes = []) => {
if (seenNodes.includes(node)) {
return [];
}

const newPath = depth === 0 ? [] : [...currentPath, {name: node.name, version: node.version}];
const newPath =
depth === 0
? []
: [...currentPath, {name: node.name, version: node.version, flags: node.flags}];
if (node.name === packageName && semverSatisfies(node.version, semver)) {
return [newPath];
}

return Object.entries(node.dependencies || {}).reduce(
(agg, [, subnode]) => agg.concat(parse(subnode, newPath, depth + 1, [...seenNodes, node])),
return aggregateDependencies(node).reduce(
(agg, subnode) => agg.concat(parse(subnode, newPath, depth + 1, [...seenNodes, node])),
[],
);
};
Expand Down Expand Up @@ -46,8 +50,10 @@ const getFindings = ({packageGraph, packageName, range, allPathsAffected = true}
: getTargetPackagesFromPaths(allPaths);
const rootDependencies = getRootPackagesFromPaths(allPaths);
const paths = getDisplayPaths(allPaths);
const sources = getTargetPackagesFromPaths(allPaths);

return {
sources,
affects,
rootDependencies,
paths,
Expand Down

0 comments on commit ad1049a

Please sign in to comment.