@sanity/codegen 5.9.2 → 5.9.3
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/bin/run.js +20 -0
- package/dist/actions/typegenWatch.js +3 -3
- package/dist/actions/typegenWatch.js.map +1 -1
- package/dist/actions/types.js.map +1 -1
- package/dist/commands/typegen/generate.js +8 -8
- package/dist/commands/typegen/generate.js.map +1 -1
- package/dist/index.d.ts +0 -10
- package/oclif.manifest.json +1 -1
- package/package.json +7 -7
- package/dist/utils/telemetryLogger.js +0 -17
- package/dist/utils/telemetryLogger.js.map +0 -1
package/bin/run.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {execute} from '@oclif/core'
|
|
3
|
+
import {CLI_TELEMETRY_SYMBOL} from '@sanity/cli-core'
|
|
3
4
|
|
|
4
5
|
const err = '\u001B[31m\u001B[1mERROR:\u001B[22m\u001B[39m '
|
|
5
6
|
const nodeVersionParts = process.version.replace(/^v/i, '').split('.').map(Number)
|
|
@@ -21,11 +22,30 @@ function isSupportedNodeVersion(major, minor, patch) {
|
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
if (!isSupportedNodeVersion(majorVersion, minorVersion, patchVersion)) {
|
|
25
|
+
// eslint-disable-next-line no-console
|
|
24
26
|
console.error(
|
|
25
27
|
`${err}Node.js version >=20.19.1 <22 or >=22.12 required. You are running ${process.version}`,
|
|
26
28
|
)
|
|
29
|
+
// eslint-disable-next-line no-console
|
|
27
30
|
console.error('')
|
|
28
31
|
process.exit(1)
|
|
29
32
|
}
|
|
30
33
|
|
|
34
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
35
|
+
/**
|
|
36
|
+
* Telemetry is added via a plugin in the main CLI.
|
|
37
|
+
* This adds a mock implementation of the telemetry API to allow running this CLI for testing.
|
|
38
|
+
*
|
|
39
|
+
* We won't be exposing this API to the public, so it's ok to use a globalThis assignment.
|
|
40
|
+
*/
|
|
41
|
+
globalThis[CLI_TELEMETRY_SYMBOL] = {
|
|
42
|
+
trace: () => ({
|
|
43
|
+
complete: () => {},
|
|
44
|
+
error: () => {},
|
|
45
|
+
log: () => {},
|
|
46
|
+
start: () => {},
|
|
47
|
+
}),
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
31
51
|
await execute({dir: import.meta.url})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { error, log } from 'node:console';
|
|
2
2
|
import { isAbsolute, join, relative } from 'node:path';
|
|
3
|
-
import {
|
|
3
|
+
import { styleText } from 'node:util';
|
|
4
4
|
import chokidar from 'chokidar';
|
|
5
5
|
import { debounce, mean } from 'lodash-es';
|
|
6
6
|
import { prepareConfig } from '../utils/config.js';
|
|
@@ -16,7 +16,7 @@ const IGNORED_PATTERNS = [
|
|
|
16
16
|
* Creates a typegen runner with concurrency control.
|
|
17
17
|
* If generation is already running, queues one more generation to run after completion.
|
|
18
18
|
* Multiple queued requests are coalesced into a single pending generation.
|
|
19
|
-
*/
|
|
19
|
+
*/ function createTypegenRunner(onGenerate) {
|
|
20
20
|
const state = {
|
|
21
21
|
isGenerating: false,
|
|
22
22
|
pendingGeneration: false
|
|
@@ -64,7 +64,7 @@ const IGNORED_PATTERNS = [
|
|
|
64
64
|
stats.successfulDurations.push(duration);
|
|
65
65
|
} catch (err) {
|
|
66
66
|
const errorMessage = err instanceof Error ? err.message : err;
|
|
67
|
-
error(` ${
|
|
67
|
+
error(` ${styleText('red', '›')} ${errorMessage}`);
|
|
68
68
|
stats.failedCount++;
|
|
69
69
|
}
|
|
70
70
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/actions/typegenWatch.ts"],"sourcesContent":["import {error, log} from 'node:console'\nimport {isAbsolute, join, relative} from 'node:path'\
|
|
1
|
+
{"version":3,"sources":["../../src/actions/typegenWatch.ts"],"sourcesContent":["import {error, log} from 'node:console'\nimport {isAbsolute, join, relative} from 'node:path'\nimport {styleText} from 'node:util'\n\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 */\ninterface 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 */\nfunction 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(` ${styleText('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","styleText","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","debouncedGenerate","paths","Array","isArray","absoluteQueryPatterns","map","pattern","absoluteSchemaPath","watchTargets","watcher","watch","cwd","ignored","ignoreInitial","on","event","filePath","timestamp","toLocaleTimeString","relativePath","getStats","averageGenerationDuration","gener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G,KAAKJ,MAAME,SAAS;YAC/C,CAAA;QACAoC,MAAM;YACJ,MAAMjB,QAAQkB,KAAK;QACrB;QACAlB;IACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/actions/types.ts"],"sourcesContent":["import {spinner} from '@sanity/cli-core/ux'\nimport {WorkerChannel} from '@sanity/worker-channels'\n\nimport {TypeGenConfig} from '../readConfig.js'\nimport {type TypegenWorkerChannel as CodegenTypegenWorkerChannel} from '../typescript/typeGenerator.js'\
|
|
1
|
+
{"version":3,"sources":["../../src/actions/types.ts"],"sourcesContent":["import {spinner} from '@sanity/cli-core/ux'\nimport {WorkerChannel} from '@sanity/worker-channels'\n\nimport {TypeGenConfig} from '../readConfig.js'\nimport {type TypegenWorkerChannel as CodegenTypegenWorkerChannel} from '../typescript/typeGenerator.js'\n\n/**\n * Data passed to the typegen worker thread.\n * @internal\n */\nexport interface TypegenGenerateTypesWorkerData {\n /** Path to the schema JSON file */\n schemaPath: string\n /** Glob pattern(s) for finding query files */\n searchPath: string | string[]\n /** Working directory (project root) */\n workDir: string\n\n /** Whether to generate client method overloads */\n overloadClientMethods?: boolean\n}\n\n/**\n * Worker channel definition for typegen worker communication.\n * Extends the base TypegenWorkerChannel with additional events for progress tracking.\n * @internal\n */\nexport type TypegenWorkerChannel = WorkerChannel.Definition<\n CodegenTypegenWorkerChannel['__definition'] & {\n loadedSchema: WorkerChannel.Event\n typegenComplete: WorkerChannel.Event<{code: string}>\n typegenStarted: WorkerChannel.Event<{expectedFileCount: number}>\n }\n>\n\n/**\n * Options for running a single typegen generation.\n * This is the programmatic API for one-off generation without file watching.\n */\nexport interface RunTypegenOptions {\n /** Working directory (usually project root) */\n workDir: string\n\n /** Typegen configuration */\n config?: Partial<TypeGenConfig>\n\n /** Optional spinner instance for progress display */\n spin?: ReturnType<typeof spinner>\n}\n\n/**\n * Result from a single generation run.\n * @internal\n */\nexport interface GenerationResult {\n code: string\n duration: number\n emptyUnionTypeNodesGenerated: number\n filesWithErrors: number\n outputSize: number\n queriesCount: number\n queryFilesCount: number\n schemaTypesCount: number\n typeNodesGenerated: number\n unknownTypeNodesGenerated: number\n unknownTypeNodesRatio: number\n}\n"],"names":[],"mappings":"AAkDA;;;CAGC,GACD,WAYC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { stat } from 'node:fs/promises';
|
|
2
|
+
import { styleText } from 'node:util';
|
|
2
3
|
import { Flags } from '@oclif/core';
|
|
3
4
|
import { SanityCommand } from '@sanity/cli-core';
|
|
4
|
-
import {
|
|
5
|
+
import { spinner } from '@sanity/cli-core/ux';
|
|
5
6
|
import { omit, once } from 'lodash-es';
|
|
6
7
|
import { runTypegenGenerate } from '../../actions/typegenGenerate.js';
|
|
7
8
|
import { runTypegenWatcher } from '../../actions/typegenWatch.js';
|
|
@@ -9,11 +10,10 @@ import { configDefinition, readConfig } from '../../readConfig.js';
|
|
|
9
10
|
import { TypegenWatchModeTrace, TypesGeneratedTrace } from '../../typegen.telemetry.js';
|
|
10
11
|
import { debug } from '../../utils/debug.js';
|
|
11
12
|
import { promiseWithResolvers } from '../../utils/promiseWithResolvers.js';
|
|
12
|
-
import { telemetry } from '../../utils/telemetryLogger.js';
|
|
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
|
|
|
16
|
-
${
|
|
16
|
+
${styleText('bold', 'Configuration:')}
|
|
17
17
|
This command can utilize configuration settings defined in a \`sanity-typegen.json\` file. These settings include:
|
|
18
18
|
|
|
19
19
|
- "path": Specifies a glob pattern to locate your TypeScript or JavaScript files.
|
|
@@ -27,7 +27,7 @@ This command can utilize configuration settings defined in a \`sanity-typegen.js
|
|
|
27
27
|
|
|
28
28
|
The 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.
|
|
29
29
|
|
|
30
|
-
${
|
|
30
|
+
${styleText('bold', 'Note:')}
|
|
31
31
|
- 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.
|
|
32
32
|
- 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();
|
|
33
33
|
/**
|
|
@@ -87,7 +87,7 @@ ${chalk.bold('Note:')}
|
|
|
87
87
|
}
|
|
88
88
|
// we have both legacy and cli config with typegen
|
|
89
89
|
if (config?.typegen && hasLegacyConfig) {
|
|
90
|
-
spin.warn(
|
|
90
|
+
spin.warn(styleText('yellow', `You've specified typegen in your Sanity CLI config, but also have a typegen config.
|
|
91
91
|
|
|
92
92
|
The config from the Sanity CLI config is used.
|
|
93
93
|
`));
|
|
@@ -100,7 +100,7 @@ ${chalk.bold('Note:')}
|
|
|
100
100
|
}
|
|
101
101
|
// we only have legacy typegen config
|
|
102
102
|
if (hasLegacyConfig) {
|
|
103
|
-
spin.warn(
|
|
103
|
+
spin.warn(styleText('yellow', `The separate typegen config has been deprecated. Use \`typegen\` in the sanity CLI config instead.
|
|
104
104
|
|
|
105
105
|
See: https://www.sanity.io/docs/help/configuring-typegen-in-sanity-cli-config`));
|
|
106
106
|
return {
|
|
@@ -126,7 +126,7 @@ ${chalk.bold('Note:')}
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
async runSingle() {
|
|
129
|
-
const trace = telemetry.trace(TypesGeneratedTrace);
|
|
129
|
+
const trace = this.telemetry.trace(TypesGeneratedTrace);
|
|
130
130
|
try {
|
|
131
131
|
const { config: typegenConfig, type: typegenConfigMethod, workDir } = await this.getConfig();
|
|
132
132
|
trace.start();
|
|
@@ -150,7 +150,7 @@ ${chalk.bold('Note:')}
|
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
async runWatcher() {
|
|
153
|
-
const trace = telemetry.trace(TypegenWatchModeTrace);
|
|
153
|
+
const trace = this.telemetry.trace(TypegenWatchModeTrace);
|
|
154
154
|
try {
|
|
155
155
|
const { config: typegenConfig, workDir } = await this.getConfig();
|
|
156
156
|
trace.start();
|
|
@@ -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} 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;QAC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AACA,KAAK,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"}
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/typegen/generate.ts"],"sourcesContent":["import {stat} from 'node:fs/promises'\nimport {styleText} from 'node:util'\n\nimport {Flags} from '@oclif/core'\nimport {SanityCommand} from '@sanity/cli-core'\nimport {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'\n\nconst description = `Sanity TypeGen (Beta)\nThis command is currently in beta and may undergo significant changes. Feedback is welcome!\n\n${styleText('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${styleText('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 styleText(\n '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 styleText(\n '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 = this.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 = this.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","styleText","Flags","SanityCommand","spinner","omit","once","runTypegenGenerate","runTypegenWatcher","configDefinition","readConfig","TypegenWatchModeTrace","TypesGeneratedTrace","debug","promiseWithResolvers","description","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","path","type","succeed","trace","telemetry","typegenConfig","typegenConfigMethod","result","traceStats","log","configMethod","configOverloadClientMethods","overloadClientMethods","complete","message","promise","resolve","typegenWatcher","stop","process","off","step","getStats","on"],"mappings":"AAAA,SAAQA,IAAI,QAAO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AMgC,OAAO/D,KAAK;gBAChBgE,QAAQC,GAAG,CAAC,UAAUF;gBACtBC,QAAQC,GAAG,CAAC,WAAWF;gBAEvBf,MAAMM,GAAG,CAAC;oBACRY,MAAM;oBACN,GAAGJ,eAAeK,QAAQ,EAAE;gBAC9B;gBACAnB,MAAMU,QAAQ;gBAEd,MAAMI,eAAeC,IAAI;gBACzBF;YACF;YAEAG,QAAQI,EAAE,CAAC,UAAUL;YACrBC,QAAQI,EAAE,CAAC,WAAWL;YAEtB,MAAMH;QACR,EAAE,OAAOnB,OAAO;YACdlC,MAAMkC;YACNO,MAAMP,KAAK,CAACA;YACZ,IAAI,CAACA,KAAK,CAAC,GAAGA,iBAAiBH,QAAQG,MAAMkB,OAAO,GAAG,iBAAiB,EAAE;gBACxEjB,MAAM;YACR;QACF;IACF;AACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,6 @@ import { SanityCommand } from '@sanity/cli-core';
|
|
|
8
8
|
import { SchemaType } from 'groq-js';
|
|
9
9
|
import { spinner } from '@sanity/cli-core/ux';
|
|
10
10
|
import * as t from '@babel/types';
|
|
11
|
-
import { TelemetryLogger } from '@sanity/telemetry';
|
|
12
11
|
import { TransformOptions } from '@babel/core';
|
|
13
12
|
import { WorkerChannel } from '@sanity/worker-channels';
|
|
14
13
|
import { WorkerChannelReporter } from '@sanity/worker-channels';
|
|
@@ -423,8 +422,6 @@ export declare interface RunTypegenOptions {
|
|
|
423
422
|
config?: Partial<TypeGenConfig>;
|
|
424
423
|
/** Optional spinner instance for progress display */
|
|
425
424
|
spin?: ReturnType<typeof spinner>;
|
|
426
|
-
/** Optional telemetry instance for tracking usage */
|
|
427
|
-
telemetry?: typeof telemetry;
|
|
428
425
|
}
|
|
429
426
|
|
|
430
427
|
/**
|
|
@@ -448,13 +445,6 @@ export declare function safeParseQuery(query: string): ExprNode;
|
|
|
448
445
|
/** Builds a tuple from elements, stopping at the first `never`. */
|
|
449
446
|
declare type TakeUntilNever<T extends unknown[]> = T extends [infer H, ...infer Rest] ? [H] extends [never] ? [] : [H, ...TakeUntilNever<Rest>] : [];
|
|
450
447
|
|
|
451
|
-
/**
|
|
452
|
-
* TODO: Remove once we have a proper telemetry logger through the `@sanity/cli-core`
|
|
453
|
-
*
|
|
454
|
-
* This logger does nothing, except provide the interface to interact with
|
|
455
|
-
*/
|
|
456
|
-
declare const telemetry: TelemetryLogger<unknown>;
|
|
457
|
-
|
|
458
448
|
/**
|
|
459
449
|
* Statistics from the query type evaluation process.
|
|
460
450
|
* @public
|
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.3",
|
|
4
4
|
"description": "Codegen toolkit for Sanity.io",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -53,8 +53,9 @@
|
|
|
53
53
|
"@babel/types": "^7.28.6",
|
|
54
54
|
"@oclif/core": "^4.8.0",
|
|
55
55
|
"@oclif/plugin-help": "^6.2.36",
|
|
56
|
-
"@sanity/cli-core": "^0.1.0-alpha.
|
|
56
|
+
"@sanity/cli-core": "^0.1.0-alpha.10",
|
|
57
57
|
"@sanity/worker-channels": "^1.1.0",
|
|
58
|
+
"chokidar": "^3.6.0",
|
|
58
59
|
"debug": "^4.4.3",
|
|
59
60
|
"globby": "^11.1.0",
|
|
60
61
|
"groq": "^5.2.0",
|
|
@@ -64,16 +65,15 @@
|
|
|
64
65
|
"prettier": "^3.7.4",
|
|
65
66
|
"reselect": "^5.1.1",
|
|
66
67
|
"tsconfig-paths": "^4.2.0",
|
|
67
|
-
"zod": "^4.3.6"
|
|
68
|
-
"chokidar": "^3.6.0"
|
|
68
|
+
"zod": "^4.3.6"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@eslint/compat": "^2.0.1",
|
|
72
|
-
"@sanity/telemetry": "^0.8.0",
|
|
73
72
|
"@microsoft/api-extractor": "^7.55.2",
|
|
74
73
|
"@oclif/test": "^4.1.15",
|
|
75
|
-
"@sanity/cli-test": "^0.0.2-alpha.
|
|
76
|
-
"@sanity/eslint-config-cli": "0.0.0-alpha.
|
|
74
|
+
"@sanity/cli-test": "^0.0.2-alpha.9",
|
|
75
|
+
"@sanity/eslint-config-cli": "0.0.0-alpha.2",
|
|
76
|
+
"@sanity/telemetry": "^0.8.0",
|
|
77
77
|
"@swc/cli": "^0.7.9",
|
|
78
78
|
"@swc/core": "^1.15.8",
|
|
79
79
|
"@types/babel__core": "^7.20.5",
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TODO: Remove once we have a proper telemetry logger through the `@sanity/cli-core`
|
|
3
|
-
*
|
|
4
|
-
* This logger does nothing, except provide the interface to interact with
|
|
5
|
-
*/ import { createBatchedStore, createSessionId } from '@sanity/telemetry';
|
|
6
|
-
const session = createSessionId();
|
|
7
|
-
const store = createBatchedStore(session, {
|
|
8
|
-
async resolveConsent () {
|
|
9
|
-
return {
|
|
10
|
-
status: 'denied'
|
|
11
|
-
};
|
|
12
|
-
},
|
|
13
|
-
sendEvents: async ()=>{}
|
|
14
|
-
});
|
|
15
|
-
export const telemetry = store.logger;
|
|
16
|
-
|
|
17
|
-
//# sourceMappingURL=telemetryLogger.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/telemetryLogger.ts"],"sourcesContent":["/**\n * TODO: Remove once we have a proper telemetry logger through the `@sanity/cli-core`\n *\n * This logger does nothing, except provide the interface to interact with\n */\n\nimport {createBatchedStore, createSessionId} from '@sanity/telemetry'\n\nconst session = createSessionId()\nconst store = createBatchedStore(session, {\n async resolveConsent() {\n return {status: 'denied'}\n },\n sendEvents: async () => {},\n})\n\nexport const telemetry = store.logger\n"],"names":["createBatchedStore","createSessionId","session","store","resolveConsent","status","sendEvents","telemetry","logger"],"mappings":"AAAA;;;;CAIC,GAED,SAAQA,kBAAkB,EAAEC,eAAe,QAAO,oBAAmB;AAErE,MAAMC,UAAUD;AAChB,MAAME,QAAQH,mBAAmBE,SAAS;IACxC,MAAME;QACJ,OAAO;YAACC,QAAQ;QAAQ;IAC1B;IACAC,YAAY,WAAa;AAC3B;AAEA,OAAO,MAAMC,YAAYJ,MAAMK,MAAM,CAAA"}
|