Home / Function/ migrateTheme() — tailwindcss Function Reference

migrateTheme() — tailwindcss Function Reference

Architecture documentation for the migrateTheme() function in migrate-js-config.ts from the tailwindcss codebase.

Entity Profile

Dependency Diagram

graph TD
  253815a9_405f_ff30_32b6_577fe2d91fb2["migrateTheme()"]
  ffe9c87e_35ad_f431_9625_80fc875792a7["migrate-js-config.ts"]
  253815a9_405f_ff30_32b6_577fe2d91fb2 -->|defined in| ffe9c87e_35ad_f431_9625_80fc875792a7
  617e9831_5cd2_4ca6_2c65_f89e3720cfd8["migrateJsConfig()"]
  617e9831_5cd2_4ca6_2c65_f89e3720cfd8 -->|calls| 253815a9_405f_ff30_32b6_577fe2d91fb2
  bc7b25d3_d5ad_3609_d595_c9755dfadcbb["resolveConfig()"]
  253815a9_405f_ff30_32b6_577fe2d91fb2 -->|calls| bc7b25d3_d5ad_3609_d595_c9755dfadcbb
  0d11f596_e057_1af5_1569_620f9e160e4b["removeUnnecessarySpacingKeys()"]
  253815a9_405f_ff30_32b6_577fe2d91fb2 -->|calls| 0d11f596_e057_1af5_1569_620f9e160e4b
  e01d9b91_28ef_ca30_15e9_dad1881235ce["keyframesToCss()"]
  253815a9_405f_ff30_32b6_577fe2d91fb2 -->|calls| e01d9b91_28ef_ca30_15e9_dad1881235ce
  06d695a5_21e2_adf5_352b_954581b3e1c0["buildCustomContainerUtilityRules()"]
  253815a9_405f_ff30_32b6_577fe2d91fb2 -->|calls| 06d695a5_21e2_adf5_352b_954581b3e1c0
  2f6881be_62d9_4b96_7331_a962ced095f7["atRule()"]
  253815a9_405f_ff30_32b6_577fe2d91fb2 -->|calls| 2f6881be_62d9_4b96_7331_a962ced095f7
  49a8c506_c50e_ed4b_5a0e_0393edae2b6f["parse()"]
  253815a9_405f_ff30_32b6_577fe2d91fb2 -->|calls| 49a8c506_c50e_ed4b_5a0e_0393edae2b6f
  961a5671_178b_5937_79ae_2463c9fb3bc9["themeableValues()"]
  253815a9_405f_ff30_32b6_577fe2d91fb2 -->|calls| 961a5671_178b_5937_79ae_2463c9fb3bc9
  12c0cce9_e937_c069_fc6e_1817b8c7583b["isValidOpacityValue()"]
  253815a9_405f_ff30_32b6_577fe2d91fb2 -->|calls| 12c0cce9_e937_c069_fc6e_1817b8c7583b
  faa57847_87ea_a82c_85ad_13fdbbf201c3["createSectionKey()"]
  253815a9_405f_ff30_32b6_577fe2d91fb2 -->|calls| faa57847_87ea_a82c_85ad_13fdbbf201c3
  1767219e_c38a_227c_492b_5d47634d54a4["keyPathToCssProperty()"]
  253815a9_405f_ff30_32b6_577fe2d91fb2 -->|calls| 1767219e_c38a_227c_492b_5d47634d54a4
  3330a25c_8114_660c_a3c7_8f1aaa37457d["escape()"]
  253815a9_405f_ff30_32b6_577fe2d91fb2 -->|calls| 3330a25c_8114_660c_a3c7_8f1aaa37457d
  9b49f3c6_0c8d_5c62_965c_30a1db6499f8["toCss()"]
  253815a9_405f_ff30_32b6_577fe2d91fb2 -->|calls| 9b49f3c6_0c8d_5c62_965c_30a1db6499f8
  style 253815a9_405f_ff30_32b6_577fe2d91fb2 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/@tailwindcss-upgrade/src/codemods/config/migrate-js-config.ts lines 97–290

