feat(shadcn): add deprecated components warning

This commit is contained in:
shadcn
2025-02-05 22:03:47 +04:00
parent 1940798555
commit 00a10e0404

View File

@@ -14,6 +14,21 @@ import { Command } from "commander"
import prompts from "prompts"
import { z } from "zod"
const DEPRECATED_COMPONENTS = [
{
name: "toast",
deprecatedBy: "sonner",
message:
"The toast component is deprecated. Use the sonner component instead.",
},
{
name: "toaster",
deprecatedBy: "sonner",
message:
"The toaster component is deprecated. Use the sonner component instead.",
},
]
export const addOptionsSchema = z.object({
components: z.array(z.string()).optional(),
yes: z.boolean(),
@@ -81,6 +96,19 @@ export const add = new Command()
options.components = await promptForRegistryComponents(options)
}
const deprecatedComponents = DEPRECATED_COMPONENTS.filter((component) =>
options.components?.includes(component.name)
)
if (deprecatedComponents?.length) {
logger.break()
deprecatedComponents.forEach((component) => {
logger.warn(highlighter.warn(component.message))
})
logger.break()
process.exit(1)
}
let { errors, config } = await preFlightAdd(options)
// No components.json file. Prompt the user to run init.
@@ -190,7 +218,13 @@ async function promptForRegistryComponents(
hint: "Space to select. A to toggle all. Enter to submit.",
instructions: false,
choices: registryIndex
.filter((entry) => entry.type === "registry:ui")
.filter(
(entry) =>
entry.type === "registry:ui" &&
!DEPRECATED_COMPONENTS.some(
(component) => component.name === entry.name
)
)
.map((entry) => ({
title: entry.name,
value: entry.name,