aws / aws/aws-cdk

(custom-resource-handlers): `*/generated.ts` file imports do not support alpha modules

Open
#28,788 0 comments 0 reactions 0 assignees View on GitHub
@aws-cdk/custom-resources bug effort/medium p1
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the bug

When a module has a dependency on `custom-resource-handlers` we will use an script to airlift the necessary files into the package to be released alongside that module.

For the `*/generated.ts` files, the import paths https://github.com/aws/aws-cdk/blob/45b8398bec9ba9c03f195c14f3b92188c9058a7b/packages/%40aws-cdk/custom-resource-handlers/lib/custom-resources-framework/modules.ts#L45-L53 used only work under the assumption that the file is being airlifted and released alongside `aws-cdk-lib` and therefore can't be supported for alpha modules.

For now when airlifting `custom-resource-handlers` into alpha modules, we can only airlift the `index.js` file and a `*/generated.ts` files must be added to `custom-resources-framework/config.ts` as `ComponentType.NO_OP` (i.e. https://github.com/aws/aws-cdk/blob/45b8398bec9ba9c03f195c14f3b92188c9058a7b/packages/%40aws-cdk/custom-resource-handlers/lib/custom-resources-framework/config.ts#L226-L230).

### Expected Behavior

The import paths in the `*/generated.ts` files should work when they're airlifted into an alpha module.

### Current Behavior

The import does not because the import path assumes that the current module is located within `aws-cdk-lib`.

### Reproduction Steps

Add
```
$customresourcedir/dist/*[^-alpha]/*.generated.ts)
cr=$(echo $file | rev | cut -d "/" -f 2-3 | rev)
airlift $cr $cr/*.generated.ts
;;
```
to the [`aws-redshift-alpha` airlift script ](https://github.com/aws/aws-cdk/blob/main/packages/%40aws-cdk/aws-redshift-alpha/scripts/airlift-custom-resource-handlers.sh)and run `yarn package`

### Possible Solution

Update the import paths in https://github.com/aws/aws-cdk/blob/main/packages/%40aws-cdk/custom-resource-handlers/lib/custom-resources-framework/modules.ts so that it can be used for alpha modules.

### Additional Information/Context

_No response_

### CDK CLI Version

2.121.1

### Framework Version

_No response_

### Node.js Version

21.1.0

### OS

14.2.1

### Language

TypeScript

### Language Version

_No response_

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with packages/@aws-cdk/custom-resource-handlers/lib/custom-resources-framework/modules.ts and compare its generated.ts import paths with the airlift behavior in the aws-redshift-alpha script. Review the related config.ts entries, then run the stated airlift reproduction and yarn package. Done means generated files can be airlifted into an alpha module without the NO_OP workaround and packaging succeeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
shell, typescript
Domain
build-system, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.