Skip to content

Commit

Permalink
(9/n) shadcn: add warning for deprecated components (#6576)
Browse files Browse the repository at this point in the history
* feat(shadcn): add deprecated components warning

* chore: changeset
  • Loading branch information
shadcn authored Feb 5, 2025
1 parent 1e357cb commit 9f4d65f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/slow-tools-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"shadcn": minor
---

add warning for deprecated components
36 changes: 35 additions & 1 deletion packages/shadcn/src/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 9f4d65f

Please sign in to comment.