Skip to content

Commit

Permalink
Drop array format for presets key instead
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwathan committed Oct 8, 2020
1 parent eb9490c commit 75dfa4e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 59 deletions.
109 changes: 63 additions & 46 deletions __tests__/customConfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,26 +211,26 @@ test('tailwind.config.js is picked up by default when passing an empty object',
})
})

test('when custom config is an array the default config is not included', () => {
test('the default config can be overridden using the presets key', () => {
return postcss([
tailwind([
{
theme: {
extend: {
colors: {
black: 'black',
tailwind({
presets: [
{
theme: {
extend: {
colors: {
black: 'black',
},
backgroundColor: theme => theme('colors'),
},
backgroundColor: theme => theme('colors'),
},
corePlugins: ['backgroundColor'],
},
corePlugins: ['backgroundColor'],
},
{
theme: {
extend: { colors: { white: 'white' } },
},
],
theme: {
extend: { colors: { white: 'white' } },
},
]),
}),
])
.process(
`
Expand All @@ -252,48 +252,65 @@ test('when custom config is an array the default config is not included', () =>
})
})

test('when custom config is an array in a file the default config is not included', () => {
return inTempDirectory(() => {
fs.writeFileSync(
path.resolve(defaultConfigFile),
`module.exports = [
test('presets can have their own presets', () => {
return postcss([
tailwind({
presets: [
{
theme: {
colors: { red: '#dd0000' },
},
},
{
presets: [
{
theme: {
colors: {
transparent: 'transparent',
red: '#ff0000',
},
},
},
],
theme: {
extend: {
colors: {
black: 'black',
red: '#ee0000',
},
backgroundColor: theme => theme('colors'),
},
},
corePlugins: ['backgroundColor'],
},
{
theme: {
extend: { colors: { white: 'white' } },
},
}
]`
],
theme: {
extend: { colors: { white: 'white' } },
},
}),
])
.process(
`
@tailwind utilities
`,
{ from: undefined }
)
.then(result => {
const expected = `
.bg-transparent {
background-color: transparent;
}
.bg-red {
background-color: #ee0000;
}
.bg-black {
background-color: black;
}
.bg-white {
background-color: white;
}
`

return postcss([tailwind()])
.process(
`
@tailwind utilities
`,
{ from: undefined }
)
.then(result => {
const expected = `
.bg-black {
background-color: black;
}
.bg-white {
background-color: white;
}
`

expect(result.css).toMatchCss(expected)
})
})
expect(result.css).toMatchCss(expected)
})
})
3 changes: 0 additions & 3 deletions resolveConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ const resolveConfigObjects = require('./lib/util/resolveConfig').default
const getAllConfigs = require('./lib/util/getAllConfigs').default

module.exports = function resolveConfig(...configs) {
if (configs.length === 1 && Array.isArray(configs[0])) {
return resolveConfigObjects([...configs[0]].reverse())
}
const [, ...defaultConfigs] = getAllConfigs(configs[0])
return resolveConfigObjects([...configs, ...defaultConfigs])
}
8 changes: 0 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ import { defaultConfigFile } from './constants'
import defaultConfig from '../stubs/defaultConfig.stub.js'

function resolveConfigPath(filePath) {
// require('tailwindcss')([{ theme: ..., variants: ... }, {...}])
if (Array.isArray(filePath)) {
return undefined
}
// require('tailwindcss')({ theme: ..., variants: ... })
if (_.isObject(filePath) && !_.has(filePath, 'config') && !_.isEmpty(filePath)) {
return undefined
Expand Down Expand Up @@ -64,10 +60,6 @@ const getConfigFunction = config => () => {

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

if (Array.isArray(configObject)) {
return resolveConfig([...configObject].reverse())
}

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

Expand Down
8 changes: 6 additions & 2 deletions src/util/getAllConfigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ import extendedFontSizeScale from '../flagged/extendedFontSizeScale.js'
import darkModeVariant from '../flagged/darkModeVariant.js'
import standardFontWeights from '../flagged/standardFontWeights'
import additionalBreakpoint from '../flagged/additionalBreakpoint'
import { flatMap, get } from 'lodash'

export default function getAllConfigs(config, defaultPresets = [defaultConfig]) {
const configs = flatMap([...get(config, 'presets', defaultPresets)].reverse(), preset => {
return getAllConfigs(preset, [])
})

export default function getAllConfigs(config) {
const configs = [defaultConfig]
const features = {
uniformColorPalette,
extendedSpacingScale,
Expand Down

0 comments on commit 75dfa4e

Please sign in to comment.