florian-lefebvre / astro-integration-kit

A package that contains utilities to help you build Astro integrations.
https://astro-integration-kit.netlify.app
MIT License
46 stars 8 forks source link

`addDts` breaks after removing the `src/env.d.ts` file inside a project #111

Open BryceRussell opened 3 weeks ago

BryceRussell commented 3 weeks ago

addDts breaks after deleting the src/env.d.ts file inside a project. Series of events:

  1. User deletes src/env.d.ts file inside a project
  2. User gets an error that the src/env.d.ts file doesn't exist
  3. User creates an empty src/env.d.ts file to fix error
  4. addDts silently fails to add an entry to the new file because it is empty and does not contain the reference /// <reference types='astro/client>

addDts breaks in two of these steps:

Possible solutions:

Why are you even deleting src/env.d.ts? What is your use case?

Sometimes I delete the file so that it can regenerate because there might be unused references from addDts or older versions of Astro

florian-lefebvre commented 3 weeks ago

Interesting! I guess delaying would be better but I think that requires moving addDts to another hook?

BryceRussell commented 3 weeks ago

Maybe the execution of addDts could be delayed using a hook (like configResolved) inside a Vite plugin so that it can stay inside astro:config:setup

florian-lefebvre commented 3 weeks ago

Yeah I think that would work https://github.com/withastro/astro/blob/main/packages%2Fastro%2Fsrc%2Fvite-plugin-inject-env-ts%2Findex.ts#L30