Home / File/ analyze.ts — tailwindcss Source File

analyze.ts — tailwindcss Source File

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

File typescript UpgradeToolkit Codemods 15 imports 1 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  764d02dc_895f_8f85_d274_59af948c9ebb["analyze.ts"]
  c056448b_f7a2_9149_54e8_f0f8470fe3aa["default-map.ts"]
  764d02dc_895f_8f85_d274_59af948c9ebb --> c056448b_f7a2_9149_54e8_f0f8470fe3aa
  bf2992f6_4a37_8536_70f8_94b13631027d["DefaultMap"]
  764d02dc_895f_8f85_d274_59af948c9ebb --> bf2992f6_4a37_8536_70f8_94b13631027d
  ef204000_8998_5a6c_5455_324b37624713["segment.ts"]
  764d02dc_895f_8f85_d274_59af948c9ebb --> ef204000_8998_5a6c_5455_324b37624713
  f712ed47_45d4_4e5a_dd73_fdefa1da71da["segment"]
  764d02dc_895f_8f85_d274_59af948c9ebb --> f712ed47_45d4_4e5a_dd73_fdefa1da71da
  41fd12a7_15c2_7d83_2e55_c5b9a8faf9b1["stylesheet.ts"]
  764d02dc_895f_8f85_d274_59af948c9ebb --> 41fd12a7_15c2_7d83_2e55_c5b9a8faf9b1
  c890fa7b_6e17_4e5d_74bf_b797d0f757b8["Stylesheet"]
  764d02dc_895f_8f85_d274_59af948c9ebb --> c890fa7b_6e17_4e5d_74bf_b797d0f757b8
  9106c15d_cfb8_77f5_665e_9707020b48c8["renderer.ts"]
  764d02dc_895f_8f85_d274_59af948c9ebb --> 9106c15d_cfb8_77f5_665e_9707020b48c8
  f1ca9393_701c_e4a7_8303_ed03f028d19b["error"]
  764d02dc_895f_8f85_d274_59af948c9ebb --> f1ca9393_701c_e4a7_8303_ed03f028d19b
  a81de696_6bb5_40db_26ca_1d707ccebed9["highlight"]
  764d02dc_895f_8f85_d274_59af948c9ebb --> a81de696_6bb5_40db_26ca_1d707ccebed9
  efdaf4fe_1cde_66e0_60e0_5e155e297f6d["relative"]
  764d02dc_895f_8f85_d274_59af948c9ebb --> efdaf4fe_1cde_66e0_60e0_5e155e297f6d
  8c8b43f7_0052_590f_b261_209a8ea9e585["resolve.ts"]
  764d02dc_895f_8f85_d274_59af948c9ebb --> 8c8b43f7_0052_590f_b261_209a8ea9e585
  5a0b5868_f0d5_73f9_87bf_98f06eb00ddb["resolveCssId"]
  764d02dc_895f_8f85_d274_59af948c9ebb --> 5a0b5868_f0d5_73f9_87bf_98f06eb00ddb
  63cf48ef_8e7b_9de4_7374_aa641613da63["globby"]
  764d02dc_895f_8f85_d274_59af948c9ebb --> 63cf48ef_8e7b_9de4_7374_aa641613da63
  2a7660a5_3e09_bd74_37f0_e4e54bc64ce5["node:path"]
  764d02dc_895f_8f85_d274_59af948c9ebb --> 2a7660a5_3e09_bd74_37f0_e4e54bc64ce5
  style 764d02dc_895f_8f85_d274_59af948c9ebb fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { isGitIgnored } from 'globby'
import path from 'node:path'
import postcss, { type Result } from 'postcss'
import { DefaultMap } from '../../../../tailwindcss/src/utils/default-map'
import { segment } from '../../../../tailwindcss/src/utils/segment'
import { Stylesheet, type StylesheetConnection } from '../../stylesheet'
import { error, highlight, relative } from '../../utils/renderer'
import { resolveCssId } from '../../utils/resolve'

export async function analyze(stylesheets: Stylesheet[]) {
  let isIgnored = await isGitIgnored()
  let processingQueue: (() => Promise<Result>)[] = []
  let stylesheetsByFile = new DefaultMap<string, Stylesheet | null>((file) => {
    // We don't want to process ignored files (like node_modules)
    try {
      if (isIgnored(file)) {
        return null
      }
    } catch {
      // If the file is not part of the current working directory (which can
      // happen if you import `tailwindcss` and it's loading a shared file from
      // pnpm) then this will throw.
      return null
    }

    try {
      let sheet = Stylesheet.loadSync(file)

      // Mutate incoming stylesheets to include the newly discovered sheet
      stylesheets.push(sheet)

      // Queue up the processing of this stylesheet
      processingQueue.push(() => processor.process(sheet.root, { from: sheet.file! }))

      return sheet
    } catch {
      return null
    }
  })

  // Step 1: Record which `@import` rules point to which stylesheets
  // and which stylesheets are parents/children of each other
  let processor = postcss([
    {
      postcssPlugin: 'mark-import-nodes',
      AtRule: {
        import(node) {
          // Find what the import points to
          let id = node.params.match(/['"](.*?)['"]/)?.[1]
          if (!id) return

          let basePath = node.source?.input.file
            ? path.dirname(node.source.input.file)
            : process.cwd()

          // Resolve the import to a file path
          let resolvedPath: string | false = false
          try {
            // We first try to resolve the file as relative to the current file
            // to mimic the behavior of `postcss-import` since that's what was
// ... (241 more lines)

Subdomains

Functions

Frequently Asked Questions

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