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

migrate-prefix.ts — tailwindcss Source File

Architecture documentation for migrate-prefix.ts, a typescript file in the tailwindcss codebase. 11 imports, 5 dependents.

File typescript CommandLineInterface Codemods 11 imports 5 dependents 3 functions

Entity Profile

Dependency Diagram

graph LR
  e4e5ac2c_0d58_689d_0ad6_7086823787f1["migrate-prefix.ts"]
  b9cbffa4_c352_cf3c_268f_cbb174fb3a47["ast.ts"]
  e4e5ac2c_0d58_689d_0ad6_7086823787f1 --> b9cbffa4_c352_cf3c_268f_cbb174fb3a47
  1369a6dc_e395_347d_5d24_b88e22c5446d["decl"]
  e4e5ac2c_0d58_689d_0ad6_7086823787f1 --> 1369a6dc_e395_347d_5d24_b88e22c5446d
  ba6fca27_7720_5839_0f92_bc2abb8db636["candidate.ts"]
  e4e5ac2c_0d58_689d_0ad6_7086823787f1 --> ba6fca27_7720_5839_0f92_bc2abb8db636
  7d328a86_10c6_b5c1_6390_36f4fffe9c14["parseCandidate"]
  e4e5ac2c_0d58_689d_0ad6_7086823787f1 --> 7d328a86_10c6_b5c1_6390_36f4fffe9c14
  da5d1116_ab2a_437a_6b13_c1429fd546fa["plugin-api.ts"]
  e4e5ac2c_0d58_689d_0ad6_7086823787f1 --> da5d1116_ab2a_437a_6b13_c1429fd546fa
  0255ffc0_a3d5_e883_5143_99660766448f["Config"]
  e4e5ac2c_0d58_689d_0ad6_7086823787f1 --> 0255ffc0_a3d5_e883_5143_99660766448f
  bdedd2f6_da4b_69dc_e990_0814b59fbe6e["design-system.ts"]
  e4e5ac2c_0d58_689d_0ad6_7086823787f1 --> bdedd2f6_da4b_69dc_e990_0814b59fbe6e
  665aa4ed_d86e_30e5_80d5_cd56b8ca8b62["DesignSystem"]
  e4e5ac2c_0d58_689d_0ad6_7086823787f1 --> 665aa4ed_d86e_30e5_80d5_cd56b8ca8b62
  bb9924cc_8308_a1f9_0e30_76de45a64970["segment.ts"]
  e4e5ac2c_0d58_689d_0ad6_7086823787f1 --> bb9924cc_8308_a1f9_0e30_76de45a64970
  c58cbb33_f3cc_0b4f_844a_15bf66a1dc61["segment"]
  e4e5ac2c_0d58_689d_0ad6_7086823787f1 --> c58cbb33_f3cc_0b4f_844a_15bf66a1dc61
  472e1b98_afcf_f1f2_ad91_916d742bb731["version.ts"]
  e4e5ac2c_0d58_689d_0ad6_7086823787f1 --> 472e1b98_afcf_f1f2_ad91_916d742bb731
  d51977aa_e57d_6179_0d9a_3c91e11a2a64["migrate-handle-empty-arbitrary-values.test.ts"]
  d51977aa_e57d_6179_0d9a_3c91e11a2a64 --> e4e5ac2c_0d58_689d_0ad6_7086823787f1
  80bb9840_1d91_d6ca_549c_09209ffc25a6["migrate-modernize-arbitrary-values.test.ts"]
  80bb9840_1d91_d6ca_549c_09209ffc25a6 --> e4e5ac2c_0d58_689d_0ad6_7086823787f1
  3fb6e8d3_05d9_63e2_c1c9_76cdf725f56a["migrate-prefix.test.ts"]
  3fb6e8d3_05d9_63e2_c1c9_76cdf725f56a --> e4e5ac2c_0d58_689d_0ad6_7086823787f1
  style e4e5ac2c_0d58_689d_0ad6_7086823787f1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { decl } from '../../../../tailwindcss/src/ast'
import { parseCandidate, type Candidate } from '../../../../tailwindcss/src/candidate'
import type { Config } from '../../../../tailwindcss/src/compat/plugin-api'
import type { DesignSystem } from '../../../../tailwindcss/src/design-system'
import { segment } from '../../../../tailwindcss/src/utils/segment'
import * as version from '../../utils/version'

let seenDesignSystems = new WeakSet<DesignSystem>()

export function migratePrefix(
  designSystem: DesignSystem,
  userConfig: Config | null,
  rawCandidate: string,
): string {
  if (!designSystem.theme.prefix) return rawCandidate
  if (!userConfig) return rawCandidate
  if (!version.isMajor(3)) return rawCandidate

  if (!seenDesignSystems.has(designSystem)) {
    designSystem.utilities.functional('group', (value) => [
      // To ensure that `@apply group` works when computing a signature
      decl('--phantom-class', 'group'),
      // To ensure `group` and `group/foo` are considered different classes
      decl('--phantom-modifier', value.modifier?.value),
    ])
    designSystem.utilities.functional('peer', (value) => [
      // To ensure that `@apply peer` works when computing a signature
      decl('--phantom-class', 'peer'),
      // To ensure `peer` and `peer/foo` are considered different classes
      decl('--phantom-modifier', value.modifier?.value),
    ])
    seenDesignSystems.add(designSystem)
  }

  let v3Base = extractV3Base(designSystem, userConfig, rawCandidate)

  if (!v3Base) return rawCandidate

  // Only migrate candidates which are valid in v4
  let originalPrefix = designSystem.theme.prefix
  let candidate: Candidate | null = null
  try {
    designSystem.theme.prefix = null

    let unprefixedCandidate =
      rawCandidate.slice(0, v3Base.start) + v3Base.base + rawCandidate.slice(v3Base.end)

    // Note: This is not a valid candidate in the original DesignSystem, so we
    // can not use the `DesignSystem#parseCandidate` API here or otherwise this
    // invalid candidate will be cached.
    let candidates = [...parseCandidate(unprefixedCandidate, designSystem)]
    if (candidates.length > 0) {
      candidate = candidates[0]
    }
  } finally {
    designSystem.theme.prefix = originalPrefix
  }

  if (!candidate) return rawCandidate

// ... (81 more lines)

Subdomains

Frequently Asked Questions

What does migrate-prefix.ts do?
migrate-prefix.ts is a source file in the tailwindcss codebase, written in typescript. It belongs to the CommandLineInterface domain, Codemods subdomain.
What functions are defined in migrate-prefix.ts?
migrate-prefix.ts defines 3 function(s): extractV3Base, migratePrefix, migratePrefixValue.
What does migrate-prefix.ts depend on?
migrate-prefix.ts imports 11 module(s): Config, DesignSystem, ast.ts, candidate.ts, decl, design-system.ts, parseCandidate, plugin-api.ts, and 3 more.
What files import migrate-prefix.ts?
migrate-prefix.ts is imported by 5 file(s): migrate-handle-empty-arbitrary-values.test.ts, migrate-modernize-arbitrary-values.test.ts, migrate-prefix.test.ts, migrate.ts, prepare-config.ts.
Where is migrate-prefix.ts in the architecture?
migrate-prefix.ts is located at packages/@tailwindcss-upgrade/src/codemods/template/migrate-prefix.ts (domain: CommandLineInterface, subdomain: Codemods, directory: packages/@tailwindcss-upgrade/src/codemods/template).

Analyze Your Own Codebase

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

Try Supermodel Free