improve checking if new candidates were added or not
This commit is contained in:
parent
145df6ca53
commit
a45ae05fca
3 changed files with 9 additions and 4 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue