Skip to content

Commit 3ef337d

Browse files
authored
fix(mixins-preview): AutoDeleteObjects mixin fails with cannot find file error (#36188)
### Issue # (if applicable) N/A ### Reason for this change Synth fails when using the `AutoDeleteObjects` mixin: ```ts import * as cdk from 'aws-cdk-lib'; import { Construct } from 'constructs'; import { CfnBucket } from 'aws-cdk-lib/aws-s3'; import { AutoDeleteObjects } from '@aws-cdk/mixins-preview/aws_s3/mixins'; import '@aws-cdk/mixins-preview/with'; import { Mixins } from '@aws-cdk/mixins-preview/core'; export class CdkSampleStack extends cdk.Stack { constructor(scope: Construct, id: string, props?: cdk.StackProps) { super(scope, id, props); const bucket = new CfnBucket(this, 'MyBucket'); Mixins.of(bucket).apply(new AutoDeleteObjects()); } } ``` Error messages: ``` ❯ npx cdk synth /Users/goto/cdk-sample/node_modules/@aws-cdk/mixins-preview/lib/custom-resource-handlers/aws-s3/auto-delete-objects-provider.ts:15 return existing ?? new AutoDeleteObjectsProvider(stack, id, props); ^ ValidationError: cannot find /Users/goto/cdk-sample/node_modules/@aws-cdk/mixins-preview/lib/custom-resource-handlers/dist/aws-s3/auto-delete-objects-handler/index.js at path [CdkSampleStack/Custom::S3AutoDeleteObjectsCustomResourceProvider] in aws-cdk-lib.CustomResourceProviderBase at Function.getOrCreateProvider (/Users/goto/cdk-sample/node_modules/@aws-cdk/mixins-preview/lib/custom-resource-handlers/aws-s3/auto-delete-objects-provider.ts:15:24) at AutoDeleteObjects.applyTo (/Users/goto/cdk-sample/node_modules/@aws-cdk/mixins-preview/lib/services/aws-s3/bucket.ts:27:48) at MixinApplicator.apply (/Users/goto/cdk-sample/node_modules/@aws-cdk/mixins-preview/lib/core/applicator.ts:29:17) at new CdkSampleStack (/Users/goto/cdk-sample/lib/cdk-sample-stack.ts:14:53) at Object.<anonymous> (/Users/goto/cdk-sample/bin/cdk-sample.ts:9:1) at Module._compile (node:internal/modules/cjs/loader:1554:14) at Module.m._compile (/Users/goto/cdk-sample/node_modules/ts-node/src/index.ts:1618:23) at node:internal/modules/cjs/loader:1706:10 at Object.require.extensions.<computed> [as .ts] (/Users/goto/cdk-sample/node_modules/ts-node/src/index.ts:1621:12) at Module.load (node:internal/modules/cjs/loader:1289:32) ``` [AutoDeleteObjectsProvider](https://github.com/aws/aws-cdk/blob/v2.229.0/packages/@aws-cdk/mixins-preview/lib/custom-resource-handlers/aws-s3/auto-delete-objects-provider.ts#L21) specifies: ```ts private constructor(scope: Construct, id: string, props?: CustomResourceProviderOptions) { super(scope, id, { ...props, codeDirectory: path.join(__dirname, '..', 'dist', 'aws-s3', 'auto-delete-objects-handler'), ``` And the [script](https://github.com/aws/aws-cdk/blob/v2.229.0/packages/@aws-cdk/mixins-preview/scripts/airlift-custom-resource-handlers.sh) copies the dist files. But [.npmignore](https://github.com/aws/aws-cdk/blob/v2.229.0/packages/@aws-cdk/mixins-preview/.npmignore) ignores `dist`, so code for auto-delete-objects-provider cannot be provided to user's module. ``` # There should be a 'dist' folder, but it is not there... ❯ ls node_modules/@aws-cdk/mixins-preview/lib/custom-resource-handlers/ aws-s3 ``` ### Description of changes ### Describe any new or updated permissions being added Added `!lib/custom-resource-handlers/dist` to packages/@aws-cdk/mixins-preview/.npmignore. ### Description of how you validated changes ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 0b9d7e6 commit 3ef337d

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

packages/@aws-cdk/mixins-preview/.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ coverage
66
*.tgz
77

88
dist
9+
!lib/custom-resource-handlers/dist
910
.LAST_PACKAGE
1011
.LAST_BUILD
1112
!*.js

0 commit comments

Comments
 (0)