From 652100e2d534eea2d51aae7de2bd8bb911264e28 Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Fri, 1 May 2020 14:41:12 -0400 Subject: [PATCH] Add corePlugins function to plugin API --- __tests__/processPlugins.test.js | 56 ++++++++++++++++++++++++++++++++ src/util/processPlugins.js | 7 ++++ 2 files changed, 63 insertions(+) diff --git a/__tests__/processPlugins.test.js b/__tests__/processPlugins.test.js index a43c2a62c..04ea56079 100644 --- a/__tests__/processPlugins.test.js +++ b/__tests__/processPlugins.test.js @@ -744,6 +744,62 @@ test('plugins apply all global variants when variants are configured globally', `) }) +test('plugins can check if corePlugins are enabled', () => { + const { components, utilities } = processPlugins( + [ + function({ addUtilities, corePlugins }) { + addUtilities({ + '.test': { + 'text-color': corePlugins('textColor') ? 'true' : 'false', + opacity: corePlugins('opacity') ? 'true' : 'false', + }, + }) + }, + ], + makeConfig({ + corePlugins: { textColor: false }, + }) + ) + + expect(components.length).toBe(0) + expect(css(utilities)).toMatchCss(` + @variants { + .test { + text-color: false; + opacity: true + } + } + `) +}) + +test('plugins can check if corePlugins are enabled when using array white-listing', () => { + const { components, utilities } = processPlugins( + [ + function({ addUtilities, corePlugins }) { + addUtilities({ + '.test': { + 'text-color': corePlugins('textColor') ? 'true' : 'false', + opacity: corePlugins('opacity') ? 'true' : 'false', + }, + }) + }, + ], + makeConfig({ + corePlugins: ['textColor'], + }) + ) + + expect(components.length).toBe(0) + expect(css(utilities)).toMatchCss(` + @variants { + .test { + text-color: true; + opacity: false + } + } + `) +}) + test('plugins can provide fallbacks to keys missing from the config', () => { const { components, utilities } = processPlugins( [ diff --git a/src/util/processPlugins.js b/src/util/processPlugins.js index a927e8fc9..7a0012300 100644 --- a/src/util/processPlugins.js +++ b/src/util/processPlugins.js @@ -41,6 +41,13 @@ export default function(plugins, config) { postcss, config: getConfigValue, theme: (path, defaultValue) => getConfigValue(`theme.${path}`, defaultValue), + corePlugins: path => { + if (Array.isArray(config.corePlugins)) { + return config.corePlugins.includes(path) + } + + return getConfigValue(`corePlugins.${path}`, true) + }, variants: (path, defaultValue) => { if (Array.isArray(config.variants)) { return config.variants