Skip to content

Commit

Permalink
feat(plugins): add support wildcard config for scoped package plugin (#…
Browse files Browse the repository at this point in the history
…3659)

* feat(plugins): add support wildcard config for scoped package plugin

* fix(plugins): support Node 10
  • Loading branch information
hdmr14 authored Mar 10, 2021
1 parent 10afab1 commit 39831b1
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 39831b1

Please sign in to comment.