Skip to content

Commit 52aab17

Browse files
authored
Merge pull request #1679 from tailwindcss/add-coreplugins-api
Add corePlugins function to plugin API
2 parents 09ff23f + 652100e commit 52aab17

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

__tests__/processPlugins.test.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,62 @@ test('plugins apply all global variants when variants are configured globally',
744744
`)
745745
})
746746

747+
test('plugins can check if corePlugins are enabled', () => {
748+
const { components, utilities } = processPlugins(
749+
[
750+
function({ addUtilities, corePlugins }) {
751+
addUtilities({
752+
'.test': {
753+
'text-color': corePlugins('textColor') ? 'true' : 'false',
754+
opacity: corePlugins('opacity') ? 'true' : 'false',
755+
},
756+
})
757+
},
758+
],
759+
makeConfig({
760+
corePlugins: { textColor: false },
761+
})
762+
)
763+
764+
expect(components.length).toBe(0)
765+
expect(css(utilities)).toMatchCss(`
766+
@variants {
767+
.test {
768+
text-color: false;
769+
opacity: true
770+
}
771+
}
772+
`)
773+
})
774+
775+
test('plugins can check if corePlugins are enabled when using array white-listing', () => {
776+
const { components, utilities } = processPlugins(
777+
[
778+
function({ addUtilities, corePlugins }) {
779+
addUtilities({
780+
'.test': {
781+
'text-color': corePlugins('textColor') ? 'true' : 'false',
782+
opacity: corePlugins('opacity') ? 'true' : 'false',
783+
},
784+
})
785+
},
786+
],
787+
makeConfig({
788+
corePlugins: ['textColor'],
789+
})
790+
)
791+
792+
expect(components.length).toBe(0)
793+
expect(css(utilities)).toMatchCss(`
794+
@variants {
795+
.test {
796+
text-color: true;
797+
opacity: false
798+
}
799+
}
800+
`)
801+
})
802+
747803
test('plugins can provide fallbacks to keys missing from the config', () => {
748804
const { components, utilities } = processPlugins(
749805
[

src/util/processPlugins.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ export default function(plugins, config) {
4141
postcss,
4242
config: getConfigValue,
4343
theme: (path, defaultValue) => getConfigValue(`theme.${path}`, defaultValue),
44+
corePlugins: path => {
45+
if (Array.isArray(config.corePlugins)) {
46+
return config.corePlugins.includes(path)
47+
}
48+
49+
return getConfigValue(`corePlugins.${path}`, true)
50+
},
4451
variants: (path, defaultValue) => {
4552
if (Array.isArray(config.variants)) {
4653
return config.variants

0 commit comments

Comments
 (0)