Skip to content

Commit

Permalink
chore(cdk): remove expired feature flags from init templates (#13085)
Browse files Browse the repository at this point in the history
As we expire feature flags in CDKv2, remove the expired feature flags
from the init templates.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
Niranjan Jayakar committed Feb 19, 2021
1 parent 0c90693 commit b92188d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/cx-api/lib/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const S3_GRANT_WRITE_WITHOUT_ACL = '@aws-cdk/aws-s3:grantWriteWithoutAcl'
*
* Tests must cover the default (disabled) case and the future (enabled) case.
*/
export const FUTURE_FLAGS = {
export const FUTURE_FLAGS: { [key: string]: any } = {
[ENABLE_STACK_NAME_DUPLICATES_CONTEXT]: 'true',
[ENABLE_DIFF_NO_FAIL_CONTEXT]: 'true',
[STACK_RELATIVE_EXPORTS_CONTEXT]: 'true',
Expand Down
7 changes: 6 additions & 1 deletion packages/aws-cdk/lib/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,15 @@ export class InitTemplate {
return;
}

const futureFlags: {[key: string]: any} = {};
Object.entries(cxapi.FUTURE_FLAGS)
.filter(([k, _]) => !cxapi.FUTURE_FLAGS_EXPIRED.includes(k))
.forEach(([k, v]) => futureFlags[k] = v);

const config = await fs.readJson(cdkJson);
config.context = {
...config.context,
...cxapi.FUTURE_FLAGS,
...futureFlags,
};

await fs.writeJson(cdkJson, config, { spaces: 2 });
Expand Down
9 changes: 7 additions & 2 deletions packages/aws-cdk/test/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,15 @@ describe.each(['1', '2'])('v%s tests', (majorVersion) => {

const config = await fs.readJson(path.join(tmpDir, 'cdk.json'));
const context = config.context || {};
for (const [key, expected] of Object.entries(cxapi.FUTURE_FLAGS)) {
const actual = context[key];
for (const [key, expected] of Object.entries(context)) {
const actual = cxapi.FUTURE_FLAGS[key];
expect(actual).toEqual(expected);
}

// assert that expired future flags are not part of the cdk.json
Object.keys(context).forEach(k => {
expect(cxapi.FUTURE_FLAGS_EXPIRED.includes(k)).toEqual(false);
});
});
}
}
Expand Down

0 comments on commit b92188d

Please sign in to comment.