From 00a10e040468de95a0d2b40147bc51ca3de3053c Mon Sep 17 00:00:00 2001 From: shadcn Date: Wed, 5 Feb 2025 22:03:47 +0400 Subject: [PATCH] feat(shadcn): add deprecated components warning --- packages/shadcn/src/commands/add.ts | 36 ++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/packages/shadcn/src/commands/add.ts b/packages/shadcn/src/commands/add.ts index 2a98071436..0e46dc63ff 100644 --- a/packages/shadcn/src/commands/add.ts +++ b/packages/shadcn/src/commands/add.ts @@ -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,