migratePreflight() — tailwindcss Function Reference
Architecture documentation for the migratePreflight() function in migrate-preflight.ts from the tailwindcss codebase.
Entity Profile
Dependency Diagram
graph TD 904b969f_df9e_eb9f_fedd_18eea0cfe028["migratePreflight()"] 4ccbfbad_b80c_422a_38fe_dc35ee118e8d["migrate-preflight.ts"] 904b969f_df9e_eb9f_fedd_18eea0cfe028 -->|defined in| 4ccbfbad_b80c_422a_38fe_dc35ee118e8d 26298c28_699e_61f2_4a12_de01f329a5d8["migrate()"] 26298c28_699e_61f2_4a12_de01f329a5d8 -->|calls| 904b969f_df9e_eb9f_fedd_18eea0cfe028 9ebd84f7_07bc_9b19_28a7_8bd93119c37e["migrateContents()"] 9ebd84f7_07bc_9b19_28a7_8bd93119c37e -->|calls| 904b969f_df9e_eb9f_fedd_18eea0cfe028 ae20c4fb_29d7_ca79_3c49_ca02c45d5369["keyPathToCssProperty()"] 904b969f_df9e_eb9f_fedd_18eea0cfe028 -->|calls| ae20c4fb_29d7_ca79_3c49_ca02c45d5369 1b250eae_0bea_d404_ca9e_42da26c56b45["toKeyPath()"] 904b969f_df9e_eb9f_fedd_18eea0cfe028 -->|calls| 1b250eae_0bea_d404_ca9e_42da26c56b45 8d08c9fd_45a1_f37c_a879_6fd2c9991403["isMajor()"] 904b969f_df9e_eb9f_fedd_18eea0cfe028 -->|calls| 8d08c9fd_45a1_f37c_a879_6fd2c9991403 2d6c8361_96d8_df0d_ca51_c62f179fdc73["parse()"] 904b969f_df9e_eb9f_fedd_18eea0cfe028 -->|calls| 2d6c8361_96d8_df0d_ca51_c62f179fdc73 ef07d6e3_0c3a_4722_5511_8d4759b3f570["substituteFunctionsInValue()"] 904b969f_df9e_eb9f_fedd_18eea0cfe028 -->|calls| ef07d6e3_0c3a_4722_5511_8d4759b3f570 style 904b969f_df9e_eb9f_fedd_18eea0cfe028 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/@tailwindcss-upgrade/src/codemods/css/migrate-preflight.ts lines 35–115
export function migratePreflight({
designSystem,
userConfig,
}: {
designSystem: DesignSystem | null
userConfig?: Config | null
}): Plugin {
// @ts-expect-error
let defaultBorderColor = userConfig?.theme?.borderColor?.DEFAULT
function canResolveThemeValue(path: string) {
if (!designSystem) return false
let variable = `--${keyPathToCssProperty(toKeyPath(path))}` as const
return Boolean(designSystem.theme.get([variable]))
}
function migrate(root: Root) {
// CSS for backwards compatibility with v3 should only injected in v3
// projects and not v4 projects.
if (!version.isMajor(3)) return
let isTailwindRoot = false
root.walkAtRules('import', (node) => {
if (
/['"]tailwindcss['"]/.test(node.params) ||
/['"]tailwindcss\/preflight['"]/.test(node.params)
) {
isTailwindRoot = true
return false
}
})
if (!isTailwindRoot) return
// Figure out the compatibility CSS to inject
let compatibilityCssString = ''
if (defaultBorderColor !== DEFAULT_BORDER_COLOR) {
compatibilityCssString += BORDER_COLOR_COMPATIBILITY_CSS
compatibilityCssString += '\n\n'
}
compatibilityCssString = `\n@tw-bucket compatibility {\n${compatibilityCssString}\n}\n`
let compatibilityCss = postcss.parse(compatibilityCssString)
// Replace the `theme(…)` with v3 values if we can't resolve the theme
// value.
compatibilityCss.walkDecls((decl) => {
if (decl.value.includes('theme(')) {
decl.value = substituteFunctionsInValue(ValueParser.parse(decl.value), (path) => {
if (canResolveThemeValue(path)) {
return defaultBorderColor
} else {
if (path === 'borderColor.DEFAULT') {
return 'var(--color-gray-200, currentcolor)'
}
}
return null
})
}
})
// Cleanup `--border-color` definition in `theme(…)`
root.walkAtRules('theme', (node) => {
node.walkDecls('--border-color', (decl) => {
decl.remove()
})
if (node.nodes?.length === 0) {
node.remove()
}
})
// Inject the compatibility CSS
root.append(compatibilityCss)
}
return {
postcssPlugin: '@tailwindcss/upgrade/migrate-preflight',
OnceExit: migrate,
}
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does migratePreflight() do?
migratePreflight() is a function in the tailwindcss codebase, defined in packages/@tailwindcss-upgrade/src/codemods/css/migrate-preflight.ts.
Where is migratePreflight() defined?
migratePreflight() is defined in packages/@tailwindcss-upgrade/src/codemods/css/migrate-preflight.ts at line 35.
What does migratePreflight() call?
migratePreflight() calls 5 function(s): isMajor, keyPathToCssProperty, parse, substituteFunctionsInValue, toKeyPath.
What calls migratePreflight()?
migratePreflight() 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