Skip to content

Commit 468c9c5

Browse files
authored
EnsurecorePlugins order is consistent (#5928)
* ensure corePlugins order is consistent * update order in tests
1 parent e08003d commit 468c9c5

File tree

4 files changed

+56
-21
lines changed

4 files changed

+56
-21
lines changed

src/util/resolveConfig.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,15 @@ function resolveVariants([firstConfig, ...variantConfigs], variantOrder) {
238238
}
239239

240240
function resolveCorePlugins(corePluginConfigs) {
241-
const result = [...corePluginConfigs].reduceRight((resolved, corePluginConfig) => {
242-
if (isFunction(corePluginConfig)) {
243-
return corePluginConfig({ corePlugins: resolved })
244-
}
245-
return configurePlugins(corePluginConfig, resolved)
246-
}, corePluginList)
241+
const result = [...corePluginConfigs]
242+
.reduceRight((resolved, corePluginConfig) => {
243+
if (isFunction(corePluginConfig)) {
244+
return corePluginConfig({ corePlugins: resolved })
245+
}
246+
return configurePlugins(corePluginConfig, resolved)
247+
}, corePluginList)
248+
.slice()
249+
.sort((a, z) => Math.sign(corePluginList.indexOf(a) - corePluginList.indexOf(z)))
247250

248251
return result
249252
}

tests/corePlugins.test.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import postcss from 'postcss'
2+
import tailwind from '../src/index'
3+
4+
function run(input, config = {}) {
5+
return postcss([tailwind(config)]).process(input, { from: undefined })
6+
}
7+
8+
it('should not change the order of the plugins based on corePlugins in config', async () => {
9+
let config1 = {
10+
purge: {
11+
enabled: true,
12+
content: [{ raw: `<div class="transform translate-x-full"></div>` }],
13+
},
14+
corePlugins: ['translate', 'transform'],
15+
}
16+
let config2 = {
17+
purge: {
18+
enabled: true,
19+
content: [{ raw: `<div class="transform translate-x-full"></div>` }],
20+
},
21+
corePlugins: ['transform', 'translate'],
22+
}
23+
24+
let input = `
25+
@tailwind base;
26+
@tailwind components;
27+
@tailwind utilities;
28+
`
29+
30+
let [first, second] = await Promise.all([run(input, config1), run(input, config2)])
31+
expect(first.css).toMatchFormattedCss(second.css)
32+
})

tests/plugins/gradientColorStops.test.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,6 @@ test('opacity variables are given to colors defined as closures', () => {
3434
.process('@tailwind utilities', { from: undefined })
3535
.then((result) => {
3636
const expected = `
37-
.text-primary {
38-
--tw-text-opacity: 1;
39-
color: rgba(31, 31, 31, var(--tw-text-opacity));
40-
}
41-
42-
.text-secondary {
43-
--tw-text-opacity: 1;
44-
color: hsla(10, 50%, 50%, var(--tw-text-opacity));
45-
}
46-
47-
.text-opacity-50 {
48-
--tw-text-opacity: 0.5;
49-
}
50-
5137
.from-primary {
5238
--tw-gradient-from: rgb(31, 31, 31);
5339
--tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to, rgba(31, 31, 31, 0));
@@ -75,6 +61,20 @@ test('opacity variables are given to colors defined as closures', () => {
7561
.to-secondary {
7662
--tw-gradient-to: hsl(10, 50%, 50%);
7763
}
64+
65+
.text-primary {
66+
--tw-text-opacity: 1;
67+
color: rgba(31, 31, 31, var(--tw-text-opacity));
68+
}
69+
70+
.text-secondary {
71+
--tw-text-opacity: 1;
72+
color: hsla(10, 50%, 50%, var(--tw-text-opacity));
73+
}
74+
75+
.text-opacity-50 {
76+
--tw-text-opacity: 0.5;
77+
}
7878
`
7979

8080
expect(result.css).toMatchCss(expected)

tests/resolveConfig.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2182,7 +2182,7 @@ test('core plugin configurations stack', () => {
21822182
separator: ':',
21832183
theme: {},
21842184
variants: {},
2185-
corePlugins: ['float', 'padding', 'margin'],
2185+
corePlugins: ['float', 'margin', 'padding'],
21862186
})
21872187
})
21882188

0 commit comments

Comments
 (0)