diff --git a/.changeset/tasty-dragons-smash.md b/.changeset/tasty-dragons-smash.md new file mode 100644 index 000000000000..d7d27ce4403f --- /dev/null +++ b/.changeset/tasty-dragons-smash.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Automatically update user's env.d.ts with the proper types to help out migrating away from assets being experimental diff --git a/packages/astro/src/vite-plugin-inject-env-ts/index.ts b/packages/astro/src/vite-plugin-inject-env-ts/index.ts index 0f0fbb86d01a..a97ca134dcd7 100644 --- a/packages/astro/src/vite-plugin-inject-env-ts/index.ts +++ b/packages/astro/src/vite-plugin-inject-env-ts/index.ts @@ -50,6 +50,16 @@ export async function setUpEnvTs({ if (fs.existsSync(envTsPath)) { let typesEnvContents = await fs.promises.readFile(envTsPath, 'utf-8'); + // TODO: Remove this in 4.0, this code is only to help users migrate away from assets being experimental for a long time + if (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)) // Add `.astro` types reference if none exists return;