fix(@typegpu/cli): use one project prompt#2548
Conversation
There was a problem hiding this comment.
Pull request overview
This PR simplifies @typegpu/cli project scaffolding by replacing separate “project directory” and “package name” prompts with a single “project name” prompt that is reused for both the created folder and package.json name.
Changes:
- Replaced
getProjectDirectory+getPackageNamewith a singlegetProjectNameprompt. - Reused the entered value for both
projectDirandpackageNameduring scaffolding. - Added combined validation to ensure the entered value satisfies both directory-name and npm package-name constraints.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/typegpu-cli/src/utils/inputs.ts | Consolidates prompts into getProjectName and validates against both directory and package-name rules. |
| packages/typegpu-cli/src/create.ts | Updates scaffolding flow to use the single project name for both directory and package name. |
Comments suppressed due to low confidence (2)
packages/typegpu-cli/src/utils/inputs.ts:24
getProjectNamevalidates the input as both a directory name and an npm package name, but scoped package names like@scope/pkgpass both validators whileisValidProjectDirectorystill allows the/. IncreateProjectthis value is reused asprojectDir, so@scope/pkgwill create nested directories (@scope/pkg) rather than a single project folder, which is surprising and can break expectations. Consider either rejecting/for the directory constraint when using a single prompt, or mapping scoped names to a safe folder name (e.g., strip the scope or replace/with-) and using that derived value forprojectDir.
return !isValidProjectDirectory(value) || !isValidPackageName(value)
? 'Invalid project name.'
: undefined;
packages/typegpu-cli/src/utils/inputs.ts:24
- This change removes the previous ability to accept an empty project directory (which defaulted to
.) and separately prompt for a valid package name. With the combined prompt, users can no longer scaffold into the current directory because.(and empty input) fails the package-name validation. If scaffolding into.is still intended to be supported, handle that as a special case (e.g., allow empty/.for the directory and derive a package name from the current folder name, or keep a fallback package-name prompt only when the directory is.).
if (!value) {
return 'Invalid project name.';
}
return !isValidProjectDirectory(value) || !isValidPackageName(value)
? 'Invalid project name.'
: undefined;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| validate: (value) => { | ||
| return value && !isValidProjectDirectory(value) ? 'Invalid project directory.' : undefined; | ||
| }, | ||
| }); | ||
|
|
||
| if (p.isCancel(projectDir)) { | ||
| cancelExit(); | ||
| } | ||
| if (!value) { | ||
| return 'Invalid project name.'; | ||
| } | ||
|
|
||
| projectDir ??= '.'; | ||
| return projectDir.trim(); | ||
| } | ||
|
|
||
| export async function getPackageName(initialValue: string) { | ||
| const packageName = await p.text({ | ||
| message: 'Package name:', | ||
| placeholder: initialValue, | ||
| initialValue, | ||
| validate: (value) => { | ||
| return !value || !isValidPackageName(value) ? 'Invalid package name.' : undefined; | ||
| return !isValidProjectDirectory(value) || !isValidPackageName(value) | ||
| ? 'Invalid project name.' | ||
| : undefined; |
|
I think we should follow create-vite, which iirc is: ask for project name, and if it happens to be invalid package name, then ask for package name. |
|
Closing this in favor of #2564, which follows the maintainer guidance from this thread by deriving the package name from the selected project directory and removing the separate package-name prompt. |
Summary
Fixes #2543
Validation
Note: local validation ran on Node v22.21.1, while the repo currently declares Node >=24.0.0; pnpm emitted engine warnings, but the focused checks above passed.