feat: tighten project name validation and export it as a reusable zod schema - #274
feat: tighten project name validation and export it as a reusable zod schema#274beeman wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 05a3e01 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
Greptile SummaryThe PR exports a reusable Zod schema and uses it to enforce lowercase kebab-case project names before checking directory existence.
Confidence Score: 5/5The code changes appear safe to merge, but repository policy separately requires the unsigned commit to be replaced with a verified signed commit. No blocking code failure remains; however, commit Important Files Changed
Reviews (2): Last reviewed commit: "feat: tighten project name validation an..." | Re-trigger Greptile |
… schema The project name is written into the generated package.json and used as the search key for the init script rename, so it must be a valid npm package name. The new projectNameSchema accepts lowercase kebab-case names only (a lowercase letter followed by lowercase letters, digits, and single dashes, max 214 characters) and is exported so downstream consumers can compose it. validateProjectName keeps its signature and still reports 'Directory already exists' after the schema check, and the previously unreachable empty-name message is now reachable via the schema's min-length check.
05a3e01 to
5d18ad4
Compare
Why
The project name is written into the generated
package.jsonand used as the search key for the init script rename, so it must be a valid npm package name. The old rule (/^[\w-]+$/i) accepted names likeMy_App,_x, and9livesthat broke both.What
projectNameSchemaexport — the pure validation rule as a zod schema, so downstream consumers can reuse and compose it. Accepts lowercase kebab-case only: a lowercase letter followed by lowercase letters, digits, and single dashes, max 214 characters (the npm limit).validateProjectNamekeeps its exact signature ((name: string) => string | undefined) and behaviour contract: schema check first, then theDirectory already existscheck.Notes
My_App,my_app) are now rejected — they always produced an invalid npm package name and a degenerate rename search key downstream, so this ships as aminor.nameargument still bypasses validation entirely (only the prompt path validates); that's a pre-existing gap tracked for a separate change.