forked from MyEtherWallet/MyEtherWallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package-audit.js
35 lines (33 loc) · 951 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
34
35
const exec = require('child_process').exec;
// tar package is not applicable to web and waiting for other packages to update
// remove handlebars once keepkey updates their dev dependencies
const AUDIT_EXCEPTIONS = ['tar', 'js-yaml', 'handlebars', 'https-proxy-agent'];
const execute = (command, callback) => {
exec(
command,
{
maxBuffer: 2000 * 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);
});