Skip to content

initial commit#1382

Merged
BilalG1 merged 2 commits intoemulator-setup-fixesfrom
create-project-cli
Apr 24, 2026
Merged

initial commit#1382
BilalG1 merged 2 commits intoemulator-setup-fixesfrom
create-project-cli

Conversation

@aadesh18
Copy link
Copy Markdown
Collaborator

Adds the ability to create a project using cli.

@aadesh18 aadesh18 requested a review from BilalG1 April 24, 2026 01:57
@aadesh18 aadesh18 self-assigned this Apr 24, 2026
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 24, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
stack-auth-hosted-components Ready Ready Preview, Comment Apr 24, 2026 3:33am
stack-backend Ready Ready Preview, Comment Apr 24, 2026 3:33am
stack-dashboard Ready Ready Preview, Comment Apr 24, 2026 3:33am
stack-demo Ready Ready Preview, Comment Apr 24, 2026 3:33am
stack-docs Ready Ready Preview, Comment Apr 24, 2026 3:33am
stack-preview-backend Ready Ready Preview, Comment Apr 24, 2026 3:33am
stack-preview-dashboard Ready Ready Preview, Comment Apr 24, 2026 3:33am

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 24, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3d2884e4-0b83-4873-9ff0-e9b192592c9b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch create-project-cli

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 24, 2026

Greptile Summary

This PR extracts shared project-creation logic into a new createProjectInteractively helper and wires it into both stack project create and stack init, so users with no existing projects can create one on the fly during init instead of receiving a hard error.

  • Whitespace-only --display-name creates an empty-named project (create-project.ts line 16): !displayName is falsy only for undefined/null/"", so " " bypasses the interactive validator and displayName.trim() produces "" sent to the API.
  • --select-project-id + zero projects in interactive mode creates an orphaned project then throws (init.ts line 163): the creation block runs unconditionally before the opts.selectProjectId lookup, leaving the user with a project they didn't intend and an immediate error.

Confidence Score: 3/5

Not 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

Filename Overview
packages/stack-cli/src/lib/create-project.ts New shared helper for interactive project creation; has a whitespace-only display name validation gap (P1) and silently picks the first team when multiple exist (P2)
packages/stack-cli/src/commands/init.ts Adds zero-project creation flow during init; --select-project-id + no projects in interactive mode creates an orphaned project then throws (P1)
packages/stack-cli/src/commands/project.ts Cleaned up by delegating project creation logic to the new createProjectInteractively helper; no issues found

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
Loading
Prompt To Fix All With AI
This 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

Comment thread packages/stack-cli/src/lib/create-project.ts
Comment thread packages/stack-cli/src/commands/init.ts
Comment thread packages/stack-cli/src/lib/create-project.ts
Comment thread packages/stack-cli/src/lib/create-project.ts
Comment thread packages/stack-cli/src/commands/init.ts
@BilalG1 BilalG1 merged commit 5586a36 into emulator-setup-fixes Apr 24, 2026
36 checks passed
@BilalG1 BilalG1 deleted the create-project-cli branch April 24, 2026 17:29
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.

2 participants