Home / File/ renderer.ts — tailwindcss Source File

renderer.ts — tailwindcss Source File

Architecture documentation for renderer.ts, a typescript file in the tailwindcss codebase. 8 imports, 2 dependents.

File typescript CommandLineInterface Renderer 8 imports 2 dependents 9 functions

Entity Profile

Dependency Diagram

graph LR
  cc1a3f06_4b21_684c_487a_f342bd18d772["renderer.ts"]
  d2f15571_c3bc_bfbb_165e_18eba9d341ba["resolve.ts"]
  cc1a3f06_4b21_684c_487a_f342bd18d772 --> d2f15571_c3bc_bfbb_165e_18eba9d341ba
  979748f4_859b_1f86_264d_addfd15b3c5b["resolve"]
  cc1a3f06_4b21_684c_487a_f342bd18d772 --> 979748f4_859b_1f86_264d_addfd15b3c5b
  668a6c78_97ae_1a3a_8906_d42fe854fff0["format-ns.ts"]
  cc1a3f06_4b21_684c_487a_f342bd18d772 --> 668a6c78_97ae_1a3a_8906_d42fe854fff0
  8f39fcf0_a336_611c_df3e_e1ab37efa73a["formatNanoseconds"]
  cc1a3f06_4b21_684c_487a_f342bd18d772 --> 8f39fcf0_a336_611c_df3e_e1ab37efa73a
  9c72d32d_a535_69d4_565b_b620ce2eaae1["node:fs"]
  cc1a3f06_4b21_684c_487a_f342bd18d772 --> 9c72d32d_a535_69d4_565b_b620ce2eaae1
  89aef3dd_1eed_c141_d425_b8949215a653["node:path"]
  cc1a3f06_4b21_684c_487a_f342bd18d772 --> 89aef3dd_1eed_c141_d425_b8949215a653
  f909665b_1fad_0830_f03c_620b7c9464c3["node:util"]
  cc1a3f06_4b21_684c_487a_f342bd18d772 --> f909665b_1fad_0830_f03c_620b7c9464c3
  5e3a9e1b_c7c3_9356_dd16_9834c49660ab["picocolors"]
  cc1a3f06_4b21_684c_487a_f342bd18d772 --> 5e3a9e1b_c7c3_9356_dd16_9834c49660ab
  dedd6830_c180_a2b0_01d1_b5874e938eb8["index.ts"]
  dedd6830_c180_a2b0_01d1_b5874e938eb8 --> cc1a3f06_4b21_684c_487a_f342bd18d772
  7dcd775d_cdd7_c609_2b1c_d31c561874d0["renderer.test.ts"]
  7dcd775d_cdd7_c609_2b1c_d31c561874d0 --> cc1a3f06_4b21_684c_487a_f342bd18d772
  style cc1a3f06_4b21_684c_487a_f342bd18d772 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import fs from 'node:fs'
import path from 'node:path'
import { stripVTControlCharacters } from 'node:util'
import pc from 'picocolors'
import { resolve } from '../utils/resolve'
import { formatNanoseconds } from './format-ns'

export const UI = {
  indent: 2,
}
export function header() {
  return `${pc.italic(pc.bold(pc.blue('\u2248')))} tailwindcss ${pc.blue(`v${getVersion()}`)}`
}

export function highlight(file: string) {
  return `${pc.dim(pc.blue('`'))}${pc.blue(file)}${pc.dim(pc.blue('`'))}`
}

/**
 * Convert an `absolute` path to a `relative` path from the current working
 * directory.
 */
export function relative(
  to: string,
  from = process.cwd(),
  { preferAbsoluteIfShorter = true } = {},
) {
  let result = path.relative(from, to)
  if (!result.startsWith('..')) {
    result = `.${path.sep}${result}`
  }

  if (preferAbsoluteIfShorter && result.length > to.length) {
    return to
  }

  return result
}

/**
 * Wrap `text` into multiple lines based on the `width`.
 */
export function wordWrap(text: string, width: number) {
  let words = text.split(' ')
  let lines = []

  let line = ''
  let lineLength = 0
  for (let word of words) {
    let wordLength = stripVTControlCharacters(word).length

    if (lineLength + wordLength + 1 > width) {
      lines.push(line)
      line = ''
      lineLength = 0
    }

    line += (lineLength ? ' ' : '') + word
    lineLength += wordLength + (lineLength ? 1 : 0)
  }

  if (lineLength) {
    lines.push(line)
  }

  return lines
}

/**
 * Format a duration in nanoseconds to a more human readable format.
 */
export function formatDuration(ns: bigint) {
  let formatted = formatNanoseconds(ns)

  if (ns <= 50 * 1e6) return pc.green(formatted)
  if (ns <= 300 * 1e6) return pc.blue(formatted)
  if (ns <= 1000 * 1e6) return pc.yellow(formatted)

  return pc.red(formatted)
}

export function indent(value: string, offset = 0) {
  return `${' '.repeat(offset + UI.indent)}${value}`
}

// Rust inspired functions to print to the console:

export function eprintln(value = '') {
  process.stderr.write(`${value}\n`)
}

export function println(value = '') {
  process.stdout.write(`${value}\n`)
}

function getVersion(): string {
  if (typeof globalThis.__tw_version === 'string') {
    return globalThis.__tw_version
  }
  let { version } = JSON.parse(fs.readFileSync(resolve('tailwindcss/package.json'), 'utf-8'))
  return version
}

Subdomains

Dependencies

Frequently Asked Questions

What does renderer.ts do?
renderer.ts is a source file in the tailwindcss codebase, written in typescript. It belongs to the CommandLineInterface domain, Renderer subdomain.
What functions are defined in renderer.ts?
renderer.ts defines 9 function(s): eprintln, formatDuration, getVersion, header, highlight, indent, println, relative, wordWrap.
What does renderer.ts depend on?
renderer.ts imports 8 module(s): format-ns.ts, formatNanoseconds, node:fs, node:path, node:util, picocolors, resolve, resolve.ts.
What files import renderer.ts?
renderer.ts is imported by 2 file(s): index.ts, renderer.test.ts.
Where is renderer.ts in the architecture?
renderer.ts is located at packages/@tailwindcss-cli/src/utils/renderer.ts (domain: CommandLineInterface, subdomain: Renderer, directory: packages/@tailwindcss-cli/src/utils).

Analyze Your Own Codebase

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

Try Supermodel Free