Repository navigation
fix(cli): make cdktn get remove stale files for resources removed from a provider - #421
Merged
jsteinich merged 1 commit intoSep 12, 2026
Conversation
cdktn get remove stale files for resources removed from a provider
1 task
Contributor
|
I'm going to lock this pull request because it has been closed for 30 days. This helps our maintainers find and focus on the active issues. If you've found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related issue
Fixes #384
Description
cdktn getnow removes generated resource directories that a previous run produced but the current one did not, so the output tree matches the provider version pinned incdktf.json. Cleanup previously reconciled only the top level ofproviders/, leaving the per-resource directories inside a still-listed provider untouched.How the pruning decides what to keep.
TerraformProviderGenerator.emitProvideralready builds afilesarray of everything it emitted, and derives the barrel-file exports from it. That same array now also populates a newemittedResourceFoldersmap, whichConstructsMakeraccumulates alongside the existingversionsmap.ConstructsMaker.removeOrphanedResourceFoldersthen lists each regenerated provider folder and removes any subdirectory absent from that map.Deriving the keep-set from the emitted files — rather than re-deriving it from the schema — means pruning cannot disagree with the barrel files: a directory is kept exactly when it is exported. To keep that guarantee explicit, the duplicated
file.replace(...)path-to-directory-name logic inemitIndexFileandemitLazyIndexFilewas extracted into a sharedresourceFolderNamehelper that all three call sites now use. This is a pure refactor — the 100 existing generator snapshots are unchanged.Scope of the deletion. Three constraints keep it conservative:
providers/<name>/<resource>/maps one-to-one onto the emitted index exports. Other languages co-locate providers and modules in the same folders, which makes a dropped resource indistinguishable from a hand-written construct — the same reasoningremoveFoldersThatShouldNotExistalready applies.filterAlreadyGeneratedcan skip a provider whose pin and folder are both unchanged. Such a provider has noemittedResourceFoldersentry and is therefore never walked, so an up-to-date tree is left alone.index.ts,lazy-index.ts) sit alongside the resource directories and are skipped by anisDirectory()check.It runs after
save(), once CodeMaker has written the current run's files, so the walk sees the new tree and removes only what is genuinely left over. A provider folder that cannot be listed is logged at debug level and skipped rather than failing the run.A plain
cdktn gettherefore converges on the same tree ascdktn get --force, without paying the cost of regenerating every provider from scratch.Checklist