Home / Function/ migrateVariantsDirective() — tailwindcss Function Reference

migrateVariantsDirective() — tailwindcss Function Reference

Architecture documentation for the migrateVariantsDirective() function in migrate-variants-directive.ts from the tailwindcss codebase.

Entity Profile

Dependency Diagram

graph TD
  b19d6a87_72b1_e244_6044_b39e640127c3["migrateVariantsDirective()"]
  7d3434a3_4704_b7bc_152c_048a7295df0f["migrate-variants-directive.ts"]
  b19d6a87_72b1_e244_6044_b39e640127c3 -->|defined in| 7d3434a3_4704_b7bc_152c_048a7295df0f
  17550040_432e_8df4_09fe_ecb183594100["migrate()"]
  17550040_432e_8df4_09fe_ecb183594100 -->|calls| b19d6a87_72b1_e244_6044_b39e640127c3
  9ebd84f7_07bc_9b19_28a7_8bd93119c37e["migrateContents()"]
  9ebd84f7_07bc_9b19_28a7_8bd93119c37e -->|calls| b19d6a87_72b1_e244_6044_b39e640127c3
  style b19d6a87_72b1_e244_6044_b39e640127c3 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/@tailwindcss-upgrade/src/codemods/css/migrate-variants-directive.ts lines 3–35

export function migrateVariantsDirective(): Plugin {
  function migrate(root: Root) {
    root.walkAtRules('variants', (node) => {
      // Migrate `@variants` to `@utility` because `@variants` make the classes
      // an actual utility.
      // ```css
      // @variants hover {
      //   .foo {}
      // }
      // ```
      //
      // Means that you can do this in your HTML:
      // ```html
      // <div class="focus:foo"></div>
      // ```
      //
      // Notice the `focus:`, even though we _only_ configured the `hover`
      // variant.
      //
      // This means that we can convert it to an `@layer utilities` rule. Later,
      // this will get converted to an `@utility` rule.
      if (node.name === 'variants') {
        node.name = 'layer'
        node.params = 'utilities'
      }
    })
  }

  return {
    postcssPlugin: '@tailwindcss/upgrade/migrate-variants-directive',
    OnceExit: migrate,
  }
}

Subdomains

Frequently Asked Questions

What does migrateVariantsDirective() do?
migrateVariantsDirective() is a function in the tailwindcss codebase, defined in packages/@tailwindcss-upgrade/src/codemods/css/migrate-variants-directive.ts.
Where is migrateVariantsDirective() defined?
migrateVariantsDirective() is defined in packages/@tailwindcss-upgrade/src/codemods/css/migrate-variants-directive.ts at line 3.
What calls migrateVariantsDirective()?
migrateVariantsDirective() is called by 2 function(s): migrate, migrateContents.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free