Skip to content

Commit

Permalink
fix: NPM ENOAUDIT message capturing improvements (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
quinnturner committed Feb 14, 2020
1 parent e836b34 commit d8a1bfe
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ const yarnAuditer = require('./yarn-auditer');

function audit(pm, config, reporter) {
const auditor = pm === 'npm' ? npmAuditer : yarnAuditer;

const RETRY_ERROR_MSG = {
npm: `${
config.registry
? `npm ERR! audit Your configured registry (${config.registry}) `
: ''
}does not support audit requests`,
const PARTIAL_RETRY_ERROR_MSG = {
// The three ENOAUDIT error messages for NPM are:
// `Either your login credentials are invalid or your registry (${opts.registry}) does not support audit.`
// `Your configured registry (${opts.registry}) does not support audit requests.`
// `Your configured registry (${opts.registry}) may not support audit requests, or the audit endpoint may be temporarily unavailable.`
// Between them, all three use the phrasing 'not support audit'.
npm: `not support audit`,
yarn: '503 Service Unavailable',
};

Expand All @@ -19,12 +19,15 @@ function audit(pm, config, reporter) {
if (
attempt < config['retry-count'] &&
message &&
message.includes(RETRY_ERROR_MSG[pm])
message.includes(PARTIAL_RETRY_ERROR_MSG[pm])
) {
console.log('RETRY-RETRY');
return run(attempt + 1);
}
if (config['pass-enoaudit'] && message.includes(RETRY_ERROR_MSG[pm])) {
if (
config['pass-enoaudit'] &&
message.includes(PARTIAL_RETRY_ERROR_MSG[pm])
) {
console.warn(
'\x1b[33m%s\x1b[0m',
`ACTION RECOMMENDED: An audit could not performed due to ${
Expand Down

0 comments on commit d8a1bfe

Please sign in to comment.