Skip to content
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

feat(CLI): improved nested stack diff #29172

Merged
merged 54 commits into from
Mar 13, 2024
Merged
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
7543775
working create changeset
comcalvi Jan 5, 2024
441993e
working nested stack parsing, I think...
comcalvi Jan 8, 2024
c2fe021
fix the thing...
comcalvi Jan 8, 2024
d89866d
reset point, in case I break it all...
comcalvi Jan 8, 2024
d26bbf0
nested diffs\!
comcalvi Jan 9, 2024
10c86cc
temp. This is probably the wrong approach so far, but save it just in…
comcalvi Jan 9, 2024
e1e4d34
Revert "temp. This is probably the wrong approach so far, but save it…
comcalvi Jan 9, 2024
f793503
Revert "Revert "temp. This is probably the wrong approach so far, but…
comcalvi Jan 9, 2024
26eeb68
Revert "Revert "Revert "temp. This is probably the wrong approach so …
comcalvi Jan 9, 2024
7725f60
Revert "Revert "Revert "Revert "temp. This is probably the wrong appr…
comcalvi Jan 10, 2024
aa3e4c7
Revert "Revert "Revert "Revert "Revert "temp. This is probably the wr…
comcalvi Jan 10, 2024
61ff29f
Revert "Revert "Revert "Revert "Revert "Revert "temp. This is probabl…
comcalvi Jan 10, 2024
d70a42a
Revert "Revert "Revert "Revert "Revert "Revert "Revert "temp. This is…
comcalvi Jan 10, 2024
5fbd0e8
well, nested stacks have been pulled out. Now it looks like we need t…
comcalvi Jan 11, 2024
a7c7303
this alsmost fixed it
comcalvi Jan 11, 2024
e7c8927
no more too long pipes from objectDiff
comcalvi Jan 11, 2024
1776ad4
working new nested stack diff
comcalvi Jan 11, 2024
9f33ed0
revert...
comcalvi Jan 11, 2024
e7fa75c
Revert
comcalvi Jan 11, 2024
9943b1e
revert
comcalvi Jan 11, 2024
4ef5478
revert
comcalvi Jan 11, 2024
32a8357
revert
comcalvi Jan 11, 2024
c849e84
revert
comcalvi Jan 11, 2024
b4e916e
revert
comcalvi Jan 11, 2024
ddb5b07
revert
comcalvi Jan 11, 2024
b03328a
revert
comcalvi Jan 11, 2024
71d9629
revert
comcalvi Jan 11, 2024
1cc79b9
Revert "working nested stack parsing, I think..."
comcalvi Jan 11, 2024
d5db852
revert
comcalvi Jan 11, 2024
3f4fb0c
refactor
comcalvi Jan 11, 2024
3ac71ea
refactor
comcalvi Jan 11, 2024
1b3c73c
this is really hard to read
comcalvi Jan 13, 2024
1ea45af
working test framework...
comcalvi Jan 17, 2024
c0b57d2
truly working framework
comcalvi Jan 17, 2024
2b86816
comment
comcalvi Jan 17, 2024
3e1835b
???
comcalvi Jan 17, 2024
e3b826c
wip
comcalvi Jan 18, 2024
21055b5
parking this for now...
comcalvi Jan 18, 2024
14491ef
undo this test framework, this is bad
comcalvi Jan 22, 2024
57cdd16
some working tests
comcalvi Jan 22, 2024
9fb25ce
tests
comcalvi Jan 22, 2024
3bffdac
tests/hotswap
comcalvi Jan 29, 2024
9341184
checkpoint
comcalvi Feb 13, 2024
84ea974
passing unit tests
comcalvi Feb 16, 2024
eb898f1
dead code
comcalvi Feb 19, 2024
6034114
use nested stack logical id if nested stack has not been deployed yet
comcalvi Feb 19, 2024
2518552
nested stack count fix
comcalvi Feb 19, 2024
d391cb1
merge from main
comcalvi Feb 19, 2024
b4f04e5
tests
comcalvi Feb 19, 2024
be179ab
dead code
comcalvi Feb 20, 2024
7d9839d
comment
comcalvi Feb 20, 2024
6be7f06
conflicts
comcalvi Mar 13, 2024
2c9dd9e
add import test
comcalvi Mar 13, 2024
918831c
Merge branch 'main' into comcalvi/improved-nested-stack-diff
mergify[bot] Mar 13, 2024
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
Prev Previous commit
Next Next commit
Revert
This reverts commit 61ff29f.
comcalvi committed Jan 11, 2024
commit e7fa75c425abd7ca574ac2018e87adfabd8cd5ff
55 changes: 5 additions & 50 deletions packages/@aws-cdk/cloudformation-diff/lib/format.ts
Original file line number Diff line number Diff line change
@@ -81,7 +81,6 @@ const UPDATE = chalk.yellow('[~]');
const REMOVAL = chalk.red('[-]');

