Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tough-sheep-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix `env.d.ts` changing types wrongly on every restart when `experimental.assets` is enabled
9 changes: 8 additions & 1 deletion packages/astro/src/vite-plugin-inject-env-ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down