diff --git a/jest/deps.d.ts b/jest/deps.d.ts index a0694f5b8128..16ad1b75fdbd 100644 --- a/jest/deps.d.ts +++ b/jest/deps.d.ts @@ -7,9 +7,18 @@ // modules only used in tests -declare module 'to-vfile'; +declare module 'to-vfile' { + import type {VFile} from 'vfile'; -declare module 'remark-mdx'; + export function read(path: string, encoding?: string): Promise; +} + +declare module 'remark-mdx' { + import type {Plugin} from 'unified'; + + const mdx: Plugin; + export = mdx; +} declare module '@testing-utils/git' { const createTempRepo: typeof import('./utils/git').createTempRepo; diff --git a/packages/docusaurus-cssnano-preset/src/remove-overridden-custom-properties/__tests__/index.test.ts b/packages/docusaurus-cssnano-preset/src/remove-overridden-custom-properties/__tests__/index.test.ts index 8e50db5a74bd..9ce352bd90c5 100644 --- a/packages/docusaurus-cssnano-preset/src/remove-overridden-custom-properties/__tests__/index.test.ts +++ b/packages/docusaurus-cssnano-preset/src/remove-overridden-custom-properties/__tests__/index.test.ts @@ -10,8 +10,8 @@ import vfile from 'to-vfile'; import postcss from 'postcss'; import postCssRemoveOverriddenCustomProperties from '../index'; -const processFixture = (name: string) => { - const input = vfile.readSync( +const processFixture = async (name: string) => { + const input = await vfile.read( path.join(__dirname, '__fixtures__', `${name}.css`), 'utf8', ); @@ -23,11 +23,11 @@ const processFixture = (name: string) => { }; describe('remove-overridden-custom-properties', () => { - it('overridden custom properties should be removed', () => { - expect(processFixture('normal')).toMatchSnapshot(); + it('overridden custom properties should be removed', async () => { + await expect(processFixture('normal')).resolves.toMatchSnapshot(); }); - it('overridden custom properties with `!important` rule should not be removed', () => { - expect(processFixture('important_rule')).toMatchSnapshot(); + it('overridden custom properties with `!important` rule should not be removed', async () => { + await expect(processFixture('important_rule')).resolves.toMatchSnapshot(); }); }); diff --git a/packages/docusaurus-migrate/src/index.ts b/packages/docusaurus-migrate/src/index.ts index 165c7c2fd32f..f5bf38134bc0 100644 --- a/packages/docusaurus-migrate/src/index.ts +++ b/packages/docusaurus-migrate/src/index.ts @@ -552,7 +552,7 @@ async function migrateVersionedSidebar( (topLevel: SidebarEntries, value) => { const key = value[0].replace(versionRegex, ''); topLevel[key] = Object.entries(value[1]).reduce<{ - [key: string]: Array; + [key: string]: (string | {[key: string]: unknown})[]; }>((acc, val) => { acc[val[0].replace(versionRegex, '')] = ( val[1] as SidebarEntry[] diff --git a/packages/docusaurus-migrate/src/types.ts b/packages/docusaurus-migrate/src/types.ts index 022139f3489d..39b5fc2d53ae 100644 --- a/packages/docusaurus-migrate/src/types.ts +++ b/packages/docusaurus-migrate/src/types.ts @@ -34,7 +34,7 @@ export type SidebarEntry = export type SidebarEntries = { [key: string]: | {[key: string]: unknown} - | Array<{[key: string]: unknown} | string>; + | ({[key: string]: unknown} | string)[]; }; export type VersionTwoConfig = { @@ -49,7 +49,7 @@ export type VersionTwoConfig = { githubHost?: string; onBrokenLinks: string; onBrokenMarkdownLinks: string; - plugins: Array<[string, {[key: string]: unknown}]>; + plugins: [string, {[key: string]: unknown}][]; themes?: []; presets: [[string, ClassicPresetEntries]]; themeConfig: { @@ -58,17 +58,14 @@ export type VersionTwoConfig = { logo?: { src?: string; }; - items: Array<{[key: string]: unknown} | null>; + items: ({[key: string]: unknown} | null)[]; }; image?: string; footer: { - links: Array<{ + links: { title: string; - items: Array<{ - label: string; - to: string; - }>; - }>; + items: {label: string; to: string}[]; + }[]; copyright?: string; logo: { src?: string; @@ -104,26 +101,26 @@ export type VersionOneConfig = { organizationName?: string; projectName?: string; noIndex?: boolean; - headerLinks?: Array<{doc: string; href: string; label: string; page: string}>; + headerLinks?: {doc: string; href: string; label: string; page: string}[]; headerIcon?: string; favicon?: string; colors?: {primaryColor: string}; copyright?: string; editUrl?: string; customDocsPath?: string; - users?: Array<{[key: string]: unknown}>; + users?: {[key: string]: unknown}[]; disableHeaderTitle?: string; disableTitleTagline?: string; - separateCss?: Array<{[key: string]: unknown}>; + separateCss?: {[key: string]: unknown}[]; footerIcon?: string; translationRecruitingLink?: string; algolia?: {[key: string]: unknown}; gaTrackingId?: string; gaGtag?: boolean; highlight?: {[key: string]: unknown}; - markdownPlugins?: Array<() => void>; - scripts?: Array<{src: string; [key: string]: unknown} | string>; - stylesheets?: Array<{href: string; [key: string]: unknown} | string>; + markdownPlugins?: (() => void)[]; + scripts?: ({src: string; [key: string]: unknown} | string)[]; + stylesheets?: ({href: string; [key: string]: unknown} | string)[]; facebookAppId?: string; facebookComments?: true; facebookPixelId?: string; 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 746288ca95e9..11e54417d884 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts @@ -31,6 +31,7 @@ import type { Options, PluginOptions, PropSidebarItemLink, + PropSidebars, } from '@docusaurus/plugin-content-docs'; import type { SidebarItemsGeneratorOption, @@ -82,7 +83,7 @@ const createFakeActions = (contentDir: string) => { // Query by prefix, because files have a hash at the end so it's not // convenient to query by full filename - const getCreatedDataByPrefix = (prefix: string) => { + function getCreatedDataByPrefix(prefix: string) { const entry = Object.entries(dataContainer).find(([key]) => key.startsWith(prefix), ); @@ -92,8 +93,8 @@ Entries created: - ${Object.keys(dataContainer).join('\n- ')} `); } - return JSON.parse(entry[1] as string); - }; + return JSON.parse(entry[1] as string) as PropSidebars; + } // Extra fns useful for tests! const utils = { @@ -571,8 +572,8 @@ describe('versioned website (community)', () => { allContent: {}, }); - utils.checkVersionMetadataPropCreated(currentVersion!); - utils.checkVersionMetadataPropCreated(version100!); + utils.checkVersionMetadataPropCreated(currentVersion); + utils.checkVersionMetadataPropCreated(version100); utils.expectSnapshot(); }); diff --git a/packages/docusaurus-theme-common/src/utils/reactUtils.tsx b/packages/docusaurus-theme-common/src/utils/reactUtils.tsx index 4a7410e3fb6d..4e0982807121 100644 --- a/packages/docusaurus-theme-common/src/utils/reactUtils.tsx +++ b/packages/docusaurus-theme-common/src/utils/reactUtils.tsx @@ -71,6 +71,6 @@ export class ReactContextError extends Error { this.message = `Hook ${ this.stack?.split('\n')[1]?.match(/at (?:\w+\.)?(?\w+)/)?.groups! .name ?? '' - } is called outside the <${providerName}>. ${additionalInfo || ''}`; + } is called outside the <${providerName}>. ${additionalInfo ?? ''}`; } } diff --git a/packages/docusaurus-theme-search-algolia/src/theme/SearchBar/index.tsx b/packages/docusaurus-theme-search-algolia/src/theme/SearchBar/index.tsx index bd36e353aa6a..beef496dffcd 100644 --- a/packages/docusaurus-theme-search-algolia/src/theme/SearchBar/index.tsx +++ b/packages/docusaurus-theme-search-algolia/src/theme/SearchBar/index.tsx @@ -120,7 +120,9 @@ function DocSearch({ } return Promise.all([ - import('@docsearch/react/modal'), + import('@docsearch/react/modal') as Promise< + typeof import('@docsearch/react') + >, import('@docsearch/react/style'), import('./styles.css'), ]).then(([{DocSearchModal: Modal}]) => { diff --git a/packages/docusaurus-utils-validation/src/__tests__/validationUtils.test.ts b/packages/docusaurus-utils-validation/src/__tests__/validationUtils.test.ts index 771ff94c855c..0bb0fd99a9f3 100644 --- a/packages/docusaurus-utils-validation/src/__tests__/validationUtils.test.ts +++ b/packages/docusaurus-utils-validation/src/__tests__/validationUtils.test.ts @@ -42,7 +42,7 @@ describe('normalizePluginOptions', () => { it('throws for invalid options', () => { const options = {foo: 1}; expect(() => - normalizePluginOptions(Joi.object({foo: Joi.string()}), options), + normalizePluginOptions(Joi.object({foo: Joi.string()}), options), ).toThrowErrorMatchingInlineSnapshot(`""foo" must be a string"`); }); @@ -90,7 +90,10 @@ describe('normalizeThemeConfig', () => { it('throws for invalid options', () => { const themeConfig = {foo: 1, bar: 1}; expect(() => - normalizeThemeConfig(Joi.object({foo: Joi.string()}), themeConfig), + normalizeThemeConfig( + Joi.object({foo: Joi.string()}), + themeConfig, + ), ).toThrowErrorMatchingInlineSnapshot(`""foo" must be a string"`); }); diff --git a/packages/docusaurus/src/client/PendingNavigation.tsx b/packages/docusaurus/src/client/PendingNavigation.tsx index 24e1e38faa2d..e1e38f40f817 100644 --- a/packages/docusaurus/src/client/PendingNavigation.tsx +++ b/packages/docusaurus/src/client/PendingNavigation.tsx @@ -35,7 +35,7 @@ class PendingNavigation extends React.Component { ? dispatchLifecycleAction('onRouteUpdate', { previousLocation: null, location: this.props.location, - })! + }) : () => {}; this.state = { nextRouteHasLoaded: true, @@ -60,14 +60,14 @@ class PendingNavigation extends React.Component { this.routeUpdateCleanupCb = dispatchLifecycleAction('onRouteUpdate', { previousLocation: this.previousLocation, location: nextLocation, - })!; + }); // Load data while the old screen remains. Force preload instead of using // `window.docusaurus`, because we want to avoid loading screen even when // user is on saveData preload(nextLocation.pathname) .then(() => { - this.routeUpdateCleanupCb?.(); + this.routeUpdateCleanupCb(); this.setState({nextRouteHasLoaded: true}); }) .catch((e: unknown) => console.warn(e)); diff --git a/packages/docusaurus/src/commands/deploy.ts b/packages/docusaurus/src/commands/deploy.ts index e35783ddb745..9b5f233f5bf4 100644 --- a/packages/docusaurus/src/commands/deploy.ts +++ b/packages/docusaurus/src/commands/deploy.ts @@ -69,7 +69,7 @@ This behavior can have SEO impacts and create relative link issues. // The source branch; defaults to the currently checked out branch const sourceBranch = - process.env.CURRENT_BRANCH || + process.env.CURRENT_BRANCH ?? shell.exec('git rev-parse --abbrev-ref HEAD', {silent: true}).stdout.trim(); const gitUser = process.env.GIT_USER; @@ -90,8 +90,8 @@ This behavior can have SEO impacts and create relative link issues. } const organizationName = - process.env.ORGANIZATION_NAME || - process.env.CIRCLE_PROJECT_USERNAME || + process.env.ORGANIZATION_NAME ?? + process.env.CIRCLE_PROJECT_USERNAME ?? siteConfig.organizationName; if (!organizationName) { throw new Error( @@ -101,8 +101,8 @@ This behavior can have SEO impacts and create relative link issues. logger.info`organizationName: name=${organizationName}`; const projectName = - process.env.PROJECT_NAME || - process.env.CIRCLE_PROJECT_REPONAME || + process.env.PROJECT_NAME ?? + process.env.CIRCLE_PROJECT_REPONAME ?? siteConfig.projectName; if (!projectName) { throw new Error( @@ -113,7 +113,7 @@ This behavior can have SEO impacts and create relative link issues. // We never deploy on pull request. const isPullRequest = - process.env.CI_PULL_REQUEST || process.env.CIRCLE_PULL_REQUEST; + process.env.CI_PULL_REQUEST ?? process.env.CIRCLE_PULL_REQUEST; if (isPullRequest) { shell.echo('Skipping deploy on a pull request.'); shell.exit(0); @@ -136,12 +136,12 @@ You can also set the deploymentBranch property in docusaurus.config.js .`); } const deploymentBranch = - process.env.DEPLOYMENT_BRANCH || siteConfig.deploymentBranch || 'gh-pages'; + process.env.DEPLOYMENT_BRANCH ?? siteConfig.deploymentBranch ?? 'gh-pages'; logger.info`deploymentBranch: name=${deploymentBranch}`; const githubHost = - process.env.GITHUB_HOST || siteConfig.githubHost || 'github.com'; - const githubPort = process.env.GITHUB_PORT || siteConfig.githubPort; + process.env.GITHUB_HOST ?? siteConfig.githubHost ?? 'github.com'; + const githubPort = process.env.GITHUB_PORT ?? siteConfig.githubPort; let deploymentRepoURL: string; if (useSSH) { @@ -214,7 +214,7 @@ You can also set the deploymentBranch property in docusaurus.config.js .`); shellExecLog('git add --all'); const commitMessage = - process.env.CUSTOM_COMMIT_MESSAGE || + process.env.CUSTOM_COMMIT_MESSAGE ?? `Deploy website - based on ${currentCommit}`; const commitResults = shellExecLog(`git commit -m "${commitMessage}"`); if ( diff --git a/packages/docusaurus/src/commands/swizzle/__tests__/index.test.ts b/packages/docusaurus/src/commands/swizzle/__tests__/index.test.ts index 74e94678f3c2..462c44c1a09e 100644 --- a/packages/docusaurus/src/commands/swizzle/__tests__/index.test.ts +++ b/packages/docusaurus/src/commands/swizzle/__tests__/index.test.ts @@ -65,7 +65,7 @@ function createExitMock() { }); // eslint-disable-next-line jest/require-top-level-describe afterEach(async () => { - mock?.mockRestore(); + mock.mockRestore(); }); return { diff --git a/packages/docusaurus/src/server/plugins/__tests__/index.test.ts b/packages/docusaurus/src/server/plugins/__tests__/index.test.ts index 2d85798e3633..0ace57b22cd9 100644 --- a/packages/docusaurus/src/server/plugins/__tests__/index.test.ts +++ b/packages/docusaurus/src/server/plugins/__tests__/index.test.ts @@ -28,7 +28,7 @@ describe('loadPlugins', () => { name: 'test1', prop: 'a', async loadContent() { - // Testing that plugin lifecycle is bound to the plugin instance + // Testing that plugin lifecycle is bound to the instance return this.prop; }, async contentLoaded({content, actions}) { diff --git a/website/docs/api/plugins/plugin-content-docs.md b/website/docs/api/plugins/plugin-content-docs.md index e5971ee2fa59..331c7cb0a9f9 100644 --- a/website/docs/api/plugins/plugin-content-docs.md +++ b/website/docs/api/plugins/plugin-content-docs.md @@ -96,14 +96,14 @@ type SidebarGenerator = (generatorArgs: { /** Useful metadata for the version this sidebar belongs to. */ version: {contentPath: string; versionName: string}; /** All the docs of that version (unfiltered). */ - docs: Array<{ + docs: { id: string; title: string; frontMatter: DocFrontMatter & Record; source: string; sourceDirName: string; sidebarPosition?: number | undefined; - }>; + }[]; /** Number prefix parser configured for this plugin. */ numberPrefixParser: PrefixParser; /** The default category index matcher which you can override. */ diff --git a/website/docs/api/plugins/plugin-pwa.md b/website/docs/api/plugins/plugin-pwa.md index 1a7ab67bbe01..7dc019fe97fb 100644 --- a/website/docs/api/plugins/plugin-pwa.md +++ b/website/docs/api/plugins/plugin-pwa.md @@ -112,8 +112,8 @@ Turn debug mode on: ### `offlineModeActivationStrategies` {#offlinemodeactivationstrategies} -- Type: `Array<'appInstalled' | 'mobile' | 'saveData'| 'queryString' | 'always'>` -- Default: `['appInstalled','queryString','standalone']` +- Type: `('appInstalled' | 'mobile' | 'saveData'| 'queryString' | 'always')[]` +- Default: `['appInstalled', 'queryString', 'standalone']` Strategies used to turn the offline mode on: @@ -194,7 +194,7 @@ The default theme includes an implementation for the reload popup and uses [Infi ### `pwaHead` {#pwahead} -- Type: `Array<{ tagName: string } & Record>` +- Type: `({ tagName: string; [attributeName: string]: string })[]` - Default: `[]` Array of objects containing `tagName` and key-value pairs for attributes to inject into the `` tag. Technically you can inject any head tag through this, but it's ideally used for tags to make your site PWA compliant. Here's a list of tag to make your app fully compliant: diff --git a/website/docs/guides/markdown-features/markdown-features-toc.mdx b/website/docs/guides/markdown-features/markdown-features-toc.mdx index 18e2d5d17614..1cc1ed43d27c 100644 --- a/website/docs/guides/markdown-features/markdown-features-toc.mdx +++ b/website/docs/guides/markdown-features/markdown-features-toc.mdx @@ -83,11 +83,11 @@ import TOCInline from '@theme/TOCInline'; The `toc` global is just a list of heading items: ```ts -declare const toc: Array<{ +declare const toc: { value: string; id: string; level: number; -}>; +}[]; ``` Note that the `toc` global is a flat array, so you can easily cut out unwanted nodes or insert extra nodes, and create a new TOC tree.