class Formatter {
private nestedDiffIndent: string = ' ';
constructor(
private readonly stream: FormatStream,
private readonly logicalToPathMap: { [logicalId: string]: string },
@@ -97,10 +96,6 @@ class Formatter {
this.stream.write(chalk.white(format(fmt, ...args)) + '\n');
}

public write(fmt: string, ...args: any[]) {
this.stream.write(chalk.white(format(fmt, ...args)));
}

public warning(fmt: string, ...args: any[]) {
this.stream.write(chalk.yellow(format(fmt, ...args)) + '\n');
}
@@ -109,29 +104,17 @@ class Formatter {
title: string,
entryType: string,
collection: DifferenceCollection<V, T>,
formatter: (type: string, id: string, diff: T, nestedIndent: boolean) => void = this.formatDifference.bind(this)) {
formatter: (type: string, id: string, diff: T) => void = this.formatDifference.bind(this)) {

if (collection.differenceCount === 0) {
return;
}

this.printSectionHeader(title);
collection.forEachDifference((id, diff) => formatter(entryType, id, diff, false));
collection.forEachDifference((id, diff) => formatter(entryType, id, diff));
this.printSectionFooter();
}

public formatNestedSection<V, T extends Difference<V>>(
entryType: string,
collection: DifferenceCollection<V, T>,
formatter: (type: string, id: string, diff: T, nestedIndent: boolean) => void = this.formatDifference.bind(this)) {

if (collection.differenceCount === 0) {
return;
}

collection.forEachDifference((id, diff) => formatter(entryType, id, diff, true));
}

public printSectionHeader(title: string) {
this.print(chalk.underline(chalk.bold(title)));
}
@@ -170,7 +153,7 @@ class Formatter {
* @param logicalId the logical ID of the resource that changed.
* @param diff the change to be rendered.
*/
public formatResourceDifference(_type: string, logicalId: string, diff: ResourceDifference, useNestedIndent: boolean) {
public formatResourceDifference(_type: string, logicalId: string, diff: ResourceDifference) {
if (!diff.isDifferent) { return; }

const resourceType = diff.isRemoval ? diff.oldResourceType : diff.newResourceType;
@@ -183,11 +166,8 @@ class Formatter {
let processedCount = 0;
diff.forEachDifference((_, name, values) => {
processedCount += 1;
this.formatTreeDiff(name, values, processedCount === differenceCount, useNestedIndent);
this.formatTreeDiff(name, values, processedCount === differenceCount);
});
if (Object.keys(diff.nestedChanges).length > 0) {
this.formatNestedDifferences(diff.nestedChanges as TemplateDiff, this.formatPrefix(diff));
}
}
}

@@ -237,7 +217,7 @@ class Formatter {
* @param diff the difference on the tree.
* @param last whether this is the last node of a parent tree.
*/
public formatTreeDiff(name: string, diff: Difference<any>, last: boolean, useNestedIndent: boolean) {
public formatTreeDiff(name: string, diff: Difference<any>, last: boolean) {
let additionalInfo = '';
if (isPropertyDifference(diff)) {
if (diff.changeImpact === ResourceImpact.MAY_REPLACE) {
@@ -246,9 +226,6 @@ class Formatter {
additionalInfo = ' (requires replacement)';
}
}
if (useNestedIndent) {
this.write(this.nestedDiffIndent);
}
this.print(' %s─ %s %s%s', last ? '└' : '├', this.changeTag(diff.oldValue, diff.newValue), name, additionalInfo);
return this.formatObjectDiff(diff.oldValue, diff.newValue, ` ${last ? ' ' : '│'}`);
}
@@ -417,28 +394,6 @@ class Formatter {
return '${' + (this.normalizedLogicalIdPath(logId) || logId) + (suffix || '') + '}';
});
}

private formatNestedDifferences(templateDiff: TemplateDiff, prefix: string) {
this.nestedDiffIndent += ' ';
this.print(`${this.nestedDiffIndent}${prefix} NestedTemplate`);
if (templateDiff.awsTemplateFormatVersion || templateDiff.transform || templateDiff.description) {
this.printSectionHeader('Template');
this.formatDifference('AWSTemplateFormatVersion', 'AWSTemplateFormatVersion', templateDiff.awsTemplateFormatVersion);
this.formatDifference('Transform', 'Transform', templateDiff.transform);
this.formatDifference('Description', 'Description', templateDiff.description);
this.printSectionFooter();
}

//formatSecurityChangesWithBanner(this, templateDiff);

this.formatNestedSection('Parameter', templateDiff.parameters);
this.formatNestedSection('Metadata', templateDiff.metadata);
this.formatNestedSection('Mapping', templateDiff.mappings);
this.formatNestedSection('Condition', templateDiff.conditions);
this.formatNestedSection('Resource', templateDiff.resources, this.formatResourceDifference.bind(this));
this.formatNestedSection('Output', templateDiff.outputs);
this.formatNestedSection('Unknown', templateDiff.unknown);
}
}

/**