Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
664f923
Move prefix option to top-level in config
adamwathan Jan 18, 2019
1a46f6b
Move important to top level option
adamwathan Jan 18, 2019
e8d16fc
Move separator to top level config option
adamwathan Jan 18, 2019
326f35a
Remove options key from config
adamwathan Jan 18, 2019
2f9172c
Update every plugin to accept its config as a parameter
adamwathan Jan 18, 2019
99b5e90
Move all config values back to single file
adamwathan Jan 24, 2019
3d2a598
Don't test for presence of defaultConfig in defaultConfig
adamwathan Jan 24, 2019
f10f182
Remove special "modules" merge behavior
adamwathan Jan 24, 2019
760e93b
Use user's specified default border color
adamwathan Jan 24, 2019
fd22dea
Always load core plugins by default
adamwathan Feb 1, 2019
95bb283
Rename defaultPlugins to corePlugins
adamwathan Feb 1, 2019
c56ae6c
Move modules outside of styles to top level key
adamwathan Feb 1, 2019
d98e97f
Rename modules to variants
adamwathan Feb 1, 2019
3fbd6b3
Disable plugins using corePlugins instead of variants
adamwathan Feb 1, 2019
efc7927
Rename styles to theme
adamwathan Feb 1, 2019
6533679
Inline theme into default config
adamwathan Feb 1, 2019
f8ddb76
Remove theme comments
adamwathan Feb 1, 2019
ec1bdd2
Move screens into theme config
adamwathan Feb 1, 2019
f3097f9
Move colors inside of theme
adamwathan Feb 1, 2019
b036cac
Fix code style
adamwathan Feb 1, 2019
ffdc2b0
Intelligently deep merge user's config
adamwathan Feb 1, 2019
195cdec
Don't skip CLI tests
adamwathan Feb 1, 2019
a4bdae4
Extract default theme to separate file
adamwathan Feb 1, 2019
083ab97
Fix code style
adamwathan Feb 1, 2019
d165661
Fix failing test
adamwathan Feb 1, 2019
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
Prev Previous commit
Next Next commit
Remove special "modules" merge behavior
Modules key no longer actually exists in the config so this is pointless.
  • Loading branch information
adamwathan committed Feb 1, 2019
commit f10f1825efef2cc1c95086370e8a2546800dedd3
81 changes: 3 additions & 78 deletions __tests__/mergeConfigWithDefaults.test.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
import mergeConfigWithDefaults from '../src/util/mergeConfigWithDefaults'

test('user top-level keys override default top-level keys except modules', () => {
test('user top-level keys override default top-level keys', () => {
const userConfig = {
modules: {},
prefix: 'tw-',
important: true,
}

const defaultConfig = {
modules: {
flexbox: ['responsive'],
},
prefix: '-',
important: false,
separator: ':',
}

const result = mergeConfigWithDefaults(userConfig, defaultConfig)

expect(result).toEqual({
modules: {
flexbox: ['responsive'],
},
prefix: 'tw-',
important: true,
separator: ':',
})
})

Expand Down Expand Up @@ -50,73 +45,3 @@ test('missing top level keys are pulled from the default config', () => {
modules: {},
})
})

test('user modules are merged with default modules', () => {
const userConfig = {
modules: { flexbox: false },
}

const defaultConfig = {
modules: {
flexbox: ['responsive'],
textAlign: ['responsive'],
},
}

const result = mergeConfigWithDefaults(userConfig, defaultConfig)

expect(result).toEqual({
modules: {
flexbox: false,
textAlign: ['responsive'],
},
})
})

test('setting modules to "all" creates all variants for all modules', () => {
const userConfig = {
modules: 'all',
}

const defaultConfig = {
modules: {
flexbox: ['responsive'],
textAlign: ['hover'],
textColors: ['focus'],
},
}

const result = mergeConfigWithDefaults(userConfig, defaultConfig)

expect(result).toEqual({
modules: {
flexbox: ['responsive', 'group-hover', 'hover', 'focus-within', 'focus', 'active'],
textAlign: ['responsive', 'group-hover', 'hover', 'focus-within', 'focus', 'active'],
textColors: ['responsive', 'group-hover', 'hover', 'focus-within', 'focus', 'active'],
},
})
})

test('setting modules to an array of variants applies those variants to all modules', () => {
const userConfig = {
modules: ['responsive', 'focus', 'hover', 'custom-variant'],
}

const defaultConfig = {
modules: {
flexbox: ['responsive'],
textAlign: ['hover'],
textColors: ['focus'],
},
}

const result = mergeConfigWithDefaults(userConfig, defaultConfig)

expect(result).toEqual({
modules: {
flexbox: ['responsive', 'focus', 'hover', 'custom-variant'],
textAlign: ['responsive', 'focus', 'hover', 'custom-variant'],
textColors: ['responsive', 'focus', 'hover', 'custom-variant'],
},
})
})
23 changes: 1 addition & 22 deletions src/util/mergeConfigWithDefaults.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,5 @@
import _ from 'lodash'

function mergeModules(userModules, defaultModules) {
if (_.isArray(userModules)) {
return _.mapValues(defaultModules, () => userModules)
}

if (userModules === 'all') {
return _.mapValues(defaultModules, () => [
'responsive',
'group-hover',
'hover',
'focus-within',
'focus',
'active',
])
}

return _.defaults(userModules, defaultModules)
}

export default function(userConfig, defaultConfig) {
_.defaults(userConfig, defaultConfig)
userConfig.modules = mergeModules(userConfig.modules, defaultConfig.modules)
return userConfig
return _.defaults(userConfig, defaultConfig)
}