diff --git a/.changeset/old-zebras-teach.md b/.changeset/old-zebras-teach.md
new file mode 100644
index 000000000000..1b22948949e5
--- /dev/null
+++ b/.changeset/old-zebras-teach.md
@@ -0,0 +1,19 @@
+---
+'astro': major
+---
+
+Changes the default `tsconfig.json` with better defaults, and makes `src/env.d.ts` optional
+
+Astro's default `tsconfig.json` in starter examples has been updated to include generated types and exclude your build output. This means that `src/env.d.ts` is only necessary if you have added custom type declarations or if you're not using a `tsconfig.json` file.
+
+Additionally, running `astro sync` no longer creates, nor updates, `src/env.d.ts` as it is not required for type-checking standard Astro projects.
+
+To update your project to Astro's recommended TypeScript settings, please add the following `include` and `exclude` properties to `tsconfig.json`:
+
+```diff
+{
+ "extends": "astro/tsconfigs/base",
++ "include": ["**/*", ".astro/types.d.ts"],
++ "exclude": ["dist"]
+}
+```
\ No newline at end of file
diff --git a/examples/basics/tsconfig.json b/examples/basics/tsconfig.json
index d78f81ec4e8e..d2e51fb463de 100644
--- a/examples/basics/tsconfig.json
+++ b/examples/basics/tsconfig.json
@@ -1,3 +1,5 @@
{
- "extends": "astro/tsconfigs/base"
+ "extends": "astro/tsconfigs/base",
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/examples/blog/src/env.d.ts b/examples/blog/src/env.d.ts
deleted file mode 100644
index e16c13c6952a..000000000000
--- a/examples/blog/src/env.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-///
diff --git a/examples/blog/tsconfig.json b/examples/blog/tsconfig.json
index e51e062706f0..c2e5e77cdc53 100644
--- a/examples/blog/tsconfig.json
+++ b/examples/blog/tsconfig.json
@@ -1,5 +1,7 @@
{
"extends": "astro/tsconfigs/base",
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"],
"compilerOptions": {
"strictNullChecks": true
}
diff --git a/examples/component/tsconfig.json b/examples/component/tsconfig.json
index 26f2fc53ddc1..3e4a08650bd4 100644
--- a/examples/component/tsconfig.json
+++ b/examples/component/tsconfig.json
@@ -1,5 +1,7 @@
{
"extends": "astro/tsconfigs/base",
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"],
"compilerOptions": {
"jsx": "preserve"
}
diff --git a/examples/container-with-vitest/tsconfig.json b/examples/container-with-vitest/tsconfig.json
index d78f81ec4e8e..d2e51fb463de 100644
--- a/examples/container-with-vitest/tsconfig.json
+++ b/examples/container-with-vitest/tsconfig.json
@@ -1,3 +1,5 @@
{
- "extends": "astro/tsconfigs/base"
+ "extends": "astro/tsconfigs/base",
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/examples/framework-alpine/src/env.d.ts b/examples/framework-alpine/src/env.d.ts
deleted file mode 100644
index e16c13c6952a..000000000000
--- a/examples/framework-alpine/src/env.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-///
diff --git a/examples/framework-alpine/tsconfig.json b/examples/framework-alpine/tsconfig.json
index d78f81ec4e8e..d2e51fb463de 100644
--- a/examples/framework-alpine/tsconfig.json
+++ b/examples/framework-alpine/tsconfig.json
@@ -1,3 +1,5 @@
{
- "extends": "astro/tsconfigs/base"
+ "extends": "astro/tsconfigs/base",
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/examples/framework-multiple/src/env.d.ts b/examples/framework-multiple/src/env.d.ts
deleted file mode 100644
index e16c13c6952a..000000000000
--- a/examples/framework-multiple/src/env.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-///
diff --git a/examples/framework-multiple/tsconfig.json b/examples/framework-multiple/tsconfig.json
index 2d48ed5fd9c3..38d2e052b524 100644
--- a/examples/framework-multiple/tsconfig.json
+++ b/examples/framework-multiple/tsconfig.json
@@ -1,5 +1,7 @@
{
"extends": "astro/tsconfigs/base",
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"],
"compilerOptions": {
// Needed for TypeScript intellisense in the template inside Vue files
"jsx": "preserve"
diff --git a/examples/framework-preact/src/env.d.ts b/examples/framework-preact/src/env.d.ts
deleted file mode 100644
index e16c13c6952a..000000000000
--- a/examples/framework-preact/src/env.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-///
diff --git a/examples/framework-preact/tsconfig.json b/examples/framework-preact/tsconfig.json
index bdd1b5a88e0a..8faaad1f8958 100644
--- a/examples/framework-preact/tsconfig.json
+++ b/examples/framework-preact/tsconfig.json
@@ -1,5 +1,7 @@
{
"extends": "astro/tsconfigs/base",
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"],
"compilerOptions": {
// Preact specific settings
"jsx": "react-jsx",
diff --git a/examples/framework-react/src/env.d.ts b/examples/framework-react/src/env.d.ts
deleted file mode 100644
index e16c13c6952a..000000000000
--- a/examples/framework-react/src/env.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-///
diff --git a/examples/framework-react/tsconfig.json b/examples/framework-react/tsconfig.json
index e726bd0b9a32..1bb17eb064a5 100644
--- a/examples/framework-react/tsconfig.json
+++ b/examples/framework-react/tsconfig.json
@@ -1,5 +1,7 @@
{
"extends": "astro/tsconfigs/base",
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"],
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "react"
diff --git a/examples/framework-solid/src/env.d.ts b/examples/framework-solid/src/env.d.ts
deleted file mode 100644
index e16c13c6952a..000000000000
--- a/examples/framework-solid/src/env.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-///
diff --git a/examples/framework-solid/tsconfig.json b/examples/framework-solid/tsconfig.json
index 6e107fd32216..c1ca2dae5f79 100644
--- a/examples/framework-solid/tsconfig.json
+++ b/examples/framework-solid/tsconfig.json
@@ -1,5 +1,7 @@
{
"extends": "astro/tsconfigs/base",
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"],
"compilerOptions": {
// Solid specific settings
"jsx": "preserve",
diff --git a/examples/framework-svelte/src/env.d.ts b/examples/framework-svelte/src/env.d.ts
deleted file mode 100644
index e16c13c6952a..000000000000
--- a/examples/framework-svelte/src/env.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-///
diff --git a/examples/framework-svelte/tsconfig.json b/examples/framework-svelte/tsconfig.json
index d78f81ec4e8e..d2e51fb463de 100644
--- a/examples/framework-svelte/tsconfig.json
+++ b/examples/framework-svelte/tsconfig.json
@@ -1,3 +1,5 @@
{
- "extends": "astro/tsconfigs/base"
+ "extends": "astro/tsconfigs/base",
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/examples/framework-vue/src/env.d.ts b/examples/framework-vue/src/env.d.ts
deleted file mode 100644
index e16c13c6952a..000000000000
--- a/examples/framework-vue/src/env.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-///
diff --git a/examples/framework-vue/tsconfig.json b/examples/framework-vue/tsconfig.json
index 2d48ed5fd9c3..38d2e052b524 100644
--- a/examples/framework-vue/tsconfig.json
+++ b/examples/framework-vue/tsconfig.json
@@ -1,5 +1,7 @@
{
"extends": "astro/tsconfigs/base",
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"],
"compilerOptions": {
// Needed for TypeScript intellisense in the template inside Vue files
"jsx": "preserve"
diff --git a/examples/hackernews/src/env.d.ts b/examples/hackernews/src/env.d.ts
deleted file mode 100644
index e16c13c6952a..000000000000
--- a/examples/hackernews/src/env.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-///
diff --git a/examples/hackernews/tsconfig.json b/examples/hackernews/tsconfig.json
index d78f81ec4e8e..d2e51fb463de 100644
--- a/examples/hackernews/tsconfig.json
+++ b/examples/hackernews/tsconfig.json
@@ -1,3 +1,5 @@
{
- "extends": "astro/tsconfigs/base"
+ "extends": "astro/tsconfigs/base",
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/examples/middleware/src/env.d.ts b/examples/middleware/src/env.d.ts
index 74b9019e5746..e992c531518b 100644
--- a/examples/middleware/src/env.d.ts
+++ b/examples/middleware/src/env.d.ts
@@ -1,4 +1,3 @@
-///
declare namespace App {
interface Locals {
user: {
diff --git a/examples/middleware/tsconfig.json b/examples/middleware/tsconfig.json
index d78f81ec4e8e..d2e51fb463de 100644
--- a/examples/middleware/tsconfig.json
+++ b/examples/middleware/tsconfig.json
@@ -1,3 +1,5 @@
{
- "extends": "astro/tsconfigs/base"
+ "extends": "astro/tsconfigs/base",
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/examples/minimal/src/env.d.ts b/examples/minimal/src/env.d.ts
deleted file mode 100644
index e16c13c6952a..000000000000
--- a/examples/minimal/src/env.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-///
diff --git a/examples/minimal/tsconfig.json b/examples/minimal/tsconfig.json
index d78f81ec4e8e..d2e51fb463de 100644
--- a/examples/minimal/tsconfig.json
+++ b/examples/minimal/tsconfig.json
@@ -1,3 +1,5 @@
{
- "extends": "astro/tsconfigs/base"
+ "extends": "astro/tsconfigs/base",
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/examples/non-html-pages/src/env.d.ts b/examples/non-html-pages/src/env.d.ts
deleted file mode 100644
index e16c13c6952a..000000000000
--- a/examples/non-html-pages/src/env.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-///
diff --git a/examples/non-html-pages/tsconfig.json b/examples/non-html-pages/tsconfig.json
index d78f81ec4e8e..d2e51fb463de 100644
--- a/examples/non-html-pages/tsconfig.json
+++ b/examples/non-html-pages/tsconfig.json
@@ -1,3 +1,5 @@
{
- "extends": "astro/tsconfigs/base"
+ "extends": "astro/tsconfigs/base",
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/examples/portfolio/src/env.d.ts b/examples/portfolio/src/env.d.ts
deleted file mode 100644
index e16c13c6952a..000000000000
--- a/examples/portfolio/src/env.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-///
diff --git a/examples/portfolio/tsconfig.json b/examples/portfolio/tsconfig.json
index d78f81ec4e8e..d2e51fb463de 100644
--- a/examples/portfolio/tsconfig.json
+++ b/examples/portfolio/tsconfig.json
@@ -1,3 +1,5 @@
{
- "extends": "astro/tsconfigs/base"
+ "extends": "astro/tsconfigs/base",
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/examples/ssr/src/env.d.ts b/examples/ssr/src/env.d.ts
deleted file mode 100644
index e16c13c6952a..000000000000
--- a/examples/ssr/src/env.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-///
diff --git a/examples/ssr/tsconfig.json b/examples/ssr/tsconfig.json
index d78f81ec4e8e..d2e51fb463de 100644
--- a/examples/ssr/tsconfig.json
+++ b/examples/ssr/tsconfig.json
@@ -1,3 +1,5 @@
{
- "extends": "astro/tsconfigs/base"
+ "extends": "astro/tsconfigs/base",
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/examples/starlog/tsconfig.json b/examples/starlog/tsconfig.json
index da42df94e013..08454317ed8d 100644
--- a/examples/starlog/tsconfig.json
+++ b/examples/starlog/tsconfig.json
@@ -1,4 +1,5 @@
{
"extends": "astro/tsconfigs/strict",
+ "include": ["**/*", ".astro/types.d.ts"],
"exclude": ["dist"]
}
diff --git a/examples/view-transitions/tsconfig.json b/examples/view-transitions/tsconfig.json
index d9bbfacf871a..60762da04dcf 100644
--- a/examples/view-transitions/tsconfig.json
+++ b/examples/view-transitions/tsconfig.json
@@ -1,5 +1,7 @@
{
"extends": "astro/tsconfigs/base",
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"],
"compilerOptions": {
"resolveJsonModule": true
}
diff --git a/examples/with-markdoc/src/env.d.ts b/examples/with-markdoc/src/env.d.ts
deleted file mode 100644
index e16c13c6952a..000000000000
--- a/examples/with-markdoc/src/env.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-///
diff --git a/examples/with-markdoc/tsconfig.json b/examples/with-markdoc/tsconfig.json
index e51e062706f0..c2e5e77cdc53 100644
--- a/examples/with-markdoc/tsconfig.json
+++ b/examples/with-markdoc/tsconfig.json
@@ -1,5 +1,7 @@
{
"extends": "astro/tsconfigs/base",
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"],
"compilerOptions": {
"strictNullChecks": true
}
diff --git a/examples/with-markdown-plugins/src/env.d.ts b/examples/with-markdown-plugins/src/env.d.ts
deleted file mode 100644
index e16c13c6952a..000000000000
--- a/examples/with-markdown-plugins/src/env.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-///
diff --git a/examples/with-markdown-plugins/tsconfig.json b/examples/with-markdown-plugins/tsconfig.json
index d78f81ec4e8e..d2e51fb463de 100644
--- a/examples/with-markdown-plugins/tsconfig.json
+++ b/examples/with-markdown-plugins/tsconfig.json
@@ -1,3 +1,5 @@
{
- "extends": "astro/tsconfigs/base"
+ "extends": "astro/tsconfigs/base",
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/examples/with-markdown-shiki/src/env.d.ts b/examples/with-markdown-shiki/src/env.d.ts
deleted file mode 100644
index e16c13c6952a..000000000000
--- a/examples/with-markdown-shiki/src/env.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-///
diff --git a/examples/with-markdown-shiki/tsconfig.json b/examples/with-markdown-shiki/tsconfig.json
index d78f81ec4e8e..d2e51fb463de 100644
--- a/examples/with-markdown-shiki/tsconfig.json
+++ b/examples/with-markdown-shiki/tsconfig.json
@@ -1,3 +1,5 @@
{
- "extends": "astro/tsconfigs/base"
+ "extends": "astro/tsconfigs/base",
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/examples/with-mdx/src/env.d.ts b/examples/with-mdx/src/env.d.ts
deleted file mode 100644
index e16c13c6952a..000000000000
--- a/examples/with-mdx/src/env.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-///
diff --git a/examples/with-mdx/tsconfig.json b/examples/with-mdx/tsconfig.json
index d78f81ec4e8e..d2e51fb463de 100644
--- a/examples/with-mdx/tsconfig.json
+++ b/examples/with-mdx/tsconfig.json
@@ -1,3 +1,5 @@
{
- "extends": "astro/tsconfigs/base"
+ "extends": "astro/tsconfigs/base",
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/examples/with-nanostores/src/env.d.ts b/examples/with-nanostores/src/env.d.ts
deleted file mode 100644
index e16c13c6952a..000000000000
--- a/examples/with-nanostores/src/env.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-///
diff --git a/examples/with-nanostores/tsconfig.json b/examples/with-nanostores/tsconfig.json
index bdd1b5a88e0a..8faaad1f8958 100644
--- a/examples/with-nanostores/tsconfig.json
+++ b/examples/with-nanostores/tsconfig.json
@@ -1,5 +1,7 @@
{
"extends": "astro/tsconfigs/base",
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"],
"compilerOptions": {
// Preact specific settings
"jsx": "react-jsx",
diff --git a/examples/with-tailwindcss/src/env.d.ts b/examples/with-tailwindcss/src/env.d.ts
deleted file mode 100644
index e16c13c6952a..000000000000
--- a/examples/with-tailwindcss/src/env.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-///
diff --git a/examples/with-tailwindcss/tsconfig.json b/examples/with-tailwindcss/tsconfig.json
index d78f81ec4e8e..d2e51fb463de 100644
--- a/examples/with-tailwindcss/tsconfig.json
+++ b/examples/with-tailwindcss/tsconfig.json
@@ -1,3 +1,5 @@
{
- "extends": "astro/tsconfigs/base"
+ "extends": "astro/tsconfigs/base",
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/examples/with-vitest/tsconfig.json b/examples/with-vitest/tsconfig.json
index d78f81ec4e8e..d2e51fb463de 100644
--- a/examples/with-vitest/tsconfig.json
+++ b/examples/with-vitest/tsconfig.json
@@ -1,3 +1,5 @@
{
- "extends": "astro/tsconfigs/base"
+ "extends": "astro/tsconfigs/base",
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/packages/astro/e2e/fixtures/actions-blog/tsconfig.json b/packages/astro/e2e/fixtures/actions-blog/tsconfig.json
index 6bed1f7a51c0..0d8f554cc0ff 100644
--- a/packages/astro/e2e/fixtures/actions-blog/tsconfig.json
+++ b/packages/astro/e2e/fixtures/actions-blog/tsconfig.json
@@ -4,5 +4,7 @@
"strictNullChecks": true,
"jsx": "react-jsx",
"jsxImportSource": "react"
- }
+ },
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
\ No newline at end of file
diff --git a/packages/astro/e2e/fixtures/actions-react-19/tsconfig.json b/packages/astro/e2e/fixtures/actions-react-19/tsconfig.json
index 6bed1f7a51c0..0d8f554cc0ff 100644
--- a/packages/astro/e2e/fixtures/actions-react-19/tsconfig.json
+++ b/packages/astro/e2e/fixtures/actions-react-19/tsconfig.json
@@ -4,5 +4,7 @@
"strictNullChecks": true,
"jsx": "react-jsx",
"jsxImportSource": "react"
- }
+ },
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
\ No newline at end of file
diff --git a/packages/astro/e2e/fixtures/client-only/tsconfig.json b/packages/astro/e2e/fixtures/client-only/tsconfig.json
index 9e4ac6056834..ea5145d3093a 100644
--- a/packages/astro/e2e/fixtures/client-only/tsconfig.json
+++ b/packages/astro/e2e/fixtures/client-only/tsconfig.json
@@ -1,5 +1,7 @@
{
"compilerOptions": {
"importsNotUsedAsValues": "error"
- }
+ },
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
\ No newline at end of file
diff --git a/packages/astro/e2e/fixtures/custom-client-directives/tsconfig.json b/packages/astro/e2e/fixtures/custom-client-directives/tsconfig.json
index 59a562e0e58b..97a67903ae0d 100644
--- a/packages/astro/e2e/fixtures/custom-client-directives/tsconfig.json
+++ b/packages/astro/e2e/fixtures/custom-client-directives/tsconfig.json
@@ -4,5 +4,6 @@
// This is only needed because we link Astro locally.
"preserveSymlinks": true
},
- "include": ["./src/**/*"]
+ "include": ["./src/**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
\ No newline at end of file
diff --git a/packages/astro/performance/fixtures/md/src/env.d.ts b/packages/astro/performance/fixtures/md/src/env.d.ts
deleted file mode 100644
index 4b38f4e5c680..000000000000
--- a/packages/astro/performance/fixtures/md/src/env.d.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-///
-///
-///
\ No newline at end of file
diff --git a/packages/astro/performance/fixtures/md/tsconfig.json b/packages/astro/performance/fixtures/md/tsconfig.json
index 7fb90fafc062..98ab98bc4c3e 100644
--- a/packages/astro/performance/fixtures/md/tsconfig.json
+++ b/packages/astro/performance/fixtures/md/tsconfig.json
@@ -3,5 +3,7 @@
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "react"
- }
+ },
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
\ No newline at end of file
diff --git a/packages/astro/performance/fixtures/mdoc/tsconfig.json b/packages/astro/performance/fixtures/mdoc/tsconfig.json
index 7fb90fafc062..98ab98bc4c3e 100644
--- a/packages/astro/performance/fixtures/mdoc/tsconfig.json
+++ b/packages/astro/performance/fixtures/mdoc/tsconfig.json
@@ -3,5 +3,7 @@
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "react"
- }
+ },
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
\ No newline at end of file
diff --git a/packages/astro/performance/fixtures/mdx/tsconfig.json b/packages/astro/performance/fixtures/mdx/tsconfig.json
index 7fb90fafc062..98ab98bc4c3e 100644
--- a/packages/astro/performance/fixtures/mdx/tsconfig.json
+++ b/packages/astro/performance/fixtures/mdx/tsconfig.json
@@ -3,5 +3,7 @@
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "react"
- }
+ },
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
\ No newline at end of file
diff --git a/packages/astro/performance/fixtures/utils/tsconfig.json b/packages/astro/performance/fixtures/utils/tsconfig.json
index 33fcab125ab3..5851e5189ac9 100644
--- a/packages/astro/performance/fixtures/utils/tsconfig.json
+++ b/packages/astro/performance/fixtures/utils/tsconfig.json
@@ -2,5 +2,7 @@
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "react"
- }
+ },
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/packages/astro/src/core/sync/constants.ts b/packages/astro/src/core/sync/constants.ts
deleted file mode 100644
index 7ff603105a75..000000000000
--- a/packages/astro/src/core/sync/constants.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-// TODO: use types.d.ts for backward compatibility. Use astro.d.ts in Astro 5.0
-export const REFERENCE_FILE = './types.d.ts';
diff --git a/packages/astro/src/core/sync/index.ts b/packages/astro/src/core/sync/index.ts
index 88c37fa882ef..236ab63a0c87 100644
--- a/packages/astro/src/core/sync/index.ts
+++ b/packages/astro/src/core/sync/index.ts
@@ -30,7 +30,8 @@ import {
import type { Logger } from '../logger/core.js';
import { formatErrorMessage } from '../messages.js';
import { ensureProcessNodeEnv } from '../util.js';
-import { writeFiles } from './write-files.js';
+import { dirname, relative } from 'node:path';
+import { normalizePath } from 'vite';
export type SyncOptions = {
/**
@@ -135,7 +136,7 @@ export async function syncInternal({
}
syncAstroEnv(settings);
- await writeFiles(settings, fs, logger);
+ writeInjectedTypes(settings, fs);
logger.info('types', `Generated ${dim(getTimeStat(timerStart, performance.now()))}`);
} catch (err) {
const error = createSafeError(err);
@@ -148,6 +149,33 @@ export async function syncInternal({
}
}
+function getTsReference(type: 'path' | 'types', value: string) {
+ return `/// `;
+}
+
+const CLIENT_TYPES_REFERENCE = getTsReference('types', 'astro/client');
+
+function writeInjectedTypes(settings: AstroSettings, fs: typeof fsMod) {
+ const references: Array = [];
+
+ for (const { filename, content } of settings.injectedTypes) {
+ const filepath = fileURLToPath(new URL(filename, settings.dotAstroDir));
+ fs.mkdirSync(dirname(filepath), { recursive: true });
+ fs.writeFileSync(filepath, content, 'utf-8');
+ references.push(normalizePath(relative(fileURLToPath(settings.dotAstroDir), filepath)));
+ }
+
+ const astroDtsContent = `${CLIENT_TYPES_REFERENCE}\n${references.map((reference) => getTsReference('path', reference)).join('\n')}`;
+ if (references.length === 0) {
+ fs.mkdirSync(settings.dotAstroDir, { recursive: true });
+ }
+ fs.writeFileSync(
+ fileURLToPath(new URL('./types.d.ts', settings.dotAstroDir)),
+ astroDtsContent,
+ 'utf-8',
+ );
+}
+
/**
* Generate content collection types, and then returns the process exit signal.
*
diff --git a/packages/astro/src/core/sync/write-files.ts b/packages/astro/src/core/sync/write-files.ts
deleted file mode 100644
index 1f7d1d304608..000000000000
--- a/packages/astro/src/core/sync/write-files.ts
+++ /dev/null
@@ -1,76 +0,0 @@
-import type fsMod from 'node:fs';
-import { dirname, relative } from 'node:path';
-import { fileURLToPath } from 'node:url';
-import { bold } from 'kleur/colors';
-import { normalizePath } from 'vite';
-import type { AstroSettings } from '../../types/astro.js';
-import { AstroError, AstroErrorData } from '../errors/index.js';
-import type { Logger } from '../logger/core.js';
-import { REFERENCE_FILE } from './constants.js';
-
-export async function writeFiles(settings: AstroSettings, fs: typeof fsMod, logger: Logger) {
- try {
- writeInjectedTypes(settings, fs);
- await setUpEnvTs(settings, fs, logger);
- } catch (e) {
- throw new AstroError(AstroErrorData.UnknownFilesystemError, { cause: e });
- }
-}
-
-function getTsReference(type: 'path' | 'types', value: string) {
- return `/// `;
-}
-
-const CLIENT_TYPES_REFERENCE = getTsReference('types', 'astro/client');
-
-function writeInjectedTypes(settings: AstroSettings, fs: typeof fsMod) {
- const references: Array = [];
-
- for (const { filename, content } of settings.injectedTypes) {
- const filepath = fileURLToPath(new URL(filename, settings.dotAstroDir));
- fs.mkdirSync(dirname(filepath), { recursive: true });
- fs.writeFileSync(filepath, content, 'utf-8');
- references.push(normalizePath(relative(fileURLToPath(settings.dotAstroDir), filepath)));
- }
-
- const astroDtsContent = `${CLIENT_TYPES_REFERENCE}\n${references.map((reference) => getTsReference('path', reference)).join('\n')}`;
- if (references.length === 0) {
- fs.mkdirSync(settings.dotAstroDir, { recursive: true });
- }
- fs.writeFileSync(
- fileURLToPath(new URL(REFERENCE_FILE, settings.dotAstroDir)),
- astroDtsContent,
- 'utf-8',
- );
-}
-
-async function setUpEnvTs(settings: AstroSettings, fs: typeof fsMod, logger: Logger) {
- const envTsPath = fileURLToPath(new URL('env.d.ts', settings.config.srcDir));
- const envTsPathRelativetoRoot = relative(fileURLToPath(settings.config.root), envTsPath);
- const relativePath = normalizePath(
- relative(
- fileURLToPath(settings.config.srcDir),
- fileURLToPath(new URL(REFERENCE_FILE, settings.dotAstroDir)),
- ),
- );
- const expectedTypeReference = getTsReference('path', relativePath);
-
- if (fs.existsSync(envTsPath)) {
- const initialEnvContents = await fs.promises.readFile(envTsPath, 'utf-8');
- let typesEnvContents = initialEnvContents;
-
- if (!typesEnvContents.includes(expectedTypeReference)) {
- typesEnvContents = `${expectedTypeReference}\n${typesEnvContents}`;
- }
-
- if (initialEnvContents !== typesEnvContents) {
- logger.info('types', `Updated ${bold(envTsPathRelativetoRoot)} type declarations.`);
- await fs.promises.writeFile(envTsPath, typesEnvContents, 'utf-8');
- }
- } else {
- // Otherwise, inject the `env.d.ts` file
- await fs.promises.mkdir(settings.config.srcDir, { recursive: true });
- await fs.promises.writeFile(envTsPath, expectedTypeReference, 'utf-8');
- logger.info('types', `Added ${bold(envTsPathRelativetoRoot)} type declarations`);
- }
-}
diff --git a/packages/astro/test/astro-sync.test.js b/packages/astro/test/astro-sync.test.js
index ce1345322261..f12fb5bc42ed 100644
--- a/packages/astro/test/astro-sync.test.js
+++ b/packages/astro/test/astro-sync.test.js
@@ -24,10 +24,6 @@ const createFixture = () => {
return astroFixture.config;
},
clean() {
- const envPath = new URL('env.d.ts', astroFixture.config.srcDir);
- if (fs.existsSync(envPath)) {
- fs.unlinkSync(new URL('env.d.ts', astroFixture.config.srcDir));
- }
fs.rmSync(new URL('./.astro/', astroFixture.config.root), { force: true, recursive: true });
},
async whenSyncing() {
@@ -108,40 +104,15 @@ describe('astro sync', () => {
fixture = createFixture();
});
- describe('References', () => {
- it('Writes `src/env.d.ts` if none exists', async () => {
- await fixture.load('./fixtures/astro-basic/');
- fixture.clean();
- await fixture.whenSyncing();
- fixture.thenFileShouldExist('src/env.d.ts');
- fixture.thenFileContentShouldInclude(
- 'src/env.d.ts',
- `/// `,
- );
- });
-
- it('Updates `src/env.d.ts` if one exists', async () => {
- const config = await fixture.load('./fixtures/astro-basic/');
- fixture.clean();
- fs.writeFileSync(new URL('./env.d.ts', config.srcDir), '// whatever', 'utf-8');
- await fixture.whenSyncing();
- fixture.thenFileShouldExist('src/env.d.ts');
- fixture.thenFileContentShouldInclude(
- 'src/env.d.ts',
- `/// `,
- );
- });
-
- it('Writes `src/types.d.ts`', async () => {
- await fixture.load('./fixtures/astro-basic/');
- fixture.clean();
- await fixture.whenSyncing();
- fixture.thenFileShouldExist('.astro/types.d.ts');
- fixture.thenFileContentShouldInclude(
- '.astro/types.d.ts',
- `/// `,
- );
- });
+ it('Writes `.astro/types.d.ts`', async () => {
+ await fixture.load('./fixtures/astro-basic/');
+ fixture.clean();
+ await fixture.whenSyncing();
+ fixture.thenFileShouldExist('.astro/types.d.ts');
+ fixture.thenFileContentShouldInclude(
+ '.astro/types.d.ts',
+ `/// `,
+ );
});
describe('Content collections', () => {
diff --git a/packages/astro/test/fixtures/alias-tsconfig-baseurl-only/tsconfig.json b/packages/astro/test/fixtures/alias-tsconfig-baseurl-only/tsconfig.json
index 738e8a46502e..0c7d303e8e82 100644
--- a/packages/astro/test/fixtures/alias-tsconfig-baseurl-only/tsconfig.json
+++ b/packages/astro/test/fixtures/alias-tsconfig-baseurl-only/tsconfig.json
@@ -1,5 +1,7 @@
{
"compilerOptions": {
"baseUrl": "./src"
- }
+ },
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/packages/astro/test/fixtures/alias-tsconfig/tsconfig.json b/packages/astro/test/fixtures/alias-tsconfig/tsconfig.json
index 52553e7d3002..1598f5fa3174 100644
--- a/packages/astro/test/fixtures/alias-tsconfig/tsconfig.json
+++ b/packages/astro/test/fixtures/alias-tsconfig/tsconfig.json
@@ -13,5 +13,7 @@
"src/*"
]
}
- }
+ },
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/packages/astro/test/fixtures/astro-env-content-collections/tsconfig.json b/packages/astro/test/fixtures/astro-env-content-collections/tsconfig.json
index d78f81ec4e8e..d2e51fb463de 100644
--- a/packages/astro/test/fixtures/astro-env-content-collections/tsconfig.json
+++ b/packages/astro/test/fixtures/astro-env-content-collections/tsconfig.json
@@ -1,3 +1,5 @@
{
- "extends": "astro/tsconfigs/base"
+ "extends": "astro/tsconfigs/base",
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/packages/astro/test/fixtures/astro-env-required-public/tsconfig.json b/packages/astro/test/fixtures/astro-env-required-public/tsconfig.json
index d78f81ec4e8e..d2e51fb463de 100644
--- a/packages/astro/test/fixtures/astro-env-required-public/tsconfig.json
+++ b/packages/astro/test/fixtures/astro-env-required-public/tsconfig.json
@@ -1,3 +1,5 @@
{
- "extends": "astro/tsconfigs/base"
+ "extends": "astro/tsconfigs/base",
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/packages/astro/test/fixtures/astro-env-server-fail/tsconfig.json b/packages/astro/test/fixtures/astro-env-server-fail/tsconfig.json
index d78f81ec4e8e..d2e51fb463de 100644
--- a/packages/astro/test/fixtures/astro-env-server-fail/tsconfig.json
+++ b/packages/astro/test/fixtures/astro-env-server-fail/tsconfig.json
@@ -1,3 +1,5 @@
{
- "extends": "astro/tsconfigs/base"
+ "extends": "astro/tsconfigs/base",
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/packages/astro/test/fixtures/astro-env-server-secret/tsconfig.json b/packages/astro/test/fixtures/astro-env-server-secret/tsconfig.json
index d78f81ec4e8e..d2e51fb463de 100644
--- a/packages/astro/test/fixtures/astro-env-server-secret/tsconfig.json
+++ b/packages/astro/test/fixtures/astro-env-server-secret/tsconfig.json
@@ -1,3 +1,5 @@
{
- "extends": "astro/tsconfigs/base"
+ "extends": "astro/tsconfigs/base",
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/packages/astro/test/fixtures/astro-env/tsconfig.json b/packages/astro/test/fixtures/astro-env/tsconfig.json
index d78f81ec4e8e..d2e51fb463de 100644
--- a/packages/astro/test/fixtures/astro-env/tsconfig.json
+++ b/packages/astro/test/fixtures/astro-env/tsconfig.json
@@ -1,3 +1,5 @@
{
- "extends": "astro/tsconfigs/base"
+ "extends": "astro/tsconfigs/base",
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/packages/astro/test/fixtures/core-image-base/tsconfig.json b/packages/astro/test/fixtures/core-image-base/tsconfig.json
index 923ed4e24fb7..b47976e21c42 100644
--- a/packages/astro/test/fixtures/core-image-base/tsconfig.json
+++ b/packages/astro/test/fixtures/core-image-base/tsconfig.json
@@ -7,5 +7,7 @@
"src/assets/*"
]
},
- }
+ },
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/packages/astro/test/fixtures/core-image-deletion/tsconfig.json b/packages/astro/test/fixtures/core-image-deletion/tsconfig.json
index b5bf6a715eb5..074b459078ff 100644
--- a/packages/astro/test/fixtures/core-image-deletion/tsconfig.json
+++ b/packages/astro/test/fixtures/core-image-deletion/tsconfig.json
@@ -5,5 +5,7 @@
"paths": {
"~/assets/*": ["src/assets/*"]
},
- }
+ },
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/packages/astro/test/fixtures/core-image-infersize/tsconfig.json b/packages/astro/test/fixtures/core-image-infersize/tsconfig.json
index 72b184b171ae..1e6aa1b676cd 100644
--- a/packages/astro/test/fixtures/core-image-infersize/tsconfig.json
+++ b/packages/astro/test/fixtures/core-image-infersize/tsconfig.json
@@ -2,5 +2,7 @@
"extends": "astro/tsconfigs/base",
"compilerOptions": {
"baseUrl": ".",
- }
+ },
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/packages/astro/test/fixtures/core-image-remark-imgattr/tsconfig.json b/packages/astro/test/fixtures/core-image-remark-imgattr/tsconfig.json
index 72b184b171ae..1e6aa1b676cd 100644
--- a/packages/astro/test/fixtures/core-image-remark-imgattr/tsconfig.json
+++ b/packages/astro/test/fixtures/core-image-remark-imgattr/tsconfig.json
@@ -2,5 +2,7 @@
"extends": "astro/tsconfigs/base",
"compilerOptions": {
"baseUrl": ".",
- }
+ },
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/packages/astro/test/fixtures/core-image-ssg/tsconfig.json b/packages/astro/test/fixtures/core-image-ssg/tsconfig.json
index b5bf6a715eb5..074b459078ff 100644
--- a/packages/astro/test/fixtures/core-image-ssg/tsconfig.json
+++ b/packages/astro/test/fixtures/core-image-ssg/tsconfig.json
@@ -5,5 +5,7 @@
"paths": {
"~/assets/*": ["src/assets/*"]
},
- }
+ },
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/packages/astro/test/fixtures/core-image-unconventional-settings/tsconfig.json b/packages/astro/test/fixtures/core-image-unconventional-settings/tsconfig.json
index b5bf6a715eb5..074b459078ff 100644
--- a/packages/astro/test/fixtures/core-image-unconventional-settings/tsconfig.json
+++ b/packages/astro/test/fixtures/core-image-unconventional-settings/tsconfig.json
@@ -5,5 +5,7 @@
"paths": {
"~/assets/*": ["src/assets/*"]
},
- }
+ },
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/packages/astro/test/fixtures/core-image/tsconfig.json b/packages/astro/test/fixtures/core-image/tsconfig.json
index 923ed4e24fb7..b47976e21c42 100644
--- a/packages/astro/test/fixtures/core-image/tsconfig.json
+++ b/packages/astro/test/fixtures/core-image/tsconfig.json
@@ -7,5 +7,7 @@
"src/assets/*"
]
},
- }
+ },
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/packages/astro/test/fixtures/react-and-solid/tsconfig.json b/packages/astro/test/fixtures/react-and-solid/tsconfig.json
index 0b4b89bbce69..d5f1fa6e4c05 100644
--- a/packages/astro/test/fixtures/react-and-solid/tsconfig.json
+++ b/packages/astro/test/fixtures/react-and-solid/tsconfig.json
@@ -3,5 +3,7 @@
"strict": true,
"jsxImportSource": "solid-js",
"types": ["astro/client"]
- }
+ },
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/packages/astro/test/fixtures/ssr-prerender-chunks/tsconfig.json b/packages/astro/test/fixtures/ssr-prerender-chunks/tsconfig.json
index 7fb90fafc062..98ab98bc4c3e 100644
--- a/packages/astro/test/fixtures/ssr-prerender-chunks/tsconfig.json
+++ b/packages/astro/test/fixtures/ssr-prerender-chunks/tsconfig.json
@@ -3,5 +3,7 @@
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "react"
- }
+ },
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
\ No newline at end of file
diff --git a/packages/db/test/fixtures/ticketing-example/tsconfig.json b/packages/db/test/fixtures/ticketing-example/tsconfig.json
index b7243b92ccf8..9d7495d5bac1 100644
--- a/packages/db/test/fixtures/ticketing-example/tsconfig.json
+++ b/packages/db/test/fixtures/ticketing-example/tsconfig.json
@@ -3,5 +3,7 @@
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "react"
- }
+ },
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/packages/integrations/markdoc/test/fixtures/image-assets/tsconfig.json b/packages/integrations/markdoc/test/fixtures/image-assets/tsconfig.json
index b5bf6a715eb5..074b459078ff 100644
--- a/packages/integrations/markdoc/test/fixtures/image-assets/tsconfig.json
+++ b/packages/integrations/markdoc/test/fixtures/image-assets/tsconfig.json
@@ -5,5 +5,7 @@
"paths": {
"~/assets/*": ["src/assets/*"]
},
- }
+ },
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
diff --git a/packages/integrations/markdoc/test/fixtures/render-with-components/tsconfig.json b/packages/integrations/markdoc/test/fixtures/render-with-components/tsconfig.json
index 99df2e61a11d..7c03d38d1fc9 100644
--- a/packages/integrations/markdoc/test/fixtures/render-with-components/tsconfig.json
+++ b/packages/integrations/markdoc/test/fixtures/render-with-components/tsconfig.json
@@ -3,5 +3,7 @@
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "preact"
- }
+ },
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}
\ No newline at end of file
diff --git a/packages/integrations/mdx/test/fixtures/mdx-images/tsconfig.json b/packages/integrations/mdx/test/fixtures/mdx-images/tsconfig.json
index b5bf6a715eb5..074b459078ff 100644
--- a/packages/integrations/mdx/test/fixtures/mdx-images/tsconfig.json
+++ b/packages/integrations/mdx/test/fixtures/mdx-images/tsconfig.json
@@ -5,5 +5,7 @@
"paths": {
"~/assets/*": ["src/assets/*"]
},
- }
+ },
+ "include": ["**/*", ".astro/types.d.ts"],
+ "exclude": ["dist"]
}