initial commit#1382
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryThis PR extracts shared project-creation logic into a new
Confidence Score: 3/5Not safe to merge — two P1 bugs: silent empty display name on whitespace input, and orphaned-project creation when --select-project-id is combined with zero existing projects in interactive mode. Two independent P1 logic defects in the changed code path: one causes a project to be created with an empty display name, the other creates an unwanted side-effect project and then throws. Both affect core user-facing flows introduced by this PR. packages/stack-cli/src/lib/create-project.ts (display name validation) and packages/stack-cli/src/commands/init.ts (select-project-id guard ordering) Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[stack init / stack project create] --> B{Has --select-project-id?}
B -- Yes --> C[resolveSessionAuth]
B -- No --> C
C --> D[listOwnedProjects]
D --> E{projects.length === 0?}
E -- No --> F{--select-project-id set?}
E -- Yes & non-interactive --> G[CliError: run stack project create first]
E -- Yes & interactive --> H[confirm: create a project?]
H -- No --> I[CliError: create at app.stack-auth.com]
H -- Yes --> J[createProjectInteractively]
J --> K{displayName provided?}
K -- whitespace-only --> L[⚠️ trim → empty string sent to API]
K -- valid string --> M[listTeams → use teams 0]
K -- empty/undefined & non-interactive --> N[CliError: --display-name required]
K -- empty/undefined & interactive --> O[prompt for display name with validate]
O --> M
M --> P[user.createProject]
P --> Q[autoCreatedProjectId set]
Q --> F
F -- Yes, search in projects array --> R{found?}
R -- No --> S[⚠️ CliError: project not found - orphaned project created]
R -- Yes --> T[use selectProjectId]
F -- No, autoCreatedProjectId set --> U[use autoCreatedProjectId]
F -- No, no auto-create --> V[select prompt from list]
T --> W[createInternalApiKey & write .env]
U --> W
V --> W
Prompt To Fix All With AIThis is a comment left during a code review.
Path: packages/stack-cli/src/lib/create-project.ts
Line: 16-25
Comment:
**Whitespace-only display name bypasses validation**
`!displayName` is truthy only for `undefined`, `null`, or `""`. A caller passing `--display-name " "` (whitespace-only) skips the prompt and its `validate` check entirely. The subsequent `displayName.trim()` then produces `""`, which is forwarded to `user.createProject` as an empty display name. The original `project.ts` code guarded against this with `if (!displayName.trim())`.
```suggestion
let displayName = opts.displayName?.trim() || undefined;
if (!displayName) {
```
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: packages/stack-cli/src/commands/init.ts
Line: 163-193
Comment:
**`--select-project-id` + zero projects creates orphaned project then throws**
When a user runs `stack init --select-project-id abc123` in interactive mode but has no projects, the code enters the creation flow, creates a new project as a side effect (`projects = [newProject]`), and then the `opts.selectProjectId` branch (line 186) tries to find `abc123` in the single-item array, fails, and throws "Project 'abc123' not found." The user is left with a project they didn't intend to create.
The `--select-project-id` path should short-circuit before offering to create a project by throwing early inside the zero-projects block when `opts.selectProjectId` is set.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: packages/stack-cli/src/lib/create-project.ts
Line: 27-34
Comment:
**Silent use of first team when multiple teams exist**
When a user belongs to multiple teams, `teams[0]` is chosen silently with no log message indicating which team was selected and no opportunity to pick a different one. A user with multiple teams may inadvertently create the project under the wrong team. Consider either logging the chosen team name or prompting with a `select` when `teams.length > 1`.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "initial commit" | Re-trigger Greptile |
Adds the ability to create a project using cli.