Skip to content

Commit 39831b1

Browse files
authoredMar 10, 2021
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
1 parent 10afab1 commit 39831b1

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed
 

‎lib/plugin.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,21 @@ function resolve (plugins, emitter) {
3232
return
3333
}
3434
const pluginDirectory = path.normalize(path.join(__dirname, '/../..'))
35-
const regexp = new RegExp(`^${plugin.replace('*', '.*')}`)
35+
const regexp = new RegExp(`^${plugin.replace(/\*/g, '.*').replace(/\//g, '[/\\\\]')}`)
3636

3737
log.debug(`Loading ${plugin} from ${pluginDirectory}`)
3838
fs.readdirSync(pluginDirectory)
39-
.filter((pluginName) => !IGNORED_PACKAGES.includes(pluginName) && regexp.test(pluginName))
40-
.forEach((pluginName) => requirePlugin(`${pluginDirectory}/${pluginName}`))
39+
.map((e) => {
40+
const modulePath = path.join(pluginDirectory, e)
41+
if (e[0] === '@') {
42+
return fs.readdirSync(modulePath).map((e) => path.join(modulePath, e))
43+
}
44+
return modulePath
45+
})
46+
.reduce((a, x) => a.concat(x), [])
47+
.map((modulePath) => path.relative(pluginDirectory, modulePath))
48+
.filter((moduleName) => !IGNORED_PACKAGES.includes(moduleName) && regexp.test(moduleName))
49+
.forEach((pluginName) => requirePlugin(path.join(pluginDirectory, pluginName)))
4150
} else if (helper.isObject(plugin)) {
4251
log.debug(`Loading inline plugin defining ${Object.keys(plugin).join(', ')}.`)
4352
modules.push(plugin)

0 commit comments

Comments
 (0)
Please sign in to comment.