Home / File/ link.ts — tailwindcss Source File

link.ts — tailwindcss Source File

Architecture documentation for link.ts, a typescript file in the tailwindcss codebase. 14 imports, 1 dependents.

File typescript UpgradeToolkit Codemods 14 imports 1 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  9db14b70_46b7_0974_d9fd_49584e40ff70["link.ts"]
  c056448b_f7a2_9149_54e8_f0f8470fe3aa["default-map.ts"]
  9db14b70_46b7_0974_d9fd_49584e40ff70 --> c056448b_f7a2_9149_54e8_f0f8470fe3aa
  bf2992f6_4a37_8536_70f8_94b13631027d["DefaultMap"]
  9db14b70_46b7_0974_d9fd_49584e40ff70 --> bf2992f6_4a37_8536_70f8_94b13631027d
  41fd12a7_15c2_7d83_2e55_c5b9a8faf9b1["stylesheet.ts"]
  9db14b70_46b7_0974_d9fd_49584e40ff70 --> 41fd12a7_15c2_7d83_2e55_c5b9a8faf9b1
  c890fa7b_6e17_4e5d_74bf_b797d0f757b8["Stylesheet"]
  9db14b70_46b7_0974_d9fd_49584e40ff70 --> c890fa7b_6e17_4e5d_74bf_b797d0f757b8
  9106c15d_cfb8_77f5_665e_9707020b48c8["renderer.ts"]
  9db14b70_46b7_0974_d9fd_49584e40ff70 --> 9106c15d_cfb8_77f5_665e_9707020b48c8
  f1ca9393_701c_e4a7_8303_ed03f028d19b["error"]
  9db14b70_46b7_0974_d9fd_49584e40ff70 --> f1ca9393_701c_e4a7_8303_ed03f028d19b
  a81de696_6bb5_40db_26ca_1d707ccebed9["highlight"]
  9db14b70_46b7_0974_d9fd_49584e40ff70 --> a81de696_6bb5_40db_26ca_1d707ccebed9
  efdaf4fe_1cde_66e0_60e0_5e155e297f6d["relative"]
  9db14b70_46b7_0974_d9fd_49584e40ff70 --> efdaf4fe_1cde_66e0_60e0_5e155e297f6d
  37b3db30_53ad_adf5_7c3d_6c08e7198514["success"]
  9db14b70_46b7_0974_d9fd_49584e40ff70 --> 37b3db30_53ad_adf5_7c3d_6c08e7198514
  c8809718_3b35_1fdb_ff99_94e375c7360a["prepare-config.ts"]
  9db14b70_46b7_0974_d9fd_49584e40ff70 --> c8809718_3b35_1fdb_ff99_94e375c7360a
  29edd669_83d1_d2aa_eab9_7e8139fc8b20["detectConfigPath"]
  9db14b70_46b7_0974_d9fd_49584e40ff70 --> 29edd669_83d1_d2aa_eab9_7e8139fc8b20
  92f2d961_72a4_d195_92d7_2e66972f8894["node"]
  9db14b70_46b7_0974_d9fd_49584e40ff70 --> 92f2d961_72a4_d195_92d7_2e66972f8894
  2a7660a5_3e09_bd74_37f0_e4e54bc64ce5["node:path"]
  9db14b70_46b7_0974_d9fd_49584e40ff70 --> 2a7660a5_3e09_bd74_37f0_e4e54bc64ce5
  ba54c7c3_7b1e_9984_bfef_a693a3df2d84["postcss"]
  9db14b70_46b7_0974_d9fd_49584e40ff70 --> ba54c7c3_7b1e_9984_bfef_a693a3df2d84
  style 9db14b70_46b7_0974_d9fd_49584e40ff70 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { normalizePath } from '@tailwindcss/node'
import path from 'node:path'
import postcss from 'postcss'
import { DefaultMap } from '../../../../tailwindcss/src/utils/default-map'
import { Stylesheet } from '../../stylesheet'
import { error, highlight, relative, success } from '../../utils/renderer'
import { detectConfigPath } from '../template/prepare-config'

export async function linkConfigs(
  stylesheets: Stylesheet[],
  { configPath, base }: { configPath: string | null; base: string },
) {
  let rootStylesheets = stylesheets.filter((sheet) => sheet.isTailwindRoot)
  if (rootStylesheets.length === 0) {
    throw new Error(
      `Cannot find any CSS files that reference Tailwind CSS.\nBefore your project can be upgraded you need to create a CSS file that imports Tailwind CSS or uses ${highlight('@tailwind')}.`,
    )
  }
  let withoutAtConfig = rootStylesheets.filter((sheet) => {
    let hasConfig = false
    sheet.root.walkAtRules('config', (node) => {
      let configPath = path.resolve(path.dirname(sheet.file!), node.params.slice(1, -1))
      sheet.linkedConfigPath = configPath
      hasConfig = true
      return false
    })
    return !hasConfig
  })

  // All stylesheets have a `@config` directives
  if (withoutAtConfig.length === 0) return

  // Find the config file path for each stylesheet
  let configPathBySheet = new Map<Stylesheet, string>()
  let sheetByConfigPath = new DefaultMap<string, Set<Stylesheet>>(() => new Set())
  for (let sheet of withoutAtConfig) {
    if (!sheet.file) continue

    let localConfigPath = configPath as string
    if (configPath === null) {
      localConfigPath = await detectConfigPath(path.dirname(sheet.file), base)
    } else if (!path.isAbsolute(localConfigPath)) {
      localConfigPath = path.resolve(base, localConfigPath)
    }

    configPathBySheet.set(sheet, localConfigPath)
    sheetByConfigPath.get(localConfigPath).add(sheet)
  }

  let problematicStylesheets = new Set<Stylesheet>()
  for (let sheets of sheetByConfigPath.values()) {
    if (sheets.size > 1) {
      for (let sheet of sheets) {
        problematicStylesheets.add(sheet)
      }
    }
  }

  // There are multiple "root" files without `@config` directives. Manual
  // intervention is needed to link to the correct Tailwind config files.
// ... (63 more lines)

Subdomains

Functions

Frequently Asked Questions

What does link.ts do?
link.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 link.ts?
link.ts defines 1 function(s): linkConfigs.
What does link.ts depend on?
link.ts imports 14 module(s): DefaultMap, Stylesheet, default-map.ts, detectConfigPath, error, highlight, node, node:path, and 6 more.
What files import link.ts?
link.ts is imported by 1 file(s): index.ts.
Where is link.ts in the architecture?
link.ts is located at packages/@tailwindcss-upgrade/src/codemods/css/link.ts (domain: UpgradeToolkit, subdomain: Codemods, directory: packages/@tailwindcss-upgrade/src/codemods/css).

Analyze Your Own Codebase

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

Try Supermodel Free