Skip to content

Instantly share code, notes, and snippets.

@elijahmanor
Last active September 21, 2023 21:07
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 elijahmanor/930d5e60fc49e78bd6111e31e51023ee to your computer and use it in GitHub Desktop.
Save elijahmanor/930d5e60fc49e78bd6111e31e51023ee to your computer and use it in GitHub Desktop.
Audit Single Package

Audit Single Package

npx https://gist.github.com/elijahmanor/930d5e60fc49e78bd6111e31e51023ee lodash
npx https://gist.github.com/elijahmanor/930d5e60fc49e78bd6111e31e51023ee lodash@3.10.0
npx https://gist.github.com/elijahmanor/930d5e60fc49e78bd6111e31e51023ee d3-color@3.0.1
#!/usr/bin/env node
const shell = require("shelljs");
function audit(name) {
const tempDir = `${shell.tempdir()}/audit/${name}`;
shell.mkdir("-p", tempDir);
shell.cd(tempDir);
shell.exec("npm init -y", { silent: true });
shell.exec(`npm install ${name}`, { silent: true });
const output = shell.exec("npm audit --json", { silent: true }).stdout;
shell.rm("-rf", tempDir);
return output;
}
if (process.argv.length === 2) {
console.error("Usage: Please provide a package name and an optional version\n\n");
console.error("\tnpx https://gist.github.com/elijahmanor/930d5e60fc49e78bd6111e31e51023ee lodash\n");
console.error("\tnpx https://gist.github.com/elijahmanor/930d5e60fc49e78bd6111e31e51023ee d3-color@3.0.1\n");
process.exit(1);
}
console.log(audit(process.argv[2]));
{
"name": "audit-package",
"version": "1.0.0",
"bin": "./index.js",
"dependencies": {
"shelljs": "^0.8.5"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment