Skip to content

Commit 9f4d65f

Browse files
authored
(9/n) shadcn: add warning for deprecated components (#6576)
* feat(shadcn): add deprecated components warning * chore: changeset
1 parent 1e357cb commit 9f4d65f

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

.changeset/slow-tools-relax.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"shadcn": minor
3+
---
4+
5+
add warning for deprecated components

packages/shadcn/src/commands/add.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ import { Command } from "commander"
1414
import prompts from "prompts"
1515
import { z } from "zod"
1616

17+
const DEPRECATED_COMPONENTS = [
18+
{
19+
name: "toast",
20+
deprecatedBy: "sonner",
21+
message:
22+
"The toast component is deprecated. Use the sonner component instead.",
23+
},
24+
{
25+
name: "toaster",
26+
deprecatedBy: "sonner",
27+
message:
28+
"The toaster component is deprecated. Use the sonner component instead.",
29+
},
30+
]
31+
1732
export const addOptionsSchema = z.object({
1833
components: z.array(z.string()).optional(),
1934
yes: z.boolean(),
@@ -81,6 +96,19 @@ export const add = new Command()
8196
options.components = await promptForRegistryComponents(options)
8297
}
8398

99+
const deprecatedComponents = DEPRECATED_COMPONENTS.filter((component) =>
100+
options.components?.includes(component.name)
101+
)
102+
103+
if (deprecatedComponents?.length) {
104+
logger.break()
105+
deprecatedComponents.forEach((component) => {
106+
logger.warn(highlighter.warn(component.message))
107+
})
108+
logger.break()
109+
process.exit(1)
110+
}
111+
84112
let { errors, config } = await preFlightAdd(options)
85113

86114
// No components.json file. Prompt the user to run init.
@@ -190,7 +218,13 @@ async function promptForRegistryComponents(
190218
hint: "Space to select. A to toggle all. Enter to submit.",
191219
instructions: false,
192220
choices: registryIndex
193-
.filter((entry) => entry.type === "registry:ui")
221+
.filter(
222+
(entry) =>
223+
entry.type === "registry:ui" &&
224+
!DEPRECATED_COMPONENTS.some(
225+
(component) => component.name === entry.name
226+
)
227+
)
194228
.map((entry) => ({
195229
title: entry.name,
196230
value: entry.name,

0 commit comments

Comments
 (0)