Last active
September 21, 2023 12:12
-
-
Save matthiasg/de75e85dcc3ebc6796359d4b98e60d55 to your computer and use it in GitHub Desktop.
common/scripts/audit.js - for @microsoft/rush
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
const path = require('path') | |
const child_process = require('child_process') | |
const pnpmPath = path.resolve(__dirname, '../temp/pnpm-local/node_modules/pnpm/bin/pnpm.cjs') | |
const tempPath = path.resolve(__dirname, '../temp') | |
let argv = process.argv.slice(2) | |
// Simple order fix to avoid building or required a full parser (only works with the two specific parameters basically) | |
if (argv[0] === '--audit-json') { | |
argv = [argv[1], argv[2], argv[0]] | |
} | |
const options = { | |
auditLevel: (argv[0] === '--audit-level' && argv[1]) || 'low', | |
json: (argv[2] === '--audit-json' && true ) || false | |
} | |
if (!fs.existsSync(pnpmPath)) { | |
console.error(`Could not find pnpm at ${pnpmPath}`) | |
process.exit(2) | |
} | |
const parameters = ['--audit-level', options.auditLevel] | |
if (options.json) { | |
parameters.push('--json') | |
} | |
const p = child_process.spawn('node', [pnpmPath, 'audit', ...parameters], { | |
shell: true, | |
cwd: tempPath, | |
stdio: 'inherit' | |
}) | |
p.on('error', (e) => { | |
console.error(`Error running pnpm: ${e}`) | |
process.exit(100) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"commands": [ | |
... | |
{ | |
"commandKind": "global", | |
"name": "audit", | |
"summary": "Audit packages for security vulnerabilities. Only use after install, update, and link", | |
"description": "Run the pnpm audit command", | |
"shellCommand": "node common/scripts/audit.js" | |
}, | |
] | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment