Skip to content

Commit

Permalink
EnsurecorePlugins order is consistent (#5928)
Browse files Browse the repository at this point in the history
* ensure corePlugins order is consistent

* update order in tests
  • Loading branch information
RobinMalfait committed Oct 29, 2021
1 parent e08003d commit 468c9c5
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 21 deletions.
15 changes: 9 additions & 6 deletions src/util/resolveConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,15 @@ function resolveVariants([firstConfig, ...variantConfigs], variantOrder) {
}

function resolveCorePlugins(corePluginConfigs) {
const result = [...corePluginConfigs].reduceRight((resolved, corePluginConfig) => {
if (isFunction(corePluginConfig)) {
return corePluginConfig({ corePlugins: resolved })
}
return configurePlugins(corePluginConfig, resolved)
}, corePluginList)
const result = [...corePluginConfigs]
.reduceRight((resolved, corePluginConfig) => {
if (isFunction(corePluginConfig)) {
return corePluginConfig({ corePlugins: resolved })
}
return configurePlugins(corePluginConfig, resolved)
}, corePluginList)
.slice()
.sort((a, z) => Math.sign(corePluginList.indexOf(a) - corePluginList.indexOf(z)))

return result
}
Expand Down
32 changes: 32 additions & 0 deletions tests/corePlugins.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import postcss from 'postcss'
import tailwind from '../src/index'

function run(input, config = {}) {
return postcss([tailwind(config)]).process(input, { from: undefined })
}

it('should not change the order of the plugins based on corePlugins in config', async () => {
let config1 = {
purge: {
enabled: true,
content: [{ raw: `<div class="transform translate-x-full"></div>` }],
},
corePlugins: ['translate', 'transform'],
}
let config2 = {
purge: {
enabled: true,
content: [{ raw: `<div class="transform translate-x-full"></div>` }],
},
corePlugins: ['transform', 'translate'],
}

let input = `
@tailwind base;
@tailwind components;
@tailwind utilities;
`

let [first, second] = await Promise.all([run(input, config1), run(input, config2)])
expect(first.css).toMatchFormattedCss(second.css)
})
28 changes: 14 additions & 14 deletions tests/plugins/gradientColorStops.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,6 @@ test('opacity variables are given to colors defined as closures', () => {
.process('@tailwind utilities', { from: undefined })
.then((result) => {
const expected = `
.text-primary {
--tw-text-opacity: 1;
color: rgba(31, 31, 31, var(--tw-text-opacity));
}
.text-secondary {
--tw-text-opacity: 1;
color: hsla(10, 50%, 50%, var(--tw-text-opacity));
}
.text-opacity-50 {
--tw-text-opacity: 0.5;
}
.from-primary {
--tw-gradient-from: rgb(31, 31, 31);
--tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to, rgba(31, 31, 31, 0));
Expand Down Expand Up @@ -75,6 +61,20 @@ test('opacity variables are given to colors defined as closures', () => {
.to-secondary {
--tw-gradient-to: hsl(10, 50%, 50%);
}
.text-primary {
--tw-text-opacity: 1;
color: rgba(31, 31, 31, var(--tw-text-opacity));
}
.text-secondary {
--tw-text-opacity: 1;
color: hsla(10, 50%, 50%, var(--tw-text-opacity));
}
.text-opacity-50 {
--tw-text-opacity: 0.5;
}
`

expect(result.css).toMatchCss(expected)
Expand Down
2 changes: 1 addition & 1 deletion tests/resolveConfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2182,7 +2182,7 @@ test('core plugin configurations stack', () => {
separator: ':',
theme: {},
variants: {},
corePlugins: ['float', 'padding', 'margin'],
corePlugins: ['float', 'margin', 'padding'],
})
})

Expand Down

0 comments on commit 468c9c5

Please sign in to comment.