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

chore(cdk-lib): migrate to jsii@5.0 / jsii-rosetta@5.0 #24425

Merged
merged 36 commits into from
Mar 22, 2023

Conversation

RomainMuller
Copy link
Contributor

@RomainMuller RomainMuller commented Mar 2, 2023

Updates dependencies & code as necessary to use jsii@5.0 to build the AWS CDK.

BREAKING CHANGE: The return type of aws-cdk-lib.aws_ec2.SecurityGroup.determineRuleScope was changed from a tuple ([SecurityGroupBase, string]) to a struct with the same values, because tuple types are not supported over the jsii interoperability layer, but jsii@v1 was incorrectly allowing this to be represented as the JSON primitive type. This made the API unusable in non-JS languages. The type of the metadata property of aws-cdk-lib.aws_s3_deployment.BucketDeploymentProps was changed from an index-only struct to an inline map, because jsii@v1 silently ignored the index signature (which is otherwise un-supported), resulting in an empty object in non-JS/TS languages. As a consequence, the values of that map can no longer be undefined (as jsii does not currently support nullable elements in collections).


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

@RomainMuller RomainMuller self-assigned this Mar 2, 2023
@github-actions github-actions bot added the p2 label Mar 2, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team March 2, 2023 15:29
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Mar 2, 2023
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@aws-cdk-automation aws-cdk-automation added the pr/needs-cli-test-run This PR needs CLI tests run against it. label Mar 2, 2023
Copy link
Contributor Author

@RomainMuller RomainMuller left a comment

Choose a reason for hiding this comment

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

The bulk of code changes here fall into one of these categories:

  • Promise<void> must be explicitly typed, or TypeScript will require a parameter be provided to the resolve handler.
  • catch bindings are unknown by default, explicitly typed as any in places where this was assumed, and removed the binding entirely in the few places where it was not used.
  • abstract async is no longer valid, removed the async keyword (the contract really is just "returns a promise", which is expressed fully with the return type declaration)
  • Some generic helper methods needed tweaking due to hardened type checking safety around uses of Object.keys, Object.values, Object.entries.
  • Some places blindly assumed Object.keys returns only string, but it could contain Symbol objects which have a throwing toString (they need to be strigified as String(sym)). The 4.9 TypeScript compiler actually reports this as an error. Hardened such uses.
  • Adding overrides keywords as I am proposing to enable noImplicitOverride

Then, there are some more annoying aspects where jsii@v4.9 checks (and prohibits) things that v1 silently ignores or mis-interprets (back-porting of these checks to v1 is planned, but they'll likely need to be WARNING there). I am adding a comment on each use-case to facilitate discussion.

@@ -178,15 +178,15 @@ abstract class SecurityGroupBase extends Resource implements ISecurityGroup {
peer: IPeer,
connection: Port,
fromTo: 'from' | 'to',
remoteRule?: boolean): [SecurityGroupBase, string] {
remoteRule?: boolean): RuleScope {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is incorrectly processed by jsii@v1, which treats it the same as object, resulting in the JSON primitive type.


The API is protected. Is it intended for external use? Can it be made @internal?


Changing the return type to an object here is a breaking change, but provides better semantics... This API is currently very awkward to use in non-JS/TS languages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note - I could not find any use of this API outside of the CDK Construct library on a cursory search on GitHub.

@@ -1,7 +1,7 @@
#!/bin/bash
set -euo pipefail

export NODE_OPTIONS="--max-old-space-size=4096 ${NODE_OPTIONS:-}"
export NODE_OPTIONS="--max-old-space-size=8196 ${NODE_OPTIONS:-}"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Uniformed the --max-old-space-size= in all the scripts to the highest value that was in any of them.

I've had jsii run out of heap building aws-cdk-lib here, with ~4G heap (the default on my system). Bumping to 8G fixed that...

We may want to review jsii's memory usage separately to see whether there are avenues for improvement (last similar exercise we did concluded that the bulk of the use was TypeScript itself, but it can't hurt to reassess).

@@ -47,7 +48,7 @@ describe('CustomResourceHandler', () => {
const nocked = nockUp((body) => {
return body.Status === 'SUCCESS'
&& body.Reason === 'OK'
&& body.Data === {}
&& isDeepStrictEqual(body.Data, {})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The TypeScript 4.9 compiler considers comparing an object literal expression as an error, since this would be a reference comparison, and not a value comparison, and the ECMAScript standard mandates that each individual object literal is an individual object (so such comparisons can never be true).

It is unclear to me how this test could have succeeded. Perhaps a V8-specific quirk?

@RomainMuller RomainMuller changed the title chore: migrate to jsii-compiler 4.9, enable noImplicitOverride chore: migrate to jsii-compiler 4.9 Mar 13, 2023
@RomainMuller RomainMuller force-pushed the rmuller/compiler-v49-next branch from 640ff29 to eed8bd4 Compare March 14, 2023 08:58
@RomainMuller RomainMuller force-pushed the rmuller/compiler-v49-next branch from f8351c2 to b279f89 Compare March 17, 2023 09:41
@RomainMuller RomainMuller marked this pull request as ready for review March 20, 2023 10:49
@RomainMuller RomainMuller changed the title chore: migrate to jsii@5.0 / jsii-rosetta@5.0 chore(aws-cdk-lib): migrate to jsii@5.0 / jsii-rosetta@5.0 Mar 20, 2023
@RomainMuller RomainMuller changed the title chore(aws-cdk-lib): migrate to jsii@5.0 / jsii-rosetta@5.0 chore(cdk-lib): migrate to jsii@5.0 / jsii-rosetta@5.0 Mar 20, 2023
@RomainMuller RomainMuller added the pr-linter/exempt-breaking-change The PR linter will not require stability in stable modules label Mar 20, 2023
@aws-cdk-automation aws-cdk-automation dismissed their stale review March 20, 2023 13:03

✅ Updated pull request passes all PRLinter validations. Dissmissing previous PRLinter review.

Copy link
Contributor

@Naumel Naumel left a comment

Choose a reason for hiding this comment

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

Relevant: https://github.com/aws/aws-cdk/pull/24425/files?diff=split&w=1#r1134057642, therefore approving √

I am marking the PR as pr/do-not-merge to allow others to review, if they chose to do so.

@@ -248,7 +248,7 @@ export interface IHttpRouteAuthorizer {
bind(options: HttpRouteAuthorizerBindOptions): HttpRouteAuthorizerConfig;
}

function undefinedIfNoKeys<A>(obj: A): A | undefined {
function undefinedIfNoKeys<A extends { [key: string]: unknown }>(obj: A): A | undefined {
Copy link
Contributor

Choose a reason for hiding this comment

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

[breadcrumb] Anything is assignable to unknown, but unknown isn't assignable to anything but itself. Diff from any.

@mergify
Copy link
Contributor

mergify bot commented Mar 21, 2023

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

@Naumel Naumel added the pr/do-not-merge This PR should not be merged at this time. label Mar 21, 2023
RomainMuller and others added 2 commits March 21, 2023 15:55
Co-authored-by: Naumel <104374999+Naumel@users.noreply.github.com>
@RomainMuller RomainMuller removed the pr/do-not-merge This PR should not be merged at this time. label Mar 22, 2023
@mergify
Copy link
Contributor

mergify bot commented Mar 22, 2023

Thank you for contributing! Your pull request will be updated from main 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 Mar 22, 2023

Thank you for contributing! Your pull request will be updated from main 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: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 61dfab0
  • 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 6d581d7 into main Mar 22, 2023
@mergify mergify bot deleted the rmuller/compiler-v49-next branch March 22, 2023 21:08
@mergify
Copy link
Contributor

mergify bot commented Mar 22, 2023

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

homakk pushed a commit to homakk/aws-cdk that referenced this pull request Mar 28, 2023
Updates dependencies & code as necessary to use `jsii@5.0` to build the AWS CDK.

BREAKING CHANGE: The return type of `aws-cdk-lib.aws_ec2.SecurityGroup.determineRuleScope` was changed from a tuple (`[SecurityGroupBase, string]`) to a struct with the same values, because tuple types are not supported over the jsii interoperability layer, but `jsii@v1` was incorrectly allowing this to be represented as the `JSON` primitive type. This made the API unusable in non-JS languages. The type of the `metadata` property of `aws-cdk-lib.aws_s3_deployment.BucketDeploymentProps` was changed from an index-only struct to an inline map, because `jsii@v1` silently ignored the index signature (which is otherwise un-supported), resulting in an empty object in non-JS/TS languages. As a consequence, the values of that map can no longer be `undefined` (as `jsii` does not currently support nullable elements in collections).

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
laurelmay added a commit to laurelmay/aws-cdk that referenced this pull request Apr 2, 2023
This follows the pattern in aws#24425 which seems to especially happen
after aws#24376 when running these scripts.

This follows the pattern in `scripts/gen.sh` or `/build.sh`.
mergify bot pushed a commit that referenced this pull request Apr 5, 2023
…#24905)

This follows the pattern in #24425 which seems to especially happen
after #24376 when running these scripts.

Closes #24932

----

*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
contribution/core This is a PR that came from AWS. p2 pr-linter/cli-integ-tested Assert that any CLI changes have been integ tested pr-linter/exempt-breaking-change The PR linter will not require stability in stable modules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants