migrateIconsFile() — ui Function Reference
Architecture documentation for the migrateIconsFile() function in migrate-icons.ts from the ui codebase.
Entity Profile
Dependency Diagram
graph TD e61ab54c_2257_1948_6d37_baaeb3351aac["migrateIconsFile()"] c417f44a_fbc3_0d59_2fa7_12379c8ead9a["migrate-icons.ts"] e61ab54c_2257_1948_6d37_baaeb3351aac -->|defined in| c417f44a_fbc3_0d59_2fa7_12379c8ead9a e664e002_0388_4db6_2b3e_9fed9a1b3640["migrateIcons()"] e664e002_0388_4db6_2b3e_9fed9a1b3640 -->|calls| e61ab54c_2257_1948_6d37_baaeb3351aac style e61ab54c_2257_1948_6d37_baaeb3351aac fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/shadcn/src/migrations/migrate-icons.ts lines 133–205
export async function migrateIconsFile(
content: string,
sourceLibrary: keyof typeof LEGACY_ICON_LIBRARIES,
targetLibrary: keyof typeof LEGACY_ICON_LIBRARIES,
iconsMapping: z.infer<typeof iconsSchema>
) {
const sourceLibraryImport = LEGACY_ICON_LIBRARIES[sourceLibrary]?.import
const targetLibraryImport = LEGACY_ICON_LIBRARIES[targetLibrary]?.import
const dir = await fs.mkdtemp(path.join(tmpdir(), "shadcn-"))
const project = new Project({
compilerOptions: {},
})
const tempFile = path.join(
dir,
`shadcn-icons-${randomBytes(4).toString("hex")}.tsx`
)
const sourceFile = project.createSourceFile(tempFile, content, {
scriptKind: ScriptKind.TSX,
})
// Find all sourceLibrary imports.
let targetedIcons: string[] = []
for (const importDeclaration of sourceFile.getImportDeclarations() ?? []) {
if (
importDeclaration.getModuleSpecifier()?.getText() !==
`"${sourceLibraryImport}"`
) {
continue
}
for (const specifier of importDeclaration.getNamedImports() ?? []) {
const iconName = specifier.getName()
// TODO: this is O(n^2) but okay for now.
const targetedIcon = Object.values(iconsMapping).find(
(icon) => icon[sourceLibrary] === iconName
)?.[targetLibrary]
if (!targetedIcon || targetedIcons.includes(targetedIcon)) {
continue
}
targetedIcons.push(targetedIcon)
// Remove the named import.
specifier.remove()
// Replace with the targeted icon.
sourceFile
.getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement)
.filter((node) => node.getTagNameNode()?.getText() === iconName)
.forEach((node) => node.getTagNameNode()?.replaceWithText(targetedIcon))
}
// If the named import is empty, remove the import declaration.
if (importDeclaration.getNamedImports()?.length === 0) {
importDeclaration.remove()
}
}
if (targetedIcons.length > 0) {
sourceFile.addImportDeclaration({
moduleSpecifier: targetLibraryImport,
namedImports: targetedIcons.map((icon) => ({
name: icon,
})),
})
}
return await sourceFile.getText()
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does migrateIconsFile() do?
migrateIconsFile() is a function in the ui codebase, defined in packages/shadcn/src/migrations/migrate-icons.ts.
Where is migrateIconsFile() defined?
migrateIconsFile() is defined in packages/shadcn/src/migrations/migrate-icons.ts at line 133.
What calls migrateIconsFile()?
migrateIconsFile() is called by 1 function(s): migrateIcons.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free