feat: async plugin creator functions (#6166)

This commit is contained in:
Sébastien Lorber 2021-12-22 19:10:49 +01:00 committed by GitHub
parent f8a670966e
commit b393700a61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 90 additions and 79 deletions

View file

@ -16,7 +16,7 @@ describe('docusaurus-plugin-content-pages', () => {
const siteDir = path.join(__dirname, '__fixtures__', 'website');
const context = await loadContext(siteDir);
const pluginPath = 'src/pages';
const plugin = pluginContentPages(
const plugin = await pluginContentPages(
context,
normalizePluginOptions({
path: pluginPath,
@ -77,7 +77,7 @@ describe('docusaurus-plugin-content-pages', () => {
const siteDir = path.join(__dirname, '__fixtures__', 'website');
const context = await loadContext(siteDir);
const pluginPath = 'src/pages';
const plugin = pluginContentPages(
const plugin = await pluginContentPages(
{
...context,
i18n: {

View file

@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/
import fs from 'fs';
import fs from 'fs-extra';
import path from 'path';
import {
encodePath,
@ -45,10 +45,10 @@ export function getContentPathList(contentPaths: PagesContentPaths): string[] {
const isMarkdownSource = (source: string) =>
source.endsWith('.md') || source.endsWith('.mdx');
export default function pluginContentPages(
export default async function pluginContentPages(
context: LoadContext,
options: PluginOptions,
): Plugin<LoadedContent | null> {
): Promise<Plugin<LoadedContent | null>> {
if (options.admonitions) {
options.remarkPlugins = options.remarkPlugins.concat([
[admonitions, options.admonitions || {}],
@ -90,7 +90,7 @@ export default function pluginContentPages(
async loadContent() {
const {include} = options;
if (!fs.existsSync(contentPaths.contentPath)) {
if (!(await fs.pathExists(contentPaths.contentPath))) {
return null;
}