Skip to content

Instantly share code, notes, and snippets.

@darcyclarke
Last active October 7, 2020 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darcyclarke/6d9e9de555997e9aa9fe828fe1fdef7d to your computer and use it in GitHub Desktop.
Save darcyclarke/6d9e9de555997e9aa9fe828fe1fdef7d to your computer and use it in GitHub Desktop.
A `npm audit <pkg>` proof-of-concept in bash...
#!/bin/bash
PKG=package.json
DIR=npm-audit-tmp
mkdir $DIR && cd $DIR && [[ $* == *--dry-run* && -f "../$PKG" ]] && cp "../$PKG" $PKG || echo '{}' >$PKG && npm i $1 --no-audit --package-lock-only --silent; npm audit; cd ../ && rm -rf $DIR
# Installation:
# 1. copy this into a file: /usr/local/bin/npm-audit
# 2. make it executable: chmod +x /usr/local/bin/npm-audit
# Usage:
# npm-audit <pkg> - displays the audit results for a specific package & it's dependencies
# npm-audit <pkg> --dry-run - displays the audit results for a specific package as if it had been installed in the current project
# Example(s):
# npm-audit bcrypt@4
# npm init -y && npm i express@2 && npm-audit bcrypt@4 --dry-run # creates a project, adds some dep w/ other issues & shows that audit outputs both the new & existing audit issues
# How it works:
# running install w/ --package-lock-only avoids fetching tarballs/reifying &
# npm audit can still work with just a package-lock.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment