From 5cdb74447e293dad9867d3dbf56976ac25b683af Mon Sep 17 00:00:00 2001 From: SangND Date: Tue, 24 Apr 2018 18:02:14 +0700 Subject: [PATCH] Support Plugin return Promise --- lib/prepare.js | 12 +++++++----- lib/util/index.js | 5 ----- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/prepare.js b/lib/prepare.js index c16f46ba76..5559131475 100644 --- a/lib/prepare.js +++ b/lib/prepare.js @@ -5,7 +5,7 @@ const yamlParser = require('js-yaml') const tomlParser = require('toml') const createMarkdown = require('./markdown') const tempPath = path.resolve(__dirname, 'app/.temp') -const { inferTitle, extractHeaders, parseFrontmatter, loadPlugin, isAsyncFunction } = require('./util') +const { inferTitle, extractHeaders, parseFrontmatter, loadPlugin } = require('./util') fs.ensureDirSync(tempPath) @@ -88,10 +88,12 @@ if (!Object.assign) Object.assign = require('object-assign')` pluginRequired = pluginRequired(plugin.options) } } - if (isAsyncFunction(pluginRequired)) { - await pluginRequired(options) - } else { - pluginRequired(options) + if (pluginRequired) { + try { + await pluginRequired(options) + } catch (e) { + throw e + } } } } diff --git a/lib/util/index.js b/lib/util/index.js index 7ff530d802..2b080948af 100644 --- a/lib/util/index.js +++ b/lib/util/index.js @@ -101,8 +101,3 @@ exports.loadPlugin = (pluginPath, options) => { } return plugin } - -exports.isAsyncFunction = (func) => { - const AsyncFunction = (async () => {}).constructor - return (func instanceof AsyncFunction && AsyncFunction !== Function) -}