-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super cool
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). |
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 CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
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). |
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)
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*
) 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)
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 fromconstructs
. In particular, the following forms are supported:import * as cdk from '@aws-cdk/core'
import * as constructs from 'constructs'
;import { Construct } from '@aws-cdk/core'
import { Construct } from 'constructs'
import { App, Construct, Stack } from '@aws-cdk/core'
=>import { App, Stack } from '@aws-cdk/core'
;import { Construct as CoreConstruct } from '@aws-cdk/core'
import { Construct as CoreConstruct } from 'constructs'
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