Skip to content

Restructure config file for 1.0 #637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
36 changes: 13 additions & 23 deletions __tests__/applyAtRule.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import postcss from 'postcss'
import substituteClassApplyAtRules from '../src/lib/substituteClassApplyAtRules'
import processPlugins from '../src/util/processPlugins'
import defaultPlugins from '../src/defaultPlugins'
import corePlugins from '../src/corePlugins'
import defaultConfig from '../defaultConfig.stub.js'

const { utilities: defaultUtilities } = processPlugins(defaultPlugins(defaultConfig), defaultConfig)
const { utilities: defaultUtilities } = processPlugins(corePlugins(defaultConfig), defaultConfig)

function run(input, config = defaultConfig, utilities = defaultUtilities) {
return postcss([substituteClassApplyAtRules(config, utilities)]).process(input, {
Expand Down Expand Up @@ -202,18 +202,13 @@ test('you can apply utility classes without using the given prefix', () => {

const config = {
...defaultConfig,
options: {
...defaultConfig.options,
prefix: 'tw-',
},
prefix: 'tw-',
}

return run(input, config, processPlugins(defaultPlugins(defaultConfig), config).utilities).then(
result => {
expect(result.css).toEqual(expected)
expect(result.warnings().length).toBe(0)
}
)
return run(input, config, processPlugins(corePlugins(config), config).utilities).then(result => {
expect(result.css).toEqual(expected)
expect(result.warnings().length).toBe(0)
})
})

test('you can apply utility classes without using the given prefix when using a function for the prefix', () => {
Expand All @@ -227,18 +222,13 @@ test('you can apply utility classes without using the given prefix when using a

const config = {
...defaultConfig,
options: {
...defaultConfig.options,
prefix: () => {
return 'tw-'
},
prefix: () => {
return 'tw-'
},
}

return run(input, config, processPlugins(defaultPlugins(defaultConfig), config).utilities).then(
result => {
expect(result.css).toEqual(expected)
expect(result.warnings().length).toBe(0)
}
)
return run(input, config, processPlugins(corePlugins(config), config).utilities).then(result => {
expect(result.css).toEqual(expected)
expect(result.warnings().length).toBe(0)
})
})
2 changes: 0 additions & 2 deletions __tests__/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ describe('cli', () => {
it('creates a Tailwind config file', () => {
return cli(['init']).then(() => {
expect(utils.writeFile.mock.calls[0][0]).toEqual(constants.defaultConfigFile)
expect(utils.writeFile.mock.calls[0][1]).toContain('defaultConfig')
Copy link
Contributor

@MattStypa MattStypa Feb 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about checking for defaultTheme instead of dropping this assertion?

expect(utils.writeFile.mock.calls[0][1]).toContain('defaultTheme')

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what I even want to scaffold for the config file when people use tailwind init yet so just gonna punt on it entirely for now I think.

})
})

it('creates a Tailwind config file in a custom location', () => {
return cli(['init', 'custom.js']).then(() => {
expect(utils.writeFile.mock.calls[0][0]).toEqual('custom.js')
expect(utils.writeFile.mock.calls[0][1]).toContain('defaultConfig')
})
})

Expand Down
32 changes: 20 additions & 12 deletions __tests__/configFunction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ function run(input, opts = {}) {

test('it looks up values in the config using dot notation', () => {
const input = `
.banana { color: config('colors.yellow'); }
.banana { color: config('theme.colors.yellow'); }
`

const output = `
.banana { color: #f7cc50; }
`

return run(input, {
colors: {
yellow: '#f7cc50',
theme: {
colors: {
yellow: '#f7cc50',
},
},
}).then(result => {
expect(result.css).toEqual(output)
Expand All @@ -26,16 +28,18 @@ test('it looks up values in the config using dot notation', () => {

test('quotes are optional around the lookup path', () => {
const input = `
.banana { color: config(colors.yellow); }
.banana { color: config(theme.colors.yellow); }
`

const output = `
.banana { color: #f7cc50; }
`

return run(input, {
colors: {
yellow: '#f7cc50',
theme: {
colors: {
yellow: '#f7cc50',
},
},
}).then(result => {
expect(result.css).toEqual(output)
Expand All @@ -45,16 +49,18 @@ test('quotes are optional around the lookup path', () => {

test('a default value can be provided', () => {
const input = `
.cookieMonster { color: config('colors.blue', #0000ff); }
.cookieMonster { color: config('theme.colors.blue', #0000ff); }
`

const output = `
.cookieMonster { color: #0000ff; }
`

return run(input, {
colors: {
yellow: '#f7cc50',
theme: {
colors: {
yellow: '#f7cc50',
},
},
}).then(result => {
expect(result.css).toEqual(output)
Expand All @@ -64,16 +70,18 @@ test('a default value can be provided', () => {

test('quotes are preserved around default values', () => {
const input = `
.heading { font-family: config('fonts.sans', "Helvetica Neue"); }
.heading { font-family: config('theme.fonts.sans', "Helvetica Neue"); }
`

const output = `
.heading { font-family: "Helvetica Neue"; }
`

return run(input, {
fonts: {
serif: 'Constantia',
theme: {
fonts: {
serif: 'Constantia',
},
},
}).then(result => {
expect(result.css).toEqual(output)
Expand Down
18 changes: 8 additions & 10 deletions __tests__/containerPlugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@ function css(nodes) {

function config(overrides) {
return _.defaultsDeep(overrides, {
screens: {
sm: '576px',
md: '768px',
lg: '992px',
xl: '1200px',
},
options: {
prefix: '',
important: false,
separator: ':',
theme: {
screens: {
sm: '576px',
md: '768px',
lg: '992px',
xl: '1200px',
},
},
prefix: '',
})
}

Expand Down
6 changes: 4 additions & 2 deletions __tests__/customConfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ test('it uses the values from the custom config file', () => {
test('custom config can be passed as an object', () => {
return postcss([
tailwind({
screens: {
mobile: '400px',
theme: {
screens: {
mobile: '400px',
},
},
}),
])
Expand Down
6 changes: 4 additions & 2 deletions __tests__/fixtures/custom-config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module.exports = {
screens: {
mobile: '400px',
theme: {
screens: {
mobile: '400px',
},
},
}
2 changes: 1 addition & 1 deletion __tests__/fixtures/tailwind-input.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
@responsive {
.example {
@apply .font-bold;
color: config('colors.red');
color: config('theme.colors.red');
}
}
5 changes: 0 additions & 5 deletions __tests__/fixtures/tailwind-output-important.css
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,6 @@ textarea {
resize: vertical;
}

img {
max-width: 100%;
height: auto;
}

input::placeholder,
textarea::placeholder {
color: inherit;
Expand Down
Loading