Skip to content

Commit

Permalink
Fix issue where dark mode experiment won't work if user has plugins a…
Browse files Browse the repository at this point in the history
…rray in config (#2322)
  • Loading branch information
adamwathan authored Sep 4, 2020
1 parent 8e49e48 commit 02eb6a6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
28 changes: 28 additions & 0 deletions __tests__/darkMode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,34 @@ test('generating dark mode variants uses the media strategy by default', () => {
})
})

test('dark mode variants can be generated even when the user has their own plugins array', () => {
const input = `
@variants dark {
.text-red {
color: red;
}
}
`

const expected = `
.text-red {
color: red;
}
@media (prefers-color-scheme: dark) {
.dark\\:text-red {
color: red;
}
}
`

expect.assertions(2)

return run(input, { plugins: [] }).then(result => {
expect(result.css).toMatchCss(expected)
expect(result.warnings().length).toBe(0)
})
})

test('dark mode variants can be generated using the class strategy', () => {
const input = `
@variants dark {
Expand Down
13 changes: 8 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import uniformColorPalette from './flagged/uniformColorPalette.js'
import extendedSpacingScale from './flagged/extendedSpacingScale.js'
import defaultLineHeights from './flagged/defaultLineHeights.js'
import extendedFontSizeScale from './flagged/extendedFontSizeScale.js'
import darkModeVariant from './flagged/darkModeVariant'
import darkModeVariant from './flagged/darkModeVariant.js'

function getDefaultConfigs(config) {
function getAllConfigs(config) {
const configs = [defaultConfig]

if (flagEnabled(config, 'uniformColorPalette')) {
Expand All @@ -40,9 +40,12 @@ function getDefaultConfigs(config) {

if (flagEnabled(config, 'darkModeVariant')) {
configs.unshift(darkModeVariant)
if (Array.isArray(config.plugins)) {
config.plugins = [...darkModeVariant.plugins, ...config.plugins]
}
}

return configs
return [config, ...configs]
}

function resolveConfigPath(filePath) {
Expand Down Expand Up @@ -78,7 +81,7 @@ function resolveConfigPath(filePath) {

const getConfigFunction = config => () => {
if (_.isUndefined(config) && !_.isObject(config)) {
return resolveConfig([...getDefaultConfigs(defaultConfig)])
return resolveConfig([...getAllConfigs(defaultConfig)])
}

// Skip this if Jest is running: https://github.com/facebook/jest/pull/9841#issuecomment-621417584
Expand All @@ -92,7 +95,7 @@ const getConfigFunction = config => () => {

const configObject = _.isObject(config) ? _.get(config, 'config', config) : require(config)

return resolveConfig([configObject, ...getDefaultConfigs(configObject)])
return resolveConfig([...getAllConfigs(configObject)])
}

const plugin = postcss.plugin('tailwind', config => {
Expand Down

0 comments on commit 02eb6a6

Please sign in to comment.