@sanity/cli 5.8.0-next.63 → 5.8.0-next.65

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.
package/lib/index.d.ts CHANGED
@@ -178,7 +178,14 @@ export declare interface CliConfig {
178
178
  /**
179
179
  * Configuration for Sanity typegen
180
180
  */
181
- typegen?: Partial<TypeGenConfig>
181
+ typegen?: Partial<TypeGenConfig> & {
182
+ /**
183
+ * Enable typegen as part of sanity dev and sanity build.
184
+ * When enabled, types are generated on startup and when files change.
185
+ * Defaults to `false`
186
+ */
187
+ enabled?: boolean
188
+ }
182
189
  /**
183
190
  * Configuration for schema extraction (`sanity schema extract`)
184
191
  */
@@ -13,7 +13,7 @@ async function main({
13
13
  workDir,
14
14
  overloadClientMethods
15
15
  }) {
16
- const report = workerChannels.WorkerChannelReporter.from(node_worker_threads.parentPort), fullPath = path__default.default.join(workDir, schemaPath);
16
+ const report = workerChannels.WorkerChannelReporter.from(node_worker_threads.parentPort), fullPath = path__default.default.isAbsolute(schemaPath) ? schemaPath : path__default.default.join(workDir, schemaPath);
17
17
  try {
18
18
  if (!(await fs.stat(fullPath)).isFile())
19
19
  throw new Error(`Schema path is not a file: ${schemaPath}`);
@@ -1 +1 @@
1
- {"version":3,"file":"typegenGenerate.js","sources":["../../src/workers/typegenGenerate.ts"],"sourcesContent":["import {stat} from 'node:fs/promises'\nimport path from 'node:path'\nimport {isMainThread, parentPort, workerData} from 'node:worker_threads'\n\nimport {\n findQueriesInPath,\n getResolver,\n readSchema,\n registerBabel,\n TypeGenerator,\n type TypegenWorkerChannel as CodegenTypegenWorkerChannel,\n} from '@sanity/codegen'\nimport {type WorkerChannel, WorkerChannelReporter} from '@sanity/worker-channels'\n\nexport interface TypegenGenerateTypesWorkerData {\n workDir: string\n schemaPath: string\n searchPath: string | string[]\n overloadClientMethods?: boolean\n}\n\nif (isMainThread || !parentPort) {\n throw new Error('This module must be run as a worker thread')\n}\n\nregisterBabel()\n\nexport type TypegenWorkerChannel = WorkerChannel.Definition<\n {\n loadedSchema: WorkerChannel.Event\n typegenStarted: WorkerChannel.Event<{expectedFileCount: number}>\n typegenComplete: WorkerChannel.Event<{code: string}>\n } & CodegenTypegenWorkerChannel['__definition']\n>\n\nasync function main({\n schemaPath,\n searchPath,\n workDir,\n overloadClientMethods,\n}: TypegenGenerateTypesWorkerData) {\n const report = WorkerChannelReporter.from<TypegenWorkerChannel>(parentPort)\n\n const fullPath = path.join(workDir, schemaPath)\n\n try {\n const schemaStats = await stat(fullPath)\n if (!schemaStats.isFile()) {\n throw new Error(`Schema path is not a file: ${schemaPath}`)\n }\n } catch (err) {\n if (err.code === 'ENOENT') {\n // If the user has not provided a specific schema path (eg we're using the default), give some help\n const hint = schemaPath === './schema.json' ? ` - did you run \"sanity schema extract\"?` : ''\n throw new Error(`Schema file not found: ${fullPath}${hint}`, {cause: err})\n }\n throw err\n }\n\n const schema = await readSchema(fullPath)\n\n report.event.loadedSchema()\n\n const typeGenerator = new TypeGenerator()\n\n const {files, queries} = findQueriesInPath({\n path: searchPath,\n resolver: getResolver(workDir),\n })\n report.event.typegenStarted({expectedFileCount: files.length})\n\n const result = await typeGenerator.generateTypes({\n queries,\n schema,\n reporter: report,\n schemaPath,\n root: workDir,\n overloadClientMethods,\n })\n report.event.typegenComplete(result)\n}\n\nmain(workerData).catch((err) => {\n // worker will terminate and parent will catch the error\n throw err\n})\n"],"names":["isMainThread","parentPort","registerBabel","WorkerChannelReporter","path","stat","readSchema","TypeGenerator","findQueriesInPath","getResolver","workerData"],"mappings":";;;;;;AAqBA,IAAIA,oBAAAA,gBAAgB,CAACC,oBAAAA;AACnB,QAAM,IAAI,MAAM,4CAA4C;AAG9DC,QAAAA,cAAA;AAUA,eAAe,KAAK;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAmC;AACjC,QAAM,SAASC,qCAAsB,KAA2BF,oBAAAA,UAAU,GAEpE,WAAWG,sBAAK,KAAK,SAAS,UAAU;AAE9C,MAAI;AAEF,QAAI,EADgB,MAAMC,GAAAA,KAAK,QAAQ,GACtB,OAAA;AACf,YAAM,IAAI,MAAM,8BAA8B,UAAU,EAAE;AAAA,EAE9D,SAAS,KAAK;AACZ,QAAI,IAAI,SAAS,UAAU;AAEzB,YAAM,OAAO,eAAe,kBAAkB,4CAA4C;AAC1F,YAAM,IAAI,MAAM,0BAA0B,QAAQ,GAAG,IAAI,IAAI,EAAC,OAAO,KAAI;AAAA,IAC3E;AACA,UAAM;AAAA,EACR;AAEA,QAAM,SAAS,MAAMC,QAAAA,WAAW,QAAQ;AAExC,SAAO,MAAM,aAAA;AAEb,QAAM,gBAAgB,IAAIC,sBAAA,GAEpB,EAAC,OAAO,QAAA,IAAWC,0BAAkB;AAAA,IACzC,MAAM;AAAA,IACN,UAAUC,QAAAA,YAAY,OAAO;AAAA,EAAA,CAC9B;AACD,SAAO,MAAM,eAAe,EAAC,mBAAmB,MAAM,QAAO;AAE7D,QAAM,SAAS,MAAM,cAAc,cAAc;AAAA,IAC/C;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA,MAAM;AAAA,IACN;AAAA,EAAA,CACD;AACD,SAAO,MAAM,gBAAgB,MAAM;AACrC;AAEA,KAAKC,8BAAU,EAAE,MAAM,CAAC,QAAQ;AAE9B,QAAM;AACR,CAAC;"}
1
+ {"version":3,"file":"typegenGenerate.js","sources":["../../src/workers/typegenGenerate.ts"],"sourcesContent":["import {stat} from 'node:fs/promises'\nimport path from 'node:path'\nimport {isMainThread, parentPort, workerData} from 'node:worker_threads'\n\nimport {\n findQueriesInPath,\n getResolver,\n readSchema,\n registerBabel,\n TypeGenerator,\n type TypegenWorkerChannel as CodegenTypegenWorkerChannel,\n} from '@sanity/codegen'\nimport {type WorkerChannel, WorkerChannelReporter} from '@sanity/worker-channels'\n\nexport interface TypegenGenerateTypesWorkerData {\n workDir: string\n schemaPath: string\n searchPath: string | string[]\n overloadClientMethods?: boolean\n}\n\nif (isMainThread || !parentPort) {\n throw new Error('This module must be run as a worker thread')\n}\n\nregisterBabel()\n\nexport type TypegenWorkerChannel = WorkerChannel.Definition<\n {\n loadedSchema: WorkerChannel.Event\n typegenStarted: WorkerChannel.Event<{expectedFileCount: number}>\n typegenComplete: WorkerChannel.Event<{code: string}>\n } & CodegenTypegenWorkerChannel['__definition']\n>\n\nasync function main({\n schemaPath,\n searchPath,\n workDir,\n overloadClientMethods,\n}: TypegenGenerateTypesWorkerData) {\n const report = WorkerChannelReporter.from<TypegenWorkerChannel>(parentPort)\n\n const fullPath = path.isAbsolute(schemaPath) ? schemaPath : path.join(workDir, schemaPath)\n\n try {\n const schemaStats = await stat(fullPath)\n if (!schemaStats.isFile()) {\n throw new Error(`Schema path is not a file: ${schemaPath}`)\n }\n } catch (err) {\n if (err.code === 'ENOENT') {\n // If the user has not provided a specific schema path (eg we're using the default), give some help\n const hint = schemaPath === './schema.json' ? ` - did you run \"sanity schema extract\"?` : ''\n throw new Error(`Schema file not found: ${fullPath}${hint}`, {cause: err})\n }\n throw err\n }\n\n const schema = await readSchema(fullPath)\n\n report.event.loadedSchema()\n\n const typeGenerator = new TypeGenerator()\n\n const {files, queries} = findQueriesInPath({\n path: searchPath,\n resolver: getResolver(workDir),\n })\n report.event.typegenStarted({expectedFileCount: files.length})\n\n const result = await typeGenerator.generateTypes({\n queries,\n schema,\n reporter: report,\n schemaPath,\n root: workDir,\n overloadClientMethods,\n })\n report.event.typegenComplete(result)\n}\n\nmain(workerData).catch((err) => {\n // worker will terminate and parent will catch the error\n throw err\n})\n"],"names":["isMainThread","parentPort","registerBabel","WorkerChannelReporter","path","stat","readSchema","TypeGenerator","findQueriesInPath","getResolver","workerData"],"mappings":";;;;;;AAqBA,IAAIA,oBAAAA,gBAAgB,CAACC,oBAAAA;AACnB,QAAM,IAAI,MAAM,4CAA4C;AAG9DC,QAAAA,cAAA;AAUA,eAAe,KAAK;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAmC;AACjC,QAAM,SAASC,eAAAA,sBAAsB,KAA2BF,oBAAAA,UAAU,GAEpE,WAAWG,cAAAA,QAAK,WAAW,UAAU,IAAI,aAAaA,cAAAA,QAAK,KAAK,SAAS,UAAU;AAEzF,MAAI;AAEF,QAAI,EADgB,MAAMC,GAAAA,KAAK,QAAQ,GACtB,OAAA;AACf,YAAM,IAAI,MAAM,8BAA8B,UAAU,EAAE;AAAA,EAE9D,SAAS,KAAK;AACZ,QAAI,IAAI,SAAS,UAAU;AAEzB,YAAM,OAAO,eAAe,kBAAkB,4CAA4C;AAC1F,YAAM,IAAI,MAAM,0BAA0B,QAAQ,GAAG,IAAI,IAAI,EAAC,OAAO,KAAI;AAAA,IAC3E;AACA,UAAM;AAAA,EACR;AAEA,QAAM,SAAS,MAAMC,QAAAA,WAAW,QAAQ;AAExC,SAAO,MAAM,aAAA;AAEb,QAAM,gBAAgB,IAAIC,sBAAA,GAEpB,EAAC,OAAO,QAAA,IAAWC,0BAAkB;AAAA,IACzC,MAAM;AAAA,IACN,UAAUC,QAAAA,YAAY,OAAO;AAAA,EAAA,CAC9B;AACD,SAAO,MAAM,eAAe,EAAC,mBAAmB,MAAM,QAAO;AAE7D,QAAM,SAAS,MAAM,cAAc,cAAc;AAAA,IAC/C;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA,MAAM;AAAA,IACN;AAAA,EAAA,CACD;AACD,SAAO,MAAM,gBAAgB,MAAM;AACrC;AAEA,KAAKC,8BAAU,EAAE,MAAM,CAAC,QAAQ;AAE9B,QAAM;AACR,CAAC;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/cli",
3
- "version": "5.8.0-next.63+7c42b39eb4",
3
+ "version": "5.8.0-next.65+dc6baaed2d",
4
4
  "description": "Sanity CLI tool for managing Sanity installations, managing plugins, schemas and datasets",
5
5
  "keywords": [
6
6
  "sanity",
@@ -112,10 +112,10 @@
112
112
  "vitest": "^4.0.18",
113
113
  "which": "^2.0.2",
114
114
  "xdg-basedir": "^4.0.0",
115
- "@repo/eslint-config": "5.8.0-next.63+7c42b39eb4",
116
- "@repo/package.config": "5.8.0-next.63+7c42b39eb4",
117
- "@repo/test-config": "5.8.0-next.63+7c42b39eb4",
118
- "@repo/tsconfig": "5.8.0-next.63+7c42b39eb4",
115
+ "@repo/eslint-config": "5.8.0-next.65+dc6baaed2d",
116
+ "@repo/test-config": "5.8.0-next.65+dc6baaed2d",
117
+ "@repo/package.config": "5.8.0-next.65+dc6baaed2d",
118
+ "@repo/tsconfig": "5.8.0-next.65+dc6baaed2d",
119
119
  "@sanity/types": "5.7.0"
120
120
  },
121
121
  "peerDependencies": {