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
  7a3f2d88_6f0c_1a25_f3a3_982e5c35e67a["canMigrateConfig()"]
  b2ba3368_7330_fe20_4543_9cafa8cfedc0["migrate-js-config.ts"]
  7a3f2d88_6f0c_1a25_f3a3_982e5c35e67a -->|defined in| b2ba3368_7330_fe20_4543_9cafa8cfedc0
  1ef01211_e07d_fbec_dcb1_d3c7a3bfe061["migrateJsConfig()"]
  1ef01211_e07d_fbec_dcb1_d3c7a3bfe061 -->|calls| 7a3f2d88_6f0c_1a25_f3a3_982e5c35e67a
  7251786a_fd41_beea_80b3_e558e273b171["findStaticPlugins()"]
  7a3f2d88_6f0c_1a25_f3a3_982e5c35e67a -->|calls| 7251786a_fd41_beea_80b3_e558e273b171
  e1a348f7_349e_c682_8a19_351237c4f546["onlyAllowedThemeValues()"]
  7a3f2d88_6f0c_1a25_f3a3_982e5c35e67a -->|calls| e1a348f7_349e_c682_8a19_351237c4f546
  style 7a3f2d88_6f0c_1a25_f3a3_982e5c35e67a 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