Home / File/ index.ts — ui Source File

index.ts — ui Source File

Architecture documentation for index.ts, a typescript file in the ui codebase. 18 imports, 7 dependents.

File typescript FrameworkTooling CLICore 18 imports 7 dependents 3 functions

Entity Profile

Dependency Diagram

graph LR
  646bd874_990a_e30f_0d03_073229dd52ad["index.ts"]
  e5d28271_9de7_c6c9_1240_13894663e9ec["transform-cleanup.ts"]
  646bd874_990a_e30f_0d03_073229dd52ad --> e5d28271_9de7_c6c9_1240_13894663e9ec
  514a1a89_b3a4_2880_543f_72365527ea8c["transformCleanup"]
  646bd874_990a_e30f_0d03_073229dd52ad --> 514a1a89_b3a4_2880_543f_72365527ea8c
  800d6a7b_126c_42b5_bf8e_f313b0852251["transform-rtl.ts"]
  646bd874_990a_e30f_0d03_073229dd52ad --> 800d6a7b_126c_42b5_bf8e_f313b0852251
  0f7c4c2a_9a83_527f_4a25_a54cc1e6c65d["transformRtl"]
  646bd874_990a_e30f_0d03_073229dd52ad --> 0f7c4c2a_9a83_527f_4a25_a54cc1e6c65d
  7edb575e_bbe2_1d90_7009_48ce3cf289ac["transform-tw-prefix.ts"]
  646bd874_990a_e30f_0d03_073229dd52ad --> 7edb575e_bbe2_1d90_7009_48ce3cf289ac
  6c4f61dd_79b1_2539_0578_e04b4256898d["transformTwPrefixes"]
  646bd874_990a_e30f_0d03_073229dd52ad --> 6c4f61dd_79b1_2539_0578_e04b4256898d
  eac8f98f_e40a_7fe8_f505_372c83d20c7a["fs"]
  646bd874_990a_e30f_0d03_073229dd52ad --> eac8f98f_e40a_7fe8_f505_372c83d20c7a
  b80715bf_43eb_b495_f2cf_a439c5eb0e34["os"]
  646bd874_990a_e30f_0d03_073229dd52ad --> b80715bf_43eb_b495_f2cf_a439c5eb0e34
  d05ec4ea_7a68_3a36_bfa4_9ba7f8409ee5["path"]
  646bd874_990a_e30f_0d03_073229dd52ad --> d05ec4ea_7a68_3a36_bfa4_9ba7f8409ee5
  a3b2545e_3d8c_699d_ef11_6ab18db14666["schema"]
  646bd874_990a_e30f_0d03_073229dd52ad --> a3b2545e_3d8c_699d_ef11_6ab18db14666
  b2895591_2a74_d518_deda_2f26be766dcb["get-config"]
  646bd874_990a_e30f_0d03_073229dd52ad --> b2895591_2a74_d518_deda_2f26be766dcb
  2c7ad61c_09d0_10d5_b87b_bfd34be3e9e7["transform-css-vars"]
  646bd874_990a_e30f_0d03_073229dd52ad --> 2c7ad61c_09d0_10d5_b87b_bfd34be3e9e7
  1ac49d1e_43d9_20be_5a7a_5ab3f3cac911["transform-icons"]
  646bd874_990a_e30f_0d03_073229dd52ad --> 1ac49d1e_43d9_20be_5a7a_5ab3f3cac911
  aaaa298e_8af2_05b0_e7ab_10832ff3542d["transform-import"]
  646bd874_990a_e30f_0d03_073229dd52ad --> aaaa298e_8af2_05b0_e7ab_10832ff3542d
  style 646bd874_990a_e30f_0d03_073229dd52ad fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { promises as fs } from "fs"
import { tmpdir } from "os"
import path from "path"
import { registryBaseColorSchema } from "@/src/schema"
import { Config } from "@/src/utils/get-config"
import { transformCssVars } from "@/src/utils/transformers/transform-css-vars"
import { transformIcons } from "@/src/utils/transformers/transform-icons"
import { transformImport } from "@/src/utils/transformers/transform-import"
import { transformJsx } from "@/src/utils/transformers/transform-jsx"
import { transformRsc } from "@/src/utils/transformers/transform-rsc"
import { Project, ScriptKind, type SourceFile } from "ts-morph"
import { z } from "zod"

import { transformCleanup } from "./transform-cleanup"
import { transformRtl } from "./transform-rtl"
import { transformTwPrefixes } from "./transform-tw-prefix"

export type TransformOpts = {
  filename: string
  raw: string
  config: Config
  baseColor?: z.infer<typeof registryBaseColorSchema>
  transformJsx?: boolean
  isRemote?: boolean
}

export type Transformer<Output = SourceFile> = (
  opts: TransformOpts & {
    sourceFile: SourceFile
  }
) => Promise<Output>

const project = new Project({
  compilerOptions: {},
})

async function createTempSourceFile(filename: string) {
  const dir = await fs.mkdtemp(path.join(tmpdir(), "shadcn-"))
  return path.join(dir, filename)
}

export async function transform(
  opts: TransformOpts,
  transformers: Transformer[] = [
    transformImport,
    transformRsc,
    transformCssVars,
    transformTwPrefixes,
    transformRtl,
    transformIcons,
    transformCleanup,
  ]
) {
  const tempFile = await createTempSourceFile(opts.filename)
  const sourceFile = project.createSourceFile(tempFile, opts.raw, {
    scriptKind: ScriptKind.TSX,
  })

  for (const transformer of transformers) {
    await transformer({ sourceFile, ...opts })
  }

  if (opts.transformJsx) {
    return await transformJsx({
      sourceFile,
      ...opts,
    })
  }

  return sourceFile.getText()
}

Subdomains

Dependencies

Frequently Asked Questions

What does index.ts do?
index.ts is a source file in the ui codebase, written in typescript. It belongs to the FrameworkTooling domain, CLICore subdomain.
What functions are defined in index.ts?
index.ts defines 3 function(s): createTempSourceFile, opts, transform.
What does index.ts depend on?
index.ts imports 18 module(s): fs, get-config, os, path, schema, transform-cleanup.ts, transform-css-vars, transform-icons, and 10 more.
What files import index.ts?
index.ts is imported by 7 file(s): transform-css-vars.test.ts, transform-import.test.ts, transform-legacy-icons.test.ts, transform-next.test.ts, transform-rsc.test.ts, transform-rtl.test.ts, transform-tw-prefix.test.ts.
Where is index.ts in the architecture?
index.ts is located at packages/shadcn/src/utils/transformers/index.ts (domain: FrameworkTooling, subdomain: CLICore, directory: packages/shadcn/src/utils/transformers).

Analyze Your Own Codebase

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

Try Supermodel Free