Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(aws-cdk-migration): Construct imports not rewritten #17826

Closed
bmacher opened this issue Dec 3, 2021 · 4 comments · Fixed by #17931
Closed

(aws-cdk-migration): Construct imports not rewritten #17826

bmacher opened this issue Dec 3, 2021 · 4 comments · Fixed by #17931
Assignees
Labels
aws-cdk-lib Related to the aws-cdk-lib package bug This issue is a bug. p1

Comments

@bmacher
Copy link
Contributor

bmacher commented Dec 3, 2021

What is the problem?

When migrating CDK imports with aws-cdk-migration then the Construct class is imported from aws-cdk-lib. However, aws-cdk-lib does not export Construct but constructs does.

Reproduction Steps

import { App, Construct, Stage } from '@aws-cdk/core';

What did you expect to happen?

import { App, Stage } from 'aws-cdk-lib';
import { Construct } from 'constructs';

What actually happened?

import { App, Construct, Stage } from 'aws-cdk-lib';

CDK CLI Version

2.0.0

Framework Version

2.0.0

Node.js Version

14.16.1

OS

macOS

Language

Typescript

Language Version

^4.3.2

Other information

No response

@bmacher bmacher added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 3, 2021
@github-actions github-actions bot added the aws-cdk-lib Related to the aws-cdk-lib package label Dec 3, 2021
@NGL321 NGL321 added p1 and removed needs-triage This issue or PR still needs to be triaged. labels Dec 8, 2021
@NGL321
Copy link
Contributor

NGL321 commented Dec 8, 2021

I have confirmed this behavior, but have not yet confirmed what causes it.

@bmacher
Copy link
Contributor Author

bmacher commented Dec 8, 2021

I assume, that it is just not considered. Only the part after from is migrated currently, which is fine in any other case.

@njlynch njlynch changed the title (aws-cdk-migration): Construct cannot be import from aws-cdk-lib (aws-cdk-migration): Construct imports not rewritten Dec 8, 2021
@njlynch
Copy link
Contributor

njlynch commented Dec 8, 2021

This was a known gap in the tool leading up to launch; it should have been more clearly documented that we had not (yet) handled this case.

I'll take a look at it this week and see if we can't make some progress.

njlynch added a commit that referenced this issue Dec 9, 2021

Verified

This commit was signed with the committer’s verified signature.
renovate-bot Mend Renovate
The `rewrite-imports-v2` tool is used to rewrite imports from CDK v1 apps and
libraries to CDK v2 compliant imports. The initial launch of this tool focused
solely on the conversion of CDKv1 to CDKv2 imports, but ignored the complexity
of 'constructs` now being used as its own independent library and the lack of
the Construct compatibility layer from v2.

This fix introduces rewrites for Constructs. All `IConstruct` and `Construct`
imports will be converted from `@aws-cdk/core` to `constructs`, and any
qualified references (e.g., `cdk.Construct`) will be renamed as well (e.g.,
`constructs.Construct`). Imports of the construct library will be added as
needed.

fixes #17826
@mergify mergify bot closed this as completed in #17931 Dec 10, 2021
mergify bot pushed a commit that referenced this issue Dec 10, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
The `rewrite-imports-v2` tool is used to rewrite imports from CDK v1 apps and
libraries to CDK v2 compliant imports. The initial launch of this tool focused
solely on the conversion of CDKv1 to CDKv2 imports, but ignored the complexity
of 'constructs` now being used as its own independent library and the lack of
the Construct compatibility layer from v2.

This fix introduces rewrites for Constructs. All `IConstruct` and `Construct`
imports will be converted from `@aws-cdk/core` to `constructs`, and any
qualified references (e.g., `cdk.Construct`) will be renamed as well (e.g.,
`constructs.Construct`). Imports of the construct library will be added as
needed.

fixes #17826

_Implementation note:_
Apologies for the diff. The best way to be able to recursively visit the tree involved
converting the existing, simple `ts.visitNode()` approach to a
`TransformerFactory`-based approach so `ts.visitEachChild()` could be used. This
required a few method moves and the creation of a class to hold some context.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this issue Feb 21, 2022
The `rewrite-imports-v2` tool is used to rewrite imports from CDK v1 apps and
libraries to CDK v2 compliant imports. The initial launch of this tool focused
solely on the conversion of CDKv1 to CDKv2 imports, but ignored the complexity
of 'constructs` now being used as its own independent library and the lack of
the Construct compatibility layer from v2.

This fix introduces rewrites for Constructs. All `IConstruct` and `Construct`
imports will be converted from `@aws-cdk/core` to `constructs`, and any
qualified references (e.g., `cdk.Construct`) will be renamed as well (e.g.,
`constructs.Construct`). Imports of the construct library will be added as
needed.

fixes aws#17826

_Implementation note:_
Apologies for the diff. The best way to be able to recursively visit the tree involved
converting the existing, simple `ts.visitNode()` approach to a
`TransformerFactory`-based approach so `ts.visitEachChild()` could be used. This
required a few method moves and the creation of a class to hold some context.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws-cdk-lib Related to the aws-cdk-lib package bug This issue is a bug. p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants