Skip to content

feat: add app resources to sanity.cli.ts#878

Open
ryanbonial wants to merge 4 commits intomainfrom
stack/sdk-711-app-resources-base
Open

feat: add app resources to sanity.cli.ts#878
ryanbonial wants to merge 4 commits intomainfrom
stack/sdk-711-app-resources-base

Conversation

@ryanbonial
Copy link
Copy Markdown
Member

@ryanbonial ryanbonial commented Apr 2, 2026

Description

This PR adds CLI config support for named app resources and updates app scaffolding to generate those resources by default.

It introduces app.resources to the CLI config types and schema, exports the related resource types from @sanity/cli-core, and updates createAppCliConfig() / bootstrapLocalTemplate() so newly scaffolded apps emit a resources.default entry with the selected projectId and dataset. This creates a shared config foundation for the later SDK v3 runtime work.

What to review

  • Review the new app.resources type surface in @sanity/cli-core
  • Confirm the schema accepts the supported resource shapes:
    • dataset resource
    • media library resource
    • canvas resource
  • Review the app init/template changes to ensure scaffolded sanity.cli.ts files now include:
    • app.resources.default.projectId
    • app.resources.default.dataset
  • Check that the exported types from @sanity/cli-core are the right public API for follow-up work

Testing

  • Added schema parsing tests for all supported app.resources variants
  • Added init template tests covering:
    • default app resource generation
    • allowing empty projectId / dataset values to flow through the template processor
  • Ran:
    • pnpm test packages/@sanity/cli-core/src/config/cli/__tests__/schemas.test.ts packages/@sanity/cli/src/actions/init/__tests__/createAppCliConfig.test.ts

Note

Medium Risk
Introduces a new public config surface (app.resources) and changes app project scaffolding output, which could affect downstream consumers and generated config expectations. Scope is limited to config typing/validation and init template generation.

Overview
Adds named app resources support via app.resources in sanity.cli.*, including a new AppResource type and Zod schema validation for {projectId, dataset} resource entries.

Updates app initialization scaffolding so createAppCliConfig() emits a resources.default block only when both projectId and dataset are available, and wires those variables through bootstrapLocalTemplate(). Adds targeted tests for schema acceptance/rejection and for template selection behavior.

Reviewed by Cursor Bugbot for commit 5c73dc9. Bugbot is set up for automated code reviews on this repo. Configure here.

@ryanbonial ryanbonial requested a review from a team as a code owner April 2, 2026 22:00
@ryanbonial ryanbonial requested review from cngonzalez and removed request for a team April 2, 2026 22:00
@claude
Copy link
Copy Markdown

claude Bot commented Apr 2, 2026

Claude finished @cngonzalez's task in 2m 1s —— View job


Review

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

Changeset description is too vague

.changeset/pr-878.md says "add app resources to sanity.cli.ts" — this doesn't tell a developer what actually changed for them. Suggested: "Scaffolded app sanity.cli.ts now includes a resources.default entry with the selected project and dataset when both are provided during init."


Schema allows empty strings for required resource fields

schemas.ts lines 27-30 use z.string() for both dataset and projectId, which accepts ''. This is inconsistent with hasResources() in createAppCliConfig.ts (line 40), which treats empty strings as falsy and skips the resource block. A user who manually writes resources: {default: {projectId: '', dataset: ''}} in their config would pass schema validation but produce a resource entry with no useful values.

Fix: add .min(1) validation.

z.object({
  dataset: z.string().min(1),
  projectId: z.string().min(1),
})

Fix this →


Schema test name is misleading

schemas.test.ts line 24: 'rejects unknown resource shapes' — the key name bad is not what's being rejected; any string key is valid per z.record(z.string(), ...). What's rejected is the value {} missing dataset/projectId. The test should be named 'rejects resources missing required fields' to avoid implying key names are constrained.


AppResource type name will likely cause confusion

AppResource is exported with only {dataset: string, projectId: string}, but the name implies it could represent any resource type (media library, canvas, etc.). Since only dataset resources are supported right now, naming it DatasetResource would be more precise and avoids the need to introduce a union type later when other resource shapes are added. This is marked @beta, so a rename is still low-cost.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 2, 2026

📦 Bundle Stats — @sanity/cli

Compared against main (2fd358fc)

@sanity/cli

Metric Value vs main (2fd358f)
Internal (raw) 2.1 KB -
Internal (gzip) 799 B -
Bundled (raw) 10.95 MB +5.9 KB, +0.1%
Bundled (gzip) 2.05 MB +1014 B, +0.0%
Import time 822ms +3ms, +0.4%

bin:sanity

Metric Value vs main (2fd358f)
Internal (raw) 975 B -
Internal (gzip) 460 B -
Bundled (raw) 9.84 MB -
Bundled (gzip) 1.77 MB -
Import time 1.93s -0ms, -0.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 — @sanity/cli-core

Compared against main (2fd358fc)

Metric Value vs main (2fd358f)
Internal (raw) 93.2 KB -562 B, -0.6%
Internal (gzip) 21.9 KB -7 B, -0.0%
Bundled (raw) 21.62 MB -568 B, -0.0%
Bundled (gzip) 3.42 MB -61 B, -0.0%
Import time 782ms +4ms, +0.5%

🗺️ 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 (2fd358fc)

Metric Value vs main (2fd358f)
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 2, 2026

Coverage Delta

File Statements
packages/@sanity/cli-core/src/config/cli/schemas.ts 100.0% (±0%)
packages/@sanity/cli/src/actions/init/bootstrapLocalTemplate.ts 89.7% (±0%)
packages/@sanity/cli/src/actions/init/createAppCliConfig.ts 100.0% (±0%)

Comparing 3 changed files against main @ 2fd358fc52ed3e2c3b89e45796e4a6044e03cd4c

Overall Coverage

Metric Coverage
Statements 84.0% (±0%)
Branches 73.7% (+ 0.0%)
Functions 83.9% (+ 0.0%)
Lines 84.4% (±0%)

@cngonzalez cngonzalez changed the title SDK app resources (base) feat: add app resources to sanity.cli.ts Apr 7, 2026
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.

functionally looks good -- most of my comments are just pedantic. Let me know what you think!

Comment thread packages/@sanity/cli/src/actions/init/createAppCliConfig.ts
Comment thread packages/@sanity/cli-core/src/config/cli/types/cliConfig.ts Outdated
Comment thread packages/@sanity/cli-core/src/config/cli/types/cliConfig.ts Outdated
Comment thread packages/@sanity/cli-core/src/config/cli/types/cliConfig.ts
@ryanbonial
Copy link
Copy Markdown
Member Author

@cngonzalez great suggestions, ready for review again

@ryanbonial ryanbonial requested a review from cngonzalez April 8, 2026 19:12
cngonzalez
cngonzalez previously approved these changes Apr 8, 2026
Copy link
Copy Markdown
Member

cngonzalez commented Apr 9, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@cngonzalez cngonzalez force-pushed the stack/sdk-711-app-resources-base branch from 7a6ae95 to 21fbd90 Compare April 15, 2026 20:55
squiggler-app Bot added a commit that referenced this pull request Apr 15, 2026
@cngonzalez cngonzalez force-pushed the stack/sdk-711-app-resources-base branch 4 times, most recently from 1293c23 to 0669398 Compare April 16, 2026 20:20
ryanbonial and others added 4 commits April 22, 2026 12:24
…validation

- Introduced two app templates: one with resources and one without

- Updated the createAppCliConfig function to select the appropriate template.
- removing support for media library and canvas resources.
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