terraform-cdk icon indicating copy to clipboard operation
terraform-cdk copied to clipboard

chore(cli): Move things to src/ folder

Open mutahhir opened this issue 2 years ago • 0 comments

While working on the CLI, I found it a bit annoying that the *.js and *.d.ts files show up alongside our *.ts files. I also realize that we're compiling everything twice because we do tsc and esbuild. So, this PR is kind of a proposal / rfc for:

  • Moving all typescript sources within the src/ folder
  • Since esbuild doesn't validate typescript, we still need to use tsc, but can we enable --noEmit to just perform type-checking.

Challenges

Incremental builds

Unfortunately, we lose the ability to use incremental builds because of this. --noEmit and --incremental work together in Typescript 4.0+, but we're restricted in that regard due to JSII.

CDKTF Application Entrypoint

One of the challenges we have with this change is the cdktf application file. It has the following code:

#!/usr/bin/env node
require("./cdktf.js");

We reference this file to run some integration-like tests which then start failing because the cdktf.js file is no longer emitted by tsc.

In this PR, I've moved that to using bundle/bin/cdktf since that's also being generated.


Changes to development workflow

A few developer workflow changes are proposed in this PR:

  • We shouldn't rely on bin/cdktf (now src/bin/cdktf). Instead the bundled version of it has to be used, which is bundle/bin/cdktf
  • Since we're no longer using tsc for building, there won't be any typechecking during watches. However, types are checked as part of the pre-commit hook. (I'm still a bit unhappy about this one, but this might actually be a bit better from a developer experience point of view).

mutahhir avatar Sep 19 '22 08:09 mutahhir