Make handler optional in object plugins

This commit is contained in:
Adam Wathan 2019-10-12 13:46:51 -04:00
parent 53dff626a7
commit 94a1d30809
3 changed files with 44 additions and 6 deletions

View File

@ -1244,3 +1244,46 @@ test('plugins can be provided as an object with a handler function', () => {
}
`)
})
test('plugins can provide a config but no handler', () => {
const { components, utilities } = processPlugins(
[
{
config: {
prefix: 'tw-',
},
},
{
handler({ addUtilities }) {
addUtilities({
'.object-fill': {
'object-fit': 'fill',
},
'.object-contain': {
'object-fit': 'contain',
},
'.object-cover': {
'object-fit': 'cover',
},
})
},
},
],
makeConfig()
)
expect(components.length).toBe(0)
expect(css(utilities)).toMatchCss(`
@variants {
.object-fill {
object-fit: fill
}
.object-contain {
object-fit: contain
}
.object-cover {
object-fit: cover
}
}
`)
})

View File

@ -1367,7 +1367,6 @@ test('plugin config modifications are applied', () => {
config: {
prefix: 'tw-',
},
handler() {},
},
],
}
@ -1416,7 +1415,6 @@ test('user config takes precedence over plugin config modifications', () => {
config: {
prefix: 'tw-',
},
handler() {},
},
],
}
@ -1468,13 +1466,11 @@ test('plugin config can register plugins that also have config', () => {
config: {
important: true,
},
handler() {},
},
{
config: {
separator: '__',
},
handler() {},
},
],
},
@ -1530,7 +1526,6 @@ test('plugin configs take precedence over plugin configs registered by that plug
config: {
prefix: 'inner-',
},
handler() {},
},
],
},

View File

@ -29,7 +29,7 @@ export default function(plugins, config) {
const getConfigValue = (path, defaultValue) => _.get(config, path, defaultValue)
plugins.forEach(plugin => {
const handler = isFunction(plugin) ? plugin : plugin.handler
const handler = isFunction(plugin) ? plugin : _.get(plugin, 'handler', () => {})
handler({
postcss,