Home / Function/ canMigrateConfig() — tailwindcss Function Reference

canMigrateConfig() — tailwindcss Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  15b378ea_3aa4_54e9_344a_eae392b6770c["canMigrateConfig()"]
  ffe9c87e_35ad_f431_9625_80fc875792a7["migrate-js-config.ts"]
  15b378ea_3aa4_54e9_344a_eae392b6770c -->|defined in| ffe9c87e_35ad_f431_9625_80fc875792a7
  617e9831_5cd2_4ca6_2c65_f89e3720cfd8["migrateJsConfig()"]
  617e9831_5cd2_4ca6_2c65_f89e3720cfd8 -->|calls| 15b378ea_3aa4_54e9_344a_eae392b6770c
  79d116f6_7ff2_5367_4672_ab907f2a77dc["findStaticPlugins()"]
  15b378ea_3aa4_54e9_344a_eae392b6770c -->|calls| 79d116f6_7ff2_5367_4672_ab907f2a77dc
  220d18cf_fa97_55bb_9b09_4d63ca376b8b["onlyAllowedThemeValues()"]
  15b378ea_3aa4_54e9_344a_eae392b6770c -->|calls| 220d18cf_fa97_55bb_9b09_4d63ca376b8b
  style 15b378ea_3aa4_54e9_344a_eae392b6770c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/@tailwindcss-upgrade/src/codemods/config/migrate-js-config.ts lines 393–467

function canMigrateConfig(unresolvedConfig: Config, source: string): boolean {
  // The file may not contain non-serializable values
  function isSimpleValue(value: unknown): boolean {
    if (typeof value === 'function') return false
    if (Array.isArray(value)) return value.every(isSimpleValue)
    if (typeof value === 'object' && value !== null) {
      return Object.values(value).every(isSimpleValue)
    }
    return ['string', 'number', 'boolean', 'undefined'].includes(typeof value)
  }

  // `theme` and `plugins` are handled separately and allowed to be more complex
  let { plugins, theme, ...remainder } = unresolvedConfig
  if (!isSimpleValue(remainder)) {
    return false
  }

  // The file may only contain known-migratable top-level properties
  let knownProperties = [
    'darkMode',
    'content',
    'theme',
    'plugins',
    'presets',
    'prefix', // Prefix is handled in the dedicated prefix migrator
    'corePlugins',
    'future',
    'experimental',
  ]

  if (Object.keys(unresolvedConfig).some((key) => !knownProperties.includes(key))) {
    return false
  }

  if (findStaticPlugins(source) === null) {
    return false
  }

  if (unresolvedConfig.presets && unresolvedConfig.presets.length > 0) {
    return false
  }

  // If there are unknown "future" flags we should bail
  if (unresolvedConfig.future && unresolvedConfig.future !== 'all') {
    let knownFlags = [
      'hoverOnlyWhenSupported',
      'respectDefaultRingColorOpacity',
      'disableColorOpacityUtilitiesByDefault',
      'relativeContentPathsByDefault',
    ]

    if (Object.keys(unresolvedConfig.future).some((key) => !knownFlags.includes(key))) {
      return false
    }
  }

  // If there are unknown "experimental" flags we should bail
  if (unresolvedConfig.experimental && unresolvedConfig.experimental !== 'all') {
    let knownFlags = ['generalizedModifiers']

    if (Object.keys(unresolvedConfig.experimental).some((key) => !knownFlags.includes(key))) {
      return false
    }
  }

  // Only migrate the config file if all top-level theme keys are allowed to be
  // migrated
  if (theme && typeof theme === 'object') {
    if (theme.extend && !onlyAllowedThemeValues(theme.extend)) return false
    let { extend: _extend, ...themeCopy } = theme
    if (!onlyAllowedThemeValues(themeCopy)) return false
  }

  return true
}

Subdomains

Called By

Frequently Asked Questions

What does canMigrateConfig() do?
canMigrateConfig() is a function in the tailwindcss codebase, defined in packages/@tailwindcss-upgrade/src/codemods/config/migrate-js-config.ts.
Where is canMigrateConfig() defined?
canMigrateConfig() is defined in packages/@tailwindcss-upgrade/src/codemods/config/migrate-js-config.ts at line 393.
What does canMigrateConfig() call?
canMigrateConfig() calls 2 function(s): findStaticPlugins, onlyAllowedThemeValues.
What calls canMigrateConfig()?
canMigrateConfig() 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