Skip to content

SDK app resources (base)#878

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

SDK app resources (base)#878
ryanbonial wants to merge 2 commits intomainfrom
stack/sdk-711-app-resources-base

Conversation

@ryanbonial
Copy link
Copy Markdown
Member

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

@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 @ryanbonial's task in 1m 32s —— View job


Review

Bug: createAppCliConfig throws when projectId/dataset are omitted

In createAppCliConfig.ts, the template contains '%projectId%' and '%dataset%' placeholders, but the options object is passed directly to processTemplate as variables. When projectId or dataset are not provided (they're optional in GenerateCliConfigOptions), those keys are absent from the object entirely.

processTemplate at line 21 checks !(variableName in variables) and throws Template variable '%projectId%' not defined if the key is missing. So calling createAppCliConfig({ entry: './src/App.tsx', organizationId: 'org-123' }) would throw at runtime.

The test covering this case ('allows empty project and dataset values to flow through the template processor') mocks processTemplate, so it doesn't catch this.

Fix — explicitly spread all variables so missing optional keys are still present (with undefined value, which processTemplate converts to ''):

// createAppCliConfig.ts
export function createAppCliConfig(options: GenerateCliConfigOptions): string {
  return processTemplate({
    template: defaultAppTemplate,
    variables: {
      dataset: options.dataset,
      entry: options.entry,
      organizationId: options.organizationId,
      projectId: options.projectId,
    },
  })
}

Fix this →


Missing negative test coverage in schemas.test.ts

The schema tests only verify valid inputs. There are no tests confirming invalid resource shapes are rejected (e.g., an empty object {} or an object with an unrecognized key). A test like this would be valuable:

test('rejects unknown resource shapes', () => {
  expect(() =>
    cliConfigSchema.parse({
      app: { resources: { bad: {} } },
    }),
  ).toThrow()
})

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

📦 Bundle Stats — @sanity/cli

Compared against main (7b98e0be)

@sanity/cli

Metric Value vs main (7b98e0b)
Internal (raw) 2.1 KB -
Internal (gzip) 799 B -
Bundled (raw) 10.96 MB +8.9 KB, +0.1%
Bundled (gzip) 2.06 MB +1.3 KB, +0.1%
Import time 827ms -14ms, -1.7%

bin:sanity

Metric Value vs main (7b98e0b)
Internal (raw) 975 B -
Internal (gzip) 460 B -
Bundled (raw) 9.84 MB -
Bundled (gzip) 1.77 MB -
Import time 2.00s -1ms, -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 (7b98e0be)

Metric Value vs main (7b98e0b)
Internal (raw) 92.7 KB +346 B, +0.4%
Internal (gzip) 21.7 KB +54 B, +0.2%
Bundled (raw) 21.53 MB +334 B, +0.0%
Bundled (gzip) 3.41 MB +63 B, +0.0%
Import time 795ms +4ms, +0.4%

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

Metric Value vs main (7b98e0b)
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 1.9% (±0%)
packages/@sanity/cli/src/actions/init/createAppCliConfig.ts 100.0% (+ 50.0%)

Comparing 3 changed files against main @ 7b98e0be69544a0a89ddf871219b8025128e622b

Overall Coverage

Metric Coverage
Statements 83.1% (+ 0.0%)
Branches 72.9% (±0%)
Functions 83.3% (+ 0.0%)
Lines 83.5% (+ 0.0%)

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.

1 participant