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 CommandLineInterface Codemods 15 imports 1 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  c30c28f2_b6df_e90d_67d1_db074bef35a5["analyze.ts"]
  28a2f72d_350c_6647_bf9d_77c69e637045["default-map.ts"]
  c30c28f2_b6df_e90d_67d1_db074bef35a5 --> 28a2f72d_350c_6647_bf9d_77c69e637045
  cfb4af0e_7b2d_34a1_693a_90088443cfec["DefaultMap"]
  c30c28f2_b6df_e90d_67d1_db074bef35a5 --> cfb4af0e_7b2d_34a1_693a_90088443cfec
  bb9924cc_8308_a1f9_0e30_76de45a64970["segment.ts"]
  c30c28f2_b6df_e90d_67d1_db074bef35a5 --> bb9924cc_8308_a1f9_0e30_76de45a64970
  c58cbb33_f3cc_0b4f_844a_15bf66a1dc61["segment"]
  c30c28f2_b6df_e90d_67d1_db074bef35a5 --> c58cbb33_f3cc_0b4f_844a_15bf66a1dc61
  bc267e18_3e03_cc17_3da0_cbc39f148f44["stylesheet.ts"]
  c30c28f2_b6df_e90d_67d1_db074bef35a5 --> bc267e18_3e03_cc17_3da0_cbc39f148f44
  b9897393_3e36_7806_d172_b9debcd215f6["Stylesheet"]
  c30c28f2_b6df_e90d_67d1_db074bef35a5 --> b9897393_3e36_7806_d172_b9debcd215f6
  2329d36e_5aa2_4fa5_cf9f_a9c6cc4e1277["renderer.ts"]
  c30c28f2_b6df_e90d_67d1_db074bef35a5 --> 2329d36e_5aa2_4fa5_cf9f_a9c6cc4e1277
  6c5b3bb2_4069_e0af_8887_216e1c995446["error"]
  c30c28f2_b6df_e90d_67d1_db074bef35a5 --> 6c5b3bb2_4069_e0af_8887_216e1c995446
  d3ccc5ce_e370_63df_a97d_a2f004fd83ca["highlight"]
  c30c28f2_b6df_e90d_67d1_db074bef35a5 --> d3ccc5ce_e370_63df_a97d_a2f004fd83ca
  1c806fef_a933_285c_65d9_c10998b12c7d["relative"]
  c30c28f2_b6df_e90d_67d1_db074bef35a5 --> 1c806fef_a933_285c_65d9_c10998b12c7d
  39d349ef_5aba_74f4_ed62_f866ab2288c7["resolve.ts"]
  c30c28f2_b6df_e90d_67d1_db074bef35a5 --> 39d349ef_5aba_74f4_ed62_f866ab2288c7
  8d04f499_5623_03cc_19ff_b22a41168fc3["resolveCssId"]
  c30c28f2_b6df_e90d_67d1_db074bef35a5 --> 8d04f499_5623_03cc_19ff_b22a41168fc3
  d150911d_e127_9567_841f_492426ace93c["globby"]
  c30c28f2_b6df_e90d_67d1_db074bef35a5 --> d150911d_e127_9567_841f_492426ace93c
  89aef3dd_1eed_c141_d425_b8949215a653["node:path"]
  c30c28f2_b6df_e90d_67d1_db074bef35a5 --> 89aef3dd_1eed_c141_d425_b8949215a653
  style c30c28f2_b6df_e90d_67d1_db074bef35a5 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 CommandLineInterface 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: CommandLineInterface, 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