From 930222ea87e9349bba7e9a5988508e7f69c90a3d Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Mon, 15 Jun 2020 22:04:15 +0800 Subject: [PATCH] refactor(v2): convert synchronous file write to asynchronous (#2936) * perf(v2): convert synchronous filewrite to asynchronous in feed file generate This looks like should return a Promise list , other than a sync io operation * perf(v2): convert synchronous filewrite to asynchronous in sitemap generate * perf(v2): convert Promise style to async/await style for consistency --- packages/docusaurus-plugin-content-blog/src/index.ts | 4 ++-- packages/docusaurus-plugin-sitemap/src/index.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/index.ts b/packages/docusaurus-plugin-content-blog/src/index.ts index 17d8c0de1e..6dd807a524 100644 --- a/packages/docusaurus-plugin-content-blog/src/index.ts +++ b/packages/docusaurus-plugin-content-blog/src/index.ts @@ -441,7 +441,7 @@ export default function pluginContentBlog( const feedTypes = getFeedTypes(options.feedOptions?.type); await Promise.all( - feedTypes.map((feedType) => { + feedTypes.map(async (feedType) => { const feedPath = path.join( outDir, options.routeBasePath, @@ -449,7 +449,7 @@ export default function pluginContentBlog( ); const feedContent = feedType === 'rss' ? feed.rss2() : feed.atom1(); try { - fs.writeFileSync(feedPath, feedContent); + await fs.outputFile(feedPath, feedContent); } catch (err) { throw new Error(`Generating ${feedType} feed failed: ${err}`); } diff --git a/packages/docusaurus-plugin-sitemap/src/index.ts b/packages/docusaurus-plugin-sitemap/src/index.ts index 003f34587b..b7a5acf75f 100644 --- a/packages/docusaurus-plugin-sitemap/src/index.ts +++ b/packages/docusaurus-plugin-sitemap/src/index.ts @@ -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 {PluginOptions} from './types'; import createSitemap from './createSitemap'; @@ -37,7 +37,7 @@ export default function pluginSitemap( // Write sitemap file. const sitemapPath = path.join(outDir, 'sitemap.xml'); try { - fs.writeFileSync(sitemapPath, generatedSitemap); + await fs.outputFile(sitemapPath, generatedSitemap); } catch (err) { throw new Error(`Sitemap error: ${err}`); }