Skip to content

Conversation

@mrgrain
Copy link
Contributor

@mrgrain mrgrain commented Dec 1, 2025

Reason for this change

The ConstructSelector API in mixins-preview was too restrictive, only accepting specific selector types rather than allowing custom implementations. Additionally, byId() used regex patterns which are less intuitive than glob patterns for path matching.

Description of changes

This PR introduces a strongly-typed IConstructSelector interface and improves selector functionality:

Breaking Changes:

  • Mixins.of() now accepts IConstructSelector instead of the concrete ConstructSelector class, enabling custom selector implementations
  • ConstructSelector.byId() now uses glob patterns instead of regular expressions for more intuitive matching
  • ConstructSelector.resourcesOfType() now requires string CloudFormation resource type names instead of accepting class references

New Features:

  • Added IConstructSelector interface for custom selector implementations
  • Added ConstructSelector.byPath() to match on construct paths using glob patterns
  • Added minimatch dependency for glob pattern matching

Examples:

// Custom selector implementation now possible
class MySelector implements IConstructSelector {
  select(scope: IConstruct): IConstruct[] { /* ... */ }
}

// Glob patterns instead of regex
ConstructSelector.byId('*prod*')  // instead of /prod-.*/
ConstructSelector.byPath('*/Prefix/**')

// String resource types
ConstructSelector.resourcesOfType(s3.CfnBucket.CFN_RESOURCE_TYPE_NAME)

Describe any new or updated permissions being added

No new or updated IAM permissions are needed.

Description of how you validated changes

  • Added test for byPath() selector
  • Updated existing tests to use new glob pattern syntax
  • Updated README examples to reflect new API
  • All tests pass

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@aws-cdk-automation aws-cdk-automation requested a review from a team December 1, 2025 22:02
@github-actions github-actions bot added the p2 label Dec 1, 2025
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Dec 1, 2025
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This review is outdated)

@mrgrain mrgrain changed the title feat(mixins-preview): strongly-typed ConstructSelector interface fix(mixins-preview): strongly-typed ConstructSelector interface Dec 1, 2025
@mrgrain mrgrain added the pr-linter/exempt-integ-test The PR linter will not require integ test changes label Dec 1, 2025
@aws-cdk-automation aws-cdk-automation dismissed their stale review December 1, 2025 22:24

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@mrgrain mrgrain force-pushed the mrgrain/fix/construct-selectors branch from f9f9c4a to 3dc8b7d Compare December 2, 2025 21:37
Changed `Mixins.of()` to take a `IConstructSelector` instead of only one of the provided selectors. This allows users to implement custom selectors.

Added `ConstructSelector.byPath()` to match on a construct path, to complement the existing `byId()`.

BREAKING CHANGE: `ConstructSelector.byId()` now takes a glob pattern instead of a regular expression.

BREAKING CHANGE: `ConstructSelector.resourcesOfType()` now must receive a string.
@mrgrain mrgrain force-pushed the mrgrain/fix/construct-selectors branch from 3dc8b7d to fa66705 Compare December 2, 2025 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution/core This is a PR that came from AWS. p2 pr-linter/exempt-integ-test The PR linter will not require integ test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants