Skip to content

Commit

Permalink
chore(cdk-lib): migrate to jsii@5.0 / jsii-rosetta@5.0 (aws#24425)
Browse files Browse the repository at this point in the history
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*
  • Loading branch information
RomainMuller authored Mar 22, 2023
1 parent 8dbca12 commit 6d581d7
Show file tree
Hide file tree
Showing 482 changed files with 1,090 additions and 1,015 deletions.
7 changes: 6 additions & 1 deletion allowed-breaking-changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,9 @@ strengthened:aws-cdk-lib.pipelines.ProduceActionOptions
# reverted a change that broke deployments for anyone using Triggers
removed:aws-cdk-lib.triggers.InvocationType
removed:aws-cdk-lib.triggers.TriggerProps.invocationType
removed:aws-cdk-lib.triggers.TriggerProps.timeout
removed:aws-cdk-lib.triggers.TriggerProps.timeout

# broken: it used to return a tuple type, that was incorrectly interpreted by jsii
change-return-type:aws-cdk-lib.aws_ec2.SecurityGroup.determineRuleScope
# broken only in non-JS/TS, where that was not previously usable
strengthened:aws-cdk-lib.aws_s3_deployment.BucketDeploymentProps
7 changes: 5 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ while [[ "${1:-}" != "" ]]; do
done

export PATH=$(npm bin):$PATH
export NODE_OPTIONS="--max-old-space-size=4096 --experimental-worker ${NODE_OPTIONS:-}"
export NODE_OPTIONS="--max-old-space-size=8196 --experimental-worker ${NODE_OPTIONS:-}"

if ! [ -x "$(command -v yarn)" ]; then
echo "yarn is not installed. Install it from here- https://yarnpkg.com/en/docs/install."
Expand Down Expand Up @@ -78,9 +78,12 @@ if [ "$run_tests" == "true" ]; then
runtarget="$runtarget+test"
fi

# Limit top-level concurrency to available CPUs - 1 to limit CPU load.
concurrency=$(node -p 'Math.max(1, require("os").cpus().length - 1)')

echo "============================================================================================="
echo "building..."
time lerna run $bail --stream $runtarget || fail
time lerna run $bail --stream --concurrency=$concurrency $runtarget || fail

if [ "$check_compat" == "true" ]; then
/bin/bash scripts/check-api-compatibility.sh
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
"fs-extra": "^9.1.0",
"graceful-fs": "^4.2.10",
"jest-junit": "^13.2.0",
"jsii-diff": "1.77.0",
"jsii-pacmak": "1.77.0",
"jsii-reflect": "1.77.0",
"jsii-rosetta": "v4.9-next",
"jsii-diff": "1.78.1",
"jsii-pacmak": "1.78.1",
"jsii-reflect": "1.78.1",
"jsii-rosetta": "~5.0.0",
"lerna": "^4.0.0",
"patch-package": "^6.5.1",
"semver": "^6.3.0",
"standard-version": "^9.5.0",
"typescript": "~3.9.10"
"typescript": "~4.9.5"
},
"resolutions": {
"colors": "1.4.0",
Expand Down
21 changes: 11 additions & 10 deletions packages/@aws-cdk-testing/cli-integ/lib/aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class AwsClients {
public async stackStatus(stackName: string): Promise<string | undefined> {
try {
return (await this.cloudFormation('describeStacks', { StackName: stackName })).Stacks?.[0].StackStatus;
} catch (e) {
} catch (e: any) {
if (isStackMissingError(e)) { return undefined; }
throw e;
}
Expand Down Expand Up @@ -113,7 +113,7 @@ export class AwsClients {
await this.s3('deleteBucket', {
Bucket: bucketName,
});
} catch (e) {
} catch (e: any) {
if (isBucketMissingError(e)) { return; }
throw e;
}
Expand All @@ -126,15 +126,16 @@ export class AwsClients {
* Create the correct client, do the call and resole the promise().
*/
async function awsCall<
A extends AWS.Service,
B extends keyof ServiceCalls<A>,
>(ctor: new (config: any) => A, config: any, call: B, request: First<ServiceCalls<A>[B]>): Promise<Second<ServiceCalls<A>[B]>> {
Svc extends AWS.Service,
Calls extends ServiceCalls<Svc>,
Call extends keyof Calls,
>(ctor: new (config: any) => Svc, config: any, call: Call, request: First<Calls[Call]>): Promise<Second<Calls[Call]>> {
const cfn = new ctor(config);
const response = cfn[call](request);
const response = ((cfn as any)[call] as any)(request);
try {
return response.promise();
} catch (e) {
const newErr = new Error(`${call}(${JSON.stringify(request)}): ${e.message}`);
} catch (e: any) {
const newErr = new Error(`${String(call)}(${JSON.stringify(request)}): ${e.message}`);
(newErr as any).code = e.code;
throw newErr;
}
Expand Down Expand Up @@ -210,7 +211,7 @@ export async function retry<A>(output: NodeJS.WritableStream, operation: string,
const ret = await block();
output.write(`💈 ${operation}: succeeded after ${i} attempts\n`);
return ret;
} catch (e) {
} catch (e: any) {
if (e.abort || Date.now() > deadline.getTime( )) {
throw new Error(`${operation}: did not succeed after ${i} attempts: ${e}`);
}
Expand Down Expand Up @@ -290,4 +291,4 @@ function chainableCredentials(region: string): AWS.Credentials | undefined {
}

return undefined;
}
}
2 changes: 1 addition & 1 deletion packages/@aws-cdk-testing/cli-integ/lib/integ-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function integTest(
output.write(`${s}\n`);
},
});
} catch (e) {
} catch (e: any) {
process.stderr.write(`[INTEG TEST::${name}] Failed: ${e}\n`);
output.write(e.message);
output.write(e.stack);
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk-testing/cli-integ/lib/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export function rimraf(fsPath: string) {
} else {
fs.unlinkSync(fsPath);
}
} catch (e) {
} catch (e: any) {
// We will survive ENOENT
if (e.code !== 'ENOENT') { throw e; }
}
Expand All @@ -165,4 +165,4 @@ export function addToShellPath(x: string) {
}

process.env.PATH = parts.join(':');
}
}
12 changes: 6 additions & 6 deletions packages/@aws-cdk-testing/cli-integ/lib/staging/codeartifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class TestRepository {

// eslint-disable-next-line no-console
console.log('Deleted', this.repositoryName);
} catch (e) {
} catch (e: any) {
if (e.code !== 'ResourceNotFoundException') { throw e; }
// Okay
}
Expand Down Expand Up @@ -199,7 +199,7 @@ export class TestRepository {
try {
await this.codeArtifact.describeDomain({ domain: this.domain }).promise();
return true;
} catch (e) {
} catch (e: any) {
if (e.code !== 'ResourceNotFoundException') { throw e; }
return false;
}
Expand All @@ -209,7 +209,7 @@ export class TestRepository {
try {
await this.codeArtifact.describeRepository({ domain: this.domain, repository: name }).promise();
return true;
} catch (e) {
} catch (e: any) {
if (e.code !== 'ResourceNotFoundException') { throw e; }
return false;
}
Expand Down Expand Up @@ -246,7 +246,7 @@ async function retry<A>(block: () => Promise<A>) {
while (true) {
try {
return await block();
} catch (e) {
} catch (e: any) {
if (attempts-- === 0) { throw e; }
// eslint-disable-next-line no-console
console.debug(e.message);
Expand All @@ -261,7 +261,7 @@ async function retryThrottled<A>(block: () => Promise<A>) {
while (true) {
try {
return await block();
} catch (e) {
} catch (e: any) {
// eslint-disable-next-line no-console
console.debug(e.message);
if (e.code !== 'ThrottlingException') { throw e; }
Expand All @@ -279,4 +279,4 @@ export interface LoginInformation {
readonly mavenEndpoint: string;
readonly nugetEndpoint: string;
readonly pypiEndpoint: string;
}
}
2 changes: 1 addition & 1 deletion packages/@aws-cdk-testing/cli-integ/lib/with-aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async function sanityCheck(aws: AwsClients) {
try {
await aws.account();
sanityChecked = true;
} catch (e) {
} catch (e: any) {
sanityChecked = false;
throw new Error(`AWS credentials probably not configured, got error: ${e.message}`);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk-testing/cli-integ/lib/with-sam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function withSamIntegrationCdkApp<A extends TestContext & AwsContext>(blo
});
}
await block(fixture);
} catch (e) {
} catch (e: any) {
// We survive certain cases involving gopkg.in
if (errorCausedByGoPkg(e.message)) {
return;
Expand Down
8 changes: 4 additions & 4 deletions packages/@aws-cdk-testing/cli-integ/lib/xpmutex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class XpMutex {
// Acquire lock by being the one to create the file
try {
return await this.writePidFile('wx'); // Fails if the file already exists
} catch (e) {
} catch (e: any) {
if (e.code !== 'EEXIST') { throw e; }
}

Expand Down Expand Up @@ -159,7 +159,7 @@ export class XpMutex {
let contents;
try {
contents = await fs.readFile(this.fileName, { encoding: 'utf-8' });
} catch (e) {
} catch (e: any) {
if (e.code === 'ENOENT') { return undefined; }
throw e;
}
Expand Down Expand Up @@ -194,7 +194,7 @@ async function fileExists(fileName: string) {
try {
await fs.stat(fileName);
return true;
} catch (e) {
} catch (e: any) {
if (e.code === 'ENOENT') { return false; }
throw e;
}
Expand All @@ -204,7 +204,7 @@ function processExists(pid: number) {
try {
process.kill(pid, 0);
return true;
} catch (e) {
} catch {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ integTest('deploy with role', withDefaultFixture(async (fixture) => {
});
}
await fixture.aws.iam('deleteRole', { RoleName: roleName });
} catch (e) {
} catch (e: any) {
if (e.message.indexOf('cannot be found') > -1) { return; }
throw e;
}
Expand Down
3 changes: 1 addition & 2 deletions packages/@aws-cdk/alexa-ask/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@
"@aws-cdk/cdk-build-tools": "0.0.0",
"@aws-cdk/cfn2ts": "0.0.0",
"@aws-cdk/pkglint": "0.0.0",
"@types/jest": "^27.5.2",
"jsii": "v4.9-next"
"@types/jest": "^27.5.2"
},
"dependencies": {
"@aws-cdk/core": "0.0.0",
Expand Down
7 changes: 7 additions & 0 deletions packages/@aws-cdk/assertions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
"description": "An assertion library for use with CDK Apps",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"typesVersions": {
"<=3.9": {
"*": [
".types-compat/ts3.9/*"
]
}
},
"scripts": {
"build": "cdk-build",
"watch": "cdk-watch",
Expand Down
3 changes: 1 addition & 2 deletions packages/@aws-cdk/aws-accessanalyzer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@
"@aws-cdk/cdk-build-tools": "0.0.0",
"@aws-cdk/cfn2ts": "0.0.0",
"@aws-cdk/pkglint": "0.0.0",
"@types/jest": "^27.5.2",
"jsii": "v4.9-next"
"@types/jest": "^27.5.2"
},
"dependencies": {
"@aws-cdk/core": "0.0.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/@aws-cdk/aws-amazonmq/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@
"@aws-cdk/cdk-build-tools": "0.0.0",
"@aws-cdk/cfn2ts": "0.0.0",
"@aws-cdk/pkglint": "0.0.0",
"@types/jest": "^27.5.2",
"jsii": "v4.9-next"
"@types/jest": "^27.5.2"
},
"dependencies": {
"@aws-cdk/core": "0.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ export abstract class ResourceHandler {
console.log(JSON.stringify(x, undefined, 2));
}

protected abstract async onCreate(): Promise<AmplifyJobId>;
protected abstract async onDelete(): Promise<void>;
protected abstract async onUpdate(): Promise<AmplifyJobId>;
protected abstract async isCreateComplete(): Promise<IsCompleteResponse>;
protected abstract async isDeleteComplete(): Promise<IsCompleteResponse>;
protected abstract async isUpdateComplete(): Promise<IsCompleteResponse>;
protected abstract onCreate(): Promise<AmplifyJobId>;
protected abstract onDelete(): Promise<void>;
protected abstract onUpdate(): Promise<AmplifyJobId>;
protected abstract isCreateComplete(): Promise<IsCompleteResponse>;
protected abstract isDeleteComplete(): Promise<IsCompleteResponse>;
protected abstract isUpdateComplete(): Promise<IsCompleteResponse>;
}
3 changes: 1 addition & 2 deletions packages/@aws-cdk/aws-amplify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@
"@aws-cdk/cfn2ts": "0.0.0",
"@aws-cdk/pkglint": "0.0.0",
"@types/jest": "^27.5.2",
"aws-sdk": "^2.1329.0",
"jsii": "v4.9-next"
"aws-sdk": "^2.1329.0"
},
"dependencies": {
"@aws-cdk/aws-codebuild": "0.0.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/@aws-cdk/aws-amplifyuibuilder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@
"@aws-cdk/cfn2ts": "0.0.0",
"@aws-cdk/pkglint": "0.0.0",
"@types/jest": "^27.5.2",
"@types/node": "18.11.19",
"jsii": "v4.9-next"
"@types/node": "18.11.19"
},
"dependencies": {
"@aws-cdk/core": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-apigateway/lib/authorizers/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ abstract class LambdaAuthorizer extends Authorizer implements IAuthorizer {
* The id of the authorizer.
* @attribute
*/
public abstract readonly authorizerId: string;
public abstract override readonly authorizerId: string;

/**
* The ARN of the authorizer to be used in permission policies, such as IAM and resource-based grants.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6d581d7

Please sign in to comment.