Skip to content

Commit 1dfc6de

Browse files
authored
2 parents 37c53d6 + 65b517f commit 1dfc6de

File tree

6 files changed

+17
-36
lines changed

6 files changed

+17
-36
lines changed

CHANGELOG.v2.alpha.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
## [2.75.1-alpha.0](https://github.com/aws/aws-cdk/compare/v2.75.0-alpha.0...v2.75.1-alpha.0) (2023-04-18)
6+
57
## [2.75.0-alpha.0](https://github.com/aws/aws-cdk/compare/v2.74.0-alpha.0...v2.75.0-alpha.0) (2023-04-17)
68

79
## [2.74.0-alpha.0](https://github.com/aws/aws-cdk/compare/v2.73.0-alpha.0...v2.74.0-alpha.0) (2023-04-13)

CHANGELOG.v2.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
## [2.75.1](https://github.com/aws/aws-cdk/compare/v2.75.0...v2.75.1) (2023-04-18)
6+
7+
### Reverts
8+
9+
* "fix(core): Add stage prefix to stack name shortening process [#24443](https://github.com/aws/aws-cdk/pull/25163)
10+
511
## [2.75.0](https://github.com/aws/aws-cdk/compare/v2.74.0...v2.75.0) (2023-04-17)
612

713

packages/aws-cdk-lib/core/lib/private/unique-resource-name.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ interface MakeUniqueResourceNameOptions {
2525
* @default - none
2626
*/
2727
readonly allowedSpecialCharacters?: string;
28-
29-
/**
30-
* Prefix to be added into the stack name
31-
*
32-
* @default - none
33-
*/
34-
readonly prefix?: string;
3528
}
3629

3730
/**
@@ -56,7 +49,6 @@ const HASH_LEN = 8;
5649
export function makeUniqueResourceName(components: string[], options: MakeUniqueResourceNameOptions) {
5750
const maxLength = options.maxLength ?? 256;
5851
const separator = options.separator ?? '';
59-
const prefix = options.prefix ?? '';
6052
components = components.filter(x => x !== HIDDEN_ID);
6153

6254
if (components.length === 0) {
@@ -67,7 +59,7 @@ export function makeUniqueResourceName(components: string[], options: MakeUnique
6759
// in order to support transparent migration of cloudformation templates to the CDK without the
6860
// need to rename all resources.
6961
if (components.length === 1) {
70-
const topLevelResource = prefix + removeNonAllowedSpecialCharacters(components[0], separator, options.allowedSpecialCharacters);
62+
const topLevelResource = removeNonAllowedSpecialCharacters(components[0], separator, options.allowedSpecialCharacters);
7163

7264
if (topLevelResource.length <= maxLength) {
7365
return topLevelResource;
@@ -76,9 +68,6 @@ export function makeUniqueResourceName(components: string[], options: MakeUnique
7668

7769
// Calculate the hash from the full path, included unresolved tokens so the hash value is always unique
7870
const hash = pathHash(components);
79-
if (prefix) {
80-
components.unshift(prefix);
81-
}
8271
const human = removeDupes(components)
8372
.filter(pathElement => pathElement !== HIDDEN_FROM_HUMAN_ID)
8473
.map(pathElement => removeNonAllowedSpecialCharacters(pathElement, separator, options.allowedSpecialCharacters))

packages/aws-cdk-lib/core/lib/stack.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,7 @@ export class Stack extends Construct implements ITaggable {
14241424
private generateStackName() {
14251425
const assembly = Stage.of(this);
14261426
const prefix = (assembly && assembly.stageName) ? `${assembly.stageName}-` : '';
1427-
return `${this.generateStackId(assembly, prefix)}`;
1427+
return `${prefix}${this.generateStackId(assembly)}`;
14281428
}
14291429

14301430
/**
@@ -1439,7 +1439,7 @@ export class Stack extends Construct implements ITaggable {
14391439
/**
14401440
* Generate an ID with respect to the given container construct.
14411441
*/
1442-
private generateStackId(container: IConstruct | undefined, prefix: string='') {
1442+
private generateStackId(container: IConstruct | undefined) {
14431443
const rootPath = rootPathTo(this, container);
14441444
const ids = rootPath.map(c => Node.of(c).id);
14451445

@@ -1449,7 +1449,7 @@ export class Stack extends Construct implements ITaggable {
14491449
throw new Error('unexpected: stack id must always be defined');
14501450
}
14511451

1452-
return makeStackName(ids, prefix);
1452+
return makeStackName(ids);
14531453
}
14541454

14551455
private resolveExportedValue(exportedValue: any): ResolvedExport {
@@ -1635,14 +1635,9 @@ export function rootPathTo(construct: IConstruct, ancestor?: IConstruct): IConst
16351635
* has only one component. Otherwise we fall back to the regular "makeUniqueId"
16361636
* behavior.
16371637
*/
1638-
function makeStackName(components: string[], prefix: string='') {
1639-
if (components.length === 1) {
1640-
const stack_name = prefix + components[0];
1641-
if (stack_name.length <= 128) {
1642-
return stack_name;
1643-
}
1644-
}
1645-
return makeUniqueResourceName(components, { maxLength: 128, prefix: prefix });
1638+
function makeStackName(components: string[]) {
1639+
if (components.length === 1) { return components[0]; }
1640+
return makeUniqueResourceName(components, { maxLength: 128 });
16461641
}
16471642

16481643
function getCreateExportsScope(stack: Stack) {

packages/aws-cdk-lib/core/test/stage.test.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,6 @@ describe('stage', () => {
103103
expect(stack.stackName).toEqual('MyStage-MyStack');
104104
});
105105

106-
test('generated stack names will not exceed 128 characters', () => {
107-
// WHEN
108-
const app = new App();
109-
const stage = new Stage(app, 'ThisStageNameIsVeryLongButWillOnlyBeTooLongWhenCombinedWithTheStackName');
110-
const stack = new BogusStack(stage, 'ThisStackNameIsVeryLongButItWillOnlyBeTooLongWhenCombinedWithTheLongPrefix');
111-
112-
// THEN
113-
expect(stack.stackName.length).toEqual(128);
114-
expect(stack.stackName).toEqual('ThisStageNameIsVeryLongButWillOnlyBeTooLongWhenCombinedWithTsVeryLongButItWillOnlyBeTooLongWhenCombinedWithTheLongPrefix4CA9F65B');
115-
});
116-
117106
test('Can not have dependencies to stacks outside the nested asm', () => {
118107
// GIVEN
119108
const app = new App();

version.v2.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"version": "2.75.0",
3-
"alphaVersion": "2.75.0-alpha.0"
2+
"version": "2.75.1",
3+
"alphaVersion": "2.75.1-alpha.0"
44
}

0 commit comments

Comments
 (0)