Skip to content

fix(@typegpu/cli): use one project prompt#2548

Closed
Will-thom wants to merge 1 commit into
software-mansion:mainfrom
Will-thom:fix/typegpu-cli-single-project-prompt
Closed

fix(@typegpu/cli): use one project prompt#2548
Will-thom wants to merge 1 commit into
software-mansion:mainfrom
Will-thom:fix/typegpu-cli-single-project-prompt

Conversation

@Will-thom
Copy link
Copy Markdown
Contributor

Summary

  • replace the separate project directory and package name prompts with a single project name prompt
  • reuse the project name for both the generated directory and package.json name
  • validate the entered project name against both directory and package-name constraints

Fixes #2543

Validation

  • corepack pnpm exec tsc -p packages/typegpu-cli/tsconfig.json --noEmit
  • corepack pnpm exec oxfmt --check packages/typegpu-cli/src/create.ts packages/typegpu-cli/src/utils/inputs.ts
  • corepack pnpm --filter @typegpu/cli build
  • corepack pnpm exec oxlint -c oxlint.config.ts --max-warnings=0 --type-aware --report-unused-disable-directives packages/typegpu-cli/src/create.ts packages/typegpu-cli/src/utils/inputs.ts

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.

Copilot AI review requested due to automatic review settings May 25, 2026 01:38
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 + getPackageName with a single getProjectName prompt.
  • Reused the entered value for both projectDir and packageName during 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

  • getProjectName validates the input as both a directory name and an npm package name, but scoped package names like @scope/pkg pass both validators while isValidProjectDirectory still allows the /. In createProject this value is reused as projectDir, so @scope/pkg will 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 for projectDir.
      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.

Comment on lines 17 to +24
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;
@aleksanderkatan
Copy link
Copy Markdown
Contributor

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.

@Will-thom
Copy link
Copy Markdown
Contributor Author

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.

@Will-thom Will-thom closed this May 26, 2026
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.

fix(@typegpu/cli): Make "directory" and "package name" a single prompt

3 participants