fix(provider-generator): stop a provider_functions resource clobbering the functions submodule - #403
Open
jsteinich wants to merge 1 commit into
Conversation
…g the functions submodule
A provider that declares provider-defined functions emits them to
providers/<provider>/provider-functions/index.ts. A resource or data source
named `<provider>_provider_functions` sanitizes to the base name
`provider_functions`, which `getFileName` maps to that same directory - so
the resource silently overwrites the functions wrapper.
Generating a schema with both (new fixture) produces, before this change:
providers/example/provider-functions/index.ts <- the RESOURCE, not the
functions wrapper
providers/example/index.ts <- exports the name
`providerFunctions` twice
The duplicate `export * as providerFunctions` is a TypeScript error, so the
generated bindings do not compile, and the provider's functions are gone.
`sanitizeClassOrNamespaceName` already gives a resource named `provider` the
`_resource` suffix for exactly this reason; this extends that to
`provider_functions`, so the resource lands in
`provider-functions-resource/` and both are exported under distinct names.
Only `provider_functions` is reserved. `functions` is not a directory the
generator emits, so a resource by that name does not collide today, and
reserving names speculatively would rename resources for no benefit.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
8 tasks
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Follow-up from the review on #400, point 1. #400 is closed; this is the part of it worth keeping, re-scoped and without the submodule rename.
Description
A provider that declares provider-defined functions emits them to
providers/<provider>/provider-functions/index.ts. A resource or data source named<provider>_provider_functionssanitizes to the base nameprovider_functions, whichgetFileNamemaps to that same directory — so the resource silently overwrites the functions wrapper.This is a live gap on
main, independent of #400's rename.sanitizeClassOrNamespaceNamealready reservesfunction(singular),license,versionand the TypeScript keywords, and gives a resource namedproviderthe_resourcesuffix for exactly this reason — but nothing coversprovider_functions.What actually happens today
Generating the new fixture (a provider with one function plus an
example_provider_functionsresource) againstmainproduces:provider-functions/index.tscontainsexport class ProviderFunctions extends cdktn.TerraformResource— the resource, not the functions wrapper. The provider's functions are gone, andindex.tsreads:The duplicate name is a TypeScript error, so the generated bindings do not compile.
lazy-index.tsgets the same duplication.The fix
Extend the existing
providerspecial case toprovider_functions, so the resource lands inprovider-functions-resource/and both are exported under distinct names.Only
provider_functionsis reserved.functionsis not a directory the generator emits, so a resource by that name does not collide today — and as noted in the #400 review,provider_functionsis a far less likely resource name thanfunctions, which is a point in favour of the current layout.Testing
New fixture and test asserting the three things that break without the guard: the functions submodule holds the wrapper rather than the resource, the resource gets its own directory, and the provider index exports no duplicate names. Plus unit assertions on
sanitizeClassOrNamespaceName.Confirmed to be a real regression guard — with the guard reverted, 3 of the 6 fail; with it, all pass.
Full
@cdktn/provider-generatorsuite: 23 suites / 112 tests / 101 snapshots pass.nx lintclean.Checklist
🤖 Generated with Claude Code