resolveModuleByProbablePath() — ui Function Reference
Architecture documentation for the resolveModuleByProbablePath() function in update-files.ts from the ui codebase.
Entity Profile
Dependency Diagram
graph TD 5ca9d691_c347_aaf4_a263_a11c048b0d37["resolveModuleByProbablePath()"] 3efb2c23_7931_d244_b4e1_85acab69298c["update-files.ts"] 5ca9d691_c347_aaf4_a263_a11c048b0d37 -->|defined in| 3efb2c23_7931_d244_b4e1_85acab69298c 7dc382f5_944d_c67e_f395_05edc855da6a["resolveImports()"] 7dc382f5_944d_c67e_f395_05edc855da6a -->|calls| 5ca9d691_c347_aaf4_a263_a11c048b0d37 style 5ca9d691_c347_aaf4_a263_a11c048b0d37 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/shadcn/src/utils/updaters/update-files.ts lines 612–682
export function resolveModuleByProbablePath(
probableImportFilePath: string,
files: string[],
config: Config,
extensions: string[] = [".tsx", ".ts", ".js", ".jsx", ".css"]
) {
const cwd = path.normalize(config.resolvedPaths.cwd)
// 1) Build a set of POSIX-normalized, project-relative files
const relativeFiles = files.map((f) => f.split(path.sep).join(path.posix.sep))
const fileSet = new Set(relativeFiles)
// 2) Strip any existing extension off the absolute base path
const extInPath = path.extname(probableImportFilePath)
const hasExt = extInPath !== ""
const absBase = hasExt
? probableImportFilePath.slice(0, -extInPath.length)
: probableImportFilePath
// 3) Compute the project-relative "base" directory for strong matching
const relBaseRaw = path.relative(cwd, absBase)
const relBase = relBaseRaw.split(path.sep).join(path.posix.sep)
// 4) Decide which extensions to try
const tryExts = hasExt ? [extInPath] : extensions
// 5) Collect candidates
const candidates = new Set<string>()
// 5a) Fast‑path: [base + ext] and [base/index + ext]
for (const e of tryExts) {
const absCand = absBase + e
const relCand = path.posix.normalize(path.relative(cwd, absCand))
if (fileSet.has(relCand) || existsSync(absCand)) {
candidates.add(relCand)
}
const absIdx = path.join(absBase, `index${e}`)
const relIdx = path.posix.normalize(path.relative(cwd, absIdx))
if (fileSet.has(relIdx) || existsSync(absIdx)) {
candidates.add(relIdx)
}
}
// 5b) Fallback: scan known files by basename
const name = path.basename(absBase)
for (const f of relativeFiles) {
if (tryExts.some((e) => f.endsWith(`/${name}${e}`))) {
candidates.add(f)
}
}
// 6) If no matches, bail
if (candidates.size === 0) return null
// 7) Sort by (1) extension priority, then (2) "strong" base match
const sorted = Array.from(candidates).sort((a, b) => {
// a) extension order
const aExt = path.posix.extname(a)
const bExt = path.posix.extname(b)
const ord = tryExts.indexOf(aExt) - tryExts.indexOf(bExt)
if (ord !== 0) return ord
// b) strong match if path starts with relBase
const aStrong = relBase && a.startsWith(relBase) ? -1 : 1
const bStrong = relBase && b.startsWith(relBase) ? -1 : 1
return aStrong - bStrong
})
// 8) Return the first (best) candidate
return sorted[0]
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does resolveModuleByProbablePath() do?
resolveModuleByProbablePath() is a function in the ui codebase, defined in packages/shadcn/src/utils/updaters/update-files.ts.
Where is resolveModuleByProbablePath() defined?
resolveModuleByProbablePath() is defined in packages/shadcn/src/utils/updaters/update-files.ts at line 612.
What calls resolveModuleByProbablePath()?
resolveModuleByProbablePath() is called by 1 function(s): resolveImports.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free