Skip to content

Commit 75dfa4e

Browse files
committed
Drop array format for presets key instead
1 parent eb9490c commit 75dfa4e

File tree

4 files changed

+69
-59
lines changed

4 files changed

+69
-59
lines changed

__tests__/customConfig.test.js

Lines changed: 63 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -211,26 +211,26 @@ test('tailwind.config.js is picked up by default when passing an empty object',
211211
})
212212
})
213213

214-
test('when custom config is an array the default config is not included', () => {
214+
test('the default config can be overridden using the presets key', () => {
215215
return postcss([
216-
tailwind([
217-
{
218-
theme: {
219-
extend: {
220-
colors: {
221-
black: 'black',
216+
tailwind({
217+
presets: [
218+
{
219+
theme: {
220+
extend: {
221+
colors: {
222+
black: 'black',
223+
},
224+
backgroundColor: theme => theme('colors'),
222225
},
223-
backgroundColor: theme => theme('colors'),
224226
},
227+
corePlugins: ['backgroundColor'],
225228
},
226-
corePlugins: ['backgroundColor'],
227-
},
228-
{
229-
theme: {
230-
extend: { colors: { white: 'white' } },
231-
},
229+
],
230+
theme: {
231+
extend: { colors: { white: 'white' } },
232232
},
233-
]),
233+
}),
234234
])
235235
.process(
236236
`
@@ -252,48 +252,65 @@ test('when custom config is an array the default config is not included', () =>
252252
})
253253
})
254254

255-
test('when custom config is an array in a file the default config is not included', () => {
256-
return inTempDirectory(() => {
257-
fs.writeFileSync(
258-
path.resolve(defaultConfigFile),
259-
`module.exports = [
255+
test('presets can have their own presets', () => {
256+
return postcss([
257+
tailwind({
258+
presets: [
259+
{
260+
theme: {
261+
colors: { red: '#dd0000' },
262+
},
263+
},
260264
{
265+
presets: [
266+
{
267+
theme: {
268+
colors: {
269+
transparent: 'transparent',
270+
red: '#ff0000',
271+
},
272+
},
273+
},
274+
],
261275
theme: {
262276
extend: {
263277
colors: {
264278
black: 'black',
279+
red: '#ee0000',
265280
},
266281
backgroundColor: theme => theme('colors'),
267282
},
268283
},
269284
corePlugins: ['backgroundColor'],
270285
},
271-
{
272-
theme: {
273-
extend: { colors: { white: 'white' } },
274-
},
275-
}
276-
]`
286+
],
287+
theme: {
288+
extend: { colors: { white: 'white' } },
289+
},
290+
}),
291+
])
292+
.process(
293+
`
294+
@tailwind utilities
295+
`,
296+
{ from: undefined }
277297
)
298+
.then(result => {
299+
const expected = `
300+
.bg-transparent {
301+
background-color: transparent;
302+
}
303+
.bg-red {
304+
background-color: #ee0000;
305+
}
306+
.bg-black {
307+
background-color: black;
308+
}
309+
.bg-white {
310+
background-color: white;
311+
}
312+
`
278313

279-
return postcss([tailwind()])
280-
.process(
281-
`
282-
@tailwind utilities
283-
`,
284-
{ from: undefined }
285-
)
286-
.then(result => {
287-
const expected = `
288-
.bg-black {
289-
background-color: black;
290-
}
291-
.bg-white {
292-
background-color: white;
293-
}
294-
`
295-
296-
expect(result.css).toMatchCss(expected)
297-
})
298-
})
314+
expect(result.css).toMatchCss(expected)
315+
})
299316
})

resolveConfig.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ const resolveConfigObjects = require('./lib/util/resolveConfig').default
22
const getAllConfigs = require('./lib/util/getAllConfigs').default
33

44
module.exports = function resolveConfig(...configs) {
5-
if (configs.length === 1 && Array.isArray(configs[0])) {
6-
return resolveConfigObjects([...configs[0]].reverse())
7-
}
85
const [, ...defaultConfigs] = getAllConfigs(configs[0])
96
return resolveConfigObjects([...configs, ...defaultConfigs])
107
}

src/index.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ import { defaultConfigFile } from './constants'
1414
import defaultConfig from '../stubs/defaultConfig.stub.js'
1515

1616
function resolveConfigPath(filePath) {
17-
// require('tailwindcss')([{ theme: ..., variants: ... }, {...}])
18-
if (Array.isArray(filePath)) {
19-
return undefined
20-
}
2117
// require('tailwindcss')({ theme: ..., variants: ... })
2218
if (_.isObject(filePath) && !_.has(filePath, 'config') && !_.isEmpty(filePath)) {
2319
return undefined
@@ -64,10 +60,6 @@ const getConfigFunction = config => () => {
6460

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

67-
if (Array.isArray(configObject)) {
68-
return resolveConfig([...configObject].reverse())
69-
}
70-
7163
return resolveConfig([...getAllConfigs(configObject)])
7264
}
7365

src/util/getAllConfigs.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ import extendedFontSizeScale from '../flagged/extendedFontSizeScale.js'
77
import darkModeVariant from '../flagged/darkModeVariant.js'
88
import standardFontWeights from '../flagged/standardFontWeights'
99
import additionalBreakpoint from '../flagged/additionalBreakpoint'
10+
import { flatMap, get } from 'lodash'
11+
12+
export default function getAllConfigs(config, defaultPresets = [defaultConfig]) {
13+
const configs = flatMap([...get(config, 'presets', defaultPresets)].reverse(), preset => {
14+
return getAllConfigs(preset, [])
15+
})
1016

11-
export default function getAllConfigs(config) {
12-
const configs = [defaultConfig]
1317
const features = {
1418
uniformColorPalette,
1519
extendedSpacingScale,

0 commit comments

Comments
 (0)