helpers.ts — ui Source File
Architecture documentation for helpers.ts, a typescript file in the ui codebase. 6 imports, 5 dependents.
Entity Profile
Dependency Diagram
graph LR d74412ab_0ee4_22df_d4c9_26e6c03c4a41["helpers.ts"] 0eb62fa0_3267_b3a7_0648_00ed9416e5c9["setup.ts"] d74412ab_0ee4_22df_d4c9_26e6c03c4a41 --> 0eb62fa0_3267_b3a7_0648_00ed9416e5c9 8eb629f2_502c_b1a4_6fec_b6329f097fbe["crypto"] d74412ab_0ee4_22df_d4c9_26e6c03c4a41 --> 8eb629f2_502c_b1a4_6fec_b6329f097fbe d05ec4ea_7a68_3a36_bfa4_9ba7f8409ee5["path"] d74412ab_0ee4_22df_d4c9_26e6c03c4a41 --> d05ec4ea_7a68_3a36_bfa4_9ba7f8409ee5 953f2b9f_f885_0acb_aad8_58f1a4e32589["url"] d74412ab_0ee4_22df_d4c9_26e6c03c4a41 --> 953f2b9f_f885_0acb_aad8_58f1a4e32589 8fa2a696_bed4_6bec_383f_7df160ded516["execa"] d74412ab_0ee4_22df_d4c9_26e6c03c4a41 --> 8fa2a696_bed4_6bec_383f_7df160ded516 f9f5e551_eb59_1a6b_8bf2_b97e73eb13de["fs-extra"] d74412ab_0ee4_22df_d4c9_26e6c03c4a41 --> f9f5e551_eb59_1a6b_8bf2_b97e73eb13de a4dc2ccb_53f0_1bd7_2946_bd83b4086231["add.test.ts"] a4dc2ccb_53f0_1bd7_2946_bd83b4086231 --> d74412ab_0ee4_22df_d4c9_26e6c03c4a41 850315ae_10e7_b3da_fe0a_07bc60ae8665["init.test.ts"] 850315ae_10e7_b3da_fe0a_07bc60ae8665 --> d74412ab_0ee4_22df_d4c9_26e6c03c4a41 53b3a078_76ff_e9b8_1c06_58b2c68c2132["registries.test.ts"] 53b3a078_76ff_e9b8_1c06_58b2c68c2132 --> d74412ab_0ee4_22df_d4c9_26e6c03c4a41 5aae16d8_dc31_7b01_2a8a_3a28b78e877b["search.test.ts"] 5aae16d8_dc31_7b01_2a8a_3a28b78e877b --> d74412ab_0ee4_22df_d4c9_26e6c03c4a41 1867f1db_8fe1_137d_8738_ad32a6243fdc["view.test.ts"] 1867f1db_8fe1_137d_8738_ad32a6243fdc --> d74412ab_0ee4_22df_d4c9_26e6c03c4a41 style d74412ab_0ee4_22df_d4c9_26e6c03c4a41 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import { randomUUID } from "crypto"
import path from "path"
import { fileURLToPath } from "url"
import { execa } from "execa"
import fs from "fs-extra"
import { TEMP_DIR } from "./setup"
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const FIXTURES_DIR = path.join(__dirname, "../../fixtures")
const SHADCN_CLI_PATH = path.join(__dirname, "../../../shadcn/dist/index.js")
export function getRegistryUrl() {
return process.env.REGISTRY_URL || "http://localhost:4000/r"
}
export async function createFixtureTestDirectory(fixtureName: string) {
const fixturePath = path.join(FIXTURES_DIR, fixtureName)
const uniqueId = `${process.pid}-${randomUUID().substring(0, 8)}`
let testDir = path.join(TEMP_DIR, `test-${uniqueId}-${fixtureName}`)
await fs.ensureDir(testDir)
await fs.copy(fixturePath, testDir)
return testDir
}
export async function runCommand(
cwd: string,
args: string[],
options?: {
env?: Record<string, string>
input?: string
}
) {
try {
const childProcess = execa("node", [SHADCN_CLI_PATH, ...args], {
cwd,
env: {
...process.env,
FORCE_COLOR: "0",
CI: "true",
...options?.env,
},
input: options?.input,
reject: false,
timeout: 30000,
})
const result = await childProcess
return {
stdout: result.stdout || "",
stderr: result.stderr || "",
exitCode: result.exitCode ?? 0,
}
} catch (error: any) {
return {
stdout: error.stdout || "",
stderr: error.stderr || error.message || "",
exitCode: error.exitCode ?? 1,
}
}
}
export async function npxShadcn(
cwd: string,
args: string[],
{
debug = false,
}: {
debug?: boolean
} = {}
) {
const result = await runCommand(cwd, args, {
env: {
REGISTRY_URL: getRegistryUrl(),
},
})
if (debug) {
console.log(result)
}
return result
}
export function cssHasProperties(
cssContent: string,
checks: Array<{
selector: string
properties: Record<string, string>
}>
) {
return checks.every(({ selector, properties }) => {
const escapedSelector = selector.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
const regex = new RegExp(`${escapedSelector}\\s*{([^}]+)}`, "s")
const match = cssContent.match(regex)
const block = match ? match[1] : ""
return Object.entries(properties).every(([property, value]) =>
block.includes(`${property}: ${value};`)
)
})
}
Domain
Subdomains
Dependencies
- crypto
- execa
- fs-extra
- path
- setup.ts
- url
Imported By
Source
Frequently Asked Questions
What does helpers.ts do?
helpers.ts is a source file in the ui codebase, written in typescript. It belongs to the ComponentRegistry domain, ChartRegistry subdomain.
What functions are defined in helpers.ts?
helpers.ts defines 5 function(s): createFixtureTestDirectory, cssHasProperties, getRegistryUrl, npxShadcn, runCommand.
What does helpers.ts depend on?
helpers.ts imports 6 module(s): crypto, execa, fs-extra, path, setup.ts, url.
What files import helpers.ts?
helpers.ts is imported by 5 file(s): add.test.ts, init.test.ts, registries.test.ts, search.test.ts, view.test.ts.
Where is helpers.ts in the architecture?
helpers.ts is located at packages/tests/src/utils/helpers.ts (domain: ComponentRegistry, subdomain: ChartRegistry, directory: packages/tests/src/utils).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free