async function migrateTheme(
  designSystem: DesignSystem,
  unresolvedConfig: Config,
  base: string,
): Promise<string> {
  // Resolve the config file without applying plugins and presets, as these are
  // migrated to CSS separately.
  let configToResolve: ConfigFile = {
    base,
    config: { ...unresolvedConfig, plugins: [], presets: undefined },
    reference: false,
    src: undefined,
  }
  let { resolvedConfig, replacedThemeKeys } = resolveConfig(designSystem, [configToResolve])

  let resetNamespaces = new Map<string, boolean>(
    Array.from(replacedThemeKeys.entries()).map(([key]) => [key, false]),
  )

  removeUnnecessarySpacingKeys(designSystem, resolvedConfig, replacedThemeKeys)

  let css = ''
  let prevSectionKey = ''
  let themeSection: string[] = []
  let keyframesCss = ''
  let variants = new Map<string, string>()

  // Special handling of specific theme keys:
  {
    if ('keyframes' in resolvedConfig.theme) {
      keyframesCss += keyframesToCss(resolvedConfig.theme.keyframes)
      delete resolvedConfig.theme.keyframes
    }

    if ('container' in resolvedConfig.theme) {
      let rules = buildCustomContainerUtilityRules(resolvedConfig.theme.container, designSystem)
      if (rules.length > 0) {
        // Using `theme` instead of `utility` so it sits before the `@layer
        // base` with compatibility CSS. While this is technically a utility, it
        // makes a bit more sense to emit this closer to the `@theme` values
        // since it is needed for backwards compatibility.
        css += `\n@tw-bucket theme {\n`
        css += toCss([atRule('@utility', 'container', rules)])
        css += '}\n' // @tw-bucket
      }
      delete resolvedConfig.theme.container
    }

    if ('aria' in resolvedConfig.theme) {
      for (let [key, value] of Object.entries(resolvedConfig.theme.aria ?? {})) {
        // Will be handled by bare values if the names match.
        // E.g.: `aria-foo:flex` should produce `[aria-foo="true"]`
        if (new RegExp(`^${key}=(['"]?)true\\1$`).test(`${value}`)) continue

        // Create custom variant
        variants.set(`aria-${key}`, `&[aria-${value}]`)
      }
      delete resolvedConfig.theme.aria
    }

    if ('data' in resolvedConfig.theme) {
      for (let [key, value] of Object.entries(resolvedConfig.theme.data ?? {})) {
        // Will be handled by bare values if the names match.
        // E.g.: `data-foo:flex` should produce `[data-foo]`
        if (key === value) continue

        // Create custom variant
        variants.set(`data-${key}`, `&[data-${value}]`)
      }
      delete resolvedConfig.theme.data
    }

    if ('supports' in resolvedConfig.theme) {
      for (let [key, value] of Object.entries(resolvedConfig.theme.supports ?? {})) {
        // Will be handled by bare values if the value of the declaration is a
        // CSS variable.
        let parsed = ValueParser.parse(`${value}`)

        // Unwrap the parens, e.g.: `(foo: var(--bar))` → `foo: var(--bar)`
        if (parsed.length === 1 && parsed[0].kind === 'function' && parsed[0].value === '') {
          parsed = parsed[0].nodes

Subdomains

Called By

Frequently Asked Questions

What does migrateTheme() do?
migrateTheme() is a function in the tailwindcss codebase, defined in packages/@tailwindcss-upgrade/src/codemods/config/migrate-js-config.ts.
Where is migrateTheme() defined?
migrateTheme() is defined in packages/@tailwindcss-upgrade/src/codemods/config/migrate-js-config.ts at line 97.
What does migrateTheme() call?
migrateTheme() calls 12 function(s): atRule, buildCustomContainerUtilityRules, createSectionKey, escape, isValidOpacityValue, keyPathToCssProperty, keyframesToCss, parse, and 4 more.
What calls migrateTheme()?
migrateTheme() is called by 1 function(s): migrateJsConfig.

Analyze Your Own Codebase

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

Try Supermodel Free