From ba84e416f0fd175c2b2cea14186e8aa30183ceed Mon Sep 17 00:00:00 2001 From: Roshane Pascual Date: Mon, 11 Sep 2023 16:01:03 -0700 Subject: [PATCH 1/7] fix: pulling with env append to local files --- .../src/attach-backend-steps/a40-generateFiles.ts | 10 ++++++---- packages/amplify-cli/src/attach-backend.ts | 5 +++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/amplify-cli/src/attach-backend-steps/a40-generateFiles.ts b/packages/amplify-cli/src/attach-backend-steps/a40-generateFiles.ts index 32a62c974df..69489383e0a 100644 --- a/packages/amplify-cli/src/attach-backend-steps/a40-generateFiles.ts +++ b/packages/amplify-cli/src/attach-backend-steps/a40-generateFiles.ts @@ -16,10 +16,12 @@ export const generateFiles = async (context: $TSContext): Promise<$TSContext> => const backendDirPath = pathManager.getBackendDirPath(projectPath); const currentBackendDirPath = pathManager.getCurrentCloudBackendDirPath(projectPath); - fs.ensureDirSync(amplifyDirPath); - fs.ensureDirSync(dotConfigDirPath); - fs.ensureDirSync(backendDirPath); - fs.ensureDirSync(currentBackendDirPath); + if (context.exeInfo.isNewProject) { + fs.ensureDirSync(amplifyDirPath); + fs.ensureDirSync(dotConfigDirPath); + fs.ensureDirSync(backendDirPath); + fs.ensureDirSync(currentBackendDirPath); + } const providerPlugins = getProviderPlugins(context); const providerOnSuccessTasks: (() => Promise<$TSAny>)[] = []; diff --git a/packages/amplify-cli/src/attach-backend.ts b/packages/amplify-cli/src/attach-backend.ts index 7b392358759..ac4f93e5117 100644 --- a/packages/amplify-cli/src/attach-backend.ts +++ b/packages/amplify-cli/src/attach-backend.ts @@ -125,7 +125,7 @@ const backupAmplifyFolder = (): void => { }); } try { - fs.moveSync(amplifyDirPath, backupAmplifyDirPath); + fs.copySync(amplifyDirPath, backupAmplifyDirPath); } catch (e) { if (e.code === 'EPERM') { throw new AmplifyError( @@ -194,9 +194,10 @@ const removeAmplifyFolderStructure = (partial = false): void => { const prepareContext = (context: $TSContext, inputParams): void => { const projectPath = process.cwd(); + const projectConfigFilePath = pathManager.getProjectConfigFilePath(projectPath); context.exeInfo = { - isNewProject: true, + isNewProject: !fs.existsSync(projectConfigFilePath), inputParams, projectConfig: {}, localEnvInfo: { From 8ede73b277a309a9e41e5cdb223affa73191c82a Mon Sep 17 00:00:00 2001 From: Roshane Pascual Date: Tue, 19 Sep 2023 17:43:59 -0700 Subject: [PATCH 2/7] test: add e2e test --- .../src/__tests__/pull.test.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/amplify-e2e-tests/src/__tests__/pull.test.ts b/packages/amplify-e2e-tests/src/__tests__/pull.test.ts index b2c8d4b6493..5fdf07bf643 100644 --- a/packages/amplify-e2e-tests/src/__tests__/pull.test.ts +++ b/packages/amplify-e2e-tests/src/__tests__/pull.test.ts @@ -15,7 +15,9 @@ import { getTeamProviderInfo, amplifyPullNonInteractive, amplifyPullWithCtrlCOnFrameworkPrompt, + initHeadless, } from '@aws-amplify/amplify-e2e-core'; +import { stateManager } from '@aws-amplify/amplify-cli-core'; import * as fs from 'fs-extra'; import * as path from 'path'; @@ -57,6 +59,24 @@ describe('amplify pull in two directories', () => { await amplifyPullWithCtrlCOnFrameworkPrompt(projRoot2, { appId, envName }); await amplifyPull(projRoot2, { appId, envName, emptyDir: true }); }); + + it('appends pulled env to local-aws-info contents instead of overriding existing env', async () => { + const envName = 'testing'; + const newEnvName = 'newenv'; + const expectedEnvs = [envName, newEnvName]; + + // add both envs to project + await initJSProjectWithProfile(projRoot, { envName, disableAmplifyAppCreation: false }); + const appId = getBackendAmplifyMeta(projRoot)?.providers?.awscloudformation?.AmplifyAppId; + await initHeadless(projRoot, newEnvName, appId); + + // pull twice for both envs + await amplifyPullNonInteractive(projRoot2, { appId, envName: envName }); + await amplifyPullNonInteractive(projRoot2, { appId, envName: newEnvName }); + + // assert that local-aws-info.json contains both envs + expect(Object.keys(stateManager.getLocalAWSInfo(projRoot))).toEqual(expectedEnvs); + }); }); describe('amplify pull', () => { From 6f5cce213a78b42ff497ba0002fbfe15e9c87a31 Mon Sep 17 00:00:00 2001 From: Roshane Pascual Date: Wed, 20 Sep 2023 13:13:32 -0700 Subject: [PATCH 3/7] chore: remove unneeded condition --- .../src/attach-backend-steps/a40-generateFiles.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/amplify-cli/src/attach-backend-steps/a40-generateFiles.ts b/packages/amplify-cli/src/attach-backend-steps/a40-generateFiles.ts index 69489383e0a..32a62c974df 100644 --- a/packages/amplify-cli/src/attach-backend-steps/a40-generateFiles.ts +++ b/packages/amplify-cli/src/attach-backend-steps/a40-generateFiles.ts @@ -16,12 +16,10 @@ export const generateFiles = async (context: $TSContext): Promise<$TSContext> => const backendDirPath = pathManager.getBackendDirPath(projectPath); const currentBackendDirPath = pathManager.getCurrentCloudBackendDirPath(projectPath); - if (context.exeInfo.isNewProject) { - fs.ensureDirSync(amplifyDirPath); - fs.ensureDirSync(dotConfigDirPath); - fs.ensureDirSync(backendDirPath); - fs.ensureDirSync(currentBackendDirPath); - } + fs.ensureDirSync(amplifyDirPath); + fs.ensureDirSync(dotConfigDirPath); + fs.ensureDirSync(backendDirPath); + fs.ensureDirSync(currentBackendDirPath); const providerPlugins = getProviderPlugins(context); const providerOnSuccessTasks: (() => Promise<$TSAny>)[] = []; From 4416383630eebaa3ea062cf8179c398d4f677eb5 Mon Sep 17 00:00:00 2001 From: Roshane Pascual Date: Fri, 22 Sep 2023 14:48:38 -0700 Subject: [PATCH 4/7] fix: revert prepareContext change --- packages/amplify-cli/src/attach-backend.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/amplify-cli/src/attach-backend.ts b/packages/amplify-cli/src/attach-backend.ts index ac4f93e5117..405ef20a1cc 100644 --- a/packages/amplify-cli/src/attach-backend.ts +++ b/packages/amplify-cli/src/attach-backend.ts @@ -194,10 +194,9 @@ const removeAmplifyFolderStructure = (partial = false): void => { const prepareContext = (context: $TSContext, inputParams): void => { const projectPath = process.cwd(); - const projectConfigFilePath = pathManager.getProjectConfigFilePath(projectPath); context.exeInfo = { - isNewProject: !fs.existsSync(projectConfigFilePath), + isNewProject: true, inputParams, projectConfig: {}, localEnvInfo: { From 548617b65ecd53800bc3d42ddd5b8b212796f758 Mon Sep 17 00:00:00 2001 From: Roshane Pascual Date: Fri, 22 Sep 2023 14:53:56 -0700 Subject: [PATCH 5/7] test: update expected changed files --- .../amplify-e2e-tests/src/__tests__/git-clone-attach.test.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/amplify-e2e-tests/src/__tests__/git-clone-attach.test.ts b/packages/amplify-e2e-tests/src/__tests__/git-clone-attach.test.ts index fb3b57dfeec..ad7939eb021 100644 --- a/packages/amplify-e2e-tests/src/__tests__/git-clone-attach.test.ts +++ b/packages/amplify-e2e-tests/src/__tests__/git-clone-attach.test.ts @@ -120,9 +120,8 @@ describe('attach amplify to git-cloned project', () => { expect(changedFiles).toMatchInlineSnapshot(` [ ".gitignore", - "amplify/README.md", ] - `); // there is a .gitignore newline and the amplify/README.md file is modified after pull + `); // there is a .gitignore newline after pull expect(getTeamProviderInfo(projRoot)).toEqual(preCleanTpi); }); }); From d29e04654ee4f0c667176bdadd5a235cc26da61d Mon Sep 17 00:00:00 2001 From: Roshane Pascual Date: Mon, 25 Sep 2023 10:02:44 -0700 Subject: [PATCH 6/7] test: change which dir to look for expected envs --- packages/amplify-e2e-tests/src/__tests__/pull.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/amplify-e2e-tests/src/__tests__/pull.test.ts b/packages/amplify-e2e-tests/src/__tests__/pull.test.ts index 5fdf07bf643..d9074138887 100644 --- a/packages/amplify-e2e-tests/src/__tests__/pull.test.ts +++ b/packages/amplify-e2e-tests/src/__tests__/pull.test.ts @@ -75,7 +75,7 @@ describe('amplify pull in two directories', () => { await amplifyPullNonInteractive(projRoot2, { appId, envName: newEnvName }); // assert that local-aws-info.json contains both envs - expect(Object.keys(stateManager.getLocalAWSInfo(projRoot))).toEqual(expectedEnvs); + expect(Object.keys(stateManager.getLocalAWSInfo(projRoot2))).toEqual(expectedEnvs); }); }); From 2727c08b1aecacb780fbeb5d4cde2aa392e0f482 Mon Sep 17 00:00:00 2001 From: Roshane Pascual Date: Mon, 25 Sep 2023 15:11:43 -0700 Subject: [PATCH 7/7] test: update method to add second env to projRoot --- packages/amplify-e2e-tests/src/__tests__/pull.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/amplify-e2e-tests/src/__tests__/pull.test.ts b/packages/amplify-e2e-tests/src/__tests__/pull.test.ts index d9074138887..22f6f401542 100644 --- a/packages/amplify-e2e-tests/src/__tests__/pull.test.ts +++ b/packages/amplify-e2e-tests/src/__tests__/pull.test.ts @@ -15,11 +15,11 @@ import { getTeamProviderInfo, amplifyPullNonInteractive, amplifyPullWithCtrlCOnFrameworkPrompt, - initHeadless, } from '@aws-amplify/amplify-e2e-core'; import { stateManager } from '@aws-amplify/amplify-cli-core'; import * as fs from 'fs-extra'; import * as path from 'path'; +import { addEnvironment } from '../environment/env'; describe('amplify pull in two directories', () => { let projRoot: string; @@ -67,10 +67,10 @@ describe('amplify pull in two directories', () => { // add both envs to project await initJSProjectWithProfile(projRoot, { envName, disableAmplifyAppCreation: false }); - const appId = getBackendAmplifyMeta(projRoot)?.providers?.awscloudformation?.AmplifyAppId; - await initHeadless(projRoot, newEnvName, appId); + await addEnvironment(projRoot, { envName: newEnvName }); - // pull twice for both envs + // pull twice for both envs in other directory + const appId = getBackendAmplifyMeta(projRoot)?.providers?.awscloudformation?.AmplifyAppId; await amplifyPullNonInteractive(projRoot2, { appId, envName: envName }); await amplifyPullNonInteractive(projRoot2, { appId, envName: newEnvName });