Home / Function/ migrateRtl() — ui Function Reference

migrateRtl() — ui Function Reference

Architecture documentation for the migrateRtl() function in migrate-rtl.ts from the ui codebase.

Entity Profile

Dependency Diagram

graph TD
  8cf8e774_79a5_beee_7743_a58046b23aa4["migrateRtl()"]
  376785b7_9619_0848_64f3_0e7ddbddb913["migrate-rtl.ts"]
  8cf8e774_79a5_beee_7743_a58046b23aa4 -->|defined in| 376785b7_9619_0848_64f3_0e7ddbddb913
  style 8cf8e774_79a5_beee_7743_a58046b23aa4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/shadcn/src/migrations/migrate-rtl.ts lines 20–159

export async function migrateRtl(
  config: Config,
  options: { yes?: boolean; path?: string } = {}
) {
  // Determine files to migrate.
  let files: string[]
  let basePath: string

  if (options.path) {
    // User provided a path/glob.
    basePath = config.resolvedPaths.cwd
    const isGlob = options.path.includes("*")

    if (isGlob) {
      files = await fg(options.path, {
        cwd: basePath,
        onlyFiles: true,
        ignore: ["**/node_modules/**"],
      })
    } else {
      const fullPath = path.resolve(basePath, options.path)
      const stat = await fs.stat(fullPath).catch(() => null)

      if (!stat) {
        throw new Error(`File not found: ${options.path}`)
      }

      if (stat.isDirectory()) {
        basePath = fullPath
        files = await fg("**/*.{js,ts,jsx,tsx}", {
          cwd: basePath,
          onlyFiles: true,
          ignore: ["**/node_modules/**"],
        })
      } else if (stat.isFile()) {
        files = [options.path]
      } else {
        throw new Error(`Unsupported path type: ${options.path}`)
      }
    }

    if (files.length === 0) {
      throw new Error(`No files found matching: ${options.path}`)
    }
  } else {
    // Default: use ui path from components.json.
    if (!config.resolvedPaths.ui) {
      throw new Error(
        "Could not find a valid `ui` path in your `components.json`. Please provide a path or glob pattern."
      )
    }

    basePath = config.resolvedPaths.ui
    files = await fg("**/*.{js,ts,jsx,tsx}", {
      cwd: basePath,
      onlyFiles: true,
    })
  }

  // Confirm with user.
  if (!options.yes) {
    const relativePath = options.path
      ? options.path
      : `./${path.relative(config.resolvedPaths.cwd, basePath)}`

    const { confirm } = await prompts({
      type: "confirm",
      name: "confirm",
      initial: true,
      message: `We will migrate ${highlighter.info(
        files.length
      )} file(s) in ${highlighter.info(relativePath)} to RTL. Continue?`,
    })

    if (!confirm) {
      logger.info("Migration cancelled.")
      process.exit(0)
    }
  }

  // Update components.json to set rtl: true.

Subdomains

Frequently Asked Questions

What does migrateRtl() do?
migrateRtl() is a function in the ui codebase, defined in packages/shadcn/src/migrations/migrate-rtl.ts.
Where is migrateRtl() defined?
migrateRtl() is defined in packages/shadcn/src/migrations/migrate-rtl.ts at line 20.

Analyze Your Own Codebase

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

Try Supermodel Free