mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-13 17:17:28 +02:00
chore(v2): Fix linter warnings (#4442)
* chore(v2): Fix linter warnings 223 warnings to 145 warnings * Remove explicit type annotations * Do not prefetch when targetLink == null
This commit is contained in:
parent
f041a37622
commit
5e73c72f26
39 changed files with 146 additions and 71 deletions
|
@ -90,6 +90,7 @@ module.exports = {
|
||||||
],
|
],
|
||||||
'no-unused-vars': OFF,
|
'no-unused-vars': OFF,
|
||||||
'no-nested-ternary': WARNING,
|
'no-nested-ternary': WARNING,
|
||||||
|
'@typescript-eslint/no-empty-function': OFF,
|
||||||
'@typescript-eslint/no-unused-vars': [ERROR, {argsIgnorePattern: '^_'}],
|
'@typescript-eslint/no-unused-vars': [ERROR, {argsIgnorePattern: '^_'}],
|
||||||
'@typescript-eslint/ban-ts-comment': [
|
'@typescript-eslint/ban-ts-comment': [
|
||||||
ERROR,
|
ERROR,
|
||||||
|
@ -108,7 +109,6 @@ module.exports = {
|
||||||
camelcase: WARNING,
|
camelcase: WARNING,
|
||||||
'no-restricted-syntax': WARNING,
|
'no-restricted-syntax': WARNING,
|
||||||
'no-unused-expressions': WARNING,
|
'no-unused-expressions': WARNING,
|
||||||
'@typescript-eslint/no-empty-function': WARNING,
|
|
||||||
'global-require': WARNING,
|
'global-require': WARNING,
|
||||||
'prefer-destructuring': WARNING,
|
'prefer-destructuring': WARNING,
|
||||||
yoda: WARNING,
|
yoda: WARNING,
|
||||||
|
|
|
@ -13,7 +13,7 @@ describe('create config', () => {
|
||||||
test('simple test', () => {
|
test('simple test', () => {
|
||||||
const v1Config: VersionOneConfig = importFresh(
|
const v1Config: VersionOneConfig = importFresh(
|
||||||
`${__dirname}/__fixtures__/sourceSiteConfig.js`,
|
`${__dirname}/__fixtures__/sourceSiteConfig.js`,
|
||||||
) as any;
|
);
|
||||||
const siteDir = 'website';
|
const siteDir = 'website';
|
||||||
const newDir = 'websiteMigrated';
|
const newDir = 'websiteMigrated';
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,9 @@ export type Data = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ClassicPresetEntries = {
|
export type ClassicPresetEntries = {
|
||||||
docs: {[key: string]: any};
|
docs: {[key: string]: unknown};
|
||||||
blog: {[key: string]: any};
|
blog: {[key: string]: unknown};
|
||||||
theme: {[key: string]: any};
|
theme: {[key: string]: unknown};
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SidebarEntries = {
|
export type SidebarEntries = {
|
||||||
|
@ -39,7 +39,7 @@ export interface VersionTwoConfig {
|
||||||
githubHost?: string;
|
githubHost?: string;
|
||||||
onBrokenLinks: string;
|
onBrokenLinks: string;
|
||||||
onBrokenMarkdownLinks: string;
|
onBrokenMarkdownLinks: string;
|
||||||
plugins: Array<[string, {[key: string]: any}]>;
|
plugins: Array<[string, {[key: string]: unknown}]>;
|
||||||
themes?: [];
|
themes?: [];
|
||||||
presets: [[string, ClassicPresetEntries]];
|
presets: [[string, ClassicPresetEntries]];
|
||||||
themeConfig: {
|
themeConfig: {
|
||||||
|
@ -114,8 +114,8 @@ export type VersionOneConfig = {
|
||||||
gaTrackingId?: string;
|
gaTrackingId?: string;
|
||||||
highlight?: Record<string, unknown>;
|
highlight?: Record<string, unknown>;
|
||||||
markdownPlugins?: Array<() => void>;
|
markdownPlugins?: Array<() => void>;
|
||||||
scripts?: Array<{src: string; [key: string]: any} | string>;
|
scripts?: Array<{src: string; [key: string]: unknown} | string>;
|
||||||
stylesheets?: Array<{href: string; [key: string]: any} | string>;
|
stylesheets?: Array<{href: string; [key: string]: unknown} | string>;
|
||||||
facebookAppId?: string;
|
facebookAppId?: string;
|
||||||
facebookComments?: true;
|
facebookComments?: true;
|
||||||
facebookPixelId?: string;
|
facebookPixelId?: string;
|
||||||
|
|
|
@ -43,7 +43,7 @@ declare module '@generated/routesChunkNames' {
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@generated/globalData' {
|
declare module '@generated/globalData' {
|
||||||
const globalData: any;
|
const globalData: Record<string, unknown>;
|
||||||
export default globalData;
|
export default globalData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -120,7 +120,10 @@ export function processDocMetadata({
|
||||||
const docsFileDirName = path.dirname(source);
|
const docsFileDirName = path.dirname(source);
|
||||||
|
|
||||||
const {frontMatter = {}, excerpt} = parseMarkdownString(content);
|
const {frontMatter = {}, excerpt} = parseMarkdownString(content);
|
||||||
const {sidebar_label, custom_edit_url} = frontMatter;
|
const {
|
||||||
|
sidebar_label: sidebarLabel,
|
||||||
|
custom_edit_url: customEditURL,
|
||||||
|
} = frontMatter;
|
||||||
|
|
||||||
const baseID: string =
|
const baseID: string =
|
||||||
frontMatter.id || path.basename(source, path.extname(source));
|
frontMatter.id || path.basename(source, path.extname(source));
|
||||||
|
@ -206,7 +209,7 @@ export function processDocMetadata({
|
||||||
source: aliasedSitePath(filePath, siteDir),
|
source: aliasedSitePath(filePath, siteDir),
|
||||||
slug: docSlug,
|
slug: docSlug,
|
||||||
permalink,
|
permalink,
|
||||||
editUrl: custom_edit_url !== undefined ? custom_edit_url : getDocEditUrl(),
|
editUrl: customEditURL !== undefined ? customEditURL : getDocEditUrl(),
|
||||||
version: versionMetadata.versionName,
|
version: versionMetadata.versionName,
|
||||||
lastUpdatedBy: lastUpdate.lastUpdatedBy,
|
lastUpdatedBy: lastUpdate.lastUpdatedBy,
|
||||||
lastUpdatedAt: lastUpdate.lastUpdatedAt,
|
lastUpdatedAt: lastUpdate.lastUpdatedAt,
|
||||||
|
@ -215,6 +218,6 @@ export function processDocMetadata({
|
||||||
lastUpdate.lastUpdatedAt * 1000,
|
lastUpdate.lastUpdatedAt * 1000,
|
||||||
)
|
)
|
||||||
: undefined,
|
: undefined,
|
||||||
sidebar_label,
|
sidebar_label: sidebarLabel,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ declare module '@docusaurus/plugin-content-docs-types' {
|
||||||
};
|
};
|
||||||
|
|
||||||
type PropsSidebarItemBase = {
|
type PropsSidebarItemBase = {
|
||||||
customProps?: object;
|
customProps?: Record<string, unknown>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type PropSidebarItemLink = PropsSidebarItemBase & {
|
export type PropSidebarItemLink = PropsSidebarItemBase & {
|
||||||
|
|
|
@ -33,11 +33,11 @@ Available document ids=
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const {title, permalink, sidebar_label} = docMetadata;
|
const {title, permalink, sidebar_label: sidebarLabel} = docMetadata;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: 'link',
|
type: 'link',
|
||||||
label: sidebar_label || title,
|
label: sidebarLabel || title,
|
||||||
href: permalink,
|
href: permalink,
|
||||||
customProps: item.customProps,
|
customProps: item.customProps,
|
||||||
};
|
};
|
||||||
|
|
|
@ -76,7 +76,7 @@ function normalizeCategoryShorthand(
|
||||||
* Check that item contains only allowed keys.
|
* Check that item contains only allowed keys.
|
||||||
*/
|
*/
|
||||||
function assertItem<K extends string>(
|
function assertItem<K extends string>(
|
||||||
item: any,
|
item: Record<string, unknown>,
|
||||||
keys: K[],
|
keys: K[],
|
||||||
): asserts item is Record<K, any> {
|
): asserts item is Record<K, any> {
|
||||||
const unknownKeys = Object.keys(item).filter(
|
const unknownKeys = Object.keys(item).filter(
|
||||||
|
@ -94,7 +94,7 @@ function assertItem<K extends string>(
|
||||||
}
|
}
|
||||||
|
|
||||||
function assertIsCategory(
|
function assertIsCategory(
|
||||||
item: unknown,
|
item: Record<string, unknown>,
|
||||||
): asserts item is SidebarItemCategoryJSON {
|
): asserts item is SidebarItemCategoryJSON {
|
||||||
assertItem(item, ['items', 'label', 'collapsed', 'customProps']);
|
assertItem(item, ['items', 'label', 'collapsed', 'customProps']);
|
||||||
if (typeof item.label !== 'string') {
|
if (typeof item.label !== 'string') {
|
||||||
|
@ -115,7 +115,9 @@ function assertIsCategory(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function assertIsDoc(item: unknown): asserts item is SidebarItemDoc {
|
function assertIsDoc(
|
||||||
|
item: Record<string, unknown>,
|
||||||
|
): asserts item is SidebarItemDoc {
|
||||||
assertItem(item, ['id', 'customProps']);
|
assertItem(item, ['id', 'customProps']);
|
||||||
if (typeof item.id !== 'string') {
|
if (typeof item.id !== 'string') {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
@ -124,7 +126,9 @@ function assertIsDoc(item: unknown): asserts item is SidebarItemDoc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function assertIsLink(item: unknown): asserts item is SidebarItemLink {
|
function assertIsLink(
|
||||||
|
item: Record<string, unknown>,
|
||||||
|
): asserts item is SidebarItemLink {
|
||||||
assertItem(item, ['href', 'label', 'customProps']);
|
assertItem(item, ['href', 'label', 'customProps']);
|
||||||
if (typeof item.href !== 'string') {
|
if (typeof item.href !== 'string') {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
|
|
@ -27,7 +27,7 @@ import {
|
||||||
export const useAllDocsData = (): Record<string, GlobalPluginData> =>
|
export const useAllDocsData = (): Record<string, GlobalPluginData> =>
|
||||||
useAllPluginInstancesData('docusaurus-plugin-content-docs');
|
useAllPluginInstancesData('docusaurus-plugin-content-docs');
|
||||||
|
|
||||||
export const useDocsData = (pluginId: string | undefined) =>
|
export const useDocsData = (pluginId: string | undefined): GlobalPluginData =>
|
||||||
usePluginData('docusaurus-plugin-content-docs', pluginId) as GlobalPluginData;
|
usePluginData('docusaurus-plugin-content-docs', pluginId) as GlobalPluginData;
|
||||||
|
|
||||||
export const useActivePlugin = (
|
export const useActivePlugin = (
|
||||||
|
|
|
@ -94,7 +94,7 @@ export type PluginOptions = MetadataOptions &
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SidebarItemBase = {
|
export type SidebarItemBase = {
|
||||||
customProps?: object;
|
customProps?: Record<string, unknown>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SidebarItemDoc = SidebarItemBase & {
|
export type SidebarItemDoc = SidebarItemBase & {
|
||||||
|
@ -147,6 +147,7 @@ export type DocMetadataBase = LastUpdateData & {
|
||||||
source: string;
|
source: string;
|
||||||
slug: string;
|
slug: string;
|
||||||
permalink: string;
|
permalink: string;
|
||||||
|
// eslint-disable-next-line camelcase
|
||||||
sidebar_label?: string;
|
sidebar_label?: string;
|
||||||
editUrl?: string | null;
|
editUrl?: string | null;
|
||||||
};
|
};
|
||||||
|
|
|
@ -427,7 +427,7 @@ function filterVersions(
|
||||||
) {
|
) {
|
||||||
if (options.onlyIncludeVersions) {
|
if (options.onlyIncludeVersions) {
|
||||||
return versionNamesUnfiltered.filter((name) =>
|
return versionNamesUnfiltered.filter((name) =>
|
||||||
options.onlyIncludeVersions!.includes(name),
|
(options.onlyIncludeVersions || []).includes(name),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return versionNamesUnfiltered;
|
return versionNamesUnfiltered;
|
||||||
|
|
|
@ -22,7 +22,7 @@ describe('docusaurus-plugin-content-pages', () => {
|
||||||
path: pluginPath,
|
path: pluginPath,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
const pagesMetadatas = (await plugin.loadContent?.())!;
|
const pagesMetadatas = await plugin.loadContent?.();
|
||||||
|
|
||||||
expect(pagesMetadatas).toEqual([
|
expect(pagesMetadatas).toEqual([
|
||||||
{
|
{
|
||||||
|
@ -89,7 +89,7 @@ describe('docusaurus-plugin-content-pages', () => {
|
||||||
path: pluginPath,
|
path: pluginPath,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
const pagesMetadatas = (await plugin.loadContent?.())!;
|
const pagesMetadatas = await plugin.loadContent?.();
|
||||||
|
|
||||||
const frTranslationsPath = path.posix.join(
|
const frTranslationsPath = path.posix.join(
|
||||||
'@site',
|
'@site',
|
||||||
|
|
|
@ -14,6 +14,7 @@ declare module '@theme/MDXPage' {
|
||||||
readonly title: string;
|
readonly title: string;
|
||||||
readonly description: string;
|
readonly description: string;
|
||||||
readonly wrapperClassName?: string;
|
readonly wrapperClassName?: string;
|
||||||
|
// eslint-disable-next-line camelcase
|
||||||
readonly hide_table_of_contents?: string;
|
readonly hide_table_of_contents?: string;
|
||||||
};
|
};
|
||||||
readonly metadata: {readonly permalink: string};
|
readonly metadata: {readonly permalink: string};
|
||||||
|
|
|
@ -18,6 +18,7 @@ const BrowserOnlyReactJson = (props) => {
|
||||||
return (
|
return (
|
||||||
<BrowserOnly>
|
<BrowserOnly>
|
||||||
{() => {
|
{() => {
|
||||||
|
// eslint-disable-next-line global-require
|
||||||
const ReactJson = require('react-json-view').default;
|
const ReactJson = require('react-json-view').default;
|
||||||
return <ReactJson {...props} />;
|
return <ReactJson {...props} />;
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -6,10 +6,11 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Highlight, {defaultProps} from 'prism-react-renderer';
|
import Highlight, {defaultProps, Language} from 'prism-react-renderer';
|
||||||
import theme from 'prism-react-renderer/themes/nightOwl';
|
import theme from 'prism-react-renderer/themes/nightOwl';
|
||||||
|
import type {Props} from '@theme/CodeBlock';
|
||||||
|
|
||||||
export default ({children, className}): JSX.Element => {
|
export default ({children, className}: Props): JSX.Element => {
|
||||||
const language = className && className.replace(/language-/, '');
|
const language = className && className.replace(/language-/, '');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -17,7 +18,7 @@ export default ({children, className}): JSX.Element => {
|
||||||
{...defaultProps}
|
{...defaultProps}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
code={children}
|
code={children}
|
||||||
language={language}>
|
language={language as Language}>
|
||||||
{({style, tokens, getLineProps, getTokenProps}) => (
|
{({style, tokens, getLineProps, getTokenProps}) => (
|
||||||
<pre className={className} style={{...style, padding: '20px'}}>
|
<pre className={className} style={{...style, padding: '20px'}}>
|
||||||
{tokens.map((line, i) => (
|
{tokens.map((line, i) => (
|
||||||
|
|
|
@ -30,7 +30,7 @@ function FooterLink({to, href, label, ...props}) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function Footer() {
|
function Footer(): JSX.Element {
|
||||||
const context = useDocusaurusContext();
|
const context = useDocusaurusContext();
|
||||||
const {siteConfig = {}} = context;
|
const {siteConfig = {}} = context;
|
||||||
const {themeConfig = {}} = siteConfig;
|
const {themeConfig = {}} = siteConfig;
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React, {ReactNode} from 'react';
|
import React, {ReactNode} from 'react';
|
||||||
import CodeBlock from '@theme/CodeBlock';
|
import CodeBlock, {Props} from '@theme/CodeBlock';
|
||||||
import {Table} from 'reactstrap';
|
import {Table} from 'reactstrap';
|
||||||
|
|
||||||
const Heading = (tag: string): ReactNode => {
|
const Heading = (tag: string): ReactNode => {
|
||||||
|
@ -22,7 +22,7 @@ export default {
|
||||||
h4: Heading('h4'),
|
h4: Heading('h4'),
|
||||||
h5: Heading('h5'),
|
h5: Heading('h5'),
|
||||||
h6: Heading('h6'),
|
h6: Heading('h6'),
|
||||||
code: (props) => {
|
code: (props: Props): JSX.Element => {
|
||||||
const {children} = props;
|
const {children} = props;
|
||||||
if (typeof children === 'string') {
|
if (typeof children === 'string') {
|
||||||
return <CodeBlock {...props} />;
|
return <CodeBlock {...props} />;
|
||||||
|
@ -30,8 +30,10 @@ export default {
|
||||||
return children;
|
return children;
|
||||||
},
|
},
|
||||||
table: Table,
|
table: Table,
|
||||||
blockquote: (props) => (
|
blockquote: (props: {children: ReactNode}): JSX.Element => (
|
||||||
<blockquote className="blockquote-footer">{props.children}</blockquote>
|
<blockquote className="blockquote-footer">{props.children}</blockquote>
|
||||||
),
|
),
|
||||||
p: (props) => <div className="font-weight-light">{props.children}</div>,
|
p: (props: {children: ReactNode}): JSX.Element => (
|
||||||
|
<div className="font-weight-light">{props.children}</div>
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|
|
@ -62,7 +62,7 @@ function NavItem({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function Navbar() {
|
function Navbar(): JSX.Element {
|
||||||
const {
|
const {
|
||||||
siteConfig: {
|
siteConfig: {
|
||||||
themeConfig: {navbar: {title = '', items: links = []} = {}},
|
themeConfig: {navbar: {title = '', items: links = []} = {}},
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
function TOCInline(_props: any): JSX.Element {
|
function TOCInline(_props: Record<string, unknown>): JSX.Element {
|
||||||
return <div>TODO bootstrap toc</div>;
|
return <div>TODO bootstrap toc</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,8 @@ import {merge} from 'lodash';
|
||||||
const {ThemeConfigSchema, DEFAULT_CONFIG} = require('../validateThemeConfig');
|
const {ThemeConfigSchema, DEFAULT_CONFIG} = require('../validateThemeConfig');
|
||||||
|
|
||||||
const {normalizeThemeConfig} = require('@docusaurus/utils-validation');
|
const {normalizeThemeConfig} = require('@docusaurus/utils-validation');
|
||||||
|
const theme = require('prism-react-renderer/themes/github');
|
||||||
|
const darkTheme = require('prism-react-renderer/themes/dracula');
|
||||||
|
|
||||||
function testValidateThemeConfig(partialThemeConfig) {
|
function testValidateThemeConfig(partialThemeConfig) {
|
||||||
return normalizeThemeConfig(ThemeConfigSchema, {
|
return normalizeThemeConfig(ThemeConfigSchema, {
|
||||||
|
@ -31,8 +33,8 @@ describe('themeConfig', () => {
|
||||||
test('should accept valid theme config', () => {
|
test('should accept valid theme config', () => {
|
||||||
const userConfig = {
|
const userConfig = {
|
||||||
prism: {
|
prism: {
|
||||||
theme: require('prism-react-renderer/themes/github'),
|
theme,
|
||||||
darkTheme: require('prism-react-renderer/themes/dracula'),
|
darkTheme,
|
||||||
defaultLanguage: 'javascript',
|
defaultLanguage: 'javascript',
|
||||||
additionalLanguages: ['kotlin', 'java'],
|
additionalLanguages: ['kotlin', 'java'],
|
||||||
},
|
},
|
||||||
|
|
|
@ -9,12 +9,18 @@ import React from 'react';
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
|
|
||||||
import Link from '@docusaurus/Link';
|
import Link from '@docusaurus/Link';
|
||||||
import {useThemeConfig} from '@docusaurus/theme-common';
|
import {FooterLinkItem, useThemeConfig} from '@docusaurus/theme-common';
|
||||||
import useBaseUrl from '@docusaurus/useBaseUrl';
|
import useBaseUrl from '@docusaurus/useBaseUrl';
|
||||||
import styles from './styles.module.css';
|
import styles from './styles.module.css';
|
||||||
import ThemedImage, {Props as ThemedImageProps} from '@theme/ThemedImage';
|
import ThemedImage, {Props as ThemedImageProps} from '@theme/ThemedImage';
|
||||||
|
|
||||||
function FooterLink({to, href, label, prependBaseUrlToHref, ...props}: any) {
|
function FooterLink({
|
||||||
|
to,
|
||||||
|
href,
|
||||||
|
label,
|
||||||
|
prependBaseUrlToHref,
|
||||||
|
...props
|
||||||
|
}: FooterLinkItem) {
|
||||||
const toUrl = useBaseUrl(to);
|
const toUrl = useBaseUrl(to);
|
||||||
const normalizedHref = useBaseUrl(href, {forcePrependBaseUrl: true});
|
const normalizedHref = useBaseUrl(href, {forcePrependBaseUrl: true});
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ const MDXComponents: MDXComponentsObject = {
|
||||||
return children;
|
return children;
|
||||||
},
|
},
|
||||||
a: (props) => <Link {...props} />,
|
a: (props) => <Link {...props} />,
|
||||||
pre: (props: any) => {
|
pre: (props) => {
|
||||||
const {children} = props;
|
const {children} = props;
|
||||||
return (
|
return (
|
||||||
<CodeBlock
|
<CodeBlock
|
||||||
|
|
|
@ -19,13 +19,13 @@ const NavbarItemComponents = {
|
||||||
// Need to lazy load these items as we don't know for sure the docs plugin is loaded
|
// Need to lazy load these items as we don't know for sure the docs plugin is loaded
|
||||||
// See https://github.com/facebook/docusaurus/issues/3360
|
// See https://github.com/facebook/docusaurus/issues/3360
|
||||||
docsVersion: () =>
|
docsVersion: () =>
|
||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
// eslint-disable-next-line @typescript-eslint/no-var-requires, global-require
|
||||||
require('@theme/NavbarItem/DocsVersionNavbarItem').default,
|
require('@theme/NavbarItem/DocsVersionNavbarItem').default,
|
||||||
docsVersionDropdown: () =>
|
docsVersionDropdown: () =>
|
||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
// eslint-disable-next-line @typescript-eslint/no-var-requires, global-require
|
||||||
require('@theme/NavbarItem/DocsVersionDropdownNavbarItem').default,
|
require('@theme/NavbarItem/DocsVersionDropdownNavbarItem').default,
|
||||||
doc: () =>
|
doc: () =>
|
||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
// eslint-disable-next-line @typescript-eslint/no-var-requires, global-require
|
||||||
require('@theme/NavbarItem/DocNavbarItem').default,
|
require('@theme/NavbarItem/DocNavbarItem').default,
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
// see https://github.com/webpack/webpack/issues/7713#issuecomment-467888437
|
// see https://github.com/webpack/webpack/issues/7713#issuecomment-467888437
|
||||||
// note: warning can be filtered: https://github.com/facebook/docusaurus/pull/3382#issuecomment-684966924
|
// note: warning can be filtered: https://github.com/facebook/docusaurus/pull/3382#issuecomment-684966924
|
||||||
try {
|
try {
|
||||||
|
// eslint-disable-next-line global-require
|
||||||
module.exports = require('@theme-init/hooks/useDocs');
|
module.exports = require('@theme-init/hooks/useDocs');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// In case the docs plugin is not available, might be useful to stub some methods here
|
// In case the docs plugin is not available, might be useful to stub some methods here
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
"@docusaurus/module-type-aliases": "2.0.0-alpha.72"
|
"@docusaurus/module-type-aliases": "2.0.0-alpha.72"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
"prism-react-renderer": "^1.1.1",
|
||||||
"react": "^16.8.4 || ^17.0.0",
|
"react": "^16.8.4 || ^17.0.0",
|
||||||
"react-dom": "^16.8.4 || ^17.0.0"
|
"react-dom": "^16.8.4 || ^17.0.0"
|
||||||
},
|
},
|
||||||
|
|
|
@ -37,7 +37,7 @@ export function useDocsPreferredVersion(
|
||||||
return {preferredVersion, savePreferredVersionName} as const;
|
return {preferredVersion, savePreferredVersionName} as const;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useDocsPreferredVersionByPluginId() {
|
export function useDocsPreferredVersionByPluginId(): Record<string, any> {
|
||||||
const allDocsData = useAllDocsData();
|
const allDocsData = useAllDocsData();
|
||||||
const [state] = useDocsPreferredVersionContext();
|
const [state] = useDocsPreferredVersionContext();
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
||||||
|
import {PrismTheme} from 'prism-react-renderer';
|
||||||
|
import {CSSProperties} from 'react';
|
||||||
|
|
||||||
export type DocsVersionPersistence = 'localStorage' | 'none';
|
export type DocsVersionPersistence = 'localStorage' | 'none';
|
||||||
|
|
||||||
|
@ -32,11 +34,39 @@ export type Navbar = {
|
||||||
logo?: NavbarLogo;
|
logo?: NavbarLogo;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type ColorModeConfig = {
|
||||||
|
defaultMode: 'light' | 'dark';
|
||||||
|
disableSwitch: boolean;
|
||||||
|
respectPrefersColorScheme: boolean;
|
||||||
|
switchConfig: {
|
||||||
|
darkIcon: string;
|
||||||
|
darkIconStyle: CSSProperties;
|
||||||
|
lightIcon: string;
|
||||||
|
lightIconStyle: CSSProperties;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export type AnnouncementBarConfig = {
|
||||||
|
id: string;
|
||||||
|
content: string;
|
||||||
|
backgroundColor: string;
|
||||||
|
textColor: string;
|
||||||
|
isCloseable: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type PrismConfig = {
|
||||||
|
theme?: PrismTheme;
|
||||||
|
darkTheme?: PrismTheme;
|
||||||
|
defaultLanguage?: string;
|
||||||
|
additionalLanguages?: string[];
|
||||||
|
};
|
||||||
|
|
||||||
export type FooterLinkItem = {
|
export type FooterLinkItem = {
|
||||||
label?: string;
|
label?: string;
|
||||||
to?: string;
|
to?: string;
|
||||||
href?: string;
|
href?: string;
|
||||||
html?: string;
|
html?: string;
|
||||||
|
prependBaseUrlToHref?: string;
|
||||||
};
|
};
|
||||||
export type FooterLinks = {
|
export type FooterLinks = {
|
||||||
title?: string;
|
title?: string;
|
||||||
|
@ -65,11 +95,11 @@ export type ThemeConfig = {
|
||||||
|
|
||||||
// TODO temporary types
|
// TODO temporary types
|
||||||
navbar: Navbar;
|
navbar: Navbar;
|
||||||
colorMode: any;
|
colorMode: ColorModeConfig;
|
||||||
announcementBar: any;
|
announcementBar?: AnnouncementBarConfig;
|
||||||
prism: any;
|
prism: PrismConfig;
|
||||||
footer: Footer | undefined;
|
footer?: Footer;
|
||||||
hideableSidebar: any;
|
hideableSidebar: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function useThemeConfig(): ThemeConfig {
|
export function useThemeConfig(): ThemeConfig {
|
||||||
|
|
|
@ -26,7 +26,7 @@ const fileHash = new Map();
|
||||||
export async function generate(
|
export async function generate(
|
||||||
generatedFilesDir: string,
|
generatedFilesDir: string,
|
||||||
file: string,
|
file: string,
|
||||||
content: any,
|
content: string,
|
||||||
skipCache: boolean = process.env.NODE_ENV === 'production',
|
skipCache: boolean = process.env.NODE_ENV === 'production',
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const filepath = path.join(generatedFilesDir, file);
|
const filepath = path.join(generatedFilesDir, file);
|
||||||
|
@ -57,11 +57,13 @@ export async function generate(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function objectWithKeySorted(obj: {[index: string]: any}) {
|
export function objectWithKeySorted<T>(
|
||||||
|
obj: Record<string, T>,
|
||||||
|
): Record<string, T> {
|
||||||
// https://github.com/lodash/lodash/issues/1459#issuecomment-460941233
|
// https://github.com/lodash/lodash/issues/1459#issuecomment-460941233
|
||||||
return Object.keys(obj)
|
return Object.keys(obj)
|
||||||
.sort()
|
.sort()
|
||||||
.reduce((acc: any, key: string) => {
|
.reduce((acc: Record<string, T>, key: string) => {
|
||||||
acc[key] = obj[key];
|
acc[key] = obj[key];
|
||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
|
|
|
@ -45,7 +45,7 @@ if (notifier.lastUpdateCheck === Date.now()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notifier.update && notifier.update.current !== notifier.update.latest) {
|
if (notifier.update && notifier.update.current !== notifier.update.latest) {
|
||||||
// eslint-disable-next-line import/no-dynamic-require
|
// eslint-disable-next-line import/no-dynamic-require, global-require
|
||||||
const sitePkg = require(path.resolve(process.cwd(), 'package.json'));
|
const sitePkg = require(path.resolve(process.cwd(), 'package.json'));
|
||||||
const siteDocusaurusPackagesForUpdate = Object.keys(sitePkg.dependencies)
|
const siteDocusaurusPackagesForUpdate = Object.keys(sitePkg.dependencies)
|
||||||
.filter((p) => p.startsWith('@docusaurus'))
|
.filter((p) => p.startsWith('@docusaurus'))
|
||||||
|
|
|
@ -111,7 +111,7 @@ export default async function choosePort(
|
||||||
)}\n\nWould you like to run the app on another port instead?`,
|
)}\n\nWould you like to run the app on another port instead?`,
|
||||||
initial: true,
|
initial: true,
|
||||||
};
|
};
|
||||||
prompts(question).then((answer: any) => {
|
prompts(question).then((answer) => {
|
||||||
if (answer.shouldChangePort === true) {
|
if (answer.shouldChangePort === true) {
|
||||||
resolve(port);
|
resolve(port);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -18,7 +18,7 @@ declare global {
|
||||||
// eslint-disable-next-line camelcase, @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line camelcase, @typescript-eslint/no-explicit-any
|
||||||
const __webpack_require__: {gca: (name: string) => string};
|
const __webpack_require__: {gca: (name: string) => string};
|
||||||
interface Navigator {
|
interface Navigator {
|
||||||
connection: any;
|
connection: {effectiveType: string; saveData: boolean};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,6 +101,6 @@ export type InterpolateProps<Str extends string> = {
|
||||||
export default function Interpolate<Str extends string>({
|
export default function Interpolate<Str extends string>({
|
||||||
children,
|
children,
|
||||||
values,
|
values,
|
||||||
}: InterpolateProps<Str>) {
|
}: InterpolateProps<Str>): ReactNode {
|
||||||
return interpolate(children, values);
|
return interpolate(children, values);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,10 @@ import {useBaseUrlUtils} from './useBaseUrl';
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
docusaurus: any;
|
docusaurus: {
|
||||||
|
prefetch: (routePath: string) => boolean;
|
||||||
|
preload: (routePath: string) => boolean;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,13 +116,15 @@ function Link({
|
||||||
if (IOSupported && ref && isInternal) {
|
if (IOSupported && ref && isInternal) {
|
||||||
// If IO supported and element reference found, setup Observer functionality.
|
// If IO supported and element reference found, setup Observer functionality.
|
||||||
handleIntersection(ref, () => {
|
handleIntersection(ref, () => {
|
||||||
window.docusaurus.prefetch(targetLink);
|
if (targetLink != null) {
|
||||||
|
window.docusaurus.prefetch(targetLink);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onMouseEnter = () => {
|
const onMouseEnter = () => {
|
||||||
if (!preloaded.current) {
|
if (!preloaded.current && targetLink != null) {
|
||||||
window.docusaurus.preload(targetLink);
|
window.docusaurus.preload(targetLink);
|
||||||
preloaded.current = true;
|
preloaded.current = true;
|
||||||
}
|
}
|
||||||
|
@ -128,7 +133,9 @@ function Link({
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// If IO is not supported. We prefetch by default (only once).
|
// If IO is not supported. We prefetch by default (only once).
|
||||||
if (!IOSupported && isInternal) {
|
if (!IOSupported && isInternal) {
|
||||||
window.docusaurus.prefetch(targetLink);
|
if (targetLink != null) {
|
||||||
|
window.docusaurus.prefetch(targetLink);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// When unmounting, stop intersection observer from watching.
|
// When unmounting, stop intersection observer from watching.
|
||||||
|
|
|
@ -13,7 +13,7 @@ import useDocusaurusContext from './useDocusaurusContext';
|
||||||
// import {DEFAULT_PLUGIN_ID} from '../../constants';
|
// import {DEFAULT_PLUGIN_ID} from '../../constants';
|
||||||
const DEFAULT_PLUGIN_ID = 'default';
|
const DEFAULT_PLUGIN_ID = 'default';
|
||||||
|
|
||||||
export default function useGlobalData() {
|
export default function useGlobalData(): Record<string, unknown> {
|
||||||
const {globalData} = useDocusaurusContext();
|
const {globalData} = useDocusaurusContext();
|
||||||
if (!globalData) {
|
if (!globalData) {
|
||||||
throw new Error('Docusaurus global data not found');
|
throw new Error('Docusaurus global data not found');
|
||||||
|
@ -31,7 +31,7 @@ export function useAllPluginInstancesData<T = unknown>(
|
||||||
`Docusaurus plugin global data not found for pluginName=${pluginName}`,
|
`Docusaurus plugin global data not found for pluginName=${pluginName}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return pluginGlobalData;
|
return pluginGlobalData as Record<string, T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function usePluginData<T = unknown>(
|
export function usePluginData<T = unknown>(
|
||||||
|
|
|
@ -91,7 +91,7 @@ export default async function build(
|
||||||
i18n.locales.indexOf(locale) === i18n.locales.length - 1;
|
i18n.locales.indexOf(locale) === i18n.locales.length - 1;
|
||||||
return tryToBuildLocale({locale, isLastLocale});
|
return tryToBuildLocale({locale, isLastLocale});
|
||||||
});
|
});
|
||||||
return results[0]!;
|
return results[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ export async function loadPlugins({
|
||||||
}): Promise<{
|
}): Promise<{
|
||||||
plugins: InitPlugin[];
|
plugins: InitPlugin[];
|
||||||
pluginsRouteConfigs: RouteConfig[];
|
pluginsRouteConfigs: RouteConfig[];
|
||||||
globalData: any;
|
globalData: unknown;
|
||||||
themeConfigTranslated: ThemeConfig;
|
themeConfigTranslated: ThemeConfig;
|
||||||
}> {
|
}> {
|
||||||
// 1. Plugin Lifecycle - Initialization/Constructor.
|
// 1. Plugin Lifecycle - Initialization/Constructor.
|
||||||
|
|
|
@ -42,9 +42,15 @@ export default function loadPresets(
|
||||||
throw new Error('Invalid presets format detected in config.');
|
throw new Error('Invalid presets format detected in config.');
|
||||||
}
|
}
|
||||||
|
|
||||||
const presetModule: any = importFresh(
|
type PresetInitializeFunction = (
|
||||||
pluginRequire.resolve(presetModuleImport),
|
context: LoadContext,
|
||||||
);
|
presetOptions: Record<string, unknown>,
|
||||||
|
) => Preset;
|
||||||
|
const presetModule = importFresh<
|
||||||
|
PresetInitializeFunction & {
|
||||||
|
default?: PresetInitializeFunction;
|
||||||
|
}
|
||||||
|
>(pluginRequire.resolve(presetModuleImport));
|
||||||
const preset: Preset = (presetModule.default || presetModule)(
|
const preset: Preset = (presetModule.default || presetModule)(
|
||||||
context,
|
context,
|
||||||
presetOptions,
|
presetOptions,
|
||||||
|
|
|
@ -552,7 +552,7 @@ describe('getPluginsDefaultCodeTranslationMessages', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('applyDefaultCodeTranslations', () => {
|
describe('applyDefaultCodeTranslations', () => {
|
||||||
const consoleSpy = jest.spyOn(console, 'warn').mockImplementation() as any;
|
const consoleSpy = jest.spyOn(console, 'warn').mockImplementation();
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
consoleSpy.mockClear();
|
consoleSpy.mockClear();
|
||||||
});
|
});
|
||||||
|
|
|
@ -11,6 +11,7 @@ import merge from 'webpack-merge';
|
||||||
import webpack, {
|
import webpack, {
|
||||||
Configuration,
|
Configuration,
|
||||||
Loader,
|
Loader,
|
||||||
|
NewLoader,
|
||||||
Plugin,
|
Plugin,
|
||||||
RuleSetRule,
|
RuleSetRule,
|
||||||
Stats,
|
Stats,
|
||||||
|
@ -23,7 +24,11 @@ import path from 'path';
|
||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import {TransformOptions} from '@babel/core';
|
import {TransformOptions} from '@babel/core';
|
||||||
import {ConfigureWebpackFn, ConfigurePostCssFn} from '@docusaurus/types';
|
import {
|
||||||
|
ConfigureWebpackFn,
|
||||||
|
ConfigurePostCssFn,
|
||||||
|
PostCssOptions,
|
||||||
|
} from '@docusaurus/types';
|
||||||
import CssNanoPreset from '@docusaurus/cssnano-preset';
|
import CssNanoPreset from '@docusaurus/cssnano-preset';
|
||||||
import {version as cacheLoaderVersion} from 'cache-loader/package.json';
|
import {version as cacheLoaderVersion} from 'cache-loader/package.json';
|
||||||
import {
|
import {
|
||||||
|
@ -177,11 +182,13 @@ export function applyConfigurePostCss(
|
||||||
configurePostCss: NonNullable<ConfigurePostCssFn>,
|
configurePostCss: NonNullable<ConfigurePostCssFn>,
|
||||||
config: Configuration,
|
config: Configuration,
|
||||||
): Configuration {
|
): Configuration {
|
||||||
type LocalPostCSSLoader = Loader & {options: {postcssOptions: any}};
|
type LocalPostCSSLoader = Loader & {
|
||||||
|
options: {postcssOptions: PostCssOptions};
|
||||||
|
};
|
||||||
|
|
||||||
// TODO not ideal heuristic but good enough for our usecase?
|
// TODO not ideal heuristic but good enough for our usecase?
|
||||||
function isPostCssLoader(loader: Loader): loader is LocalPostCSSLoader {
|
function isPostCssLoader(loader: Loader): loader is LocalPostCSSLoader {
|
||||||
return !!(loader as any)?.options?.postcssOptions;
|
return !!(loader as NewLoader)?.options?.postcssOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Does not handle all edge cases, but good enough for now
|
// Does not handle all edge cases, but good enough for now
|
||||||
|
@ -207,7 +214,7 @@ export function applyConfigurePostCss(
|
||||||
// See https://webpack.js.org/configuration/stats/#statswarningsfilter
|
// See https://webpack.js.org/configuration/stats/#statswarningsfilter
|
||||||
// @slorber: note sure why we have to re-implement this logic
|
// @slorber: note sure why we have to re-implement this logic
|
||||||
// just know that legacy had this only partially implemented, so completed it
|
// just know that legacy had this only partially implemented, so completed it
|
||||||
type WarningFilter = string | RegExp | Function;
|
type WarningFilter = string | RegExp | ((warning: string) => boolean);
|
||||||
function filterWarnings(
|
function filterWarnings(
|
||||||
warningsFilter: WarningFilter[],
|
warningsFilter: WarningFilter[],
|
||||||
warnings: string[],
|
warnings: string[],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue