0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00

Fix env.d.ts switching back between types on every restart when assets are enabled (#6532)

* fix(assets): Fix assets types reverting back on every dev server starts

* chore: changeset
This commit is contained in:
Erika 2023-03-13 14:53:39 +01:00 committed by GitHub
parent acf78c5e27
commit 637f9bc728
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix `env.d.ts` changing types wrongly on every restart when `experimental.assets` is enabled

View file

@ -49,18 +49,25 @@ export async function setUpEnvTs({
if (fs.existsSync(envTsPath)) {
let typesEnvContents = await fs.promises.readFile(envTsPath, 'utf-8');
// TODO: Remove this logic in 3.0, as `astro/client-image` will be merged into `astro/client`
if (settings.config.experimental.assets && typesEnvContents.includes('types="astro/client"')) {
typesEnvContents = typesEnvContents.replace(
'types="astro/client"',
'types="astro/client-image"'
);
await fs.promises.writeFile(envTsPath, typesEnvContents, 'utf-8');
} else if (typesEnvContents.includes('types="astro/client-image"')) {
info(logging, 'assets', `Added ${bold(envTsPathRelativetoRoot)} types`);
} else if (
!settings.config.experimental.assets &&
typesEnvContents.includes('types="astro/client-image"')
) {
typesEnvContents = typesEnvContents.replace(
'types="astro/client-image"',
'types="astro/client"'
);
await fs.promises.writeFile(envTsPath, typesEnvContents, 'utf-8');
info(logging, 'assets', `Removed ${bold(envTsPathRelativetoRoot)} types`);
}
if (!fs.existsSync(dotAstroDir))