Skip to content

Commit 5cdb744

Browse files
committed
Support Plugin return Promise
1 parent c72bf9d commit 5cdb744

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

lib/prepare.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const yamlParser = require('js-yaml')
55
const tomlParser = require('toml')
66
const createMarkdown = require('./markdown')
77
const tempPath = path.resolve(__dirname, 'app/.temp')
8-
const { inferTitle, extractHeaders, parseFrontmatter, loadPlugin, isAsyncFunction } = require('./util')
8+
const { inferTitle, extractHeaders, parseFrontmatter, loadPlugin } = require('./util')
99

1010
fs.ensureDirSync(tempPath)
1111

@@ -88,10 +88,12 @@ if (!Object.assign) Object.assign = require('object-assign')`
8888
pluginRequired = pluginRequired(plugin.options)
8989
}
9090
}
91-
if (isAsyncFunction(pluginRequired)) {
92-
await pluginRequired(options)
93-
} else {
94-
pluginRequired(options)
91+
if (pluginRequired) {
92+
try {
93+
await pluginRequired(options)
94+
} catch (e) {
95+
throw e
96+
}
9597
}
9698
}
9799
}

lib/util/index.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,3 @@ exports.loadPlugin = (pluginPath, options) => {
101101
}
102102
return plugin
103103
}
104-
105-
exports.isAsyncFunction = (func) => {
106-
const AsyncFunction = (async () => {}).constructor
107-
return (func instanceof AsyncFunction && AsyncFunction !== Function)
108-
}

0 commit comments

Comments
 (0)