Skip to content

feat(init): select project and dataset during app init#968

Merged
binoy14 merged 6 commits intomainfrom
select-projects-during-init
Apr 20, 2026
Merged

feat(init): select project and dataset during app init#968
binoy14 merged 6 commits intomainfrom
select-projects-during-init

Conversation

@binoy14
Copy link
Copy Markdown
Contributor

@binoy14 binoy14 commented Apr 16, 2026

Description

Adds project and dataset selection to sanity init for app templates (app-quickstart, app-sanity-ui). Users can pick an existing project, create a new one, or skip — the selected projectId and dataset are rendered into src/App.tsx so the app works out of the box.

FIXES SDK-302

What to review

  • commands/init.ts — new promptForAppProjectSetup method with skip/create/existing options
  • actions/init/bootstrapLocalTemplate.ts — renders %projectId%/%dataset% placeholders in App.tsx
  • actions/init/initApp.ts — threads projectId/datasetName through; conditional success message
  • templates/app-quickstart/src/App.tsx and templates/app-sanity-ui/src/App.tsx — placeholder variables
  • App templates marked typescriptOnly: true since they only ship .tsx files

Testing

  • bootstrapLocalTemplate.test.ts — placeholder substitution and empty-string-on-skip cases
  • init.get-project-details.test.ts — skip, pick existing, create new, unattended with/without flags
  • init.bootstrap-app.test.ts — updated for new select prompt

🤖 Generated with Claude Code

@claude
Copy link
Copy Markdown

claude Bot commented Apr 16, 2026

Claude finished @binoy14's task in 1m 57s —— View job


Review

  • Gather context
  • Read changed files
  • Analyze for issues
  • Post review

packages/@sanity/cli/src/commands/init.ts:1083–1138newProject ignored in interactive app template path

When --project-name is supplied without --yes for an app template, createProjectFromName runs first and creates a project, but promptForAppTemplateSetup's interactive branch ignores the newProject parameter entirely — it calls listProjects() fresh and shows a full selector. The newly-created project will appear in the list with no preselection, and if the user picks something else or skips, the project they never intended to create is silently orphaned.

Fix: in the interactive branch, check newProject and fast-forward to the dataset step if it's set:

// before the select prompt
if (newProject) {
  const displayName = projects.find((p) => p.id === newProject)?.displayName ?? ''
  const dataset = await this.getOrCreateDataset({ displayName, projectId: newProject, showDefaultConfigPrompt: false })
  return { datasetName: dataset.datasetName, displayName, projectId: newProject }
}

Fix this →


packages/@sanity/cli/src/commands/init.ts:~1084 — missing spinner on listProjects() in interactive app-template path

Every other API call in the init flow has a spinner, but the listProjects() call at the top of promptForAppTemplateSetup's interactive branch has none. On a slow connection this shows a blank pause. The non-app template path has the same pattern but it's covered by the "Fetching existing projects" log printed earlier in run(). That log is explicitly suppressed for app templates (if (!isAppTemplate) { this.log('Fetching existing projects') }), so there's no feedback at all here.


.changeset/pr-968.md — two unrelated fixes in one changeset entry

The changeset mixes a feature and a bug fix into two bullets. Conventionally each distinct user-facing change gets its own sentence (or its own changeset file). The TypeScript crash fix is unrelated to project/dataset selection and could confuse users reading the changelog.


packages/@sanity/cli/src/commands/init.ts:~1084listProjects() includes member-role projects

listProjects() returns all projects the user can see, including those where they are only a member. For app templates that then call getOrCreateDataset, a member-role project may lack the permissions needed to list or create datasets, producing a confusing downstream API error. Consider filtering to projects where the user has at least editor/admin role, or adding an error message that contextualises the permission failure.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 16, 2026

📦 Bundle Stats — @sanity/cli

Compared against main (10db76fa)

@sanity/cli

Metric Value vs main (10db76f)
Internal (raw) 2.1 KB -
Internal (gzip) 799 B -
Bundled (raw) 10.94 MB -
Bundled (gzip) 2.05 MB -
Import time 829ms +6ms, +0.8%

bin:sanity

Metric Value vs main (10db76f)
Internal (raw) 975 B -
Internal (gzip) 460 B -
Bundled (raw) 9.84 MB -
Bundled (gzip) 1.77 MB -
Import time 1.96s +4ms, +0.2%

🗺️ View treemap · Artifacts

Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

📦 Bundle Stats — @sanity/cli-core

Compared against main (10db76fa)

