From bd71b1713e84f56f62a008b58376f3c943b96ada Mon Sep 17 00:00:00 2001 From: Branden Rodgers Date: Fri, 10 Jan 2025 12:06:26 -0500 Subject: [PATCH 1/8] chore: remove support for portal env variable --- bin/cli.js | 32 +++++++++++++++++++++++++++----- lang/en.lyaml | 2 ++ lib/commonOpts.ts | 22 ---------------------- yarn.lock | 32 ++++++++++++++++++++++++++++---- 4 files changed, 57 insertions(+), 31 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 1644f7ed0..97b52a364 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -13,11 +13,7 @@ const { validateConfig, } = require('@hubspot/local-dev-lib/config'); const { logError } = require('../lib/errorHandlers/index'); -const { - setLogLevel, - getCommandName, - injectAccountIdMiddleware, -} = require('../lib/commonOpts'); +const { setLogLevel, getCommandName } = require('../lib/commonOpts'); const { validateAccount } = require('../lib/validation'); const { trackHelpUsage, @@ -176,6 +172,32 @@ const SKIP_CONFIG_VALIDATION = { auth: { target: true }, }; +/** + * Auto-injects the derivedAccountId flag into all commands + */ +const injectAccountIdMiddleware = async options => { + const { account } = options; + + // Preserves the original --account flag for certain commands. + options.providedAccountId = account; + + if (options.useEnv && process.env.HUBSPOT_ACCOUNT_ID) { + options.derivedAccountId = parseInt(process.env.HUBSPOT_ACCOUNT_ID, 10); + return; + } + + if (options.useEnv && process.env.HUBSPOT_PORTAL_ID) { + logger.error( + i18n(`${i18nKey}.injectAccountIdMiddleware.portalEnvVarDeprecated`, { + configPath: getConfigPath(), + }) + ); + process.exit(EXIT_CODES.ERROR); + } + + options.derivedAccountId = getAccountIdFromConfig(account); +}; + const loadConfigMiddleware = async options => { // Skip this when no command is provided if (!options._.length) { diff --git a/lang/en.lyaml b/lang/en.lyaml index 3ce2a43d3..4793cc5d3 100644 --- a/lang/en.lyaml +++ b/lang/en.lyaml @@ -7,6 +7,8 @@ en: cliUpdateNotification: "HubSpot CLI version {{#cyan}}{{#bold}}{currentVersion}{{/bold}}{{/cyan}} is outdated.\nRun {{ updateCommand }} to upgrade to version {{#cyan}}{{#bold}}{latestVersion}{{/bold}}{{/cyan}}" srcIsProject: "\"{{ src }}\" is in a project folder. Did you mean \"hs project {{command}}\"?" setDefaultAccountMoved: "This command has moved. Try `hs accounts use` instead" + injectAccountIdMiddleware: + portalEnvVarDeprecated: "The HUBSPOT_PORTAL_ID environment variable is deprecatted. Please use HUBSPOT_ACCOUNT_ID instead." loadConfigMiddleware: configFileExists: "A configuration file already exists at {{ configPath }}. To specify a new configuration file, delete the existing one and try again." completion: diff --git a/lib/commonOpts.ts b/lib/commonOpts.ts index ba6caf0d7..c2d37d152 100644 --- a/lib/commonOpts.ts +++ b/lib/commonOpts.ts @@ -117,28 +117,6 @@ export function getAccountId( return getAccountIdFromConfig(account); } -/** - * Auto-injects the derivedAccountId flag into all commands - */ -export async function injectAccountIdMiddleware( - options: Arguments<{ - derivedAccountId?: number | null; - account?: number | string; - }> -): Promise { - const { account } = options; - - // Preserves the original --account flag for certain commands. - options.providedAccountId = account; - - if (options.useEnv && process.env.HUBSPOT_ACCOUNT_ID) { - options.derivedAccountId = parseInt(process.env.HUBSPOT_ACCOUNT_ID, 10); - return; - } - - options.derivedAccountId = getAccountIdFromConfig(account); -} - export function getCmsPublishMode( options: Arguments<{ cmsPublishMode?: CmsPublishMode }> ): CmsPublishMode { diff --git a/yarn.lock b/yarn.lock index 8d8182926..698f7c306 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10709,7 +10709,16 @@ string-length@^4.0.1: char-regex "^1.0.2" strip-ansi "^6.0.0" -"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: +"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: 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== @@ -10791,7 +10800,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@^6.0.0, strip-ansi@^6.0.1: +"strip-ansi-cjs@npm: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== @@ -10805,6 +10814,13 @@ 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, strip-ansi@^7.1.0: version "7.1.0" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45" @@ -11829,8 +11845,7 @@ 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@^7.0.0: - name wrap-ansi-cjs +"wrap-ansi-cjs@npm: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== @@ -11848,6 +11863,15 @@ 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 f5162b44c0981a698f2e812821ebcf95e3d3a397 Mon Sep 17 00:00:00 2001 From: Branden Rodgers Date: Fri, 10 Jan 2025 13:12:12 -0500 Subject: [PATCH 2/8] deprecate the HUBSPOT_PORTAL_ID instead of remove --- bin/cli.js | 20 ++++++++++---------- lang/en.lyaml | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 97b52a364..88066988b 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -23,7 +23,7 @@ const { getIsInProject } = require('../lib/projects'); const pkg = require('../package.json'); const { i18n } = require('../lib/lang'); const { EXIT_CODES } = require('../lib/enums/exitCodes'); -const { UI_COLORS, uiCommandReference } = require('../lib/ui'); +const { UI_COLORS, uiCommandReference, uiDeprecatedTag } = require('../lib/ui'); const { checkAndWarnGitInclusion } = require('../lib/ui/git'); const removeCommand = require('../commands/remove'); @@ -183,19 +183,19 @@ const injectAccountIdMiddleware = async options => { if (options.useEnv && process.env.HUBSPOT_ACCOUNT_ID) { options.derivedAccountId = parseInt(process.env.HUBSPOT_ACCOUNT_ID, 10); - return; - } - - if (options.useEnv && process.env.HUBSPOT_PORTAL_ID) { - logger.error( + } else if (options.useEnv && process.env.HUBSPOT_PORTAL_ID) { + // HUBSPOT_PORTAL_ID is deprecated, but we'll still support it for now + // The HubSpot GH Deploy Action still uses HUBSPOT_PORTAL_ID + uiDeprecatedTag( i18n(`${i18nKey}.injectAccountIdMiddleware.portalEnvVarDeprecated`, { configPath: getConfigPath(), }) ); - process.exit(EXIT_CODES.ERROR); + process.env.HUBSPOT_ACCOUNT_ID = process.env.HUBSPOT_PORTAL_ID; + options.derivedAccountId = parseInt(process.env.HUBSPOT_ACCOUNT_ID, 10); + } else { + options.derivedAccountId = getAccountIdFromConfig(account); } - - options.derivedAccountId = getAccountIdFromConfig(account); }; const loadConfigMiddleware = async options => { @@ -283,8 +283,8 @@ const argv = yargs .middleware([ setLogLevel, setRequestHeaders, - loadConfigMiddleware, injectAccountIdMiddleware, + loadConfigMiddleware, checkAndWarnGitInclusionMiddleware, validateAccountOptions, ]) diff --git a/lang/en.lyaml b/lang/en.lyaml index 4793cc5d3..bdad31024 100644 --- a/lang/en.lyaml +++ b/lang/en.lyaml @@ -8,7 +8,7 @@ en: srcIsProject: "\"{{ src }}\" is in a project folder. Did you mean \"hs project {{command}}\"?" setDefaultAccountMoved: "This command has moved. Try `hs accounts use` instead" injectAccountIdMiddleware: - portalEnvVarDeprecated: "The HUBSPOT_PORTAL_ID environment variable is deprecatted. Please use HUBSPOT_ACCOUNT_ID instead." + portalEnvVarDeprecated: "The HUBSPOT_PORTAL_ID environment variable is deprecated. Please use HUBSPOT_ACCOUNT_ID instead." loadConfigMiddleware: configFileExists: "A configuration file already exists at {{ configPath }}. To specify a new configuration file, delete the existing one and try again." completion: From 787fd89eb2201aecfd861b105db31215cf754744 Mon Sep 17 00:00:00 2001 From: Branden Rodgers Date: Fri, 10 Jan 2025 13:36:58 -0500 Subject: [PATCH 3/8] add import, use QA LDL version --- bin/cli.js | 3 ++- package.json | 2 +- yarn.lock | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 88066988b..2d2aded94 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -8,6 +8,7 @@ const { logger } = require('@hubspot/local-dev-lib/logger'); const { addUserAgentHeader } = require('@hubspot/local-dev-lib/http'); const { loadConfig, + getAccountId, configFileExists, getConfigPath, validateConfig, @@ -194,7 +195,7 @@ const injectAccountIdMiddleware = async options => { process.env.HUBSPOT_ACCOUNT_ID = process.env.HUBSPOT_PORTAL_ID; options.derivedAccountId = parseInt(process.env.HUBSPOT_ACCOUNT_ID, 10); } else { - options.derivedAccountId = getAccountIdFromConfig(account); + options.derivedAccountId = getAccountId(account); } }; diff --git a/package.json b/package.json index a51a207e1..dddb4a37c 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.1.0", + "@hubspot/local-dev-lib": "3.1.1-beta.0", "@hubspot/serverless-dev-runtime": "7.0.1", "@hubspot/theme-preview-dev-server": "0.0.10", "@hubspot/ui-extensions-dev-server": "0.8.40", diff --git a/yarn.lock b/yarn.lock index 698f7c306..bdd3ee7c0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1446,10 +1446,10 @@ semver "^6.3.0" unixify "^1.0.0" -"@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== +"@hubspot/local-dev-lib@3.1.1-beta.0": + version "3.1.1-beta.0" + resolved "https://registry.yarnpkg.com/@hubspot/local-dev-lib/-/local-dev-lib-3.1.1-beta.0.tgz#2b827476deb4feec4b369743a5d7d056a56fc3f5" + integrity sha512-QoQZ17nc8rXOAK346KjQvMzL1O/+itoJaiE0raVhIXy7xkujrpV6kG+l6gCmnh5KKtzSrHH+uG6vj08robWC0A== dependencies: address "^2.0.1" axios "^1.3.5" From 5d597a44000a1f10028de7995e79585682812b5a Mon Sep 17 00:00:00 2001 From: Branden Rodgers Date: Fri, 10 Jan 2025 14:02:25 -0500 Subject: [PATCH 4/8] change middleware order --- bin/cli.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/cli.js b/bin/cli.js index 2d2aded94..1d5d6f68a 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -284,8 +284,8 @@ const argv = yargs .middleware([ setLogLevel, setRequestHeaders, - injectAccountIdMiddleware, loadConfigMiddleware, + injectAccountIdMiddleware, checkAndWarnGitInclusionMiddleware, validateAccountOptions, ]) From 3dad7437fc97d4a5d34582bdba75aecbc7486269 Mon Sep 17 00:00:00 2001 From: Branden Rodgers Date: Fri, 10 Jan 2025 14:13:55 -0500 Subject: [PATCH 5/8] inject account id must happen after config is loaded --- bin/cli.js | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 1d5d6f68a..06cb1e70b 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -173,6 +173,23 @@ const SKIP_CONFIG_VALIDATION = { auth: { target: true }, }; +const handleDeprecatedEnvVariables = options => { + // HUBSPOT_PORTAL_ID is deprecated, but we'll still support it for now + // The HubSpot GH Deploy Action still uses HUBSPOT_PORTAL_ID + if ( + options.useEnv && + process.env.HUBSPOT_PORTAL_ID && + !process.env.HUBSPOT_ACCOUNT_ID + ) { + uiDeprecatedTag( + i18n(`${i18nKey}.injectAccountIdMiddleware.portalEnvVarDeprecated`, { + configPath: getConfigPath(), + }) + ); + process.env.HUBSPOT_ACCOUNT_ID = process.env.HUBSPOT_PORTAL_ID; + } +}; + /** * Auto-injects the derivedAccountId flag into all commands */ @@ -184,16 +201,6 @@ const injectAccountIdMiddleware = async options => { if (options.useEnv && process.env.HUBSPOT_ACCOUNT_ID) { options.derivedAccountId = parseInt(process.env.HUBSPOT_ACCOUNT_ID, 10); - } else if (options.useEnv && process.env.HUBSPOT_PORTAL_ID) { - // HUBSPOT_PORTAL_ID is deprecated, but we'll still support it for now - // The HubSpot GH Deploy Action still uses HUBSPOT_PORTAL_ID - uiDeprecatedTag( - i18n(`${i18nKey}.injectAccountIdMiddleware.portalEnvVarDeprecated`, { - configPath: getConfigPath(), - }) - ); - process.env.HUBSPOT_ACCOUNT_ID = process.env.HUBSPOT_PORTAL_ID; - options.derivedAccountId = parseInt(process.env.HUBSPOT_ACCOUNT_ID, 10); } else { options.derivedAccountId = getAccountId(account); } @@ -284,6 +291,7 @@ const argv = yargs .middleware([ setLogLevel, setRequestHeaders, + handleDeprecatedEnvVariables, loadConfigMiddleware, injectAccountIdMiddleware, checkAndWarnGitInclusionMiddleware, From ed3f9c3cdf2297cdec62de0680dc7b93ed864d17 Mon Sep 17 00:00:00 2001 From: Branden Rodgers Date: Fri, 10 Jan 2025 14:16:21 -0500 Subject: [PATCH 6/8] use LDL 3.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dddb4a37c..e2a8bb558 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.1.1-beta.0", + "@hubspot/local-dev-lib": "3.1.1", "@hubspot/serverless-dev-runtime": "7.0.1", "@hubspot/theme-preview-dev-server": "0.0.10", "@hubspot/ui-extensions-dev-server": "0.8.40", From ec68692d9338581a342ed8443abd7d66f907f183 Mon Sep 17 00:00:00 2001 From: Branden Rodgers Date: Fri, 10 Jan 2025 14:16:49 -0500 Subject: [PATCH 7/8] update deps --- yarn.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/yarn.lock b/yarn.lock index bdd3ee7c0..065849c51 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1446,10 +1446,10 @@ semver "^6.3.0" unixify "^1.0.0" -"@hubspot/local-dev-lib@3.1.1-beta.0": - version "3.1.1-beta.0" - resolved "https://registry.yarnpkg.com/@hubspot/local-dev-lib/-/local-dev-lib-3.1.1-beta.0.tgz#2b827476deb4feec4b369743a5d7d056a56fc3f5" - integrity sha512-QoQZ17nc8rXOAK346KjQvMzL1O/+itoJaiE0raVhIXy7xkujrpV6kG+l6gCmnh5KKtzSrHH+uG6vj08robWC0A== +"@hubspot/local-dev-lib@3.1.1": + version "3.1.1" + resolved "https://registry.yarnpkg.com/@hubspot/local-dev-lib/-/local-dev-lib-3.1.1.tgz#b67646d7a7b399cebc5d74f62c389c13554e950c" + integrity sha512-/SIKBuC3ORkKMXityS6tCz2sNU7OY96slJtLM0CxRlKDCiwEGb08Lf0Ruf1PMBJnAu8iHbw/6SprefFEHEQOpw== dependencies: address "^2.0.1" axios "^1.3.5" From 91f521566f4a1df940ade926dc8b8c8392aaa428 Mon Sep 17 00:00:00 2001 From: Branden Rodgers Date: Fri, 10 Jan 2025 14:17:57 -0500 Subject: [PATCH 8/8] fix lang key --- bin/cli.js | 2 +- lang/en.lyaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 06cb1e70b..017485619 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -182,7 +182,7 @@ const handleDeprecatedEnvVariables = options => { !process.env.HUBSPOT_ACCOUNT_ID ) { uiDeprecatedTag( - i18n(`${i18nKey}.injectAccountIdMiddleware.portalEnvVarDeprecated`, { + i18n(`${i18nKey}.handleDeprecatedEnvVariables.portalEnvVarDeprecated`, { configPath: getConfigPath(), }) ); diff --git a/lang/en.lyaml b/lang/en.lyaml index bdad31024..295c67f75 100644 --- a/lang/en.lyaml +++ b/lang/en.lyaml @@ -7,7 +7,7 @@ en: cliUpdateNotification: "HubSpot CLI version {{#cyan}}{{#bold}}{currentVersion}{{/bold}}{{/cyan}} is outdated.\nRun {{ updateCommand }} to upgrade to version {{#cyan}}{{#bold}}{latestVersion}{{/bold}}{{/cyan}}" srcIsProject: "\"{{ src }}\" is in a project folder. Did you mean \"hs project {{command}}\"?" setDefaultAccountMoved: "This command has moved. Try `hs accounts use` instead" - injectAccountIdMiddleware: + handleDeprecatedEnvVariables: portalEnvVarDeprecated: "The HUBSPOT_PORTAL_ID environment variable is deprecated. Please use HUBSPOT_ACCOUNT_ID instead." loadConfigMiddleware: configFileExists: "A configuration file already exists at {{ configPath }}. To specify a new configuration file, delete the existing one and try again."