fix(cli-internal): avoid duplicate Construct import for double-quoted sources#14927
Draft
sarayev wants to merge 2 commits into
Draft
fix(cli-internal): avoid duplicate Construct import for double-quoted sources#14927sarayev wants to merge 2 commits into
sarayev wants to merge 2 commits into
Conversation
… sources
transformResource() injected 'import { Construct } from "constructs";'
guarded by a single-quote-only substring check
(content.includes("from 'constructs'")). A custom resource whose
cdk-stack.ts already imported Construct with double quotes slipped past
the guard, yielding two Construct imports and TS2300 duplicate identifier.
Replace the guard with a quote-agnostic, binding-specific regex that
detects an existing Construct named import in either quote style, while
still injecting when only a different binding (e.g. IConstruct) is
imported from 'constructs'.
…dup test The construct-import dedup test used real temp dirs and relied on a file-reading mock, which fails under the package's default jest config (fs-extra is auto-mocked and JSONUtilities is real), causing 'project-config.json does not exist'. Rewrite it to mirror the sibling custom.generator.test.ts pattern: mock node:fs/promises and JSONUtilities, drive the generator with a double-quoted Construct import, and assert exactly one constructs import in the written content.
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
transformResource()injectedimport { Construct } from 'constructs';guarded by a single-quote-only substring check (content.includes(\"from 'constructs'\")). A custom resource whosecdk-stack.tsalready importedConstructwith double quotes slipped past the guard, yielding twoConstructimports — TS2300.Fix
Replace the guard with a quote-agnostic, binding-specific regex that detects an existing
Constructnamed import in either quote style, while still injecting when only a different binding (e.g.IConstruct) is imported fromconstructs.Test
custom.generator.construct-import-dedup.test.tsdrivesCustomResourceGeneratorwith a double-quoteConstructfixture and asserts exactly oneconstructsimport.Risk
Low. One-line guard change; existing custom-resources tests unchanged.