From 39831b1c2f9cbeebdba94c73ce353efb7c44e802 Mon Sep 17 00:00:00 2001 From: hdmr14 <58992133+hdmr14@users.noreply.github.com> Date: Thu, 11 Mar 2021 08:26:24 +0900 Subject: [PATCH] feat(plugins): add support wildcard config for scoped package plugin (#3659) * feat(plugins): add support wildcard config for scoped package plugin * fix(plugins): support Node 10 --- lib/plugin.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/plugin.js b/lib/plugin.js index 53dfc68a2..8805a288d 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -32,12 +32,21 @@ function resolve (plugins, emitter) { return } const pluginDirectory = path.normalize(path.join(__dirname, '/../..')) - const regexp = new RegExp(`^${plugin.replace('*', '.*')}`) + const regexp = new RegExp(`^${plugin.replace(/\*/g, '.*').replace(/\//g, '[/\\\\]')}`) log.debug(`Loading ${plugin} from ${pluginDirectory}`) fs.readdirSync(pluginDirectory) - .filter((pluginName) => !IGNORED_PACKAGES.includes(pluginName) && regexp.test(pluginName)) - .forEach((pluginName) => requirePlugin(`${pluginDirectory}/${pluginName}`)) + .map((e) => { + const modulePath = path.join(pluginDirectory, e) + if (e[0] === '@') { + return fs.readdirSync(modulePath).map((e) => path.join(modulePath, e)) + } + return modulePath + }) + .reduce((a, x) => a.concat(x), []) + .map((modulePath) => path.relative(pluginDirectory, modulePath)) + .filter((moduleName) => !IGNORED_PACKAGES.includes(moduleName) && regexp.test(moduleName)) + .forEach((pluginName) => requirePlugin(path.join(pluginDirectory, pluginName))) } else if (helper.isObject(plugin)) { log.debug(`Loading inline plugin defining ${Object.keys(plugin).join(', ')}.`) modules.push(plugin)