mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-07-07 14:08:47 +00:00
feat(shadcn): add deprecated components warning
This commit is contained in:
@@ -14,6 +14,21 @@ import { Command } from "commander"
|
|||||||
import prompts from "prompts"
|
import prompts from "prompts"
|
||||||
import { z } from "zod"
|
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({
|
export const addOptionsSchema = z.object({
|
||||||
components: z.array(z.string()).optional(),
|
components: z.array(z.string()).optional(),
|
||||||
yes: z.boolean(),
|
yes: z.boolean(),
|
||||||
@@ -81,6 +96,19 @@ export const add = new Command()
|
|||||||
options.components = await promptForRegistryComponents(options)
|
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)
|
let { errors, config } = await preFlightAdd(options)
|
||||||
|
|
||||||
// No components.json file. Prompt the user to run init.
|
// 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.",
|
hint: "Space to select. A to toggle all. Enter to submit.",
|
||||||
instructions: false,
|
instructions: false,
|
||||||
choices: registryIndex
|
choices: registryIndex
|
||||||
.filter((entry) => entry.type === "registry:ui")
|
.filter(
|
||||||
|
(entry) =>
|
||||||
|
entry.type === "registry:ui" &&
|
||||||
|
!DEPRECATED_COMPONENTS.some(
|
||||||
|
(component) => component.name === entry.name
|
||||||
|
)
|
||||||
|
)
|
||||||
.map((entry) => ({
|
.map((entry) => ({
|
||||||
title: entry.name,
|
title: entry.name,
|
||||||
value: entry.name,
|
value: entry.name,
|
||||||
|
|||||||
Reference in New Issue
Block a user