Skip to content

Commit eb8af47

Browse files
committed
fix(cli): load config properly in sanity schema validate
`sanity schema validate` was not using `resolveConfig` which means that it goes through a very different path than what Studio in the browser does. Most notably, default plugins are only loaded through `resolveConfig`. This fixes an issue where `sanity schema validate` would fail to find the `sanity.video` type.
1 parent dbb4b01 commit eb8af47

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

packages/sanity/src/_internal/cli/threads/validateSchema.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import {isMainThread, parentPort, workerData as _workerData} from 'node:worker_threads'
22

3-
import {groupProblems, validateSchema} from '@sanity/schema/_internal'
43
import {type SchemaValidationProblem, type SchemaValidationProblemGroup} from '@sanity/types'
5-
import {resolveSchemaTypes} from 'sanity'
64

7-
import {getStudioConfig} from '../util/getStudioWorkspaces'
5+
import {getStudioWorkspaces} from '../util/getStudioWorkspaces'
86
import {mockBrowserEnvironment} from '../util/mockBrowserEnvironment'
97

108
/** @internal */
@@ -33,7 +31,7 @@ async function main() {
3331
const cleanup = mockBrowserEnvironment(workDir)
3432

3533
try {
36-
const workspaces = getStudioConfig({basePath: workDir})
34+
const workspaces = await getStudioWorkspaces({basePath: workDir})
3735

3836
if (!workspaces.length) {
3937
throw new Error(`Configuration did not return any workspaces.`)
@@ -54,12 +52,8 @@ async function main() {
5452
workspace = workspaces[0]
5553
}
5654

57-
const schemaTypes = resolveSchemaTypes({
58-
config: workspace,
59-
context: {dataset: workspace.dataset, projectId: workspace.projectId},
60-
})
61-
62-
const validation = groupProblems(validateSchema(schemaTypes).getTypes())
55+
const schema = workspace.schema
56+
const validation = schema._validation!
6357

6458
const result: ValidateSchemaWorkerResult = {
6559
validation: validation

0 commit comments

Comments
 (0)