mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-12 16:47:26 +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-nested-ternary': WARNING,
|
||||
'@typescript-eslint/no-empty-function': OFF,
|
||||
'@typescript-eslint/no-unused-vars': [ERROR, {argsIgnorePattern: '^_'}],
|
||||
'@typescript-eslint/ban-ts-comment': [
|
||||
ERROR,
|
||||
|
@ -108,7 +109,6 @@ module.exports = {
|
|||
camelcase: WARNING,
|
||||
'no-restricted-syntax': WARNING,
|
||||
'no-unused-expressions': WARNING,
|
||||
'@typescript-eslint/no-empty-function': WARNING,
|
||||
'global-require': WARNING,
|
||||
'prefer-destructuring': WARNING,
|
||||
yoda: WARNING,
|
||||
|
|
|
@ -13,7 +13,7 @@ describe('create config', () => {
|
|||
test('simple test', () => {
|
||||
const v1Config: VersionOneConfig = importFresh(
|
||||
`${__dirname}/__fixtures__/sourceSiteConfig.js`,
|
||||
) as any;
|
||||
);
|
||||
const siteDir = 'website';
|
||||
const newDir = 'websiteMigrated';
|
||||
|
||||
|
|
|
@ -16,9 +16,9 @@ export type Data = {
|
|||
};
|
||||
|
||||
export type ClassicPresetEntries = {
|
||||
docs: {[key: string]: any};
|
||||
blog: {[key: string]: any};
|
||||
theme: {[key: string]: any};
|
||||
docs: {[key: string]: unknown};
|
||||
blog: {[key: string]: unknown};
|
||||
theme: {[key: string]: unknown};
|
||||
};
|
||||
|
||||
export type SidebarEntries = {
|
||||
|
@ -39,7 +39,7 @@ export interface VersionTwoConfig {
|
|||
githubHost?: string;
|
||||
onBrokenLinks: string;
|
||||
onBrokenMarkdownLinks: string;
|
||||
plugins: Array<[string, {[key: string]: any}]>;
|
||||
plugins: Array<[string, {[key: string]: unknown}]>;
|
||||
themes?: [];
|
||||
presets: [[string, ClassicPresetEntries]];
|
||||
themeConfig: {
|
||||
|
@ -114,8 +114,8 @@ export type VersionOneConfig = {
|
|||
gaTrackingId?: string;
|
||||
highlight?: Record<string, unknown>;
|
||||
markdownPlugins?: Array<() => void>;
|
||||
scripts?: Array<{src: string; [key: string]: any} | string>;
|
||||
stylesheets?: Array<{href: string; [key: string]: any} | string>;
|
||||
scripts?: Array<{src: string; [key: string]: unknown} | string>;
|
||||
stylesheets?: Array<{href: string; [key: string]: unknown} | string>;
|
||||
facebookAppId?: string;
|
||||
facebookComments?: true;
|
||||
facebookPixelId?: string;
|
||||
|
|
|
@ -43,7 +43,7 @@ declare module '@generated/routesChunkNames' {
|
|||
}
|
||||
|
||||
declare module '@generated/globalData' {
|
||||
const globalData: any;
|
||||
const globalData: Record<string, unknown>;
|
||||
export default globalData;
|
||||
}
|
||||
|
||||
|
|
|
@ -120,7 +120,10 @@ export function processDocMetadata({
|
|||
const docsFileDirName = path.dirname(source);
|
||||
|
||||
const {frontMatter = {}, excerpt} = parseMarkdownString(content);
|
||||
const {sidebar_label, custom_edit_url} = frontMatter;
|
||||
const {
|
||||
sidebar_label: sidebarLabel,
|
||||
custom_edit_url: customEditURL,
|
||||
} = frontMatter;
|
||||
|
||||
const baseID: string =
|
||||
frontMatter.id || path.basename(source, path.extname(source));
|
||||
|
@ -206,7 +209,7 @@ export function processDocMetadata({
|
|||
source: aliasedSitePath(filePath, siteDir),
|
||||
slug: docSlug,
|
||||
permalink,
|
||||
editUrl: custom_edit_url !== undefined ? custom_edit_url : getDocEditUrl(),
|
||||
editUrl: customEditURL !== undefined ? customEditURL : getDocEditUrl(),
|
||||
version: versionMetadata.versionName,
|
||||
lastUpdatedBy: lastUpdate.lastUpdatedBy,
|
||||
lastUpdatedAt: lastUpdate.lastUpdatedAt,
|
||||
|
@ -215,6 +218,6 @@ export function processDocMetadata({
|
|||
lastUpdate.lastUpdatedAt * 1000,
|
||||
)
|
||||
: undefined,
|
||||
sidebar_label,
|
||||
sidebar_label: sidebarLabel,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ declare module '@docusaurus/plugin-content-docs-types' {
|
|||
};
|
||||
|
||||
type PropsSidebarItemBase = {
|
||||
customProps?: object;
|
||||
customProps?: Record<string, unknown>;
|
||||
};
|
||||
|
||||
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 {
|
||||
type: 'link',
|
||||
label: sidebar_label || title,
|
||||
label: sidebarLabel || title,
|
||||
href: permalink,
|
||||
customProps: item.customProps,
|
||||
};
|
||||
|
|
|
@ -76,7 +76,7 @@ function normalizeCategoryShorthand(
|
|||
* Check that item contains only allowed keys.
|
||||
*/
|
||||
function assertItem<K extends string>(
|
||||
item: any,
|
||||
item: Record<string, unknown>,
|
||||
keys: K[],
|
||||
): asserts item is Record<K, any> {
|
||||
const unknownKeys = Object.keys(item).filter(
|
||||
|
@ -94,7 +94,7 @@ function assertItem<K extends string>(
|
|||
}
|
||||
|
||||
function assertIsCategory(
|
||||
item: unknown,
|
||||
item: Record<string, unknown>,
|
||||
): asserts item is SidebarItemCategoryJSON {
|
||||
assertItem(item, ['items', 'label', 'collapsed', 'customProps']);
|
||||
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']);
|
||||
if (typeof item.id !== 'string') {
|
||||
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']);
|
||||
if (typeof item.href !== 'string') {
|
||||
throw new Error(
|
||||
|
|
|
@ -27,7 +27,7 @@ import {
|
|||
export const useAllDocsData = (): Record<string, GlobalPluginData> =>
|
||||
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;
|
||||
|
||||
export const useActivePlugin = (
|
||||
|
|
|
@ -94,7 +94,7 @@ export type PluginOptions = MetadataOptions &
|
|||
};
|
||||
|
||||
export type SidebarItemBase = {
|
||||
customProps?: object;
|
||||
customProps?: Record<string, unknown>;
|
||||
};
|
||||
|
||||
export type SidebarItemDoc = SidebarItemBase & {
|
||||
|
@ -147,6 +147,7 @@ export type DocMetadataBase = LastUpdateData & {
|
|||
source: string;
|
||||
slug: string;
|
||||
permalink: string;
|
||||
// eslint-disable-next-line camelcase
|
||||
sidebar_label?: string;
|
||||
editUrl?: string | null;
|
||||
};
|
||||
|
|
|
@ -427,7 +427,7 @@ function filterVersions(
|
|||
) {
|
||||
if (options.onlyIncludeVersions) {
|
||||
return versionNamesUnfiltered.filter((name) =>
|
||||
options.onlyIncludeVersions!.includes(name),
|
||||
(options.onlyIncludeVersions || []).includes(name),
|
||||
);
|
||||
} else {
|
||||
return versionNamesUnfiltered;
|
||||
|
|
|
@ -22,7 +22,7 @@ describe('docusaurus-plugin-content-pages', () => {
|
|||
path: pluginPath,
|
||||
}),
|
||||
);
|
||||
const pagesMetadatas = (await plugin.loadContent?.())!;
|
||||
const pagesMetadatas = await plugin.loadContent?.();
|
||||
|
||||
expect(pagesMetadatas).toEqual([
|
||||
{
|
||||
|
@ -89,7 +89,7 @@ describe('docusaurus-plugin-content-pages', () => {
|
|||
path: pluginPath,
|
||||
}),
|
||||
);
|
||||
const pagesMetadatas = (await plugin.loadContent?.())!;
|
||||
const pagesMetadatas = await plugin.loadContent?.();
|
||||
|
||||
const frTranslationsPath = path.posix.join(
|
||||
'@site',
|
||||
|
|
|
@ -14,6 +14,7 @@ declare module '@theme/MDXPage' {
|
|||
readonly title: string;
|
||||
readonly description: string;
|
||||
readonly wrapperClassName?: string;
|
||||
// eslint-disable-next-line camelcase
|
||||
readonly hide_table_of_contents?: string;
|
||||
};
|
||||
readonly metadata: {readonly permalink: string};
|
||||
|
|
|
@ -18,6 +18,7 @@ const BrowserOnlyReactJson = (props) => {
|
|||
return (
|
||||
<BrowserOnly>
|
||||
{() => {
|
||||
// eslint-disable-next-line global-require
|
||||
const ReactJson = require('react-json-view').default;
|
||||
return <ReactJson {...props} />;
|
||||
}}
|
||||
|
|
|
@ -6,10 +6,11 @@
|
|||
*/
|
||||
|
||||
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 type {Props} from '@theme/CodeBlock';
|
||||
|
||||
export default ({children, className}): JSX.Element => {
|
||||
export default ({children, className}: Props): JSX.Element => {
|
||||
const language = className && className.replace(/language-/, '');
|
||||
|
||||
return (
|
||||
|
@ -17,7 +18,7 @@ export default ({children, className}): JSX.Element => {
|
|||
{...defaultProps}
|
||||
theme={theme}
|
||||
code={children}
|
||||
language={language}>
|
||||
language={language as Language}>
|
||||
{({style, tokens, getLineProps, getTokenProps}) => (
|
||||
<pre className={className} style={{...style, padding: '20px'}}>
|
||||
{tokens.map((line, i) => (
|
||||
|
|
|
@ -30,7 +30,7 @@ function FooterLink({to, href, label, ...props}) {
|
|||
);
|
||||
}
|
||||
|
||||
function Footer() {
|
||||
function Footer(): JSX.Element {
|
||||
const context = useDocusaurusContext();
|
||||
const {siteConfig = {}} = context;
|
||||
const {themeConfig = {}} = siteConfig;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
import React, {ReactNode} from 'react';
|
||||
import CodeBlock from '@theme/CodeBlock';
|
||||
import CodeBlock, {Props} from '@theme/CodeBlock';
|
||||
import {Table} from 'reactstrap';
|
||||
|
||||
const Heading = (tag: string): ReactNode => {
|
||||
|
@ -22,7 +22,7 @@ export default {
|
|||
h4: Heading('h4'),
|
||||
h5: Heading('h5'),
|
||||
h6: Heading('h6'),
|
||||
code: (props) => {
|
||||
code: (props: Props): JSX.Element => {
|
||||
const {children} = props;
|
||||
if (typeof children === 'string') {
|
||||
return <CodeBlock {...props} />;
|
||||
|
@ -30,8 +30,10 @@ export default {
|
|||
return children;
|
||||
},
|
||||
table: Table,
|
||||
blockquote: (props) => (
|
||||
blockquote: (props: {children: ReactNode}): JSX.Element => (
|
||||
<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 {
|
||||
siteConfig: {
|
||||
themeConfig: {navbar: {title = '', items: links = []} = {}},
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
import React from 'react';
|
||||
|
||||
function TOCInline(_props: any): JSX.Element {
|
||||
function TOCInline(_props: Record<string, unknown>): JSX.Element {
|
||||
return <div>TODO bootstrap toc</div>;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@ import {merge} from 'lodash';
|
|||
const {ThemeConfigSchema, DEFAULT_CONFIG} = require('../validateThemeConfig');
|
||||
|
||||
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) {
|
||||
return normalizeThemeConfig(ThemeConfigSchema, {
|
||||
|
@ -31,8 +33,8 @@ describe('themeConfig', () => {
|
|||
test('should accept valid theme config', () => {
|
||||
const userConfig = {
|
||||
prism: {
|
||||
theme: require('prism-react-renderer/themes/github'),
|
||||
darkTheme: require('prism-react-renderer/themes/dracula'),
|
||||
theme,
|
||||
darkTheme,
|
||||
defaultLanguage: 'javascript',
|
||||
additionalLanguages: ['kotlin', 'java'],
|
||||
},
|
||||
|
|
|
@ -9,12 +9,18 @@ import React from 'react';
|
|||
import clsx from 'clsx';
|
||||
|
||||
import Link from '@docusaurus/Link';
|
||||
import {useThemeConfig} from '@docusaurus/theme-common';
|
||||
import {FooterLinkItem, useThemeConfig} from '@docusaurus/theme-common';
|
||||
import useBaseUrl from '@docusaurus/useBaseUrl';
|
||||
import styles from './styles.module.css';
|
||||
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 normalizedHref = useBaseUrl(href, {forcePrependBaseUrl: true});
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ const MDXComponents: MDXComponentsObject = {
|
|||
return children;
|
||||
},
|
||||
a: (props) => <Link {...props} />,
|
||||
pre: (props: any) => {
|
||||
pre: (props) => {
|
||||
const {children} = props;
|
||||
return (
|
||||
<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
|
||||
// See https://github.com/facebook/docusaurus/issues/3360
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
} as const;
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
// see https://github.com/webpack/webpack/issues/7713#issuecomment-467888437
|
||||
// note: warning can be filtered: https://github.com/facebook/docusaurus/pull/3382#issuecomment-684966924
|
||||
try {
|
||||
// eslint-disable-next-line global-require
|
||||
module.exports = require('@theme-init/hooks/useDocs');
|
||||
} catch (e) {
|
||||
// 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"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"prism-react-renderer": "^1.1.1",
|
||||
"react": "^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;
|
||||
}
|
||||
|
||||
export function useDocsPreferredVersionByPluginId() {
|
||||
export function useDocsPreferredVersionByPluginId(): Record<string, any> {
|
||||
const allDocsData = useAllDocsData();
|
||||
const [state] = useDocsPreferredVersionContext();
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
||||
import {PrismTheme} from 'prism-react-renderer';
|
||||
import {CSSProperties} from 'react';
|
||||
|
||||
export type DocsVersionPersistence = 'localStorage' | 'none';
|
||||
|
||||
|
@ -32,11 +34,39 @@ export type Navbar = {
|
|||
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 = {
|
||||
label?: string;
|
||||
to?: string;
|
||||
href?: string;
|
||||
html?: string;
|
||||
prependBaseUrlToHref?: string;
|
||||
};
|
||||
export type FooterLinks = {
|
||||
title?: string;
|
||||
|
@ -65,11 +95,11 @@ export type ThemeConfig = {
|
|||
|
||||
// TODO temporary types
|
||||
navbar: Navbar;
|
||||
colorMode: any;
|
||||
announcementBar: any;
|
||||
prism: any;
|
||||
footer: Footer | undefined;
|
||||
hideableSidebar: any;
|
||||
colorMode: ColorModeConfig;
|
||||
announcementBar?: AnnouncementBarConfig;
|
||||
prism: PrismConfig;
|
||||
footer?: Footer;
|
||||
hideableSidebar: boolean;
|
||||
};
|
||||
|
||||
export function useThemeConfig(): ThemeConfig {
|
||||
|
|
|
@ -26,7 +26,7 @@ const fileHash = new Map();
|
|||
export async function generate(
|
||||
generatedFilesDir: string,
|
||||
file: string,
|
||||
content: any,
|
||||
content: string,
|
||||
skipCache: boolean = process.env.NODE_ENV === 'production',
|
||||
): Promise<void> {
|
||||
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
|
||||
return Object.keys(obj)
|
||||
.sort()
|
||||
.reduce((acc: any, key: string) => {
|
||||
.reduce((acc: Record<string, T>, key: string) => {
|
||||
acc[key] = obj[key];
|
||||
return acc;
|
||||
}, {});
|
||||
|
|
|
@ -45,7 +45,7 @@ if (notifier.lastUpdateCheck === Date.now()) {
|
|||
}
|
||||
|
||||
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 siteDocusaurusPackagesForUpdate = Object.keys(sitePkg.dependencies)
|
||||
.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?`,
|
||||
initial: true,
|
||||
};
|
||||
prompts(question).then((answer: any) => {
|
||||
prompts(question).then((answer) => {
|
||||
if (answer.shouldChangePort === true) {
|
||||
resolve(port);
|
||||
} else {
|
||||
|
|
|
@ -18,7 +18,7 @@ declare global {
|
|||
// eslint-disable-next-line camelcase, @typescript-eslint/no-explicit-any
|
||||
const __webpack_require__: {gca: (name: string) => string};
|
||||
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>({
|
||||
children,
|
||||
values,
|
||||
}: InterpolateProps<Str>) {
|
||||
}: InterpolateProps<Str>): ReactNode {
|
||||
return interpolate(children, values);
|
||||
}
|
||||
|
|
|
@ -15,7 +15,10 @@ import {useBaseUrlUtils} from './useBaseUrl';
|
|||
|
||||
declare global {
|
||||
interface Window {
|
||||
docusaurus: any;
|
||||
docusaurus: {
|
||||
prefetch: (routePath: string) => boolean;
|
||||
preload: (routePath: string) => boolean;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -113,13 +116,15 @@ function Link({
|
|||
if (IOSupported && ref && isInternal) {
|
||||
// If IO supported and element reference found, setup Observer functionality.
|
||||
handleIntersection(ref, () => {
|
||||
if (targetLink != null) {
|
||||
window.docusaurus.prefetch(targetLink);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const onMouseEnter = () => {
|
||||
if (!preloaded.current) {
|
||||
if (!preloaded.current && targetLink != null) {
|
||||
window.docusaurus.preload(targetLink);
|
||||
preloaded.current = true;
|
||||
}
|
||||
|
@ -128,8 +133,10 @@ function Link({
|
|||
useEffect(() => {
|
||||
// If IO is not supported. We prefetch by default (only once).
|
||||
if (!IOSupported && isInternal) {
|
||||
if (targetLink != null) {
|
||||
window.docusaurus.prefetch(targetLink);
|
||||
}
|
||||
}
|
||||
|
||||
// When unmounting, stop intersection observer from watching.
|
||||
return () => {
|
||||
|
|
|
@ -13,7 +13,7 @@ import useDocusaurusContext from './useDocusaurusContext';
|
|||
// import {DEFAULT_PLUGIN_ID} from '../../constants';
|
||||
const DEFAULT_PLUGIN_ID = 'default';
|
||||
|
||||
export default function useGlobalData() {
|
||||
export default function useGlobalData(): Record<string, unknown> {
|
||||
const {globalData} = useDocusaurusContext();
|
||||
if (!globalData) {
|
||||
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}`,
|
||||
);
|
||||
}
|
||||
return pluginGlobalData;
|
||||
return pluginGlobalData as Record<string, T>;
|
||||
}
|
||||
|
||||
export function usePluginData<T = unknown>(
|
||||
|
|
|
@ -91,7 +91,7 @@ export default async function build(
|
|||
i18n.locales.indexOf(locale) === i18n.locales.length - 1;
|
||||
return tryToBuildLocale({locale, isLastLocale});
|
||||
});
|
||||
return results[0]!;
|
||||
return results[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ export async function loadPlugins({
|
|||
}): Promise<{
|
||||
plugins: InitPlugin[];
|
||||
pluginsRouteConfigs: RouteConfig[];
|
||||
globalData: any;
|
||||
globalData: unknown;
|
||||
themeConfigTranslated: ThemeConfig;
|
||||
}> {
|
||||
// 1. Plugin Lifecycle - Initialization/Constructor.
|
||||
|
|
|
@ -42,9 +42,15 @@ export default function loadPresets(
|
|||
throw new Error('Invalid presets format detected in config.');
|
||||
}
|
||||
|
||||
const presetModule: any = importFresh(
|
||||
pluginRequire.resolve(presetModuleImport),
|
||||
);
|
||||
type PresetInitializeFunction = (
|
||||
context: LoadContext,
|
||||
presetOptions: Record<string, unknown>,
|
||||
) => Preset;
|
||||
const presetModule = importFresh<
|
||||
PresetInitializeFunction & {
|
||||
default?: PresetInitializeFunction;
|
||||
}
|
||||
>(pluginRequire.resolve(presetModuleImport));
|
||||
const preset: Preset = (presetModule.default || presetModule)(
|
||||
context,
|
||||
presetOptions,
|
||||
|
|
|
@ -552,7 +552,7 @@ describe('getPluginsDefaultCodeTranslationMessages', () => {
|
|||
});
|
||||
|
||||
describe('applyDefaultCodeTranslations', () => {
|
||||
const consoleSpy = jest.spyOn(console, 'warn').mockImplementation() as any;
|
||||
const consoleSpy = jest.spyOn(console, 'warn').mockImplementation();
|
||||
beforeEach(() => {
|
||||
consoleSpy.mockClear();
|
||||
});
|
||||
|
|
|
@ -11,6 +11,7 @@ import merge from 'webpack-merge';
|
|||
import webpack, {
|
||||
Configuration,
|
||||
Loader,
|
||||
NewLoader,
|
||||
Plugin,
|
||||
RuleSetRule,
|
||||
Stats,
|
||||
|
@ -23,7 +24,11 @@ import path from 'path';
|
|||
import crypto from 'crypto';
|
||||
import chalk from 'chalk';
|
||||
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 {version as cacheLoaderVersion} from 'cache-loader/package.json';
|
||||
import {
|
||||
|
@ -177,11 +182,13 @@ export function applyConfigurePostCss(
|
|||
configurePostCss: NonNullable<ConfigurePostCssFn>,
|
||||
config: Configuration,
|
||||
): Configuration {
|
||||
type LocalPostCSSLoader = Loader & {options: {postcssOptions: any}};
|
||||
type LocalPostCSSLoader = Loader & {
|
||||
options: {postcssOptions: PostCssOptions};
|
||||
};
|
||||
|
||||
// TODO not ideal heuristic but good enough for our usecase?
|
||||
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
|
||||
|
@ -207,7 +214,7 @@ export function applyConfigurePostCss(
|
|||
// See https://webpack.js.org/configuration/stats/#statswarningsfilter
|
||||
// @slorber: note sure why we have to re-implement this logic
|
||||
// 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(
|
||||
warningsFilter: WarningFilter[],
|
||||
warnings: string[],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue