Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

Repository files navigation

canonical-tailwind

Repo-wide Tailwind CSS v4 canonical class converter.

The CLI uses Tailwind's design system and canonicalizeCandidates(...) as its source of truth. It can report non-canonical classes or rewrite supported static class literals across a repository.

Requirements

  • Node.js 22.12 or newer at runtime.
  • A Tailwind CSS entrypoint. The bundled Tailwind engine is pinned to 4.3.3 and is upgraded deliberately with regression tests.

Installation

bun add --dev canonical-tailwind

Run the local binary with bunx canonical-tailwind or invoke the installed canonical-tailwind executable from your package scripts.

Usage

Start with check or a dry run before writing files:

canonical-tailwind check . --css resources/css/app.css
canonical-tailwind fix . --css resources/css/app.css --dry-run
canonical-tailwind fix . --css resources/css/app.css

If --css is omitted, the CLI searches the working directory. Autodetection succeeds only when exactly one uncommented Tailwind entrypoint is found. An ambiguous result fails and lists the candidates instead of guessing.

Options

Both commands accept:

  • --css <file>: select the Tailwind CSS entrypoint explicitly.
  • --collapse: canonicalize the whole list and collapse compatible utilities.
  • --rem <number>: set the root font size; defaults to 16.
  • --jobs <number>: use 1 to 8 analysis workers; defaults to 1.
  • --json: print structured results to stdout.
  • --verbose: include literals that were intentionally skipped.

fix additionally accepts --dry-run, which reports the exact changes without writing files.

More workers are not automatically faster. Each worker loads an independent Tailwind design system and cache. Keep the default unless a representative benchmark of your repository proves that a larger value helps.

Exit codes

  • check: 0 when no replacements are needed, 1 when replacements exist.
  • fix: 0 after a successful run, including a dry run.
  • Operational and validation failures: 2.
  • Command-line syntax errors reported by Commander: 1.

Successful --json output is written only to stdout. Errors are written to stderr.

Supported source forms

The scanner includes .vue, .html, .jsx, .tsx, .js, .ts, .svelte, and .astro files.

Supported forms include:

  • quoted class and className attributes inside markup tags;
  • string literals inside JSX class and className expressions;
  • string literals inside Vue :class, v-bind:class, :ui, and v-bind:ui;
  • Astro class:list string literals;
  • string literals passed to statically imported clsx, cn, cva, tv, and twMerge bindings, including imported aliases.

Dynamic template literals are skipped. Svelte class:name directives are also left unchanged because the utility is part of syntax rather than a safely replaceable string literal. A same-named local or global helper without an import is left unchanged; the scanner uses import evidence but does not perform full semantic binding analysis.

Outside --collapse, existing whitespace between class tokens is preserved. Collapse mode may reorder, combine, or normalize the whole class list.

File discovery and write safety

  • Built-in ignores cover Git metadata, dependencies, vendor files, generated builds, coverage, distributions, storage, and lockfiles.
  • Rules from the working directory's root .gitignore are applied during directory scans; an explicitly selected file remains explicit.
  • Supported dot-directories such as .storybook are scanned unless ignored.
  • Directory symlinks are not followed, and a symlink cannot be used as the target path.

fix analyzes every file successfully before it starts writing. Changed files are prepared as temporary siblings and renamed into place, which prevents a partial individual file and preserves its permission mode. A filesystem failure during the final multi-file rename phase cannot be globally transactional, so run the command in a clean version-controlled worktree.

Development

bun install
bun run ts:check
bun test
bun run build

prepack rebuilds dist, so a package created from a clean checkout contains the CLI, declarations, and source maps with embedded TypeScript sources.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages