class Importmap::Commands
def audit
def audit vulnerable_packages = npm.vulnerable_packages if vulnerable_packages.any? table = [["Package", "Severity", "Vulnerable versions", "Vulnerability"]] vulnerable_packages.each { |p| table << [p.name, p.severity, p.vulnerable_versions, p.vulnerability] } puts_table(table) vulnerabilities = 'vulnerability'.pluralize(vulnerable_packages.size) severities = vulnerable_packages.map(&:severity).tally.sort_by(&:last).reverse .map { |severity, count| "#{count} #{severity}" } .join(", ") puts " #{vulnerable_packages.size} #{vulnerabilities} found: #{severities}" exit 1 else puts "No vulnerable packages found" end end