forked from XinFinOrg/Wallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package-audit.js
33 lines (31 loc) · 875 Bytes
/
package-audit.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const exec = require('child_process').exec;
const AUDIT_EXCEPTIONS = ['decompress', 'http-proxy', 'findings', 'elliptic', 'dot-prop', 'serialize-javascript', 'handlebars', 'cryptiles', 'bl'];
const execute = (command, callback) => {
exec(
command,
{
maxBuffer: 100000 * 1024
},
(error, stdout, stderr) => {
callback(stdout);
}
);
};
execute('npm audit --json', json => {
const advisories = JSON.parse(json).advisories;
if (!advisories) {
console.info('Most likely npm audit is unavailable', json);
process.exit(0);
}
let auditPass = true;
for (const id in advisories) {
if (
advisories[id].severity === 'high' &&
!AUDIT_EXCEPTIONS.includes(advisories[id].module_name)
) {
console.error('AUDIT Failed', advisories[id]);
auditPass = false;
}
}
if (!auditPass) process.exit(1);
});