Skip to content

Commit

Permalink
Cache alphabetic sort
Browse files Browse the repository at this point in the history
  • Loading branch information
feelepxyz committed May 13, 2022
1 parent 41e284c commit 09a73ed
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/commands/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const log = require('../utils/log-shim.js')
const pulseTillDone = require('../utils/pulse-till-done.js')
const reifyFinish = require('../utils/reify-finish.js')

const sortAlphabetically = (a, b) => localeCompare(a.name, b.name)

const verifySignature = async ({ message, signature, publicKey }) => {
const verifier = crypto.createVerify('SHA256')
verifier.write(message)
Expand Down Expand Up @@ -63,9 +65,8 @@ class VerifySignatures {
throw new Error('No dependencies found in current install')
}

// Sort alphabetically
const invalid = Array.from(this.invalid).sort((a, b) => localeCompare(a.name, b.name))
const missing = Array.from(this.missing).sort((a, b) => localeCompare(a.name, b.name))
const invalid = Array.from(this.invalid).sort(sortAlphabetically)
const missing = Array.from(this.missing).sort(sortAlphabetically)

const verified = invalid.length === 0 && missing.length === 0

Expand Down Expand Up @@ -307,7 +308,7 @@ class VerifySignatures {
return `${nameVersion}${suffix}`
}))

return uniquePackages.join('\n')
return [...uniquePackages].join('\n')
}

makeJSON ({ invalid, missing }) {
Expand Down

0 comments on commit 09a73ed

Please sign in to comment.