Skip to content

Commit

Permalink
Add class for plugin list
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Nov 12, 2019
1 parent 71d9c99 commit 00d9499
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions packages/size-limit/load-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ function toArray (obj) {
return typeof obj === 'object' ? Object.keys(obj) : []
}

class Plugins {
constructor (list) {
this.list = list
this.isEmpty = list.length === 0
}

has (type) {
return this.list.some(i => i.name === `@size-limit/${ type }`)
}
}

module.exports = function loadPlugins (pkg) {
if (!pkg || !pkg.packageJson) return []

Expand All @@ -12,11 +23,7 @@ module.exports = function loadPlugins (pkg) {
paths: [process.cwd()]
}))), [])

return {
list,
isEmpty: list.length === 0,
has (type) {
return this.list.some(i => i.name === `@size-limit/${ type }`)
}
}
return new Plugins(list)
}

module.exports.Plugins = Plugins

0 comments on commit 00d9499

Please sign in to comment.