Home / Function/ migrateAtApply() — tailwindcss Function Reference

migrateAtApply() — tailwindcss Function Reference

Architecture documentation for the migrateAtApply() function in migrate-at-apply.ts from the tailwindcss codebase.

Entity Profile

Dependency Diagram

graph TD
  6d8d6d7e_6e94_511f_8419_616e12ba69b8["migrateAtApply()"]
  587045dd_6997_cdb6_9548_cd81dc79a115["migrate-at-apply.ts"]
  6d8d6d7e_6e94_511f_8419_616e12ba69b8 -->|defined in| 587045dd_6997_cdb6_9548_cd81dc79a115
  e1339745_c682_c711_99e4_826034d7caaf["migrate()"]
  e1339745_c682_c711_99e4_826034d7caaf -->|calls| 6d8d6d7e_6e94_511f_8419_616e12ba69b8
  1be562b7_fe23_7e22_03ec_31b3d101e5e5["migrateContents()"]
  1be562b7_fe23_7e22_03ec_31b3d101e5e5 -->|calls| 6d8d6d7e_6e94_511f_8419_616e12ba69b8
  af7447ce_3295_6173_2897_ddd297a6bfb9["migrate()"]
  6d8d6d7e_6e94_511f_8419_616e12ba69b8 -->|calls| af7447ce_3295_6173_2897_ddd297a6bfb9
  c58cbb33_f3cc_0b4f_844a_15bf66a1dc61["segment()"]
  6d8d6d7e_6e94_511f_8419_616e12ba69b8 -->|calls| c58cbb33_f3cc_0b4f_844a_15bf66a1dc61
  66c57db2_afd7_9e7b_cea6_76cdb074b086["migrateCandidate()"]
  6d8d6d7e_6e94_511f_8419_616e12ba69b8 -->|calls| 66c57db2_afd7_9e7b_cea6_76cdb074b086
  style 6d8d6d7e_6e94_511f_8419_616e12ba69b8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/@tailwindcss-upgrade/src/codemods/css/migrate-at-apply.ts lines 7–61

export function migrateAtApply({
  designSystem,
  userConfig,
}: {
  designSystem: DesignSystem | null
  userConfig: Config | null
}): Plugin {
  function migrate(atRule: AtRule) {
    let utilities = atRule.params.split(/(\s+)/)
    let important =
      utilities[utilities.length - 1] === '!important' ||
      utilities[utilities.length - 1] === '#{!important}' // Sass/SCSS

    if (important) utilities.pop() // Remove `!important`

    let params = utilities.map((part) => {
      // Keep whitespace
      if (part.trim() === '') return part
      let variants = segment(part, ':')
      let utility = variants.pop()!

      // Apply the important modifier to all the rules if necessary
      if (important && utility[0] !== '!' && utility[utility.length - 1] !== '!') {
        utility += '!'
      }

      // Reconstruct the utility with the variants
      return [...variants, utility].join(':')
    })

    return async () => {
      if (!designSystem) return

      // If we have a valid designSystem and config setup, we can run all
      // candidate migrations on each utility
      params = await Promise.all(
        params.map(async (param) => await migrateCandidate(designSystem, userConfig, param)),
      )

      atRule.params = params.join('').trim()
    }
  }

  return {
    postcssPlugin: '@tailwindcss/upgrade/migrate-at-apply',
    async OnceExit(root) {
      let migrations: (() => void)[] = []
      root.walkAtRules('apply', (atRule) => {
        migrations.push(migrate(atRule))
      })

      await Promise.allSettled(migrations.map((m) => m()))
    },
  }
}

Subdomains

Frequently Asked Questions

What does migrateAtApply() do?
migrateAtApply() is a function in the tailwindcss codebase, defined in packages/@tailwindcss-upgrade/src/codemods/css/migrate-at-apply.ts.
Where is migrateAtApply() defined?
migrateAtApply() is defined in packages/@tailwindcss-upgrade/src/codemods/css/migrate-at-apply.ts at line 7.
What does migrateAtApply() call?
migrateAtApply() calls 3 function(s): migrate, migrateCandidate, segment.
What calls migrateAtApply()?
migrateAtApply() 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