Skip to content

Commit 94bc801

Browse files
Sync from internal - version 7.11.1 (#1571)
1 parent bf262b5 commit 94bc801

File tree

189 files changed

+6498
-2557
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

189 files changed

+6498
-2557
lines changed

.dockerignore

Lines changed: 0 additions & 13 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ acceptance-tests/test-output
2323
**/.claude/settings.local.json
2424

2525
# Dir to sync to public repo
26-
temp-repo-sync
26+
hs-temp-repo-sync

Dockerfile

Lines changed: 0 additions & 30 deletions
This file was deleted.

bin/cli.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import {
99
} from '../lib/usageTracking.js';
1010
import { EXIT_CODES } from '../lib/enums/exitCodes.js';
1111
import {
12-
loadAndValidateConfigMiddleware,
12+
validateConfigMiddleware,
1313
injectAccountIdMiddleware,
1414
validateAccountOptions,
1515
handleDeprecatedEnvVariables,
16+
handleCustomConfigLocationMiddleware,
1617
} from '../lib/middleware/configMiddleware.js';
1718
import { autoUpdateCLI } from '../lib/middleware/autoUpdateMiddleware.js';
1819
import { checkAndWarnGitInclusionMiddleware } from '../lib/middleware/gitMiddleware.js';
@@ -68,7 +69,8 @@ function handleFailure(msg: string, err: Error, yargs: Argv): void {
6869
logError(err);
6970
}
7071

71-
if (msg === null) {
72+
if (msg === null && !err) {
73+
// Required so running `hs` without a command shows the help
7274
yargs.showHelp('log');
7375
process.exit(EXIT_CODES.SUCCESS);
7476
} else {
@@ -78,13 +80,13 @@ function handleFailure(msg: string, err: Error, yargs: Argv): void {
7880

7981
const argv = yargs(process.argv.slice(2))
8082
.usage('The command line interface to interact with HubSpot.')
81-
// loadConfigMiddleware loads the new hidden config for all commands
8283
.middleware([
8384
setCLILogLevel,
8485
setRequestHeaders,
8586
handleDeprecatedEnvVariables,
86-
loadAndValidateConfigMiddleware,
87+
handleCustomConfigLocationMiddleware,
8788
injectAccountIdMiddleware,
89+
validateConfigMiddleware,
8890
autoUpdateCLI,
8991
checkAndWarnGitInclusionMiddleware,
9092
validateAccountOptions,

commands/__tests__/getStarted.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import { MockedFunction } from 'vitest';
22
import getStartedCommand from '../getStarted.js';
33
import { trackCommandUsage } from '../../lib/usageTracking.js';
44
import { promptUser } from '../../lib/prompts/promptUtils.js';
5+
import { getConfigAccountById } from '@hubspot/local-dev-lib/config';
56
import { projectNameAndDestPrompt } from '../../lib/prompts/projectNameAndDestPrompt.js';
67
import { cloneGithubRepo } from '@hubspot/local-dev-lib/github';
8+
import { HubSpotConfigAccount } from '@hubspot/local-dev-lib/types/Accounts';
79
import {
810
getProjectConfig,
911
writeProjectConfig,
@@ -24,6 +26,7 @@ vi.mock('../../lib/ui/logger');
2426
vi.mock('../../lib/errorHandlers');
2527
vi.mock('@hubspot/local-dev-lib/github');
2628
vi.mock('../../lib/dependencyManagement');
29+
vi.mock('@hubspot/local-dev-lib/config');
2730

2831
vi.mock('open');
2932
vi.mock('fs-extra', () => ({
@@ -37,6 +40,17 @@ vi.mock('fs-extra', () => ({
3740
describe('commands/get-started', () => {
3841
beforeEach(() => {
3942
vi.clearAllMocks();
43+
44+
// @TODO Revisit config mocking in tests
45+
(
46+
getConfigAccountById as MockedFunction<typeof getConfigAccountById>
47+
).mockReturnValue({
48+
accountId: 12345,
49+
name: 'Test Account',
50+
authType: 'personalaccesskey',
51+
personalAccessKey: 'test-key',
52+
env: 'prod',
53+
} as HubSpotConfigAccount);
4054
});
4155

4256
describe('command', () => {

commands/__tests__/project.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import migrateApp from '../project/migrateApp.js';
1313
import migrate from '../project/migrate.js';
1414
import cloneApp from '../project/cloneApp.js';
1515
import installDeps from '../project/installDeps.js';
16+
import lint from '../project/lint.js';
1617
import updateDeps from '../project/updateDeps.js';
1718
import validate from '../project/validate.js';
1819
import profileCommands from '../project/profile.js';
@@ -39,6 +40,7 @@ vi.mock('../project/migrate', () => ({
3940
default: {},
4041
}));
4142
vi.mock('../project/installDeps');
43+
vi.mock('../project/lint');
4244
vi.mock('../project/profile');
4345
vi.mock('../../lib/commonOpts');
4446

@@ -78,6 +80,7 @@ describe('commands/project', () => {
7880
migrate,
7981
cloneApp,
8082
installDeps,
83+
lint,
8184
updateDeps,
8285
profileCommands,
8386
validate,

commands/account/__tests__/rename.test.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import accountRenameCommand, { AccountRenameArgs } from '../rename.js';
77
import * as config from '@hubspot/local-dev-lib/config';
88
import { logError } from '../../../lib/errorHandlers/index.js';
99
import { EXIT_CODES } from '../../../lib/enums/exitCodes.js';
10+
import * as usageTracking from '../../../lib/usageTracking.js';
1011

1112
vi.mock('../../../lib/commonOpts');
1213
vi.mock('@hubspot/local-dev-lib/config');
1314
vi.mock('../../../lib/errorHandlers/index.js');
15+
vi.mock('../../../lib/usageTracking.js');
1416

1517
const positionalSpy = vi
1618
.spyOn(yargs as Argv, 'positional')
@@ -19,8 +21,9 @@ const exampleSpy = vi
1921
.spyOn(yargs as Argv, 'example')
2022
.mockReturnValue(yargs as Argv);
2123

22-
const renameAccountSpy = vi.spyOn(config, 'renameAccount');
24+
const renameAccountSpy = vi.spyOn(config, 'renameConfigAccount');
2325
const processExitSpy = vi.spyOn(process, 'exit');
26+
const trackCommandUsageSpy = vi.spyOn(usageTracking, 'trackCommandUsage');
2427

2528
describe('commands/account/rename', () => {
2629
const yargsMock = yargs as Argv;
@@ -44,7 +47,7 @@ describe('commands/account/rename', () => {
4447

4548
beforeEach(() => {
4649
vi.clearAllMocks();
47-
renameAccountSpy.mockResolvedValue(undefined);
50+
renameAccountSpy.mockReturnValue(undefined);
4851
processExitSpy.mockImplementation(() => {
4952
throw new Error('process.exit called');
5053
});
@@ -58,6 +61,11 @@ describe('commands/account/rename', () => {
5861
await expect(accountRenameCommand.handler(args)).rejects.toThrow(
5962
'process.exit called'
6063
);
64+
expect(trackCommandUsageSpy).toHaveBeenCalledWith(
65+
'accounts-rename',
66+
undefined,
67+
undefined
68+
);
6169
expect(renameAccountSpy).toHaveBeenCalledWith(
6270
'myExistingAccountName',
6371
'my-new-account-name'
@@ -67,12 +75,19 @@ describe('commands/account/rename', () => {
6775

6876
it('should handle errors when renameAccount throws', async () => {
6977
const error = new Error('Failed to rename account');
70-
renameAccountSpy.mockRejectedValue(error);
78+
renameAccountSpy.mockImplementation(() => {
79+
throw error;
80+
});
7181

7282
await expect(accountRenameCommand.handler(args)).rejects.toThrow(
7383
'process.exit called'
7484
);
7585

86+
expect(trackCommandUsageSpy).toHaveBeenCalledWith(
87+
'accounts-rename',
88+
undefined,
89+
undefined
90+
);
7691
expect(renameAccountSpy).toHaveBeenCalledWith(
7792
'myExistingAccountName',
7893
'my-new-account-name'

commands/account/auth.ts

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
import { Argv, ArgumentsCamelCase } from 'yargs';
22
import {
3-
loadConfig,
4-
updateAccountConfig,
5-
writeConfig,
3+
updateConfigAccount,
64
createEmptyConfigFile,
7-
deleteEmptyConfigFile,
5+
deleteConfigFileIfEmpty,
6+
getConfigFilePath,
7+
localConfigFileExists,
8+
globalConfigFileExists,
89
} from '@hubspot/local-dev-lib/config';
9-
import {
10-
configFileExists,
11-
getConfigPath,
12-
} from '@hubspot/local-dev-lib/config/migrate';
13-
import { getAccountIdentifier } from '@hubspot/local-dev-lib/config/getAccountIdentifier';
1410
import {
1511
getAccessToken,
1612
updateConfigWithAccessToken,
1713
} from '@hubspot/local-dev-lib/personalAccessKey';
1814
import { ENVIRONMENTS } from '@hubspot/local-dev-lib/constants/environments';
1915
import { toKebabCase } from '@hubspot/local-dev-lib/text';
2016
import { Environment } from '@hubspot/local-dev-lib/types/Config';
21-
import { CLIAccount } from '@hubspot/local-dev-lib/types/Accounts';
17+
import { HubSpotConfigAccount } from '@hubspot/local-dev-lib/types/Accounts';
2218
import { PERSONAL_ACCESS_KEY_AUTH_METHOD } from '@hubspot/local-dev-lib/constants/auth';
2319
import { handleMerge, handleMigration } from '../../lib/configMigrate.js';
2420
import { handleExit } from '../../lib/process.js';
@@ -52,7 +48,7 @@ async function updateConfigWithNewAccount(
5248
configAlreadyExists: boolean,
5349
providedPersonalAccessKey?: string,
5450
accountId?: number
55-
): Promise<CLIAccount | null> {
51+
): Promise<HubSpotConfigAccount | null> {
5652
try {
5753
const { personalAccessKey } = providedPersonalAccessKey
5854
? { personalAccessKey: providedPersonalAccessKey }
@@ -84,10 +80,9 @@ async function updateConfigWithNewAccount(
8480
updatedConfig.name = (
8581
await cliAccountNamePrompt(defaultAccountName)
8682
).name;
87-
updateAccountConfig({
83+
updateConfigAccount({
8884
...updatedConfig,
8985
});
90-
writeConfig();
9186
}
9287

9388
return updatedConfig;
@@ -98,8 +93,8 @@ async function updateConfigWithNewAccount(
9893
}
9994

10095
async function handleConfigMigration(): Promise<boolean> {
101-
const deprecatedConfigExists = configFileExists(false);
102-
const globalConfigExists = configFileExists(true);
96+
const deprecatedConfigExists = localConfigFileExists();
97+
const globalConfigExists = globalConfigFileExists();
10398

10499
// No deprecated config exists, so no migration is needed
105100
if (!deprecatedConfigExists) {
@@ -181,15 +176,13 @@ async function handler(
181176
process.exit(EXIT_CODES.ERROR);
182177
}
183178

184-
const configAlreadyExists = configFileExists(true);
179+
const configAlreadyExists = globalConfigFileExists();
185180

186181
if (!configAlreadyExists) {
187-
createEmptyConfigFile({}, true);
182+
createEmptyConfigFile(true);
188183
}
189184

190-
loadConfig('');
191-
192-
handleExit(deleteEmptyConfigFile);
185+
handleExit(deleteConfigFileIfEmpty);
193186

194187
const updatedConfig = await updateConfigWithNewAccount(
195188
args.qa ? ENVIRONMENTS.QA : ENVIRONMENTS.PROD,
@@ -209,20 +202,20 @@ async function handler(
209202
process.exit(EXIT_CODES.ERROR);
210203
}
211204

212-
const accountId = getAccountIdentifier(updatedConfig);
205+
const { accountId, name } = updatedConfig;
213206

214207
if (!configAlreadyExists) {
215208
uiLogger.log('');
216209
uiLogger.success(
217210
commands.account.subcommands.auth.success.configFileCreated(
218-
getConfigPath('', true)!
211+
getConfigFilePath()
219212
)
220213
);
221214
uiLogger.success(
222-
commands.account.subcommands.auth.success.configFileUpdated(accountId!)
215+
commands.account.subcommands.auth.success.configFileUpdated(accountId)
223216
);
224217
} else {
225-
await setAsDefaultAccountPrompt(updatedConfig.name!);
218+
await setAsDefaultAccountPrompt(name);
226219
}
227220

228221
uiFeatureHighlight([

0 commit comments

Comments
 (0)