Skip to content

Commit e6f4b41

Browse files
authored
Merge pull request tailwindlabs#620 from tailwindcss/modules-as-plugins
Convert built-in utility modules to private plugins
2 parents 9f0000e + e120f59 commit e6f4b41

File tree

120 files changed

+1460
-1515
lines changed

Some content is hidden

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

120 files changed

+1460
-1515
lines changed

__tests__/applyAtRule.test.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import postcss from 'postcss'
2-
import plugin from '../src/lib/substituteClassApplyAtRules'
3-
import generateUtilities from '../src/util/generateUtilities'
2+
import substituteClassApplyAtRules from '../src/lib/substituteClassApplyAtRules'
3+
import processPlugins from '../src/util/processPlugins'
4+
import defaultPlugins from '../src/defaultPlugins'
45
import defaultConfig from '../defaultConfig.stub.js'
56

6-
const defaultUtilities = generateUtilities(defaultConfig, [])
7+
const { utilities: defaultUtilities } = processPlugins(defaultPlugins(defaultConfig), defaultConfig)
78

89
function run(input, config = defaultConfig, utilities = defaultUtilities) {
9-
return postcss([plugin(config, utilities)]).process(input, { from: undefined })
10+
return postcss([substituteClassApplyAtRules(config, utilities)]).process(input, {
11+
from: undefined,
12+
})
1013
}
1114

1215
test("it copies a class's declarations into itself", () => {
@@ -206,10 +209,12 @@ test('you can apply utility classes without using the given prefix', () => {
206209
experiments: { shadowLookup: true },
207210
}
208211

209-
return run(input, config, generateUtilities(config, [])).then(result => {
210-
expect(result.css).toEqual(expected)
211-
expect(result.warnings().length).toBe(0)
212-
})
212+
return run(input, config, processPlugins(defaultPlugins(defaultConfig), config).utilities).then(
213+
result => {
214+
expect(result.css).toEqual(expected)
215+
expect(result.warnings().length).toBe(0)
216+
}
217+
)
213218
})
214219

215220
test('you can apply utility classes without using the given prefix when using a function for the prefix', () => {
@@ -232,8 +237,10 @@ test('you can apply utility classes without using the given prefix when using a
232237
experiments: { shadowLookup: true },
233238
}
234239

235-
return run(input, config, generateUtilities(config, [])).then(result => {
236-
expect(result.css).toEqual(expected)
237-
expect(result.warnings().length).toBe(0)
238-
})
240+
return run(input, config, processPlugins(defaultPlugins(defaultConfig), config).utilities).then(
241+
result => {
242+
expect(result.css).toEqual(expected)
243+
expect(result.warnings().length).toBe(0)
244+
}
245+
)
239246
})

__tests__/containerPlugin.test.js

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,24 @@ function css(nodes) {
77
return postcss.root({ nodes }).toString()
88
}
99

10-
function processPluginsWithValidConfig(config) {
11-
return processPlugins(
12-
_.defaultsDeep(config, {
13-
screens: {
14-
sm: '576px',
15-
md: '768px',
16-
lg: '992px',
17-
xl: '1200px',
18-
},
19-
options: {
20-
prefix: '',
21-
important: false,
22-
separator: ':',
23-
},
24-
})
25-
)
10+
function config(overrides) {
11+
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: ':',
22+
},
23+
})
2624
}
2725

28-
test('options are not required', () => {
29-
const { components } = processPluginsWithValidConfig({
30-
plugins: [container()],
31-
})
26+
test.only('options are not required', () => {
27+
const { components } = processPlugins([container()], config())
3228

3329
expect(css(components)).toMatchCss(`
3430
.container { width: 100% }
@@ -47,17 +43,18 @@ test('options are not required', () => {
4743
`)
4844
})
4945

50-
test('screens can be specified explicitly', () => {
51-
const { components } = processPluginsWithValidConfig({
52-
plugins: [
46+
test.only('screens can be specified explicitly', () => {
47+
const { components } = processPlugins(
48+
[
5349
container({
5450
screens: {
5551
sm: '400px',
5652
lg: '500px',
5753
},
5854
}),
5955
],
60-
})
56+
config()
57+
)
6158

6259
expect(css(components)).toMatchCss(`
6360
.container { width: 100% }
@@ -70,14 +67,15 @@ test('screens can be specified explicitly', () => {
7067
`)
7168
})
7269

73-
test('screens can be an array', () => {
74-
const { components } = processPluginsWithValidConfig({
75-
plugins: [
70+
test.only('screens can be an array', () => {
71+
const { components } = processPlugins(
72+
[
7673
container({
7774
screens: ['400px', '500px'],
7875
}),
7976
],
80-
})
77+
config()
78+
)
8179

8280
expect(css(components)).toMatchCss(`
8381
.container { width: 100% }
@@ -90,14 +88,15 @@ test('screens can be an array', () => {
9088
`)
9189
})
9290

93-
test('the container can be centered by default', () => {
94-
const { components } = processPluginsWithValidConfig({
95-
plugins: [
91+
test.only('the container can be centered by default', () => {
92+
const { components } = processPlugins(
93+
[
9694
container({
9795
center: true,
9896
}),
9997
],
100-
})
98+
config()
99+
)
101100

102101
expect(css(components)).toMatchCss(`
103102
.container {
@@ -120,14 +119,15 @@ test('the container can be centered by default', () => {
120119
`)
121120
})
122121

123-
test('horizontal padding can be included by default', () => {
124-
const { components } = processPluginsWithValidConfig({
125-
plugins: [
122+
test.only('horizontal padding can be included by default', () => {
123+
const { components } = processPlugins(
124+
[
126125
container({
127126
padding: '2rem',
128127
}),
129128
],
130-
})
129+
config()
130+
)
131131

132132
expect(css(components)).toMatchCss(`
133133
.container {
@@ -150,9 +150,9 @@ test('horizontal padding can be included by default', () => {
150150
`)
151151
})
152152

153-
test('setting all options at once', () => {
154-
const { components } = processPluginsWithValidConfig({
155-
plugins: [
153+
test.only('setting all options at once', () => {
154+
const { components } = processPlugins(
155+
[
156156
container({
157157
screens: {
158158
sm: '400px',
@@ -162,7 +162,8 @@ test('setting all options at once', () => {
162162
padding: '2rem',
163163
}),
164164
],
165-
})
165+
config()
166+
)
166167

167168
expect(css(components)).toMatchCss(`
168169
.container {

__tests__/defineClass.test.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

__tests__/defineClasses.test.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

__tests__/generateModules.test.js

Lines changed: 0 additions & 133 deletions
This file was deleted.

0 commit comments

Comments
 (0)