Skip to content

Commit d60e505

Browse files
authored
fix: set awscloudformation flag to false in vscode settings after override (#13310)
* fix: add method to remove awscloudformation flag from settings * test: add asserts to make sure awscloudformation flag is set to false after override
1 parent f3c9c05 commit d60e505

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

packages/amplify-cli-core/src/overrides-manager/override-skeleton-generator.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { printer, prompter } from '@aws-amplify/amplify-prompts';
22
import execa from 'execa';
33
import * as fs from 'fs-extra';
44
import * as path from 'path';
5-
import { $TSContext, AmplifyError, getPackageManager, pathManager, skipHooks } from '../index';
5+
import { $TSContext, AmplifyError, getPackageManager, pathManager, skipHooks, stateManager } from '../index';
66
import { JSONUtilities } from '../jsonUtilities';
7+
import { merge } from 'lodash';
78

89
/**
910
* This method generates the default/template overrides file
@@ -63,6 +64,10 @@ export const buildOverrideDir = async (cwd: string, destDirPath: string): Promis
6364
const overrideSampleTsconfigJsonPath = path.join(__dirname, '..', '..', 'resources', 'overrides-resource', 'tsconfig.json');
6465
fs.writeFileSync(overrideBackendTsConfigJson, fs.readFileSync(overrideSampleTsconfigJsonPath));
6566
}
67+
68+
// ensure awscloudformation folder is not excluded in vscode
69+
setSettingsJsonAwscloudformationFlagFalse();
70+
6671
const packageManager = await getPackageManager(cwd);
6772

6873
if (packageManager === null) {
@@ -154,3 +159,27 @@ export const generateTsConfigforProject = (srcResourceDirPath: string, destDirPa
154159
fs.writeFileSync(overrideFileName, fs.readFileSync(path.join(srcResourceDirPath, 'override.ts.sample')));
155160
fs.writeFileSync(resourceTsConfigFileName, fs.readFileSync(path.join(srcResourceDirPath, 'tsconfig.resource.json')));
156161
};
162+
163+
/**
164+
* this method sets the flag to false in vscode settings.json to show awscloudformation folder in vscode
165+
*/
166+
const setSettingsJsonAwscloudformationFlagFalse = (): void => {
167+
if (stateManager.getLocalEnvInfo().defaultEditor !== 'vscode') {
168+
return;
169+
}
170+
171+
const workspaceSettingsPath = '.vscode/settings.json';
172+
const exclusionRules = {
173+
'files.exclude': {
174+
'amplify/backend/awscloudformation': false,
175+
},
176+
};
177+
178+
try {
179+
// if settings file exists, safely add exclude settings to it
180+
const settings = JSONUtilities.readJson(workspaceSettingsPath);
181+
JSONUtilities.writeJson(workspaceSettingsPath, merge(settings, exclusionRules));
182+
} catch (error) {
183+
// workspace settings file does not exist, noop
184+
}
185+
};

packages/amplify-e2e-tests/src/__tests__/init_e.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,22 @@ describe('amplify init e', () => {
4040
expect(meta.Region).toBeDefined();
4141
const { AuthRoleName, UnauthRoleName, UnauthRoleArn, AuthRoleArn, DeploymentBucketName } = meta;
4242

43+
// test default vscode settings.json for awscloudformation folder
44+
const editorSettingsPath = path.join(projRoot, '.vscode', 'settings.json');
45+
const editorSettings = fs.readJSONSync(editorSettingsPath);
46+
expect(editorSettings['files.exclude']['amplify/backend/awscloudformation']).toEqual(true);
47+
4348
await expect(UnauthRoleName).toBeIAMRoleWithArn(UnauthRoleArn);
4449
await expect(AuthRoleName).toBeIAMRoleWithArn(AuthRoleArn);
4550
await expect(DeploymentBucketName).toBeAS3Bucket(DeploymentBucketName);
4651

4752
// override new env
4853
await amplifyOverrideRoot(projRoot, { testingWithLatestCodebase: false });
4954

55+
// test awscloudformation folder is not excluded in vscode settings.json after override
56+
const editorSettingsAfterOverride = fs.readJSONSync(editorSettingsPath);
57+
expect(editorSettingsAfterOverride['files.exclude']['amplify/backend/awscloudformation']).toEqual(false);
58+
5059
// this is where we will write overrides to
5160
const destOverrideFilePath = path.join(projRoot, 'amplify', 'backend', 'awscloudformation', 'override.ts');
5261

0 commit comments

Comments
 (0)