fix(cli-internal): dedup Gen2 backend namespace import aliases#14926
Draft
sarayev wants to merge 1 commit into
Draft
fix(cli-internal): dedup Gen2 backend namespace import aliases#14926sarayev wants to merge 1 commit into
sarayev wants to merge 1 commit into
Conversation
When two Gen1 resources of different categories shared a name (e.g. a REST API and a Lambda function both named 'mergeStudents'), backend.ts emitted two 'import * as <name>' declarations, causing TS2300 duplicate identifier and TS2339 (the second import shadowed the first). BackendGenerator.addNamespaceImport performed no alias de-duplication. Add a centralized reserveAlias(preferred, category) that returns the preferred alias when free, else disambiguates by appending the capitalized category (then a numeric suffix). All category generators reserve their import-binding alias through it. Import paths and defineBackend keys keep the original resource name; only the import binding alias is disambiguated. Also fixes the REST API generator using the (now possibly-suffixed) alias in the import path instead of the on-disk apiName.
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.
Problem
When two Gen1 resources of different categories share a name (e.g. a REST API and a Lambda function both named
mergeStudents),backend.tsemitted twoimport * as <name>declarations — TS2300 duplicate identifier, plus TS2339 because the second import shadowed the first.Fix
BackendGenerator.addNamespaceImportperformed no de-duplication. Added a centralizedreserveAlias(preferred, category)that returns the preferred alias when free, else disambiguates by appending the capitalized category (then a numeric suffix). All category generators reserve their import-binding alias through it. Import paths anddefineBackendkeys keep the original resource name; only the import binding alias is disambiguated. Also fixes the REST API generator using the (possibly-suffixed) alias in the import path instead of the on-diskapiName.Test
Added a dedup test to
backend.generator.test.ts. Existing snapshots are unchanged (reserveAlias returns the preferred alias when there is no collision).Risk
Medium surface (touches all category generators) but mechanical; no behavior change when names don't collide.