refactor: unify export directive style (#6751)

This commit is contained in:
Joshua Chen 2022-02-24 17:25:17 +08:00 committed by GitHub
parent 0c807b3501
commit 0d14470d54
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
105 changed files with 315 additions and 510 deletions

View file

@ -36,7 +36,7 @@ const {
*
* cache data is stored in `~/.config/configstore/update-notifier-@docusaurus`
*/
async function beforeCli() {
export default async function beforeCli() {
const notifier = updateNotifier({
pkg: {
name,
@ -134,5 +134,3 @@ async function beforeCli() {
process.exit(1);
}
}
export default beforeCli;

View file

@ -70,9 +70,7 @@ function getTransformOptions(isServer: boolean): TransformOptions {
};
}
function babelPresets(api: ConfigAPI): TransformOptions {
export default function babelPresets(api: ConfigAPI): TransformOptions {
const callerName = api.caller((caller) => caller?.name);
return getTransformOptions(callerName === 'server');
}
export default babelPresets;

View file

@ -21,7 +21,7 @@ import './client-lifecycles-dispatcher';
import ErrorBoundary from '@docusaurus/ErrorBoundary';
import Error from '@theme/Error';
function App(): JSX.Element {
export default function App(): JSX.Element {
return (
<ErrorBoundary fallback={Error}>
<DocusaurusContextProvider>
@ -37,5 +37,3 @@ function App(): JSX.Element {
</ErrorBoundary>
);
}
export default App;

View file

@ -10,7 +10,7 @@ import useIsBrowser from '@docusaurus/useIsBrowser';
// Similar comp to the one described here:
// https://www.joshwcomeau.com/react/the-perils-of-rehydration/#abstractions
function BrowserOnly({
export default function BrowserOnly({
children,
fallback,
}: {
@ -32,5 +32,3 @@ Current type: ${isValidElement(children) ? 'React element' : typeof children}`);
return fallback || null;
}
export default BrowserOnly;

View file

@ -14,7 +14,7 @@ import flat from '../flat';
type OptsLoader = Record<string, typeof registry[keyof typeof registry][0]>;
function ComponentCreator(
export default function ComponentCreator(
path: string,
hash: string,
): ReturnType<typeof Loadable> {
@ -89,5 +89,3 @@ function ComponentCreator(
},
});
}
export default ComponentCreator;

View file

@ -15,7 +15,7 @@ interface State {
error: Error | null;
}
class ErrorBoundary extends React.Component<Props, State> {
export default class ErrorBoundary extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {error: null};
@ -47,5 +47,3 @@ class ErrorBoundary extends React.Component<Props, State> {
);
}
}
export default ErrorBoundary;

View file

@ -9,8 +9,6 @@ import React from 'react';
import {Helmet} from 'react-helmet-async';
import type {Props} from '@docusaurus/Head';
function Head(props: Props): JSX.Element {
export default function Head(props: Props): JSX.Element {
return <Helmet {...props} />;
}
export default Head;

View file

@ -5,6 +5,4 @@
* LICENSE file in the root directory of this source tree.
*/
import {renderRoutes} from 'react-router-config';
export default renderRoutes;
export {renderRoutes as default} from 'react-router-config';

View file

@ -9,8 +9,6 @@ import {useContext} from 'react';
import {Context} from './docusaurusContext';
import type {DocusaurusContext} from '@docusaurus/types';
function useDocusaurusContext(): DocusaurusContext {
export default function useDocusaurusContext(): DocusaurusContext {
return useContext(Context);
}
export default useDocusaurusContext;

View file

@ -10,7 +10,7 @@ import type {RouteChunksTree} from '@docusaurus/types';
const isTree = (x: string | RouteChunksTree): x is RouteChunksTree =>
typeof x === 'object' && !!x && Object.keys(x).length > 0;
function flat(target: RouteChunksTree): Record<string, string> {
export default function flat(target: RouteChunksTree): Record<string, string> {
const delimiter = '.';
const output: Record<string, string> = {};
@ -30,5 +30,3 @@ function flat(target: RouteChunksTree): Record<string, string> {
step(target);
return output;
}
export default flat;

View file

@ -10,7 +10,7 @@ import type {Location} from 'history';
// Memoize previously normalized pathnames.
const pathnames: Record<string, string> = {};
function normalizeLocation<T extends Location>(location: T): T {
export default function normalizeLocation<T extends Location>(location: T): T {
if (pathnames[location.pathname]) {
return {
...location,
@ -32,5 +32,3 @@ function normalizeLocation<T extends Location>(location: T): T {
pathname,
};
}
export default normalizeLocation;

View file

@ -67,7 +67,7 @@ const supportedPrefetchStrategy = support('prefetch')
const preFetched: Record<string, boolean> = {};
function prefetch(url: string): Promise<void> {
export default function prefetch(url: string): Promise<void> {
return new Promise((resolve) => {
if (preFetched[url]) {
resolve();
@ -82,5 +82,3 @@ function prefetch(url: string): Promise<void> {
.catch(() => {}); // 404s are logged to the console anyway.
});
}
export default prefetch;

View file

@ -31,7 +31,7 @@ function ErrorDisplay({error, tryAgain}: Props): JSX.Element {
);
}
function Error({error, tryAgain}: Props): JSX.Element {
export default function Error({error, tryAgain}: Props): JSX.Element {
// We wrap the error in its own error boundary because the layout can actually
// throw too... Only the ErrorDisplay component is simple enough to be
// considered safe to never throw
@ -46,5 +46,3 @@ function Error({error, tryAgain}: Props): JSX.Element {
</ErrorBoundary>
);
}
export default Error;

View file

@ -11,7 +11,11 @@ import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import useBaseUrl from '@docusaurus/useBaseUrl';
import type {Props} from '@theme/Layout';
function Layout({children, title, description}: Props): JSX.Element {
export default function Layout({
children,
title,
description,
}: Props): JSX.Element {
const context = useDocusaurusContext();
const {siteConfig} = context;
const {favicon, tagline, title: defaultTitle} = siteConfig;
@ -30,5 +34,3 @@ function Layout({children, title, description}: Props): JSX.Element {
</>
);
}
export default Layout;

View file

@ -8,7 +8,7 @@
import React from 'react';
import Layout from '@theme/Layout';
function NotFound(): JSX.Element {
export default function NotFound(): JSX.Element {
return (
<Layout title="Page Not Found">
<div
@ -24,5 +24,3 @@ function NotFound(): JSX.Element {
</Layout>
);
}
export default NotFound;

View file

@ -14,8 +14,6 @@ import type {ReactNode} from 'react';
// and these providers won't reset state when we navigate
//
// See https://github.com/facebook/docusaurus/issues/3919
function Root({children}: {children: ReactNode}): ReactNode {
export default function Root({children}: {children: ReactNode}): ReactNode {
return children;
}
export default Root;

View file

@ -30,7 +30,7 @@ declare module 'react-loadable-ssr-addon-v5-slorber' {
new (props: {filename: string});
}
declare const plugin: ReactLoadableSSRAddon;
const plugin: ReactLoadableSSRAddon;
export default plugin;
}
@ -57,7 +57,7 @@ declare module '@slorber/static-site-generator-webpack-plugin' {
});
}
declare const plugin: StaticSiteGeneratorPlugin;
const plugin: StaticSiteGeneratorPlugin;
export default plugin;
}

View file

@ -10,7 +10,7 @@ import {load} from './index';
import type {Props} from '@docusaurus/types';
// Helper methods to setup dummy/fake projects.
const loadSetup = async (name: string): Promise<Props> => {
export default async function loadSetup(name: string): Promise<Props> {
const fixtures = path.join(__dirname, '__tests__', '__fixtures__');
const simpleSite = path.join(fixtures, 'simple-site');
const customSite = path.join(fixtures, 'custom-site');
@ -22,6 +22,4 @@ const loadSetup = async (name: string): Promise<Props> => {
default:
return load(simpleSite);
}
};
export default loadSetup;
}

View file

@ -20,7 +20,7 @@ const pluginName = 'chunk-asset-plugin';
*
* "gca" stands for "get chunk asset"
*/
class ChunkAssetPlugin {
export default class ChunkAssetPlugin {
apply(compiler: Compiler): void {
compiler.hooks.thisCompilation.tap(pluginName, ({mainTemplate}) => {
mainTemplate.hooks.requireExtensions.tap(pluginName, (source, chunk) => {
@ -52,5 +52,3 @@ class ChunkAssetPlugin {
});
}
}
export default ChunkAssetPlugin;

View file

@ -67,7 +67,7 @@ export interface Options {
cleanOnceBeforeBuildPatterns?: string[];
}
class CleanWebpackPlugin {
export default class CleanWebpackPlugin {
private readonly verbose: boolean;
private readonly cleanStaleWebpackAssets: boolean;
private readonly protectWebpackAssets: boolean;
@ -250,5 +250,3 @@ class CleanWebpackPlugin {
}
}
}
export default CleanWebpackPlugin;