Open ivan-plotnikov opened 2 days ago
Seeing the same issue
Same issue here
+1
Look like similar issue #5436
At least on September 3, it worked correctly https://x.com/shadcn/status/1830955101265305963?s=46
+1
even when I running init command, the utils.ts file is created on ./lib/utils.ts not ./resources/js/lib/utils.ts
+1
+1
+1
+1
+1
+1
+1
+1
+1
If I clone the repo and run the tests, some tests fails. Coincidently it is related to file paths.
On top of that the getRegistryItemFileTargetPath
function from packages/shadcn/src/utils/registry/index.ts
is not being tested at all.
This function is used on packages/shadcn/src/utils/updaters/update-files.ts
, which is used on packages/shadcn/src/utils/add-components.ts
, and finally on packages/shadcn/src/commands/add.ts
Which is exactly the command that we are experiencing issues.
First time looking at this code base and I didn't investigated in depth, but it seems relevant enough to share the findings.
+1
BRING THE OLD CLI BACKK
I think I found the issue and it's not related with my comment above.
The filePath
and targetDir
is being overwritten here on lines 74
and 75
:
On line 69
and 71
the targetDir
and filePath
respectively, are what we expect based in the aliases
on components.json
!
The file.target
on line 74
comes from the registry. For example, for the Alert component see the following url:
https://ui.shadcn.com/r/styles/default/alert.json
Response from URL above:
{
"name": "alert",
"type": "registry:ui",
"files": [
{
"path": "ui/alert.tsx",
"content": "import * as React from \"react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\n\nimport { cn } from \"@/lib/utils\"\n\nconst alertVariants = cva(\n \"relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground\",\n {\n variants: {\n variant: {\n default: \"bg-background text-foreground\",\n destructive:\n \"border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive\",\n },\n },\n defaultVariants: {\n variant: \"default\",\n },\n }\n)\n\nconst Alert = React.forwardRef<\n HTMLDivElement,\n React.HTMLAttributes<HTMLDivElement> & VariantProps<typeof alertVariants>\n>(({ className, variant, ...props }, ref) => (\n <div\n ref={ref}\n role=\"alert\"\n className={cn(alertVariants({ variant }), className)}\n {...props}\n />\n))\nAlert.displayName = \"Alert\"\n\nconst AlertTitle = React.forwardRef<\n HTMLParagraphElement,\n React.HTMLAttributes<HTMLHeadingElement>\n>(({ className, ...props }, ref) => (\n <h5\n ref={ref}\n className={cn(\"mb-1 font-medium leading-none tracking-tight\", className)}\n {...props}\n />\n))\nAlertTitle.displayName = \"AlertTitle\"\n\nconst AlertDescription = React.forwardRef<\n HTMLParagraphElement,\n React.HTMLAttributes<HTMLParagraphElement>\n>(({ className, ...props }, ref) => (\n <div\n ref={ref}\n className={cn(\"text-sm [&_p]:leading-relaxed\", className)}\n {...props}\n />\n))\nAlertDescription.displayName = \"AlertDescription\"\n\nexport { Alert, AlertTitle, AlertDescription }\n",
"type": "registry:ui",
"target": "components/ui/alert.tsx"
}
]
}
I believe that removing the following if statement would fix it, and I can confirm that it works.
However, since I don't fully understand the use case, it is hard for me to know for sure if that's the way or if it will add any other bug.
Before removing respective lines (does not respect the aliases):
After removing the respective lines (respect the aliases):
My components.json
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "default",
"rsc": true,
"tsx": true,
"tailwind": {
"config": "tailwind.config.ts",
"css": "src/styles/globals.css",
"baseColor": "neutral",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"components": "~/app/_components",
"utils": "~/lib/styles",
"ui": "~/app/_components/ui",
"lib": "~/lib",
"hooks": "~/hooks"
}
}
It would be necessary to understand the business rules for this scenario.
For example:
target
from the registry always present?targetDir
and filePath
?I could create a PR to fix this, but I need some input on the questions above. Maybe @shadcn could help clarifying some of the questions? 🙏
Same issue as well. The new CLI completely ignores the aliases.
+1
im just a dev in a sunday wanting this to work 😭
I'm new to shadcn and just started using today, and I'm having this issue with brand new next-app (its replicable)
And it does not makes sense with current docs.
Describe the bug
The old version of the CLI installed my components correctly, in the resources/js/components folder In the new version, no matter what I change, components are ALWAYS installed in components/ui in the root of the project. Changing the aliases does not affect anything. I created a new Laravel application following the instructions in the documentation, and it has the same behavior.
What is particularly mind-blowing is that if you create a src folder in the root of the project, it will always install components there, even though I have not specified this folder as a path/alias anywhere.
Installing with the --path option also fails.
Expected behavior: components are installed in resources/js/components/ui folder Current behavior: components are installed in the components/ui folder
components.json
tsconfig.json
vite.config.js
Installation log: plotnikov@MacBook-Air-Ivan my-app % npx shadcn init Need to install the following packages: shadcn@2.1.0 Ok to proceed? (y) y
✔ Preflight checks. ✔ Verifying framework. Found Laravel. ✔ Validating Tailwind CSS. ✔ Validating import alias. ✔ Which style would you like to use? › Default ✔ Which color would you like to use as the base color? › Zinc ✔ Would you like to use CSS variables for theming? … no / yes ✔ Writing components.json. ✔ Checking registry. ✔ Updating tailwind.config.js ✔ Updating resources/css/app.css ✔ Installing dependencies. ✔ Created 1 file:
Success! Project initialization completed. You may now add components.
Affected component/components
All components
How to reproduce
1) Install new Laravel App by docs 2) Add any component, e.g.
npx shadcn@latest add button
Codesandbox/StackBlitz link
No response
Logs
No response
System Info
Before submitting