Don't mutate the user's config when resolving

This commit is contained in:
Adam Wathan 2019-03-22 12:47:14 -04:00
parent b8e7c12cfd
commit 7e1113561a
2 changed files with 41 additions and 1 deletions

View File

@ -826,3 +826,43 @@ test('theme values in the extend section are lazily evaluated', () => {
},
})
})
test('the original theme is not mutated', () => {
const userConfig = {
theme: {
extend: {
colors: {
orange: 'orange',
},
},
},
}
const defaultConfig = {
prefix: '-',
important: false,
separator: ':',
theme: {
colors: {
cyan: 'cyan',
magenta: 'magenta',
yellow: 'yellow',
},
},
variants: {
borderColor: ['responsive', 'hover', 'focus'],
},
}
resolveConfig([userConfig, defaultConfig])
expect(userConfig).toEqual({
theme: {
extend: {
colors: {
orange: 'orange',
},
},
},
})
})

View File

@ -38,7 +38,7 @@ function resolveFunctionKeys(object) {
export default function resolveConfig(configs) {
return defaults(
{
theme: resolveFunctionKeys(mergeExtensions(defaults(...map(configs, 'theme')))),
theme: resolveFunctionKeys(mergeExtensions(defaults({}, ...map(configs, 'theme')))),
variants: defaults(...map(configs, 'variants')),
},
...configs