@sanity/codegen 5.9.0 → 5.9.1
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/dist/actions/streamProcessor.js +3 -2
- package/dist/actions/streamProcessor.js.map +1 -1
- package/dist/actions/typegenGenerate.js +1 -1
- package/dist/actions/typegenGenerate.js.map +1 -1
- package/dist/actions/typegenGenerate.worker.js +2 -2
- package/dist/actions/typegenGenerate.worker.js.map +1 -1
- package/dist/actions/typegenWatch.js +9 -4
- package/dist/actions/typegenWatch.js.map +1 -1
- package/dist/commands/typegen/generate.js +56 -47
- package/dist/commands/typegen/generate.js.map +1 -1
- package/dist/utils/debug.js +4 -0
- package/dist/utils/debug.js.map +1 -0
- package/oclif.manifest.json +1 -1
- package/package.json +5 -2
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { debug } from 'node:console';
|
|
2
1
|
import { writeFile } from 'node:fs/promises';
|
|
3
2
|
import { spinner } from '@sanity/cli-core/ux';
|
|
4
3
|
import { format, resolveConfig as resolvePrettierConfig } from 'prettier';
|
|
5
4
|
import { count } from '../utils/count.js';
|
|
5
|
+
import { debug } from '../utils/debug.js';
|
|
6
6
|
import { formatPath } from '../utils/formatPath.js';
|
|
7
7
|
import { getMessage } from '../utils/getMessage.js';
|
|
8
8
|
import { percent } from '../utils/percent.js';
|
|
@@ -20,8 +20,8 @@ import { generatedFileWarning } from './generatedFileWarning.js';
|
|
|
20
20
|
const start = Date.now();
|
|
21
21
|
const { formatGeneratedCode, generates, schema } = options;
|
|
22
22
|
let code = '';
|
|
23
|
+
const spin = spinner().start(`Loading schema…`);
|
|
23
24
|
try {
|
|
24
|
-
const spin = spinner().start(`Loading schema…`);
|
|
25
25
|
await receiver.event.loadedSchema();
|
|
26
26
|
spin.succeed(`Schema loaded from ${formatPath(schema ?? '')}`);
|
|
27
27
|
spin.start('Generating schema types…');
|
|
@@ -97,6 +97,7 @@ import { generatedFileWarning } from './generatedFileWarning.js';
|
|
|
97
97
|
code
|
|
98
98
|
};
|
|
99
99
|
} catch (err) {
|
|
100
|
+
spin.fail();
|
|
100
101
|
debug('error generating types', err);
|
|
101
102
|
throw err;
|
|
102
103
|
} finally{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/actions/streamProcessor.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../src/actions/streamProcessor.ts"],"sourcesContent":["import {writeFile} from 'node:fs/promises'\n\nimport {spinner} from '@sanity/cli-core/ux'\nimport {WorkerChannelReceiver} from '@sanity/worker-channels'\nimport {format, resolveConfig as resolvePrettierConfig} from 'prettier'\n\nimport {TypeGenConfig} from '../readConfig.js'\nimport {count} from '../utils/count.js'\nimport {debug} from '../utils/debug.js'\nimport {formatPath} from '../utils/formatPath.js'\nimport {getMessage} from '../utils/getMessage.js'\nimport {percent} from '../utils/percent.js'\nimport {generatedFileWarning} from './generatedFileWarning.js'\nimport {TypegenWorkerChannel} from './types.js'\n\n/**\n * Processes the event stream from a typegen worker thread.\n *\n * Listens to worker channel events, displays progress via CLI spinners,\n * writes the generated types to disk, and optionally formats with prettier.\n *\n * @param receiver - Worker channel receiver for typegen events\n * @param options - Typegen configuration options\n * @returns Generation result containing the generated code and statistics\n */\nexport async function processTypegenWorkerStream(\n receiver: WorkerChannelReceiver<TypegenWorkerChannel>,\n options: TypeGenConfig,\n) {\n const start = Date.now()\n const {formatGeneratedCode, generates, schema} = options\n let code = ''\n\n const spin = spinner().start(`Loading schema…`)\n\n try {\n await receiver.event.loadedSchema()\n spin.succeed(`Schema loaded from ${formatPath(schema ?? '')}`)\n\n spin.start('Generating schema types…')\n const {expectedFileCount} = await receiver.event.typegenStarted()\n const {schemaTypeDeclarations} = await receiver.event.generatedSchemaTypes()\n const schemaTypesCount = schemaTypeDeclarations.length\n\n spin.text = 'Generating query types…'\n\n let queriesCount = 0\n let evaluatedFiles = 0\n let filesWithErrors = 0\n let queryFilesCount = 0\n let typeNodesGenerated = 0\n let unknownTypeNodesGenerated = 0\n let emptyUnionTypeNodesGenerated = 0\n\n for await (const {errors, queries} of receiver.stream.evaluatedModules()) {\n evaluatedFiles++\n queriesCount += queries.length\n queryFilesCount += queries.length > 0 ? 1 : 0\n filesWithErrors += errors.length > 0 ? 1 : 0\n\n for (const {stats} of queries) {\n typeNodesGenerated += stats.allTypes\n unknownTypeNodesGenerated += stats.unknownTypes\n emptyUnionTypeNodesGenerated += stats.emptyUnions\n }\n\n for (const error of errors) {\n spin.fail(getMessage(error))\n }\n\n if (!spin.isSpinning) {\n spin.start()\n }\n\n spin.text =\n `Generating query types… (${percent(evaluatedFiles / expectedFileCount)})\\n` +\n ` └─ Processed ${count(evaluatedFiles)} of ${count(expectedFileCount, 'files')}. ` +\n `Found ${count(queriesCount, 'queries', 'query')} from ${count(queryFilesCount, 'files')}.`\n }\n\n const result = await receiver.event.typegenComplete()\n code = `${generatedFileWarning}${result.code}`\n await writeFile(generates, code)\n\n let formattingError = false\n if (formatGeneratedCode) {\n spin.text = `Formatting generated types with prettier…`\n\n try {\n const prettierConfig = await resolvePrettierConfig(generates)\n const formattedCode = await format(code, {\n ...prettierConfig,\n parser: 'typescript' as const,\n })\n await writeFile(generates, formattedCode)\n } catch (err) {\n formattingError = true\n spin.warn(`Failed to format generated types with prettier: ${getMessage(err)}`)\n }\n }\n\n if (filesWithErrors > 0) {\n spin.warn(`Encountered errors in ${count(filesWithErrors, 'files')} while generating types`)\n }\n\n const stats = {\n duration: Date.now() - start,\n emptyUnionTypeNodesGenerated,\n filesWithErrors,\n outputSize: Buffer.byteLength(code),\n queriesCount,\n queryFilesCount,\n schemaTypesCount,\n typeNodesGenerated,\n unknownTypeNodesGenerated,\n unknownTypeNodesRatio:\n typeNodesGenerated > 0 ? unknownTypeNodesGenerated / typeNodesGenerated : 0,\n }\n\n let successText =\n `Successfully generated types to ${formatPath(generates)} in ${Number(stats.duration).toFixed(0)}ms` +\n `\\n └─ ${count(queriesCount, 'queries', 'query')} and ${count(schemaTypesCount, 'schema types', 'schema type')}` +\n `\\n └─ found queries in ${count(queryFilesCount, 'files', 'file')} after evaluating ${count(evaluatedFiles, 'files', 'file')}`\n\n if (formatGeneratedCode) {\n successText += `\\n └─ ${formattingError ? 'an error occured during formatting' : 'formatted the generated code with prettier'}`\n }\n\n spin.succeed(successText)\n\n return {\n ...stats,\n code,\n }\n } catch (err) {\n spin.fail()\n debug('error generating types', err)\n throw err\n } finally {\n receiver.unsubscribe()\n }\n}\n"],"names":["writeFile","spinner","format","resolveConfig","resolvePrettierConfig","count","debug","formatPath","getMessage","percent","generatedFileWarning","processTypegenWorkerStream","receiver","options","start","Date","now","formatGeneratedCode","generates","schema","code","spin","event","loadedSchema","succeed","expectedFileCount","typegenStarted","schemaTypeDeclarations","generatedSchemaTypes","schemaTypesCount","length","text","queriesCount","evaluatedFiles","filesWithErrors","queryFilesCount","typeNodesGenerated","unknownTypeNodesGenerated","emptyUnionTypeNodesGenerated","errors","queries","stream","evaluatedModules","stats","allTypes","unknownTypes","emptyUnions","error","fail","isSpinning","result","typegenComplete","formattingError","prettierConfig","formattedCode","parser","err","warn","duration","outputSize","Buffer","byteLength","unknownTypeNodesRatio","successText","Number","toFixed","unsubscribe"],"mappings":"AAAA,SAAQA,SAAS,QAAO,mBAAkB;AAE1C,SAAQC,OAAO,QAAO,sBAAqB;AAE3C,SAAQC,MAAM,EAAEC,iBAAiBC,qBAAqB,QAAO,WAAU;AAGvE,SAAQC,KAAK,QAAO,oBAAmB;AACvC,SAAQC,KAAK,QAAO,oBAAmB;AACvC,SAAQC,UAAU,QAAO,yBAAwB;AACjD,SAAQC,UAAU,QAAO,yBAAwB;AACjD,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,SAAQC,oBAAoB,QAAO,4BAA2B;AAG9D;;;;;;;;;CASC,GACD,OAAO,eAAeC,2BACpBC,QAAqD,EACrDC,OAAsB;IAEtB,MAAMC,QAAQC,KAAKC,GAAG;IACtB,MAAM,EAACC,mBAAmB,EAA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AAS,KAAK,EAAE3B,MAAMwB,kBAAkB,gBAAgB,gBAAgB,GACjH,CAAC,wBAAwB,EAAExB,MAAM8B,iBAAiB,SAAS,QAAQ,kBAAkB,EAAE9B,MAAM4B,gBAAgB,SAAS,SAAS;QAEjI,IAAIhB,qBAAqB;YACvB8C,eAAe,CAAC,OAAO,EAAEX,kBAAkB,uCAAuC,8CAA8C;QAClI;QAEA/B,KAAKG,OAAO,CAACuC;QAEb,OAAO;YACL,GAAGpB,KAAK;YACRvB;QACF;IACF,EAAE,OAAOoC,KAAK;QACZnC,KAAK2B,IAAI;QACT1C,MAAM,0BAA0BkD;QAChC,MAAMA;IACR,SAAU;QACR5C,SAASsD,WAAW;IACtB;AACF"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { debug } from 'node:console';
|
|
2
1
|
import { mkdir } from 'node:fs/promises';
|
|
3
2
|
import { dirname, isAbsolute, join } from 'node:path';
|
|
4
3
|
import { env } from 'node:process';
|
|
5
4
|
import { Worker } from 'node:worker_threads';
|
|
6
5
|
import { WorkerChannelReceiver } from '@sanity/worker-channels';
|
|
7
6
|
import { prepareConfig } from '../utils/config.js';
|
|
7
|
+
import { debug } from '../utils/debug.js';
|
|
8
8
|
import { processTypegenWorkerStream } from './streamProcessor.js';
|
|
9
9
|
/**
|
|
10
10
|
* Runs a single typegen generation.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/actions/typegenGenerate.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../src/actions/typegenGenerate.ts"],"sourcesContent":["import {mkdir} from 'node:fs/promises'\nimport {dirname, isAbsolute, join} from 'node:path'\nimport {env} from 'node:process'\nimport {Worker} from 'node:worker_threads'\n\nimport {WorkerChannelReceiver} from '@sanity/worker-channels'\n\nimport {prepareConfig} from '../utils/config.js'\nimport {debug} from '../utils/debug.js'\nimport {processTypegenWorkerStream} from './streamProcessor.js'\nimport {\n type GenerationResult,\n type RunTypegenOptions,\n TypegenGenerateTypesWorkerData,\n TypegenWorkerChannel,\n} from './types.js'\n\n/**\n * Runs a single typegen generation.\n *\n * This is the programmatic API for generating TypeScript types from GROQ queries.\n * It spawns a worker thread to perform the generation and displays progress via CLI spinners.\n *\n * @param options - Configuration options including typegen config and working directory\n * @returns Generation result containing the generated code and statistics\n */\nexport async function runTypegenGenerate(options: RunTypegenOptions): Promise<GenerationResult> {\n const {config, workDir} = options\n\n const {formatGeneratedCode, generates, overloadClientMethods, path, schema} =\n prepareConfig(config)\n\n const outputPath = isAbsolute(generates) ? generates : join(workDir, generates)\n\n // create output dir if it isn't there\n const outputDir = dirname(outputPath)\n await mkdir(outputDir, {recursive: true})\n\n // set up worker\n const workerPath = new URL('../actions/typegenGenerate.worker.js', import.meta.url)\n const workerData: TypegenGenerateTypesWorkerData = {\n overloadClientMethods,\n schemaPath: schema,\n searchPath: path,\n workDir,\n }\n const worker = new Worker(workerPath, {env, workerData})\n\n try {\n const result = await processTypegenWorkerStream(\n WorkerChannelReceiver.from<TypegenWorkerChannel>(worker),\n {\n formatGeneratedCode,\n generates: outputPath,\n overloadClientMethods,\n path,\n schema,\n },\n )\n\n return result\n } catch (err) {\n debug('error generating types', err)\n throw err\n } finally {\n worker.terminate()\n }\n}\n"],"names":["mkdir","dirname","isAbsolute","join","env","Worker","WorkerChannelReceiver","prepareConfig","debug","processTypegenWorkerStream","runTypegenGenerate","options","config","workDir","formatGeneratedCode","generates","overloadClientMethods","path","schema","outputPath","outputDir","recursive","workerPath","URL","url","workerData","schemaPath","searchPath","worker","result","from","err","terminate"],"mappings":"AAAA,SAAQA,KAAK,QAAO,mBAAkB;AACtC,SAAQC,OAAO,EAAEC,UAAU,EAAEC,IAAI,QAAO,YAAW;AACnD,SAAQC,GAAG,QAAO,eAAc;AAChC,SAAQC,MAAM,QAAO,sBAAqB;AAE1C,SAAQC,qBAAqB,QAAO,0BAAyB;AAE7D,SAAQC,aAAa,QAAO,qBAAoB;AAChD,SAAQC,KAAK,QAAO,oBAAmB;AACvC,SAAQC,0BAA0B,QAAO,uBAAsB;AAQ/D;;;;;;;;CAQC,GACD,OAAO,eAAeC,mBAAmBC,OAA0B;IACjE,MAAM,EAACC,MAAM,EAAEC,OAAO,EAAC,GAAGF;IAE1B,MAAM,EAACG,mBAAmB,EAAEC,SAAS,EAAEC,qBAAqB,EAAEC,IAAI,EAAEC,MAAM,EAAC,GACzEX,cAAcK;IAEhB,MAAMO,aAAajB,WAAWa,aAAaA,YAAYZ,KAAKU,SAASE;IAErE,sCAAsC;IACtC,MAAMK,YAAYnB,QAAQkB;IAC1B,MAAMnB,MAAMoB,WAAW;QAACC,WAAW;IAAI;IAEvC,gBAAgB;IAChB,MAAMC,aAAa,IAAIC,IAAI,wCAAwC,YAAYC,GAAG;IAClF,MAAMC,aAA6C;QACjDT;QACAU,YAAYR;QACZS,YAAYV;QACZJ;IACF;IACA,MAAMe,SAAS,IAAIvB,OAAOiB,YAAY;QAAClB;QAAKqB;IAAU;IAEtD,IAAI;QACF,MAAMI,SAAS,MAAMpB,2BACnBH,sBAAsBwB,IAAI,CAAuBF,SACjD;YACEd;YACAC,WAAWI;YACXH;YACAC;YACAC;QACF;QAGF,OAAOW;IACT,EAAE,OAAOE,KAAK;QACZvB,MAAM,0BAA0BuB;QAChC,MAAMA;IACR,SAAU;QACRH,OAAOI,SAAS;IAClB;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { stat } from 'node:fs/promises';
|
|
2
|
-
import
|
|
2
|
+
import { isAbsolute, join } from 'node:path';
|
|
3
3
|
import { isMainThread, parentPort, workerData } from 'node:worker_threads';
|
|
4
4
|
import { WorkerChannelReporter } from '@sanity/worker-channels';
|
|
5
5
|
import { readSchema } from '../readSchema.js';
|
|
@@ -13,7 +13,7 @@ if (isMainThread || !parentPort) {
|
|
|
13
13
|
registerBabel();
|
|
14
14
|
async function main({ overloadClientMethods, schemaPath, searchPath, workDir }) {
|
|
15
15
|
const report = WorkerChannelReporter.from(parentPort);
|
|
16
|
-
const fullPath =
|
|
16
|
+
const fullPath = isAbsolute(schemaPath) ? schemaPath : join(workDir, schemaPath);
|
|
17
17
|
try {
|
|
18
18
|
const schemaStats = await stat(fullPath);
|
|
19
19
|
if (!schemaStats.isFile()) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/actions/typegenGenerate.worker.ts"],"sourcesContent":["import {stat} from 'node:fs/promises'\nimport
|
|
1
|
+
{"version":3,"sources":["../../src/actions/typegenGenerate.worker.ts"],"sourcesContent":["import {stat} from 'node:fs/promises'\nimport {isAbsolute, join} from 'node:path'\nimport {isMainThread, parentPort, workerData} from 'node:worker_threads'\n\nimport {WorkerChannelReporter} from '@sanity/worker-channels'\n\nimport {readSchema} from '../readSchema.js'\nimport {findQueriesInPath} from '../typescript/findQueriesInPath.js'\nimport {getResolver} from '../typescript/moduleResolver.js'\nimport {registerBabel} from '../typescript/registerBabel.js'\nimport {TypeGenerator} from '../typescript/typeGenerator.js'\nimport {TypegenGenerateTypesWorkerData, TypegenWorkerChannel} from './types.js'\n\nif (isMainThread || !parentPort) {\n throw new Error('This module must be run as a worker thread')\n}\n\nregisterBabel()\n\nasync function main({\n overloadClientMethods,\n schemaPath,\n searchPath,\n workDir,\n}: TypegenGenerateTypesWorkerData) {\n const report = WorkerChannelReporter.from<TypegenWorkerChannel>(parentPort)\n\n const fullPath = isAbsolute(schemaPath) ? schemaPath : 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 instanceof Error && 'code' in err && 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 overloadClientMethods,\n queries,\n reporter: report,\n root: workDir,\n schema,\n schemaPath,\n })\n report.event.typegenComplete(result)\n}\n\nawait main(workerData)\n"],"names":["stat","isAbsolute","join","isMainThread","parentPort","workerData","WorkerChannelReporter","readSchema","findQueriesInPath","getResolver","registerBabel","TypeGenerator","Error","main","overloadClientMethods","schemaPath","searchPath","workDir","report","from","fullPath","schemaStats","isFile","err","code","hint","cause","schema","event","loadedSchema","typeGenerator","files","queries","path","resolver","typegenStarted","expectedFileCount","length","result","generateTypes","reporter","root","typegenComplete"],"mappings":"AAAA,SAAQA,IAAI,QAAO,mBAAkB;AACrC,SAAQC,UAAU,EAAEC,IAAI,QAAO,YAAW;AAC1C,SAAQC,YAAY,EAAEC,UAAU,EAAEC,UAAU,QAAO,sBAAqB;AAExE,SAAQC,qBAAqB,QAAO,0BAAyB;AAE7D,SAAQC,UAAU,QAAO,mBAAkB;AAC3C,SAAQC,iBAAiB,QAAO,qCAAoC;AACpE,SAAQC,WAAW,QAAO,kCAAiC;AAC3D,SAAQC,aAAa,QAAO,iCAAgC;AAC5D,SAAQC,aAAa,QAAO,iCAAgC;AAG5D,IAAIR,gBAAgB,CAACC,YAAY;IAC/B,MAAM,IAAIQ,MAAM;AAClB;AAEAF;AAEA,eAAeG,KAAK,EAClBC,qBAAqB,EACrBC,UAAU,EACVC,UAAU,EACVC,OAAO,EACwB;IAC/B,MAAMC,SAASZ,sBAAsBa,IAAI,CAAuBf;IAEhE,MAAMgB,WAAWnB,WAAWc,cAAcA,aAAab,KAAKe,SAASF;IAErE,IAAI;QACF,MAAMM,cAAc,MAAMrB,KAAKoB;QAC/B,IAAI,CAACC,YAAYC,MAAM,IAAI;YACzB,MAAM,IAAIV,MAAM,CAAC,2BAA2B,EAAEG,YAAY;QAC5D;IACF,EAAE,OAAOQ,KAAK;QACZ,IAAIA,eAAeX,SAAS,UAAUW,OAAOA,IAAIC,IAAI,KAAK,UAAU;YAClE,mGAAmG;YACnG,MAAMC,OAAOV,eAAe,kBAAkB,CAAC,uCAAuC,CAAC,GAAG;YAC1F,MAAM,IAAIH,MAAM,CAAC,uBAAuB,EAAEQ,WAAWK,MAAM,EAAE;gBAACC,OAAOH;YAAG;QAC1E;QACA,MAAMA;IACR;IAEA,MAAMI,SAAS,MAAMpB,WAAWa;IAEhCF,OAAOU,KAAK,CAACC,YAAY;IAEzB,MAAMC,gBAAgB,IAAInB;IAE1B,MAAM,EAACoB,KAAK,EAAEC,OAAO,EAAC,GAAGxB,kBAAkB;QACzCyB,MAAMjB;QACNkB,UAAUzB,YAAYQ;IACxB;IACAC,OAAOU,KAAK,CAACO,cAAc,CAAC;QAACC,mBAAmBL,MAAMM,MAAM;IAAA;IAE5D,MAAMC,SAAS,MAAMR,cAAcS,aAAa,CAAC;QAC/CzB;QACAkB;QACAQ,UAAUtB;QACVuB,MAAMxB;QACNU;QACAZ;IACF;IACAG,OAAOU,KAAK,CAACc,eAAe,CAACJ;AAC/B;AAEA,MAAMzB,KAAKR"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { error, log } from 'node:console';
|
|
2
2
|
import { isAbsolute, join, relative } from 'node:path';
|
|
3
|
+
import { chalk } from '@sanity/cli-core/ux';
|
|
3
4
|
import chokidar from 'chokidar';
|
|
4
5
|
import { debounce, mean } from 'lodash-es';
|
|
5
6
|
import { prepareConfig } from '../utils/config.js';
|
|
@@ -57,9 +58,13 @@ const IGNORED_PATTERNS = [
|
|
|
57
58
|
};
|
|
58
59
|
const { runGeneration } = createTypegenRunner(async ()=>{
|
|
59
60
|
try {
|
|
60
|
-
const { duration } = await runTypegenGenerate(
|
|
61
|
+
const { duration } = await runTypegenGenerate({
|
|
62
|
+
...options
|
|
63
|
+
});
|
|
61
64
|
stats.successfulDurations.push(duration);
|
|
62
|
-
} catch
|
|
65
|
+
} catch (err) {
|
|
66
|
+
const errorMessage = err instanceof Error ? err.message : err;
|
|
67
|
+
error(` ${chalk.red('›')} ${errorMessage}`);
|
|
63
68
|
stats.failedCount++;
|
|
64
69
|
}
|
|
65
70
|
});
|
|
@@ -86,7 +91,7 @@ const IGNORED_PATTERNS = [
|
|
|
86
91
|
watcher.on('all', (event, filePath)=>{
|
|
87
92
|
const timestamp = new Date().toLocaleTimeString();
|
|
88
93
|
const relativePath = isAbsolute(filePath) ? relative(workDir, filePath) : filePath;
|
|
89
|
-
|
|
94
|
+
log(`[${timestamp}] ${event}: ${relativePath}`);
|
|
90
95
|
debouncedGenerate();
|
|
91
96
|
});
|
|
92
97
|
watcher.on('error', (err)=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/actions/typegenWatch.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../src/actions/typegenWatch.ts"],"sourcesContent":["import {error, log} from 'node:console'\nimport {isAbsolute, join, relative} from 'node:path'\n\nimport {chalk} from '@sanity/cli-core/ux'\nimport chokidar, {FSWatcher} from 'chokidar'\nimport {debounce, mean} from 'lodash-es'\n\nimport {TypegenWatchModeTraceAttributes} from '../typegen.telemetry.js'\nimport {prepareConfig} from '../utils/config.js'\nimport {runTypegenGenerate} from './typegenGenerate.js'\nimport {type RunTypegenOptions} from './types.js'\n\nconst IGNORED_PATTERNS = [\n '**/node_modules/**',\n '**/.git/**',\n '**/dist/**',\n '**/lib/**',\n '**/.sanity/**',\n]\n\n/** State for tracking generation status */\nexport interface WatchState {\n isGenerating: boolean\n pendingGeneration: boolean\n}\n\n/** Return type for createTypegenRunner */\ninterface TypegenRunner {\n runGeneration: () => Promise<void>\n state: WatchState\n}\n\ntype WatcherStats = Omit<Extract<TypegenWatchModeTraceAttributes, {step: 'stopped'}>, 'step'>\n\n/**\n * Creates a typegen runner with concurrency control.\n * If generation is already running, queues one more generation to run after completion.\n * Multiple queued requests are coalesced into a single pending generation.\n */\nexport function createTypegenRunner(onGenerate: () => Promise<unknown>): TypegenRunner {\n const state: WatchState = {\n isGenerating: false,\n pendingGeneration: false,\n }\n\n async function runGeneration(): Promise<void> {\n if (state.isGenerating) {\n state.pendingGeneration = true\n return\n }\n\n state.isGenerating = true\n state.pendingGeneration = false\n\n try {\n await onGenerate()\n } finally {\n state.isGenerating = false\n\n // If a change came in during generation, run again\n if (state.pendingGeneration) {\n state.pendingGeneration = false\n await runGeneration()\n }\n }\n }\n\n return {runGeneration, state}\n}\n\n/**\n * Starts a file watcher that triggers typegen on changes.\n * Watches both query files (via patterns) and the schema JSON file.\n * Implements debouncing and concurrency control to prevent multiple generations.\n */\nexport function runTypegenWatcher(options: RunTypegenOptions): {\n getStats: () => WatcherStats\n stop: () => Promise<void>\n watcher: FSWatcher\n} {\n const {config, workDir} = options\n const {path, schema} = prepareConfig(config)\n\n const stats = {\n failedCount: 0,\n startTime: Date.now(),\n successfulDurations: [] as number[],\n }\n\n const {runGeneration} = createTypegenRunner(async () => {\n try {\n const {duration} = await runTypegenGenerate({...options})\n stats.successfulDurations.push(duration)\n } catch (err) {\n const errorMessage = err instanceof Error ? err.message : err\n error(` ${chalk.red('›')} ${errorMessage}`)\n stats.failedCount++\n }\n })\n\n // Debounced generation trigger\n const debouncedGenerate = debounce(runGeneration, 1000)\n\n // Build absolute patterns for query files and schema file\n const paths = Array.isArray(path) ? path : [path]\n const absoluteQueryPatterns = paths.map((pattern) =>\n isAbsolute(pattern) ? pattern : join(workDir, pattern),\n )\n const absoluteSchemaPath = isAbsolute(schema) ? schema : join(workDir, schema)\n const watchTargets = [...absoluteQueryPatterns, absoluteSchemaPath]\n\n // perform initial generation\n debouncedGenerate()\n\n // set up watcher\n const watcher = chokidar.watch(watchTargets, {\n cwd: workDir,\n ignored: IGNORED_PATTERNS,\n ignoreInitial: true,\n })\n\n watcher.on('all', (event: string, filePath: string) => {\n const timestamp = new Date().toLocaleTimeString()\n const relativePath = isAbsolute(filePath) ? relative(workDir, filePath) : filePath\n log(`[${timestamp}] ${event}: ${relativePath}`)\n debouncedGenerate()\n })\n\n watcher.on('error', (err: Error) => {\n error(`Watcher error: ${err.message}`)\n })\n\n return {\n getStats: () => ({\n averageGenerationDuration: mean(stats.successfulDurations) || 0,\n generationFailedCount: stats.failedCount,\n generationSuccessfulCount: stats.successfulDurations.length,\n watcherDuration: Date.now() - stats.startTime,\n }),\n stop: async () => {\n await watcher.close()\n },\n watcher,\n }\n}\n"],"names":["error","log","isAbsolute","join","relative","chalk","chokidar","debounce","mean","prepareConfig","runTypegenGenerate","IGNORED_PATTERNS","createTypegenRunner","onGenerate","state","isGenerating","pendingGeneration","runGeneration","runTypegenWatcher","options","config","workDir","path","schema","stats","failedCount","startTime","Date","now","successfulDurations","duration","push","err","errorMessage","Error","message","red","debouncedGenerate","paths","Array","isArray","absoluteQueryPatterns","map","pattern","absoluteSchemaPath","watchTargets","watcher","watch","cwd","ignored","ignoreInitial","on","event","filePath","timestamp","toLocaleTimeString","relativePath","getStats","averageGenerationDuration","generationFailedCount","generationSuccessfulCount","length","watcherDuration","stop","close"],"mappings":"AAAA,SAAQA,KAAK,EAAEC,GAAG,QAAO,eAAc;AACvC,SAAQC,UAAU,EAAEC,IAAI,EAAEC,QAAQ,QAAO,YAAW;AAEpD,SAAQC,KAAK,QAAO,sBAAqB;AACzC,OAAOC,cAA2B,WAAU;AAC5C,SAAQC,QAAQ,EAAEC,IAAI,QAAO,YAAW;AAGxC,SAAQC,aAAa,QAAO,qBAAoB;AAChD,SAAQC,kBAAkB,QAAO,uBAAsB;AAGvD,MAAMC,mBAAmB;IACvB;IACA;IACA;IACA;IACA;CACD;AAgBD;;;;CAIC,GACD,OAAO,SAASC,oBAAoBC,UAAkC;IACpE,MAAMC,QAAoB;QACxBC,cAAc;QACdC,mBAAmB;IACrB;IAEA,eAAeC;QACb,IAAIH,MAAMC,YAAY,EAAE;YACtBD,MAAME,iBAAiB,GAAG;YAC1B;Q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,6BAA6B;IAC7BP;IAEA,iBAAiB;IACjB,MAAMS,UAAUxC,SAASyC,KAAK,CAACF,cAAc;QAC3CG,KAAK3B;QACL4B,SAAStC;QACTuC,eAAe;IACjB;IAEAJ,QAAQK,EAAE,CAAC,OAAO,CAACC,OAAeC;QAChC,MAAMC,YAAY,IAAI3B,OAAO4B,kBAAkB;QAC/C,MAAMC,eAAetD,WAAWmD,YAAYjD,SAASiB,SAASgC,YAAYA;QAC1EpD,IAAI,CAAC,CAAC,EAAEqD,UAAU,EAAE,EAAEF,MAAM,EAAE,EAAEI,cAAc;QAC9CnB;IACF;IAEAS,QAAQK,EAAE,CAAC,SAAS,CAACnB;QACnBhC,MAAM,CAAC,eAAe,EAAEgC,IAAIG,OAAO,EAAE;IACvC;IAEA,OAAO;QACLsB,UAAU,IAAO,CAAA;gBACfC,2BAA2BlD,KAAKgB,MAAMK,mBAAmB,KAAK;gBAC9D8B,uBAAuBnC,MAAMC,WAAW;gBACxCmC,2BAA2BpC,MAAMK,mBAAmB,CAACgC,MAAM;gBAC3DC,iBAAiBnC,KAAKC,GAAG,KAAKJ,MAAME,SAAS;YAC/C,CAAA;QACAqC,MAAM;YACJ,MAAMjB,QAAQkB,KAAK;QACrB;QACAlB;IACF;AACF"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { stat } from 'node:fs/promises';
|
|
2
2
|
import { Flags } from '@oclif/core';
|
|
3
|
-
import { SanityCommand
|
|
3
|
+
import { SanityCommand } from '@sanity/cli-core';
|
|
4
4
|
import { chalk, spinner } from '@sanity/cli-core/ux';
|
|
5
5
|
import { omit, once } from 'lodash-es';
|
|
6
6
|
import { runTypegenGenerate } from '../../actions/typegenGenerate.js';
|
|
7
7
|
import { runTypegenWatcher } from '../../actions/typegenWatch.js';
|
|
8
8
|
import { configDefinition, readConfig } from '../../readConfig.js';
|
|
9
9
|
import { TypegenWatchModeTrace, TypesGeneratedTrace } from '../../typegen.telemetry.js';
|
|
10
|
+
import { debug } from '../../utils/debug.js';
|
|
10
11
|
import { promiseWithResolvers } from '../../utils/promiseWithResolvers.js';
|
|
11
12
|
import { telemetry } from '../../utils/telemetryLogger.js';
|
|
12
|
-
const debug = subdebug('typegen:generate');
|
|
13
13
|
const description = `Sanity TypeGen (Beta)
|
|
14
14
|
This command is currently in beta and may undergo significant changes. Feedback is welcome!
|
|
15
15
|
|
|
@@ -59,62 +59,71 @@ ${chalk.bold('Note:')}
|
|
|
59
59
|
}
|
|
60
60
|
async getConfig() {
|
|
61
61
|
const spin = spinner({}).start('Loading config…');
|
|
62
|
-
const { flags } = await this.parse(TypegenGenerateCommand);
|
|
63
|
-
const rootDir = await this.getProjectRoot();
|
|
64
|
-
const config = await this.getCliConfig();
|
|
65
|
-
const configPath = flags['config-path'];
|
|
66
|
-
const workDir = rootDir.directory;
|
|
67
|
-
// check if the legacy config exist
|
|
68
|
-
const legacyConfigPath = configPath || 'sanity-typegen.json';
|
|
69
|
-
let hasLegacyConfig = false;
|
|
70
62
|
try {
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
63
|
+
const { flags } = await this.parse(TypegenGenerateCommand);
|
|
64
|
+
const rootDir = await this.getProjectRoot();
|
|
65
|
+
const config = await this.getCliConfig();
|
|
66
|
+
const configPath = flags['config-path'];
|
|
67
|
+
const workDir = rootDir.directory;
|
|
68
|
+
// check if the legacy config exist
|
|
69
|
+
const legacyConfigPath = configPath || 'sanity-typegen.json';
|
|
70
|
+
let hasLegacyConfig = false;
|
|
71
|
+
try {
|
|
72
|
+
const file = await stat(legacyConfigPath);
|
|
73
|
+
hasLegacyConfig = file.isFile();
|
|
74
|
+
} catch (err) {
|
|
75
|
+
if (err instanceof Error && 'code' in err && err.code === 'ENOENT' && configPath) {
|
|
76
|
+
spin.fail();
|
|
77
|
+
this.error(`Typegen config file not found: ${configPath}`, {
|
|
78
|
+
exit: 1
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
if (err instanceof Error && 'code' in err && err.code !== 'ENOENT') {
|
|
82
|
+
spin.fail();
|
|
83
|
+
this.error(`Error when checking if typegen config file exists: ${legacyConfigPath}`, {
|
|
84
|
+
exit: 1
|
|
85
|
+
});
|
|
86
|
+
}
|
|
78
87
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
88
|
+
// we have both legacy and cli config with typegen
|
|
89
|
+
if (config?.typegen && hasLegacyConfig) {
|
|
90
|
+
spin.warn(chalk.yellow(`You've specified typegen in your Sanity CLI config, but also have a typegen config.
|
|
91
|
+
|
|
92
|
+
The config from the Sanity CLI config is used.
|
|
93
|
+
`));
|
|
94
|
+
return {
|
|
95
|
+
config: configDefinition.parse(config.typegen || {}),
|
|
96
|
+
path: rootDir.path,
|
|
97
|
+
type: 'cli',
|
|
98
|
+
workDir
|
|
99
|
+
};
|
|
83
100
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
spin.warn(chalk.yellow(`You've specified typegen in your Sanity CLI config, but also have a typegen config.
|
|
101
|
+
// we only have legacy typegen config
|
|
102
|
+
if (hasLegacyConfig) {
|
|
103
|
+
spin.warn(chalk.yellow(`The separate typegen config has been deprecated. Use \`typegen\` in the sanity CLI config instead.
|
|
88
104
|
|
|
89
|
-
|
|
90
|
-
|
|
105
|
+
See: https://www.sanity.io/docs/help/configuring-typegen-in-sanity-cli-config`));
|
|
106
|
+
return {
|
|
107
|
+
config: await readConfig(legacyConfigPath),
|
|
108
|
+
path: legacyConfigPath,
|
|
109
|
+
type: 'legacy',
|
|
110
|
+
workDir
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
spin.succeed(`Config loaded from sanity.cli.ts`);
|
|
114
|
+
// we only have cli config
|
|
91
115
|
return {
|
|
92
116
|
config: configDefinition.parse(config.typegen || {}),
|
|
93
117
|
path: rootDir.path,
|
|
94
118
|
type: 'cli',
|
|
95
119
|
workDir
|
|
96
120
|
};
|
|
121
|
+
} catch (err) {
|
|
122
|
+
spin.fail();
|
|
123
|
+
this.error(`An error occured during config loading ${err}`, {
|
|
124
|
+
exit: 1
|
|
125
|
+
});
|
|
97
126
|
}
|
|
98
|
-
// we only have legacy typegen config
|
|
99
|
-
if (hasLegacyConfig) {
|
|
100
|
-
spin.warn(chalk.yellow(`The separate typegen config has been deprecated. Use \`typegen\` in the sanity CLI config instead.
|
|
101
|
-
|
|
102
|
-
See: https://www.sanity.io/docs/help/configuring-typegen-in-sanity-cli-config`));
|
|
103
|
-
return {
|
|
104
|
-
config: await readConfig(legacyConfigPath),
|
|
105
|
-
path: legacyConfigPath,
|
|
106
|
-
type: 'legacy',
|
|
107
|
-
workDir
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
spin.succeed(`Config loaded from sanity.cli.ts`);
|
|
111
|
-
// we only have cli config
|
|
112
|
-
return {
|
|
113
|
-
config: configDefinition.parse(config.typegen || {}),
|
|
114
|
-
path: rootDir.path,
|
|
115
|
-
type: 'cli',
|
|
116
|
-
workDir
|
|
117
|
-
};
|
|
118
127
|
}
|
|
119
128
|
async runSingle() {
|
|
120
129
|
const trace = telemetry.trace(TypesGeneratedTrace);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/commands/typegen/generate.ts"],"sourcesContent":["import {stat} from 'node:fs/promises'\n\nimport {Flags} from '@oclif/core'\nimport {SanityCommand, subdebug} from '@sanity/cli-core'\nimport {chalk, spinner} from '@sanity/cli-core/ux'\nimport {omit, once} from 'lodash-es'\n\nimport {runTypegenGenerate} from '../../actions/typegenGenerate.js'\nimport {runTypegenWatcher} from '../../actions/typegenWatch.js'\nimport {configDefinition, readConfig, type TypeGenConfig} from '../../readConfig.js'\nimport {TypegenWatchModeTrace, TypesGeneratedTrace} from '../../typegen.telemetry.js'\nimport {promiseWithResolvers} from '../../utils/promiseWithResolvers.js'\nimport {telemetry} from '../../utils/telemetryLogger.js'\n\nconst debug = subdebug('typegen:generate')\n\nconst description = `Sanity TypeGen (Beta)\nThis command is currently in beta and may undergo significant changes. Feedback is welcome!\n\n${chalk.bold('Configuration:')}\nThis command can utilize configuration settings defined in a \\`sanity-typegen.json\\` file. These settings include:\n\n- \"path\": Specifies a glob pattern to locate your TypeScript or JavaScript files.\n Default: \"./src/**/*.{ts,tsx,js,jsx}\"\n\n- \"schema\": Defines the path to your Sanity schema file. This file should be generated using the \\`sanity schema extract\\` command.\n Default: \"schema.json\"\n\n- \"generates\": Indicates the path where the generated TypeScript type definitions will be saved.\n Default: \"./sanity.types.ts\"\n\nThe default configuration values listed above are used if not overridden in your \\`sanity-typegen.json\\` configuration file. To customize the behavior of the type generation, adjust these properties in the configuration file according to your project's needs.\n\n${chalk.bold('Note:')}\n- The \\`sanity schema extract\\` command is a prerequisite for extracting your Sanity Studio schema into a \\`schema.json\\` file, which is then used by the \\`sanity typegen generate\\` command to generate type definitions.\n- While this tool is in beta, we encourage you to experiment with these configurations and provide feedback to help improve its functionality and usability.`.trim()\n\n/**\n * @internal\n */\nexport class TypegenGenerateCommand extends SanityCommand<typeof TypegenGenerateCommand> {\n static override description = description\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: `Generate TypeScript type definitions from a Sanity Studio schema extracted using the \\`sanity schema extract\\` command.`,\n },\n ]\n\n static override flags = {\n 'config-path': Flags.string({\n description:\n '[Default: sanity-typegen.json] Specifies the path to the typegen configuration file. This file should be a JSON file that contains settings for the type generation process.',\n }),\n watch: Flags.boolean({\n default: false,\n description: '[Default: false] Run the typegen in watch mode',\n }),\n }\n\n public async run() {\n const {flags} = await this.parse(TypegenGenerateCommand)\n\n if (flags.watch) {\n await this.runWatcher()\n return\n }\n\n await this.runSingle()\n }\n\n private async getConfig(): Promise<{\n config: TypeGenConfig\n path?: string\n type: 'cli' | 'legacy'\n workDir: string\n }> {\n const spin = spinner({}).start('Loading config…')\n\n const {flags} = await this.parse(TypegenGenerateCommand)\n const rootDir = await this.getProjectRoot()\n const config = await this.getCliConfig()\n\n const configPath = flags['config-path']\n const workDir = rootDir.directory\n\n // check if the legacy config exist\n const legacyConfigPath = configPath || 'sanity-typegen.json'\n let hasLegacyConfig = false\n try {\n const file = await stat(legacyConfigPath)\n hasLegacyConfig = file.isFile()\n } catch (err) {\n if (err instanceof Error && 'code' in err && err.code === 'ENOENT' && configPath) {\n throw new Error(`Typegen config file not found: ${configPath}`, {cause: err})\n }\n\n if (err instanceof Error && 'code' in err && err.code !== 'ENOENT') {\n throw new Error(`Error when checking if typegen config file exists: ${legacyConfigPath}`, {\n cause: err,\n })\n }\n }\n\n // we have both legacy and cli config with typegen\n if (config?.typegen && hasLegacyConfig) {\n spin.warn(\n chalk.yellow(\n `You've specified typegen in your Sanity CLI config, but also have a typegen config.\n\n The config from the Sanity CLI config is used.\n `,\n ),\n )\n\n return {\n config: configDefinition.parse(config.typegen || {}),\n path: rootDir.path,\n type: 'cli',\n workDir,\n }\n }\n\n // we only have legacy typegen config\n if (hasLegacyConfig) {\n spin.warn(\n chalk.yellow(\n `The separate typegen config has been deprecated. Use \\`typegen\\` in the sanity CLI config instead.\n\n See: https://www.sanity.io/docs/help/configuring-typegen-in-sanity-cli-config`,\n ),\n )\n return {\n config: await readConfig(legacyConfigPath),\n path: legacyConfigPath,\n type: 'legacy',\n workDir,\n }\n }\n\n spin.succeed(`Config loaded from sanity.cli.ts`)\n\n // we only have cli config\n return {\n config: configDefinition.parse(config.typegen || {}),\n path: rootDir.path,\n type: 'cli',\n workDir,\n }\n }\n\n private async runSingle() {\n const trace = telemetry.trace(TypesGeneratedTrace)\n\n try {\n const {config: typegenConfig, type: typegenConfigMethod, workDir} = await this.getConfig()\n trace.start()\n\n const result = await runTypegenGenerate({\n config: typegenConfig,\n workDir,\n })\n\n const traceStats = omit(result, 'code', 'duration')\n\n trace.log({\n configMethod: typegenConfigMethod,\n configOverloadClientMethods: typegenConfig.overloadClientMethods,\n ...traceStats,\n })\n trace.complete()\n } catch (error) {\n debug(error)\n trace.error(error as Error)\n this.error(`${error instanceof Error ? error.message : 'Unknown error'}`, {\n exit: 1,\n })\n }\n }\n\n private async runWatcher() {\n const trace = telemetry.trace(TypegenWatchModeTrace)\n\n try {\n const {config: typegenConfig, workDir} = await this.getConfig()\n trace.start()\n\n const {promise, resolve} = promiseWithResolvers()\n\n const typegenWatcher = runTypegenWatcher({\n config: typegenConfig,\n workDir,\n })\n\n const stop = once(async () => {\n process.off('SIGINT', stop)\n process.off('SIGTERM', stop)\n\n trace.log({\n step: 'stopped',\n ...typegenWatcher.getStats(),\n })\n trace.complete()\n\n await typegenWatcher.stop()\n resolve()\n })\n\n process.on('SIGINT', stop)\n process.on('SIGTERM', stop)\n\n await promise\n } catch (error) {\n debug(error)\n trace.error(error as Error)\n this.error(`${error instanceof Error ? error.message : 'Unknown error'}`, {\n exit: 1,\n })\n }\n }\n}\n"],"names":["stat","Flags","SanityCommand","subdebug","chalk","spinner","omit","once","runTypegenGenerate","runTypegenWatcher","configDefinition","readConfig","TypegenWatchModeTrace","TypesGeneratedTrace","promiseWithResolvers","telemetry","debug","description","bold","trim","TypegenGenerateCommand","examples","command","flags","string","watch","boolean","default","run","parse","runWatcher","runSingle","getConfig","spin","start","rootDir","getProjectRoot","config","getCliConfig","configPath","workDir","directory","legacyConfigPath","hasLegacyConfig","file","isFile","err","Error","code","cause","typegen","warn","yellow","path","type","succeed","trace","typegenConfig","typegenConfigMethod","result","traceStats","log","configMethod","configOverloadClientMethods","overloadClientMethods","complete","error","message","exit","promise","resolve","typegenWatcher","stop","process","off","step","getStats","on"],"mappings":"AAAA,SAAQA,IAAI,QAAO,mBAAkB;AAErC,SAAQC,KAAK,QAAO,cAAa;AACjC,SAAQC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACxD,SAAQC,KAAK,EAAEC,OAAO,QAAO,sBAAqB;AAClD,SAAQC,IAAI,EAAEC,IAAI,QAAO,YAAW;AAEpC,SAAQC,kBAAkB,QAAO,mCAAkC;AACnE,SAAQC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AAiBnB,QAAQmB,MAAMC,OAAO,GAAG,iBAAiB,EAAE;gBACxEC,MAAM;YACR;QACF;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/typegen/generate.ts"],"sourcesContent":["import {stat} from 'node:fs/promises'\n\nimport {Flags} from '@oclif/core'\nimport {SanityCommand} from '@sanity/cli-core'\nimport {chalk, spinner} from '@sanity/cli-core/ux'\nimport {omit, once} from 'lodash-es'\n\nimport {runTypegenGenerate} from '../../actions/typegenGenerate.js'\nimport {runTypegenWatcher} from '../../actions/typegenWatch.js'\nimport {configDefinition, readConfig, type TypeGenConfig} from '../../readConfig.js'\nimport {TypegenWatchModeTrace, TypesGeneratedTrace} from '../../typegen.telemetry.js'\nimport {debug} from '../../utils/debug.js'\nimport {promiseWithResolvers} from '../../utils/promiseWithResolvers.js'\nimport {telemetry} from '../../utils/telemetryLogger.js'\n\nconst description = `Sanity TypeGen (Beta)\nThis command is currently in beta and may undergo significant changes. Feedback is welcome!\n\n${chalk.bold('Configuration:')}\nThis command can utilize configuration settings defined in a \\`sanity-typegen.json\\` file. These settings include:\n\n- \"path\": Specifies a glob pattern to locate your TypeScript or JavaScript files.\n Default: \"./src/**/*.{ts,tsx,js,jsx}\"\n\n- \"schema\": Defines the path to your Sanity schema file. This file should be generated using the \\`sanity schema extract\\` command.\n Default: \"schema.json\"\n\n- \"generates\": Indicates the path where the generated TypeScript type definitions will be saved.\n Default: \"./sanity.types.ts\"\n\nThe default configuration values listed above are used if not overridden in your \\`sanity-typegen.json\\` configuration file. To customize the behavior of the type generation, adjust these properties in the configuration file according to your project's needs.\n\n${chalk.bold('Note:')}\n- The \\`sanity schema extract\\` command is a prerequisite for extracting your Sanity Studio schema into a \\`schema.json\\` file, which is then used by the \\`sanity typegen generate\\` command to generate type definitions.\n- While this tool is in beta, we encourage you to experiment with these configurations and provide feedback to help improve its functionality and usability.`.trim()\n\n/**\n * @internal\n */\nexport class TypegenGenerateCommand extends SanityCommand<typeof TypegenGenerateCommand> {\n static override description = description\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: `Generate TypeScript type definitions from a Sanity Studio schema extracted using the \\`sanity schema extract\\` command.`,\n },\n ]\n\n static override flags = {\n 'config-path': Flags.string({\n description:\n '[Default: sanity-typegen.json] Specifies the path to the typegen configuration file. This file should be a JSON file that contains settings for the type generation process.',\n }),\n watch: Flags.boolean({\n default: false,\n description: '[Default: false] Run the typegen in watch mode',\n }),\n }\n\n public async run() {\n const {flags} = await this.parse(TypegenGenerateCommand)\n\n if (flags.watch) {\n await this.runWatcher()\n return\n }\n\n await this.runSingle()\n }\n\n private async getConfig(): Promise<{\n config: TypeGenConfig\n path?: string\n type: 'cli' | 'legacy'\n workDir: string\n }> {\n const spin = spinner({}).start('Loading config…')\n\n try {\n const {flags} = await this.parse(TypegenGenerateCommand)\n const rootDir = await this.getProjectRoot()\n const config = await this.getCliConfig()\n\n const configPath = flags['config-path']\n const workDir = rootDir.directory\n\n // check if the legacy config exist\n const legacyConfigPath = configPath || 'sanity-typegen.json'\n let hasLegacyConfig = false\n\n try {\n const file = await stat(legacyConfigPath)\n hasLegacyConfig = file.isFile()\n } catch (err) {\n if (err instanceof Error && 'code' in err && err.code === 'ENOENT' && configPath) {\n spin.fail()\n this.error(`Typegen config file not found: ${configPath}`, {exit: 1})\n }\n\n if (err instanceof Error && 'code' in err && err.code !== 'ENOENT') {\n spin.fail()\n this.error(`Error when checking if typegen config file exists: ${legacyConfigPath}`, {\n exit: 1,\n })\n }\n }\n\n // we have both legacy and cli config with typegen\n if (config?.typegen && hasLegacyConfig) {\n spin.warn(\n chalk.yellow(\n `You've specified typegen in your Sanity CLI config, but also have a typegen config.\n\n The config from the Sanity CLI config is used.\n `,\n ),\n )\n\n return {\n config: configDefinition.parse(config.typegen || {}),\n path: rootDir.path,\n type: 'cli',\n workDir,\n }\n }\n\n // we only have legacy typegen config\n if (hasLegacyConfig) {\n spin.warn(\n chalk.yellow(\n `The separate typegen config has been deprecated. Use \\`typegen\\` in the sanity CLI config instead.\n\n See: https://www.sanity.io/docs/help/configuring-typegen-in-sanity-cli-config`,\n ),\n )\n return {\n config: await readConfig(legacyConfigPath),\n path: legacyConfigPath,\n type: 'legacy',\n workDir,\n }\n }\n\n spin.succeed(`Config loaded from sanity.cli.ts`)\n\n // we only have cli config\n return {\n config: configDefinition.parse(config.typegen || {}),\n path: rootDir.path,\n type: 'cli',\n workDir,\n }\n } catch (err) {\n spin.fail()\n this.error(`An error occured during config loading ${err}`, {exit: 1})\n }\n }\n\n private async runSingle() {\n const trace = telemetry.trace(TypesGeneratedTrace)\n\n try {\n const {config: typegenConfig, type: typegenConfigMethod, workDir} = await this.getConfig()\n trace.start()\n\n const result = await runTypegenGenerate({\n config: typegenConfig,\n workDir,\n })\n\n const traceStats = omit(result, 'code', 'duration')\n\n trace.log({\n configMethod: typegenConfigMethod,\n configOverloadClientMethods: typegenConfig.overloadClientMethods,\n ...traceStats,\n })\n trace.complete()\n } catch (error) {\n debug(error)\n trace.error(error as Error)\n this.error(`${error instanceof Error ? error.message : 'Unknown error'}`, {\n exit: 1,\n })\n }\n }\n\n private async runWatcher() {\n const trace = telemetry.trace(TypegenWatchModeTrace)\n\n try {\n const {config: typegenConfig, workDir} = await this.getConfig()\n trace.start()\n\n const {promise, resolve} = promiseWithResolvers()\n\n const typegenWatcher = runTypegenWatcher({\n config: typegenConfig,\n workDir,\n })\n\n const stop = once(async () => {\n process.off('SIGINT', stop)\n process.off('SIGTERM', stop)\n\n trace.log({\n step: 'stopped',\n ...typegenWatcher.getStats(),\n })\n trace.complete()\n\n await typegenWatcher.stop()\n resolve()\n })\n\n process.on('SIGINT', stop)\n process.on('SIGTERM', stop)\n\n await promise\n } catch (error) {\n debug(error)\n trace.error(error as Error)\n this.error(`${error instanceof Error ? error.message : 'Unknown error'}`, {\n exit: 1,\n })\n }\n }\n}\n"],"names":["stat","Flags","SanityCommand","chalk","spinner","omit","once","runTypegenGenerate","runTypegenWatcher","configDefinition","readConfig","TypegenWatchModeTrace","TypesGeneratedTrace","debug","promiseWithResolvers","telemetry","description","bold","trim","TypegenGenerateCommand","examples","command","flags","string","watch","boolean","default","run","parse","runWatcher","runSingle","getConfig","spin","start","rootDir","getProjectRoot","config","getCliConfig","configPath","workDir","directory","legacyConfigPath","hasLegacyConfig","file","isFile","err","Error","code","fail","error","exit","typegen","warn","yellow","path","type","succeed","trace","typegenConfig","typegenConfigMethod","result","traceStats","log","configMethod","configOverloadClientMethods","overloadClientMethods","complete","message","promise","resolve","typegenWatcher","stop","process","off","step","getStats","on"],"mappings":"AAAA,SAAQA,IAAI,QAAO,mBAAkB;AAErC,SAAQC,KAAK,QAAO,cAAa;AACjC,SAAQC,aAAa,QAAO,mBAAkB;AAC9C,SAAQC,KAAK,EAAEC,OAAO,QAAO,sBAAqB;AAClD,SAAQC,IAAI,EAAEC,IAAI,QAAO,YAAW;AAEpC,SAAQC,kBAAkB,QAAO,mCAAkC;AACnE,SAAQC,iBAAiB,QAAO,gCAA+B;AAC/D,SAAQC,gBAAgB,EAAEC,UAAU,QAA2B,sBAAqB;AACpF,SAAQC,qBAAqB,EAAEC,mBAAmB,QAAO,6BAA4B;AACrF,SAAQC,KAAK,QAAO,uBAAsB;AAC1C,SAAQC,oBAAoB,QAAO,sCAAqC;AACxE,SAAQC,SAAS,QAAO,iCAAgC;AAExD,MAAMC,cAAc,CAAC;;;AAGrB,EAAEb,MAAMc,IAAI,CAAC,kBAAkB;;;;;;;;;;;;;;AAc/B,EAAEd,MAAMc,IAAI,CAAC,SAAS;;4JAEsI,CAAC,CAACC,IAAI;AAElK;;CAEC,GACD,OAAO,MAAMC,+BAA+BjB;IAC1C,OAAgBc,cAAcA,YAAW;IAEzC,OAAgBI,WAAW;QACzB;YACEC,SAAS;YACTL,aAAa,CAAC,uHAAuH,CAAC;QACxI;KACD,CAAA;IAED,OAAgBM,QAAQ;QACtB,eAAerB,MAAMsB,MAAM,CAAC;YAC1BP,aACE;QACJ;QACAQ,O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AAK,CAAC,GAAGA,iBAAiBH,QAAQG,MAAMkB,OAAO,GAAG,iBAAiB,EAAE;gBACxEjB,MAAM;YACR;QACF;IACF;IAEA,MAAcrB,aAAa;QACzB,MAAM4B,QAAQ1C,UAAU0C,KAAK,CAAC9C;QAE9B,IAAI;YACF,MAAM,EAACyB,QAAQsB,aAAa,EAAEnB,OAAO,EAAC,GAAG,MAAM,IAAI,CAACR,SAAS;YAC7D0B,MAAMxB,KAAK;YAEX,MAAM,EAACmC,OAAO,EAAEC,OAAO,EAAC,GAAGvD;YAE3B,MAAMwD,iBAAiB9D,kBAAkB;gBACvC4B,QAAQsB;gBACRnB;YACF;YAEA,MAAMgC,OAAOjE,KAAK;gBAChBkE,QAAQC,GAAG,CAAC,UAAUF;gBACtBC,QAAQC,GAAG,CAAC,WAAWF;gBAEvBd,MAAMK,GAAG,CAAC;oBACRY,MAAM;oBACN,GAAGJ,eAAeK,QAAQ,EAAE;gBAC9B;gBACAlB,MAAMS,QAAQ;gBAEd,MAAMI,eAAeC,IAAI;gBACzBF;YACF;YAEAG,QAAQI,EAAE,CAAC,UAAUL;YACrBC,QAAQI,EAAE,CAAC,WAAWL;YAEtB,MAAMH;QACR,EAAE,OAAOnB,OAAO;YACdpC,MAAMoC;YACNQ,MAAMR,KAAK,CAACA;YACZ,IAAI,CAACA,KAAK,CAAC,GAAGA,iBAAiBH,QAAQG,MAAMkB,OAAO,GAAG,iBAAiB,EAAE;gBACxEjB,MAAM;YACR;QACF;IACF;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/debug.ts"],"sourcesContent":["import {subdebug} from '@sanity/cli-core'\n\nexport const debug = subdebug('typegen:generate')\n"],"names":["subdebug","debug"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,mBAAkB;AAEzC,OAAO,MAAMC,QAAQD,SAAS,oBAAmB"}
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/codegen",
|
|
3
|
-
"version": "5.9.
|
|
3
|
+
"version": "5.9.1",
|
|
4
4
|
"description": "Codegen toolkit for Sanity.io",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -54,7 +54,6 @@
|
|
|
54
54
|
"@oclif/core": "^4.8.0",
|
|
55
55
|
"@oclif/plugin-help": "^6.2.36",
|
|
56
56
|
"@sanity/cli-core": "^0.1.0-alpha.8",
|
|
57
|
-
"@sanity/telemetry": "^0.8.1",
|
|
58
57
|
"@sanity/worker-channels": "^1.1.0",
|
|
59
58
|
"debug": "^4.4.3",
|
|
60
59
|
"globby": "^11.1.0",
|
|
@@ -70,6 +69,7 @@
|
|
|
70
69
|
},
|
|
71
70
|
"devDependencies": {
|
|
72
71
|
"@eslint/compat": "^2.0.1",
|
|
72
|
+
"@sanity/telemetry": "^0.8.0",
|
|
73
73
|
"@microsoft/api-extractor": "^7.55.2",
|
|
74
74
|
"@oclif/test": "^4.1.15",
|
|
75
75
|
"@sanity/cli-test": "^0.0.2-alpha.7",
|
|
@@ -94,6 +94,9 @@
|
|
|
94
94
|
"typescript": "^5.9.3",
|
|
95
95
|
"vitest": "^4.0.17"
|
|
96
96
|
},
|
|
97
|
+
"peerDependencies": {
|
|
98
|
+
"@sanity/telemetry": "^0.8.0"
|
|
99
|
+
},
|
|
97
100
|
"engines": {
|
|
98
101
|
"node": ">=20.19 <22 || >=22.12"
|
|
99
102
|
},
|