diff --git a/admin/scripts/test-release.sh b/admin/scripts/test-release.sh index 53bbb868b1c4..942043436cb0 100755 --- a/admin/scripts/test-release.sh +++ b/admin/scripts/test-release.sh @@ -10,7 +10,7 @@ set -xeuo pipefail rm -rf ../test-website CUSTOM_REGISTRY_URL="http://localhost:4873" -NEW_VERSION="$(node -p "require('./packages/docusaurus/package.json').version")-NEW" +NEW_VERSION="$(node -p "require('./packages/docusaurus/package.json').version")-NEW-$RANDOM" CONTAINER_NAME="verdaccio" EXTRA_OPTS="" diff --git a/packages/create-docusaurus/templates/classic-typescript/package.json b/packages/create-docusaurus/templates/classic-typescript/package.json index a6b52a1aa5ed..aa4d545ffeae 100644 --- a/packages/create-docusaurus/templates/classic-typescript/package.json +++ b/packages/create-docusaurus/templates/classic-typescript/package.json @@ -16,6 +16,7 @@ }, "dependencies": { "@docusaurus/core": "3.9.2", + "@docusaurus/faster": "3.9.2", "@docusaurus/preset-classic": "3.9.2", "@mdx-js/react": "^3.0.0", "clsx": "^2.0.0", diff --git a/packages/create-docusaurus/templates/classic/package.json b/packages/create-docusaurus/templates/classic/package.json index 549f25cff334..1152abb056d8 100644 --- a/packages/create-docusaurus/templates/classic/package.json +++ b/packages/create-docusaurus/templates/classic/package.json @@ -15,6 +15,7 @@ }, "dependencies": { "@docusaurus/core": "3.9.2", + "@docusaurus/faster": "3.9.2", "@docusaurus/preset-classic": "3.9.2", "@mdx-js/react": "^3.0.0", "clsx": "^2.0.0", diff --git a/packages/docusaurus-bundler/src/currentBundler.ts b/packages/docusaurus-bundler/src/currentBundler.ts index d0bf5607e934..3d78005dda71 100644 --- a/packages/docusaurus-bundler/src/currentBundler.ts +++ b/packages/docusaurus-bundler/src/currentBundler.ts @@ -16,15 +16,12 @@ import type {CurrentBundler, DocusaurusConfig} from '@docusaurus/types'; // We inject a site config slice because the Rspack flag might change place type SiteConfigSlice = { future: { - experimental_faster: Pick< - DocusaurusConfig['future']['experimental_faster'], - 'rspackBundler' - >; + faster: Pick; }; }; function isRspack(siteConfig: SiteConfigSlice): boolean { - return siteConfig.future.experimental_faster.rspackBundler; + return siteConfig.future.faster.rspackBundler; } export async function getCurrentBundler({ diff --git a/packages/docusaurus-bundler/src/loaders/__tests__/jsLoader.test.ts b/packages/docusaurus-bundler/src/loaders/__tests__/jsLoader.test.ts index a3c7ea43e492..389cce042c68 100644 --- a/packages/docusaurus-bundler/src/loaders/__tests__/jsLoader.test.ts +++ b/packages/docusaurus-bundler/src/loaders/__tests__/jsLoader.test.ts @@ -25,8 +25,8 @@ describe('createJsLoaderFactory', () => { webpack: siteConfig?.webpack, future: fromPartial({ ...siteConfig?.future, - experimental_faster: fromPartial({ - ...siteConfig?.future?.experimental_faster, + faster: fromPartial({ + ...siteConfig?.future?.faster, }), }), }, @@ -71,7 +71,7 @@ describe('createJsLoaderFactory', () => { await expect(() => testJsLoaderFactory({ future: { - experimental_faster: { + faster: { swcJsLoader: true, }, }, @@ -82,10 +82,10 @@ describe('createJsLoaderFactory', () => { }, }), ).rejects.toThrowErrorMatchingInlineSnapshot(` - "You can't use siteConfig.webpack.jsLoader and siteConfig.future.experimental_faster.swcJsLoader at the same time. + "You can't use siteConfig.webpack.jsLoader and siteConfig.future.faster.swcJsLoader at the same time. To avoid any configuration ambiguity, you must make an explicit choice: - If you want to use Docusaurus Faster and SWC (recommended), remove siteConfig.webpack.jsLoader - - If you want to use a custom JS loader, use siteConfig.future.experimental_faster.swcJsLoader: false" + - If you want to use a custom JS loader, use siteConfig.future.faster.swcJsLoader: false" `); }); diff --git a/packages/docusaurus-bundler/src/loaders/jsLoader.ts b/packages/docusaurus-bundler/src/loaders/jsLoader.ts index 51d749ce640a..b60f817a1559 100644 --- a/packages/docusaurus-bundler/src/loaders/jsLoader.ts +++ b/packages/docusaurus-bundler/src/loaders/jsLoader.ts @@ -56,19 +56,19 @@ export async function createJsLoaderFactory({ siteConfig: { webpack?: DocusaurusConfig['webpack']; future: { - experimental_faster: DocusaurusConfig['future']['experimental_faster']; + faster: DocusaurusConfig['future']['faster']; }; }; }): Promise { const currentBundler = await getCurrentBundler({siteConfig}); - const isSWCLoader = siteConfig.future.experimental_faster.swcJsLoader; + const isSWCLoader = siteConfig.future.faster.swcJsLoader; if (isSWCLoader) { if (siteConfig.webpack?.jsLoader) { throw new Error( - `You can't use siteConfig.webpack.jsLoader and siteConfig.future.experimental_faster.swcJsLoader at the same time. + `You can't use siteConfig.webpack.jsLoader and siteConfig.future.faster.swcJsLoader at the same time. To avoid any configuration ambiguity, you must make an explicit choice: - If you want to use Docusaurus Faster and SWC (recommended), remove siteConfig.webpack.jsLoader -- If you want to use a custom JS loader, use siteConfig.future.experimental_faster.swcJsLoader: false`, +- If you want to use a custom JS loader, use siteConfig.future.faster.swcJsLoader: false`, ); } return currentBundler.name === 'rspack' diff --git a/packages/docusaurus-plugin-content-blog/src/index.ts b/packages/docusaurus-plugin-content-blog/src/index.ts index 53fe1a5a05f0..fd5e4d4eed42 100644 --- a/packages/docusaurus-plugin-content-blog/src/index.ts +++ b/packages/docusaurus-plugin-content-blog/src/index.ts @@ -118,8 +118,7 @@ export default async function pluginContentBlog( const contentDirs = getContentPathList(contentPaths); const mdxLoaderItem = await createMDXLoaderItem({ - useCrossCompilerCache: - siteConfig.future.experimental_faster.mdxCrossCompilerCache, + useCrossCompilerCache: siteConfig.future.faster.mdxCrossCompilerCache, admonitions, remarkPlugins, rehypePlugins, diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts b/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts index 26594bc95daf..61c863f7de6f 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts @@ -330,7 +330,7 @@ describe('simple website', () => { configureWebpackUtils: await createConfigureWebpackUtils({ siteConfig: { webpack: {jsLoader: 'babel'}, - future: {experimental_faster: fromPartial({})}, + future: {faster: fromPartial({})}, }, }), content, diff --git a/packages/docusaurus-plugin-content-docs/src/index.ts b/packages/docusaurus-plugin-content-docs/src/index.ts index 317dadbad08f..90975eff9860 100644 --- a/packages/docusaurus-plugin-content-docs/src/index.ts +++ b/packages/docusaurus-plugin-content-docs/src/index.ts @@ -131,8 +131,7 @@ export default async function pluginContentDocs( }), ].filter((d): d is string => typeof d === 'string'), - useCrossCompilerCache: - siteConfig.future.experimental_faster.mdxCrossCompilerCache, + useCrossCompilerCache: siteConfig.future.faster.mdxCrossCompilerCache, admonitions: options.admonitions, remarkPlugins, rehypePlugins, diff --git a/packages/docusaurus-plugin-content-pages/src/index.ts b/packages/docusaurus-plugin-content-pages/src/index.ts index 3d250894d876..9b6c770d348f 100644 --- a/packages/docusaurus-plugin-content-pages/src/index.ts +++ b/packages/docusaurus-plugin-content-pages/src/index.ts @@ -58,8 +58,7 @@ export default async function pluginContentPages( // Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970 .map(addTrailingPathSeparator), options: { - useCrossCompilerCache: - siteConfig.future.experimental_faster.mdxCrossCompilerCache, + useCrossCompilerCache: siteConfig.future.faster.mdxCrossCompilerCache, admonitions, remarkPlugins, rehypePlugins, diff --git a/packages/docusaurus-plugin-pwa/src/index.ts b/packages/docusaurus-plugin-pwa/src/index.ts index fd0aa6d56f84..643a069af958 100644 --- a/packages/docusaurus-plugin-pwa/src/index.ts +++ b/packages/docusaurus-plugin-pwa/src/index.ts @@ -157,7 +157,7 @@ export default function pluginPWA( minimizer: debug ? [] : await getMinimizers({ - faster: props.siteConfig.future.experimental_faster, + faster: props.siteConfig.future.faster, currentBundler: props.currentBundler, }), }, diff --git a/packages/docusaurus-types/src/config.d.ts b/packages/docusaurus-types/src/config.d.ts index 0ce567b4a20e..b6d3d8a0a396 100644 --- a/packages/docusaurus-types/src/config.d.ts +++ b/packages/docusaurus-types/src/config.d.ts @@ -40,6 +40,7 @@ export type FutureV4Config = { removeLegacyPostBuildHeadAttribute: boolean; useCssCascadeLayers: boolean; siteStorageNamespacing: boolean; + fasterByDefault: boolean; }; // VCS (Version Control System) info about a given change, e.g., a git commit. @@ -95,7 +96,7 @@ export type FutureConfig = { */ v4: FutureV4Config; - experimental_faster: FasterConfig; + faster: FasterConfig; experimental_vcs: VcsConfig; @@ -421,7 +422,7 @@ export type Config = Overwrite< DeepPartial, { v4?: boolean | Partial; - experimental_faster?: boolean | Partial; + faster?: boolean | Partial; experimental_vcs?: VcsPreset | VcsConfig | boolean; } >; diff --git a/packages/docusaurus/package.json b/packages/docusaurus/package.json index 0ba34a2bfdd2..af4f4e8bb72e 100644 --- a/packages/docusaurus/package.json +++ b/packages/docusaurus/package.json @@ -90,10 +90,16 @@ "tree-node-cli": "^1.6.0" }, "peerDependencies": { + "@docusaurus/faster": "*", "@mdx-js/react": "^3.0.0", "react": "^18.0.0 || ^19.0.0", "react-dom": "^18.0.0 || ^19.0.0" }, + "peerDependenciesMeta": { + "@docusaurus/faster": { + "optional": true + } + }, "engines": { "node": ">=20.0" } diff --git a/packages/docusaurus/src/commands/build/buildLocale.ts b/packages/docusaurus/src/commands/build/buildLocale.ts index 21175d55af79..483f347d1127 100644 --- a/packages/docusaurus/src/commands/build/buildLocale.ts +++ b/packages/docusaurus/src/commands/build/buildLocale.ts @@ -217,7 +217,7 @@ async function getBuildClientConfig({ const result = await createBuildClientConfig({ props, minify: cliOptions.minify ?? true, - faster: props.siteConfig.future.experimental_faster, + faster: props.siteConfig.future.faster, configureWebpackUtils, bundleAnalyzer: cliOptions.bundleAnalyzer ?? false, }); diff --git a/packages/docusaurus/src/commands/start/webpack.ts b/packages/docusaurus/src/commands/start/webpack.ts index b77a1cd44287..722198d84ba4 100644 --- a/packages/docusaurus/src/commands/start/webpack.ts +++ b/packages/docusaurus/src/commands/start/webpack.ts @@ -134,7 +134,7 @@ async function getStartClientConfig({ let {clientConfig: config} = await createStartClientConfig({ props, minify, - faster: props.siteConfig.future.experimental_faster, + faster: props.siteConfig.future.faster, poll, configureWebpackUtils, }); diff --git a/packages/docusaurus/src/server/__tests__/__snapshots__/config.test.ts.snap b/packages/docusaurus/src/server/__tests__/__snapshots__/config.test.ts.snap index 704bb6aee625..c0437a9e133a 100644 --- a/packages/docusaurus/src/server/__tests__/__snapshots__/config.test.ts.snap +++ b/packages/docusaurus/src/server/__tests__/__snapshots__/config.test.ts.snap @@ -8,7 +8,13 @@ exports[`loadSiteConfig website with .cjs siteConfig 1`] = ` "clientModules": [], "customFields": {}, "future": { - "experimental_faster": { + "experimental_router": "browser", + "experimental_vcs": { + "getFileCreationInfo": [Function], + "getFileLastUpdateInfo": [Function], + "initialize": [Function], + }, + "faster": { "gitEagerVcs": false, "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, @@ -19,13 +25,8 @@ exports[`loadSiteConfig website with .cjs siteConfig 1`] = ` "swcJsLoader": false, "swcJsMinimizer": false, }, - "experimental_router": "browser", - "experimental_vcs": { - "getFileCreationInfo": [Function], - "getFileLastUpdateInfo": [Function], - "initialize": [Function], - }, "v4": { + "fasterByDefault": false, "removeLegacyPostBuildHeadAttribute": false, "siteStorageNamespacing": false, "useCssCascadeLayers": false, @@ -94,7 +95,13 @@ exports[`loadSiteConfig website with ts + js config 1`] = ` "clientModules": [], "customFields": {}, "future": { - "experimental_faster": { + "experimental_router": "browser", + "experimental_vcs": { + "getFileCreationInfo": [Function], + "getFileLastUpdateInfo": [Function], + "initialize": [Function], + }, + "faster": { "gitEagerVcs": false, "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, @@ -105,13 +112,8 @@ exports[`loadSiteConfig website with ts + js config 1`] = ` "swcJsLoader": false, "swcJsMinimizer": false, }, - "experimental_router": "browser", - "experimental_vcs": { - "getFileCreationInfo": [Function], - "getFileLastUpdateInfo": [Function], - "initialize": [Function], - }, "v4": { + "fasterByDefault": false, "removeLegacyPostBuildHeadAttribute": false, "siteStorageNamespacing": false, "useCssCascadeLayers": false, @@ -180,7 +182,13 @@ exports[`loadSiteConfig website with valid JS CJS config 1`] = ` "clientModules": [], "customFields": {}, "future": { - "experimental_faster": { + "experimental_router": "browser", + "experimental_vcs": { + "getFileCreationInfo": [Function], + "getFileLastUpdateInfo": [Function], + "initialize": [Function], + }, + "faster": { "gitEagerVcs": false, "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, @@ -191,13 +199,8 @@ exports[`loadSiteConfig website with valid JS CJS config 1`] = ` "swcJsLoader": false, "swcJsMinimizer": false, }, - "experimental_router": "browser", - "experimental_vcs": { - "getFileCreationInfo": [Function], - "getFileLastUpdateInfo": [Function], - "initialize": [Function], - }, "v4": { + "fasterByDefault": false, "removeLegacyPostBuildHeadAttribute": false, "siteStorageNamespacing": false, "useCssCascadeLayers": false, @@ -266,7 +269,13 @@ exports[`loadSiteConfig website with valid JS ESM config 1`] = ` "clientModules": [], "customFields": {}, "future": { - "experimental_faster": { + "experimental_router": "browser", + "experimental_vcs": { + "getFileCreationInfo": [Function], + "getFileLastUpdateInfo": [Function], + "initialize": [Function], + }, + "faster": { "gitEagerVcs": false, "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, @@ -277,13 +286,8 @@ exports[`loadSiteConfig website with valid JS ESM config 1`] = ` "swcJsLoader": false, "swcJsMinimizer": false, }, - "experimental_router": "browser", - "experimental_vcs": { - "getFileCreationInfo": [Function], - "getFileLastUpdateInfo": [Function], - "initialize": [Function], - }, "v4": { + "fasterByDefault": false, "removeLegacyPostBuildHeadAttribute": false, "siteStorageNamespacing": false, "useCssCascadeLayers": false, @@ -352,7 +356,13 @@ exports[`loadSiteConfig website with valid TypeScript CJS config 1`] = ` "clientModules": [], "customFields": {}, "future": { - "experimental_faster": { + "experimental_router": "browser", + "experimental_vcs": { + "getFileCreationInfo": [Function], + "getFileLastUpdateInfo": [Function], + "initialize": [Function], + }, + "faster": { "gitEagerVcs": false, "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, @@ -363,13 +373,8 @@ exports[`loadSiteConfig website with valid TypeScript CJS config 1`] = ` "swcJsLoader": false, "swcJsMinimizer": false, }, - "experimental_router": "browser", - "experimental_vcs": { - "getFileCreationInfo": [Function], - "getFileLastUpdateInfo": [Function], - "initialize": [Function], - }, "v4": { + "fasterByDefault": false, "removeLegacyPostBuildHeadAttribute": false, "siteStorageNamespacing": false, "useCssCascadeLayers": false, @@ -438,7 +443,13 @@ exports[`loadSiteConfig website with valid TypeScript ESM config 1`] = ` "clientModules": [], "customFields": {}, "future": { - "experimental_faster": { + "experimental_router": "browser", + "experimental_vcs": { + "getFileCreationInfo": [Function], + "getFileLastUpdateInfo": [Function], + "initialize": [Function], + }, + "faster": { "gitEagerVcs": false, "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, @@ -449,13 +460,8 @@ exports[`loadSiteConfig website with valid TypeScript ESM config 1`] = ` "swcJsLoader": false, "swcJsMinimizer": false, }, - "experimental_router": "browser", - "experimental_vcs": { - "getFileCreationInfo": [Function], - "getFileLastUpdateInfo": [Function], - "initialize": [Function], - }, "v4": { + "fasterByDefault": false, "removeLegacyPostBuildHeadAttribute": false, "siteStorageNamespacing": false, "useCssCascadeLayers": false, @@ -524,7 +530,13 @@ exports[`loadSiteConfig website with valid async config 1`] = ` "clientModules": [], "customFields": {}, "future": { - "experimental_faster": { + "experimental_router": "browser", + "experimental_vcs": { + "getFileCreationInfo": [Function], + "getFileLastUpdateInfo": [Function], + "initialize": [Function], + }, + "faster": { "gitEagerVcs": false, "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, @@ -535,13 +547,8 @@ exports[`loadSiteConfig website with valid async config 1`] = ` "swcJsLoader": false, "swcJsMinimizer": false, }, - "experimental_router": "browser", - "experimental_vcs": { - "getFileCreationInfo": [Function], - "getFileLastUpdateInfo": [Function], - "initialize": [Function], - }, "v4": { + "fasterByDefault": false, "removeLegacyPostBuildHeadAttribute": false, "siteStorageNamespacing": false, "useCssCascadeLayers": false, @@ -612,7 +619,13 @@ exports[`loadSiteConfig website with valid async config creator function 1`] = ` "clientModules": [], "customFields": {}, "future": { - "experimental_faster": { + "experimental_router": "browser", + "experimental_vcs": { + "getFileCreationInfo": [Function], + "getFileLastUpdateInfo": [Function], + "initialize": [Function], + }, + "faster": { "gitEagerVcs": false, "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, @@ -623,13 +636,8 @@ exports[`loadSiteConfig website with valid async config creator function 1`] = ` "swcJsLoader": false, "swcJsMinimizer": false, }, - "experimental_router": "browser", - "experimental_vcs": { - "getFileCreationInfo": [Function], - "getFileLastUpdateInfo": [Function], - "initialize": [Function], - }, "v4": { + "fasterByDefault": false, "removeLegacyPostBuildHeadAttribute": false, "siteStorageNamespacing": false, "useCssCascadeLayers": false, @@ -700,7 +708,13 @@ exports[`loadSiteConfig website with valid config creator function 1`] = ` "clientModules": [], "customFields": {}, "future": { - "experimental_faster": { + "experimental_router": "browser", + "experimental_vcs": { + "getFileCreationInfo": [Function], + "getFileLastUpdateInfo": [Function], + "initialize": [Function], + }, + "faster": { "gitEagerVcs": false, "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, @@ -711,13 +725,8 @@ exports[`loadSiteConfig website with valid config creator function 1`] = ` "swcJsLoader": false, "swcJsMinimizer": false, }, - "experimental_router": "browser", - "experimental_vcs": { - "getFileCreationInfo": [Function], - "getFileLastUpdateInfo": [Function], - "initialize": [Function], - }, "v4": { + "fasterByDefault": false, "removeLegacyPostBuildHeadAttribute": false, "siteStorageNamespacing": false, "useCssCascadeLayers": false, @@ -791,7 +800,13 @@ exports[`loadSiteConfig website with valid siteConfig 1`] = ` "customFields": {}, "favicon": "img/docusaurus.ico", "future": { - "experimental_faster": { + "experimental_router": "browser", + "experimental_vcs": { + "getFileCreationInfo": [Function], + "getFileLastUpdateInfo": [Function], + "initialize": [Function], + }, + "faster": { "gitEagerVcs": false, "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, @@ -802,13 +817,8 @@ exports[`loadSiteConfig website with valid siteConfig 1`] = ` "swcJsLoader": false, "swcJsMinimizer": false, }, - "experimental_router": "browser", - "experimental_vcs": { - "getFileCreationInfo": [Function], - "getFileLastUpdateInfo": [Function], - "initialize": [Function], - }, "v4": { + "fasterByDefault": false, "removeLegacyPostBuildHeadAttribute": false, "siteStorageNamespacing": false, "useCssCascadeLayers": false, diff --git a/packages/docusaurus/src/server/__tests__/__snapshots__/site.test.ts.snap b/packages/docusaurus/src/server/__tests__/__snapshots__/site.test.ts.snap index 08fc5ae5ca38..a6999ad02ad6 100644 --- a/packages/docusaurus/src/server/__tests__/__snapshots__/site.test.ts.snap +++ b/packages/docusaurus/src/server/__tests__/__snapshots__/site.test.ts.snap @@ -88,7 +88,13 @@ exports[`loadSite custom-i18n-site loads site 1`] = ` "clientModules": [], "customFields": {}, "future": { - "experimental_faster": { + "experimental_router": "browser", + "experimental_vcs": { + "getFileCreationInfo": [Function], + "getFileLastUpdateInfo": [Function], + "initialize": [Function], + }, + "faster": { "gitEagerVcs": false, "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, @@ -99,13 +105,8 @@ exports[`loadSite custom-i18n-site loads site 1`] = ` "swcJsLoader": false, "swcJsMinimizer": false, }, - "experimental_router": "browser", - "experimental_vcs": { - "getFileCreationInfo": [Function], - "getFileLastUpdateInfo": [Function], - "initialize": [Function], - }, "v4": { + "fasterByDefault": false, "removeLegacyPostBuildHeadAttribute": false, "siteStorageNamespacing": false, "useCssCascadeLayers": false, @@ -262,7 +263,13 @@ exports[`loadSite simple-site-with-baseUrl loads site - custom config 1`] = ` "clientModules": [], "customFields": {}, "future": { - "experimental_faster": { + "experimental_router": "browser", + "experimental_vcs": { + "getFileCreationInfo": [Function], + "getFileLastUpdateInfo": [Function], + "initialize": [Function], + }, + "faster": { "gitEagerVcs": false, "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, @@ -273,13 +280,8 @@ exports[`loadSite simple-site-with-baseUrl loads site - custom config 1`] = ` "swcJsLoader": false, "swcJsMinimizer": false, }, - "experimental_router": "browser", - "experimental_vcs": { - "getFileCreationInfo": [Function], - "getFileLastUpdateInfo": [Function], - "initialize": [Function], - }, "v4": { + "fasterByDefault": false, "removeLegacyPostBuildHeadAttribute": false, "siteStorageNamespacing": false, "useCssCascadeLayers": false, @@ -428,7 +430,13 @@ exports[`loadSite simple-site-with-baseUrl loads site - custom outDir 1`] = ` "clientModules": [], "customFields": {}, "future": { - "experimental_faster": { + "experimental_router": "browser", + "experimental_vcs": { + "getFileCreationInfo": [Function], + "getFileLastUpdateInfo": [Function], + "initialize": [Function], + }, + "faster": { "gitEagerVcs": false, "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, @@ -439,13 +447,8 @@ exports[`loadSite simple-site-with-baseUrl loads site - custom outDir 1`] = ` "swcJsLoader": false, "swcJsMinimizer": false, }, - "experimental_router": "browser", - "experimental_vcs": { - "getFileCreationInfo": [Function], - "getFileLastUpdateInfo": [Function], - "initialize": [Function], - }, "v4": { + "fasterByDefault": false, "removeLegacyPostBuildHeadAttribute": false, "siteStorageNamespacing": false, "useCssCascadeLayers": false, @@ -594,7 +597,13 @@ exports[`loadSite simple-site-with-baseUrl loads site 1`] = ` "clientModules": [], "customFields": {}, "future": { - "experimental_faster": { + "experimental_router": "browser", + "experimental_vcs": { + "getFileCreationInfo": [Function], + "getFileLastUpdateInfo": [Function], + "initialize": [Function], + }, + "faster": { "gitEagerVcs": false, "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, @@ -605,13 +614,8 @@ exports[`loadSite simple-site-with-baseUrl loads site 1`] = ` "swcJsLoader": false, "swcJsMinimizer": false, }, - "experimental_router": "browser", - "experimental_vcs": { - "getFileCreationInfo": [Function], - "getFileLastUpdateInfo": [Function], - "initialize": [Function], - }, "v4": { + "fasterByDefault": false, "removeLegacyPostBuildHeadAttribute": false, "siteStorageNamespacing": false, "useCssCascadeLayers": false, @@ -804,7 +808,13 @@ exports[`loadSite simple-site-with-baseUrl-i18n loads site - locale fr + custom "clientModules": [], "customFields": {}, "future": { - "experimental_faster": { + "experimental_router": "browser", + "experimental_vcs": { + "getFileCreationInfo": [Function], + "getFileLastUpdateInfo": [Function], + "initialize": [Function], + }, + "faster": { "gitEagerVcs": false, "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, @@ -815,13 +825,8 @@ exports[`loadSite simple-site-with-baseUrl-i18n loads site - locale fr + custom "swcJsLoader": false, "swcJsMinimizer": false, }, - "experimental_router": "browser", - "experimental_vcs": { - "getFileCreationInfo": [Function], - "getFileLastUpdateInfo": [Function], - "initialize": [Function], - }, "v4": { + "fasterByDefault": false, "removeLegacyPostBuildHeadAttribute": false, "siteStorageNamespacing": false, "useCssCascadeLayers": false, @@ -1036,7 +1041,13 @@ exports[`loadSite simple-site-with-baseUrl-i18n loads site - custom outDir 1`] = "clientModules": [], "customFields": {}, "future": { - "experimental_faster": { + "experimental_router": "browser", + "experimental_vcs": { + "getFileCreationInfo": [Function], + "getFileLastUpdateInfo": [Function], + "initialize": [Function], + }, + "faster": { "gitEagerVcs": false, "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, @@ -1047,13 +1058,8 @@ exports[`loadSite simple-site-with-baseUrl-i18n loads site - custom outDir 1`] = "swcJsLoader": false, "swcJsMinimizer": false, }, - "experimental_router": "browser", - "experimental_vcs": { - "getFileCreationInfo": [Function], - "getFileLastUpdateInfo": [Function], - "initialize": [Function], - }, "v4": { + "fasterByDefault": false, "removeLegacyPostBuildHeadAttribute": false, "siteStorageNamespacing": false, "useCssCascadeLayers": false, @@ -1268,7 +1274,13 @@ exports[`loadSite simple-site-with-baseUrl-i18n loads site - locale de 1`] = ` "clientModules": [], "customFields": {}, "future": { - "experimental_faster": { + "experimental_router": "browser", + "experimental_vcs": { + "getFileCreationInfo": [Function], + "getFileLastUpdateInfo": [Function], + "initialize": [Function], + }, + "faster": { "gitEagerVcs": false, "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, @@ -1279,13 +1291,8 @@ exports[`loadSite simple-site-with-baseUrl-i18n loads site - locale de 1`] = ` "swcJsLoader": false, "swcJsMinimizer": false, }, - "experimental_router": "browser", - "experimental_vcs": { - "getFileCreationInfo": [Function], - "getFileLastUpdateInfo": [Function], - "initialize": [Function], - }, "v4": { + "fasterByDefault": false, "removeLegacyPostBuildHeadAttribute": false, "siteStorageNamespacing": false, "useCssCascadeLayers": false, @@ -1500,7 +1507,13 @@ exports[`loadSite simple-site-with-baseUrl-i18n loads site - locale en 1`] = ` "clientModules": [], "customFields": {}, "future": { - "experimental_faster": { + "experimental_router": "browser", + "experimental_vcs": { + "getFileCreationInfo": [Function], + "getFileLastUpdateInfo": [Function], + "initialize": [Function], + }, + "faster": { "gitEagerVcs": false, "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, @@ -1511,13 +1524,8 @@ exports[`loadSite simple-site-with-baseUrl-i18n loads site - locale en 1`] = ` "swcJsLoader": false, "swcJsMinimizer": false, }, - "experimental_router": "browser", - "experimental_vcs": { - "getFileCreationInfo": [Function], - "getFileLastUpdateInfo": [Function], - "initialize": [Function], - }, "v4": { + "fasterByDefault": false, "removeLegacyPostBuildHeadAttribute": false, "siteStorageNamespacing": false, "useCssCascadeLayers": false, @@ -1732,7 +1740,13 @@ exports[`loadSite simple-site-with-baseUrl-i18n loads site - locale es 1`] = ` "clientModules": [], "customFields": {}, "future": { - "experimental_faster": { + "experimental_router": "browser", + "experimental_vcs": { + "getFileCreationInfo": [Function], + "getFileLastUpdateInfo": [Function], + "initialize": [Function], + }, + "faster": { "gitEagerVcs": false, "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, @@ -1743,13 +1757,8 @@ exports[`loadSite simple-site-with-baseUrl-i18n loads site - locale es 1`] = ` "swcJsLoader": false, "swcJsMinimizer": false, }, - "experimental_router": "browser", - "experimental_vcs": { - "getFileCreationInfo": [Function], - "getFileLastUpdateInfo": [Function], - "initialize": [Function], - }, "v4": { + "fasterByDefault": false, "removeLegacyPostBuildHeadAttribute": false, "siteStorageNamespacing": false, "useCssCascadeLayers": false, @@ -1964,7 +1973,13 @@ exports[`loadSite simple-site-with-baseUrl-i18n loads site - locale fr 1`] = ` "clientModules": [], "customFields": {}, "future": { - "experimental_faster": { + "experimental_router": "browser", + "experimental_vcs": { + "getFileCreationInfo": [Function], + "getFileLastUpdateInfo": [Function], + "initialize": [Function], + }, + "faster": { "gitEagerVcs": false, "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, @@ -1975,13 +1990,8 @@ exports[`loadSite simple-site-with-baseUrl-i18n loads site - locale fr 1`] = ` "swcJsLoader": false, "swcJsMinimizer": false, }, - "experimental_router": "browser", - "experimental_vcs": { - "getFileCreationInfo": [Function], - "getFileLastUpdateInfo": [Function], - "initialize": [Function], - }, "v4": { + "fasterByDefault": false, "removeLegacyPostBuildHeadAttribute": false, "siteStorageNamespacing": false, "useCssCascadeLayers": false, @@ -2196,7 +2206,13 @@ exports[`loadSite simple-site-with-baseUrl-i18n loads site - locale it 1`] = ` "clientModules": [], "customFields": {}, "future": { - "experimental_faster": { + "experimental_router": "browser", + "experimental_vcs": { + "getFileCreationInfo": [Function], + "getFileLastUpdateInfo": [Function], + "initialize": [Function], + }, + "faster": { "gitEagerVcs": false, "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, @@ -2207,13 +2223,8 @@ exports[`loadSite simple-site-with-baseUrl-i18n loads site - locale it 1`] = ` "swcJsLoader": false, "swcJsMinimizer": false, }, - "experimental_router": "browser", - "experimental_vcs": { - "getFileCreationInfo": [Function], - "getFileLastUpdateInfo": [Function], - "initialize": [Function], - }, "v4": { + "fasterByDefault": false, "removeLegacyPostBuildHeadAttribute": false, "siteStorageNamespacing": false, "useCssCascadeLayers": false, @@ -2428,7 +2439,13 @@ exports[`loadSite simple-site-with-baseUrl-i18n loads site 1`] = ` "clientModules": [], "customFields": {}, "future": { - "experimental_faster": { + "experimental_router": "browser", + "experimental_vcs": { + "getFileCreationInfo": [Function], + "getFileLastUpdateInfo": [Function], + "initialize": [Function], + }, + "faster": { "gitEagerVcs": false, "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, @@ -2439,13 +2456,8 @@ exports[`loadSite simple-site-with-baseUrl-i18n loads site 1`] = ` "swcJsLoader": false, "swcJsMinimizer": false, }, - "experimental_router": "browser", - "experimental_vcs": { - "getFileCreationInfo": [Function], - "getFileLastUpdateInfo": [Function], - "initialize": [Function], - }, "v4": { + "fasterByDefault": false, "removeLegacyPostBuildHeadAttribute": false, "siteStorageNamespacing": false, "useCssCascadeLayers": false, diff --git a/packages/docusaurus/src/server/__tests__/configValidation.test.ts b/packages/docusaurus/src/server/__tests__/configValidation.test.ts index 8b9287b74882..63c58e82da1e 100644 --- a/packages/docusaurus/src/server/__tests__/configValidation.test.ts +++ b/packages/docusaurus/src/server/__tests__/configValidation.test.ts @@ -66,8 +66,9 @@ describe('normalizeConfig', () => { removeLegacyPostBuildHeadAttribute: true, useCssCascadeLayers: true, siteStorageNamespacing: true, + fasterByDefault: true, }, - experimental_faster: { + faster: { swcJsLoader: true, swcJsMinimizer: true, swcHtmlMinimizer: true, @@ -1139,6 +1140,20 @@ describe('storage', () => { `); }); + it('rejects future.experimental_faster', () => { + expect(() => + normalizeConfig({ + future: { + // @ts-expect-error: testing removed config + experimental_faster: true, + }, + }), + ).toThrowErrorMatchingInlineSnapshot(` + "The Docusaurus config \`future.experimental_faster\` has been renamed to \`future.faster\`. Please update your Docusaurus config. + " + `); + }); + describe('type', () => { it('accepts type', () => { const storage: Partial = { @@ -1332,8 +1347,9 @@ describe('future', () => { removeLegacyPostBuildHeadAttribute: true, useCssCascadeLayers: true, siteStorageNamespacing: true, + fasterByDefault: true, }, - experimental_faster: { + faster: { swcJsLoader: true, swcJsMinimizer: true, swcHtmlMinimizer: true, @@ -1648,7 +1664,7 @@ describe('future', () => { describe('faster', () => { function fasterContaining(faster: Partial) { return futureContaining({ - experimental_faster: expect.objectContaining(faster), + faster: expect.objectContaining(faster), }); } @@ -1656,7 +1672,7 @@ describe('future', () => { expect( normalizeConfig({ future: { - experimental_faster: undefined, + faster: undefined, }, }), ).toEqual(futureContaining(DEFAULT_FUTURE_CONFIG)); @@ -1665,7 +1681,7 @@ describe('future', () => { it('accepts faster - empty', () => { expect( normalizeConfig({ - future: {experimental_faster: {}}, + future: {faster: {}}, }), ).toEqual(futureContaining(DEFAULT_FUTURE_CONFIG)); }); @@ -1686,7 +1702,7 @@ describe('future', () => { normalizeConfig({ future: { v4: true, - experimental_faster: faster, + faster, }, }), ).toEqual(fasterContaining(faster)); @@ -1695,7 +1711,7 @@ describe('future', () => { it('accepts faster - false', () => { expect( normalizeConfig({ - future: {experimental_faster: false}, + future: {faster: false}, }), ).toEqual(fasterContaining(DEFAULT_FASTER_CONFIG)); }); @@ -1705,7 +1721,7 @@ describe('future', () => { normalizeConfig({ future: { v4: true, - experimental_faster: true, + faster: true, }, }), ).toEqual(fasterContaining(DEFAULT_FASTER_CONFIG_TRUE)); @@ -1716,11 +1732,11 @@ describe('future', () => { normalizeConfig({ future: { v4: false, - experimental_faster: true, + faster: true, }, }), ).toThrowErrorMatchingInlineSnapshot(` - "Docusaurus config \`future.experimental_faster.ssgWorkerThreads\` requires the future flag \`future.v4.removeLegacyPostBuildHeadAttribute\` to be turned on. + "Docusaurus config \`future.faster.ssgWorkerThreads\` requires the future flag \`future.v4.removeLegacyPostBuildHeadAttribute\` to be turned on. If you use Docusaurus Faster, we recommend that you also activate Docusaurus v4 future flags: \`{future: {v4: true}}\` All the v4 future flags are documented here: https://docusaurus.io/docs/api/docusaurus-config#future" `); @@ -1731,11 +1747,11 @@ describe('future', () => { normalizeConfig({ future: { v4: false, - experimental_faster: true, + faster: true, }, }), ).toThrowErrorMatchingInlineSnapshot(` - "Docusaurus config \`future.experimental_faster.ssgWorkerThreads\` requires the future flag \`future.v4.removeLegacyPostBuildHeadAttribute\` to be turned on. + "Docusaurus config \`future.faster.ssgWorkerThreads\` requires the future flag \`future.v4.removeLegacyPostBuildHeadAttribute\` to be turned on. If you use Docusaurus Faster, we recommend that you also activate Docusaurus v4 future flags: \`{future: {v4: true}}\` All the v4 future flags are documented here: https://docusaurus.io/docs/api/docusaurus-config#future" `); @@ -1747,11 +1763,11 @@ describe('future', () => { expect(() => normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toThrowErrorMatchingInlineSnapshot(` - ""future.experimental_faster" must be one of [object, boolean] + ""future.faster" must be one of [object, boolean] " `); }); @@ -1764,7 +1780,7 @@ describe('future', () => { expect( normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toEqual(fasterContaining({swcJsLoader: false})); @@ -1777,7 +1793,7 @@ describe('future', () => { expect( normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toEqual(fasterContaining({swcJsLoader: true})); @@ -1790,7 +1806,7 @@ describe('future', () => { expect( normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toEqual(fasterContaining({swcJsLoader: false})); @@ -1802,11 +1818,11 @@ describe('future', () => { expect(() => normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toThrowErrorMatchingInlineSnapshot(` - ""future.experimental_faster.swcJsLoader" must be a boolean + ""future.faster.swcJsLoader" must be a boolean " `); }); @@ -1817,11 +1833,11 @@ describe('future', () => { expect(() => normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toThrowErrorMatchingInlineSnapshot(` - ""future.experimental_faster.swcJsLoader" must be a boolean + ""future.faster.swcJsLoader" must be a boolean " `); }); @@ -1835,7 +1851,7 @@ describe('future', () => { expect( normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toEqual(fasterContaining({swcJsMinimizer: false})); @@ -1848,7 +1864,7 @@ describe('future', () => { expect( normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toEqual(fasterContaining({swcJsMinimizer: true})); @@ -1861,7 +1877,7 @@ describe('future', () => { expect( normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toEqual(fasterContaining({swcJsMinimizer: false})); @@ -1873,11 +1889,11 @@ describe('future', () => { expect(() => normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toThrowErrorMatchingInlineSnapshot(` - ""future.experimental_faster.swcJsMinimizer" must be a boolean + ""future.faster.swcJsMinimizer" must be a boolean " `); }); @@ -1888,11 +1904,11 @@ describe('future', () => { expect(() => normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toThrowErrorMatchingInlineSnapshot(` - ""future.experimental_faster.swcJsMinimizer" must be a boolean + ""future.faster.swcJsMinimizer" must be a boolean " `); }); @@ -1906,7 +1922,7 @@ describe('future', () => { expect( normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toEqual(fasterContaining({swcHtmlMinimizer: false})); @@ -1919,7 +1935,7 @@ describe('future', () => { expect( normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toEqual(fasterContaining({swcHtmlMinimizer: true})); @@ -1932,7 +1948,7 @@ describe('future', () => { expect( normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toEqual(fasterContaining({swcHtmlMinimizer: false})); @@ -1944,11 +1960,11 @@ describe('future', () => { expect(() => normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toThrowErrorMatchingInlineSnapshot(` - ""future.experimental_faster.swcHtmlMinimizer" must be a boolean + ""future.faster.swcHtmlMinimizer" must be a boolean " `); }); @@ -1959,11 +1975,11 @@ describe('future', () => { expect(() => normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toThrowErrorMatchingInlineSnapshot(` - ""future.experimental_faster.swcHtmlMinimizer" must be a boolean + ""future.faster.swcHtmlMinimizer" must be a boolean " `); }); @@ -1977,7 +1993,7 @@ describe('future', () => { expect( normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toEqual(fasterContaining({lightningCssMinimizer: false})); @@ -1990,7 +2006,7 @@ describe('future', () => { expect( normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toEqual(fasterContaining({lightningCssMinimizer: true})); @@ -2003,7 +2019,7 @@ describe('future', () => { expect( normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toEqual(fasterContaining({lightningCssMinimizer: false})); @@ -2015,11 +2031,11 @@ describe('future', () => { expect(() => normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toThrowErrorMatchingInlineSnapshot(` - ""future.experimental_faster.lightningCssMinimizer" must be a boolean + ""future.faster.lightningCssMinimizer" must be a boolean " `); }); @@ -2030,11 +2046,11 @@ describe('future', () => { expect(() => normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toThrowErrorMatchingInlineSnapshot(` - ""future.experimental_faster.lightningCssMinimizer" must be a boolean + ""future.faster.lightningCssMinimizer" must be a boolean " `); }); @@ -2048,7 +2064,7 @@ describe('future', () => { expect( normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toEqual(fasterContaining({mdxCrossCompilerCache: false})); @@ -2061,7 +2077,7 @@ describe('future', () => { expect( normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toEqual(fasterContaining({mdxCrossCompilerCache: true})); @@ -2074,7 +2090,7 @@ describe('future', () => { expect( normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toEqual(fasterContaining({mdxCrossCompilerCache: false})); @@ -2086,11 +2102,11 @@ describe('future', () => { expect(() => normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toThrowErrorMatchingInlineSnapshot(` - ""future.experimental_faster.mdxCrossCompilerCache" must be a boolean + ""future.faster.mdxCrossCompilerCache" must be a boolean " `); }); @@ -2101,11 +2117,11 @@ describe('future', () => { expect(() => normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toThrowErrorMatchingInlineSnapshot(` - ""future.experimental_faster.mdxCrossCompilerCache" must be a boolean + ""future.faster.mdxCrossCompilerCache" must be a boolean " `); }); @@ -2119,7 +2135,7 @@ describe('future', () => { expect( normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toEqual(fasterContaining({rspackBundler: false})); @@ -2132,7 +2148,7 @@ describe('future', () => { expect( normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toEqual(fasterContaining({rspackBundler: true})); @@ -2145,7 +2161,7 @@ describe('future', () => { expect( normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toEqual(fasterContaining({rspackBundler: false})); @@ -2157,11 +2173,11 @@ describe('future', () => { expect(() => normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toThrowErrorMatchingInlineSnapshot(` - ""future.experimental_faster.rspackBundler" must be a boolean + ""future.faster.rspackBundler" must be a boolean " `); }); @@ -2172,11 +2188,11 @@ describe('future', () => { expect(() => normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toThrowErrorMatchingInlineSnapshot(` - ""future.experimental_faster.rspackBundler" must be a boolean + ""future.faster.rspackBundler" must be a boolean " `); }); @@ -2190,7 +2206,7 @@ describe('future', () => { expect( normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toEqual(fasterContaining({rspackPersistentCache: false})); @@ -2204,7 +2220,7 @@ describe('future', () => { expect( normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toEqual(fasterContaining({rspackPersistentCache: true})); @@ -2218,11 +2234,11 @@ describe('future', () => { expect(() => normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toThrowErrorMatchingInlineSnapshot( - `"Docusaurus config flag \`future.experimental_faster.rspackPersistentCache\` requires the flag \`future.experimental_faster.rspackBundler\` to be turned on."`, + `"Docusaurus config flag \`future.faster.rspackPersistentCache\` requires the flag \`future.faster.rspackBundler\` to be turned on."`, ); }); @@ -2234,11 +2250,11 @@ describe('future', () => { expect(() => normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toThrowErrorMatchingInlineSnapshot( - `"Docusaurus config flag \`future.experimental_faster.rspackPersistentCache\` requires the flag \`future.experimental_faster.rspackBundler\` to be turned on."`, + `"Docusaurus config flag \`future.faster.rspackPersistentCache\` requires the flag \`future.faster.rspackBundler\` to be turned on."`, ); }); @@ -2249,7 +2265,7 @@ describe('future', () => { expect( normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toEqual(fasterContaining({rspackPersistentCache: false})); @@ -2261,11 +2277,11 @@ describe('future', () => { expect(() => normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toThrowErrorMatchingInlineSnapshot(` - ""future.experimental_faster.rspackPersistentCache" must be a boolean + ""future.faster.rspackPersistentCache" must be a boolean " `); }); @@ -2276,11 +2292,11 @@ describe('future', () => { expect(() => normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toThrowErrorMatchingInlineSnapshot(` - ""future.experimental_faster.rspackPersistentCache" must be a boolean + ""future.faster.rspackPersistentCache" must be a boolean " `); }); @@ -2294,7 +2310,7 @@ describe('future', () => { expect( normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toEqual(fasterContaining({ssgWorkerThreads: false})); @@ -2308,7 +2324,7 @@ describe('future', () => { normalizeConfig({ future: { v4: true, - experimental_faster: faster, + faster, }, }), ).toEqual(fasterContaining({ssgWorkerThreads: true})); @@ -2322,11 +2338,11 @@ describe('future', () => { normalizeConfig({ future: { v4: false, - experimental_faster: faster, + faster, }, }), ).toThrowErrorMatchingInlineSnapshot(` - "Docusaurus config \`future.experimental_faster.ssgWorkerThreads\` requires the future flag \`future.v4.removeLegacyPostBuildHeadAttribute\` to be turned on. + "Docusaurus config \`future.faster.ssgWorkerThreads\` requires the future flag \`future.v4.removeLegacyPostBuildHeadAttribute\` to be turned on. If you use Docusaurus Faster, we recommend that you also activate Docusaurus v4 future flags: \`{future: {v4: true}}\` All the v4 future flags are documented here: https://docusaurus.io/docs/api/docusaurus-config#future" `); @@ -2340,11 +2356,11 @@ describe('future', () => { normalizeConfig({ future: { v4: undefined, - experimental_faster: faster, + faster, }, }), ).toThrowErrorMatchingInlineSnapshot(` - "Docusaurus config \`future.experimental_faster.ssgWorkerThreads\` requires the future flag \`future.v4.removeLegacyPostBuildHeadAttribute\` to be turned on. + "Docusaurus config \`future.faster.ssgWorkerThreads\` requires the future flag \`future.v4.removeLegacyPostBuildHeadAttribute\` to be turned on. If you use Docusaurus Faster, we recommend that you also activate Docusaurus v4 future flags: \`{future: {v4: true}}\` All the v4 future flags are documented here: https://docusaurus.io/docs/api/docusaurus-config#future" `); @@ -2357,7 +2373,7 @@ describe('future', () => { expect( normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toEqual(fasterContaining({ssgWorkerThreads: false})); @@ -2369,11 +2385,11 @@ describe('future', () => { expect(() => normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toThrowErrorMatchingInlineSnapshot(` - ""future.experimental_faster.ssgWorkerThreads" must be a boolean + ""future.faster.ssgWorkerThreads" must be a boolean " `); }); @@ -2384,11 +2400,11 @@ describe('future', () => { expect(() => normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toThrowErrorMatchingInlineSnapshot(` - ""future.experimental_faster.ssgWorkerThreads" must be a boolean + ""future.faster.ssgWorkerThreads" must be a boolean " `); }); @@ -2402,7 +2418,7 @@ describe('future', () => { expect( normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toEqual(fasterContaining({gitEagerVcs: false})); @@ -2415,12 +2431,12 @@ describe('future', () => { expect( normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toEqual( futureContaining({ - experimental_faster: expect.objectContaining(faster), + faster: expect.objectContaining(faster), experimental_vcs: getVcsPreset('default-v2'), }), ); @@ -2433,12 +2449,12 @@ describe('future', () => { expect( normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toEqual( futureContaining({ - experimental_faster: expect.objectContaining(faster), + faster: expect.objectContaining(faster), experimental_vcs: getVcsPreset('default-v1'), }), ); @@ -2450,11 +2466,11 @@ describe('future', () => { expect(() => normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toThrowErrorMatchingInlineSnapshot(` - ""future.experimental_faster.gitEagerVcs" must be a boolean + ""future.faster.gitEagerVcs" must be a boolean " `); }); @@ -2465,15 +2481,58 @@ describe('future', () => { expect(() => normalizeConfig({ future: { - experimental_faster: faster, + faster, }, }), ).toThrowErrorMatchingInlineSnapshot(` - ""future.experimental_faster.gitEagerVcs" must be a boolean + ""future.faster.gitEagerVcs" must be a boolean " `); }); }); + + it('v4.fasterByDefault defaults all faster flags to true', () => { + expect( + normalizeConfig({ + future: { + v4: { + fasterByDefault: true, + removeLegacyPostBuildHeadAttribute: true, + }, + }, + }), + ).toEqual(fasterContaining(DEFAULT_FASTER_CONFIG_TRUE)); + }); + + it('v4.fasterByDefault with partial faster keeps overrides', () => { + expect( + normalizeConfig({ + future: { + v4: { + fasterByDefault: true, + removeLegacyPostBuildHeadAttribute: true, + }, + faster: {swcJsLoader: false}, + }, + }), + ).toEqual( + fasterContaining({ + ...DEFAULT_FASTER_CONFIG_TRUE, + swcJsLoader: false, + }), + ); + }); + + it('faster: false overrides fasterByDefault', () => { + expect( + normalizeConfig({ + future: { + v4: {fasterByDefault: true}, + faster: false, + }, + }), + ).toEqual(fasterContaining(DEFAULT_FASTER_CONFIG)); + }); }); describe('v4', () => { @@ -2506,6 +2565,7 @@ describe('future', () => { removeLegacyPostBuildHeadAttribute: true, useCssCascadeLayers: true, siteStorageNamespacing: true, + fasterByDefault: true, }; expect( normalizeConfig({ @@ -2770,5 +2830,81 @@ describe('future', () => { `); }); }); + + describe('fasterByDefault', () => { + it('accepts - undefined', () => { + const v4: Partial = { + fasterByDefault: undefined, + }; + expect( + normalizeConfig({ + future: { + v4, + }, + }), + ).toEqual(v4Containing({fasterByDefault: false})); + }); + + it('accepts - true', () => { + const v4: Partial = { + fasterByDefault: true, + removeLegacyPostBuildHeadAttribute: true, + }; + expect( + normalizeConfig({ + future: { + v4, + }, + }), + ).toEqual(v4Containing({fasterByDefault: true})); + }); + + it('accepts - false', () => { + const v4: Partial = { + fasterByDefault: false, + }; + expect( + normalizeConfig({ + future: { + v4, + }, + }), + ).toEqual(v4Containing({fasterByDefault: false})); + }); + + it('rejects - null', () => { + const v4: Partial = { + // @ts-expect-error: invalid + fasterByDefault: null, + }; + expect(() => + normalizeConfig({ + future: { + v4, + }, + }), + ).toThrowErrorMatchingInlineSnapshot(` + ""future.v4.fasterByDefault" must be a boolean + " + `); + }); + + it('rejects - number', () => { + const v4: Partial = { + // @ts-expect-error: invalid + fasterByDefault: 42, + }; + expect(() => + normalizeConfig({ + future: { + v4, + }, + }), + ).toThrowErrorMatchingInlineSnapshot(` + ""future.v4.fasterByDefault" must be a boolean + " + `); + }); + }); }); }); diff --git a/packages/docusaurus/src/server/__tests__/siteMessages.test.ts b/packages/docusaurus/src/server/__tests__/siteMessages.test.ts index d50adc7ccada..d06145ee015e 100644 --- a/packages/docusaurus/src/server/__tests__/siteMessages.test.ts +++ b/packages/docusaurus/src/server/__tests__/siteMessages.test.ts @@ -29,7 +29,7 @@ describe('collectAllSiteMessages', () => { siteDir, siteConfig: { future: { - experimental_faster: { + faster: { swcJsLoader, }, }, diff --git a/packages/docusaurus/src/server/configValidation.ts b/packages/docusaurus/src/server/configValidation.ts index 9f64189efacc..defc47589b7b 100644 --- a/packages/docusaurus/src/server/configValidation.ts +++ b/packages/docusaurus/src/server/configValidation.ts @@ -101,6 +101,7 @@ export const DEFAULT_FUTURE_V4_CONFIG: FutureV4Config = { removeLegacyPostBuildHeadAttribute: false, useCssCascadeLayers: false, siteStorageNamespacing: false, + fasterByDefault: false, }; // When using the "v4: true" shortcut @@ -108,11 +109,12 @@ export const DEFAULT_FUTURE_V4_CONFIG_TRUE: FutureV4Config = { removeLegacyPostBuildHeadAttribute: true, useCssCascadeLayers: true, siteStorageNamespacing: true, + fasterByDefault: true, }; export const DEFAULT_FUTURE_CONFIG: FutureConfig = { v4: DEFAULT_FUTURE_V4_CONFIG, - experimental_faster: DEFAULT_FASTER_CONFIG, + faster: DEFAULT_FASTER_CONFIG, experimental_vcs: getVcsPreset('default-v1'), experimental_router: 'browser', }; @@ -278,30 +280,21 @@ const I18N_CONFIG_SCHEMA = Joi.object({ .optional() .default(DEFAULT_I18N_CONFIG); +// Individual boolean defaults are not set here on purpose +// They are resolved in postProcessDocusaurusConfig based on +// the future.v4.fasterByDefault flag const FASTER_CONFIG_SCHEMA = Joi.alternatives() .try( Joi.object({ - swcJsLoader: Joi.boolean().default(DEFAULT_FASTER_CONFIG.swcJsLoader), - swcJsMinimizer: Joi.boolean().default( - DEFAULT_FASTER_CONFIG.swcJsMinimizer, - ), - swcHtmlMinimizer: Joi.boolean().default( - DEFAULT_FASTER_CONFIG.swcHtmlMinimizer, - ), - lightningCssMinimizer: Joi.boolean().default( - DEFAULT_FASTER_CONFIG.lightningCssMinimizer, - ), - mdxCrossCompilerCache: Joi.boolean().default( - DEFAULT_FASTER_CONFIG.mdxCrossCompilerCache, - ), - rspackBundler: Joi.boolean().default(DEFAULT_FASTER_CONFIG.rspackBundler), - rspackPersistentCache: Joi.boolean().default( - DEFAULT_FASTER_CONFIG.rspackPersistentCache, - ), - ssgWorkerThreads: Joi.boolean().default( - DEFAULT_FASTER_CONFIG.ssgWorkerThreads, - ), - gitEagerVcs: Joi.boolean().default(DEFAULT_FASTER_CONFIG.gitEagerVcs), + swcJsLoader: Joi.boolean(), + swcJsMinimizer: Joi.boolean(), + swcHtmlMinimizer: Joi.boolean(), + lightningCssMinimizer: Joi.boolean(), + mdxCrossCompilerCache: Joi.boolean(), + rspackBundler: Joi.boolean(), + rspackPersistentCache: Joi.boolean(), + ssgWorkerThreads: Joi.boolean(), + gitEagerVcs: Joi.boolean(), }), Joi.boolean() .required() @@ -309,8 +302,7 @@ const FASTER_CONFIG_SCHEMA = Joi.alternatives() bool ? DEFAULT_FASTER_CONFIG_TRUE : DEFAULT_FASTER_CONFIG, ), ) - .optional() - .default(DEFAULT_FASTER_CONFIG); + .optional(); const FUTURE_V4_SCHEMA = Joi.alternatives() .try( @@ -324,6 +316,9 @@ const FUTURE_V4_SCHEMA = Joi.alternatives() siteStorageNamespacing: Joi.boolean().default( DEFAULT_FUTURE_V4_CONFIG.siteStorageNamespacing, ), + fasterByDefault: Joi.boolean().default( + DEFAULT_FUTURE_V4_CONFIG.fasterByDefault, + ), }), Joi.boolean() .required() @@ -377,10 +372,10 @@ const VCS_CONFIG_SCHEMA = Joi.custom((input) => { }).default(true); const FUTURE_CONFIG_SCHEMA = Joi.object< - FutureConfig & {experimental_storage: never} + FutureConfig & {experimental_storage: never; experimental_faster: never} >({ v4: FUTURE_V4_SCHEMA, - experimental_faster: FASTER_CONFIG_SCHEMA, + faster: FASTER_CONFIG_SCHEMA, experimental_vcs: VCS_CONFIG_SCHEMA, experimental_router: Joi.string() .equal('browser', 'hash') @@ -394,6 +389,15 @@ const FUTURE_CONFIG_SCHEMA = Joi.object< 'storage', )} config attribute. Please move your storage config to the top level.`, }), + experimental_faster: Joi.any() + .forbidden() + .messages({ + 'any.unknown': `The Docusaurus config ${logger.code( + 'future.experimental_faster', + )} has been renamed to ${logger.code( + 'future.faster', + )}. Please update your Docusaurus config.`, + }), }) .optional() .default(DEFAULT_FUTURE_CONFIG); @@ -557,6 +561,41 @@ function postProcessDocusaurusConfig(config: DocusaurusConfig) { config.storage.namespace = config.future.v4.siteStorageNamespacing; } + // Resolve faster config based on the v4.fasterByDefault flag + // undefined means "not explicitly set by user" + if (config.future.faster === undefined) { + config.future.faster = {} as FasterConfig; + } + const fasterDefault = config.future.v4.fasterByDefault; + const fasterKeys = Object.keys( + DEFAULT_FASTER_CONFIG, + ) as (keyof FasterConfig)[]; + for (const key of fasterKeys) { + if (config.future.faster[key] === undefined) { + config.future.faster[key] = fasterDefault; + } + } + + // Docusaurus Faster doesn't fully support Yarn PnP :s + // Until we support Rspack + PnP, we simply revert to Webpack with a warning + // See https://github.com/facebook/docusaurus/issues/10787 + if (process.versions.pnp) { + if (config.future.faster.rspackBundler) { + logger.warn(`Docusaurus Faster doesn't fully support the Yarn PnP linker yet. +We recommend to use Yarn node-linker instead. +Docusaurus will still attempt to build your app with Webpack (instead of Rspack) and use slower minimizers. +See also https://github.com/facebook/docusaurus/issues/10787`); + config.future.faster.rspackBundler = false; + config.future.faster.rspackPersistentCache = false; + + // This also won't work due to Webpack libs using peerDependencies :s + // This could eventually work if the deps are added at the site level + // TODO Docusaurus v4 clean this up + config.future.faster.lightningCssMinimizer = false; + config.future.faster.swcJsMinimizer = false; + } + } + if (config.onBrokenMarkdownLinks) { logger.warn`The code=${'siteConfig.onBrokenMarkdownLinks'} config option is deprecated and will be removed in Docusaurus v4. Please migrate and move this option to code=${'siteConfig.markdown.hooks.onBrokenMarkdownLinks'} instead.`; @@ -569,7 +608,7 @@ Please migrate and move this option to code=${'siteConfig.markdown.hooks.onBroke // We normalize the VCS config when using a boolean value if (typeof config.future.experimental_vcs === 'boolean') { const vcsConfig = config.future.experimental_vcs - ? config.future.experimental_faster.gitEagerVcs + ? config.future.faster.gitEagerVcs ? getVcsPreset('default-v2') : getVcsPreset('default-v1') : getVcsPreset('disabled'); @@ -578,12 +617,12 @@ Please migrate and move this option to code=${'siteConfig.markdown.hooks.onBroke } if ( - config.future.experimental_faster.ssgWorkerThreads && + config.future.faster.ssgWorkerThreads && !config.future.v4.removeLegacyPostBuildHeadAttribute ) { throw new Error( `Docusaurus config ${logger.code( - 'future.experimental_faster.ssgWorkerThreads', + 'future.faster.ssgWorkerThreads', )} requires the future flag ${logger.code( 'future.v4.removeLegacyPostBuildHeadAttribute', )} to be turned on. @@ -595,14 +634,14 @@ All the v4 future flags are documented here: https://docusaurus.io/docs/api/docu } if ( - config.future.experimental_faster.rspackPersistentCache && - !config.future.experimental_faster.rspackBundler + config.future.faster.rspackPersistentCache && + !config.future.faster.rspackBundler ) { throw new Error( `Docusaurus config flag ${logger.code( - 'future.experimental_faster.rspackPersistentCache', + 'future.faster.rspackPersistentCache', )} requires the flag ${logger.code( - 'future.experimental_faster.rspackBundler', + 'future.faster.rspackBundler', )} to be turned on.`, ); } diff --git a/packages/docusaurus/src/server/plugins/synthetic.ts b/packages/docusaurus/src/server/plugins/synthetic.ts index a79125c634ed..9d172b93a675 100644 --- a/packages/docusaurus/src/server/plugins/synthetic.ts +++ b/packages/docusaurus/src/server/plugins/synthetic.ts @@ -80,8 +80,7 @@ export async function createMDXFallbackPlugin({ siteConfig, }: LoadContext): Promise { const mdxLoaderItem = await createMDXLoaderItem({ - useCrossCompilerCache: - siteConfig.future.experimental_faster.mdxCrossCompilerCache, + useCrossCompilerCache: siteConfig.future.faster.mdxCrossCompilerCache, admonitions: true, staticDirs: siteConfig.staticDirectories.map((dir) => path.resolve(siteDir, dir), diff --git a/packages/docusaurus/src/server/siteMessages.ts b/packages/docusaurus/src/server/siteMessages.ts index e2b16d8c57cd..e012fec7021f 100644 --- a/packages/docusaurus/src/server/siteMessages.ts +++ b/packages/docusaurus/src/server/siteMessages.ts @@ -21,7 +21,7 @@ const uselessBabelConfigMessages: SiteMessageCreator = async ({site}) => { const { props: {siteDir, siteConfig}, } = site; - if (siteConfig.future.experimental_faster.swcJsLoader) { + if (siteConfig.future.faster.swcJsLoader) { const babelConfigFilePath = await getCustomBabelConfigFilePath(siteDir); if (babelConfigFilePath) { return [ diff --git a/packages/docusaurus/src/ssg/ssgExecutor.ts b/packages/docusaurus/src/ssg/ssgExecutor.ts index 0b4f7c703ab2..c329a635ca6d 100644 --- a/packages/docusaurus/src/ssg/ssgExecutor.ts +++ b/packages/docusaurus/src/ssg/ssgExecutor.ts @@ -201,8 +201,7 @@ export async function executeSSG({ return {collectedData: {}}; } - const createExecutor = props.siteConfig.future.experimental_faster - .ssgWorkerThreads + const createExecutor = props.siteConfig.future.faster.ssgWorkerThreads ? createPooledSSGExecutor : createSimpleSSGExecutor; diff --git a/packages/docusaurus/src/ssg/ssgParams.ts b/packages/docusaurus/src/ssg/ssgParams.ts index 90f219079673..7a11633e044e 100644 --- a/packages/docusaurus/src/ssg/ssgParams.ts +++ b/packages/docusaurus/src/ssg/ssgParams.ts @@ -61,8 +61,7 @@ export async function createSSGParams({ noIndex: props.siteConfig.noIndex, DOCUSAURUS_VERSION, serverBundlePath, - htmlMinifierType: props.siteConfig.future.experimental_faster - .swcHtmlMinimizer + htmlMinifierType: props.siteConfig.future.faster.swcHtmlMinimizer ? 'swc' : 'terser', diff --git a/packages/docusaurus/src/webpack/base.ts b/packages/docusaurus/src/webpack/base.ts index 6cf165db4f47..e5b736634271 100644 --- a/packages/docusaurus/src/webpack/base.ts +++ b/packages/docusaurus/src/webpack/base.ts @@ -130,7 +130,7 @@ export async function createBaseConfig({ return disabledPersistentCacheValue; } if (props.currentBundler.name === 'rspack') { - if (props.siteConfig.future.experimental_faster.rspackPersistentCache) { + if (props.siteConfig.future.faster.rspackPersistentCache) { // Use cache: true + experiments.cache.type: "persistent" // See https://rspack.dev/config/experiments#persistent-cache return true; diff --git a/packages/docusaurus/src/webpack/server.ts b/packages/docusaurus/src/webpack/server.ts index 740c322c48f6..51ce1f954c0b 100644 --- a/packages/docusaurus/src/webpack/server.ts +++ b/packages/docusaurus/src/webpack/server.ts @@ -24,7 +24,7 @@ export default async function createServerConfig({ props, isServer: true, minify: false, - faster: props.siteConfig.future.experimental_faster, + faster: props.siteConfig.future.faster, configureWebpackUtils, }); diff --git a/website/docs/api/docusaurus.config.js.mdx b/website/docs/api/docusaurus.config.js.mdx index 6dd7bec969b9..8e0019f461aa 100644 --- a/website/docs/api/docusaurus.config.js.mdx +++ b/website/docs/api/docusaurus.config.js.mdx @@ -253,8 +253,9 @@ export default { removeLegacyPostBuildHeadAttribute: true, useCssCascadeLayers: true, siteStorageNamespacing: true, + fasterByDefault: true, }, - experimental_faster: { + faster: { swcJsLoader: true, swcJsMinimizer: true, swcHtmlMinimizer: true, @@ -273,7 +274,8 @@ export default { - [`removeLegacyPostBuildHeadAttribute`](https://github.com/facebook/docusaurus/pull/10435): Removes the legacy `plugin.postBuild({head})` API that prevents us from applying useful SSG optimizations ([explanations](https://github.com/facebook/docusaurus/pull/10850)). - [`useCssCascadeLayers`](https://github.com/facebook/docusaurus/pull/11142): This enables the [Docusaurus CSS Cascade Layers plugin](./plugins/plugin-css-cascade-layers.mdx) with pre-configured layers that we plan to apply by default for Docusaurus v4. - `siteStorageNamespacing`: Defaults the [`storage.namespace`](#storage) config to `true` instead of `false`. This enables automatic browser storage key namespacing, which avoids storage key conflicts when multiple Docusaurus sites are hosted under the same domain, or on localhost. -- `experimental_faster`: An object containing feature flags to make the Docusaurus build faster. This requires adding the `@docusaurus/faster` package to your site's dependencies. Use `true` as a shorthand to enable all flags. Read more on the [Docusaurus Faster](https://github.com/facebook/docusaurus/issues/10556) issue. Available feature flags: + - `fasterByDefault`: Defaults all `future.faster` flags to `true` instead of `false`. This enables [Docusaurus Faster](https://github.com/facebook/docusaurus/issues/10556) features by default. Requires having `@docusaurus/faster` in your dependencies. If you explicitly set individual `faster` flags, those explicit values take precedence. +- `faster`: An object containing feature flags to make the Docusaurus build faster. This requires adding the `@docusaurus/faster` package to your site's dependencies. Use `true` as a shorthand to enable all flags. Read more on the [Docusaurus Faster](https://github.com/facebook/docusaurus/issues/10556) issue. Available feature flags: - [`swcJsLoader`](https://github.com/facebook/docusaurus/pull/10435): Use [SWC](https://swc.rs/) to transpile JS (instead of [Babel](https://babeljs.io/)). - [`swcJsMinimizer`](https://github.com/facebook/docusaurus/pull/10441): Use [SWC](https://swc.rs/) to minify JS (instead of [Terser](https://github.com/terser/terser)). - [`swcHtmlMinimizer `](https://github.com/facebook/docusaurus/pull/10554): Use [SWC](https://swc.rs/) to minify HTML and inlined JS/CSS (instead of [html-minifier-terser](https://github.com/terser/html-minifier-terser)). diff --git a/website/docusaurus.config.ts b/website/docusaurus.config.ts index f49ef0c0247b..7f541c1caf52 100644 --- a/website/docusaurus.config.ts +++ b/website/docusaurus.config.ts @@ -179,7 +179,7 @@ export default async function createConfigAsync() { url: 'https://docusaurus.io', future: { v4: !isSlower, // Not accurate, but good enough - experimental_faster: isSlower + faster: isSlower ? false : { // Verbose object: easier to independently test single attributes