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

feat(migration): add constructs migration to rewrite script #14916

Merged
merged 10 commits into from
Jun 9, 2021

Conversation

BenChaimberg
Copy link
Contributor

@BenChaimberg BenChaimberg commented May 29, 2021

Add support to the rewrite-imports script for removing the construct compatibility layer. This change will rewrite all imports of Construct that come from @aws-cdk/core to the one that comes from constructs. In particular, the following forms are supported:

  • namespaced: import * as cdk from '@aws-cdk/core'
    • adds a new import: import * as constructs from 'constructs';
  • barrel: import { Construct } from '@aws-cdk/core'
    • adds a new import: import { Construct } from 'constructs'
    • removes old import: import { App, Construct, Stack } from '@aws-cdk/core' => import { App, Stack } from '@aws-cdk/core';
  • barrel with alias: import { Construct as CoreConstruct } from '@aws-cdk/core'
    • adds a new import: import { Construct as CoreConstruct } from 'constructs'
    • removes old import, as above

As always, the unit tests are authoritative!

I also removed some invalid import styles but let me know if they are actually valid and I just missed something!


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

@BenChaimberg BenChaimberg requested a review from rix0rrr May 29, 2021 02:03
@gitpod-io
Copy link

gitpod-io bot commented May 29, 2021

@mergify mergify bot added the contribution/core This is a PR that came from AWS. label May 29, 2021
@BenChaimberg BenChaimberg marked this pull request as ready for review June 1, 2021 20:46
@BenChaimberg BenChaimberg requested a review from a team June 8, 2021 22:32
Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

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

Super cool

@BenChaimberg BenChaimberg requested a review from a team June 9, 2021 14:07
@nija-at nija-at added the pr/do-not-merge This PR should not be merged at this time. label Jun 9, 2021
@BenChaimberg BenChaimberg removed the pr/do-not-merge This PR should not be merged at this time. label Jun 9, 2021
@mergify
Copy link
Contributor

mergify bot commented Jun 9, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify
Copy link
Contributor

mergify bot commented Jun 9, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 6149993
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 37a4c8d into master Jun 9, 2021
@mergify mergify bot deleted the chaimber/rewrite_imports_v2 branch June 9, 2021 18:15
@mergify
Copy link
Contributor

mergify bot commented Jun 9, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

rix0rrr added a commit that referenced this pull request Jul 8, 2021
rix0rrr added a commit that referenced this pull request Jul 8, 2021
mergify bot pushed a commit that referenced this pull request Jul 8, 2021
Reverts #14916

This is causing issues in the v2 forward merge.

```
import * as cdk from '@aws-cdk/core';
```

Is being rewritten as `import * as constructs from 'constructs'`, regardless of what from `cdk` we use. In the case of https://github.com/aws/aws-cdk/blob/master/packages/@aws-cdk/assert-internal/lib/synth-utils.ts for example, we only use `cdk.Stack`, but the imports turn into:

```
import * as fs from 'fs';
import * as path from 'path';
import * as core from 'aws-cdk-lib';
import * as constructs from 'constructs';
import * as cxapi from 'aws-cdk-lib/cx-api';
```

And then TSC complains:

```
@aws-cdk/assert: lib/synth-utils.ts(4,1): error TS6133: 'constructs' is declared but its value is never read.
@aws-cdk/assert: lib/expect.ts(2,1): error TS6133: 'constructs' is declared but its value is never read.
@aws-cdk/assert: jest.ts(2,1): error TS6133: 'constructs' is declared but its value is never read.
@aws-cdk/assert: test/assertions.test.ts(2,13): error TS2300: Duplicate identifier 'constructs'.
@aws-cdk/assert: test/assertions.test.ts(4,13): error TS2300: Duplicate identifier 'constructs'.
```

(Also note `Duplicate identifier` errors)
hollanddd pushed a commit to hollanddd/aws-cdk that referenced this pull request Aug 26, 2021
Add support to the rewrite-imports script for removing the construct compatibility layer. This change will rewrite all imports of `Construct` that come from `@aws-cdk/core` to the one that comes from `constructs`. In particular, the following forms are supported:
- namespaced: `import * as cdk from '@aws-cdk/core'`
  - adds a new import: `import * as constructs from 'constructs'`;
- barrel: `import { Construct } from '@aws-cdk/core'`
  - adds a new import: `import { Construct } from 'constructs'`
  - removes old import: `import { App, Construct, Stack } from '@aws-cdk/core'` => `import { App, Stack } from '@aws-cdk/core'`;
- barrel with alias: `import { Construct as CoreConstruct } from '@aws-cdk/core'`
  - adds a new import: `import { Construct as CoreConstruct } from 'constructs'`
  - removes old import, as above

As always, the unit tests are authoritative!

I also removed some invalid import styles but let me know if they are actually valid and I just missed something!

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
hollanddd pushed a commit to hollanddd/aws-cdk that referenced this pull request Aug 26, 2021
)

Reverts aws#14916

This is causing issues in the v2 forward merge.

```
import * as cdk from '@aws-cdk/core';
```

Is being rewritten as `import * as constructs from 'constructs'`, regardless of what from `cdk` we use. In the case of https://github.com/aws/aws-cdk/blob/master/packages/@aws-cdk/assert-internal/lib/synth-utils.ts for example, we only use `cdk.Stack`, but the imports turn into:

```
import * as fs from 'fs';
import * as path from 'path';
import * as core from 'aws-cdk-lib';
import * as constructs from 'constructs';
import * as cxapi from 'aws-cdk-lib/cx-api';
```

And then TSC complains:

```
@aws-cdk/assert: lib/synth-utils.ts(4,1): error TS6133: 'constructs' is declared but its value is never read.
@aws-cdk/assert: lib/expect.ts(2,1): error TS6133: 'constructs' is declared but its value is never read.
@aws-cdk/assert: jest.ts(2,1): error TS6133: 'constructs' is declared but its value is never read.
@aws-cdk/assert: test/assertions.test.ts(2,13): error TS2300: Duplicate identifier 'constructs'.
@aws-cdk/assert: test/assertions.test.ts(4,13): error TS2300: Duplicate identifier 'constructs'.
```

(Also note `Duplicate identifier` errors)
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants