-
Notifications
You must be signed in to change notification settings - Fork 28
feat: refactor (dry-run mode only) #342
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
Conversation
// 8. Refactor (8xxx) | ||
CDK_TOOLKIT_I8900: make.result<RefactorResult>({ | ||
code: 'CDK_TOOLKIT_I8900', | ||
description: 'Refactor result', | ||
interface: 'RefactorResult', | ||
}), | ||
|
||
CDK_TOOLKIT_W8010: make.warn({ | ||
code: 'CDK_TOOLKIT_W8010', | ||
description: 'Refactor execution not yet supported', | ||
}), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if I got the pattern right, here. Someone please check me on this.
@@ -0,0 +1,23 @@ | |||
import { Writable } from 'node:stream'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was moved from the diff-formatter.ts
file.
packages/@aws-cdk/tmp-toolkit-helpers/src/api/refactoring/index.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surface level stuff, still need to look at the meat & potatoes
/** | ||
* Refactor Action. Moves resources from one location (stack + logical ID) to another. | ||
*/ | ||
public async refactor(cx: ICloudAssemblySource, options: RefactorOptions = {}): Promise<void> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor should probably return some useful structure as well, shouldn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly. I'm confused as to what should get notified to the IoHost
, and what should be returned.
|
||
const strategy = options.stacks?.strategy ?? StackSelectionStrategy.ALL_STACKS; | ||
if (strategy !== StackSelectionStrategy.ALL_STACKS) { | ||
await ioHelper.notify(IO.CDK_TOOLKIT_W8010.msg( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this just be an error?
If you want to convert user input into a warning and proceeding anyway, then do the conversion in the CLI?
|
||
const stacks = await this.selectStacksForList([]); | ||
try { | ||
const mappings = await detectRefactorMappings(stacks.stackArtifacts, this.props.sdkProvider); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. I thought the CLI would use the toolkit code here, but I see we haven't gotten that far yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I understand, the idea is that both the CLI and the toolkit library share common code, but the CLI doesn't call the toolkit library. Not yet, at least.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have some comments that I'll leave for you to decide what to do with, but I don't want to stand in the way of this, especially since you're going to iterate on it over time anyway.
packages/@aws-cdk/tmp-toolkit-helpers/src/api/refactoring/index.ts
Outdated
Show resolved
Hide resolved
packages/@aws-cdk/tmp-toolkit-helpers/src/api/refactoring/index.ts
Outdated
Show resolved
Hide resolved
packages/@aws-cdk/tmp-toolkit-helpers/src/api/refactoring/index.ts
Outdated
Show resolved
Hide resolved
packages/@aws-cdk/tmp-toolkit-helpers/src/api/refactoring/index.ts
Outdated
Show resolved
Hide resolved
packages/@aws-cdk/tmp-toolkit-helpers/src/api/refactoring/index.ts
Outdated
Show resolved
Hide resolved
packages/@aws-cdk/tmp-toolkit-helpers/src/api/refactoring/index.ts
Outdated
Show resolved
Hide resolved
packages/@aws-cdk/tmp-toolkit-helpers/src/api/refactoring/index.ts
Outdated
Show resolved
Hide resolved
// 3. Topological sort | ||
const inDegree = Object.keys(graph).reduce((acc, k) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure already have a couple of flavors of toposort lying around the code base already you should be able to reuse 😉
} | ||
|
||
// 2. Detect dependencies by searching for Ref/Fn::GetAtt | ||
const findDependencies = (value: any): string[] => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget that dependencies can also come from DependsOn
at the top level, which contains logical IDs.
packages/@aws-cdk/tmp-toolkit-helpers/src/api/refactoring/index.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more thing: in calculating the digest, should we normalize property order and dependency order?
A reordering of the properties in the bag will affect the hash right now, but it probably shouldn't.
Add a
refactor
command. For now, it only works in dry run mode (-dry-run
in the command line, ordryRun: true
to the toolkit). It computes the mappings based on the difference between the deployed stacks and the cloud assembly stacks, and shows them in a table. Example:Note that we are launching this feature under unstable mode, which requires the user to acknowledge that by passing the
--unstable=refactor
flag.Closes #132, #133, #141, #134 and #135.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license