From d8a1bfe0564d51114cc653bc552e532f9fd027be Mon Sep 17 00:00:00 2001 From: Quinn Turner Date: Fri, 14 Feb 2020 16:23:34 -0500 Subject: [PATCH] fix: NPM ENOAUDIT message capturing improvements (#129) --- lib/audit.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/audit.js b/lib/audit.js index 501ea592..98a5d4a5 100644 --- a/lib/audit.js +++ b/lib/audit.js @@ -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', }; @@ -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 ${