Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/aws-cdk-lib/core/lib/stack.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from 'fs';
import * as path from 'path';
import type { IConstruct } from 'constructs';
import type { IConstruct, IMixin } from 'constructs';
import { Construct, Node } from 'constructs';
import { Annotations } from './annotations';
import { App } from './app';
Expand All @@ -15,6 +15,7 @@ import { CfnResource, TagType } from './cfn-resource';
import { ContextProvider } from './context-provider';
import type { Environment, ResourceEnvironment } from './environment';
import { FeatureFlags } from './feature-flags';
import { withMixins } from './mixins/private/mixin-metadata';
import type { PermissionsBoundary } from './permissions-boundary';
import { PERMISSIONS_BOUNDARY_CONTEXT_KEY } from './permissions-boundary';
import { CLOUDFORMATION_TOKEN_RESOLVER, CloudFormationLang } from './private/cloudformation-lang';
Expand Down Expand Up @@ -616,6 +617,10 @@ export class Stack extends Construct implements ITaggable {
}
}

public with(...mixins: IMixin[]): IConstruct {
return withMixins(this, ...mixins);
}

/**
* Resolve a tokenized value in the context of the current stack.
*/
Expand Down
17 changes: 17 additions & 0 deletions packages/aws-cdk-lib/core/test/mixins/mixin-metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,21 @@ describe('Mixin Metadata', () => {
expect(metadata).toBeDefined();
expect(metadata?.data).toEqual({ mixin: '*' });
});

test('Stack.with() records mixin metadata', () => {
stack.with(new TestMixin());

const metadata = stack.node.metadata.find(m => m.type === MIXIN_METADATA_KEY);
expect(metadata).toBeDefined();
expect(metadata?.data).toEqual({ mixin: '@aws-cdk/mixins-preview.TestMixin' });
});

test('Stack.with() records metadata for child constructs', () => {
const child = new Construct(stack, 'Child');
stack.with(new TestMixin());

const childMetadata = child.node.metadata.find(m => m.type === MIXIN_METADATA_KEY);
expect(childMetadata).toBeDefined();
expect(childMetadata?.data).toEqual({ mixin: '@aws-cdk/mixins-preview.TestMixin' });
});
});
Loading