Skip to content

Commit

Permalink
chore(cdk): Speed up typescript app compile time (#25089)
Browse files Browse the repository at this point in the history
> REPLACE THIS TEXT BLOCK
>
> Describe the reason for this change, what the solution is, and any
> important design decisions you made. 
>
> Remember to follow the [CONTRIBUTING GUIDE] and [DESIGN GUIDELINES] for any
> code you submit.
>
> [CONTRIBUTING GUIDE]: https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md
> [DESIGN GUIDELINES]: https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md

Closes #None.

The cdk init command can generate a typescript cdk app. The cdk app uses ts-node for things like cdk deploys. As a developer, it seems to take forever for the ts-node to start the cdk deploy process. Adding SWC to the tsconfig file allows ts-node to use a rust-based transpiler when doing a cdk deploy. The SWC speeds up the cdk deploy time by a lot.

I have not noticed any type checking issues in vscode nor any transpile issues in deployed lambda functions.

Ref: https://typestrong.org/ts-node/docs/swc/
Ref: https://aws.plainenglish.io/speed-up-aws-cdk-deploys-up-to-80-c47afad1c18c

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
miguel-a-calles-mba authored May 22, 2023
1 parent c6f9fb6 commit f05ed21
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/aws-cdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -811,3 +811,25 @@ The following environment variables affect aws-cdk:
The CLI will attempt to detect whether it is being run in CI by looking for the presence of an
environment variable `CI=true`. This can be forced by passing the `--ci` flag. By default the CLI
sends most of its logs to `stderr`, but when `ci=true` it will send the logs to `stdout` instead.

### Changing the default TypeScript transpiler

The ts-node package used to synthesize and deploy CDK apps supports an alternate transpiler that might improve transpile times. The SWC transpiler is written in Rust and has no type checking. The SWC transpiler should be enabled by experienced TypeScript developers.

To enable the SWC transpiler, install the package in the CDK app.

```sh
npm i -D @swc/core @swc/helpers regenerator-runtime
```

And, update the `tsconfig.json` file to add the `ts-node` property.

```json
{
"ts-node": {
"swc": true
}
}
```

The documentation may be found at <https://typestrong.org/ts-node/docs/swc/>

0 comments on commit f05ed21

Please sign in to comment.