diff --git a/.github/workflows/tests-e2e.yml b/.github/workflows/tests-e2e.yml index 1ae61a878c01..dbd9012baf5c 100644 --- a/.github/workflows/tests-e2e.yml +++ b/.github/workflows/tests-e2e.yml @@ -158,18 +158,28 @@ jobs: working-directory: ../test-website env: E2E_TEST: true + - name: TypeCheck website # TODO: there're some lingering issues with PnP + tsc. Enable tsc in PnP later. if: matrix.variant == '-st' && matrix.nodeLinker != 'pnp' working-directory: ../test-website run: yarn typecheck + - name: TypeCheck website - min version - v5.1 # TODO: there're some lingering issues with PnP + tsc. Enable tsc in PnP later. if: matrix.variant == '-st' && matrix.nodeLinker != 'pnp' working-directory: ../test-website run: | yarn add typescript@5.1.6 --exact + + # Downgrade TS ignoreDeprecations option + node -e "const fs = require('fs'); const f = 'tsconfig.json'; fs.writeFileSync(f, fs.readFileSync(f,'utf8').replace('\"ignoreDeprecations\": \"6.0\"', '\"ignoreDeprecations\": \"5.0\"'))" + yarn typecheck + + # Restore TS ignoreDeprecations option + node -e "const fs = require('fs'); const f = 'tsconfig.json'; fs.writeFileSync(f, fs.readFileSync(f,'utf8').replace('\"ignoreDeprecations\": \"5.0\"', '\"ignoreDeprecations\": \"6.0\"'))" + - name: TypeCheck website - max version - Latest # TODO: there're some lingering issues with PnP + tsc. Enable tsc in PnP later. if: matrix.variant == '-st' && matrix.nodeLinker != 'pnp' diff --git a/.github/workflows/tests-windows.yml b/.github/workflows/tests-windows.yml index 69d7a8b7f523..e766abd9cb78 100644 --- a/.github/workflows/tests-windows.yml +++ b/.github/workflows/tests-windows.yml @@ -61,18 +61,23 @@ jobs: - name: TypeCheck website # see https://github.com/facebook/docusaurus/pull/10486 run: yarn workspace website typecheck + + - name: TypeCheck website - max version - Latest + # For latest TS there are often lib check errors, so we disable it + # Details: https://github.com/facebook/docusaurus/pull/10486 + run: | + yarn add typescript@latest --exact -D -W --ignore-scripts + yarn workspace website typecheck --project tsconfig.skipLibCheck.json + - name: TypeCheck website - min version - v5.1 run: | yarn add typescript@5.1.6 --exact -D -W --ignore-scripts + # Downgrade TS ignoreDeprecations option + node -e 'const fs = require("fs"); const f = "website/tsconfig.json"; fs.writeFileSync(f, fs.readFileSync(f, "utf8").replace(/"ignoreDeprecations"\s*:\s*"6\.0"/, "\"ignoreDeprecations\": \"5.0\""));' + # DocSearch@4/ai@5 doesn't support TS 5.1 (with skipLibCheck=false) jq '.resolutions."@docsearch/react" = "^3.9.0"' package.json > package.json.tmp && mv -Force package.json.tmp package.json yarn add @docsearch/react@^3.9.0 --exact -D -W --ignore-scripts yarn workspace website typecheck - - name: TypeCheck website - max version - Latest - # For latest TS there are often lib check errors, so we disable it - # Details: https://github.com/facebook/docusaurus/pull/10486 - run: | - yarn add typescript@latest --exact -D -W --ignore-scripts - yarn workspace website typecheck --project tsconfig.skipLibCheck.json diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 816fcee7b2b2..05e3f3c173f9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -58,15 +58,23 @@ jobs: - name: TypeCheck website # see https://github.com/facebook/docusaurus/pull/10486 run: yarn workspace website typecheck + - name: TypeCheck website - min version - v5.1 run: | yarn add typescript@5.1.6 --exact -D -W --ignore-scripts + # Downgrade TS ignoreDeprecations option + node -e "const fs = require('fs'); const f = 'website/tsconfig.json'; fs.writeFileSync(f, fs.readFileSync(f,'utf8').replace('\"ignoreDeprecations\": \"6.0\"', '\"ignoreDeprecations\": \"5.0\"'))" + # DocSearch@4/ai@5 doesn't support TS 5.1 (with skipLibCheck=false) jq '.resolutions."@docsearch/react" = "^3.9.0"' package.json > package.json.tmp && mv -f package.json.tmp package.json yarn add @docsearch/react@^3.9.0 --exact -D -W --ignore-scripts yarn workspace website typecheck + + # Restore TS ignoreDeprecations option + node -e "const fs = require('fs'); const f = 'website/tsconfig.json'; fs.writeFileSync(f, fs.readFileSync(f,'utf8').replace('\"ignoreDeprecations\": \"5.0\"', '\"ignoreDeprecations\": \"6.0\"'))" + - name: TypeCheck website - max version - Latest # For latest TS there are often lib check errors, so we disable it # Details: https://github.com/facebook/docusaurus/pull/10486 diff --git a/package.json b/package.json index 885b9fc25850..90f0fa334570 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,7 @@ "@types/fs-extra": "^9.0.13", "@types/jest": "^30.0.0", "@types/lodash": "^4.14.197", - "@types/node": "^18.16.19", + "@types/node": "^20.19.37", "@types/prompts": "^2.4.4", "@types/react": "^19.2.10", "@types/semver": "^7.5.0", @@ -128,7 +128,7 @@ "stylelint": "^14.16.1", "stylelint-config-prettier": "^9.0.5", "stylelint-config-standard": "^29.0.0", - "typescript": "~5.8.2" + "typescript": "~6.0.2" }, "resolutions": { "**/pretty-format/react-is": "^19.2.4" diff --git a/packages/create-docusaurus/templates/classic-typescript/package.json b/packages/create-docusaurus/templates/classic-typescript/package.json index aa4d545ffeae..cc9ed3d5b874 100644 --- a/packages/create-docusaurus/templates/classic-typescript/package.json +++ b/packages/create-docusaurus/templates/classic-typescript/package.json @@ -29,7 +29,7 @@ "@docusaurus/tsconfig": "3.9.2", "@docusaurus/types": "3.9.2", "@types/react": "^19.0.0", - "typescript": "~5.6.2" + "typescript": "~6.0.2" }, "browserslist": { "production": [ diff --git a/packages/create-docusaurus/templates/classic-typescript/tsconfig.json b/packages/create-docusaurus/templates/classic-typescript/tsconfig.json index aceae0dd36e4..405d777064cb 100644 --- a/packages/create-docusaurus/templates/classic-typescript/tsconfig.json +++ b/packages/create-docusaurus/templates/classic-typescript/tsconfig.json @@ -5,6 +5,7 @@ "extends": "@docusaurus/tsconfig", "compilerOptions": { "baseUrl": ".", + "ignoreDeprecations": "6.0", "strict": true }, "exclude": [".docusaurus", "build"] diff --git a/packages/docusaurus-logger/src/perfLogger.ts b/packages/docusaurus-logger/src/perfLogger.ts index 2bc94b7730e0..e5e5823afc70 100644 --- a/packages/docusaurus-logger/src/perfLogger.ts +++ b/packages/docusaurus-logger/src/perfLogger.ts @@ -4,7 +4,9 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ -import {AsyncLocalStorage} from 'async_hooks'; + +import {AsyncLocalStorage} from 'node:async_hooks'; +import {type PerformanceMark} from 'node:perf_hooks'; import logger from './logger'; // For now this is a private env variable we use internally diff --git a/packages/docusaurus-plugin-content-blog/tsconfig.client.json b/packages/docusaurus-plugin-content-blog/tsconfig.client.json index be1294f32d10..ad1fa888de1e 100644 --- a/packages/docusaurus-plugin-content-blog/tsconfig.client.json +++ b/packages/docusaurus-plugin-content-blog/tsconfig.client.json @@ -1,5 +1,5 @@ { "extends": "../../tsconfig.base.client.json", "include": ["src/client", "src/*.d.ts"], - "exclude": ["**/__tests__/**"] + "exclude": ["**/__tests__/**", "**/*.test.ts"] } diff --git a/packages/docusaurus-plugin-content-blog/tsconfig.json b/packages/docusaurus-plugin-content-blog/tsconfig.json index 8cec50ee1327..60dfa46f1b9f 100644 --- a/packages/docusaurus-plugin-content-blog/tsconfig.json +++ b/packages/docusaurus-plugin-content-blog/tsconfig.json @@ -5,5 +5,5 @@ "noEmit": false }, "include": ["src"], - "exclude": ["src/client", "**/__tests__/**"] + "exclude": ["src/client", "**/__tests__/**", "**/*.test.ts"] } diff --git a/packages/docusaurus-plugin-content-docs/tsconfig.client.json b/packages/docusaurus-plugin-content-docs/tsconfig.client.json index be1294f32d10..ad1fa888de1e 100644 --- a/packages/docusaurus-plugin-content-docs/tsconfig.client.json +++ b/packages/docusaurus-plugin-content-docs/tsconfig.client.json @@ -1,5 +1,5 @@ { "extends": "../../tsconfig.base.client.json", "include": ["src/client", "src/*.d.ts"], - "exclude": ["**/__tests__/**"] + "exclude": ["**/__tests__/**", "**/*.test.ts"] } diff --git a/packages/docusaurus-plugin-content-docs/tsconfig.json b/packages/docusaurus-plugin-content-docs/tsconfig.json index 8cec50ee1327..60dfa46f1b9f 100644 --- a/packages/docusaurus-plugin-content-docs/tsconfig.json +++ b/packages/docusaurus-plugin-content-docs/tsconfig.json @@ -5,5 +5,5 @@ "noEmit": false }, "include": ["src"], - "exclude": ["src/client", "**/__tests__/**"] + "exclude": ["src/client", "**/__tests__/**", "**/*.test.ts"] } diff --git a/packages/docusaurus-plugin-google-gtag/tsconfig.client.json b/packages/docusaurus-plugin-google-gtag/tsconfig.client.json index 55a83c9a16f4..8ce90029c715 100644 --- a/packages/docusaurus-plugin-google-gtag/tsconfig.client.json +++ b/packages/docusaurus-plugin-google-gtag/tsconfig.client.json @@ -1,5 +1,8 @@ { "extends": "../../tsconfig.base.client.json", + "compilerOptions": { + "types": ["gtag.js"] + }, "include": ["src/gtag.ts", "src/*.d.ts"], "exclude": ["**/__tests__/**"] } diff --git a/packages/docusaurus-plugin-pwa/tsconfig.worker.json b/packages/docusaurus-plugin-pwa/tsconfig.worker.json index d649d9cfe6d7..7270da1d425e 100644 --- a/packages/docusaurus-plugin-pwa/tsconfig.worker.json +++ b/packages/docusaurus-plugin-pwa/tsconfig.worker.json @@ -6,8 +6,7 @@ "tsBuildInfoFile": "lib/.tsbuildinfo-worker", "moduleResolution": "bundler", "module": "esnext", - "target": "esnext", - "types": ["node"] + "target": "esnext" }, "include": ["src/sw.ts"], "exclude": ["**/__tests__/**"] diff --git a/packages/docusaurus/package.json b/packages/docusaurus/package.json index 4d683ccc7b7c..2f348c658485 100644 --- a/packages/docusaurus/package.json +++ b/packages/docusaurus/package.json @@ -86,6 +86,7 @@ "@types/serve-handler": "^6.1.4", "@types/update-notifier": "^6.0.4", "@types/webpack-bundle-analyzer": "^4.7.0", + "@types/webpack-env": "^1.18.8", "tmp-promise": "^3.0.3", "tree-node-cli": "^1.6.0" }, diff --git a/packages/docusaurus/src/client/clientEntry.tsx b/packages/docusaurus/src/client/clientEntry.tsx index eb2f67368a20..db521bb39f50 100644 --- a/packages/docusaurus/src/client/clientEntry.tsx +++ b/packages/docusaurus/src/client/clientEntry.tsx @@ -23,12 +23,6 @@ function Router({children}: {children: ReactNode}): ReactNode { ); } -declare global { - interface NodeModule { - hot?: {accept: () => void}; - } -} - const hydrate = Boolean(process.env.HYDRATE_CLIENT_ENTRY); // Client-side render (e.g: running in browser) to become single-page diff --git a/packages/docusaurus/src/client/docusaurus.ts b/packages/docusaurus/src/client/docusaurus.ts index 79bb4e21c779..24dff371728b 100644 --- a/packages/docusaurus/src/client/docusaurus.ts +++ b/packages/docusaurus/src/client/docusaurus.ts @@ -16,8 +16,7 @@ const fetched = new Set(); const loaded = new Set(); declare global { - // eslint-disable-next-line camelcase, no-underscore-dangle - const __webpack_require__: {gca: (name: string) => string}; + // See https://github.com/microsoft/TypeScript/issues/56962 interface Navigator { connection?: {effectiveType: string; saveData: boolean}; } diff --git a/packages/docusaurus/src/client/exports/ComponentCreator.tsx b/packages/docusaurus/src/client/exports/ComponentCreator.tsx index 48d6640385b7..b5e70812b594 100644 --- a/packages/docusaurus/src/client/exports/ComponentCreator.tsx +++ b/packages/docusaurus/src/client/exports/ComponentCreator.tsx @@ -14,12 +14,6 @@ import flat from '../flat'; import {RouteContextProvider} from '../routeContext'; import type {RouteContext} from '@docusaurus/types'; -declare global { - interface NodeRequire { - resolveWeak: (name: string) => number; - } -} - export default function ComponentCreator( path: string, hash: string, diff --git a/packages/docusaurus/src/server/i18n.ts b/packages/docusaurus/src/server/i18n.ts index 8a80f4e6486f..3b0dab396d9f 100644 --- a/packages/docusaurus/src/server/i18n.ts +++ b/packages/docusaurus/src/server/i18n.ts @@ -64,7 +64,6 @@ function getDefaultCalendar(localeStr: string) { // See https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCalendars // See https://caniuse.com/mdn-javascript_builtins_intl_locale_getcalendars const calendars = - // @ts-expect-error: new std method (Bun/JSC/WebKit) locale.getCalendars?.() ?? // @ts-expect-error: non-std attribute (V8/Chromium/Node) locale.calendars; @@ -84,7 +83,7 @@ function getDefaultDirection(localeStr: string) { // TODO Docusaurus v4: remove the fallback to locale.textInfo // @ts-expect-error: The TC39 proposal was updated const textInto = locale.getTextInfo?.() ?? locale.textInfo; - return textInto.direction; + return textInto.direction ?? 'ltr'; } export function getDefaultLocaleConfig( diff --git a/packages/docusaurus/tsconfig.client.json b/packages/docusaurus/tsconfig.client.json index be1294f32d10..e9f8e88e5fd9 100644 --- a/packages/docusaurus/tsconfig.client.json +++ b/packages/docusaurus/tsconfig.client.json @@ -1,5 +1,8 @@ { "extends": "../../tsconfig.base.client.json", "include": ["src/client", "src/*.d.ts"], - "exclude": ["**/__tests__/**"] + "exclude": ["**/__tests__/**"], + "compilerOptions": { + "types": ["node", "webpack-env"] + } } diff --git a/tsconfig.base.client.json b/tsconfig.base.client.json index ae15d13c915e..bd02813b86a4 100644 --- a/tsconfig.base.client.json +++ b/tsconfig.base.client.json @@ -2,9 +2,11 @@ "extends": "./tsconfig.base.json", "compilerOptions": { "tsBuildInfoFile": "${configDir}/lib/.tsbuildinfo-client", + "lib": ["DOM", "ESNext"], "noEmit": false, "moduleResolution": "bundler", "module": "esnext", - "target": "esnext" + "target": "esnext", + "types": [] } } diff --git a/tsconfig.base.json b/tsconfig.base.json index 247a84af9df5..43b39e34593a 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -6,6 +6,7 @@ "incremental": true, "tsBuildInfoFile": "${configDir}/lib/.tsbuildinfo", "erasableSyntaxOnly": true, + "types": ["node"], /* Emit */ "target": "ES2020", "lib": ["ESNext"], diff --git a/website/tsconfig.json b/website/tsconfig.json index caea2e3443e5..22c38a19eb6c 100644 --- a/website/tsconfig.json +++ b/website/tsconfig.json @@ -4,6 +4,7 @@ "compilerOptions": { "lib": ["DOM", "ESNext"], "baseUrl": ".", + "ignoreDeprecations": "6.0", "resolveJsonModule": true, "allowArbitraryExtensions": true, diff --git a/yarn.lock b/yarn.lock index 769b4e0691bf..c39ff43d5bc5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4587,12 +4587,12 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.45.tgz#2c0fafd78705e7a18b7906b5201a522719dc5190" integrity sha512-w+tIMs3rq2afQdsPJlODhoUEKzFP1ayaoyl1CcnwtIlsVe7K7bA1NGm4s3PraqTLlXnbIN84zuBlxBWo1u9BLw== -"@types/node@^18.16.19": - version "18.19.59" - resolved "https://registry.yarnpkg.com/@types/node/-/node-18.19.59.tgz#2de1b95b0b468089b616b2feb809755d70a74949" - integrity sha512-vizm2EqwV/7Zay+A6J3tGl9Lhr7CjZe2HmWS988sefiEmsyP9CeXEleho6i4hJk/8UtZAo0bWN4QPZZr83RxvQ== +"@types/node@^20.19.37": + version "20.19.37" + resolved "https://registry.yarnpkg.com/@types/node/-/node-20.19.37.tgz#b4fb4033408dd97becce63ec932c9ec57a9e2919" + integrity sha512-8kzdPJ3FsNsVIurqBs7oodNnCEVbni9yUEkaHbgptDACOPW04jimGagZ51E6+lXUwJjgnBw+hyko/lkFWCldqw== dependencies: - undici-types "~5.26.4" + undici-types "~6.21.0" "@types/normalize-package-data@^2.4.0": version "2.4.1" @@ -4826,6 +4826,11 @@ tapable "^2.2.0" webpack "^5" +"@types/webpack-env@^1.18.8": + version "1.18.8" + resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.18.8.tgz#71f083718c094204d7b64443701d32f1db3989e3" + integrity sha512-G9eAoJRMLjcvN4I08wB5I7YofOb/kaJNd5uoCMX+LbKXTPCF+ZIHuqTnFaK9Jz1rgs035f9JUPUhNFtqgucy/A== + "@types/webpack-sources@*": version "3.2.3" resolved "https://registry.yarnpkg.com/@types/webpack-sources/-/webpack-sources-3.2.3.tgz#b667bd13e9fa15a9c26603dce502c7985418c3d8" @@ -17876,15 +17881,10 @@ typedarray@^0.0.6: resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.9.3.tgz#5b4f59e15310ab17a216f5d6cf53ee476ede670f" integrity sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw== -typescript@~5.6.2: - version "5.6.3" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.6.3.tgz#5f3449e31c9d94febb17de03cc081dd56d81db5b" - integrity sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw== - -typescript@~5.8.2: - version "5.8.2" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.8.2.tgz#8170b3702f74b79db2e5a96207c15e65807999e4" - integrity sha512-aJn6wq13/afZp/jT9QZmwEjDqqvSGp1VT5GVg+f/t6/oVyrgXM6BY1h9BRh/O5p3PlUPAe+WuiEZOmb/49RqoQ== +typescript@~6.0.2: + version "6.0.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-6.0.2.tgz#0b1bfb15f68c64b97032f3d78abbf98bdbba501f" + integrity sha512-bGdAIrZ0wiGDo5l8c++HWtbaNCWTS4UTv7RaTH/ThVIgjkveJt83m74bBHMJkuCbslY8ixgLBVZJIOiQlQTjfQ== ufo@^1.5.4: version "1.6.0" @@ -17906,16 +17906,16 @@ unbox-primitive@^1.0.2: has-symbols "^1.0.3" which-boxed-primitive "^1.0.2" -undici-types@~5.26.4: - version "5.26.5" - resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617" - integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA== - undici-types@~6.19.2: version "6.19.8" resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.19.8.tgz#35111c9d1437ab83a7cdc0abae2f26d88eda0a02" integrity sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw== +undici-types@~6.21.0: + version "6.21.0" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.21.0.tgz#691d00af3909be93a7faa13be61b3a5b50ef12cb" + integrity sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ== + unicode-canonical-property-names-ecmascript@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-2.0.1.tgz#cb3173fe47ca743e228216e4a3ddc4c84d628cc2"