Skip to content

Commit 94a1d30

Browse files
committed
Make handler optional in object plugins
1 parent 53dff62 commit 94a1d30

File tree

3 files changed

+44
-6
lines changed

3 files changed

+44
-6
lines changed

__tests__/processPlugins.test.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,3 +1244,46 @@ test('plugins can be provided as an object with a handler function', () => {
12441244
}
12451245
`)
12461246
})
1247+
1248+
test('plugins can provide a config but no handler', () => {
1249+
const { components, utilities } = processPlugins(
1250+
[
1251+
{
1252+
config: {
1253+
prefix: 'tw-',
1254+
},
1255+
},
1256+
{
1257+
handler({ addUtilities }) {
1258+
addUtilities({
1259+
'.object-fill': {
1260+
'object-fit': 'fill',
1261+
},
1262+
'.object-contain': {
1263+
'object-fit': 'contain',
1264+
},
1265+
'.object-cover': {
1266+
'object-fit': 'cover',
1267+
},
1268+
})
1269+
},
1270+
},
1271+
],
1272+
makeConfig()
1273+
)
1274+
1275+
expect(components.length).toBe(0)
1276+
expect(css(utilities)).toMatchCss(`
1277+
@variants {
1278+
.object-fill {
1279+
object-fit: fill
1280+
}
1281+
.object-contain {
1282+
object-fit: contain
1283+
}
1284+
.object-cover {
1285+
object-fit: cover
1286+
}
1287+
}
1288+
`)
1289+
})

__tests__/resolveConfig.test.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,6 @@ test('plugin config modifications are applied', () => {
13671367
config: {
13681368
prefix: 'tw-',
13691369
},
1370-
handler() {},
13711370
},
13721371
],
13731372
}
@@ -1416,7 +1415,6 @@ test('user config takes precedence over plugin config modifications', () => {
14161415
config: {
14171416
prefix: 'tw-',
14181417
},
1419-
handler() {},
14201418
},
14211419
],
14221420
}
@@ -1468,13 +1466,11 @@ test('plugin config can register plugins that also have config', () => {
14681466
config: {
14691467
important: true,
14701468
},
1471-
handler() {},
14721469
},
14731470
{
14741471
config: {
14751472
separator: '__',
14761473
},
1477-
handler() {},
14781474
},
14791475
],
14801476
},
@@ -1530,7 +1526,6 @@ test('plugin configs take precedence over plugin configs registered by that plug
15301526
config: {
15311527
prefix: 'inner-',
15321528
},
1533-
handler() {},
15341529
},
15351530
],
15361531
},

src/util/processPlugins.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default function(plugins, config) {
2929
const getConfigValue = (path, defaultValue) => _.get(config, path, defaultValue)
3030

3131
plugins.forEach(plugin => {
32-
const handler = isFunction(plugin) ? plugin : plugin.handler
32+
const handler = isFunction(plugin) ? plugin : _.get(plugin, 'handler', () => {})
3333

3434
handler({
3535
postcss,

0 commit comments

Comments
 (0)