Home / File/ migrate-tailwind-directives.ts — tailwindcss Source File

migrate-tailwind-directives.ts — tailwindcss Source File

Architecture documentation for migrate-tailwind-directives.ts, a typescript file in the tailwindcss codebase. 1 imports, 2 dependents.

File typescript CommandLineInterface Codemods 1 imports 2 dependents 2 functions

Entity Profile

Dependency Diagram

graph LR
  ab650bb5_df86_6206_c20d_13143f971e6c["migrate-tailwind-directives.ts"]
  7c3c22f8_be1a_4490_9f3e_622280887fe1["postcss"]
  ab650bb5_df86_6206_c20d_13143f971e6c --> 7c3c22f8_be1a_4490_9f3e_622280887fe1
  320d991a_2688_e5d4_fc07_c946ad430e00["migrate-tailwind-directives.test.ts"]
  320d991a_2688_e5d4_fc07_c946ad430e00 --> ab650bb5_df86_6206_c20d_13143f971e6c
  9e542b1f_db4d_cc7b_b37d_1324d5719263["migrate.ts"]
  9e542b1f_db4d_cc7b_b37d_1324d5719263 --> ab650bb5_df86_6206_c20d_13143f971e6c
  style ab650bb5_df86_6206_c20d_13143f971e6c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { AtRule, type ChildNode, type Plugin, type Root } from 'postcss'

const DEFAULT_LAYER_ORDER = ['theme', 'base', 'components', 'utilities']

export function migrateTailwindDirectives(options: { newPrefix: string | null }): Plugin {
  let prefixParams = options.newPrefix ? ` prefix(${options.newPrefix})` : ''

  function migrate(root: Root) {
    let baseNode = null as AtRule | null
    let utilitiesNode = null as AtRule | null
    let orderedNodes: AtRule[] = []

    let defaultImportNode = null as AtRule | null
    let utilitiesImportNode = null as AtRule | null
    let preflightImportNode = null as AtRule | null
    let themeImportNode = null as AtRule | null

    let layerOrder: string[] = []

    root.walkAtRules((node) => {
      // Migrate legacy `@import "tailwindcss/tailwind.css"`
      if (node.name === 'import' && node.params.match(/^["']tailwindcss\/tailwind\.css["']$/)) {
        node.params = node.params.replace('tailwindcss/tailwind.css', 'tailwindcss')
      }

      // Append any new prefix() param to existing `@import 'tailwindcss'` directives
      if (node.name === 'import' && node.params.match(/^["']tailwindcss["']/)) {
        node.params += prefixParams
      }

      // Track old imports and directives
      else if (
        (node.name === 'tailwind' && node.params === 'base') ||
        (node.name === 'import' && node.params.match(/^["']tailwindcss\/base["']$/))
      ) {
        layerOrder.push('base')
        orderedNodes.push(node)
        baseNode = node
      } else if (
        (node.name === 'tailwind' && node.params === 'utilities') ||
        (node.name === 'import' && node.params.match(/^["']tailwindcss\/utilities["']$/))
      ) {
        layerOrder.push('utilities')
        orderedNodes.push(node)
        utilitiesNode = node
      }

      // Remove directives that are not needed anymore
      else if (
        (node.name === 'tailwind' && node.params === 'components') ||
        (node.name === 'tailwind' && node.params === 'screens') ||
        (node.name === 'tailwind' && node.params === 'variants') ||
        (node.name === 'import' && node.params.match(/^["']tailwindcss\/components["']$/))
      ) {
        node.remove()
      }

      // Replace Tailwind CSS v2 directives that still worked in v3.
      else if (node.name === 'responsive') {
        if (node.nodes) {
// ... (129 more lines)

Subdomains

Dependencies

  • postcss

Frequently Asked Questions

What does migrate-tailwind-directives.ts do?
migrate-tailwind-directives.ts is a source file in the tailwindcss codebase, written in typescript. It belongs to the CommandLineInterface domain, Codemods subdomain.
What functions are defined in migrate-tailwind-directives.ts?
migrate-tailwind-directives.ts defines 2 function(s): findTargetNode, migrateTailwindDirectives.
What does migrate-tailwind-directives.ts depend on?
migrate-tailwind-directives.ts imports 1 module(s): postcss.
What files import migrate-tailwind-directives.ts?
migrate-tailwind-directives.ts is imported by 2 file(s): migrate-tailwind-directives.test.ts, migrate.ts.
Where is migrate-tailwind-directives.ts in the architecture?
migrate-tailwind-directives.ts is located at packages/@tailwindcss-upgrade/src/codemods/css/migrate-tailwind-directives.ts (domain: CommandLineInterface, subdomain: Codemods, directory: packages/@tailwindcss-upgrade/src/codemods/css).

Analyze Your Own Codebase

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

Try Supermodel Free