Sort class lists deterministically for Prettier plugin (#10672)

* Ensure class sorting is deterministic for Prettier

* Update changelog
This commit is contained in:
Jordan Pittman 2023-02-23 13:32:24 -05:00 • committed by GitHub
parent 261a8b42cb
commit d2a95a00a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 4 deletions

View file

@ -931,12 +931,19 @@ function registerPlugins(plugins, context) {
prefix(context, 'peer'),
]
context.getClassOrder = function getClassOrder(classes) {
// Sort classes so they're ordered in a deterministic manner
let sorted = [...classes].sort((a, z) => {
if (a === z) return 0
if (a < z) return -1
return 1
})
// Non-util classes won't be generated, so we default them to null
let sortedClassNames = new Map(classes.map((className) => [className, null]))
let sortedClassNames = new Map(sorted.map((className) => [className, null]))
// Sort all classes in order
// Non-tailwind classes won't be generated and will be left as `null`
let rules = generateRules(new Set(classes), context)
let rules = generateRules(new Set(sorted), context)
rules = context.offsets.sort(rules)
let idx = BigInt(parasiteUtilities.length)