From 10ad71855edc3977c2c0eb75951c0a42952155f3 Mon Sep 17 00:00:00 2001 From: Alexey Ivanov Date: Sat, 20 Apr 2024 01:44:18 +0900 Subject: [PATCH 1/8] Add option to preserve case in anchors --- .../docusaurus-mdx-loader/src/processor.ts | 12 +++------ .../remark/headings/__tests__/index.test.ts | 27 +++++++++++++++++-- .../src/remark/headings/index.ts | 10 +++++-- packages/docusaurus-types/src/config.d.ts | 9 +++++++ website/docs/api/docusaurus.config.js.mdx | 6 +++++ 5 files changed, 52 insertions(+), 12 deletions(-) diff --git a/packages/docusaurus-mdx-loader/src/processor.ts b/packages/docusaurus-mdx-loader/src/processor.ts index 6865f721a999..a4172a7c324a 100644 --- a/packages/docusaurus-mdx-loader/src/processor.ts +++ b/packages/docusaurus-mdx-loader/src/processor.ts @@ -47,11 +47,6 @@ type SimpleProcessor = { }) => Promise; }; -async function getDefaultRemarkPlugins(): Promise { - const {default: emoji} = await import('remark-emoji'); - return [headings, emoji, toc]; -} - export type MDXPlugin = Pluggable; export type MDXOptions = { @@ -86,8 +81,7 @@ async function createProcessorFactory() { const {default: comment} = await import('@slorber/remark-comment'); const {default: directive} = await import('remark-directive'); const {VFile} = await import('vfile'); - - const defaultRemarkPlugins = await getDefaultRemarkPlugins(); + const {default: emoji} = await import('remark-emoji'); // /!\ this method is synchronous on purpose // Using async code here can create cache entry race conditions! @@ -104,7 +98,9 @@ async function createProcessorFactory() { directive, [contentTitle, {removeContentTitle: options.removeContentTitle}], ...getAdmonitionsPlugins(options.admonitions ?? false), - ...defaultRemarkPlugins, + [headings, options.markdownConfig.anchors], + emoji, + toc, details, head, ...(options.markdownConfig.mermaid ? [mermaid] : []), diff --git a/packages/docusaurus-mdx-loader/src/remark/headings/__tests__/index.test.ts b/packages/docusaurus-mdx-loader/src/remark/headings/__tests__/index.test.ts index f9385ca71fba..0f0ab6317edb 100644 --- a/packages/docusaurus-mdx-loader/src/remark/headings/__tests__/index.test.ts +++ b/packages/docusaurus-mdx-loader/src/remark/headings/__tests__/index.test.ts @@ -12,12 +12,19 @@ import {removePosition} from 'unist-util-remove-position'; import {toString} from 'mdast-util-to-string'; import {visit} from 'unist-util-visit'; import slug from '../index'; +import type {PluginOptions} from '../index'; import type {Plugin} from 'unified'; import type {Parent} from 'unist'; -async function process(doc: string, plugins: Plugin[] = []) { +async function process( + doc: string, + plugins: Plugin[] = [], + options: PluginOptions = {maintainCase: false}, +) { const {remark} = await import('remark'); - const processor = await remark().use({plugins: [...plugins, slug]}); + const processor = await remark().use({ + plugins: [...plugins, [slug, options]], + }); const result = await processor.run(processor.parse(doc)); removePosition(result, {force: true}); return result; @@ -312,4 +319,20 @@ describe('headings remark plugin', () => { }, ]); }); + + it('preserve anchors case then "maintainCase" option is set', async () => { + const result = await process('# Normal\n', [], {maintainCase: true}); + const expected = u('root', [ + u( + 'heading', + { + depth: 1, + data: {hProperties: {id: 'Normal'}, id: 'Normal'}, + }, + [u('text', 'Normal')], + ), + ]); + + expect(result).toEqual(expected); + }); }); diff --git a/packages/docusaurus-mdx-loader/src/remark/headings/index.ts b/packages/docusaurus-mdx-loader/src/remark/headings/index.ts index 90f90e75a5ad..a43aafd5efc4 100644 --- a/packages/docusaurus-mdx-loader/src/remark/headings/index.ts +++ b/packages/docusaurus-mdx-loader/src/remark/headings/index.ts @@ -12,7 +12,13 @@ import {parseMarkdownHeadingId, createSlugger} from '@docusaurus/utils'; import type {Transformer} from 'unified'; import type {Heading, Text} from 'mdast'; -export default function plugin(): Transformer { +export interface PluginOptions { + maintainCase: boolean; +} + +export default function plugin( + {maintainCase}: PluginOptions = {maintainCase: false}, +): Transformer { return async (root) => { const {toString} = await import('mdast-util-to-string'); const {visit} = await import('unist-util-visit'); @@ -38,7 +44,7 @@ export default function plugin(): Transformer { // Support explicit heading IDs const parsedHeading = parseMarkdownHeadingId(heading); - id = parsedHeading.id ?? slugs.slug(heading); + id = parsedHeading.id ?? slugs.slug(heading, {maintainCase}); if (parsedHeading.id) { // When there's an id, it is always in the last child node diff --git a/packages/docusaurus-types/src/config.d.ts b/packages/docusaurus-types/src/config.d.ts index 47bfde898d44..4016466ff641 100644 --- a/packages/docusaurus-types/src/config.d.ts +++ b/packages/docusaurus-types/src/config.d.ts @@ -101,6 +101,15 @@ export type MarkdownConfig = { * See also https://github.com/remarkjs/remark-rehype#options */ remarkRehypeOptions: RemarkRehypeOptions; + + /** + * Ability to preserve the case of the heading anchor links. + * See also https://github.com/facebook/docusaurus/issues/7946 + */ + + anchors?: { + maintainCase: boolean; + }; }; /** diff --git a/website/docs/api/docusaurus.config.js.mdx b/website/docs/api/docusaurus.config.js.mdx index 5a187dfcaaff..049422e84bcd 100644 --- a/website/docs/api/docusaurus.config.js.mdx +++ b/website/docs/api/docusaurus.config.js.mdx @@ -445,6 +445,9 @@ type MarkdownConfig = { parseFrontMatter?: ParseFrontMatter; mdx1Compat: MDX1CompatOptions; remarkRehypeOptions: object; // see https://github.com/remarkjs/remark-rehype#options + anchors?: { + maintainCase: boolean; + }; }; ``` @@ -469,6 +472,9 @@ export default { admonitions: true, headingIds: true, }, + anchors: { + maintainCase: true, + }, }, }; ``` From b282404a78bb590633d5db40856707a5cc9c640c Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Sun, 21 Apr 2024 00:10:30 -0400 Subject: [PATCH 2/8] Update config.d.ts --- packages/docusaurus-types/src/config.d.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/docusaurus-types/src/config.d.ts b/packages/docusaurus-types/src/config.d.ts index 4016466ff641..d20d5dbb8de0 100644 --- a/packages/docusaurus-types/src/config.d.ts +++ b/packages/docusaurus-types/src/config.d.ts @@ -102,12 +102,10 @@ export type MarkdownConfig = { */ remarkRehypeOptions: RemarkRehypeOptions; - /** - * Ability to preserve the case of the heading anchor links. - * See also https://github.com/facebook/docusaurus/issues/7946 - */ - anchors?: { + /** + * Ability to preserve the case of the heading anchor links. + */ maintainCase: boolean; }; }; From 49d747d38be5a178575bf66a5da6e8d8c5686db8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lorber?= Date: Fri, 19 Apr 2024 19:01:04 +0200 Subject: [PATCH 3/8] test(e2e): TypeCheck website/starter in min/max range of TS versions (#10063) --- .github/workflows/tests-e2e.yml | 18 +++++++++++++++++- .github/workflows/tests-windows.yml | 9 +++++++++ .github/workflows/tests.yml | 13 +++++++++++-- website/docs/migration/v3.mdx | 8 ++++---- website/docs/typescript-support.mdx | 2 +- .../version-3.0.1/migration/v3.mdx | 8 ++++---- .../version-3.0.1/typescript-support.mdx | 2 +- .../version-3.1.1/migration/v3.mdx | 8 ++++---- .../version-3.1.1/typescript-support.mdx | 2 +- .../version-3.2.1/migration/v3.mdx | 8 ++++---- .../version-3.2.1/typescript-support.mdx | 2 +- 11 files changed, 57 insertions(+), 23 deletions(-) diff --git a/.github/workflows/tests-e2e.yml b/.github/workflows/tests-e2e.yml index bdb96090f941..de5f5134ea3d 100644 --- a/.github/workflows/tests-e2e.yml +++ b/.github/workflows/tests-e2e.yml @@ -114,11 +114,27 @@ jobs: working-directory: ../test-website env: E2E_TEST: true - - name: Type check + + - 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 + yarn typecheck + - 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' working-directory: ../test-website + run: | + yarn add typescript@latest --exact + yarn typecheck + - name: Build test-website project run: yarn build working-directory: ../test-website diff --git a/.github/workflows/tests-windows.yml b/.github/workflows/tests-windows.yml index 2c14fe9706bb..0cb9a15b6c74 100644 --- a/.github/workflows/tests-windows.yml +++ b/.github/workflows/tests-windows.yml @@ -52,5 +52,14 @@ jobs: run: yarn workspace website test:swizzle:wrap:ts - name: Docusaurus Build run: yarn build:website:fast + - name: TypeCheck website run: yarn workspace website typecheck + - name: TypeCheck website - min version - v5.1 + run: | + yarn workspace website add typescript@5.1.6 --exact + yarn workspace website typecheck + - name: TypeCheck website - max version - Latest + run: | + yarn workspace website add typescript@latest --exact + yarn workspace website typecheck diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 208d26c93bce..16d9e168a710 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -39,9 +39,18 @@ jobs: run: yarn - name: Test run: yarn test - - name: TypeCheck website - run: yarn workspace website typecheck - name: Remove Theme Internal Re-export run: yarn workspace @docusaurus/theme-common removeThemeInternalReexport - name: Docusaurus Build run: yarn build:website:fast + + - name: TypeCheck website + run: yarn workspace website typecheck + - name: TypeCheck website - min version - v5.1 + run: | + yarn workspace website add typescript@5.1.6 --exact + yarn workspace website typecheck + - name: TypeCheck website - max version - Latest + run: | + yarn workspace website add typescript@latest --exact + yarn workspace website typecheck diff --git a/website/docs/migration/v3.mdx b/website/docs/migration/v3.mdx index 219310b1c625..38cc4a4026a7 100644 --- a/website/docs/migration/v3.mdx +++ b/website/docs/migration/v3.mdx @@ -36,7 +36,7 @@ Docusaurus v3 now uses the following dependencies: - Node.js v18.0+ - React v18.0+ - MDX v3.0+ -- TypeScript v5.0+ +- TypeScript v5.1+ - prism-react-renderer v2.0+ - react-live v4.0+ - remark-emoji v4.0+ @@ -98,7 +98,7 @@ For TypeScript users: // upgrade React types to v18.0+ - "@types/react": "^17.0.69", + "@types/react": "^18.2.29", - // upgrade TypeScript to v5.0+ + // upgrade TypeScript to v5.1+ - "typescript": "~4.7.4" + "typescript": "~5.2.2" } @@ -689,9 +689,9 @@ However, this is a new major library version containing breaking changes, and we ::: -### TypeScript v5.0+ +### TypeScript v5.1+ -Docusaurus v3 now requires **TypeScript >= 5.0**. +Docusaurus v3 now requires **TypeScript >= 5.1**. :::info How to upgrade diff --git a/website/docs/typescript-support.mdx b/website/docs/typescript-support.mdx index 3746982f4cc1..1493cbe123c7 100644 --- a/website/docs/typescript-support.mdx +++ b/website/docs/typescript-support.mdx @@ -6,7 +6,7 @@ description: Docusaurus is written in TypeScript and provides first-class TypeSc Docusaurus is written in TypeScript and provides first-class TypeScript support. -The minimum required version is **TypeScript 5.0**. +The minimum required version is **TypeScript 5.1**. ## Initialization {#initialization} diff --git a/website/versioned_docs/version-3.0.1/migration/v3.mdx b/website/versioned_docs/version-3.0.1/migration/v3.mdx index 25056f94876b..affbb747ad4a 100644 --- a/website/versioned_docs/version-3.0.1/migration/v3.mdx +++ b/website/versioned_docs/version-3.0.1/migration/v3.mdx @@ -36,7 +36,7 @@ Docusaurus v3 now uses the following dependencies: - Node.js v18.0+ - React v18.0+ - MDX v3.0+ -- TypeScript v5.0+ +- TypeScript v5.1+ - prism-react-renderer v2.0+ - react-live v4.0+ - remark-emoji v4.0+ @@ -98,7 +98,7 @@ For TypeScript users: // upgrade React types to v18.0+ - "@types/react": "^17.0.69", + "@types/react": "^18.2.29", - // upgrade TypeScript to v5.0+ + // upgrade TypeScript to v5.1+ - "typescript": "~4.7.4" + "typescript": "~5.2.2" } @@ -601,9 +601,9 @@ However, this is a new major library version containing breaking changes, and we ::: -### TypeScript v5.0+ +### TypeScript v5.1+ -Docusaurus v3 now requires **TypeScript >= 5.0**. +Docusaurus v3 now requires **TypeScript >= 5.1**. :::info How to upgrade diff --git a/website/versioned_docs/version-3.0.1/typescript-support.mdx b/website/versioned_docs/version-3.0.1/typescript-support.mdx index 3746982f4cc1..1493cbe123c7 100644 --- a/website/versioned_docs/version-3.0.1/typescript-support.mdx +++ b/website/versioned_docs/version-3.0.1/typescript-support.mdx @@ -6,7 +6,7 @@ description: Docusaurus is written in TypeScript and provides first-class TypeSc Docusaurus is written in TypeScript and provides first-class TypeScript support. -The minimum required version is **TypeScript 5.0**. +The minimum required version is **TypeScript 5.1**. ## Initialization {#initialization} diff --git a/website/versioned_docs/version-3.1.1/migration/v3.mdx b/website/versioned_docs/version-3.1.1/migration/v3.mdx index ff8a0050f123..7195e82ea904 100644 --- a/website/versioned_docs/version-3.1.1/migration/v3.mdx +++ b/website/versioned_docs/version-3.1.1/migration/v3.mdx @@ -36,7 +36,7 @@ Docusaurus v3 now uses the following dependencies: - Node.js v18.0+ - React v18.0+ - MDX v3.0+ -- TypeScript v5.0+ +- TypeScript v5.1+ - prism-react-renderer v2.0+ - react-live v4.0+ - remark-emoji v4.0+ @@ -98,7 +98,7 @@ For TypeScript users: // upgrade React types to v18.0+ - "@types/react": "^17.0.69", + "@types/react": "^18.2.29", - // upgrade TypeScript to v5.0+ + // upgrade TypeScript to v5.1+ - "typescript": "~4.7.4" + "typescript": "~5.2.2" } @@ -689,9 +689,9 @@ However, this is a new major library version containing breaking changes, and we ::: -### TypeScript v5.0+ +### TypeScript v5.1+ -Docusaurus v3 now requires **TypeScript >= 5.0**. +Docusaurus v3 now requires **TypeScript >= 5.1**. :::info How to upgrade diff --git a/website/versioned_docs/version-3.1.1/typescript-support.mdx b/website/versioned_docs/version-3.1.1/typescript-support.mdx index 3746982f4cc1..1493cbe123c7 100644 --- a/website/versioned_docs/version-3.1.1/typescript-support.mdx +++ b/website/versioned_docs/version-3.1.1/typescript-support.mdx @@ -6,7 +6,7 @@ description: Docusaurus is written in TypeScript and provides first-class TypeSc Docusaurus is written in TypeScript and provides first-class TypeScript support. -The minimum required version is **TypeScript 5.0**. +The minimum required version is **TypeScript 5.1**. ## Initialization {#initialization} diff --git a/website/versioned_docs/version-3.2.1/migration/v3.mdx b/website/versioned_docs/version-3.2.1/migration/v3.mdx index 219310b1c625..38cc4a4026a7 100644 --- a/website/versioned_docs/version-3.2.1/migration/v3.mdx +++ b/website/versioned_docs/version-3.2.1/migration/v3.mdx @@ -36,7 +36,7 @@ Docusaurus v3 now uses the following dependencies: - Node.js v18.0+ - React v18.0+ - MDX v3.0+ -- TypeScript v5.0+ +- TypeScript v5.1+ - prism-react-renderer v2.0+ - react-live v4.0+ - remark-emoji v4.0+ @@ -98,7 +98,7 @@ For TypeScript users: // upgrade React types to v18.0+ - "@types/react": "^17.0.69", + "@types/react": "^18.2.29", - // upgrade TypeScript to v5.0+ + // upgrade TypeScript to v5.1+ - "typescript": "~4.7.4" + "typescript": "~5.2.2" } @@ -689,9 +689,9 @@ However, this is a new major library version containing breaking changes, and we ::: -### TypeScript v5.0+ +### TypeScript v5.1+ -Docusaurus v3 now requires **TypeScript >= 5.0**. +Docusaurus v3 now requires **TypeScript >= 5.1**. :::info How to upgrade diff --git a/website/versioned_docs/version-3.2.1/typescript-support.mdx b/website/versioned_docs/version-3.2.1/typescript-support.mdx index 3746982f4cc1..1493cbe123c7 100644 --- a/website/versioned_docs/version-3.2.1/typescript-support.mdx +++ b/website/versioned_docs/version-3.2.1/typescript-support.mdx @@ -6,7 +6,7 @@ description: Docusaurus is written in TypeScript and provides first-class TypeSc Docusaurus is written in TypeScript and provides first-class TypeScript support. -The minimum required version is **TypeScript 5.0**. +The minimum required version is **TypeScript 5.1**. ## Initialization {#initialization} From aaa99aa810353b6e28ebeea1f94aaafeaefe9be9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lorber?= Date: Fri, 19 Apr 2024 21:03:32 +0200 Subject: [PATCH 4/8] refactor: extract base TS client config + upgrade TS + refactor TS setup (#10065) --- .eslintrc.js | 2 +- .github/workflows/tests-e2e.yml | 4 +- .github/workflows/tests-windows.yml | 2 +- .github/workflows/tests.yml | 2 +- __tests__/validate-tsconfig.test.ts | 53 +++++++++---------- .../create-docusaurus/tsconfig.build.json | 4 +- packages/create-docusaurus/tsconfig.json | 2 +- .../docusaurus-cssnano-preset/tsconfig.json | 4 +- packages/docusaurus-logger/tsconfig.json | 4 +- packages/docusaurus-mdx-loader/tsconfig.json | 4 +- .../tsconfig.json | 4 +- .../tsconfig.client.json | 12 ++--- .../tsconfig.json | 4 +- .../tsconfig.client.json | 12 ++--- .../tsconfig.json | 4 +- .../tsconfig.json | 4 +- .../tsconfig.client.json | 12 ++--- .../docusaurus-plugin-debug/tsconfig.json | 4 +- .../tsconfig.client.json | 12 ++--- .../tsconfig.json | 4 +- .../tsconfig.client.json | 12 ++--- .../tsconfig.json | 4 +- .../tsconfig.client.json | 12 ++--- .../tsconfig.json | 4 +- .../tsconfig.client.json | 12 ++--- .../tsconfig.json | 4 +- .../tsconfig.client.json | 10 +--- packages/docusaurus-plugin-pwa/tsconfig.json | 4 +- .../tsconfig.worker.json | 4 +- .../docusaurus-plugin-sitemap/tsconfig.json | 4 +- .../tsconfig.client.json | 12 ++--- .../tsconfig.json | 4 +- .../docusaurus-preset-classic/tsconfig.json | 4 +- .../tsconfig.json | 4 +- .../tsconfig.client.json | 10 +--- .../docusaurus-theme-classic/tsconfig.json | 4 +- .../docusaurus-theme-common/tsconfig.json | 15 ++---- .../tsconfig.client.json | 10 +--- .../tsconfig.json | 4 +- .../tsconfig.client.json | 10 +--- .../docusaurus-theme-mermaid/tsconfig.json | 4 +- .../tsconfig.client.json | 10 +--- .../tsconfig.json | 4 +- .../tsconfig.build.json | 4 +- .../tsconfig.json | 2 +- .../docusaurus-utils-common/tsconfig.json | 4 +- .../docusaurus-utils-validation/tsconfig.json | 4 +- packages/docusaurus-utils/tsconfig.json | 4 +- packages/docusaurus/tsconfig.client.json | 12 ++--- packages/docusaurus/tsconfig.json | 2 +- packages/docusaurus/tsconfig.server.json | 4 +- packages/eslint-plugin/tsconfig.json | 4 +- packages/lqip-loader/tsconfig.json | 4 +- packages/stylelint-copyright/tsconfig.json | 4 +- tsconfig.base.client.json | 11 ++++ tsconfig.json => tsconfig.base.json | 0 56 files changed, 149 insertions(+), 228 deletions(-) create mode 100644 tsconfig.base.client.json rename tsconfig.json => tsconfig.base.json (100%) diff --git a/.eslintrc.js b/.eslintrc.js index 3b67b0030944..9aefce002eca 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -32,7 +32,7 @@ module.exports = { parser: '@typescript-eslint/parser', parserOptions: { // tsconfigRootDir: __dirname, - // project: ['./tsconfig.json', './website/tsconfig.json'], + // project: ['./tsconfig.base.json', './website/tsconfig.base.json'], }, globals: { JSX: true, diff --git a/.github/workflows/tests-e2e.yml b/.github/workflows/tests-e2e.yml index de5f5134ea3d..b98cb3270ba6 100644 --- a/.github/workflows/tests-e2e.yml +++ b/.github/workflows/tests-e2e.yml @@ -10,7 +10,7 @@ on: - yarn.lock - jest.config.mjs - packages/** - - tsconfig.json + - tsconfig.*.json pull_request: branches: - main @@ -20,7 +20,7 @@ on: - yarn.lock - jest.config.mjs - packages/** - - tsconfig.json + - tsconfig.*.json - admin/verdaccio.yaml - .github/workflows/tests-e2e.yml diff --git a/.github/workflows/tests-windows.yml b/.github/workflows/tests-windows.yml index 0cb9a15b6c74..c280e4fd9608 100644 --- a/.github/workflows/tests-windows.yml +++ b/.github/workflows/tests-windows.yml @@ -10,7 +10,7 @@ on: - yarn.lock - jest.config.mjs - packages/** - - tsconfig.json + - tsconfig.*.json concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 16d9e168a710..ae170e8b25d7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,7 +10,7 @@ on: - yarn.lock - jest.config.mjs - packages/** - - tsconfig.json + - tsconfig.*.json concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} diff --git a/__tests__/validate-tsconfig.test.ts b/__tests__/validate-tsconfig.test.ts index 8038a04ae824..c5dc5749ed3e 100644 --- a/__tests__/validate-tsconfig.test.ts +++ b/__tests__/validate-tsconfig.test.ts @@ -31,38 +31,37 @@ async function getTsconfigFiles(): Promise { } const tsconfigSchema = Joi.object({ - extends: '../../tsconfig.json', - compilerOptions: Joi.alternatives().conditional( - Joi.object({noEmit: true}).unknown(), - { - then: Joi.object({ - noEmit: Joi.valid(true).required(), - incremental: Joi.forbidden(), - tsBuildInfoFile: Joi.forbidden(), - outDir: Joi.forbidden(), - }).unknown(), - otherwise: Joi.object({ - noEmit: Joi.valid(false).required(), - incremental: Joi.valid(true).required(), - rootDir: Joi.valid('src').required(), - outDir: Joi.valid('lib').required(), - }).unknown(), - }, + extends: Joi.valid( + '../../tsconfig.base.json', + '../../tsconfig.base.client.json', ), + compilerOptions: Joi.object({ + rootDir: Joi.valid('src').required(), + outDir: Joi.valid('lib').required(), + tsBuildInfoFile: Joi.valid( + 'lib/.tsbuildinfo', + 'lib/.tsbuildinfo-client', + 'lib/.tsbuildinfo-worker', + ), + }).unknown(), }).unknown(); describe('tsconfig files', () => { it('contain all required fields', async () => { const tsconfigFiles = await getTsconfigFiles(); - tsconfigFiles.forEach((file) => { - try { - Joi.attempt(file.content, tsconfigSchema); - } catch (e) { - ( - e as Error - ).message += `\n${file.file} does not match the required schema.`; - throw e; - } - }); + + tsconfigFiles + // Ignore noEmit configs + .filter((file) => !(file.content.compilerOptions!.noEmit === true)) + .forEach((file) => { + try { + Joi.attempt(file.content, tsconfigSchema); + } catch (e) { + ( + e as Error + ).message += `\n${file.file} does not match the required schema.`; + throw e; + } + }); }); }); diff --git a/packages/create-docusaurus/tsconfig.build.json b/packages/create-docusaurus/tsconfig.build.json index 36377cdd0cbe..a95d8eb4c1fd 100644 --- a/packages/create-docusaurus/tsconfig.build.json +++ b/packages/create-docusaurus/tsconfig.build.json @@ -1,10 +1,10 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "compilerOptions": { "noEmit": false, "composite": true, "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo", + "tsBuildInfoFile": "lib/.tsbuildinfo", "rootDir": "src", "outDir": "lib" }, diff --git a/packages/create-docusaurus/tsconfig.json b/packages/create-docusaurus/tsconfig.json index 13e35c5a957c..fd08e5ac9775 100644 --- a/packages/create-docusaurus/tsconfig.json +++ b/packages/create-docusaurus/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "references": [{"path": "./tsconfig.build.json"}], "compilerOptions": { "noEmit": true, diff --git a/packages/docusaurus-cssnano-preset/tsconfig.json b/packages/docusaurus-cssnano-preset/tsconfig.json index e16d5c2c5d33..0f463da3d702 100644 --- a/packages/docusaurus-cssnano-preset/tsconfig.json +++ b/packages/docusaurus-cssnano-preset/tsconfig.json @@ -1,9 +1,9 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "compilerOptions": { "noEmit": false, "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo", + "tsBuildInfoFile": "lib/.tsbuildinfo", "rootDir": "src", "outDir": "lib" }, diff --git a/packages/docusaurus-logger/tsconfig.json b/packages/docusaurus-logger/tsconfig.json index 69bd9341b47e..6a904aac6f51 100644 --- a/packages/docusaurus-logger/tsconfig.json +++ b/packages/docusaurus-logger/tsconfig.json @@ -1,9 +1,9 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "compilerOptions": { "noEmit": false, "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo", + "tsBuildInfoFile": "lib/.tsbuildinfo", "sourceMap": true, "declarationMap": true, "rootDir": "src", diff --git a/packages/docusaurus-mdx-loader/tsconfig.json b/packages/docusaurus-mdx-loader/tsconfig.json index 670db9ce9168..8708abf63c45 100644 --- a/packages/docusaurus-mdx-loader/tsconfig.json +++ b/packages/docusaurus-mdx-loader/tsconfig.json @@ -1,9 +1,9 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "compilerOptions": { "noEmit": false, "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo", + "tsBuildInfoFile": "lib/.tsbuildinfo", "sourceMap": true, "declarationMap": true, "rootDir": "src", diff --git a/packages/docusaurus-plugin-client-redirects/tsconfig.json b/packages/docusaurus-plugin-client-redirects/tsconfig.json index e16d5c2c5d33..0f463da3d702 100644 --- a/packages/docusaurus-plugin-client-redirects/tsconfig.json +++ b/packages/docusaurus-plugin-client-redirects/tsconfig.json @@ -1,9 +1,9 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "compilerOptions": { "noEmit": false, "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo", + "tsBuildInfoFile": "lib/.tsbuildinfo", "rootDir": "src", "outDir": "lib" }, diff --git a/packages/docusaurus-plugin-content-blog/tsconfig.client.json b/packages/docusaurus-plugin-content-blog/tsconfig.client.json index 5d06aa818c96..5e2b6e245224 100644 --- a/packages/docusaurus-plugin-content-blog/tsconfig.client.json +++ b/packages/docusaurus-plugin-content-blog/tsconfig.client.json @@ -1,15 +1,9 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.client.json", "compilerOptions": { - "noEmit": false, - "composite": true, - "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo-client", - "moduleResolution": "bundler", - "module": "esnext", - "target": "esnext", "rootDir": "src", - "outDir": "lib" + "outDir": "lib", + "tsBuildInfoFile": "lib/.tsbuildinfo-client" }, "include": ["src/client", "src/*.d.ts"], "exclude": ["**/__tests__/**"] diff --git a/packages/docusaurus-plugin-content-blog/tsconfig.json b/packages/docusaurus-plugin-content-blog/tsconfig.json index 3936df64b7e4..fd1428b0b32c 100644 --- a/packages/docusaurus-plugin-content-blog/tsconfig.json +++ b/packages/docusaurus-plugin-content-blog/tsconfig.json @@ -1,10 +1,10 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "references": [{"path": "./tsconfig.client.json"}], "compilerOptions": { "noEmit": false, "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo", + "tsBuildInfoFile": "lib/.tsbuildinfo", "rootDir": "src", "outDir": "lib" }, diff --git a/packages/docusaurus-plugin-content-docs/tsconfig.client.json b/packages/docusaurus-plugin-content-docs/tsconfig.client.json index 5d06aa818c96..5e2b6e245224 100644 --- a/packages/docusaurus-plugin-content-docs/tsconfig.client.json +++ b/packages/docusaurus-plugin-content-docs/tsconfig.client.json @@ -1,15 +1,9 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.client.json", "compilerOptions": { - "noEmit": false, - "composite": true, - "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo-client", - "moduleResolution": "bundler", - "module": "esnext", - "target": "esnext", "rootDir": "src", - "outDir": "lib" + "outDir": "lib", + "tsBuildInfoFile": "lib/.tsbuildinfo-client" }, "include": ["src/client", "src/*.d.ts"], "exclude": ["**/__tests__/**"] diff --git a/packages/docusaurus-plugin-content-docs/tsconfig.json b/packages/docusaurus-plugin-content-docs/tsconfig.json index 3936df64b7e4..fd1428b0b32c 100644 --- a/packages/docusaurus-plugin-content-docs/tsconfig.json +++ b/packages/docusaurus-plugin-content-docs/tsconfig.json @@ -1,10 +1,10 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "references": [{"path": "./tsconfig.client.json"}], "compilerOptions": { "noEmit": false, "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo", + "tsBuildInfoFile": "lib/.tsbuildinfo", "rootDir": "src", "outDir": "lib" }, diff --git a/packages/docusaurus-plugin-content-pages/tsconfig.json b/packages/docusaurus-plugin-content-pages/tsconfig.json index e16d5c2c5d33..0f463da3d702 100644 --- a/packages/docusaurus-plugin-content-pages/tsconfig.json +++ b/packages/docusaurus-plugin-content-pages/tsconfig.json @@ -1,9 +1,9 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "compilerOptions": { "noEmit": false, "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo", + "tsBuildInfoFile": "lib/.tsbuildinfo", "rootDir": "src", "outDir": "lib" }, diff --git a/packages/docusaurus-plugin-debug/tsconfig.client.json b/packages/docusaurus-plugin-debug/tsconfig.client.json index e69d347194cc..c411568a6d43 100644 --- a/packages/docusaurus-plugin-debug/tsconfig.client.json +++ b/packages/docusaurus-plugin-debug/tsconfig.client.json @@ -1,15 +1,9 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.client.json", "compilerOptions": { - "noEmit": false, - "composite": true, - "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo-client", - "moduleResolution": "bundler", - "module": "esnext", - "target": "esnext", "rootDir": "src", - "outDir": "lib" + "outDir": "lib", + "tsBuildInfoFile": "lib/.tsbuildinfo-client" }, "include": ["src/theme", "src/*.d.ts"], "exclude": ["**/__tests__/**"] diff --git a/packages/docusaurus-plugin-debug/tsconfig.json b/packages/docusaurus-plugin-debug/tsconfig.json index 18b9536626ad..65bf6a5b9e1a 100644 --- a/packages/docusaurus-plugin-debug/tsconfig.json +++ b/packages/docusaurus-plugin-debug/tsconfig.json @@ -1,10 +1,10 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "references": [{"path": "./tsconfig.client.json"}], "compilerOptions": { "noEmit": false, "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo", + "tsBuildInfoFile": "lib/.tsbuildinfo", "rootDir": "src", "outDir": "lib" }, diff --git a/packages/docusaurus-plugin-google-analytics/tsconfig.client.json b/packages/docusaurus-plugin-google-analytics/tsconfig.client.json index 7cf373d92f92..d9c0e68fff3a 100644 --- a/packages/docusaurus-plugin-google-analytics/tsconfig.client.json +++ b/packages/docusaurus-plugin-google-analytics/tsconfig.client.json @@ -1,15 +1,9 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.client.json", "compilerOptions": { - "noEmit": false, - "composite": true, - "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo-client", - "moduleResolution": "bundler", - "module": "esnext", - "target": "esnext", "rootDir": "src", - "outDir": "lib" + "outDir": "lib", + "tsBuildInfoFile": "lib/.tsbuildinfo-client" }, "include": ["src/analytics.ts", "src/*.d.ts"], "exclude": ["**/__tests__/**"] diff --git a/packages/docusaurus-plugin-google-analytics/tsconfig.json b/packages/docusaurus-plugin-google-analytics/tsconfig.json index c7fda37effc4..b3ccd5c0696a 100644 --- a/packages/docusaurus-plugin-google-analytics/tsconfig.json +++ b/packages/docusaurus-plugin-google-analytics/tsconfig.json @@ -1,10 +1,10 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "references": [{"path": "./tsconfig.client.json"}], "compilerOptions": { "noEmit": false, "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo", + "tsBuildInfoFile": "lib/.tsbuildinfo", "rootDir": "src", "outDir": "lib" }, diff --git a/packages/docusaurus-plugin-google-gtag/tsconfig.client.json b/packages/docusaurus-plugin-google-gtag/tsconfig.client.json index e31b80c88b1d..9d3fd42b756d 100644 --- a/packages/docusaurus-plugin-google-gtag/tsconfig.client.json +++ b/packages/docusaurus-plugin-google-gtag/tsconfig.client.json @@ -1,15 +1,9 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.client.json", "compilerOptions": { - "noEmit": false, - "composite": true, - "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo-client", - "moduleResolution": "bundler", - "module": "esnext", - "target": "esnext", "rootDir": "src", - "outDir": "lib" + "outDir": "lib", + "tsBuildInfoFile": "lib/.tsbuildinfo-client" }, "include": ["src/gtag.ts", "src/*.d.ts"], "exclude": ["**/__tests__/**"] diff --git a/packages/docusaurus-plugin-google-gtag/tsconfig.json b/packages/docusaurus-plugin-google-gtag/tsconfig.json index fe656511f355..d71de8f76746 100644 --- a/packages/docusaurus-plugin-google-gtag/tsconfig.json +++ b/packages/docusaurus-plugin-google-gtag/tsconfig.json @@ -1,10 +1,10 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "references": [{"path": "./tsconfig.client.json"}], "compilerOptions": { "noEmit": false, "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo", + "tsBuildInfoFile": "lib/.tsbuildinfo", "rootDir": "src", "outDir": "lib" }, diff --git a/packages/docusaurus-plugin-google-tag-manager/tsconfig.client.json b/packages/docusaurus-plugin-google-tag-manager/tsconfig.client.json index 3480c8bca6e4..ba742c0016b9 100644 --- a/packages/docusaurus-plugin-google-tag-manager/tsconfig.client.json +++ b/packages/docusaurus-plugin-google-tag-manager/tsconfig.client.json @@ -1,15 +1,9 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.client.json", "compilerOptions": { - "noEmit": false, - "composite": true, - "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo-client", - "moduleResolution": "bundler", - "module": "esnext", - "target": "esnext", "rootDir": "src", - "outDir": "lib" + "outDir": "lib", + "tsBuildInfoFile": "lib/.tsbuildinfo-client" }, "include": ["src/*.d.ts"], "exclude": ["**/__tests__/**"] diff --git a/packages/docusaurus-plugin-google-tag-manager/tsconfig.json b/packages/docusaurus-plugin-google-tag-manager/tsconfig.json index 1e49538f9ea2..b10e2ae30234 100644 --- a/packages/docusaurus-plugin-google-tag-manager/tsconfig.json +++ b/packages/docusaurus-plugin-google-tag-manager/tsconfig.json @@ -1,10 +1,10 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "references": [{"path": "./tsconfig.client.json"}], "compilerOptions": { "noEmit": false, "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo", + "tsBuildInfoFile": "lib/.tsbuildinfo", "rootDir": "src", "outDir": "lib" }, diff --git a/packages/docusaurus-plugin-ideal-image/tsconfig.client.json b/packages/docusaurus-plugin-ideal-image/tsconfig.client.json index e69d347194cc..c411568a6d43 100644 --- a/packages/docusaurus-plugin-ideal-image/tsconfig.client.json +++ b/packages/docusaurus-plugin-ideal-image/tsconfig.client.json @@ -1,15 +1,9 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.client.json", "compilerOptions": { - "noEmit": false, - "composite": true, - "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo-client", - "moduleResolution": "bundler", - "module": "esnext", - "target": "esnext", "rootDir": "src", - "outDir": "lib" + "outDir": "lib", + "tsBuildInfoFile": "lib/.tsbuildinfo-client" }, "include": ["src/theme", "src/*.d.ts"], "exclude": ["**/__tests__/**"] diff --git a/packages/docusaurus-plugin-ideal-image/tsconfig.json b/packages/docusaurus-plugin-ideal-image/tsconfig.json index 18b9536626ad..65bf6a5b9e1a 100644 --- a/packages/docusaurus-plugin-ideal-image/tsconfig.json +++ b/packages/docusaurus-plugin-ideal-image/tsconfig.json @@ -1,10 +1,10 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "references": [{"path": "./tsconfig.client.json"}], "compilerOptions": { "noEmit": false, "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo", + "tsBuildInfoFile": "lib/.tsbuildinfo", "rootDir": "src", "outDir": "lib" }, diff --git a/packages/docusaurus-plugin-pwa/tsconfig.client.json b/packages/docusaurus-plugin-pwa/tsconfig.client.json index 52fd7b2b3398..c0825ea0820f 100644 --- a/packages/docusaurus-plugin-pwa/tsconfig.client.json +++ b/packages/docusaurus-plugin-pwa/tsconfig.client.json @@ -1,15 +1,9 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.client.json", "compilerOptions": { - "noEmit": false, - "composite": true, - "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo-client", "rootDir": "src", "outDir": "lib", - "moduleResolution": "bundler", - "module": "esnext", - "target": "esnext" + "tsBuildInfoFile": "lib/.tsbuildinfo-client" }, "include": [ "src/theme/", diff --git a/packages/docusaurus-plugin-pwa/tsconfig.json b/packages/docusaurus-plugin-pwa/tsconfig.json index 0bef8e601656..555d8315d108 100644 --- a/packages/docusaurus-plugin-pwa/tsconfig.json +++ b/packages/docusaurus-plugin-pwa/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "references": [ {"path": "./tsconfig.client.json"}, {"path": "./tsconfig.worker.json"} @@ -7,7 +7,7 @@ "compilerOptions": { "noEmit": false, "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo", + "tsBuildInfoFile": "lib/.tsbuildinfo", "rootDir": "src", "outDir": "lib" }, diff --git a/packages/docusaurus-plugin-pwa/tsconfig.worker.json b/packages/docusaurus-plugin-pwa/tsconfig.worker.json index 7e3209535ad8..6316e841c235 100644 --- a/packages/docusaurus-plugin-pwa/tsconfig.worker.json +++ b/packages/docusaurus-plugin-pwa/tsconfig.worker.json @@ -1,11 +1,11 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "compilerOptions": { "noEmit": false, "composite": true, "incremental": true, "lib": ["webworker", "esnext"], - "tsBuildInfoFile": "./lib/.tsbuildinfo-worker", + "tsBuildInfoFile": "lib/.tsbuildinfo-worker", "rootDir": "src", "outDir": "lib", "moduleResolution": "bundler", diff --git a/packages/docusaurus-plugin-sitemap/tsconfig.json b/packages/docusaurus-plugin-sitemap/tsconfig.json index e16d5c2c5d33..0f463da3d702 100644 --- a/packages/docusaurus-plugin-sitemap/tsconfig.json +++ b/packages/docusaurus-plugin-sitemap/tsconfig.json @@ -1,9 +1,9 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "compilerOptions": { "noEmit": false, "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo", + "tsBuildInfoFile": "lib/.tsbuildinfo", "rootDir": "src", "outDir": "lib" }, diff --git a/packages/docusaurus-plugin-vercel-analytics/tsconfig.client.json b/packages/docusaurus-plugin-vercel-analytics/tsconfig.client.json index e77a5fd904ff..09a0864ae1fa 100644 --- a/packages/docusaurus-plugin-vercel-analytics/tsconfig.client.json +++ b/packages/docusaurus-plugin-vercel-analytics/tsconfig.client.json @@ -1,15 +1,9 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.client.json", "compilerOptions": { - "noEmit": false, - "composite": true, - "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo-client", - "moduleResolution": "bundler", - "module": "esnext", - "target": "esnext", "rootDir": "src", - "outDir": "lib" + "outDir": "lib", + "tsBuildInfoFile": "lib/.tsbuildinfo-client" }, "include": ["src/analytics.ts", "src/options.ts", "src/*.d.ts"], "exclude": ["**/__tests__/**"] diff --git a/packages/docusaurus-plugin-vercel-analytics/tsconfig.json b/packages/docusaurus-plugin-vercel-analytics/tsconfig.json index c7fda37effc4..b3ccd5c0696a 100644 --- a/packages/docusaurus-plugin-vercel-analytics/tsconfig.json +++ b/packages/docusaurus-plugin-vercel-analytics/tsconfig.json @@ -1,10 +1,10 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "references": [{"path": "./tsconfig.client.json"}], "compilerOptions": { "noEmit": false, "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo", + "tsBuildInfoFile": "lib/.tsbuildinfo", "rootDir": "src", "outDir": "lib" }, diff --git a/packages/docusaurus-preset-classic/tsconfig.json b/packages/docusaurus-preset-classic/tsconfig.json index e16d5c2c5d33..0f463da3d702 100644 --- a/packages/docusaurus-preset-classic/tsconfig.json +++ b/packages/docusaurus-preset-classic/tsconfig.json @@ -1,9 +1,9 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "compilerOptions": { "noEmit": false, "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo", + "tsBuildInfoFile": "lib/.tsbuildinfo", "rootDir": "src", "outDir": "lib" }, diff --git a/packages/docusaurus-remark-plugin-npm2yarn/tsconfig.json b/packages/docusaurus-remark-plugin-npm2yarn/tsconfig.json index 69bd9341b47e..6a904aac6f51 100644 --- a/packages/docusaurus-remark-plugin-npm2yarn/tsconfig.json +++ b/packages/docusaurus-remark-plugin-npm2yarn/tsconfig.json @@ -1,9 +1,9 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "compilerOptions": { "noEmit": false, "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo", + "tsBuildInfoFile": "lib/.tsbuildinfo", "sourceMap": true, "declarationMap": true, "rootDir": "src", diff --git a/packages/docusaurus-theme-classic/tsconfig.client.json b/packages/docusaurus-theme-classic/tsconfig.client.json index babbfc92e1cf..c034d3826b6c 100644 --- a/packages/docusaurus-theme-classic/tsconfig.client.json +++ b/packages/docusaurus-theme-classic/tsconfig.client.json @@ -1,15 +1,9 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.client.json", "compilerOptions": { - "noEmit": false, - "composite": true, - "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo-client", "rootDir": "src", "outDir": "lib", - "moduleResolution": "bundler", - "module": "esnext", - "target": "esnext" + "tsBuildInfoFile": "lib/.tsbuildinfo-client" }, "include": [ "src/nprogress.ts", diff --git a/packages/docusaurus-theme-classic/tsconfig.json b/packages/docusaurus-theme-classic/tsconfig.json index 8aa1157eefbc..1ede3dd6e17d 100644 --- a/packages/docusaurus-theme-classic/tsconfig.json +++ b/packages/docusaurus-theme-classic/tsconfig.json @@ -1,10 +1,10 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "references": [{"path": "./tsconfig.client.json"}], "compilerOptions": { "noEmit": false, "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo", + "tsBuildInfoFile": "lib/.tsbuildinfo", "rootDir": "src", "outDir": "lib" }, diff --git a/packages/docusaurus-theme-common/tsconfig.json b/packages/docusaurus-theme-common/tsconfig.json index c3110df9497f..226848d2d64a 100644 --- a/packages/docusaurus-theme-common/tsconfig.json +++ b/packages/docusaurus-theme-common/tsconfig.json @@ -1,16 +1,11 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.client.json", "compilerOptions": { - "noEmit": false, - "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo", - "moduleResolution": "bundler", - "module": "esnext", - "target": "esnext", - "sourceMap": true, - "declarationMap": true, "rootDir": "src", - "outDir": "lib" + "outDir": "lib", + "tsBuildInfoFile": "lib/.tsbuildinfo-client", + "sourceMap": true, + "declarationMap": true }, "include": ["src"], "exclude": ["**/__tests__/**"] diff --git a/packages/docusaurus-theme-live-codeblock/tsconfig.client.json b/packages/docusaurus-theme-live-codeblock/tsconfig.client.json index 361e08ae7d3d..20d299c51897 100644 --- a/packages/docusaurus-theme-live-codeblock/tsconfig.client.json +++ b/packages/docusaurus-theme-live-codeblock/tsconfig.client.json @@ -1,15 +1,9 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.client.json", "compilerOptions": { - "noEmit": false, - "composite": true, - "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo-client", "rootDir": "src", "outDir": "lib", - "moduleResolution": "bundler", - "module": "esnext", - "target": "esnext" + "tsBuildInfoFile": "lib/.tsbuildinfo-client" }, "include": ["src/theme", "src/*.d.ts", "src/custom-buble.ts"], "exclude": ["**/__tests__/**"] diff --git a/packages/docusaurus-theme-live-codeblock/tsconfig.json b/packages/docusaurus-theme-live-codeblock/tsconfig.json index a6dc07deeeee..fecfd3133ad3 100644 --- a/packages/docusaurus-theme-live-codeblock/tsconfig.json +++ b/packages/docusaurus-theme-live-codeblock/tsconfig.json @@ -1,10 +1,10 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "references": [{"path": "./tsconfig.client.json"}], "compilerOptions": { "noEmit": false, "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo", + "tsBuildInfoFile": "lib/.tsbuildinfo", "rootDir": "src", "outDir": "lib" }, diff --git a/packages/docusaurus-theme-mermaid/tsconfig.client.json b/packages/docusaurus-theme-mermaid/tsconfig.client.json index a8a71b6cad65..394b25d2a35e 100644 --- a/packages/docusaurus-theme-mermaid/tsconfig.client.json +++ b/packages/docusaurus-theme-mermaid/tsconfig.client.json @@ -1,15 +1,9 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.client.json", "compilerOptions": { - "noEmit": false, - "composite": true, - "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo-client", "rootDir": "src", "outDir": "lib", - "moduleResolution": "bundler", - "module": "esnext", - "target": "esnext" + "tsBuildInfoFile": "lib/.tsbuildinfo-client" }, "include": ["src/client", "src/theme", "src/*.d.ts"], "exclude": ["**/__tests__/**"] diff --git a/packages/docusaurus-theme-mermaid/tsconfig.json b/packages/docusaurus-theme-mermaid/tsconfig.json index 4eb745d80ce7..7ce7f61f550f 100644 --- a/packages/docusaurus-theme-mermaid/tsconfig.json +++ b/packages/docusaurus-theme-mermaid/tsconfig.json @@ -1,10 +1,10 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "references": [{"path": "./tsconfig.client.json"}], "compilerOptions": { "noEmit": false, "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo", + "tsBuildInfoFile": "lib/.tsbuildinfo", "rootDir": "src", "outDir": "lib" }, diff --git a/packages/docusaurus-theme-search-algolia/tsconfig.client.json b/packages/docusaurus-theme-search-algolia/tsconfig.client.json index 46cf1129e28f..2d3e8ea69414 100644 --- a/packages/docusaurus-theme-search-algolia/tsconfig.client.json +++ b/packages/docusaurus-theme-search-algolia/tsconfig.client.json @@ -1,15 +1,9 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.client.json", "compilerOptions": { - "noEmit": false, - "composite": true, - "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo-client", "rootDir": "src", "outDir": "lib", - "moduleResolution": "bundler", - "module": "esnext", - "target": "esnext" + "tsBuildInfoFile": "lib/.tsbuildinfo-client" }, "include": ["src/theme", "src/client", "src/*.d.ts"], "exclude": ["**/__tests__/**"] diff --git a/packages/docusaurus-theme-search-algolia/tsconfig.json b/packages/docusaurus-theme-search-algolia/tsconfig.json index 4eb745d80ce7..7ce7f61f550f 100644 --- a/packages/docusaurus-theme-search-algolia/tsconfig.json +++ b/packages/docusaurus-theme-search-algolia/tsconfig.json @@ -1,10 +1,10 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "references": [{"path": "./tsconfig.client.json"}], "compilerOptions": { "noEmit": false, "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo", + "tsBuildInfoFile": "lib/.tsbuildinfo", "rootDir": "src", "outDir": "lib" }, diff --git a/packages/docusaurus-theme-translations/tsconfig.build.json b/packages/docusaurus-theme-translations/tsconfig.build.json index 912de0a933a8..377da210d5da 100644 --- a/packages/docusaurus-theme-translations/tsconfig.build.json +++ b/packages/docusaurus-theme-translations/tsconfig.build.json @@ -1,10 +1,10 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "compilerOptions": { "noEmit": false, "composite": true, "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo", + "tsBuildInfoFile": "lib/.tsbuildinfo", "sourceMap": true, "declarationMap": true, "rootDir": "src", diff --git a/packages/docusaurus-theme-translations/tsconfig.json b/packages/docusaurus-theme-translations/tsconfig.json index 6ba7dee96bcd..c0dddebdf608 100644 --- a/packages/docusaurus-theme-translations/tsconfig.json +++ b/packages/docusaurus-theme-translations/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "references": [{"path": "./tsconfig.build.json"}], "compilerOptions": { "noEmit": true, diff --git a/packages/docusaurus-utils-common/tsconfig.json b/packages/docusaurus-utils-common/tsconfig.json index 0e5365a3c1e8..6be28b4e8f78 100644 --- a/packages/docusaurus-utils-common/tsconfig.json +++ b/packages/docusaurus-utils-common/tsconfig.json @@ -1,9 +1,9 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "compilerOptions": { "noEmit": false, "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo", + "tsBuildInfoFile": "lib/.tsbuildinfo", "sourceMap": true, "declarationMap": true, "rootDir": "src", diff --git a/packages/docusaurus-utils-validation/tsconfig.json b/packages/docusaurus-utils-validation/tsconfig.json index 69bd9341b47e..6a904aac6f51 100644 --- a/packages/docusaurus-utils-validation/tsconfig.json +++ b/packages/docusaurus-utils-validation/tsconfig.json @@ -1,9 +1,9 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "compilerOptions": { "noEmit": false, "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo", + "tsBuildInfoFile": "lib/.tsbuildinfo", "sourceMap": true, "declarationMap": true, "rootDir": "src", diff --git a/packages/docusaurus-utils/tsconfig.json b/packages/docusaurus-utils/tsconfig.json index 69bd9341b47e..6a904aac6f51 100644 --- a/packages/docusaurus-utils/tsconfig.json +++ b/packages/docusaurus-utils/tsconfig.json @@ -1,9 +1,9 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "compilerOptions": { "noEmit": false, "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo", + "tsBuildInfoFile": "lib/.tsbuildinfo", "sourceMap": true, "declarationMap": true, "rootDir": "src", diff --git a/packages/docusaurus/tsconfig.client.json b/packages/docusaurus/tsconfig.client.json index 5d06aa818c96..5e2b6e245224 100644 --- a/packages/docusaurus/tsconfig.client.json +++ b/packages/docusaurus/tsconfig.client.json @@ -1,15 +1,9 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.client.json", "compilerOptions": { - "noEmit": false, - "composite": true, - "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo-client", - "moduleResolution": "bundler", - "module": "esnext", - "target": "esnext", "rootDir": "src", - "outDir": "lib" + "outDir": "lib", + "tsBuildInfoFile": "lib/.tsbuildinfo-client" }, "include": ["src/client", "src/*.d.ts"], "exclude": ["**/__tests__/**"] diff --git a/packages/docusaurus/tsconfig.json b/packages/docusaurus/tsconfig.json index 80dfc91440a4..253a34db6ca4 100644 --- a/packages/docusaurus/tsconfig.json +++ b/packages/docusaurus/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "references": [ {"path": "./tsconfig.server.json"}, {"path": "./tsconfig.client.json"} diff --git a/packages/docusaurus/tsconfig.server.json b/packages/docusaurus/tsconfig.server.json index e26c376455c3..b55af5720ab9 100644 --- a/packages/docusaurus/tsconfig.server.json +++ b/packages/docusaurus/tsconfig.server.json @@ -1,10 +1,10 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "compilerOptions": { "noEmit": false, "composite": true, "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo", + "tsBuildInfoFile": "lib/.tsbuildinfo", "rootDir": "src", "outDir": "lib" }, diff --git a/packages/eslint-plugin/tsconfig.json b/packages/eslint-plugin/tsconfig.json index e16d5c2c5d33..0f463da3d702 100644 --- a/packages/eslint-plugin/tsconfig.json +++ b/packages/eslint-plugin/tsconfig.json @@ -1,9 +1,9 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "compilerOptions": { "noEmit": false, "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo", + "tsBuildInfoFile": "lib/.tsbuildinfo", "rootDir": "src", "outDir": "lib" }, diff --git a/packages/lqip-loader/tsconfig.json b/packages/lqip-loader/tsconfig.json index e16d5c2c5d33..0f463da3d702 100644 --- a/packages/lqip-loader/tsconfig.json +++ b/packages/lqip-loader/tsconfig.json @@ -1,9 +1,9 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "compilerOptions": { "noEmit": false, "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo", + "tsBuildInfoFile": "lib/.tsbuildinfo", "rootDir": "src", "outDir": "lib" }, diff --git a/packages/stylelint-copyright/tsconfig.json b/packages/stylelint-copyright/tsconfig.json index e16d5c2c5d33..0f463da3d702 100644 --- a/packages/stylelint-copyright/tsconfig.json +++ b/packages/stylelint-copyright/tsconfig.json @@ -1,9 +1,9 @@ { - "extends": "../../tsconfig.json", + "extends": "../../tsconfig.base.json", "compilerOptions": { "noEmit": false, "incremental": true, - "tsBuildInfoFile": "./lib/.tsbuildinfo", + "tsBuildInfoFile": "lib/.tsbuildinfo", "rootDir": "src", "outDir": "lib" }, diff --git a/tsconfig.base.client.json b/tsconfig.base.client.json new file mode 100644 index 000000000000..186c9e90df12 --- /dev/null +++ b/tsconfig.base.client.json @@ -0,0 +1,11 @@ +{ + "extends": "./tsconfig.base.json", + "compilerOptions": { + "noEmit": false, + "composite": true, + "incremental": true, + "moduleResolution": "bundler", + "module": "esnext", + "target": "esnext" + } +} diff --git a/tsconfig.json b/tsconfig.base.json similarity index 100% rename from tsconfig.json rename to tsconfig.base.json From 6d7f80ba306c913e5eae6a2be76862e031bc8b15 Mon Sep 17 00:00:00 2001 From: Alexey Ivanov Date: Mon, 22 Apr 2024 01:26:03 +0900 Subject: [PATCH 5/8] Add config validation and make all options optional --- packages/docusaurus-types/src/config.d.ts | 5 +---- packages/docusaurus/src/server/configValidation.ts | 8 ++++++++ website/docs/api/docusaurus.config.js.mdx | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/docusaurus-types/src/config.d.ts b/packages/docusaurus-types/src/config.d.ts index d20d5dbb8de0..60cb38f56789 100644 --- a/packages/docusaurus-types/src/config.d.ts +++ b/packages/docusaurus-types/src/config.d.ts @@ -103,10 +103,7 @@ export type MarkdownConfig = { remarkRehypeOptions: RemarkRehypeOptions; anchors?: { - /** - * Ability to preserve the case of the heading anchor links. - */ - maintainCase: boolean; + maintainCase?: boolean; }; }; diff --git a/packages/docusaurus/src/server/configValidation.ts b/packages/docusaurus/src/server/configValidation.ts index cf2d16aa59f5..c3d6ec045679 100644 --- a/packages/docusaurus/src/server/configValidation.ts +++ b/packages/docusaurus/src/server/configValidation.ts @@ -41,6 +41,9 @@ export const DEFAULT_MARKDOWN_CONFIG: MarkdownConfig = { admonitions: true, headingIds: true, }, + anchors: { + maintainCase: false, + }, remarkRehypeOptions: undefined, }; @@ -320,6 +323,11 @@ export const ConfigSchema = Joi.object({ // Not sure if it's a good idea, validation is likely to become stale // See https://github.com/remarkjs/remark-rehype#options Joi.object().unknown(), + anchors: Joi.object({ + maintainCase: Joi.boolean().default( + DEFAULT_CONFIG.markdown.anchors?.maintainCase, + ), + }), }).default(DEFAULT_CONFIG.markdown), }).messages({ 'docusaurus.configValidationWarning': diff --git a/website/docs/api/docusaurus.config.js.mdx b/website/docs/api/docusaurus.config.js.mdx index 049422e84bcd..d20a836d919e 100644 --- a/website/docs/api/docusaurus.config.js.mdx +++ b/website/docs/api/docusaurus.config.js.mdx @@ -446,7 +446,7 @@ type MarkdownConfig = { mdx1Compat: MDX1CompatOptions; remarkRehypeOptions: object; // see https://github.com/remarkjs/remark-rehype#options anchors?: { - maintainCase: boolean; + maintainCase?: boolean; }; }; ``` From a673b6ff714641dabfd51f3989de38a29d33af1c Mon Sep 17 00:00:00 2001 From: sebastien Date: Thu, 25 Apr 2024 15:31:29 +0200 Subject: [PATCH 6/8] Adjust little details --- .../docusaurus-mdx-loader/src/processor.ts | 13 +++++++- .../remark/headings/__tests__/index.test.ts | 19 +++++++----- .../src/remark/headings/index.ts | 12 ++++---- .../src/remark/toc/__tests__/index.test.ts | 2 +- packages/docusaurus-types/src/config.d.ts | 11 +++++-- .../__snapshots__/config.test.ts.snap | 30 +++++++++++++++++++ .../__tests__/__snapshots__/site.test.ts.snap | 3 ++ .../server/__tests__/configValidation.test.ts | 6 ++++ .../docusaurus/src/server/configValidation.ts | 4 +-- website/docs/api/docusaurus.config.js.mdx | 9 ++++-- 10 files changed, 87 insertions(+), 22 deletions(-) diff --git a/packages/docusaurus-mdx-loader/src/processor.ts b/packages/docusaurus-mdx-loader/src/processor.ts index a4172a7c324a..b2224758e179 100644 --- a/packages/docusaurus-mdx-loader/src/processor.ts +++ b/packages/docusaurus-mdx-loader/src/processor.ts @@ -83,6 +83,17 @@ async function createProcessorFactory() { const {VFile} = await import('vfile'); const {default: emoji} = await import('remark-emoji'); + function getDefaultRemarkPlugins({options}: {options: Options}): MDXPlugin[] { + return [ + [ + headings, + {anchorsMaintainCase: options.markdownConfig.anchors.maintainCase}, + ], + emoji, + toc, + ]; + } + // /!\ this method is synchronous on purpose // Using async code here can create cache entry race conditions! function createProcessorSync({ @@ -98,7 +109,7 @@ async function createProcessorFactory() { directive, [contentTitle, {removeContentTitle: options.removeContentTitle}], ...getAdmonitionsPlugins(options.admonitions ?? false), - [headings, options.markdownConfig.anchors], + ...getDefaultRemarkPlugins({options}), emoji, toc, details, diff --git a/packages/docusaurus-mdx-loader/src/remark/headings/__tests__/index.test.ts b/packages/docusaurus-mdx-loader/src/remark/headings/__tests__/index.test.ts index 0f0ab6317edb..3e5aa89636b2 100644 --- a/packages/docusaurus-mdx-loader/src/remark/headings/__tests__/index.test.ts +++ b/packages/docusaurus-mdx-loader/src/remark/headings/__tests__/index.test.ts @@ -11,7 +11,7 @@ import u from 'unist-builder'; import {removePosition} from 'unist-util-remove-position'; import {toString} from 'mdast-util-to-string'; import {visit} from 'unist-util-visit'; -import slug from '../index'; +import plugin from '../index'; import type {PluginOptions} from '../index'; import type {Plugin} from 'unified'; import type {Parent} from 'unist'; @@ -19,11 +19,11 @@ import type {Parent} from 'unist'; async function process( doc: string, plugins: Plugin[] = [], - options: PluginOptions = {maintainCase: false}, + options: PluginOptions = {anchorsMaintainCase: false}, ) { const {remark} = await import('remark'); const processor = await remark().use({ - plugins: [...plugins, [slug, options]], + plugins: [...plugins, [plugin, options]], }); const result = await processor.run(processor.parse(doc)); removePosition(result, {force: true}); @@ -320,16 +320,21 @@ describe('headings remark plugin', () => { ]); }); - it('preserve anchors case then "maintainCase" option is set', async () => { - const result = await process('# Normal\n', [], {maintainCase: true}); + it('preserve anchors case then "anchorsMaintainCase" option is set', async () => { + const result = await process('# Case Sensitive Heading', [], { + anchorsMaintainCase: true, + }); const expected = u('root', [ u( 'heading', { depth: 1, - data: {hProperties: {id: 'Normal'}, id: 'Normal'}, + data: { + hProperties: {id: 'Case-Sensitive-Heading'}, + id: 'Case-Sensitive-Heading', + }, }, - [u('text', 'Normal')], + [u('text', 'Case Sensitive Heading')], ), ]); diff --git a/packages/docusaurus-mdx-loader/src/remark/headings/index.ts b/packages/docusaurus-mdx-loader/src/remark/headings/index.ts index a43aafd5efc4..5f2250a9c17e 100644 --- a/packages/docusaurus-mdx-loader/src/remark/headings/index.ts +++ b/packages/docusaurus-mdx-loader/src/remark/headings/index.ts @@ -13,12 +13,12 @@ import type {Transformer} from 'unified'; import type {Heading, Text} from 'mdast'; export interface PluginOptions { - maintainCase: boolean; + anchorsMaintainCase: boolean; } -export default function plugin( - {maintainCase}: PluginOptions = {maintainCase: false}, -): Transformer { +export default function plugin({ + anchorsMaintainCase, +}: PluginOptions): Transformer { return async (root) => { const {toString} = await import('mdast-util-to-string'); const {visit} = await import('unist-util-visit'); @@ -44,7 +44,9 @@ export default function plugin( // Support explicit heading IDs const parsedHeading = parseMarkdownHeadingId(heading); - id = parsedHeading.id ?? slugs.slug(heading, {maintainCase}); + id = + parsedHeading.id ?? + slugs.slug(heading, {maintainCase: anchorsMaintainCase}); if (parsedHeading.id) { // When there's an id, it is always in the last child node diff --git a/packages/docusaurus-mdx-loader/src/remark/toc/__tests__/index.test.ts b/packages/docusaurus-mdx-loader/src/remark/toc/__tests__/index.test.ts index 87bc5c6793dd..c246a7bcfedd 100644 --- a/packages/docusaurus-mdx-loader/src/remark/toc/__tests__/index.test.ts +++ b/packages/docusaurus-mdx-loader/src/remark/toc/__tests__/index.test.ts @@ -25,7 +25,7 @@ const processFixture = async (name: string) => { const result = await compile(file, { format: 'mdx', - remarkPlugins: [headings, gfm, plugin], + remarkPlugins: [[headings, {anchorsMaintainCase: false}], gfm, plugin], rehypePlugins: [], }); diff --git a/packages/docusaurus-types/src/config.d.ts b/packages/docusaurus-types/src/config.d.ts index 60cb38f56789..9d1d590d590a 100644 --- a/packages/docusaurus-types/src/config.d.ts +++ b/packages/docusaurus-types/src/config.d.ts @@ -45,6 +45,13 @@ export type ParseFrontMatter = ( }, ) => Promise; +export type MarkdownAnchorsConfig = { + /** + * Preserves the case of the heading text when generating anchor ids. + */ + maintainCase: boolean; +}; + export type MarkdownConfig = { /** * The Markdown format to use by default. @@ -102,9 +109,7 @@ export type MarkdownConfig = { */ remarkRehypeOptions: RemarkRehypeOptions; - anchors?: { - maintainCase?: boolean; - }; + anchors: MarkdownAnchorsConfig; }; /** 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 c10c4833901e..72d6a58aa5a8 100644 --- a/packages/docusaurus/src/server/__tests__/__snapshots__/config.test.ts.snap +++ b/packages/docusaurus/src/server/__tests__/__snapshots__/config.test.ts.snap @@ -17,6 +17,9 @@ exports[`loadSiteConfig website with .cjs siteConfig 1`] = ` "path": "i18n", }, "markdown": { + "anchors": { + "maintainCase": false, + }, "format": "mdx", "mdx1Compat": { "admonitions": true, @@ -68,6 +71,9 @@ exports[`loadSiteConfig website with ts + js config 1`] = ` "path": "i18n", }, "markdown": { + "anchors": { + "maintainCase": false, + }, "format": "mdx", "mdx1Compat": { "admonitions": true, @@ -119,6 +125,9 @@ exports[`loadSiteConfig website with valid JS CJS config 1`] = ` "path": "i18n", }, "markdown": { + "anchors": { + "maintainCase": false, + }, "format": "mdx", "mdx1Compat": { "admonitions": true, @@ -170,6 +179,9 @@ exports[`loadSiteConfig website with valid JS ESM config 1`] = ` "path": "i18n", }, "markdown": { + "anchors": { + "maintainCase": false, + }, "format": "mdx", "mdx1Compat": { "admonitions": true, @@ -221,6 +233,9 @@ exports[`loadSiteConfig website with valid TypeScript CJS config 1`] = ` "path": "i18n", }, "markdown": { + "anchors": { + "maintainCase": false, + }, "format": "mdx", "mdx1Compat": { "admonitions": true, @@ -272,6 +287,9 @@ exports[`loadSiteConfig website with valid TypeScript ESM config 1`] = ` "path": "i18n", }, "markdown": { + "anchors": { + "maintainCase": false, + }, "format": "mdx", "mdx1Compat": { "admonitions": true, @@ -323,6 +341,9 @@ exports[`loadSiteConfig website with valid async config 1`] = ` "path": "i18n", }, "markdown": { + "anchors": { + "maintainCase": false, + }, "format": "mdx", "mdx1Compat": { "admonitions": true, @@ -376,6 +397,9 @@ exports[`loadSiteConfig website with valid async config creator function 1`] = ` "path": "i18n", }, "markdown": { + "anchors": { + "maintainCase": false, + }, "format": "mdx", "mdx1Compat": { "admonitions": true, @@ -429,6 +453,9 @@ exports[`loadSiteConfig website with valid config creator function 1`] = ` "path": "i18n", }, "markdown": { + "anchors": { + "maintainCase": false, + }, "format": "mdx", "mdx1Compat": { "admonitions": true, @@ -485,6 +512,9 @@ exports[`loadSiteConfig website with valid siteConfig 1`] = ` "path": "i18n", }, "markdown": { + "anchors": { + "maintainCase": false, + }, "format": "mdx", "mdx1Compat": { "admonitions": true, 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 8a48af985e45..c2562812b70f 100644 --- a/packages/docusaurus/src/server/__tests__/__snapshots__/site.test.ts.snap +++ b/packages/docusaurus/src/server/__tests__/__snapshots__/site.test.ts.snap @@ -97,6 +97,9 @@ exports[`load loads props for site with custom i18n path 1`] = ` "path": "i18n", }, "markdown": { + "anchors": { + "maintainCase": false, + }, "format": "mdx", "mdx1Compat": { "admonitions": true, diff --git a/packages/docusaurus/src/server/__tests__/configValidation.test.ts b/packages/docusaurus/src/server/__tests__/configValidation.test.ts index ea76af81408b..c20ff6431493 100644 --- a/packages/docusaurus/src/server/__tests__/configValidation.test.ts +++ b/packages/docusaurus/src/server/__tests__/configValidation.test.ts @@ -69,6 +69,9 @@ describe('normalizeConfig', () => { admonitions: false, headingIds: true, }, + anchors: { + maintainCase: true, + }, remarkRehypeOptions: { footnoteLabel: 'Pied de page', }, @@ -517,6 +520,9 @@ describe('markdown', () => { admonitions: true, headingIds: false, }, + anchors: { + maintainCase: true, + }, remarkRehypeOptions: { footnoteLabel: 'Notes de bas de page', // @ts-expect-error: we don't validate it on purpose diff --git a/packages/docusaurus/src/server/configValidation.ts b/packages/docusaurus/src/server/configValidation.ts index c3d6ec045679..3f6fac5fb174 100644 --- a/packages/docusaurus/src/server/configValidation.ts +++ b/packages/docusaurus/src/server/configValidation.ts @@ -325,9 +325,9 @@ export const ConfigSchema = Joi.object({ Joi.object().unknown(), anchors: Joi.object({ maintainCase: Joi.boolean().default( - DEFAULT_CONFIG.markdown.anchors?.maintainCase, + DEFAULT_CONFIG.markdown.anchors.maintainCase, ), - }), + }).default(DEFAULT_CONFIG.markdown.anchors), }).default(DEFAULT_CONFIG.markdown), }).messages({ 'docusaurus.configValidationWarning': diff --git a/website/docs/api/docusaurus.config.js.mdx b/website/docs/api/docusaurus.config.js.mdx index d20a836d919e..116f070bada6 100644 --- a/website/docs/api/docusaurus.config.js.mdx +++ b/website/docs/api/docusaurus.config.js.mdx @@ -438,6 +438,10 @@ export type ParseFrontMatter = (params: { content: string; }>; +type MarkdownAnchorsConfig = { + maintainCase: boolean; +}; + type MarkdownConfig = { format: 'mdx' | 'md' | 'detect'; mermaid: boolean; @@ -445,9 +449,7 @@ type MarkdownConfig = { parseFrontMatter?: ParseFrontMatter; mdx1Compat: MDX1CompatOptions; remarkRehypeOptions: object; // see https://github.com/remarkjs/remark-rehype#options - anchors?: { - maintainCase?: boolean; - }; + anchors: MarkdownAnchorsConfig; }; ``` @@ -490,6 +492,7 @@ export default { | `preprocessor` | `MarkdownPreprocessor` | `undefined` | Gives you the ability to alter the Markdown content string before parsing. Use it as a last-resort escape hatch or workaround: it is almost always better to implement a Remark/Rehype plugin. | | `parseFrontMatter` | `ParseFrontMatter` | `undefined` | Gives you the ability to provide your own front matter parser, or to enhance the default parser. Read our [front matter guide](../guides/markdown-features/markdown-features-intro.mdx#front-matter) for details. | | `mdx1Compat` | `MDX1CompatOptions` | `{comments: true, admonitions: true, headingIds: true}` | Compatibility options to make it easier to upgrade to Docusaurus v3+. | +| `anchors` | `MarkdownAnchorsConfig` | `{maintainCase: false}` | Options related to anchors generated from Markdown headings | | `remarkRehypeOptions` | `object` | `undefined` | Makes it possible to pass custom [`remark-rehype` options](https://github.com/remarkjs/remark-rehype#options). | ```mdx-code-block From bf9e811f7ab92d363aabc0b1e615525dd215fd18 Mon Sep 17 00:00:00 2001 From: sebastien Date: Thu, 25 Apr 2024 15:32:06 +0200 Subject: [PATCH 7/8] typo --- packages/docusaurus-mdx-loader/src/processor.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/docusaurus-mdx-loader/src/processor.ts b/packages/docusaurus-mdx-loader/src/processor.ts index b2224758e179..778bfce1ba47 100644 --- a/packages/docusaurus-mdx-loader/src/processor.ts +++ b/packages/docusaurus-mdx-loader/src/processor.ts @@ -110,8 +110,6 @@ async function createProcessorFactory() { [contentTitle, {removeContentTitle: options.removeContentTitle}], ...getAdmonitionsPlugins(options.admonitions ?? false), ...getDefaultRemarkPlugins({options}), - emoji, - toc, details, head, ...(options.markdownConfig.mermaid ? [mermaid] : []), From 729759479a0b7c7bb0f055c01d7f1b71e35ea1fc Mon Sep 17 00:00:00 2001 From: sebastien Date: Thu, 25 Apr 2024 15:36:06 +0200 Subject: [PATCH 8/8] nit --- packages/docusaurus-types/src/config.d.ts | 3 +++ website/docs/api/docusaurus.config.js.mdx | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/docusaurus-types/src/config.d.ts b/packages/docusaurus-types/src/config.d.ts index 9d1d590d590a..62627281cc66 100644 --- a/packages/docusaurus-types/src/config.d.ts +++ b/packages/docusaurus-types/src/config.d.ts @@ -109,6 +109,9 @@ export type MarkdownConfig = { */ remarkRehypeOptions: RemarkRehypeOptions; + /** + * Options to control the behavior of anchors generated from Markdown headings + */ anchors: MarkdownAnchorsConfig; }; diff --git a/website/docs/api/docusaurus.config.js.mdx b/website/docs/api/docusaurus.config.js.mdx index 116f070bada6..2a346d2e2eff 100644 --- a/website/docs/api/docusaurus.config.js.mdx +++ b/website/docs/api/docusaurus.config.js.mdx @@ -492,7 +492,7 @@ export default { | `preprocessor` | `MarkdownPreprocessor` | `undefined` | Gives you the ability to alter the Markdown content string before parsing. Use it as a last-resort escape hatch or workaround: it is almost always better to implement a Remark/Rehype plugin. | | `parseFrontMatter` | `ParseFrontMatter` | `undefined` | Gives you the ability to provide your own front matter parser, or to enhance the default parser. Read our [front matter guide](../guides/markdown-features/markdown-features-intro.mdx#front-matter) for details. | | `mdx1Compat` | `MDX1CompatOptions` | `{comments: true, admonitions: true, headingIds: true}` | Compatibility options to make it easier to upgrade to Docusaurus v3+. | -| `anchors` | `MarkdownAnchorsConfig` | `{maintainCase: false}` | Options related to anchors generated from Markdown headings | +| `anchors` | `MarkdownAnchorsConfig` | `{maintainCase: false}` | Options to control the behavior of anchors generated from Markdown headings | | `remarkRehypeOptions` | `object` | `undefined` | Makes it possible to pass custom [`remark-rehype` options](https://github.com/remarkjs/remark-rehype#options). | ```mdx-code-block