Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make resolveConfig compatible with feature flag configs #2347

Merged
merged 2 commits into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
}