@sanity/cli-core 1.1.3 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,27 +1,29 @@
|
|
|
1
1
|
import { dirname } from 'node:path';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { studioWorkerTask } from '../../loaders/studio/studioWorkerTask.js';
|
|
4
|
-
const schemaSchema = z.
|
|
4
|
+
const schemaSchema = z.looseObject({
|
|
5
5
|
name: z.string().optional(),
|
|
6
|
-
types: z.array(z.
|
|
6
|
+
types: z.array(z.looseObject({}))
|
|
7
7
|
});
|
|
8
|
-
const sourceSchema = z.
|
|
8
|
+
const sourceSchema = z.looseObject({
|
|
9
9
|
dataset: z.string(),
|
|
10
10
|
projectId: z.string(),
|
|
11
|
-
schema: z.
|
|
11
|
+
schema: z.looseObject({
|
|
12
12
|
_original: schemaSchema
|
|
13
13
|
})
|
|
14
14
|
});
|
|
15
|
-
|
|
15
|
+
// Raw workspace schema (resolvePlugins: false) - unstable_sources not yet populated
|
|
16
|
+
const rawWorkspaceSchema = z.looseObject({
|
|
16
17
|
...sourceSchema.shape,
|
|
17
18
|
basePath: z.string().optional(),
|
|
18
19
|
name: z.string().optional(),
|
|
19
20
|
plugins: z.array(z.unknown()).optional(),
|
|
20
21
|
schema: schemaSchema.optional(),
|
|
21
22
|
title: z.string().optional(),
|
|
22
|
-
unstable_sources: z.array(sourceSchema)
|
|
23
|
-
})
|
|
24
|
-
|
|
23
|
+
unstable_sources: z.array(sourceSchema).optional()
|
|
24
|
+
});
|
|
25
|
+
// Resolved config schema (resolvePlugins: true) - all fields required
|
|
26
|
+
const resolvedWorkspaceSchema = z.looseObject({
|
|
25
27
|
...sourceSchema.shape,
|
|
26
28
|
basePath: z.string(),
|
|
27
29
|
name: z.string(),
|
|
@@ -30,10 +32,10 @@ const studioWorkspaceSchema = z.object({
|
|
|
30
32
|
unstable_sources: z.array(sourceSchema)
|
|
31
33
|
});
|
|
32
34
|
const rawConfigSchema = z.union([
|
|
33
|
-
z.array(
|
|
34
|
-
|
|
35
|
+
z.array(rawWorkspaceSchema),
|
|
36
|
+
rawWorkspaceSchema
|
|
35
37
|
]);
|
|
36
|
-
const resolvedConfigSchema = z.array(
|
|
38
|
+
const resolvedConfigSchema = z.array(resolvedWorkspaceSchema);
|
|
37
39
|
export async function readStudioConfig(configPath, options) {
|
|
38
40
|
const result = await studioWorkerTask(new URL('readStudioConfig.worker.js', import.meta.url), {
|
|
39
41
|
name: 'studioConfig',
|
|
@@ -43,7 +45,36 @@ export async function readStudioConfig(configPath, options) {
|
|
|
43
45
|
resolvePlugins: options.resolvePlugins
|
|
44
46
|
}
|
|
45
47
|
});
|
|
46
|
-
|
|
48
|
+
try {
|
|
49
|
+
return options.resolvePlugins ? resolvedConfigSchema.parse(result) : rawConfigSchema.parse(result);
|
|
50
|
+
} catch (err) {
|
|
51
|
+
if (err instanceof z.ZodError) {
|
|
52
|
+
throw new Error(`Invalid studio config at ${configPath}:\n${formatZodIssues(err.issues)}`);
|
|
53
|
+
}
|
|
54
|
+
throw err;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Recursively extracts leaf-level messages from Zod issues, including
|
|
59
|
+
* those nested inside union errors. Note that `prettifyError` from Zod
|
|
60
|
+
* only gives a high-level summary for union errors, so this function is
|
|
61
|
+
* needed to get the full details of all validation issues in a readable format.
|
|
62
|
+
*
|
|
63
|
+
* @internal exported for testing only
|
|
64
|
+
*/ export function formatZodIssues(issues, indent = 2) {
|
|
65
|
+
const lines = [];
|
|
66
|
+
const prefix = ' '.repeat(indent);
|
|
67
|
+
for (const issue of issues){
|
|
68
|
+
if (issue.code === 'invalid_union' && 'errors' in issue && Array.isArray(issue.errors)) {
|
|
69
|
+
for (const [i, unionIssues] of issue.errors.entries()){
|
|
70
|
+
lines.push(`${prefix}Union option ${i + 1}:`, formatZodIssues(unionIssues, indent + 2));
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
const path = issue.path.length > 0 ? ` at "${issue.path.join('.')}"` : '';
|
|
74
|
+
lines.push(`${prefix}- ${issue.message}${path}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return lines.join('\n');
|
|
47
78
|
}
|
|
48
79
|
|
|
49
80
|
//# sourceMappingURL=readStudioConfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/config/studio/readStudioConfig.ts"],"sourcesContent":["import {dirname} from 'node:path'\n\nimport {z} from 'zod'\n\nimport {studioWorkerTask} from '../../loaders/studio/studioWorkerTask.js'\n\nconst schemaSchema = z.
|
|
1
|
+
{"version":3,"sources":["../../../src/config/studio/readStudioConfig.ts"],"sourcesContent":["import {dirname} from 'node:path'\n\nimport {z} from 'zod'\n\nimport {studioWorkerTask} from '../../loaders/studio/studioWorkerTask.js'\n\nconst schemaSchema = z.looseObject({\n name: z.string().optional(),\n types: z.array(z.looseObject({})),\n})\n\nconst sourceSchema = z.looseObject({\n dataset: z.string(),\n projectId: z.string(),\n schema: z.looseObject({_original: schemaSchema}),\n})\n\n// Raw workspace schema (resolvePlugins: false) - unstable_sources not yet populated\nconst rawWorkspaceSchema = z.looseObject({\n ...sourceSchema.shape,\n basePath: z.string().optional(),\n name: z.string().optional(),\n plugins: z.array(z.unknown()).optional(),\n schema: schemaSchema.optional(),\n title: z.string().optional(),\n unstable_sources: z.array(sourceSchema).optional(),\n})\n\n// Resolved config schema (resolvePlugins: true) - all fields required\nconst resolvedWorkspaceSchema = z.looseObject({\n ...sourceSchema.shape,\n basePath: z.string(),\n name: z.string(),\n plugins: z.array(z.unknown()).optional(),\n title: z.string(),\n unstable_sources: z.array(sourceSchema),\n})\n\nconst rawConfigSchema = z.union([z.array(rawWorkspaceSchema), rawWorkspaceSchema])\nconst resolvedConfigSchema = z.array(resolvedWorkspaceSchema)\n\nexport type RawStudioConfig = z.infer<typeof rawConfigSchema>\nexport type ResolvedStudioConfig = z.infer<typeof resolvedConfigSchema>\n\nexport interface ReadStudioConfigOptions {\n /**\n * Whether or not to resolve the plugins defined in the config.\n *\n * In some cases, you need this in order to have the full picture of what the studio\n * would \"see\". As an example, plugins can define schema types that are not explicitly\n * defined in the users' schema types. In order to get the full picture, you need to\n * resolve the plugins, which is an asyncronous operation.\n *\n * In other cases, it might be enough to only do a shallow pass. As an example, if you\n * only need to know about the defined workspace, or the user-defined schema types,\n * this can be set to `false` - which should resolve faster (and potentially \"safer\")\n * in terms of not triggering all kinds of browser behavior that may or may not be\n * loaded as the plugins are resolved.\n */\n resolvePlugins: boolean\n}\n\nexport async function readStudioConfig(\n configPath: string,\n options: {resolvePlugins: true},\n): Promise<ResolvedStudioConfig>\n\nexport async function readStudioConfig(\n configPath: string,\n options: {resolvePlugins: false},\n): Promise<RawStudioConfig>\n\nexport async function readStudioConfig(\n configPath: string,\n options: ReadStudioConfigOptions,\n): Promise<RawStudioConfig | ResolvedStudioConfig> {\n const result = await studioWorkerTask(new URL('readStudioConfig.worker.js', import.meta.url), {\n name: 'studioConfig',\n studioRootPath: dirname(configPath),\n workerData: {configPath, resolvePlugins: options.resolvePlugins},\n })\n\n try {\n return options.resolvePlugins\n ? resolvedConfigSchema.parse(result)\n : rawConfigSchema.parse(result)\n } catch (err) {\n if (err instanceof z.ZodError) {\n throw new Error(`Invalid studio config at ${configPath}:\\n${formatZodIssues(err.issues)}`)\n }\n\n throw err\n }\n}\n\n/**\n * Recursively extracts leaf-level messages from Zod issues, including\n * those nested inside union errors. Note that `prettifyError` from Zod\n * only gives a high-level summary for union errors, so this function is\n * needed to get the full details of all validation issues in a readable format.\n *\n * @internal exported for testing only\n */\nexport function formatZodIssues(issues: z.core.$ZodIssue[], indent = 2): string {\n const lines: string[] = []\n const prefix = ' '.repeat(indent)\n\n for (const issue of issues) {\n if (issue.code === 'invalid_union' && 'errors' in issue && Array.isArray(issue.errors)) {\n for (const [i, unionIssues] of issue.errors.entries()) {\n lines.push(`${prefix}Union option ${i + 1}:`, formatZodIssues(unionIssues, indent + 2))\n }\n } else {\n const path = issue.path.length > 0 ? ` at \"${issue.path.join('.')}\"` : ''\n lines.push(`${prefix}- ${issue.message}${path}`)\n }\n }\n\n return lines.join('\\n')\n}\n"],"names":["dirname","z","studioWorkerTask","schemaSchema","looseObject","name","string","optional","types","array","sourceSchema","dataset","projectId","schema","_original","rawWorkspaceSchema","shape","basePath","plugins","unknown","title","unstable_sources","resolvedWorkspaceSchema","rawConfigSchema","union","resolvedConfigSchema","readStudioConfig","configPath","options","result","URL","url","studioRootPath","workerData","resolvePlugins","parse","err","ZodError","Error","formatZodIssues","issues","indent","lines","prefix","repeat","issue","code","Array","isArray","errors","i","unionIssues","entries","push","path","length","join","message"],"mappings":"AAAA,SAAQA,OAAO,QAAO,YAAW;AAEjC,SAAQC,CAAC,QAAO,MAAK;AAErB,SAAQC,gBAAgB,QAAO,2CAA0C;AAEzE,MAAMC,eAAeF,EAAEG,WAAW,CAAC;IACjCC,MAAMJ,EAAEK,MAAM,GAAGC,QAAQ;IACzBC,OAAOP,EAAEQ,KAAK,CAACR,EAAEG,WAAW,CAAC,CAAC;AAChC;AAEA,MAAMM,eAAeT,EAAEG,WAAW,CAAC;IACjCO,SAASV,EAAEK,MAAM;IACjBM,WAAWX,EAAEK,MAAM;IACnBO,QAAQZ,EAAEG,WAAW,CAAC;QAACU,WAAWX;IAAY;AAChD;AAEA,oFAAoF;AACpF,MAAMY,qBAAqBd,EAAEG,WAAW,CAAC;IACvC,GAAGM,aAAaM,KAAK;IACrBC,UAAUhB,EAAEK,MAAM,GAAGC,QAAQ;IAC7BF,MAAMJ,EAAEK,MAAM,GAAGC,QAAQ;IACzBW,SAASjB,EAAEQ,KAAK,CAACR,EAAEkB,OAAO,IAAIZ,QAAQ;IACtCM,QAAQV,aAAaI,QAAQ;IAC7Ba,OAAOnB,EAAEK,MAAM,GAAGC,QAAQ;IAC1Bc,kBAAkBpB,EAAEQ,KAAK,CAACC,cAAcH,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AM,CAACC,GAAGC,YAAY,IAAIN,MAAMI,MAAM,CAACG,OAAO,GAAI;gBACrDV,MAAMW,IAAI,CAAC,GAAGV,OAAO,aAAa,EAAEO,IAAI,EAAE,CAAC,CAAC,EAAEX,gBAAgBY,aAAaV,SAAS;YACtF;QACF,OAAO;YACL,MAAMa,OAAOT,MAAMS,IAAI,CAACC,MAAM,GAAG,IAAI,CAAC,KAAK,EAAEV,MAAMS,IAAI,CAACE,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG;YACvEd,MAAMW,IAAI,CAAC,GAAGV,OAAO,EAAE,EAAEE,MAAMY,OAAO,GAAGH,MAAM;QACjD;IACF;IAEA,OAAOZ,MAAMc,IAAI,CAAC;AACpB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -786,47 +786,46 @@ declare const rawConfigSchema: z.ZodUnion<
|
|
|
786
786
|
z.ZodArray<
|
|
787
787
|
z.ZodObject<
|
|
788
788
|
{
|
|
789
|
-
basePath: z.ZodString
|
|
790
|
-
name: z.ZodString
|
|
789
|
+
basePath: z.ZodOptional<z.ZodString>;
|
|
790
|
+
name: z.ZodOptional<z.ZodString>;
|
|
791
791
|
plugins: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
|
|
792
|
-
|
|
793
|
-
unstable_sources: z.ZodArray<
|
|
792
|
+
schema: z.ZodOptional<
|
|
794
793
|
z.ZodObject<
|
|
795
794
|
{
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
schema: z.ZodObject<
|
|
799
|
-
{
|
|
800
|
-
_original: z.ZodObject<
|
|
801
|
-
{
|
|
802
|
-
name: z.ZodOptional<z.ZodString>;
|
|
803
|
-
types: z.ZodArray<z.ZodObject<{}, z.core.$loose>>;
|
|
804
|
-
},
|
|
805
|
-
z.core.$strip
|
|
806
|
-
>;
|
|
807
|
-
},
|
|
808
|
-
z.core.$strip
|
|
809
|
-
>;
|
|
795
|
+
name: z.ZodOptional<z.ZodString>;
|
|
796
|
+
types: z.ZodArray<z.ZodObject<{}, z.core.$loose>>;
|
|
810
797
|
},
|
|
811
|
-
z.core.$
|
|
798
|
+
z.core.$loose
|
|
812
799
|
>
|
|
813
800
|
>;
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
_original: z.ZodObject<
|
|
801
|
+
title: z.ZodOptional<z.ZodString>;
|
|
802
|
+
unstable_sources: z.ZodOptional<
|
|
803
|
+
z.ZodArray<
|
|
804
|
+
z.ZodObject<
|
|
819
805
|
{
|
|
820
|
-
|
|
821
|
-
|
|
806
|
+
dataset: z.ZodString;
|
|
807
|
+
projectId: z.ZodString;
|
|
808
|
+
schema: z.ZodObject<
|
|
809
|
+
{
|
|
810
|
+
_original: z.ZodObject<
|
|
811
|
+
{
|
|
812
|
+
name: z.ZodOptional<z.ZodString>;
|
|
813
|
+
types: z.ZodArray<z.ZodObject<{}, z.core.$loose>>;
|
|
814
|
+
},
|
|
815
|
+
z.core.$loose
|
|
816
|
+
>;
|
|
817
|
+
},
|
|
818
|
+
z.core.$loose
|
|
819
|
+
>;
|
|
822
820
|
},
|
|
823
|
-
z.core.$
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
z.core.$strip
|
|
821
|
+
z.core.$loose
|
|
822
|
+
>
|
|
823
|
+
>
|
|
827
824
|
>;
|
|
825
|
+
dataset: z.ZodString;
|
|
826
|
+
projectId: z.ZodString;
|
|
828
827
|
},
|
|
829
|
-
z.core.$
|
|
828
|
+
z.core.$loose
|
|
830
829
|
>
|
|
831
830
|
>,
|
|
832
831
|
z.ZodObject<
|
|
@@ -840,29 +839,31 @@ declare const rawConfigSchema: z.ZodUnion<
|
|
|
840
839
|
name: z.ZodOptional<z.ZodString>;
|
|
841
840
|
types: z.ZodArray<z.ZodObject<{}, z.core.$loose>>;
|
|
842
841
|
},
|
|
843
|
-
z.core.$
|
|
842
|
+
z.core.$loose
|
|
844
843
|
>
|
|
845
844
|
>;
|
|
846
845
|
title: z.ZodOptional<z.ZodString>;
|
|
847
|
-
unstable_sources: z.
|
|
848
|
-
z.
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
846
|
+
unstable_sources: z.ZodOptional<
|
|
847
|
+
z.ZodArray<
|
|
848
|
+
z.ZodObject<
|
|
849
|
+
{
|
|
850
|
+
dataset: z.ZodString;
|
|
851
|
+
projectId: z.ZodString;
|
|
852
|
+
schema: z.ZodObject<
|
|
853
|
+
{
|
|
854
|
+
_original: z.ZodObject<
|
|
855
|
+
{
|
|
856
|
+
name: z.ZodOptional<z.ZodString>;
|
|
857
|
+
types: z.ZodArray<z.ZodObject<{}, z.core.$loose>>;
|
|
858
|
+
},
|
|
859
|
+
z.core.$loose
|
|
860
|
+
>;
|
|
861
|
+
},
|
|
862
|
+
z.core.$loose
|
|
863
|
+
>;
|
|
864
|
+
},
|
|
865
|
+
z.core.$loose
|
|
866
|
+
>
|
|
866
867
|
>
|
|
867
868
|
>;
|
|
868
869
|
dataset: z.ZodString;
|
|
@@ -928,13 +929,13 @@ declare const resolvedConfigSchema: z.ZodArray<
|
|
|
928
929
|
name: z.ZodOptional<z.ZodString>;
|
|
929
930
|
types: z.ZodArray<z.ZodObject<{}, z.core.$loose>>;
|
|
930
931
|
},
|
|
931
|
-
z.core.$
|
|
932
|
+
z.core.$loose
|
|
932
933
|
>;
|
|
933
934
|
},
|
|
934
|
-
z.core.$
|
|
935
|
+
z.core.$loose
|
|
935
936
|
>;
|
|
936
937
|
},
|
|
937
|
-
z.core.$
|
|
938
|
+
z.core.$loose
|
|
938
939
|
>
|
|
939
940
|
>;
|
|
940
941
|
dataset: z.ZodString;
|
|
@@ -946,13 +947,13 @@ declare const resolvedConfigSchema: z.ZodArray<
|
|
|
946
947
|
name: z.ZodOptional<z.ZodString>;
|
|
947
948
|
types: z.ZodArray<z.ZodObject<{}, z.core.$loose>>;
|
|
948
949
|
},
|
|
949
|
-
z.core.$
|
|
950
|
+
z.core.$loose
|
|
950
951
|
>;
|
|
951
952
|
},
|
|
952
|
-
z.core.$
|
|
953
|
+
z.core.$loose
|
|
953
954
|
>;
|
|
954
955
|
},
|
|
955
|
-
z.core.$
|
|
956
|
+
z.core.$loose
|
|
956
957
|
>
|
|
957
958
|
>;
|
|
958
959
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/cli-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Sanity CLI core package",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -86,8 +86,8 @@
|
|
|
86
86
|
"sanity": "^5.17.1",
|
|
87
87
|
"typescript": "^5.9.3",
|
|
88
88
|
"vitest": "^4.1.0",
|
|
89
|
-
"@repo/package.config": "0.0.1",
|
|
90
89
|
"@repo/tsconfig": "3.70.0",
|
|
90
|
+
"@repo/package.config": "0.0.1",
|
|
91
91
|
"@sanity/eslint-config-cli": "1.0.1"
|
|
92
92
|
},
|
|
93
93
|
"peerDependencies": {
|