Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add npm audit resolve command #10

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/cli/npm-audit.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ npm-audit(1) -- Run a security audit

npm audit [--json|--parseable]
npm audit fix [--force|--package-lock-only|--dry-run|--production|--only=dev]
npm audit resolve

## EXAMPLES

Expand Down
11 changes: 9 additions & 2 deletions lib/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const Installer = require('./install.js').Installer
const lockVerify = require('lock-verify')
const log = require('npmlog')
const npa = require('npm-package-arg')
const auditResolver = require('npm-audit-resolver')
const npm = require('./npm.js')
const output = require('./utils/output.js')
const parseJson = require('json-parse-better-errors')
Expand All @@ -21,7 +22,8 @@ auditCmd.usage = usage(
'audit',
'\nnpm audit [--json]' +
'\nnpm audit fix ' +
'[--force|--package-lock-only|--dry-run|--production|--only=(dev|prod)]'
'[--force|--package-lock-only|--dry-run|--production|--only=(dev|prod)]' +
'\nnpm audit resolve'
)

auditCmd.completion = function (opts, cb) {
Expand Down Expand Up @@ -130,7 +132,7 @@ function auditCmd (args, cb) {
err.code = 'EAUDITGLOBAL'
throw err
}
if (args.length && args[0] !== 'fix') {
if (args.length && !['fix', 'resolve'].includes(args[0])) {
return cb(new Error('Invalid audit subcommand: `' + args[0] + '`\n\nUsage:\n' + auditCmd.usage))
}
return Bluebird.all([
Expand Down Expand Up @@ -255,6 +257,11 @@ function auditCmd (args, cb) {
}
})
})
} else if (args[0] === 'resolve') {
output(`Total of ${auditResult.actions.length} actions to process`)
return auditResolver.resolveAudit(auditResult, {
prefix: npm.prefix
}).then(() => output('done.'))
} else {
const vulns =
auditResult.metadata.vulnerabilities.low +
Expand Down
5 changes: 5 additions & 0 deletions lib/install/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ exports.printFullReport = printFullReport

const Bluebird = require('bluebird')
const auditReport = require('npm-audit-report')
const auditResolver = require('npm-audit-resolver')
const treeToShrinkwrap = require('../shrinkwrap.js').treeToShrinkwrap
const packageId = require('../utils/package-id.js')
const output = require('../utils/output.js')
Expand Down Expand Up @@ -105,6 +106,9 @@ function printInstallReport (auditResult) {
}

function printFullReport (auditResult) {
auditResult = auditResolver.skipResolvedActions(auditResult, {
prefix: npm.prefix
})
return auditReport(auditResult, {
log: output,
reporter: npm.config.get('json') ? 'json' : 'detail',
Expand Down Expand Up @@ -244,6 +248,7 @@ function generateMetadata () {
return readFile(path.resolve(npm.prefix, '.git', headFile), 'utf8')
}).then((commitHash) => {
meta.commit_hash = commitHash.trim()
//hint: this should be inside promise constructor, so if it throws, promise is rejected
const proc = spawn('git', qw`diff --quiet --exit-code package.json package-lock.json`, {cwd: npm.prefix, stdio: 'ignore'})
return new Promise((resolve, reject) => {
proc.once('error', reject)
Expand Down
14 changes: 14 additions & 0 deletions node_modules/default-shell/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions node_modules/default-shell/license

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 76 additions & 0 deletions node_modules/default-shell/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions node_modules/default-shell/readme.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions node_modules/is-plain-obj/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions node_modules/is-plain-obj/license

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions node_modules/is-plain-obj/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions node_modules/is-plain-obj/readme.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading