Home / File/ migrate-missing-layers.ts — tailwindcss Source File

migrate-missing-layers.ts — tailwindcss Source File

Architecture documentation for migrate-missing-layers.ts, a typescript file in the tailwindcss codebase. 3 imports, 2 dependents.

File typescript CommandLineInterface Codemods 3 imports 2 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  c8e9db66_5242_9932_2886_2c9db99f6ac2["migrate-missing-layers.ts"]
  bb9924cc_8308_a1f9_0e30_76de45a64970["segment.ts"]
  c8e9db66_5242_9932_2886_2c9db99f6ac2 --> bb9924cc_8308_a1f9_0e30_76de45a64970
  c58cbb33_f3cc_0b4f_844a_15bf66a1dc61["segment"]
  c8e9db66_5242_9932_2886_2c9db99f6ac2 --> c58cbb33_f3cc_0b4f_844a_15bf66a1dc61
  7c3c22f8_be1a_4490_9f3e_622280887fe1["postcss"]
  c8e9db66_5242_9932_2886_2c9db99f6ac2 --> 7c3c22f8_be1a_4490_9f3e_622280887fe1
  961d377c_755d_e488_5737_dfddc91c3ee6["migrate-missing-layers.test.ts"]
  961d377c_755d_e488_5737_dfddc91c3ee6 --> c8e9db66_5242_9932_2886_2c9db99f6ac2
  9e542b1f_db4d_cc7b_b37d_1324d5719263["migrate.ts"]
  9e542b1f_db4d_cc7b_b37d_1324d5719263 --> c8e9db66_5242_9932_2886_2c9db99f6ac2
  style c8e9db66_5242_9932_2886_2c9db99f6ac2 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { AtRule, type ChildNode, type Plugin, type Root } from 'postcss'
import { segment } from '../../../../tailwindcss/src/utils/segment'

export function migrateMissingLayers(): Plugin {
  function migrate(root: Root) {
    let lastLayer = ''
    let bucket: ChildNode[] = []
    let buckets: [layer: string, bucket: typeof bucket][] = []
    let firstLayerName: string | null = null

    root.each((node) => {
      if (node.type === 'atrule') {
        // Known Tailwind directives that should not be inside a layer.
        if (
          node.name === 'config' ||
          node.name === 'source' ||
          node.name === 'theme' ||
          node.name === 'utility' ||
          node.name === 'custom-variant' ||
          node.name === 'variant'
        ) {
          if (bucket.length > 0) {
            buckets.push([lastLayer, bucket.splice(0)])
          }
          return
        }

        // Base
        if (
          (node.name === 'tailwind' && node.params === 'base') ||
          (node.name === 'import' && node.params.match(/^["']tailwindcss\/base["']/))
        ) {
          if (bucket.length > 0) {
            buckets.push([lastLayer, bucket.splice(0)])
          }

          firstLayerName ??= 'base'
          lastLayer = 'base'
          return
        }

        // Components
        if (
          (node.name === 'tailwind' && node.params === 'components') ||
          (node.name === 'import' && node.params.match(/^["']tailwindcss\/components["']/))
        ) {
          if (bucket.length > 0) {
            buckets.push([lastLayer, bucket.splice(0)])
          }

          firstLayerName ??= 'components'
          lastLayer = 'components'
          return
        }

        // Utilities
        if (
          (node.name === 'tailwind' && node.params === 'utilities') ||
          (node.name === 'import' && node.params.match(/^["']tailwindcss\/utilities["']/))
        ) {
// ... (102 more lines)

Subdomains

Dependencies

Frequently Asked Questions

What does migrate-missing-layers.ts do?
migrate-missing-layers.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-missing-layers.ts?
migrate-missing-layers.ts defines 1 function(s): migrateMissingLayers.
What does migrate-missing-layers.ts depend on?
migrate-missing-layers.ts imports 3 module(s): postcss, segment, segment.ts.
What files import migrate-missing-layers.ts?
migrate-missing-layers.ts is imported by 2 file(s): migrate-missing-layers.test.ts, migrate.ts.
Where is migrate-missing-layers.ts in the architecture?
migrate-missing-layers.ts is located at packages/@tailwindcss-upgrade/src/codemods/css/migrate-missing-layers.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