Skip to content

Commit

Permalink
refactor: Make deprecations default mode internally modifyable
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Jul 5, 2021
1 parent b124152 commit 07a69a8
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions lib/utils/logDeprecation.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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}`
Expand All @@ -84,3 +96,4 @@ module.exports = (code, message, { serviceConfig } = {}) => {
};

module.exports.triggeredDeprecations = triggeredDeprecations;
module.exports.defaultMode = 'warn';

0 comments on commit 07a69a8

Please sign in to comment.