Skip to content

Commit a187253

Browse files
authored
Merge pull request #637 from tailwindcss/config-restructuring
Restructure config file for 1.0
2 parents ee27bba + d165661 commit a187253

File tree

126 files changed

+967
-1360
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+967
-1360
lines changed

__tests__/applyAtRule.test.js

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import postcss from 'postcss'
22
import substituteClassApplyAtRules from '../src/lib/substituteClassApplyAtRules'
33
import processPlugins from '../src/util/processPlugins'
4-
import defaultPlugins from '../src/defaultPlugins'
4+
import corePlugins from '../src/corePlugins'
55
import defaultConfig from '../defaultConfig.stub.js'
66

7-
const { utilities: defaultUtilities } = processPlugins(defaultPlugins(defaultConfig), defaultConfig)
7+
const { utilities: defaultUtilities } = processPlugins(corePlugins(defaultConfig), defaultConfig)
88

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

203203
const config = {
204204
...defaultConfig,
205-
options: {
206-
...defaultConfig.options,
207-
prefix: 'tw-',
208-
},
205+
prefix: 'tw-',
209206
}
210207

211-
return run(input, config, processPlugins(defaultPlugins(defaultConfig), config).utilities).then(
212-
result => {
213-
expect(result.css).toEqual(expected)
214-
expect(result.warnings().length).toBe(0)
215-
}
216-
)
208+
return run(input, config, processPlugins(corePlugins(config), config).utilities).then(result => {
209+
expect(result.css).toEqual(expected)
210+
expect(result.warnings().length).toBe(0)
211+
})
217212
})
218213

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

228223
const config = {
229224
...defaultConfig,
230-
options: {
231-
...defaultConfig.options,
232-
prefix: () => {
233-
return 'tw-'
234-
},
225+
prefix: () => {
226+
return 'tw-'
235227
},
236228
}
237229

238-
return run(input, config, processPlugins(defaultPlugins(defaultConfig), config).utilities).then(
239-
result => {
240-
expect(result.css).toEqual(expected)
241-
expect(result.warnings().length).toBe(0)
242-
}
243-
)
230+
return run(input, config, processPlugins(corePlugins(config), config).utilities).then(result => {
231+
expect(result.css).toEqual(expected)
232+
expect(result.warnings().length).toBe(0)
233+
})
244234
})

__tests__/cli.test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@ describe('cli', () => {
1818
it('creates a Tailwind config file', () => {
1919
return cli(['init']).then(() => {
2020
expect(utils.writeFile.mock.calls[0][0]).toEqual(constants.defaultConfigFile)
21-
expect(utils.writeFile.mock.calls[0][1]).toContain('defaultConfig')
2221
})
2322
})
2423

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

__tests__/configFunction.test.js

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ function run(input, opts = {}) {
77

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

1313
const output = `
1414
.banana { color: #f7cc50; }
1515
`
1616

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

2729
test('quotes are optional around the lookup path', () => {
2830
const input = `
29-
.banana { color: config(colors.yellow); }
31+
.banana { color: config(theme.colors.yellow); }
3032
`
3133

3234
const output = `
3335
.banana { color: #f7cc50; }
3436
`
3537

3638
return run(input, {
37-
colors: {
38-
yellow: '#f7cc50',
39+
theme: {
40+
colors: {
41+
yellow: '#f7cc50',
42+
},
3943
},
4044
}).then(result => {
4145
expect(result.css).toEqual(output)
@@ -45,16 +49,18 @@ test('quotes are optional around the lookup path', () => {
4549

4650
test('a default value can be provided', () => {
4751
const input = `
48-
.cookieMonster { color: config('colors.blue', #0000ff); }
52+
.cookieMonster { color: config('theme.colors.blue', #0000ff); }
4953
`
5054

5155
const output = `
5256
.cookieMonster { color: #0000ff; }
5357
`
5458

5559
return run(input, {
56-
colors: {
57-
yellow: '#f7cc50',
60+
theme: {
61+
colors: {
62+
yellow: '#f7cc50',
63+
},
5864
},
5965
}).then(result => {
6066
expect(result.css).toEqual(output)
@@ -64,16 +70,18 @@ test('a default value can be provided', () => {
6470

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

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

7480
return run(input, {
75-
fonts: {
76-
serif: 'Constantia',
81+
theme: {
82+
fonts: {
83+
serif: 'Constantia',
84+
},
7785
},
7886
}).then(result => {
7987
expect(result.css).toEqual(output)

__tests__/containerPlugin.test.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,15 @@ function css(nodes) {
99

1010
function config(overrides) {
1111
return _.defaultsDeep(overrides, {
12-
screens: {
13-
sm: '576px',
14-
md: '768px',
15-
lg: '992px',
16-
xl: '1200px',
17-
},
18-
options: {
19-
prefix: '',
20-
important: false,
21-
separator: ':',
12+
theme: {
13+
screens: {
14+
sm: '576px',
15+
md: '768px',
16+
lg: '992px',
17+
xl: '1200px',
18+
},
2219
},
20+
prefix: '',
2321
})
2422
}
2523

__tests__/customConfig.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ test('it uses the values from the custom config file', () => {
3333
test('custom config can be passed as an object', () => {
3434
return postcss([
3535
tailwind({
36-
screens: {
37-
mobile: '400px',
36+
theme: {
37+
screens: {
38+
mobile: '400px',
39+
},
3840
},
3941
}),
4042
])

__tests__/fixtures/custom-config.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
module.exports = {
2-
screens: {
3-
mobile: '400px',
2+
theme: {
3+
screens: {
4+
mobile: '400px',
5+
},
46
},
57
}

__tests__/fixtures/tailwind-input.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
@responsive {
88
.example {
99
@apply .font-bold;
10-
color: config('colors.red');
10+
color: config('theme.colors.red');
1111
}
1212
}

__tests__/fixtures/tailwind-output-important.css

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -463,11 +463,6 @@ textarea {
463463
resize: vertical;
464464
}
465465

466-
img {
467-
max-width: 100%;
468-
height: auto;
469-
}
470-
471466
input::placeholder,
472467
textarea::placeholder {
473468
color: inherit;

0 commit comments

Comments
 (0)