Home / File/ migrate-postcss.ts — tailwindcss Source File

migrate-postcss.ts — tailwindcss Source File

Architecture documentation for migrate-postcss.ts, a typescript file in the tailwindcss codebase. 10 imports, 1 dependents.

File typescript UpgradeToolkit Codemods 10 imports 1 dependents 7 functions

Entity Profile

Dependency Diagram

graph LR
  9c861556_2895_9b7c_50ec_d9aa3cfc5c68["migrate-postcss.ts"]
  6403ca00_0447_9313_3bb5_f9ea44ca2dbb["packages.ts"]
  9c861556_2895_9b7c_50ec_d9aa3cfc5c68 --> 6403ca00_0447_9313_3bb5_f9ea44ca2dbb
  14c611e1_f56a_262f_0861_6fb84b21afb3["pkg"]
  9c861556_2895_9b7c_50ec_d9aa3cfc5c68 --> 14c611e1_f56a_262f_0861_6fb84b21afb3
  9106c15d_cfb8_77f5_665e_9707020b48c8["renderer.ts"]
  9c861556_2895_9b7c_50ec_d9aa3cfc5c68 --> 9106c15d_cfb8_77f5_665e_9707020b48c8
  a81de696_6bb5_40db_26ca_1d707ccebed9["highlight"]
  9c861556_2895_9b7c_50ec_d9aa3cfc5c68 --> a81de696_6bb5_40db_26ca_1d707ccebed9
  f6cf39d1_9161_38f6_5e39_d0d0f34bb6a8["info"]
  9c861556_2895_9b7c_50ec_d9aa3cfc5c68 --> f6cf39d1_9161_38f6_5e39_d0d0f34bb6a8
  efdaf4fe_1cde_66e0_60e0_5e155e297f6d["relative"]
  9c861556_2895_9b7c_50ec_d9aa3cfc5c68 --> efdaf4fe_1cde_66e0_60e0_5e155e297f6d
  37b3db30_53ad_adf5_7c3d_6c08e7198514["success"]
  9c861556_2895_9b7c_50ec_d9aa3cfc5c68 --> 37b3db30_53ad_adf5_7c3d_6c08e7198514
  e019b578_e34e_650f_6c6e_85cd4f4dbeb8["warn"]
  9c861556_2895_9b7c_50ec_d9aa3cfc5c68 --> e019b578_e34e_650f_6c6e_85cd4f4dbeb8
  8118fcf2_a51d_d1a1_93d3_c71d3a646692["promises"]
  9c861556_2895_9b7c_50ec_d9aa3cfc5c68 --> 8118fcf2_a51d_d1a1_93d3_c71d3a646692
  2a7660a5_3e09_bd74_37f0_e4e54bc64ce5["node:path"]
  9c861556_2895_9b7c_50ec_d9aa3cfc5c68 --> 2a7660a5_3e09_bd74_37f0_e4e54bc64ce5
  b2eb6cbf_d28d_9ec7_61c1_8992d8f4efb8["index.ts"]
  b2eb6cbf_d28d_9ec7_61c1_8992d8f4efb8 --> 9c861556_2895_9b7c_50ec_d9aa3cfc5c68
  style 9c861556_2895_9b7c_50ec_d9aa3cfc5c68 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import fs from 'node:fs/promises'
import path from 'node:path'
import { pkg } from '../../utils/packages'
import { highlight, info, relative, success, warn } from '../../utils/renderer'

// Migrates simple PostCSS setups. This is to cover non-dynamic config files
// similar to the ones we have all over our docs:
//
// ```js
// module.exports = {
//   plugins: {
//     'postcss-import': {},
//     'tailwindcss/nesting': 'postcss-nesting',
//     tailwindcss: {},
//     autoprefixer: {},
//   }
// }
// ```
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
// ... (289 more lines)

Subdomains

Frequently Asked Questions

What does migrate-postcss.ts do?
migrate-postcss.ts is a source file in the tailwindcss codebase, written in typescript. It belongs to the UpgradeToolkit domain, Codemods subdomain.
What functions are defined in migrate-postcss.ts?
migrate-postcss.ts defines 7 function(s): detectJSConfigPath, detectJSONConfigPath, isEmptyObject, isSimplePostCSSConfig, migratePostCSSConfig, migratePostCSSJSConfig, migratePostCSSJsonConfig.
What does migrate-postcss.ts depend on?
migrate-postcss.ts imports 10 module(s): highlight, info, node:path, packages.ts, pkg, promises, relative, renderer.ts, and 2 more.
What files import migrate-postcss.ts?
migrate-postcss.ts is imported by 1 file(s): index.ts.
Where is migrate-postcss.ts in the architecture?
migrate-postcss.ts is located at packages/@tailwindcss-upgrade/src/codemods/config/migrate-postcss.ts (domain: UpgradeToolkit, subdomain: Codemods, directory: packages/@tailwindcss-upgrade/src/codemods/config).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free