diff --git a/packages/amplify-cli-core/src/overrides-manager/override-skeleton-generator.ts b/packages/amplify-cli-core/src/overrides-manager/override-skeleton-generator.ts index 018898bdef0..2ef3baa4f0d 100644 --- a/packages/amplify-cli-core/src/overrides-manager/override-skeleton-generator.ts +++ b/packages/amplify-cli-core/src/overrides-manager/override-skeleton-generator.ts @@ -2,8 +2,9 @@ import { printer, prompter } from '@aws-amplify/amplify-prompts'; import execa from 'execa'; import * as fs from 'fs-extra'; import * as path from 'path'; -import { $TSContext, AmplifyError, getPackageManager, pathManager, skipHooks } from '../index'; +import { $TSContext, AmplifyError, getPackageManager, pathManager, skipHooks, stateManager } from '../index'; import { JSONUtilities } from '../jsonUtilities'; +import { merge } from 'lodash'; /** * This method generates the default/template overrides file @@ -63,6 +64,10 @@ export const buildOverrideDir = async (cwd: string, destDirPath: string): Promis const overrideSampleTsconfigJsonPath = path.join(__dirname, '..', '..', 'resources', 'overrides-resource', 'tsconfig.json'); fs.writeFileSync(overrideBackendTsConfigJson, fs.readFileSync(overrideSampleTsconfigJsonPath)); } + + // ensure awscloudformation folder is not excluded in vscode + setSettingsJsonAwscloudformationFlagFalse(); + const packageManager = await getPackageManager(cwd); if (packageManager === null) { @@ -154,3 +159,27 @@ export const generateTsConfigforProject = (srcResourceDirPath: string, destDirPa fs.writeFileSync(overrideFileName, fs.readFileSync(path.join(srcResourceDirPath, 'override.ts.sample'))); fs.writeFileSync(resourceTsConfigFileName, fs.readFileSync(path.join(srcResourceDirPath, 'tsconfig.resource.json'))); }; + +/** + * this method sets the flag to false in vscode settings.json to show awscloudformation folder in vscode + */ +const setSettingsJsonAwscloudformationFlagFalse = (): void => { + if (stateManager.getLocalEnvInfo().defaultEditor !== 'vscode') { + return; + } + + const workspaceSettingsPath = '.vscode/settings.json'; + const exclusionRules = { + 'files.exclude': { + 'amplify/backend/awscloudformation': false, + }, + }; + + try { + // if settings file exists, safely add exclude settings to it + const settings = JSONUtilities.readJson(workspaceSettingsPath); + JSONUtilities.writeJson(workspaceSettingsPath, merge(settings, exclusionRules)); + } catch (error) { + // workspace settings file does not exist, noop + } +}; diff --git a/packages/amplify-e2e-tests/src/__tests__/init_e.test.ts b/packages/amplify-e2e-tests/src/__tests__/init_e.test.ts index 56bbe4a00ca..d7ceec14f7e 100644 --- a/packages/amplify-e2e-tests/src/__tests__/init_e.test.ts +++ b/packages/amplify-e2e-tests/src/__tests__/init_e.test.ts @@ -40,6 +40,11 @@ describe('amplify init e', () => { expect(meta.Region).toBeDefined(); const { AuthRoleName, UnauthRoleName, UnauthRoleArn, AuthRoleArn, DeploymentBucketName } = meta; + // test default vscode settings.json for awscloudformation folder + const editorSettingsPath = path.join(projRoot, '.vscode', 'settings.json'); + const editorSettings = fs.readJSONSync(editorSettingsPath); + expect(editorSettings['files.exclude']['amplify/backend/awscloudformation']).toEqual(true); + await expect(UnauthRoleName).toBeIAMRoleWithArn(UnauthRoleArn); await expect(AuthRoleName).toBeIAMRoleWithArn(AuthRoleArn); await expect(DeploymentBucketName).toBeAS3Bucket(DeploymentBucketName); @@ -47,6 +52,10 @@ describe('amplify init e', () => { // override new env await amplifyOverrideRoot(projRoot, { testingWithLatestCodebase: false }); + // test awscloudformation folder is not excluded in vscode settings.json after override + const editorSettingsAfterOverride = fs.readJSONSync(editorSettingsPath); + expect(editorSettingsAfterOverride['files.exclude']['amplify/backend/awscloudformation']).toEqual(false); + // this is where we will write overrides to const destOverrideFilePath = path.join(projRoot, 'amplify', 'backend', 'awscloudformation', 'override.ts');