From c71194d7aac9c08b0cba5ab189bd7f8c8b046f9b Mon Sep 17 00:00:00 2001 From: Princesseuh Date: Mon, 13 Mar 2023 14:23:26 +0100 Subject: [PATCH 1/2] fix(assets): Fix assets types reverting back on every dev server starts --- packages/astro/src/vite-plugin-inject-env-ts/index.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 bee2f37cc663..1693917f7e7e 100644 --- a/packages/astro/src/vite-plugin-inject-env-ts/index.ts +++ b/packages/astro/src/vite-plugin-inject-env-ts/index.ts @@ -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)) From e3a917922755bc4c4602c6a31ec921d396f0fa33 Mon Sep 17 00:00:00 2001 From: Princesseuh Date: Mon, 13 Mar 2023 14:27:48 +0100 Subject: [PATCH 2/2] chore: changeset --- .changeset/tough-sheep-grab.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/tough-sheep-grab.md diff --git a/.changeset/tough-sheep-grab.md b/.changeset/tough-sheep-grab.md new file mode 100644 index 000000000000..d4870c980ea8 --- /dev/null +++ b/.changeset/tough-sheep-grab.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix `env.d.ts` changing types wrongly on every restart when `experimental.assets` is enabled