graphify icon indicating copy to clipboard operation
graphify copied to clipboard

No extraction path for .css/.scss: design-token systems are invisible to the graph (measured: 714 tokens, 1334 edges recoverable)

Open febryo-sc opened this issue 2 months ago • 1 comments

Summary

.css / .scss appear in none of detect.py's extension sets — not CODE_EXTENSIONS, not DOC_EXTENSIONS — so a stylesheet contributes zero nodes even when it is the authority for a project's design system. On a codebase whose colours, spacing and radii all resolve through CSS custom properties, the graph cannot answer "what defines --color-brand" or "which components use it", and a token rename's blast radius is invisible.

(Related but different: #2498 covers the filename-based sensitive filter dropping a tokens.css that would otherwise be scanned. This is the missing extractor underneath it — even un-skipped, the file has no extraction path.)

What a minimal extractor recovers

I measured this by writing an external pass over the same repo (4 stylesheets: a token layer, a brand ramp, an admin theme, a globals file) and merging its output into graph.json:

token nodes (--name: definitions) 714
defines_token edges (stylesheet → token) 714
uses_token edges (var(--name) in .css/.ts/.tsx) 620

Two things that turned out to matter, in case they save someone the same iteration:

  1. Brace depth, not a flat regex. One globals file had 609 --name: declarations of which only 22 were definitions — the other 587 were components locally overriding an inherited token (.some-scope { --spacing: ...; }). Counting those as definitions makes every consumer look like a definer.
  2. Token identity is per-file, not per-name. Two separate design systems in one repo both defined --color-card; merging them by name would have fused two deliberately unshared themes. Scoping the node to (file, name) and fanning uses_token out to same-named candidates kept them distinct.

Deliberately excluded: resolving Tailwind-style utility class names back to tokens. var() references are unambiguous; utility-name inference is not.

Suggested shape

Add .css/.scss to CODE_EXTENSIONS with an extractors/css.py that emits a node per custom-property definition (with source_location) plus defines_token / uses_token edges. tree-sitter-css exists, though for custom properties specifically a brace-depth scan was enough — no grammar needed, which may matter given the packaging discussion in #2959.

Version: 0.9.56.

febryo-sc avatar Sep 10 '26 11:09 febryo-sc

Fixed by #4263, which supersedes #3480 and the CSS/SCSS halves of #3067 and #2240 (all raised against older v8 revisions and no longer merge).

.css/.scss/.less are now first-class code with a dependency-free, brace-aware design-token extractor:

  • a node per custom-property definition in a root/theme context (:root, :host, html, body, [data-theme…], .dark, .theme-*, @theme), with defines_token edges;
  • var(--x) uses resolved to a same-file definition, or to exactly one cross-file definition — ambiguous or missing uses emit nothing (no fan-out);
  • a custom property declared locally (outside a root context) shadows a same-named global, so a component override does not invent a false cross-file edge; a file that also declares the token in :root keeps its same-file edge;
  • wired through the incremental cache (raw_token_uses) and id-remap passes; warm and cold builds agree.

See #4263.

nothariharan avatar Oct 09 '26 16:10 nothariharan