Skip to content

Commit

Permalink
Merge pull request #184 from snyk/fix/correctly-choose-key-to-index-p…
Browse files Browse the repository at this point in the history
…kg-lock

fix: correctly choose key to index pkg lock data
  • Loading branch information
JamesPatrickGill committed Mar 27, 2023
2 parents 591bef9 + 74ebda8 commit 10f0a95
Show file tree
Hide file tree
Showing 8 changed files with 80,090 additions and 11 deletions.
18 changes: 10 additions & 8 deletions lib/dep-graph-builders/npm-lock-v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,16 @@ const getChildNodeKey = (
}
}

// If not in bundle then we can just see if it is scoped by parent
// and then just look directly for it
if (ancestry.length === 1) {
return `node_modules/${name}`;
const ancestry_names = ancestry.map((el) => el.name).concat(name);
while (ancestry_names.length > 0) {
const possible_key = `node_modules/${ancestry_names.join(
'/node_modules/',
)}`;
if (pkgs[possible_key]) {
return possible_key;
}
ancestry_names.shift();
}

const parentName = ancestry[ancestry.length - 1].name;
return pkgs[`node_modules/${parentName}/node_modules/${name}`]
? `node_modules/${parentName}/node_modules/${name}`
: `node_modules/${name}`;
return undefined;
};
Loading

0 comments on commit 10f0a95

Please sign in to comment.