From 9f4d65fc8fe72f632706fafd4036f63fd9317780 Mon Sep 17 00:00:00 2001 From: shadcn Date: Wed, 5 Feb 2025 22:51:31 +0400 Subject: [PATCH] (9/n) shadcn: add warning for deprecated components (#6576) * feat(shadcn): add deprecated components warning * chore: changeset --- .changeset/slow-tools-relax.md | 5 ++++ packages/shadcn/src/commands/add.ts | 36 ++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 .changeset/slow-tools-relax.md diff --git a/.changeset/slow-tools-relax.md b/.changeset/slow-tools-relax.md new file mode 100644 index 00000000000..68f1588ab89 --- /dev/null +++ b/.changeset/slow-tools-relax.md @@ -0,0 +1,5 @@ +--- +"shadcn": minor +--- + +add warning for deprecated components diff --git a/packages/shadcn/src/commands/add.ts b/packages/shadcn/src/commands/add.ts index 2a98071436a..0e46dc63fff 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,