Metric Value vs main (10db76f)
Internal (raw) 93.8 KB -
Internal (gzip) 21.9 KB -
Bundled (raw) 21.62 MB -
Bundled (gzip) 3.42 MB -
Import time 790ms +8ms, +1.0%

🗺️ View treemap · Artifacts

Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

📦 Bundle Stats — create-sanity

Compared against main (10db76fa)

Metric Value vs main (10db76f)
Internal (raw) 976 B -
Internal (gzip) 507 B -
Bundled (raw) 50.7 KB -
Bundled (gzip) 12.6 KB -
Import time ❌ ChildProcess denied: node -
Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 16, 2026

Coverage Delta

File Statements
packages/@sanity/cli/src/actions/init/bootstrapLocalTemplate.ts 89.7% (+ 87.7%)
packages/@sanity/cli/src/actions/init/initApp.ts 96.0% (+ 0.5%)
packages/@sanity/cli/src/actions/init/templates/appQuickstart.ts 100.0% (±0%)
packages/@sanity/cli/src/actions/init/templates/appSanityUi.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/init.ts 95.1% (- 0.3%)
packages/@sanity/cli/src/telemetry/init.telemetry.ts 100.0% (±0%)

Comparing 6 changed files against main @ 10db76fa8864014ff9b3b8d678ef6818740973b3

Overall Coverage

Metric Coverage
Statements 83.9% (+ 0.8%)
Branches 73.7% (+ 0.4%)
Functions 83.8% (+ 0.8%)
Lines 84.3% (+ 0.8%)

@binoy14 binoy14 force-pushed the select-projects-during-init branch 2 times, most recently from db4041c to 7fb05da Compare April 17, 2026 00:53
squiggler-app Bot added a commit that referenced this pull request Apr 17, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 17, 2026

Preview this PR with pkg.pr.new

Run the Sanity CLI

npx https://pkg.pr.new/sanity-io/cli/@sanity/cli@c147127 <command>

...Or upgrade project dependencies

📦 @sanity/cli
pnpm install https://pkg.pr.new/@sanity/cli@c147127
📦 @sanity/cli-core
pnpm install https://pkg.pr.new/@sanity/cli-core@c147127
📦 @sanity/cli-test
pnpm install https://pkg.pr.new/@sanity/cli-test@c147127
📦 @sanity/eslint-config-cli
pnpm install https://pkg.pr.new/@sanity/eslint-config-cli@c147127

View Commit (c147127)

@binoy14 binoy14 force-pushed the select-projects-during-init branch from 8390d48 to 3bd43b7 Compare April 17, 2026 15:37
squiggler-app Bot added a commit that referenced this pull request Apr 17, 2026
binoy14 added a commit that referenced this pull request Apr 17, 2026
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@binoy14 binoy14 force-pushed the select-projects-during-init branch from be33cd5 to 1879740 Compare April 17, 2026 16:12
@binoy14 binoy14 marked this pull request as ready for review April 17, 2026 16:58
@binoy14 binoy14 requested a review from a team as a code owner April 17, 2026 16:58
@binoy14 binoy14 requested review from cngonzalez, mttdnt and rexxars and removed request for a team April 17, 2026 16:58
Copy link
Copy Markdown
Member

@cngonzalez cngonzalez left a comment

Choose a reason for hiding this comment

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

A few nits, nothing super blocking -- I'd just want an update on the "sources" language

Comment thread packages/@sanity/cli/src/actions/init/initApp.ts Outdated
Comment thread packages/@sanity/cli/src/commands/init.ts Outdated
Comment thread packages/@sanity/cli/src/commands/init.ts Outdated
binoy14 and others added 5 commits April 20, 2026 10:52
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Avoids collision with a project actually named "skip" or "new".

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@binoy14 binoy14 force-pushed the select-projects-during-init branch 2 times, most recently from 23bfb26 to 2033f72 Compare April 20, 2026 15:26
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@binoy14 binoy14 force-pushed the select-projects-during-init branch from 2033f72 to c147127 Compare April 20, 2026 15:47
@binoy14 binoy14 requested review from cngonzalez and mttdnt April 20, 2026 15:58
Copy link
Copy Markdown
Member

@cngonzalez cngonzalez left a comment

Choose a reason for hiding this comment

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

LGTM!

@binoy14 binoy14 merged commit c88caf7 into main Apr 20, 2026
51 checks passed
@binoy14 binoy14 deleted the select-projects-during-init branch April 20, 2026 17:35
@squiggler-app squiggler-app Bot mentioned this pull request Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants