Open BryceRussell opened 3 weeks ago
Interesting! I guess delaying would be better but I think that requires moving addDts
to another hook?
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
Yeah I think that would work https://github.com/withastro/astro/blob/main/packages%2Fastro%2Fsrc%2Fvite-plugin-inject-env-ts%2Findex.ts#L30
addDts
breaks after deleting thesrc/env.d.ts
file inside a project. Series of events:src/env.d.ts
file inside a projectsrc/env.d.ts
file doesn't existsrc/env.d.ts
file to fix erroraddDts
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:addDts
runs before Astro can create and seed thesrc/env.d.ts
file. This causes an error when trying to read the file because the file doesn't exist.src/env.d.ts
file is empty,addDts
does not add type references to the file because the/// <reference types='astro/client>
reference does not exist.Possible solutions:
src/env.d.ts
file if it doesn't exist and seed emptysrc/env.d.ts
files with the client reference (like Astro does)addDts
until after Astro generates asrc/env.d.ts
fileWhy 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