From 3323a7ff3d90b744cd0eafe584da69784f01a936 Mon Sep 17 00:00:00 2001 From: jhockett Date: Thu, 11 Nov 2021 10:55:44 -0800 Subject: [PATCH] fix: ensure FF on stack transform, revert revert --- packages/amplify-category-custom/package.json | 2 +- .../src/feature-flags/featureFlags.ts | 25 +++++++++++- .../package.json | 4 +- packages/amplify-cli/package.json | 2 +- .../get-category-pluginInfo.ts | 6 +-- .../amplify-helpers/resource-status-data.ts | 33 +++++---------- .../commands/awscloudformation/override.ts | 40 +++++-------------- .../src/initializer.ts | 4 +- .../override-manager/transform-resource.ts | 3 +- .../src/push-resources.ts | 8 ++-- 10 files changed, 58 insertions(+), 69 deletions(-) diff --git a/packages/amplify-category-custom/package.json b/packages/amplify-category-custom/package.json index f3439482f32..2bbc32ccbc5 100644 --- a/packages/amplify-category-custom/package.json +++ b/packages/amplify-category-custom/package.json @@ -26,7 +26,7 @@ }, "dependencies": { "amplify-cli-core": "1.33.0", - "amplify-prompts": "1.1.2", + "amplify-prompts": "1.3.0", "execa": "^5.1.1", "fs-extra": "^8.1.0", "glob": "^7.2.0", diff --git a/packages/amplify-cli-core/src/feature-flags/featureFlags.ts b/packages/amplify-cli-core/src/feature-flags/featureFlags.ts index a710347a2f3..414b4b46c19 100644 --- a/packages/amplify-cli-core/src/feature-flags/featureFlags.ts +++ b/packages/amplify-cli-core/src/feature-flags/featureFlags.ts @@ -94,6 +94,28 @@ export class FeatureFlags { } }; + /** + * If feature flag exists do nothing, otherwise initalize the given feature flag with the default value. + * If the configuration file does not exist it will be created with the default features. + */ + public static ensureFeatureFlag = async (featureFlagSection: string, featureFlagName: string): Promise => { + FeatureFlags.ensureInitialized(); + + let config = stateManager.getCLIJSON(FeatureFlags.instance.projectPath, undefined, { + throwIfNotExist: false, + preserveComments: true, + }); + + if (!config?.features) { + FeatureFlags.ensureDefaultFeatureFlags(false); + } else if (config.features?.[featureFlagSection]?.[featureFlagName] === undefined) { + const features = FeatureFlags.getExistingProjectDefaults(); + _.set(config, ['features', featureFlagSection, featureFlagName], features[featureFlagSection][featureFlagName]); + + stateManager.setCLIJSON(FeatureFlags.instance.projectPath, config); + } + }; + public static getBoolean = (flagName: string): boolean => { FeatureFlags.ensureInitialized(); @@ -718,12 +740,11 @@ export class FeatureFlags { }, ]); - // project level flags this.registerFlag('project', [ { name: 'overrides', type: 'boolean', - defaultValueForExistingProjects: false, + defaultValueForExistingProjects: true, defaultValueForNewProjects: true, }, ]); diff --git a/packages/amplify-cli-extensibility-helper/package.json b/packages/amplify-cli-extensibility-helper/package.json index ada7a3efb1e..d659c1cf803 100644 --- a/packages/amplify-cli-extensibility-helper/package.json +++ b/packages/amplify-cli-extensibility-helper/package.json @@ -34,8 +34,8 @@ "@aws-cdk/aws-lambda": "~1.124.0", "@aws-cdk/aws-s3": "~1.124.0", "@aws-cdk/core": "~1.124.0", - "amplify-cli-core": "1.31.1", - "amplify-prompts": "1.1.2" + "amplify-cli-core": "1.33.0", + "amplify-prompts": "1.3.0" }, "jest": { "transform": { diff --git a/packages/amplify-cli/package.json b/packages/amplify-cli/package.json index d7fd237506f..252845d1772 100644 --- a/packages/amplify-cli/package.json +++ b/packages/amplify-cli/package.json @@ -46,7 +46,7 @@ "amplify-category-interactions": "2.7.0", "amplify-category-notifications": "2.19.4", "amplify-category-predictions": "2.10.0", - "amplify-category-xr": "2.8.24", + "amplify-category-xr": "2.9.0", "amplify-cli-core": "1.33.0", "amplify-cli-logger": "1.1.0", "amplify-codegen": "^2.23.1", diff --git a/packages/amplify-cli/src/extensions/amplify-helpers/get-category-pluginInfo.ts b/packages/amplify-cli/src/extensions/amplify-helpers/get-category-pluginInfo.ts index 8906d3c4913..5d73933432a 100644 --- a/packages/amplify-cli/src/extensions/amplify-helpers/get-category-pluginInfo.ts +++ b/packages/amplify-cli/src/extensions/amplify-helpers/get-category-pluginInfo.ts @@ -1,6 +1,6 @@ -import { FeatureFlags } from 'amplify-cli-core'; +import { $TSContext } from 'amplify-cli-core'; -export function getCategoryPluginInfo(context, category, service?) { +export function getCategoryPluginInfo(context: $TSContext, category: string, service?) { let categoryPluginInfo; const pluginInfosForCategory = context.pluginPlatform.plugins[category]; @@ -18,7 +18,7 @@ export function getCategoryPluginInfo(context, category, service?) { } } else { const overidedPlugin = pluginInfosForCategory.find(plugin => { - return plugin.packageName === `@aws-amplify/amplify-category-${category}` && FeatureFlags.getBoolean(`overrides.${category}`); + return plugin.packageName === `@aws-amplify/amplify-category-${category}`; }); if (overidedPlugin !== undefined) { return overidedPlugin; diff --git a/packages/amplify-cli/src/extensions/amplify-helpers/resource-status-data.ts b/packages/amplify-cli/src/extensions/amplify-helpers/resource-status-data.ts index 421930f214a..c9374b1634b 100644 --- a/packages/amplify-cli/src/extensions/amplify-helpers/resource-status-data.ts +++ b/packages/amplify-cli/src/extensions/amplify-helpers/resource-status-data.ts @@ -133,28 +133,17 @@ export async function getResourceStatus( const tagsUpdated = !_.isEqual(stateManager.getProjectTags(), stateManager.getCurrentProjectTags()); // if not equal there is a root stack update - if (FeatureFlags.getBoolean('project.overrides')) { - const rootStackUpdated = await isRootStackModifiedSinceLastPush(getHashForRootStack); - - return { - resourcesToBeCreated, - resourcesToBeUpdated, - resourcesToBeSynced, - resourcesToBeDeleted, - rootStackUpdated, - tagsUpdated, - allResources, - }; - } else { - return { - resourcesToBeCreated, - resourcesToBeUpdated, - resourcesToBeSynced, - resourcesToBeDeleted, - tagsUpdated, - allResources, - }; - } + const rootStackUpdated = await isRootStackModifiedSinceLastPush(getHashForRootStack); + + return { + resourcesToBeCreated, + resourcesToBeUpdated, + resourcesToBeSynced, + resourcesToBeDeleted, + rootStackUpdated, + tagsUpdated, + allResources, + }; } export function getAllResources(amplifyMeta, category, resourceName, filteredResources) { diff --git a/packages/amplify-provider-awscloudformation/src/commands/awscloudformation/override.ts b/packages/amplify-provider-awscloudformation/src/commands/awscloudformation/override.ts index a3f555e20d5..fdc2cfd2202 100644 --- a/packages/amplify-provider-awscloudformation/src/commands/awscloudformation/override.ts +++ b/packages/amplify-provider-awscloudformation/src/commands/awscloudformation/override.ts @@ -2,41 +2,23 @@ entry code for amplify override root */ -import { $TSContext, FeatureFlags, generateOverrideSkeleton, pathManager } from 'amplify-cli-core'; -import { printer } from 'amplify-prompts'; +import { $TSContext, generateOverrideSkeleton, pathManager } from 'amplify-cli-core'; import * as fs from 'fs-extra'; import * as path from 'path'; -const subcommand = 'override'; - export const name = 'overrides'; export const run = async (context: $TSContext) => { - if (FeatureFlags.getBoolean('project.overrides')) { - const backendDir = pathManager.getBackendDirPath(); + const backendDir = pathManager.getBackendDirPath(); - const destPath = path.join(backendDir, 'awscloudformation'); - fs.ensureDirSync(destPath); - const srcPath = path.join(__dirname, '..', '..', '..', 'resources', 'overrides-resource'); - // removing runtime old root cfn stack - // no need for rollback since these files will be autogenerated after push - const oldRootStackFile = path.join(destPath, 'nested-cloudformation-stack.yml'); - if (fs.existsSync(oldRootStackFile)) { - fs.unlinkSync(oldRootStackFile); - } - await generateOverrideSkeleton(context, srcPath, destPath); - } else { - printer.info('Project level overrides is currently not turned on. In cli.json file please include the following:'); - printer.info( - JSON.stringify( - { - project: { - overrides: true, - }, - }, - undefined, - 2, - ), - ); + const destPath = path.join(backendDir, 'awscloudformation'); + fs.ensureDirSync(destPath); + const srcPath = path.join(__dirname, '..', '..', '..', 'resources', 'overrides-resource'); + // removing runtime old root cfn stack + // no need for rollback since these files will be autogenerated after push + const oldRootStackFile = path.join(destPath, 'nested-cloudformation-stack.yml'); + if (fs.existsSync(oldRootStackFile)) { + fs.unlinkSync(oldRootStackFile); } + await generateOverrideSkeleton(context, srcPath, destPath); }; diff --git a/packages/amplify-provider-awscloudformation/src/initializer.ts b/packages/amplify-provider-awscloudformation/src/initializer.ts index 201b1726638..9ec16ce0adb 100644 --- a/packages/amplify-provider-awscloudformation/src/initializer.ts +++ b/packages/amplify-provider-awscloudformation/src/initializer.ts @@ -169,9 +169,7 @@ function cloneCLIJSONForNewEnvironment(context) { export async function onInitSuccessful(context) { configurationManager.onInitSuccessful(context); if (context.exeInfo.isNewEnv) { - if (FeatureFlags.getBoolean('project.overrides')) { - await storeRootStackTemplate(context); - } + await storeRootStackTemplate(context); context = await storeCurrentCloudBackend(context); await storeArtifactsForAmplifyService(context); await uploadHooksDirectory(context); diff --git a/packages/amplify-provider-awscloudformation/src/override-manager/transform-resource.ts b/packages/amplify-provider-awscloudformation/src/override-manager/transform-resource.ts index 90ef58ddfbe..190db36b7e8 100644 --- a/packages/amplify-provider-awscloudformation/src/override-manager/transform-resource.ts +++ b/packages/amplify-provider-awscloudformation/src/override-manager/transform-resource.ts @@ -1,4 +1,4 @@ -import { $TSContext, IAmplifyResource, JSONUtilities, pathManager } from 'amplify-cli-core'; +import { $TSContext, FeatureFlags, IAmplifyResource, JSONUtilities, pathManager } from 'amplify-cli-core'; import { printer } from 'amplify-prompts'; import * as fs from 'fs-extra'; import ora from 'ora'; @@ -24,6 +24,7 @@ export async function transformResourceWithOverrides(context: $TSContext, resour spinner = ora(`Building resource ${resource.category}/${resource.resourceName}`); spinner.start(); await transformCategoryStack(context, resource); + FeatureFlags.ensureFeatureFlag('project', 'overrides'); spinner.stop(); return; } else { diff --git a/packages/amplify-provider-awscloudformation/src/push-resources.ts b/packages/amplify-provider-awscloudformation/src/push-resources.ts index 37148fa6f7e..8f9da0045da 100644 --- a/packages/amplify-provider-awscloudformation/src/push-resources.ts +++ b/packages/amplify-provider-awscloudformation/src/push-resources.ts @@ -288,11 +288,9 @@ export async function run(context: $TSContext, resourceDefinition: $TSObject, re try { await updateCloudFormationNestedStack(context, nestedStack, resourcesToBeCreated, resourcesToBeUpdated); - if (FeatureFlags.getBoolean('project.overrides')) { - await storeRootStackTemplate(context, nestedStack); - // if the only root stack updates, function is called with empty resources . this fn copies amplifyMeta and backend Config to #current-cloud-backend - context.amplify.updateamplifyMetaAfterPush([]); - } + await storeRootStackTemplate(context, nestedStack); + // if the only root stack updates, function is called with empty resources . this fn copies amplifyMeta and backend Config to #current-cloud-backend + context.amplify.updateamplifyMetaAfterPush([]); } catch (err) { if (err?.name === 'ValidationError' && err?.message === 'No updates are to be performed.') { return;