Skip to content

Fix(shadcn init): improve shadcn package behavior #7524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

Anas-github-acc
Copy link

@Anas-github-acc Anas-github-acc commented Jun 1, 2025

PR: Fix Project Directory Creation Issues ( shadcn init )

Issue

Screenshot 2025-06-02 005007

Changes

  • Ensured cwd resolution before override: in shadcn/commands/init.ts Placed the options ...opts before the cwd resolution logic to prevent any overrides that cause incorrect working directory resolution.
    image

Issue

Screenshot 2025-06-02 005919

The issue is that if a folder exists with the same path when you try to init a new next.js project using shadcn init and the folder contain some files (e.g., my-app contains content2.txt) but lack package.json file, the program continues to execute and encounters the error during next.js create-next-app. The unclear error message makes it hard for user to identify error and additional time to get to the error message is frustrating.

How i fixed it

  • Attempt to create the project directory (used fs.mkdirSync)
    • If it already exists, check if it is empty (reading first entry of the directory).
    • If not empty, show a clear error and exit.
    • If not writable or path does not exist, show a clear error and exit.
    • if exists but is empty, proceed with project creation.

Impact

  1. Proper writable permission check for the target directory.
  2. This prevents cryptic errors when the target folder is not suitable.

Test

  • Some tests in shadcn/utils/create-project.test.ts have been added, and others have been updated

…hecks

  checks to ensure the project directory:
  - Exists and is writable.
  - Is empty before proceeding.
  - Provides clear errors for invalid states
Copy link

vercel bot commented Jun 1, 2025

@Anas-github-acc is attempting to deploy a commit to the shadcn-pro Team on Vercel.

A member of the Team first needs to authorize it.

@Anas-github-acc Anas-github-acc changed the title Fix/improve shadcn package behavior Fix(shadcn init): improve shadcn package behavior Jun 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant