Skip to content

Commit

Permalink
Merge pull request #5875 from dependabot/mctofu/npm-flake-fix
Browse files Browse the repository at this point in the history
[npm] Randomize advisory id to avoid cache collisions across tests
  • Loading branch information
mctofu authored Oct 12, 2022
2 parents 42c1413 + 352fe7f commit 7b19233
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions npm_and_yarn/helpers/lib/npm/vulnerability-auditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,14 @@ async function findVulnerableDependencies(directory, advisories) {
}

function convertAdvisoriesToRegistryBulkFormat(advisories) {
// npm audit differentiates advisories by `id`. In order to prevent
// advisories from being clobbered, we maintain a counter so that each
// advisory gets a unique `id`.
let nextAdvisoryId = 1

return advisories.reduce((formattedAdvisories, advisory) => {
if (!formattedAdvisories[advisory.dependency_name]) {
formattedAdvisories[advisory.dependency_name] = []
}
let formattedVersions =
advisory.affected_versions.reduce((memo, version) => {
memo.push({
id: nextAdvisoryId++,
id: Math.floor(Math.random() * Number.MAX_SAFE_INTEGER),
vulnerable_versions: version
})
return memo
Expand Down

0 comments on commit 7b19233

Please sign in to comment.