Skip to content

Commit

Permalink
refactor: Ensure support for warn mode for modern deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrzesik committed Jan 14, 2022
1 parent 20afe33 commit 82303b3
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/utils/logDeprecation.js
Expand Up @@ -55,22 +55,29 @@ const resolveMode = (serviceConfig) => {
}
};

function writeDeprecation(code, message) {
function writeDeprecation(code, message, { onlyLegacy } = {}) {
const prefix = 'Serverless: ';
const messageLines = message.split('\n');
const modernLogsMessageLines = [...messageLines];
const followingLinesPrefix = ' '.repeat(prefix.length);
for (let i = 1; i < messageLines.length; ++i) {
messageLines[i] = followingLinesPrefix + messageLines[i];
}
message = messageLines.join('\n');
legacy.write(`Serverless: ${chalk.keyword('orange')(`Deprecation warning: ${message}`)}\n`);
if (!code.startsWith('EXT_')) {
modernLogsMessageLines.push(
`More Info: https://www.serverless.com/framework/docs/deprecations/#${code}`
);
legacy.write(
` ${chalk.keyword('orange')(
`More Info: https://www.serverless.com/framework/docs/deprecations/#${code}`
)}\n`
);
}
if (!onlyLegacy) {
log.warning(modernLogsMessageLines.join('\n'));
}
}

module.exports = (code, message, { serviceConfig } = {}) => {
Expand Down Expand Up @@ -167,7 +174,7 @@ module.exports.printSummary = async () => {

if (bufferedDeprecations.length === 1) {
const { code, message } = bufferedDeprecations[0];
writeDeprecation(code, message);
writeDeprecation(code, message, { onlyLegacy: true });
return;
}
const prefix = 'Serverless: ';
Expand Down

0 comments on commit 82303b3

Please sign in to comment.