From 859fe158d692bcbf35d71885afa2e23830657156 Mon Sep 17 00:00:00 2001 From: "@zimeg" Date: Thu, 27 Jun 2024 17:03:45 -0700 Subject: [PATCH] cli-hooks(fix): remove environment variable requirements from the start hook --- packages/cli-hooks/src/start.js | 19 ------------ packages/cli-hooks/src/start.spec.js | 43 ---------------------------- 2 files changed, 62 deletions(-) diff --git a/packages/cli-hooks/src/start.js b/packages/cli-hooks/src/start.js index 741c48528..8f08f81c4 100755 --- a/packages/cli-hooks/src/start.js +++ b/packages/cli-hooks/src/start.js @@ -19,8 +19,6 @@ if (fs.realpathSync(process.argv[1]) === fileURLToPath(import.meta.url)) { * @param {string} cwd - The current working directory of the project. */ export default function start(cwd) { - validateEnvironment(); - const customPath = process.env.SLACK_CLI_CUSTOM_FILE_PATH; const pkgJSONMain = getPackageJSONMain(cwd); const pkgJSONDefault = 'app.js'; @@ -53,20 +51,3 @@ function getPackageJSONMain(cwd) { return undefined; } } - -/** - * Confirms environment variables are prepared by the CLI. - */ -function validateEnvironment() { - const missingTokenError = `Missing the {type} token needed to start the app with Socket Mode. -Hints: Setting the {token} environment variable is required. -Check: Confirm that you are using the latest version of the Slack CLI.`; - if (!process.env.SLACK_CLI_XOXB) { - const missingBotTokenError = missingTokenError.replace('{type}', 'bot').replace('{token}', 'SLACK_CLI_XOXB'); - throw new Error(missingBotTokenError); - } - if (!process.env.SLACK_CLI_XAPP) { - const missingAppTokenError = missingTokenError.replace('{type}', 'app').replace('{token}', 'SLACK_CLI_XAPP'); - throw new Error(missingAppTokenError); - } -} diff --git a/packages/cli-hooks/src/start.spec.js b/packages/cli-hooks/src/start.spec.js index 1561c72e9..e6cba8a6f 100644 --- a/packages/cli-hooks/src/start.spec.js +++ b/packages/cli-hooks/src/start.spec.js @@ -126,47 +126,4 @@ describe('start implementation', async () => { }); }); }); - - describe('without valid tokens', async () => { - beforeEach(() => { - sinon.stub(console, 'log'); - delete process.env.SLACK_CLI_XOXB; - delete process.env.SLACK_CLI_XAPP; - }); - afterEach(() => { - sinon.restore(); - delete process.env.SLACK_CLI_XOXB; - delete process.env.SLACK_CLI_XAPP; - }); - - it('should error without a bot token', async () => { - try { - process.env.SLACK_CLI_XAPP = 'xapp-example'; - start('./'); - } catch (err) { - if (err instanceof Error) { - assert(err.message.includes('Missing the bot token needed to start the app with Socket Mode.')); - assert(err.message.includes('Hints: Setting the SLACK_CLI_XOXB environment variable is required.')); - assert(err.message.includes('Check: Confirm that you are using the latest version of the Slack CLI.')); - return; - } - } - assert(false); - }); - - it('should error without an app token', async () => { - try { - process.env.SLACK_CLI_XOXB = 'xoxb-example'; - start('./'); - } catch (err) { - if (err instanceof Error) { - assert(err.message.includes('Missing the app token needed to start the app with Socket Mode.')); - assert(err.message.includes('Hints: Setting the SLACK_CLI_XAPP environment variable is required.')); - assert(err.message.includes('Check: Confirm that you are using the latest version of the Slack CLI.')); - return; - } - } - assert(false); - }); - }); });