From dc5bf05fe07e23ccb0a7546715edafadd35e6449 Mon Sep 17 00:00:00 2001 From: Allison Kemmerle Date: Tue, 17 Dec 2024 11:29:58 -0500 Subject: [PATCH 01/12] Add validation to config middleware --- bin/cli.js | 16 ++++++++++++++++ lib/constants.ts | 9 +++++++++ 2 files changed, 25 insertions(+) diff --git a/bin/cli.js b/bin/cli.js index 66cf1d431..be657879a 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -12,7 +12,9 @@ const { getAndLoadConfigIfNeeded, configFileExists, getConfigPath, + validateConfig: isValidConfig, } = require('@hubspot/local-dev-lib/config'); +const { NO_VALIDATE_LIST } = require('../lib/constants'); const { logError } = require('../lib/errorHandlers/index'); const { setLogLevel, @@ -149,6 +151,17 @@ const setRequestHeaders = () => { }; const loadConfigMiddleware = async options => { + const validateConfig = () => { + const shouldValidate = options._.every( + item => !NO_VALIDATE_LIST.includes(item) + ); + if (shouldValidate) { + if (!isValidConfig()) { + process.exit(EXIT_CODES.ERROR); + } + } + }; + // Load the new config and check for the conflicting config flag if (configFileExists(true)) { loadConfig('', options); @@ -161,6 +174,7 @@ const loadConfigMiddleware = async options => { ); process.exit(EXIT_CODES.ERROR); } + validateConfig(); return; } @@ -169,11 +183,13 @@ const loadConfigMiddleware = async options => { if (options.config && fs.existsSync(options.config)) { const { config: configPath } = options; await loadConfig(configPath, options); + validateConfig(); return; } // Load deprecated config without a config flag and with no warnings getAndLoadConfigIfNeeded(options); + validateConfig(); return; }; diff --git a/lib/constants.ts b/lib/constants.ts index 754a41d85..9ed95ecd0 100644 --- a/lib/constants.ts +++ b/lib/constants.ts @@ -80,3 +80,12 @@ export const PLATFORM_VERSION_ERROR_TYPES = { PLATFORM_VERSION_SPECIFIED_DOES_NOT_EXIST: 'PlatformVersionErrorType.PLATFORM_VERSION_SPECIFIED_DOES_NOT_EXIST', } as const; + +export const NO_VALIDATE_LIST = [ + 'init', + 'clean', + 'list', + 'remove', + 'use', + 'delete', +] as const; From 24c78e289fc7bf4e8832826b131a7ce821d8c462 Mon Sep 17 00:00:00 2001 From: Allison Kemmerle Date: Tue, 17 Dec 2024 15:47:13 -0500 Subject: [PATCH 02/12] Address feedback p1 --- .../workflows/accountManagementFlow.spec.ts | 11 +++++------ bin/cli.js | 17 +++++++++-------- lib/constants.ts | 9 --------- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/acceptance-tests/tests/workflows/accountManagementFlow.spec.ts b/acceptance-tests/tests/workflows/accountManagementFlow.spec.ts index 85904be64..523d1fdd6 100644 --- a/acceptance-tests/tests/workflows/accountManagementFlow.spec.ts +++ b/acceptance-tests/tests/workflows/accountManagementFlow.spec.ts @@ -73,12 +73,11 @@ describe('Account Management Flow', () => { describe('hs accounts list', () => { it('should not list the removed authenticated account', async () => { - const output = await testState.cli.executeWithTestConfig([ - 'accounts', - 'list', - ]); - - expect(output).not.toContain(accountName); + await expect(() => + testState.cli.executeWithTestConfig(['accounts', 'list']) + ).rejects.toThrow( + /There are no accounts defined in the configuration file/ + ); }); }); diff --git a/bin/cli.js b/bin/cli.js index be657879a..8c6383df5 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -12,9 +12,8 @@ const { getAndLoadConfigIfNeeded, configFileExists, getConfigPath, - validateConfig: isValidConfig, + validateConfig, } = require('@hubspot/local-dev-lib/config'); -const { NO_VALIDATE_LIST } = require('../lib/constants'); const { logError } = require('../lib/errorHandlers/index'); const { setLogLevel, @@ -150,13 +149,15 @@ const setRequestHeaders = () => { addUserAgentHeader('HubSpot CLI', pkg.version); }; +const NO_VALIDATE_LIST = ['init', 'auth']; + const loadConfigMiddleware = async options => { - const validateConfig = () => { + const maybeValidateConfig = () => { const shouldValidate = options._.every( item => !NO_VALIDATE_LIST.includes(item) ); if (shouldValidate) { - if (!isValidConfig()) { + if (!validateConfig()) { process.exit(EXIT_CODES.ERROR); } } @@ -174,7 +175,7 @@ const loadConfigMiddleware = async options => { ); process.exit(EXIT_CODES.ERROR); } - validateConfig(); + maybeValidateConfig(); return; } @@ -182,14 +183,14 @@ const loadConfigMiddleware = async options => { // so that getAccountIdFromConfig() in injectAccountIdMiddleware reads from the right config if (options.config && fs.existsSync(options.config)) { const { config: configPath } = options; - await loadConfig(configPath, options); - validateConfig(); + loadConfig(configPath, options); + maybeValidateConfig(); return; } // Load deprecated config without a config flag and with no warnings getAndLoadConfigIfNeeded(options); - validateConfig(); + maybeValidateConfig(); return; }; diff --git a/lib/constants.ts b/lib/constants.ts index 9ed95ecd0..754a41d85 100644 --- a/lib/constants.ts +++ b/lib/constants.ts @@ -80,12 +80,3 @@ export const PLATFORM_VERSION_ERROR_TYPES = { PLATFORM_VERSION_SPECIFIED_DOES_NOT_EXIST: 'PlatformVersionErrorType.PLATFORM_VERSION_SPECIFIED_DOES_NOT_EXIST', } as const; - -export const NO_VALIDATE_LIST = [ - 'init', - 'clean', - 'list', - 'remove', - 'use', - 'delete', -] as const; From 1b06e9c6fb89063594542d8f01c10b5b493e4f9b Mon Sep 17 00:00:00 2001 From: Allison Kemmerle Date: Tue, 17 Dec 2024 15:53:45 -0500 Subject: [PATCH 03/12] Refactor no validate list --- bin/cli.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 8c6383df5..eb4861a29 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -149,12 +149,15 @@ const setRequestHeaders = () => { addUserAgentHeader('HubSpot CLI', pkg.version); }; -const NO_VALIDATE_LIST = ['init', 'auth']; +const NO_VALIDATE_LIST = { + init: { skip: true }, + auth: { skip: true }, +}; const loadConfigMiddleware = async options => { const maybeValidateConfig = () => { const shouldValidate = options._.every( - item => !NO_VALIDATE_LIST.includes(item) + item => !(NO_VALIDATE_LIST[item] && NO_VALIDATE_LIST[item].skip) ); if (shouldValidate) { if (!validateConfig()) { From 3b63df8c5d5b2e2e0eefa74dbab497e6d74b7f33 Mon Sep 17 00:00:00 2001 From: Allison Kemmerle Date: Tue, 17 Dec 2024 15:58:46 -0500 Subject: [PATCH 04/12] Add more descriptive variables --- bin/cli.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index eb4861a29..23f2a55a7 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -149,7 +149,7 @@ const setRequestHeaders = () => { addUserAgentHeader('HubSpot CLI', pkg.version); }; -const NO_VALIDATE_LIST = { +const NO_CONFIG_VALIDATION = { init: { skip: true }, auth: { skip: true }, }; @@ -157,7 +157,8 @@ const NO_VALIDATE_LIST = { const loadConfigMiddleware = async options => { const maybeValidateConfig = () => { const shouldValidate = options._.every( - item => !(NO_VALIDATE_LIST[item] && NO_VALIDATE_LIST[item].skip) + command => + !(NO_CONFIG_VALIDATION[command] && NO_CONFIG_VALIDATION[command].skip) ); if (shouldValidate) { if (!validateConfig()) { From 2d219014c71b653e469925403a52d6464d468a4c Mon Sep 17 00:00:00 2001 From: Allison Kemmerle Date: Wed, 18 Dec 2024 11:46:23 -0500 Subject: [PATCH 05/12] Remove validateConfig from loadAndValidateOptions --- lib/validation.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/validation.ts b/lib/validation.ts index e770e2348..d970c0fd3 100644 --- a/lib/validation.ts +++ b/lib/validation.ts @@ -11,7 +11,6 @@ const { const { commaSeparatedValues } = require('@hubspot/local-dev-lib/text'); const { getConfigPath, - validateConfig, getAccountConfig, loadConfigFromEnvironment, } = require('@hubspot/local-dev-lib/config'); @@ -34,7 +33,7 @@ async function loadAndValidateOptions(options, shouldValidateAccount = true) { validAccount = await validateAccount(options); } - if (!(validateConfig() && validAccount)) { + if (!validAccount) { process.exit(EXIT_CODES.ERROR); } } From 47028a4aa6640801c0f01cd3c7b0c4ddf4f355a4 Mon Sep 17 00:00:00 2001 From: Allison Kemmerle Date: Wed, 18 Dec 2024 14:57:34 -0500 Subject: [PATCH 06/12] Bump LDL version --- package.json | 2 +- yarn.lock | 40 ++++++++-------------------------------- 2 files changed, 9 insertions(+), 33 deletions(-) diff --git a/package.json b/package.json index d9c4db28b..3b0c3dfc9 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "license": "Apache-2.0", "repository": "https://github.com/HubSpot/hubspot-cli", "dependencies": { - "@hubspot/local-dev-lib": "3.0.1", + "@hubspot/local-dev-lib": "3.1.0", "@hubspot/serverless-dev-runtime": "7.0.0", "@hubspot/theme-preview-dev-server": "0.0.10", "@hubspot/ui-extensions-dev-server": "0.8.33", diff --git a/yarn.lock b/yarn.lock index 52879ffe0..186c644fc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1463,10 +1463,10 @@ semver "^6.3.0" unixify "^1.0.0" -"@hubspot/local-dev-lib@3.0.1": - version "3.0.1" - resolved "https://registry.yarnpkg.com/@hubspot/local-dev-lib/-/local-dev-lib-3.0.1.tgz#1dd22f439d6e262353f14915a354115bbc1f5f76" - integrity sha512-h1jOmZJNdHZFbrOA5Gn815YCsix8eY81A4dkrUuDZI4MzVaJH3o4RoRalMl+Hr2e35nDrbrbcIR1RMQADPSmwg== +"@hubspot/local-dev-lib@3.1.0": + version "3.1.0" + resolved "https://registry.yarnpkg.com/@hubspot/local-dev-lib/-/local-dev-lib-3.1.0.tgz#76b5d524aa694aad2bfc6e199ee1dac314f15774" + integrity sha512-iop3PgZ0ZWejCH6PmSeYnnGwV8vGIuA4F+w7SxukdX3QfhivlczClATWPaZanv1CYJHdflqoItq1kdF8ASJJmA== dependencies: address "^2.0.1" axios "^1.3.5" @@ -10427,16 +10427,7 @@ string-length@^4.0.1: char-regex "^1.0.2" strip-ansi "^6.0.0" -"string-width-cjs@npm:string-width@^4.2.0": - version "4.2.3" - resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" - integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== - dependencies: - emoji-regex "^8.0.0" - is-fullwidth-code-point "^3.0.0" - strip-ansi "^6.0.1" - -string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3: +"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -10505,7 +10496,7 @@ stringify-object@^3.2.1, stringify-object@^3.3.0: is-obj "^1.0.1" is-regexp "^1.0.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1": +"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -10519,13 +10510,6 @@ strip-ansi@^5.2.0: dependencies: ansi-regex "^4.1.0" -strip-ansi@^6.0.0, strip-ansi@^6.0.1: - version "6.0.1" - resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" - integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== - dependencies: - ansi-regex "^5.0.1" - strip-ansi@^7.0.1: version "7.1.0" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45" @@ -11512,7 +11496,8 @@ wordwrap@^1.0.0: resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb" integrity sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q== -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: + name wrap-ansi-cjs version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== @@ -11530,15 +11515,6 @@ wrap-ansi@^6.2.0: string-width "^4.1.0" strip-ansi "^6.0.0" -wrap-ansi@^7.0.0: - version "7.0.0" - resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" - integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== - dependencies: - ansi-styles "^4.0.0" - string-width "^4.1.0" - strip-ansi "^6.0.0" - wrap-ansi@^8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214" From c3fd8cc35cb4f896afc9f9af520107a6cd95732f Mon Sep 17 00:00:00 2001 From: Allison Kemmerle Date: Thu, 19 Dec 2024 13:18:05 -0500 Subject: [PATCH 07/12] Address feedback p1 --- bin/cli.js | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 23f2a55a7..d4f2abb86 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -160,10 +160,8 @@ const loadConfigMiddleware = async options => { command => !(NO_CONFIG_VALIDATION[command] && NO_CONFIG_VALIDATION[command].skip) ); - if (shouldValidate) { - if (!validateConfig()) { - process.exit(EXIT_CODES.ERROR); - } + if (shouldValidate && !validateConfig()) { + process.exit(EXIT_CODES.ERROR); } }; @@ -179,23 +177,17 @@ const loadConfigMiddleware = async options => { ); process.exit(EXIT_CODES.ERROR); } - maybeValidateConfig(); - return; - } - - // We need to load the config when options.config exists, - // so that getAccountIdFromConfig() in injectAccountIdMiddleware reads from the right config - if (options.config && fs.existsSync(options.config)) { + } else if (options.config && fs.existsSync(options.config)) { + // We need to load the config when options.config exists, + // so that getAccountIdFromConfig() in injectAccountIdMiddleware reads from the right config const { config: configPath } = options; loadConfig(configPath, options); - maybeValidateConfig(); - return; + } else { + // Load deprecated config without a config flag and with no warnings + getAndLoadConfigIfNeeded(options); } - // Load deprecated config without a config flag and with no warnings - getAndLoadConfigIfNeeded(options); maybeValidateConfig(); - return; }; const checkAndWarnGitInclusionMiddleware = () => { From 77bebbddb2b8e8577be0735497442e9534394f1b Mon Sep 17 00:00:00 2001 From: Allison Kemmerle Date: Thu, 19 Dec 2024 16:42:26 -0500 Subject: [PATCH 08/12] Fix acceptance tests --- .../tests/commands/create.spec.ts | 27 ++++++++++++------- .../tests/workflows/cmsTemplateFlow.spec.ts | 2 +- commands/create.ts | 7 ++++- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/acceptance-tests/tests/commands/create.spec.ts b/acceptance-tests/tests/commands/create.spec.ts index 7770efe31..97717f628 100644 --- a/acceptance-tests/tests/commands/create.spec.ts +++ b/acceptance-tests/tests/commands/create.spec.ts @@ -69,7 +69,7 @@ describe('hs create', () => { }); it('creates a module', async () => { - await testState.cli.execute( + await testState.cli.executeWithTestConfig( ['create', 'module', FOLDERS.module.name], ['label', ENTER, ENTER, ENTER, 'y', ENTER, ENTER] ); @@ -80,7 +80,7 @@ describe('hs create', () => { }); it('creates a template', async () => { - await testState.cli.execute( + await testState.cli.executeWithTestConfig( ['create', 'template', FOLDERS.template.name], [ENTER] ); @@ -90,35 +90,44 @@ describe('hs create', () => { }); it('website-theme', async () => { - await testState.cli.execute(['create', FOLDERS.websiteTheme.name]); + await testState.cli.executeWithTestConfig([ + 'create', + FOLDERS.websiteTheme.name, + ]); expect( testState.existsInTestOutputDirectory(FOLDERS.websiteTheme.folder) ).toBe(true); }); it('react-app', async () => { - await testState.cli.execute(['create', FOLDERS.reactApp.name]); + await testState.cli.executeWithTestConfig([ + 'create', + FOLDERS.reactApp.name, + ]); expect(testState.existsInTestOutputDirectory(FOLDERS.reactApp.folder)).toBe( true ); }); it('vue-app', async () => { - await testState.cli.execute(['create', FOLDERS.vueApp.name]); + await testState.cli.executeWithTestConfig(['create', FOLDERS.vueApp.name]); expect(testState.existsInTestOutputDirectory(FOLDERS.vueApp.folder)).toBe( true ); }); it('webpack-serverless', async () => { - await testState.cli.execute(['create', FOLDERS.webpackServerless.name]); + await testState.cli.executeWithTestConfig([ + 'create', + FOLDERS.webpackServerless.name, + ]); expect( testState.existsInTestOutputDirectory(FOLDERS.webpackServerless.folder) ).toBe(true); }); it('api-sample', async () => { - await testState.cli.execute( + await testState.cli.executeWithTestConfig( ['create', FOLDERS.apiSample.name, FOLDERS.apiSample.name], [ENTER, ENTER] ); @@ -129,14 +138,14 @@ describe('hs create', () => { }); it('app', async () => { - await testState.cli.execute(['create', FOLDERS.app.name]); + await testState.cli.executeWithTestConfig(['create', FOLDERS.app.name]); expect(testState.existsInTestOutputDirectory(FOLDERS.app.folder)).toBe( true ); }); it('function', async () => { - await testState.cli.execute( + await testState.cli.executeWithTestConfig( ['create', 'function'], [ FOLDERS.function.name, diff --git a/acceptance-tests/tests/workflows/cmsTemplateFlow.spec.ts b/acceptance-tests/tests/workflows/cmsTemplateFlow.spec.ts index 2030e081f..680b11234 100644 --- a/acceptance-tests/tests/workflows/cmsTemplateFlow.spec.ts +++ b/acceptance-tests/tests/workflows/cmsTemplateFlow.spec.ts @@ -21,7 +21,7 @@ describe('CMS Template Flow', () => { describe('hs create', () => { it('should create a CMS template', async () => { - await testState.cli.execute( + await testState.cli.executeWithTestConfig( ['create', 'template', TEMPLATE_NAME], [ENTER] ); diff --git a/commands/create.ts b/commands/create.ts index ef180cb75..5dd1ef57f 100644 --- a/commands/create.ts +++ b/commands/create.ts @@ -26,7 +26,11 @@ const fs = require('fs-extra'); const { logError } = require('../lib/errorHandlers/index'); const { logger } = require('@hubspot/local-dev-lib/logger'); -const { setLogLevel, addGlobalOptions } = require('../lib/commonOpts'); +const { + setLogLevel, + addGlobalOptions, + addConfigOptions, +} = require('../lib/commonOpts'); const { resolveLocalPath } = require('../lib/filesystem'); const { trackCommandUsage } = require('../lib/usageTracking'); const assets = require('./create/index'); @@ -117,6 +121,7 @@ exports.builder = yargs => { hidden: true, }); + addConfigOptions(yargs); addGlobalOptions(yargs); return yargs; From ab3c51ffecad3e57bbfd2c18fa7c850364989677 Mon Sep 17 00:00:00 2001 From: Allison Kemmerle Date: Thu, 19 Dec 2024 16:43:16 -0500 Subject: [PATCH 09/12] Streamline loading config --- bin/cli.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index d4f2abb86..568d5a7f2 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -3,13 +3,11 @@ const yargs = require('yargs'); const updateNotifier = require('update-notifier'); const chalk = require('chalk'); -const fs = require('fs'); const { logger } = require('@hubspot/local-dev-lib/logger'); const { addUserAgentHeader } = require('@hubspot/local-dev-lib/http'); const { loadConfig, - getAndLoadConfigIfNeeded, configFileExists, getConfigPath, validateConfig, @@ -177,14 +175,13 @@ const loadConfigMiddleware = async options => { ); process.exit(EXIT_CODES.ERROR); } - } else if (options.config && fs.existsSync(options.config)) { + } else { // We need to load the config when options.config exists, // so that getAccountIdFromConfig() in injectAccountIdMiddleware reads from the right config const { config: configPath } = options; - loadConfig(configPath, options); - } else { - // Load deprecated config without a config flag and with no warnings - getAndLoadConfigIfNeeded(options); + if (!options._.includes('init')) { + loadConfig(configPath, options); + } } maybeValidateConfig(); From df81f4fc57c14a11cac8826fdd6a5d055757b918 Mon Sep 17 00:00:00 2001 From: Allison Kemmerle Date: Thu, 19 Dec 2024 16:54:21 -0500 Subject: [PATCH 10/12] Streamline loading config p2 --- bin/cli.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 568d5a7f2..da9a691e4 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -164,17 +164,13 @@ const loadConfigMiddleware = async options => { }; // Load the new config and check for the conflicting config flag - if (configFileExists(true)) { - loadConfig('', options); - - if (options.config) { - logger.error( - i18n(`${i18nKey}.loadConfigMiddleware.configFileExists`, { - configPath: getConfigPath(), - }) - ); - process.exit(EXIT_CODES.ERROR); - } + if (configFileExists(true) && options.config) { + logger.error( + i18n(`${i18nKey}.loadConfigMiddleware.configFileExists`, { + configPath: getConfigPath(), + }) + ); + process.exit(EXIT_CODES.ERROR); } else { // We need to load the config when options.config exists, // so that getAccountIdFromConfig() in injectAccountIdMiddleware reads from the right config From a85ce94293b436e6b52acbc80af9e199c0ab51ff Mon Sep 17 00:00:00 2001 From: Allison Kemmerle Date: Thu, 19 Dec 2024 17:00:05 -0500 Subject: [PATCH 11/12] Fix tests p2 --- commands/__tests__/create.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/__tests__/create.test.ts b/commands/__tests__/create.test.ts index 388869374..d326ccbc8 100644 --- a/commands/__tests__/create.test.ts +++ b/commands/__tests__/create.test.ts @@ -41,7 +41,7 @@ describe('commands/create', () => { it('should support the correct options', () => { createCommand.builder(yargs); - expect(yargs.option).toHaveBeenCalledTimes(2); + expect(yargs.option).toHaveBeenCalledTimes(3); expect(yargs.option).toHaveBeenCalledWith( 'internal', expect.objectContaining({ type: 'boolean', hidden: true }) From 24a38b52cc51d9d07959ff79fbb02e5078eb174b Mon Sep 17 00:00:00 2001 From: Allison Kemmerle Date: Fri, 20 Dec 2024 12:36:23 -0500 Subject: [PATCH 12/12] Simplify loading config --- bin/cli.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index da9a691e4..8ed71494c 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -163,7 +163,6 @@ const loadConfigMiddleware = async options => { } }; - // Load the new config and check for the conflicting config flag if (configFileExists(true) && options.config) { logger.error( i18n(`${i18nKey}.loadConfigMiddleware.configFileExists`, { @@ -171,13 +170,9 @@ const loadConfigMiddleware = async options => { }) ); process.exit(EXIT_CODES.ERROR); - } else { - // We need to load the config when options.config exists, - // so that getAccountIdFromConfig() in injectAccountIdMiddleware reads from the right config + } else if (!options._.includes('init')) { const { config: configPath } = options; - if (!options._.includes('init')) { - loadConfig(configPath, options); - } + loadConfig(configPath, options); } maybeValidateConfig();