mirror of
https://github.com/tailwindlabs/tailwindcss.git
synced 2025-12-08 21:36:08 +00:00
Rename mergeConfig to resolveConfig
Accept configs to resolve as an array to allow reuse when only resolving from a single config, update processTailwindFeatures to use resolveConfig even when no config is provided, update defaultTheme to self-reference colors.
This commit is contained in:
parent
40413690a2
commit
04e1274e86
@ -1,4 +1,4 @@
|
||||
import mergeConfigWithDefaults from '../src/util/mergeConfigWithDefaults'
|
||||
import resolveConfig from '../src/util/resolveConfig'
|
||||
|
||||
test('prefix key overrides default prefix', () => {
|
||||
const userConfig = {
|
||||
@ -21,7 +21,7 @@ test('prefix key overrides default prefix', () => {
|
||||
},
|
||||
}
|
||||
|
||||
const result = mergeConfigWithDefaults(userConfig, defaultConfig)
|
||||
const result = resolveConfig([userConfig, defaultConfig])
|
||||
|
||||
expect(result).toEqual({
|
||||
prefix: 'tw-',
|
||||
@ -61,7 +61,7 @@ test('important key overrides default important', () => {
|
||||
},
|
||||
}
|
||||
|
||||
const result = mergeConfigWithDefaults(userConfig, defaultConfig)
|
||||
const result = resolveConfig([userConfig, defaultConfig])
|
||||
|
||||
expect(result).toEqual({
|
||||
prefix: '',
|
||||
@ -101,7 +101,7 @@ test('separator key overrides default separator', () => {
|
||||
},
|
||||
}
|
||||
|
||||
const result = mergeConfigWithDefaults(userConfig, defaultConfig)
|
||||
const result = resolveConfig([userConfig, defaultConfig])
|
||||
|
||||
expect(result).toEqual({
|
||||
prefix: '',
|
||||
@ -158,7 +158,7 @@ test('theme key is merged instead of replaced', () => {
|
||||
},
|
||||
}
|
||||
|
||||
const result = mergeConfigWithDefaults(userConfig, defaultConfig)
|
||||
const result = resolveConfig([userConfig, defaultConfig])
|
||||
|
||||
expect(result).toEqual({
|
||||
prefix: '-',
|
||||
@ -227,7 +227,7 @@ test('variants key is merged instead of replaced', () => {
|
||||
},
|
||||
}
|
||||
|
||||
const result = mergeConfigWithDefaults(userConfig, defaultConfig)
|
||||
const result = resolveConfig([userConfig, defaultConfig])
|
||||
|
||||
expect(result).toEqual({
|
||||
prefix: '-',
|
||||
@ -281,7 +281,7 @@ test('missing top level keys are pulled from the default config', () => {
|
||||
},
|
||||
}
|
||||
|
||||
const result = mergeConfigWithDefaults(userConfig, defaultConfig)
|
||||
const result = resolveConfig([userConfig, defaultConfig])
|
||||
|
||||
expect(result).toEqual({
|
||||
prefix: '-',
|
||||
@ -331,7 +331,7 @@ test('functions in the default theme section are lazily evaluated', () => {
|
||||
},
|
||||
}
|
||||
|
||||
const result = mergeConfigWithDefaults(userConfig, defaultConfig)
|
||||
const result = resolveConfig([userConfig, defaultConfig])
|
||||
|
||||
expect(result).toEqual({
|
||||
prefix: '-',
|
||||
@ -399,7 +399,7 @@ test('functions in the user theme section are lazily evaluated', () => {
|
||||
},
|
||||
}
|
||||
|
||||
const result = mergeConfigWithDefaults(userConfig, defaultConfig)
|
||||
const result = resolveConfig([userConfig, defaultConfig])
|
||||
|
||||
expect(result).toEqual({
|
||||
prefix: '-',
|
||||
@ -155,8 +155,8 @@ module.exports = function() {
|
||||
normal: '0',
|
||||
wide: '0.05em',
|
||||
},
|
||||
textColors: colors,
|
||||
backgroundColors: colors,
|
||||
textColors: theme => theme.colors,
|
||||
backgroundColors: theme => theme.colors,
|
||||
backgroundSize: {
|
||||
auto: 'auto',
|
||||
cover: 'cover',
|
||||
@ -169,7 +169,9 @@ module.exports = function() {
|
||||
'4': '4px',
|
||||
'8': '8px',
|
||||
},
|
||||
borderColors: global.Object.assign({ default: colors['grey-light'] }, colors),
|
||||
borderColors: theme => {
|
||||
return global.Object.assign({ default: colors['grey-light'] }, theme.colors)
|
||||
},
|
||||
borderRadius: {
|
||||
none: '0',
|
||||
sm: '.125rem',
|
||||
|
||||
10
src/index.js
10
src/index.js
@ -6,7 +6,7 @@ import perfectionist from 'perfectionist'
|
||||
|
||||
import registerConfigAsDependency from './lib/registerConfigAsDependency'
|
||||
import processTailwindFeatures from './processTailwindFeatures'
|
||||
import mergeConfigWithDefaults from './util/mergeConfigWithDefaults'
|
||||
import resolveConfig from './util/resolveConfig'
|
||||
|
||||
const plugin = postcss.plugin('tailwind', config => {
|
||||
const plugins = []
|
||||
@ -17,17 +17,17 @@ const plugin = postcss.plugin('tailwind', config => {
|
||||
|
||||
const getConfig = () => {
|
||||
if (_.isUndefined(config)) {
|
||||
return require('../defaultConfig')()
|
||||
return resolveConfig([require('../defaultConfig')()])
|
||||
}
|
||||
|
||||
if (!_.isObject(config)) {
|
||||
delete require.cache[require.resolve(path.resolve(config))]
|
||||
}
|
||||
|
||||
return mergeConfigWithDefaults(
|
||||
return resolveConfig([
|
||||
_.isObject(config) ? config : require(path.resolve(config)),
|
||||
require('../defaultConfig')()
|
||||
)
|
||||
require('../defaultConfig')(),
|
||||
])
|
||||
}
|
||||
|
||||
return postcss([
|
||||
|
||||
@ -4,18 +4,17 @@ function resolveFunctionKeys(object) {
|
||||
return Object.keys(object).reduce((resolved, key) => {
|
||||
return {
|
||||
...resolved,
|
||||
[key]: _.isFunction(object[key]) ? object[key](object) : object[key]
|
||||
[key]: _.isFunction(object[key]) ? object[key](object) : object[key],
|
||||
}
|
||||
}, {})
|
||||
}
|
||||
|
||||
export default function(userConfig, defaultConfig) {
|
||||
export default function(configs) {
|
||||
return _.defaults(
|
||||
{
|
||||
theme: resolveFunctionKeys(_.defaults(userConfig.theme, defaultConfig.theme)),
|
||||
variants: _.defaults(userConfig.variants, defaultConfig.variants),
|
||||
theme: resolveFunctionKeys(_.defaults(..._.map(configs, 'theme'))),
|
||||
variants: _.defaults(..._.map(configs, 'variants')),
|
||||
},
|
||||
userConfig,
|
||||
defaultConfig
|
||||
...configs
|
||||
)
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user