From ee8f110afe76e2e4933ef8010442e0975d935490 Mon Sep 17 00:00:00 2001 From: Omotayo Ishola Date: Mon, 1 Jul 2024 18:10:33 +0100 Subject: [PATCH 1/3] Update index.js prevent post-deployment errors due to attempts to access `require.chalk.require` which is undefined --- index.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index c4ee46b8f..add010e07 100644 --- a/index.js +++ b/index.js @@ -7,6 +7,15 @@ const {warnIfUsingSecretsWithoutTheBrefDependency} = require('./plugin/secrets') const fs = require('fs'); const path = require('path'); +function formatText(text) { + const grayText = "\x1b[37m"; // Gray text + const grayBackground = "\x1b[100m"; // Gray background + const reset = "\x1b[0m"; // Reset formatting + + // Combine ANSI escape codes with the text + return `${grayBackground}${grayText}${text}${reset}`; +} + // Disable `sls` promoting the Serverless Console because it's not compatible with PHP, it's tripping users up if (!process.env.SLS_NOTIFICATIONS_MODE) { process.env.SLS_NOTIFICATIONS_MODE = 'upgrades-only'; @@ -150,14 +159,14 @@ class ServerlessPlugin { /** @type {typeof import('chalk')} */ // @ts-ignore const chalk = require.main.require('chalk'); - utils.log(chalk.gray('View, tail, and search logs from all functions with https://dashboard.bref.sh')); + utils.log(formatText('View, tail, and search logs from all functions with https://dashboard.bref.sh')); utils.log(); }, 'before:metrics:metrics': () => { /** @type {typeof import('chalk')} */ // @ts-ignore const chalk = require.main.require('chalk'); - utils.log(chalk.gray('View all your application\'s metrics with https://dashboard.bref.sh')); + utils.log(formatText('View all your application\'s metrics with https://dashboard.bref.sh')); utils.log(); }, }; @@ -168,9 +177,9 @@ class ServerlessPlugin { if (command.startsWith('deploy') && code === 0) { /** @type {typeof import('chalk')} */ // @ts-ignore - const chalk = require.main.require('chalk'); + // const chalk = require.main.require('chalk'); // This will aslways throw an error as chalk is not available here. if we cannot load chalk into the required context utils.log(); - utils.log(chalk.gray('Want a better experience than the AWS console? Try out https://dashboard.bref.sh')); + utils.log( formatText('Want a better experience than the AWS console? Try out https://dashboard.bref.sh')); } }); } From 1b0a2524389b0fb133a405ecfb1cfb2b3dcf9271 Mon Sep 17 00:00:00 2001 From: Omotayo Ishola Date: Mon, 1 Jul 2024 18:18:19 +0100 Subject: [PATCH 2/3] removed all chalk dependencies --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index add010e07..50bd98f7a 100644 --- a/index.js +++ b/index.js @@ -158,14 +158,14 @@ class ServerlessPlugin { 'before:logs:logs': () => { /** @type {typeof import('chalk')} */ // @ts-ignore - const chalk = require.main.require('chalk'); + // const chalk = require.main.require('chalk'); utils.log(formatText('View, tail, and search logs from all functions with https://dashboard.bref.sh')); utils.log(); }, 'before:metrics:metrics': () => { /** @type {typeof import('chalk')} */ // @ts-ignore - const chalk = require.main.require('chalk'); + // const chalk = require.main.require('chalk'); utils.log(formatText('View all your application\'s metrics with https://dashboard.bref.sh')); utils.log(); }, From 920d0737e56d7d38b068b6083e35c0f2aff06d46 Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Tue, 2 Jul 2024 11:57:14 +0200 Subject: [PATCH 3/3] Support Serverless Framework v3 and v4 --- index.js | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/index.js b/index.js index 50bd98f7a..c660ab3ea 100644 --- a/index.js +++ b/index.js @@ -7,15 +7,6 @@ const {warnIfUsingSecretsWithoutTheBrefDependency} = require('./plugin/secrets') const fs = require('fs'); const path = require('path'); -function formatText(text) { - const grayText = "\x1b[37m"; // Gray text - const grayBackground = "\x1b[100m"; // Gray background - const reset = "\x1b[0m"; // Reset formatting - - // Combine ANSI escape codes with the text - return `${grayBackground}${grayText}${text}${reset}`; -} - // Disable `sls` promoting the Serverless Console because it's not compatible with PHP, it's tripping users up if (!process.env.SLS_NOTIFICATIONS_MODE) { process.env.SLS_NOTIFICATIONS_MODE = 'upgrades-only'; @@ -156,17 +147,11 @@ class ServerlessPlugin { 'bref:local:run': () => runLocal(this.serverless, options), 'bref:layers:show': () => listLayers(this.serverless, utils.log), 'before:logs:logs': () => { - /** @type {typeof import('chalk')} */ - // @ts-ignore - // const chalk = require.main.require('chalk'); - utils.log(formatText('View, tail, and search logs from all functions with https://dashboard.bref.sh')); + utils.log(this.gray('View, tail, and search logs from all functions with https://dashboard.bref.sh')); utils.log(); }, 'before:metrics:metrics': () => { - /** @type {typeof import('chalk')} */ - // @ts-ignore - // const chalk = require.main.require('chalk'); - utils.log(formatText('View all your application\'s metrics with https://dashboard.bref.sh')); + utils.log(this.gray('View all your application\'s metrics with https://dashboard.bref.sh')); utils.log(); }, }; @@ -175,11 +160,8 @@ class ServerlessPlugin { const command = serverless.processedInput.commands[0] || ''; // On successful deploy if (command.startsWith('deploy') && code === 0) { - /** @type {typeof import('chalk')} */ - // @ts-ignore - // const chalk = require.main.require('chalk'); // This will aslways throw an error as chalk is not available here. if we cannot load chalk into the required context utils.log(); - utils.log( formatText('Want a better experience than the AWS console? Try out https://dashboard.bref.sh')); + utils.log(this.gray('Want a better experience than the AWS console? Try out https://dashboard.bref.sh')); } }); } @@ -387,6 +369,16 @@ class ServerlessPlugin { } }); } + + /** + * @param {string} text + * @returns {string} + */ + gray(text) { + const grayText = "\x1b[90m"; + const reset = "\x1b[0m"; + return `${grayText}${text}${reset}`; + } } module.exports = ServerlessPlugin;