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
  fad5e0cf_28c4_1123_bbfa_bb74fa036ea3["canMigrateConfig()"]
  dc1d7e71_14d1_dd51_5d14_8265f9e59cce["migrateJsConfig()"]
  dc1d7e71_14d1_dd51_5d14_8265f9e59cce -->|calls| fad5e0cf_28c4_1123_bbfa_bb74fa036ea3
  69c92c68_5d52_a398_56aa_286ad1f8d262["findStaticPlugins()"]
  fad5e0cf_28c4_1123_bbfa_bb74fa036ea3 -->|calls| 69c92c68_5d52_a398_56aa_286ad1f8d262
  9763f2a9_9f57_9b9d_f9df_a71589bcbb08["onlyAllowedThemeValues()"]
  fad5e0cf_28c4_1123_bbfa_bb74fa036ea3 -->|calls| 9763f2a9_9f57_9b9d_f9df_a71589bcbb08
  style fad5e0cf_28c4_1123_bbfa_bb74fa036ea3 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.
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