astro icon indicating copy to clipboard operation
astro copied to clipboard

`create-astro`: always create `tsconfig.json`

Open mrienstra opened this issue 1 year ago • 1 comments

Changes

Alway write chosen config to tsconfig.json.

  • Before: Only when strict or strictest was selected
  • After: Also when base is selected (via "Relaxed" or "I prefer not to use TypeScript")

Testing

Added new typescript-step.test.js test file to test existing and new behavior related to the typescript prompt / --typescript CLI argument).

Docs

Existing create-astro docs don't mention tsconfig.json, so no changes are needed.

Motivation

Before this PR:

  1. If base: A) Do nothing: assumes a default base tsconfig.json, which is the case for all 23 official templates, but not necessarily for third-party templates.

  2. If strict or strictest: A) Make sure tsconfig.json exists (create if missing). B) Write chosen extends to tsconfig.json (e.g. { "extends": "astro/tsconfigs/strict" }).

After this PR: base is treated the same as strict or strictest.

Template without tsconfig.json

The example command for installing a third-party template -- rather conveniently for the sake of this PR -- uses a template without a tsconfig.json file, and installing it (prior to the changes in this PR) with the base Typescript option results in no tsconfig.json file, rather than a tsconfig.json file containing { "extends": "astro/tsconfigs/base" } as would be expected.

Template with tsconfig.json not containing { "extends": "astro/tsconfigs/base" }

If a third-party template doesn't use the base config, installing it (prior to the changes in this PR) with the base Typescript option results in no changes to tsconfig.json, rather than setting extends to astro/tsconfigs/base as would be expected.

mrienstra avatar Sep 20 '22 09:09 mrienstra