From 053c5073f8898397a76ba3983a44910aa74f59a6 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Mon, 15 Jun 2020 14:23:24 +0800 Subject: [PATCH 1/3] 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 --- packages/docusaurus-plugin-content-blog/src/index.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/index.ts b/packages/docusaurus-plugin-content-blog/src/index.ts index 17d8c0de1ece..aa4d3a32ca82 100644 --- a/packages/docusaurus-plugin-content-blog/src/index.ts +++ b/packages/docusaurus-plugin-content-blog/src/index.ts @@ -448,11 +448,9 @@ export default function pluginContentBlog( `${feedType}.xml`, ); const feedContent = feedType === 'rss' ? feed.rss2() : feed.atom1(); - try { - fs.writeFileSync(feedPath, feedContent); - } catch (err) { + return fs.outputFile(feedPath, feedContent).catch((err) => { throw new Error(`Generating ${feedType} feed failed: ${err}`); - } + }); }), ); }, From 41d13d51d0416cca56899c8b7366e3947a465f81 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Mon, 15 Jun 2020 14:26:59 +0800 Subject: [PATCH 2/3] perf(v2): convert synchronous filewrite to asynchronous in sitemap generate --- packages/docusaurus-plugin-sitemap/src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/docusaurus-plugin-sitemap/src/index.ts b/packages/docusaurus-plugin-sitemap/src/index.ts index 003f34587b18..b7a5acf75f5a 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}`); } From b7df851460b2f85ab8ede7951a1cf66c3621cdaf Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Mon, 15 Jun 2020 21:20:09 +0800 Subject: [PATCH 3/3] perf(v2): convert Promise style to async/await style for consistency --- packages/docusaurus-plugin-content-blog/src/index.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/index.ts b/packages/docusaurus-plugin-content-blog/src/index.ts index aa4d3a32ca82..6dd807a524d0 100644 --- a/packages/docusaurus-plugin-content-blog/src/index.ts +++ b/packages/docusaurus-plugin-content-blog/src/index.ts @@ -441,16 +441,18 @@ 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, `${feedType}.xml`, ); const feedContent = feedType === 'rss' ? feed.rss2() : feed.atom1(); - return fs.outputFile(feedPath, feedContent).catch((err) => { + try { + await fs.outputFile(feedPath, feedContent); + } catch (err) { throw new Error(`Generating ${feedType} feed failed: ${err}`); - }); + } }), ); },