Skip to content

Commit

Permalink
feat(shadcn): remove react-19 check
Browse files Browse the repository at this point in the history
  • Loading branch information
shadcn committed Nov 3, 2024
1 parent ba9b7a4 commit 4fe7b21
Showing 1 changed file with 1 addition and 44 deletions.
45 changes: 1 addition & 44 deletions packages/shadcn/src/utils/updaters/update-dependencies.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { Config } from "@/src/utils/get-config"
import { getPackageInfo } from "@/src/utils/get-package-info"
import { getPackageManager } from "@/src/utils/get-package-manager"
import { logger } from "@/src/utils/logger"
import { RegistryItem } from "@/src/utils/registry/schema"
import { spinner } from "@/src/utils/spinner"
import { execa } from "execa"
import prompts from "prompts"

export async function updateDependencies(
dependencies: RegistryItem["dependencies"],
Expand All @@ -29,52 +26,12 @@ export async function updateDependencies(
})?.start()
const packageManager = await getPackageManager(config.resolvedPaths.cwd)

// Offer to use --force or --legacy-peer-deps if using React 19 with npm.
let flag = ""
if (isUsingReact19(config) && packageManager === "npm") {
dependenciesSpinner.stopAndPersist()
logger.warn(
"\nIt looks like you are using React 19. \nSome packages may fail to install due to peer dependency issues (see https://ui.shadcn.com/react-19).\n"
)
const confirmation = await prompts([
{
type: "select",
name: "flag",
message: "How would you like to proceed?",
choices: [
{ title: "Use --force", value: "force" },
{ title: "Use --legacy-peer-deps", value: "legacy-peer-deps" },
],
},
])

if (confirmation) {
flag = confirmation.flag
}
}

dependenciesSpinner?.start()

await execa(
packageManager,
[
packageManager === "npm" ? "install" : "add",
...(packageManager === "npm" && flag ? [`--${flag}`] : []),
...dependencies,
],
[packageManager === "npm" ? "install" : "add", ...dependencies],
{
cwd: config.resolvedPaths.cwd,
}
)
dependenciesSpinner?.succeed()
}

function isUsingReact19(config: Config) {
const packageInfo = getPackageInfo(config.resolvedPaths.cwd)

if (!packageInfo?.dependencies?.react) {
return false
}

return /^(?:\^|~)?19(?:\.\d+)*(?:-.*)?$/.test(packageInfo.dependencies.react)
}

0 comments on commit 4fe7b21

Please sign in to comment.