diff --git a/.github/scripts/tsconfig.json b/.github/scripts/tsconfig.json index 2529f53ec0ef..73c65eec211a 100644 --- a/.github/scripts/tsconfig.json +++ b/.github/scripts/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../../tsconfig.base.json", + "extends": "../../configs/tsconfig.base.json", "compilerOptions": { "composite": true, "allowJs": true diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6de1ff9aee0c..43082d5c39e7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -140,8 +140,8 @@ jobs: - name: Lint publish code run: pnpm run publint - - name: Type-check test files - run: pnpm run typecheck:tests + - name: Type-check files + run: pnpm run typecheck test: name: 'Test (${{ matrix.TEST_SUITE.name }}): ${{ matrix.os }} (node@${{ matrix.NODE_VERSION }})' diff --git a/benchmark/packages/adapter/tsconfig.json b/benchmark/packages/adapter/tsconfig.json index 7f8d5c4c2184..9c68e9d49b08 100644 --- a/benchmark/packages/adapter/tsconfig.json +++ b/benchmark/packages/adapter/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../../../tsconfig.base.json", + "extends": "../../../configs/tsconfig.base.json", "include": ["src"], "compilerOptions": { "rootDir": "./src", diff --git a/benchmark/packages/timer/tsconfig.json b/benchmark/packages/timer/tsconfig.json index 7f8d5c4c2184..9c68e9d49b08 100644 --- a/benchmark/packages/timer/tsconfig.json +++ b/benchmark/packages/timer/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../../../tsconfig.base.json", + "extends": "../../../configs/tsconfig.base.json", "include": ["src"], "compilerOptions": { "rootDir": "./src", diff --git a/tsconfig.base.json b/configs/tsconfig.base.json similarity index 64% rename from tsconfig.base.json rename to configs/tsconfig.base.json index 1600925b31ce..39d164af7e45 100644 --- a/tsconfig.base.json +++ b/configs/tsconfig.base.json @@ -1,9 +1,12 @@ { "$schema": "https://json.schemastore.org/tsconfig", "compilerOptions": { + "composite": true, "declaration": true, "emitDeclarationOnly": true, "strict": true, + "allowJs": true, + "forceConsistentCasingInFileNames": true, "moduleResolution": "nodenext", "target": "esnext", "module": "nodenext", @@ -14,7 +17,8 @@ "noUnusedLocals": true, "noUnusedParameters": true, "erasableSyntaxOnly": true, - "outDir": "${configDir}/node_modules/.cache/tsconfig/out", + // Emit declaration and cache files to a directory that would be ignored by tools like Git and ESLint. + "outDir": "${configDir}/node_modules/.cache/ts_base/out", "types": ["node"] } } diff --git a/configs/tsconfig.build.json b/configs/tsconfig.build.json new file mode 100644 index 000000000000..5772e9670b57 --- /dev/null +++ b/configs/tsconfig.build.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "extends": "./tsconfig.base.json", + "compilerOptions": { + "rootDir": "${configDir}/src", + "outDir": "${configDir}/dist", + // `._cache/` is ignored when publishing to NPM registry, so it's a safe place to put build artifacts that we don't want to publish. + // See https://docs.npmjs.com/cli/v10/configuring-npm/package-json#files + "tsBuildInfoFile": "${configDir}/dist/._cache/ts_build/build.tsbuildinfo" + }, + "include": ["${configDir}/src"] +} diff --git a/packages/language-tools/tsconfig.json b/configs/tsconfig.language-tools.json similarity index 55% rename from packages/language-tools/tsconfig.json rename to configs/tsconfig.language-tools.json index 83a96ac9ee32..5c388d86979c 100644 --- a/packages/language-tools/tsconfig.json +++ b/configs/tsconfig.language-tools.json @@ -1,15 +1,13 @@ { + "$schema": "https://json.schemastore.org/tsconfig", + "extends": "./tsconfig.build.json", "compilerOptions": { "target": "ES2021", "lib": ["WebWorker", "ES2021"], "module": "commonjs", // TODO: when upgrading to TS 6, will need to be set to "bundler" "moduleResolution": "node", - "declaration": true, - "emitDeclarationOnly": true, - "strict": true, - "esModuleInterop": true, - "skipLibCheck": true, - "forceConsistentCasingInFileNames": true + "verbatimModuleSyntax": false, + "erasableSyntaxOnly": false } } diff --git a/configs/tsconfig.test.json b/configs/tsconfig.test.json new file mode 100644 index 000000000000..3d43c022cb1e --- /dev/null +++ b/configs/tsconfig.test.json @@ -0,0 +1,13 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "extends": "./tsconfig.base.json", + "compilerOptions": { + "rootDir": "${configDir}", + "noUnusedLocals": false, + "noUnusedParameters": false, + "allowImportingTsExtensions": true, + "outDir": "${configDir}/node_modules/.cache/ts_test/out" + }, + "include": ["${configDir}/test/**/*"], + "exclude": ["${configDir}/test/fixtures/**/*"] +} diff --git a/knip.js b/knip.js index 12e1efcf7afa..09c35626ae9b 100644 --- a/knip.js +++ b/knip.js @@ -1,4 +1,6 @@ // @ts-check +const srcEntry = 'src/**/*.{js,ts,cts}'; +const dtsEntry = '*.d.ts'; const testEntry = 'test/**/*.test.{js,ts}'; /** @type {import('knip').KnipConfig} */ @@ -24,12 +26,14 @@ export default { entry: ['.flue/agents/*.ts', '.flue/workflows/*/WORKFLOW.ts'], }, 'packages/*': { - entry: [testEntry], + entry: [srcEntry, dtsEntry, testEntry], }, 'packages/astro': { entry: [ // Can't be detected automatically since it's only in package.json#files 'templates/**/*', + srcEntry, + dtsEntry, testEntry, 'test/types/**/*', 'e2e/**/*.test.{js,ts}', @@ -53,37 +57,30 @@ export default { 'rehype-toc', 'remark-code-titles', '@types/http-cache-semantics', - // Dynamically imported by astro add cloudflare - '@astrojs/cloudflare', ], }, 'packages/db': { - entry: [testEntry, 'test/types/**/*'], + entry: [srcEntry, dtsEntry, testEntry, 'test/types/**/*'], }, 'packages/integrations/*': { - entry: [testEntry], + entry: [srcEntry, dtsEntry, testEntry], }, 'packages/integrations/cloudflare': { - entry: [testEntry], + entry: [srcEntry, dtsEntry, testEntry], // False positive because of cloudflare:workers ignoreDependencies: ['cloudflare'], }, - 'packages/integrations/mdx': { - entry: [testEntry], - // Required but not imported directly - ignoreDependencies: ['@types/*'], - }, 'packages/integrations/netlify': { - entry: [testEntry], + entry: [srcEntry, dtsEntry, testEntry], ignore: ['test/hosted/**'], }, 'packages/integrations/solid': { - entry: [testEntry], + entry: [srcEntry, dtsEntry, testEntry], // It's an optional peer dep (triggers a warning) but it's fine in this case ignoreDependencies: ['solid-devtools'], }, 'packages/markdown/remark': { - entry: [testEntry], + entry: [srcEntry, dtsEntry, testEntry], // package.json#imports are not resolved at the moment ignore: ['src/import-plugin-browser.ts', 'src/shiki-engine-workerd.ts'], }, diff --git a/package.json b/package.json index 74b59aef1d85..21f9374ba832 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "test:e2e": "cd packages/astro && pnpm playwright install firefox && pnpm run test:e2e", "test:e2e:match": "cd packages/astro && pnpm playwright install firefox && pnpm run test:e2e:match", "test:e2e:hosts": "turbo run test:hosted", - "typecheck:tests": "pnpm -r run --sequential typecheck:tests", + "typecheck": "tsc -b", "benchmark": "astro-benchmark", "lint": "biome lint && knip && eslint . --report-unused-disable-directives-severity=warn --concurrency=auto", "lint:ci": "knip && pnpm run eslint:ci", diff --git a/packages/astro-prism/package.json b/packages/astro-prism/package.json index 5a7c3ced874a..2486ec08732a 100644 --- a/packages/astro-prism/package.json +++ b/packages/astro-prism/package.json @@ -14,7 +14,7 @@ "homepage": "https://docs.astro.build/en/reference/api-reference/#prism-", "main": "dist/index.js", "scripts": { - "build": "astro-scripts build \"src/**/*.ts\" && tsc -p ./tsconfig.json", + "build": "astro-scripts build \"src/**/*.ts\" && tsc -b", "build:ci": "astro-scripts build \"src/**/*.ts\"", "dev": "astro-scripts dev \"src/**/*.ts\"" }, diff --git a/packages/astro-prism/tsconfig.build.json b/packages/astro-prism/tsconfig.build.json new file mode 100644 index 000000000000..79fbbc66db11 --- /dev/null +++ b/packages/astro-prism/tsconfig.build.json @@ -0,0 +1,3 @@ +{ + "extends": "../../configs/tsconfig.build.json" +} diff --git a/packages/astro-prism/tsconfig.json b/packages/astro-prism/tsconfig.json index 17e08031358c..585d16fe2f3c 100644 --- a/packages/astro-prism/tsconfig.json +++ b/packages/astro-prism/tsconfig.json @@ -1,8 +1,5 @@ { - "extends": "../../tsconfig.base.json", - "include": ["src"], - "compilerOptions": { - "rootDir": "./src", - "outDir": "./dist" - } + "extends": "../../configs/tsconfig.base.json", + "files": [], + "references": [{ "path": "./tsconfig.build.json" }] } diff --git a/packages/astro-rss/package.json b/packages/astro-rss/package.json index ef76cd050187..a74e5410b33c 100644 --- a/packages/astro-rss/package.json +++ b/packages/astro-rss/package.json @@ -21,11 +21,10 @@ "dist" ], "scripts": { - "build": "astro-scripts build \"src/**/*.ts\" && tsc", + "build": "astro-scripts build \"src/**/*.ts\" && tsc -b", "build:ci": "astro-scripts build \"src/**/*.ts\"", "dev": "astro-scripts dev \"src/**/*.ts\"", - "test": "astro-scripts test \"test/**/*.test.ts\"", - "typecheck:tests": "tsc --build tsconfig.test.json" + "test": "astro-scripts test \"test/**/*.test.ts\"" }, "devDependencies": { "@types/xml2js": "^0.4.14", diff --git a/packages/astro-rss/tsconfig.build.json b/packages/astro-rss/tsconfig.build.json new file mode 100644 index 000000000000..79fbbc66db11 --- /dev/null +++ b/packages/astro-rss/tsconfig.build.json @@ -0,0 +1,3 @@ +{ + "extends": "../../configs/tsconfig.build.json" +} diff --git a/packages/astro-rss/tsconfig.json b/packages/astro-rss/tsconfig.json index 17e08031358c..64908093d2fe 100644 --- a/packages/astro-rss/tsconfig.json +++ b/packages/astro-rss/tsconfig.json @@ -1,8 +1,5 @@ { - "extends": "../../tsconfig.base.json", - "include": ["src"], - "compilerOptions": { - "rootDir": "./src", - "outDir": "./dist" - } + "extends": "../../configs/tsconfig.base.json", + "files": [], + "references": [{ "path": "./tsconfig.build.json" }, { "path": "./tsconfig.test.json" }] } diff --git a/packages/astro-rss/tsconfig.test.json b/packages/astro-rss/tsconfig.test.json index 7d6bc4428b35..9ca68b5a3d26 100644 --- a/packages/astro-rss/tsconfig.test.json +++ b/packages/astro-rss/tsconfig.test.json @@ -1,12 +1,4 @@ { - "extends": "../../tsconfig.base.json", - "include": ["test/**/*.ts"], - "exclude": ["test/fixtures/**"], - "compilerOptions": { - "allowJs": true, - "noUnusedLocals": false, - "noUnusedParameters": false, - "rewriteRelativeImportExtensions": true - }, - "references": [{ "path": "../astro/tsconfig.test.json" }] + "extends": "../../configs/tsconfig.test.json", + "references": [{ "path": "./tsconfig.build.json" }] } diff --git a/packages/astro/components/tsconfig.json b/packages/astro/components/tsconfig.json index 71b1925eb046..34dadb4719a4 100644 --- a/packages/astro/components/tsconfig.json +++ b/packages/astro/components/tsconfig.json @@ -1,9 +1,8 @@ { - "extends": "../../../tsconfig.base.json", + "extends": "../../../configs/tsconfig.base.json", "compilerOptions": { - "allowJs": true, "emitDeclarationOnly": false, - "noEmit": true, "jsx": "preserve" - } + }, + "references": [{ "path": "../tsconfig.build.json" }] } diff --git a/packages/astro/package.json b/packages/astro/package.json index 5c435735c2a1..adb3ba4daa10 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -112,7 +112,7 @@ ], "scripts": { "prebuild": "astro-scripts prebuild --to-string \"src/runtime/server/astro-island.ts\" \"src/runtime/client/{idle,load,media,only,visible}.ts\"", - "build": "pnpm run prebuild && astro-scripts build \"src/**/*.{ts,js}\" --copy-wasm && tsc && astro-check -- -- --root ./components", + "build": "pnpm run prebuild && astro-scripts build \"src/**/*.{ts,js}\" --copy-wasm && tsc -b && astro-check -- -- --root ./components", "build:ci": "pnpm run prebuild && astro-scripts build \"src/**/*.{ts,js}\" --copy-wasm", "dev": "astro-scripts dev --copy-wasm --prebuild \"src/runtime/server/astro-island.ts\" --prebuild \"src/runtime/client/{idle,load,media,only,visible}.ts\" \"src/**/*.{ts,js}\"", "test": "pnpm run test:unit && pnpm run test:integration && pnpm run test:types", @@ -123,7 +123,6 @@ "test:e2e:chrome": "playwright test", "test:e2e:firefox": "playwright test --config playwright.firefox.config.js", "test:types": "tsc --build test/types/tsconfig.json", - "typecheck:tests": "tsc --build tsconfig.test.json", "test:unit": "astro-scripts test \"test/units/**/*.test.ts\" --strip-types --teardown ./test/units/teardown.ts", "test:integration": "pnpm run test:integration:js && pnpm run test:integration:ts", "test:integration:js": "astro-scripts test \"test/*.test.js\"", diff --git a/packages/astro/src/cli/check/index.ts b/packages/astro/src/cli/check/index.ts index b6fa06f6cf76..06cab5ec7d57 100644 --- a/packages/astro/src/cli/check/index.ts +++ b/packages/astro/src/cli/check/index.ts @@ -3,7 +3,7 @@ import { ensureProcessNodeEnv } from '../../core/util.js'; import { createLoggerFromFlags, type Flags, flagsToAstroInlineConfig } from '../flags.js'; import { getPackage } from '../install-package.js'; -export async function check(flags: Flags) { +export async function check(flags: Flags): Promise { ensureProcessNodeEnv('production'); const logger = createLoggerFromFlags(flags); const getPackageOpts = { diff --git a/packages/astro/src/types/public/config.ts b/packages/astro/src/types/public/config.ts index 1dd35ea050f5..17414659494d 100644 --- a/packages/astro/src/types/public/config.ts +++ b/packages/astro/src/types/public/config.ts @@ -1411,7 +1411,7 @@ export interface AstroUserConfig< * * ```js title="astro.config.mjs" * import { defineConfig, sessionDrivers } from 'astro/config'; - + * * export default defineConfig({ * session: { * driver: sessionDrivers.redis({ diff --git a/packages/astro/test/alias-path-alias-style.test.js b/packages/astro/test/alias-path-alias-style.test.ts similarity index 94% rename from packages/astro/test/alias-path-alias-style.test.js rename to packages/astro/test/alias-path-alias-style.test.ts index 52b4ede479ce..459a23b7f715 100644 --- a/packages/astro/test/alias-path-alias-style.test.js +++ b/packages/astro/test/alias-path-alias-style.test.ts @@ -1,12 +1,12 @@ import assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; import * as cheerio from 'cheerio'; -import { loadFixture } from './test-utils.ts'; +import { type Fixture, loadFixture } from './test-utils.ts'; // Regression test for https://github.com/withastro/astro/issues/15963 //