improve checking if new candidates were added or not

This commit is contained in:
Robin Malfait 2024-03-08 15:56:39 +01:00
parent 145df6ca53
commit a45ae05fca
No known key found for this signature in database
3 changed files with 9 additions and 4 deletions

View file

@ -196,7 +196,9 @@ export async function handle(args: Result<ReturnType<typeof options>>) {
// Scan changed files only for incremental rebuilds.
else if (rebuildStrategy === 'incremental') {
compiledCss = result.rebuild(scanFiles(changedFiles, IO.Sequential | Parsing.Sequential))
let newCandidates = scanFiles(changedFiles, IO.Sequential | Parsing.Sequential)
compiledCss = result.rebuild(newCandidates)
}
await write(compiledCss, args)

View file

@ -32,8 +32,8 @@ export type DesignSystem = {
export function buildDesignSystem(theme: Theme): DesignSystem {
let utilities = createUtilities(theme)
let variants = createVariants(theme)
let invalidRawCandidates = new Set<string>()
let invalidRawCandidates = new Set<string>()
let parsedVariants = new DefaultMap((variant) => parseVariant(variant, designSystem))
let parsedCandidates = new DefaultMap((candidate) => parseCandidate(candidate, designSystem))
let compiledAstNodes = new DefaultMap((candidate) => compileAstNodes(candidate, designSystem))

View file

@ -187,17 +187,20 @@ export function compile(
return {
rebuild(newRawCandidates: string[]) {
let didChange = false
// Add all new candidates unless we know that they are invalid.
let previousSize = allValidCandidates.size
let prevSize = allValidCandidates.size
for (let candidate of newRawCandidates) {
if (!designSystem.isInvalidCandidate(candidate)) {
allValidCandidates.add(candidate)
didChange ||= allValidCandidates.size !== prevSize
}
}
// If no new candidates were added, we can return the original CSS. This
// currently assumes that we only add new candidates and never remove any.
if (previousSize === allValidCandidates.size) {
if (!didChange) {
return compiledCss
}