Skip to content

fix(build): prefer the most specific CSS export pattern - #171

Open
cixiangtao wants to merge 1 commit into
shadcn-ui:mainfrom
cixiangtao:fix/css-export-pattern-specificity
Open

cixiangtao wants to merge 1 commit into
shadcn-ui:mainfrom
cixiangtao:fix/css-export-pattern-specificity

Conversation

@cixiangtao

Copy link
Copy Markdown

cn build can read the wrong stylesheet when a CSS package exports overlapping patterns with the same prefix. For example:

{
  "exports": {
    "./themes/*": "./fallback/*.css",
    "./themes/*.css": "./specific/*.css"
  }
}

Importing pkg/themes/card.css should select ./specific/card.css. The current matcher only compares prefix lengths, so it selects the first pattern instead. If that target is missing, the theme is silently skipped. A custom rounded-card utility then survives cn("rounded-card rounded-lg") even though Tailwind generates its CSS and both utilities set the border radius.

Break equal-prefix ties by pattern length, selecting the longest suffix. Exact exports retain priority, and a more specific null export continues to exclude the subpath.

The regression test fails on the original implementation and passes with the fix. Six end-to-end cases cover both declaration orders, a missing broad target, longer-prefix priority, exact exports, and null exclusions. They also check the generated tables' merge behavior. A patch changeset is included.

Validation:

  • Independently reproduced with published cn@0.5.2 and @tailwindcss/node@4.3.5: Node and Tailwind select the specific file; unpatched cn selects the broad target or misses the stylesheet. The patched build agrees with Tailwind, including reversed-order and exact-export controls.
  • vp check and vp run typecheck.
  • FUZZ_ITERS=300000 vp run test: all suites pass, including 56,353 correctness cases and 300,000 fuzz cases.
  • vp run size: default entry remains 26,631 bytes minified / 11,021 bytes gzip, below the 11,100-byte budget.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant