Skip to content

Commit

Permalink
Make resolveConfig compatible with feature flag configs (#2347)
Browse files Browse the repository at this point in the history
* Make resolveConfig compatible with feature flag configs

* Update changelog
  • Loading branch information
adamwathan authored Sep 7, 2020
1 parent ac36e8d commit e5c193a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 44 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Nothing yet!
- Fix issue where `resolveConfig` didn't take into account configs added by feature flags ([#2347](https://github.com/tailwindlabs/tailwindcss/pull/2347))

## [1.8.4] - 2020-09-06

Expand Down
9 changes: 7 additions & 2 deletions resolveConfig.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const resolveConfigObjects = require('./lib/util/resolveConfig').default
const defaultConfig = require('./stubs/defaultConfig.stub.js')
const getAllConfigs = require('./lib/util/getAllConfigs').default

module.exports = function resolveConfig(...configs) {
return resolveConfigObjects([...configs, defaultConfig])
// Make sure the correct config object is mutated to include flagged config plugins.
// This sucks, refactor soon.
const firstConfigWithPlugins = configs.find(c => Array.isArray(c.plugins)) || configs[0]
const [, ...defaultConfigs] = getAllConfigs(firstConfigWithPlugins)

return resolveConfigObjects([...configs, ...defaultConfigs])
}
42 changes: 1 addition & 41 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,9 @@ import registerConfigAsDependency from './lib/registerConfigAsDependency'
import processTailwindFeatures from './processTailwindFeatures'
import formatCSS from './lib/formatCSS'
import resolveConfig from './util/resolveConfig'
import getAllConfigs from './util/getAllConfigs'
import { defaultConfigFile } from './constants'
import defaultConfig from '../stubs/defaultConfig.stub.js'
import { flagEnabled } from './featureFlags'

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.js'
import standardFontWeights from './flagged/standardFontWeights'

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

if (flagEnabled(config, 'uniformColorPalette')) {
configs.unshift(uniformColorPalette)
}

if (flagEnabled(config, 'extendedSpacingScale')) {
configs.unshift(extendedSpacingScale)
}

if (flagEnabled(config, 'defaultLineHeights')) {
configs.unshift(defaultLineHeights)
}

if (flagEnabled(config, 'extendedFontSizeScale')) {
configs.unshift(extendedFontSizeScale)
}

if (flagEnabled(config, 'standardFontWeights')) {
configs.unshift(standardFontWeights)
}

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

return [config, ...configs]
}

function resolveConfigPath(filePath) {
// require('tailwindcss')({ theme: ..., variants: ... })
Expand Down
41 changes: 41 additions & 0 deletions src/util/getAllConfigs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import defaultConfig from '../../stubs/defaultConfig.stub.js'
import { flagEnabled } from '../featureFlags'
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.js'
import standardFontWeights from '../flagged/standardFontWeights'

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

if (flagEnabled(config, 'uniformColorPalette')) {
configs.unshift(uniformColorPalette)
}

if (flagEnabled(config, 'extendedSpacingScale')) {
configs.unshift(extendedSpacingScale)
}

if (flagEnabled(config, 'defaultLineHeights')) {
configs.unshift(defaultLineHeights)
}

if (flagEnabled(config, 'extendedFontSizeScale')) {
configs.unshift(extendedFontSizeScale)
}

if (flagEnabled(config, 'standardFontWeights')) {
configs.unshift(standardFontWeights)
}

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

return [config, ...configs]
}

0 comments on commit e5c193a

Please sign in to comment.