Skip to content
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

EnsurecorePlugins order is consistent #5928

Merged
merged 2 commits into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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