Skip to content

Commit bc3fc55

Browse files
committed
audit: Verify lockfile integrity before running
Credit: @iarna
1 parent 7d43ddf commit bc3fc55

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/audit.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const audit = require('./install/audit.js')
55
const npm = require('./npm.js')
66
const log = require('npmlog')
77
const parseJson = require('json-parse-better-errors')
8+
const lockVerify = require('lock-verify')
89

910
const readFile = Bluebird.promisify(fs.readFile)
1011

@@ -66,7 +67,15 @@ function auditCmd (args, cb) {
6667
(pkgJson && pkgJson.dependencies) || {},
6768
(pkgJson && pkgJson.devDependencies) || {}
6869
)
69-
return audit.generate(sw, requires)
70+
return lockVerify(npm.prefix).then((result) => {
71+
if (result.status) return audit.generate(sw, requires)
72+
73+
const lockFile = shrinkwrap ? 'npm-shrinkwrap.json' : 'package-lock.json'
74+
const err = new Error(`Errors were found in your ${lockFile}, run npm install to fix them.\n ` +
75+
result.errors.join('\n '))
76+
err.code = 'ELOCKVERIFY'
77+
throw err
78+
})
7079
}).then((auditReport) => {
7180
return audit.submitForFullReport(auditReport)
7281
}).catch((err) => {

0 commit comments

Comments
 (0)