Skip to content

Commit c8fda09

Browse files
authored
feat(cli): detect and use next version (#6093)
* feat: detect and use next version * chore: changeset
1 parent 1ff01b1 commit c8fda09

File tree

8 files changed

+44
-7
lines changed

8 files changed

+44
-7
lines changed

.changeset/three-hornets-wash.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"shadcn": patch
3+
---
4+
5+
detect and use next version

apps/www/public/r/styles/default/chart.json

+1-1
Large diffs are not rendered by default.

apps/www/public/r/styles/new-york/chart.json

+1-1
Large diffs are not rendered by default.

apps/www/registry/default/ui/chart.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ ChartContainer.displayName = "Chart"
6969

7070
const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
7171
const colorConfig = Object.entries(config).filter(
72-
([_, config]) => config.theme || config.color
72+
([, config]) => config.theme || config.color
7373
)
7474

7575
if (!colorConfig.length) {

apps/www/registry/new-york/ui/chart.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ ChartContainer.displayName = "Chart"
6969

7070
const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
7171
const colorConfig = Object.entries(config).filter(
72-
([_, config]) => config.theme || config.color
72+
([, config]) => config.theme || config.color
7373
)
7474

7575
if (!colorConfig.length) {

packages/shadcn/src/commands/add.ts

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export const add = new Command()
116116
cwd: options.cwd,
117117
force: options.overwrite,
118118
srcDir: options.srcDir,
119+
components: options.components,
119120
})
120121
if (!projectPath) {
121122
logger.break()

packages/shadcn/src/utils/create-project.ts

+33-2
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,49 @@
11
import path from "path"
22
import { initOptionsSchema } from "@/src/commands/init"
33
import { getPackageManager } from "@/src/utils/get-package-manager"
4+
import { handleError } from "@/src/utils/handle-error"
45
import { highlighter } from "@/src/utils/highlighter"
56
import { logger } from "@/src/utils/logger"
7+
import { fetchRegistry } from "@/src/utils/registry"
68
import { spinner } from "@/src/utils/spinner"
79
import { execa } from "execa"
810
import fs from "fs-extra"
911
import prompts from "prompts"
1012
import { z } from "zod"
1113

1214
export async function createProject(
13-
options: Pick<z.infer<typeof initOptionsSchema>, "cwd" | "force" | "srcDir">
15+
options: Pick<
16+
z.infer<typeof initOptionsSchema>,
17+
"cwd" | "force" | "srcDir" | "components"
18+
>
1419
) {
1520
options = {
1621
srcDir: false,
1722
...options,
1823
}
1924

25+
let nextVersion = "14.2.16"
26+
27+
const isRemoteComponent =
28+
options.components?.length === 1 &&
29+
!!options.components[0].match(/\/chat\/b\//)
30+
if (options.components && isRemoteComponent) {
31+
try {
32+
const [result] = await fetchRegistry(options.components)
33+
const { meta } = z
34+
.object({
35+
meta: z.object({
36+
nextVersion: z.string(),
37+
}),
38+
})
39+
.parse(result)
40+
nextVersion = meta.nextVersion
41+
} catch (error) {
42+
logger.break()
43+
handleError(error)
44+
}
45+
}
46+
2047
if (!options.force) {
2148
const { proceed } = await prompts({
2249
type: "confirm",
@@ -93,10 +120,14 @@ export async function createProject(
93120
`--use-${packageManager}`,
94121
]
95122

123+
if (nextVersion.startsWith("15")) {
124+
args.push("--turbopack")
125+
}
126+
96127
try {
97128
await execa(
98129
"npx",
99-
["create-next-app@14.2.16", projectPath, "--silent", ...args],
130+
[`create-next-app@${nextVersion}`, projectPath, "--silent", ...args],
100131
{
101132
cwd: options.cwd,
102133
}

packages/shadcn/src/utils/registry/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ export async function getItemTargetPath(
170170
)
171171
}
172172

173-
async function fetchRegistry(paths: string[]) {
173+
export async function fetchRegistry(paths: string[]) {
174174
try {
175175
const results = await Promise.all(
176176
paths.map(async (path) => {

0 commit comments

Comments
 (0)