From 07a69a836c506e3ab8ab976ef27d4f3b672722f7 Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Mon, 5 Jul 2021 14:45:31 +0200 Subject: [PATCH] refactor: Make deprecations default mode internally modifyable --- lib/utils/logDeprecation.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/utils/logDeprecation.js b/lib/utils/logDeprecation.js index 223876a2953..a8ce16398fc 100644 --- a/lib/utils/logDeprecation.js +++ b/lib/utils/logDeprecation.js @@ -28,9 +28,21 @@ const resolveDisabledDeprecationsByService = weakMemoizee((serviceConfig) => { return new Set(disabledDeprecations); }); -const isErrorNotificationMode = (serviceConfig) => { - if (notificationModeByEnv) return notificationModeByEnv === 'error'; - return _.get(serviceConfig, 'deprecationNotificationMode') === 'error'; +const resolveMode = (serviceConfig) => { + switch (notificationModeByEnv) { + case 'error': + case 'warn': + return notificationModeByEnv; + default: + } + const modeByConfig = _.get(serviceConfig, 'deprecationNotificationMode'); + switch (modeByConfig) { + case 'error': + case 'warn': + return modeByConfig; + default: + return module.exports.defaultMode; + } }; function writeDeprecation(code, message) { @@ -70,7 +82,7 @@ module.exports = (code, message, { serviceConfig } = {}) => { } } - if (isErrorNotificationMode(serviceConfig)) { + if (resolveMode(serviceConfig) === 'error') { throw new ServerlessError( `${message}\n More Info: https://www.serverless.com/framework/docs/deprecations/#${code}`, `REJECTED_DEPRECATION_${code}` @@ -84,3 +96,4 @@ module.exports = (code, message, { serviceConfig } = {}) => { }; module.exports.triggeredDeprecations = triggeredDeprecations; +module.exports.defaultMode = 'warn';