Skip to content

feat: tighten project name validation and export it as a reusable zod schema - #274

Open
beeman wants to merge 1 commit into
mainfrom
beeman/project-name-schema
Open

feat: tighten project name validation and export it as a reusable zod schema#274
beeman wants to merge 1 commit into
mainfrom
beeman/project-name-schema

Conversation

@beeman

@beeman beeman commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Why

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 old rule (/^[\w-]+$/i) accepted names like My_App, _x, and 9lives that broke both.

What

  • New projectNameSchema export — 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).
  • validateProjectName keeps its exact signature ((name: string) => string | undefined) and behaviour contract: schema check first, then the Directory already exists check.
  • Fixes a dead branch — the empty-name message was unreachable behind the old regex; it is now reachable via the schema's min-length check.

Notes

  • Names that previously passed the prompt (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 a minor.
  • The positional CLI name argument still bypasses validation entirely (only the prompt path validates); that's a pre-existing gap tracked for a separate change.

@changeset-bot

changeset-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 05a3e01

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
create-solana-dapp Minor

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

@pkg-pr-new

pkg-pr-new Bot commented Aug 5, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/create-solana-dapp@274

commit: 5d18ad4

@greptile-apps

greptile-apps Bot commented Aug 5, 2026

Copy link
Copy Markdown

Greptile Summary

The PR exports a reusable Zod schema and uses it to enforce lowercase kebab-case project names before checking directory existence.

  • Adds projectNameSchema to the package root exports.
  • Reuses the schema in project-name validation.
  • Adds validation, filesystem-ordering, and root-export tests.
  • Adds a minor-release changeset.

Confidence Score: 5/5

The 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 5d18ad4e0fa53b68aea6ae4e59cc395d4e50de10 is reported by Git as unsigned and therefore does not satisfy the repository owner’s verified-commit requirement.

Important Files Changed

Filename Overview
src/utils/validate-project-name.ts Introduces the reusable schema and delegates format validation to it while preserving the subsequent directory-existence check.
src/index.ts Exports the new schema alongside the existing validation function.
test/validate-project-name.test.ts Covers accepted and rejected names, length boundaries, directory collisions, and schema purity.
test/root-exports-schemas.test.ts Verifies that the package root exposes the same schema instance used internally.
.changeset/project-name-schema.md Documents the stricter validation and reusable export as a minor release.

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.
@beeman
beeman force-pushed the beeman/project-name-schema branch from 05a3e01 to 5d18ad4 Compare August 7, 2026 13:50
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