From 74887c50da1001df27b9ece1d8f10cb611ac4728 Mon Sep 17 00:00:00 2001 From: Shigma <33423008+Shigma@users.noreply.github.com> Date: Sun, 7 Apr 2019 00:55:49 +0800 Subject: [PATCH] feat($core): assert return type for functional plugin (#1516) --- packages/@vuepress/core/lib/node/plugin-api/util.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/@vuepress/core/lib/node/plugin-api/util.js b/packages/@vuepress/core/lib/node/plugin-api/util.js index a0d7be90ed..b3c17a5025 100644 --- a/packages/@vuepress/core/lib/node/plugin-api/util.js +++ b/packages/@vuepress/core/lib/node/plugin-api/util.js @@ -43,6 +43,14 @@ exports.flattenPlugin = function ( // 'Object.create' here is to give each plugin a separate context, // but also own the inheritance context. config = config(pluginOptions, Object.create(pluginContext), self) + const { valid, warnMsg } = assertTypes(config, [Object]) + if (!valid) { + logger.warn( + `[${chalk.gray(shortcut)}] ` + + `Invalid value for plugin: ${warnMsg}` + ) + config = {} + } } // respect name in local plugin config