nestjs / nest-cli

CLI tool for Nest applications 🍹
https://nestjs.com
Other
1.97k stars 394 forks source link

Allow `--type-check` to be set to `false` and override `nest-cli.json` #2796

Open dunklesToast opened 2 days ago

dunklesToast commented 2 days ago

Is there an existing issue that is already proposing this?

Is your feature request related to a problem? Please describe it

Right now it does seem possible to turn off type-checking with SWC if it is enabled in the nest-cli.json. Take this config:

{
  "collection": "@nestjs/schematics",
  "sourceRoot": "src",
  "compilerOptions": {
    "typeCheck": true,
    "builder": "swc"
  }
}

Running nest start starts the TSC TypeChecker and when done builds with swc which is what I expect. If i now use nest build --type-check=false (also tried without =) the type check will start anyway. This seems to be a somewhat specific handling for this flag only, as nest start --builder=tsc would start the build process using tscinstead, ruling over my nest-cli.json.

Describe the solution you'd like

The easiest solution would be to allow --type-check (and maybe other boolean-like flags) to also be disabled by the CLI via an (optional) argument. I've tried finding my way through this repository but couldn't quite figure out where this logic happens.

Teachability, documentation, adoption, migration strategy

User could add an additional, optional parameter after the --type-check. I'd suggest an interface like this:

nest build # fallback to config
nest build --type-check # type-checks
nest build --type-check true # type checks
nest build --type-check false # does not type-check, even if config is `true`

as this would not touch the current behavior there shouldn't be any issues with just releasing this as an minor issue.

What is the motivation / use case for changing the behavior?

I have two motivations for this change, which boil down to the same reason: speed and efficiency.

The first use case is in our CI: We're already type-checking our whole monorepo earlier in the CI process so it's not necessary to do this again when building NestJS. Removing the unnecessary type check here will speed up the process by about 20s. Our second use case is swagger.json generation. If our Nest Application is started with a specific environment variable it will only output the swagger.json and then exit. This is needed to generate the OpenAPI Clients based on this swagger file. At this time in the process we don't really care if the types are valid (cause either it is mid-development or they've already been checked before in the CI) so we would love to also skip type checking there as well.

micalevisk commented 2 days ago

we have a naming convention for the disabled version of a boolean flag. For example: --no-flat and --no-spec from the generate command

So I'd suggest --no-type-check instead

dunklesToast commented 1 day ago

Alright - did not knew that. Maybe then I can check again if I can implement this myself as adding a whole new flag seems to be easier doable as to add arguments. If you find the feature idea useful and have no objections I'd begin working on it and if done would create a PR. Would that work for you?