fix(cli): validate project name using npm package name rules #9161
+57
−8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #9160
Problem
When creating a new project using
npx shadcn@latest create, the CLI accepts uppercase letters in the project name but then fails with a generic error message:This happens because npm package names cannot contain uppercase letters, but the CLI wasn't validating this before attempting to create the project.
Solution
Added proper npm package name validation using the
validate-npm-package-namepackage. This validates the project name against npm's naming rules and provides clear, actionable error messages when validation fails.Reference:
Next CLI validation: https://github.com/vercel/next.js/blob/canary/packages/create-next-app/helpers/validate-pkg.ts
NextJS requires this naming convention, although
vite-reactandtantack-startmight not need this validation. So, we have two options:Option 1 does not seem like a proper solution, so I chose
option 2, awaiting opinions or reviews from @shadcn or team members.Changes
validate-npm-package-namedependency and its typespackages/shadcn/src/utils/validate-pkg.tsutility for name validationpackages/shadcn/src/commands/create.tsto use the new validation in the project name promptBefore
After