Skip to content

feat(core): allow multiple transforms on ITemplateOptions #3395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion packages/@aws-cdk/core/lib/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,9 +545,19 @@ export class Stack extends Construct implements ITaggable {
* @internal
*/
protected _toCloudFormation() {
if (this.templateOptions.transform) {
// tslint:disable-next-line: max-line-length
this.node.addWarning('This stack is using the deprecated `templateOptions.transform` property. Consider switching to `templateOptions.transforms`.');
if (!this.templateOptions.transforms) {
this.templateOptions.transforms = [];
}
if (this.templateOptions.transforms.indexOf(this.templateOptions.transform) === -1) {
this.templateOptions.transforms.unshift(this.templateOptions.transform);
}
}
const template: any = {
Description: this.templateOptions.description,
Transform: this.templateOptions.transform,
Transform: extractSingleValue(this.templateOptions.transforms),
AWSTemplateFormatVersion: this.templateOptions.templateFormatVersion,
Metadata: this.templateOptions.metadata
};
Expand Down Expand Up @@ -690,9 +700,16 @@ export interface ITemplateOptions {

/**
* Gets or sets the top-level template transform for this stack (e.g. "AWS::Serverless-2016-10-31").
*
* @deprecated use `transforms` instead.
*/
transform?: string;

/**
* Gets or sets the top-level template transform(s) for this stack (e.g. `["AWS::Serverless-2016-10-31"]`).
*/
transforms?: string[];

/**
* Metadata associated with the CloudFormation template.
*/
Expand Down Expand Up @@ -746,3 +763,10 @@ interface StackDependency {
stack: Stack;
reason: string;
}

function extractSingleValue<T>(array: T[] | undefined): T[] | T | undefined {
if (array && array.length === 1) {
return array[0];
}
return array;
}
5 changes: 3 additions & 2 deletions packages/@aws-cdk/core/test/test.stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ export = {

stack.templateOptions.description = 'StackDescription';
stack.templateOptions.templateFormatVersion = 'TemplateVersion';
stack.templateOptions.transform = 'Transform';
stack.templateOptions.transform = 'DeprecatedField';
stack.templateOptions.transforms = ['Transform'];
stack.templateOptions.metadata = {
MetadataKey: 'MetadataValue'
};

test.deepEqual(toCloudFormation(stack), {
Description: 'StackDescription',
Transform: 'Transform',
Transform: ['DeprecatedField', 'Transform'],
AWSTemplateFormatVersion: 'TemplateVersion',
Metadata: { MetadataKey: 'MetadataValue' }
});
Expand Down