migratePostCSSConfig() — tailwindcss Function Reference
Architecture documentation for the migratePostCSSConfig() function in migrate-postcss.ts from the tailwindcss codebase.
Entity Profile
Dependency Diagram
graph TD 32e1ecdd_6093_f556_114f_ec3d5663975f["migratePostCSSConfig()"] eb8ababf_fa35_08e1_76f8_c2b2cea868b8["run()"] eb8ababf_fa35_08e1_76f8_c2b2cea868b8 -->|calls| 32e1ecdd_6093_f556_114f_ec3d5663975f 9b400cc0_c561_f305_42a2_61c2c7cb8b6e["detectJSConfigPath()"] 32e1ecdd_6093_f556_114f_ec3d5663975f -->|calls| 9b400cc0_c561_f305_42a2_61c2c7cb8b6e 02abfdc1_e285_188c_43c7_c63389394a0b["migratePostCSSJSConfig()"] 32e1ecdd_6093_f556_114f_ec3d5663975f -->|calls| 02abfdc1_e285_188c_43c7_c63389394a0b d3b72ca3_3ae9_3f74_bf5f_97dcf66a4539["migratePostCSSJsonConfig()"] 32e1ecdd_6093_f556_114f_ec3d5663975f -->|calls| d3b72ca3_3ae9_3f74_bf5f_97dcf66a4539 c1727fe3_2e0f_3feb_0928_5ffae0e1aea2["detectJSONConfigPath()"] 32e1ecdd_6093_f556_114f_ec3d5663975f -->|calls| c1727fe3_2e0f_3feb_0928_5ffae0e1aea2 98289381_3219_727d_fea6_371f55963ac8["info()"] 32e1ecdd_6093_f556_114f_ec3d5663975f -->|calls| 98289381_3219_727d_fea6_371f55963ac8 00cccf76_743c_3b0f_179f_c3f05c433097["pkg()"] 32e1ecdd_6093_f556_114f_ec3d5663975f -->|calls| 00cccf76_743c_3b0f_179f_c3f05c433097 d3757426_3d9a_0d83_2369_bcd1fe94ac5f["success()"] 32e1ecdd_6093_f556_114f_ec3d5663975f -->|calls| d3757426_3d9a_0d83_2369_bcd1fe94ac5f c1e4d14f_eec6_482b_9f78_0242ee9d41b8["highlight()"] 32e1ecdd_6093_f556_114f_ec3d5663975f -->|calls| c1e4d14f_eec6_482b_9f78_0242ee9d41b8 85696a99_698d_94e6_aa94_10c070d75965["relative()"] 32e1ecdd_6093_f556_114f_ec3d5663975f -->|calls| 85696a99_698d_94e6_aa94_10c070d75965 style 32e1ecdd_6093_f556_114f_ec3d5663975f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/@tailwindcss-upgrade/src/codemods/config/migrate-postcss.ts lines 19–131
export async function migratePostCSSConfig(base: string) {
let ranMigration = false
let didMigrate = false
let didAddPostcssClient = false
let didRemoveAutoprefixer = false
let didRemovePostCSSImport = false
let packageJsonPath = path.resolve(base, 'package.json')
let packageJson
try {
packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf-8'))
} catch {}
// Priority 1: Handle JS config files
let jsConfigPath = await detectJSConfigPath(base)
if (jsConfigPath) {
let result = await migratePostCSSJSConfig(jsConfigPath)
ranMigration = true
if (result) {
didMigrate = true
didAddPostcssClient = result.didAddPostcssClient
didRemoveAutoprefixer = result.didRemoveAutoprefixer
didRemovePostCSSImport = result.didRemovePostCSSImport
}
}
// Priority 2: Handle package.json config
if (!ranMigration) {
if (packageJson && 'postcss' in packageJson) {
let result = await migratePostCSSJsonConfig(packageJson.postcss)
ranMigration = true
if (result) {
await fs.writeFile(
packageJsonPath,
JSON.stringify({ ...packageJson, postcss: result?.json }, null, 2),
)
didMigrate = true
didAddPostcssClient = result.didAddPostcssClient
didRemoveAutoprefixer = result.didRemoveAutoprefixer
didRemovePostCSSImport = result.didRemovePostCSSImport
}
}
}
// Priority 3: JSON based postcss config files
if (!ranMigration) {
let jsonConfigPath = await detectJSONConfigPath(base)
let jsonConfig: null | any = null
if (jsonConfigPath) {
try {
jsonConfig = JSON.parse(await fs.readFile(jsonConfigPath, 'utf-8'))
} catch {}
if (jsonConfig) {
let result = await migratePostCSSJsonConfig(jsonConfig)
ranMigration = true
if (result) {
await fs.writeFile(jsonConfigPath, JSON.stringify(result.json, null, 2))
didMigrate = true
didAddPostcssClient = result.didAddPostcssClient
didRemoveAutoprefixer = result.didRemoveAutoprefixer
didRemovePostCSSImport = result.didRemovePostCSSImport
}
}
}
}
if (!ranMigration) {
info('No PostCSS config found, skipping migration.', {
prefix: '↳ ',
})
return
}
if (didAddPostcssClient) {
let location = Object.hasOwn(packageJson?.dependencies ?? {}, 'tailwindcss')
? ('dependencies' as const)
: Object.hasOwn(packageJson?.devDependencies ?? {}, 'tailwindcss')
? ('devDependencies' as const)
: null
if (location !== null) {
try {
await pkg(base).add(['@tailwindcss/postcss@latest'], location)
success(`Installed package: ${highlight('@tailwindcss/postcss')}`, { prefix: '↳ ' })
} catch {}
}
}
if (didRemoveAutoprefixer) {
try {
await pkg(base).remove(['autoprefixer'])
success(`Removed package: ${highlight('autoprefixer')}`, { prefix: '↳ ' })
} catch {}
}
if (didRemovePostCSSImport) {
try {
await pkg(base).remove(['postcss-import'])
success(`Removed package: ${highlight('postcss-import')}`, { prefix: '↳ ' })
} catch {}
}
if (didMigrate && jsConfigPath) {
success(`Migrated PostCSS configuration: ${highlight(relative(jsConfigPath, base))}`, {
prefix: '↳ ',
})
}
}
Domain
Subdomains
Calls
Called By
Source
Frequently Asked Questions
What does migratePostCSSConfig() do?
migratePostCSSConfig() is a function in the tailwindcss codebase.
What does migratePostCSSConfig() call?
migratePostCSSConfig() calls 9 function(s): detectJSConfigPath, detectJSONConfigPath, highlight, info, migratePostCSSJSConfig, migratePostCSSJsonConfig, pkg, relative, and 1 more.
What calls migratePostCSSConfig()?
migratePostCSSConfig() is called by 1 function(s): run.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free