@sanity/cli-core 2.1.2 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/README.md +224 -1
  2. package/dist/SanityCommand.d.ts +454 -0
  3. package/dist/SanityCommand.js +5 -4
  4. package/dist/SanityCommand.js.map +1 -1
  5. package/dist/_exports/browser.d.ts +21 -0
  6. package/dist/_exports/browser.js +5 -0
  7. package/dist/_exports/browser.js.map +1 -0
  8. package/dist/_exports/config.d.ts +653 -0
  9. package/dist/_exports/config.js +18 -0
  10. package/dist/_exports/config.js.map +1 -0
  11. package/dist/_exports/debug.d.ts +20 -0
  12. package/dist/_exports/debug.js.map +1 -0
  13. package/dist/_exports/errors.d.ts +67 -0
  14. package/dist/_exports/errors.js +5 -0
  15. package/dist/_exports/errors.js.map +1 -0
  16. package/dist/_exports/index.d.ts +30 -33
  17. package/dist/_exports/index.js +42 -39
  18. package/dist/_exports/index.js.map +1 -1
  19. package/dist/_exports/package-manager.d.ts +191 -0
  20. package/dist/_exports/package-manager.js +3 -0
  21. package/dist/_exports/package-manager.js.map +1 -1
  22. package/dist/_exports/schemas.d.ts +227 -0
  23. package/dist/_exports/schemas.js +4 -0
  24. package/dist/_exports/schemas.js.map +1 -0
  25. package/dist/_exports/tasks.d.ts +120 -0
  26. package/dist/_exports/tasks.js +4 -0
  27. package/dist/_exports/tasks.js.map +1 -0
  28. package/dist/_exports/telemetry.d.ts +156 -0
  29. package/dist/_exports/telemetry.js +7 -0
  30. package/dist/_exports/telemetry.js.map +1 -0
  31. package/dist/_exports/types.d.ts +444 -0
  32. package/dist/_exports/types.js +3 -0
  33. package/dist/_exports/types.js.map +1 -0
  34. package/dist/_exports/util.d.ts +132 -0
  35. package/dist/_exports/util.js +16 -0
  36. package/dist/_exports/util.js.map +1 -0
  37. package/dist/_exports/ux.d.ts +15 -0
  38. package/dist/_exports/ux.js +6 -4
  39. package/dist/_exports/ux.js.map +1 -1
  40. package/dist/apiClient.d.ts +79 -0
  41. package/dist/{services/apiClient.js → apiClient.js} +2 -2
  42. package/dist/{services/apiClient.js.map → apiClient.js.map} +1 -1
  43. package/dist/config/cli/cliTokenCache.js.map +1 -0
  44. package/dist/{services → config/cli}/cliUserConfig.js +31 -6
  45. package/dist/config/cli/cliUserConfig.js.map +1 -0
  46. package/dist/config/cli/getCliConfig.js +1 -1
  47. package/dist/config/cli/getCliConfig.js.map +1 -1
  48. package/dist/config/cli/schemas.js +1 -0
  49. package/dist/config/cli/schemas.js.map +1 -1
  50. package/dist/config/cli/types/cliConfig.js.map +1 -1
  51. package/dist/config/cli/workbenchApp.js +19 -38
  52. package/dist/config/cli/workbenchApp.js.map +1 -1
  53. package/dist/config/studio/getStudioWorkspaces.js +1 -1
  54. package/dist/config/studio/getStudioWorkspaces.js.map +1 -1
  55. package/dist/config/studio/readStudioConfig.worker.js +1 -1
  56. package/dist/config/studio/readStudioConfig.worker.js.map +1 -1
  57. package/dist/exitCodes.d.ts +23 -0
  58. package/dist/loaders/studio/studioWorkerLoader.worker.js +2 -2
  59. package/dist/loaders/studio/studioWorkerLoader.worker.js.map +1 -1
  60. package/dist/telemetry/getCliTelemetry.js +3 -2
  61. package/dist/telemetry/getCliTelemetry.js.map +1 -1
  62. package/dist/telemetry/getTelemetryBaseInfo.js +1 -1
  63. package/dist/telemetry/getTelemetryBaseInfo.js.map +1 -1
  64. package/dist/util/environment/mockBrowserEnvironment.js +3 -2
  65. package/dist/util/environment/mockBrowserEnvironment.js.map +1 -1
  66. package/dist/util/environment/setupBrowserStubs.js +1 -1
  67. package/dist/util/environment/setupBrowserStubs.js.map +1 -1
  68. package/dist/util/getSanityConfigDir.js +1 -0
  69. package/dist/util/getSanityConfigDir.js.map +1 -1
  70. package/dist/util/getSanityEnvVar.js +1 -0
  71. package/dist/util/getSanityEnvVar.js.map +1 -1
  72. package/dist/util/getSanityUrl.js +1 -0
  73. package/dist/util/getSanityUrl.js.map +1 -1
  74. package/dist/util/getWorkspace.js +1 -0
  75. package/dist/util/getWorkspace.js.map +1 -1
  76. package/dist/util/importModule.js +1 -1
  77. package/dist/util/importModule.js.map +1 -1
  78. package/dist/util/promisifyWorker.js +1 -1
  79. package/dist/util/promisifyWorker.js.map +1 -1
  80. package/package.json +57 -9
  81. package/dist/debug.js.map +0 -1
  82. package/dist/services/cliTokenCache.js.map +0 -1
  83. package/dist/services/cliUserConfig.js.map +0 -1
  84. package/dist/services/getCliToken.js +0 -26
  85. package/dist/services/getCliToken.js.map +0 -1
  86. /package/dist/{debug.js → _exports/debug.js} +0 -0
  87. /package/dist/{services → config/cli}/cliTokenCache.js +0 -0
package/README.md CHANGED
@@ -1,3 +1,226 @@
1
1
  # @sanity/cli-core
2
2
 
3
- Helper functions for the Sanity CLI.
3
+ Groups of helper functions for the Sanity CLI and related tooling.
4
+
5
+ # API
6
+
7
+ Instead of importing from the main `@sanity/cli-core` barrel (which pulls in the full dependency graph, including `jsdom`), import from the more granular export sub-paths.
8
+
9
+ > **Note:** The root `@sanity/cli-core` export is kept for backwards compatibility for now. Do not add new exports there; use the appropriate sub-path instead.
10
+
11
+ ## `@sanity/cli-core/apiClient`
12
+
13
+ Authenticated Sanity API client factories.
14
+
15
+ | Export | Description |
16
+ | ------------------------------ | ---------------------------------------------- |
17
+ | `getGlobalCliClient(options)` | Create an unscoped (global) Sanity API client. |
18
+ | `getProjectCliClient(options)` | Create a project-scoped Sanity API client. |
19
+ | `GlobalCliClientOptions` | Options type for `getGlobalCliClient`. |
20
+ | `ProjectCliClientOptions` | Options type for `getProjectCliClient`. |
21
+
22
+ ## `@sanity/cli-core/browser`
23
+
24
+ Browser environment mock. Note this depends on `jsdom` (~46 MB) and so has non-trivial performance implications.
25
+
26
+ | Export | Description |
27
+ | -------------------------- | ---------------------------------------------- |
28
+ | `mockBrowserEnvironment()` | Set up a mocked browser environment via JSDOM. |
29
+
30
+ ## `@sanity/cli-core/config`
31
+
32
+ CLI, studio, and workspace configuration helpers.
33
+
34
+ | Export | Description |
35
+ | --------------------------------- | ----------------------------------------------------------------- |
36
+ | `getCliConfig(workDir)` | Read and cache the CLI config for a project. |
37
+ | `getCliConfigUncached(workDir)` | Read the CLI config without caching. |
38
+ | `getCliConfigSync(workDir)` | Synchronously read the CLI config. |
39
+ | `getCliToken()` | Get the stored CLI authentication token. |
40
+ | `clearCliTokenCache()` | Clear the cached CLI token. |
41
+ | `getCliUserConfig()` | Read the full CLI user config from disk. |
42
+ | `getUserConfig()` | Get a `ConfigStore` instance for the CLI user config. |
43
+ | `setCliUserConfig(key, value)` | Write a value to the CLI user config. |
44
+ | `findProjectRoot(cwd)` | Resolve the nearest project root directory. |
45
+ | `findProjectRootSync(cwd)` | Synchronously resolve the nearest project root. |
46
+ | `getStudioConfig(options)` | Load the studio configuration. |
47
+ | `getStudioWorkspaces(options)` | Resolve the list of studio workspaces. |
48
+ | `isStudioConfig(config)` | Type-guard for studio config objects. |
49
+ | `findStudioConfigPath(cwd)` | Find the studio config file path. |
50
+ | `tryFindStudioConfigPath(cwd)` | Find the studio config file path, returning `null` if not found. |
51
+ | `findPathForFiles(cwd, files)` | Find the directory containing any of the given config file names. |
52
+ | `isWorkbenchApp(config)` | Type-guard for workbench app configs. |
53
+ | `parseWorkbenchCliConfig(config)` | Parse a workbench CLI config object. |
54
+ | `getSanityConfigDir()` | Get the path to the global Sanity config directory. |
55
+ | `getSanityDataDir()` | Get the path to the global Sanity data directory. |
56
+ | `getSanityEnvVar(name)` | Read a `SANITY_*` environment variable. |
57
+ | `getSanityUrl(path?)` | Build a `sanity.io` URL. |
58
+ | `getWorkspace(options)` | Resolve a specific workspace from the studio config. |
59
+
60
+ ## `@sanity/cli-core/debug`
61
+
62
+ Namespaced `debug` logger.
63
+
64
+ | Export | Description |
65
+ | --------------------- | --------------------------------------------------------------- |
66
+ | `debug` | `debug` instance scoped to `sanity:cli`. |
67
+ | `subdebug(namespace)` | Create a child `debug` instance under `sanity:cli:<namespace>`. |
68
+
69
+ ## `@sanity/cli-core/errors`
70
+
71
+ Typed CLI error classes.
72
+
73
+ | Export | Description |
74
+ | --------------------------------- | ------------------------------------------------------- |
75
+ | `NonInteractiveError` | Thrown when a command requires an interactive terminal. |
76
+ | `NotFoundError` | Thrown for 404-type resource-not-found situations. |
77
+ | `isNotFoundError(err)` | Type-guard for `NotFoundError`. |
78
+ | `ProjectRootNotFoundError` | Thrown when no project root can be resolved. |
79
+ | `isProjectRootNotFoundError(err)` | Type-guard for `ProjectRootNotFoundError`. |
80
+
81
+ ## `@sanity/cli-core/package-manager`
82
+
83
+ Package manager detection and utilities.
84
+
85
+ | Export | Description |
86
+ | ------------------------------------- | ---------------------------------------------------------------------- |
87
+ | `getRunningPackageManager()` | Detect which package manager is currently running. |
88
+ | `getBinCommand(pkg, args?)` | Get the correct bin invocation command for the active package manager. |
89
+ | `getYarnMajorVersion()` | Get the major version of the installed Yarn. |
90
+ | `readPackageJson(dir)` | Read and parse a `package.json` file. |
91
+ | `resolveLocalPackage(name)` | Resolve the path to a locally installed package. |
92
+ | `resolveLocalPackageFrom(name, from)` | Resolve a local package relative to a given directory. |
93
+ | `resolveLocalPackagePath(name)` | Resolve only the package root path. |
94
+ | `getLocalPackageDir(name)` | Get the directory of a locally installed package. |
95
+ | `getLocalPackageVersion(name)` | Get the version of a locally installed package. |
96
+ | `DetectedPackageManager` | Union type of supported package manager identifiers. |
97
+ | `PackageJson` | Type representing a parsed `package.json`. |
98
+ | `ReadPackageJsonOptions` | Options type for `readPackageJson`. |
99
+
100
+ ## `@sanity/cli-core/request`
101
+
102
+ HTTP request utilities built on [`get-it`](https://github.com/sanity-io/get-it).
103
+
104
+ | Export | Description |
105
+ | --------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- |
106
+ | `createRequester(middleware?)` | Create a configured `get-it` requester instance. |
107
+ | `Requester` | `get-it` `Requester` type. |
108
+ | `MiddlewareOptions` | Options type for `createRequester`. |
109
+ | `agent`, `base`, `injectResponse`, `jsonRequest`, `jsonResponse`, `keepAlive`, `observable`, `progress`, `proxy`, `retry`, `urlEncoded` | Optional `get-it` middleware for use alongside `createRequester`. |
110
+
111
+ ## `@sanity/cli-core/schemas`
112
+
113
+ Zod schemas for CLI configuration and app manifests.
114
+
115
+ | Export | Description |
116
+ | ----------------------- | ------------------------------------------ |
117
+ | `cliConfigSchema` | Zod schema for the CLI config file. |
118
+ | `coreAppManifestSchema` | Zod schema for core app manifests. |
119
+ | `studioManifestSchema` | Zod schema for studio manifests. |
120
+ | `CoreAppManifest` | Inferred type for `coreAppManifestSchema`. |
121
+ | `StudioManifest` | Inferred type for `studioManifestSchema`. |
122
+
123
+ ## `@sanity/cli-core/tasks`
124
+
125
+ Worker-based task runners.
126
+
127
+ | Export | Description |
128
+ | ------------------------ | -------------------------------------------- |
129
+ | `studioWorkerTask(task)` | Run a task in the studio worker. |
130
+ | `createStudioWorker()` | Create a studio worker instance. |
131
+ | `tsxWorkerTask(task)` | Run a TypeScript task via `tsx` in a worker. |
132
+
133
+ ## `@sanity/cli-core/telemetry`
134
+
135
+ Telemetry store and reporting helpers.
136
+
137
+ | Export | Description |
138
+ | -------------------------- | ----------------------------------------------------------- |
139
+ | `getCliTelemetry()` | Get the active CLI telemetry store. |
140
+ | `setCliTelemetry(store)` | Set the active CLI telemetry store. |
141
+ | `clearCliTelemetry()` | Reset the active CLI telemetry store. |
142
+ | `reportCliTraceError(err)` | Record an error in the active CLI trace. |
143
+ | `getTelemetryBaseInfo()` | Collect base telemetry properties (OS, Node version, etc.). |
144
+ | `noopLogger` | A no-op telemetry logger for use in tests. |
145
+ | `CLI_TELEMETRY_SYMBOL` | Symbol used as the key for the telemetry store. |
146
+
147
+ ## `@sanity/cli-core/types`
148
+
149
+ TypeScript types only — no runtime code.
150
+
151
+ | Export | Description |
152
+ | ------------------------- | ------------------------------------------------------------ |
153
+ | `CliConfig` | Shape of the `sanity.cli.ts` / `sanity.cli.js` config file. |
154
+ | `TypeGenConfig` | Config options for type generation. |
155
+ | `UserViteConfig` | User-supplied Vite config type. |
156
+ | `ApplicationType` | Union of supported Sanity application types. |
157
+ | `ProjectRootResult` | Return type of `findProjectRoot`. |
158
+ | `SanityCommandInterface` | Interface for `SanityCommand` (useful for mocking). |
159
+ | `CLITelemetryStore` | Telemetry store interface. |
160
+ | `ConsentInformation` | Telemetry consent data type. |
161
+ | `TelemetryUserProperties` | Telemetry user properties type. |
162
+ | `Output` | Object type for CLI output helpers (`log`, `warn`, `error`). |
163
+ | `RequireProps` | Utility type to make specific keys required. |
164
+ | `SanityOrgUser` | Shape of a Sanity organization user. |
165
+ | `PackageJson` | Parsed `package.json` type. |
166
+ | `ReadPackageJsonOptions` | Options for `readPackageJson`. |
167
+ | `CoreAppManifest` | Core app manifest type. |
168
+ | `StudioManifest` | Studio manifest type. |
169
+
170
+ ## `@sanity/cli-core/util`
171
+
172
+ Pure, zero-dependency utility functions related to module importing, paths and path resolution, environment detection and other miscellaneous tools.
173
+
174
+ | Export | Description |
175
+ | ------------------------------- | ---------------------------------------------------------------------- |
176
+ | `doImport(specifier)` | Dynamically import a module. |
177
+ | `importModule(specifier, root)` | Import a module resolved relative to a project root. |
178
+ | `getSanityConfigDir()` | Get the global Sanity config directory. |
179
+ | `getSanityDataDir()` | Get the global Sanity data directory. |
180
+ | `getSanityEnvVar(name)` | Read a `SANITY_*` environment variable. |
181
+ | `getSanityUrl(path?)` | Build a `sanity.io` URL. |
182
+ | `getWorkspace(options)` | Resolve a workspace from the studio config. |
183
+ | `isCi()` | Detect whether running in a CI environment. |
184
+ | `isInteractive()` | Detect whether the terminal is interactive. |
185
+ | `isStaging()` | Detect whether running against the staging API. |
186
+ | `isTrueish(value)` | Return `true` for common truthy string values (`"1"`, `"true"`, etc.). |
187
+ | `normalizePath(path)` | Normalize a file path to use forward slashes. |
188
+ | `safeStructuredClone(value)` | `structuredClone` with a fallback for environments that lack it. |
189
+
190
+ ## `@sanity/cli-core/ux`
191
+
192
+ Terminal UI utilities: prompts, spinners, boxes, and more.
193
+
194
+ | Export | Description |
195
+ | -------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- |
196
+ | `select`, `input`, `confirm`, `checkbox`, `password`, `number`, `search`, `editor`, `expand`, `rawlist`, `Separator` | Interactive prompt helpers from `@inquirer/prompts`. |
197
+ | `spinner(options?)` | Create a terminal spinner. |
198
+ | `spinnerPromise(promise, options)` | Wrap a promise with a spinner. |
199
+ | `Spinner`, `SpinnerInstance`, `SpinnerOptions`, `SpinnerPromiseOptions` | Spinner types. |
200
+ | `boxen(text, options?)` | Render text inside a terminal box. |
201
+ | `BoxenOptions`, `Boxes`, `CustomBorderStyle`, `Spacing` | `boxen` types. |
202
+ | `colorizeJson(value)` | Pretty-print and colorize a JSON value for terminal output. |
203
+ | `logSymbols` | Colored Unicode symbols: `✔` `✖` `⚠` `ℹ`. |
204
+ | `getTimer()` | Create a high-resolution timer. |
205
+ | `NonInteractiveError` | Error thrown when a prompt runs in a non-interactive terminal. |
206
+
207
+ ## `@sanity/cli-core/SanityCommand`
208
+
209
+ Base class for building Sanity CLI commands (wraps [oclif](https://oclif.io/)).
210
+
211
+ | Export | Description |
212
+ | ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------- |
213
+ | `SanityCommand` | Abstract base `Command` class with Sanity-specific helpers (`getCliConfig`, `getProjectId`, `getProjectRoot`, `isUnattended`, `output`, etc.). |
214
+ | `SanityCommandInterface` | Interface for `SanityCommand`, useful for creating mock implementations in tests. |
215
+
216
+ ## `@sanity/cli-core/ExitCodes`
217
+
218
+ Standard exit codes for CLI commands.
219
+
220
+ | Export | Description |
221
+ | ------------------------- | --------------------------------------------------------- |
222
+ | `exitCodes.SUCCESS` | `0` — command completed normally. |
223
+ | `exitCodes.RUNTIME_ERROR` | `1` — something went wrong (API errors, network, config). |
224
+ | `exitCodes.USAGE_ERROR` | `2` — user provided invalid input. |
225
+ | `exitCodes.USER_ABORT` | `3` — user declined a confirmation. |
226
+ | `exitCodes.SIGINT` | `130` — user interrupted via Ctrl+C (128 + SIGINT). |
@@ -0,0 +1,454 @@
1
+ import { ClientConfig } from "@sanity/client";
2
+ import { Command } from "@oclif/core";
3
+ import { CommandError } from "@oclif/core/interfaces";
4
+ import { ConfigEnv } from "vite";
5
+ import { InlineConfig } from "vite";
6
+ import { Interfaces } from "@oclif/core";
7
+ import { PluginOptions } from "babel-plugin-react-compiler";
8
+ import { SanityClient } from "sanity";
9
+
10
+ declare type Args<T extends typeof Command> = Interfaces.InferredArgs<
11
+ T["args"]
12
+ >;
13
+
14
+ /**
15
+ * @public
16
+ */
17
+ declare interface CliConfig {
18
+ /** The project ID and dataset the Sanity CLI should use to run its commands */
19
+ api?: {
20
+ dataset?: string;
21
+ projectId?: string;
22
+ };
23
+ /** Configuration for custom Sanity apps built with the App SDK */
24
+ app?: {
25
+ /** The entrypoint for your custom app. By default, `src/App.tsx` */
26
+ entry?: string;
27
+ /** Dock group the app renders in. Defaults to `dock.applications`. */
28
+ group?: "dock.applications" | "dock.system" | "dock.user";
29
+ /**
30
+ * Path to an icon file relative to project root.
31
+ * The file must be an SVG.
32
+ */
33
+ icon?: string;
34
+ /** @deprecated Use deployment.appId */
35
+ id?: string;
36
+ /** The ID for the Sanity organization that manages this application */
37
+ organizationId?: string;
38
+ /** Sort position within the dock group, ascending. Defaults to `100`. */
39
+ priority?: number;
40
+ /** The title of the custom app, as it is seen in Dashboard UI */
41
+ title?: string;
42
+ };
43
+ /** @deprecated Use deployment.autoUpdates */
44
+ autoUpdates?: boolean;
45
+ /** Options for custom app and Studio deployments */
46
+ deployment?: {
47
+ /**
48
+ * The ID for your custom app or Studio. Generated when deploying your app or Studio for the first time.
49
+ * Get your app ID by either:
50
+ * 1. Checking the output of `sanity deploy`, or
51
+ * 2. Checking your project’s Studio tab at https://sanity.io/manage
52
+ *
53
+ * @remarks This is required for all custom app deployments, and for Studios opting in to fine grained version control.
54
+ * {@link https://www.sanity.io/docs/studio/latest-version-of-sanity#k0896ed4574b7}
55
+ */
56
+ appId?: string;
57
+ /**
58
+ * Enable automatic updates for your Studio or custom app’s Sanity dependencies.
59
+ * {@link https://www.sanity.io/docs/studio/latest-version-of-sanity}
60
+ */
61
+ autoUpdates?: boolean;
62
+ };
63
+ /** Define the GraphQL APIs that the CLI can deploy and interact with */
64
+ graphql?: Array<{
65
+ filterSuffix?: string;
66
+ generation?: "gen1" | "gen2" | "gen3";
67
+ id?: string;
68
+ nonNullDocumentFields?: boolean;
69
+ playground?: boolean;
70
+ source?: string;
71
+ tag?: string;
72
+ workspace?: string;
73
+ }>;
74
+ /** Configuration for the Media Library */
75
+ mediaLibrary?: {
76
+ /** The path to the Media Library aspects directory. When using the CLI to manage aspects, this is the directory they will be read from and written to. */
77
+ aspectsPath?: string;
78
+ };
79
+ /** Contains the property `basePath` which lets you change the top-level slug for the Studio. You typically need to set this if you embed the Studio in another application where it is one of many routes. Defaults to an empty string. */
80
+ project?: {
81
+ basePath?: string;
82
+ };
83
+ /** Configuration options for React Compiler */
84
+ reactCompiler?: PluginOptions;
85
+ /** Wraps the Studio in \<React.StrictMode\> root to aid in flagging potential problems related to concurrent features (startTransition, useTransition, useDeferredValue, Suspense). Can also be enabled by setting SANITY_STUDIO_REACT_STRICT_MODE="true"|"false". It only applies to sanity dev in development mode and is ignored in sanity build and in production. Defaults to true. */
86
+ reactStrictMode?: boolean;
87
+ /**
88
+ * Configuration for schema extraction (`sanity schema extract`)
89
+ */
90
+ schemaExtraction?: {
91
+ /**
92
+ * Enable schema extraction as part of sanity dev and sanity build
93
+ */
94
+ enabled?: boolean;
95
+ /**
96
+ * When true, schema fields marked as required will be non-optional in the output.
97
+ * Defaults to `false`
98
+ */
99
+ enforceRequiredFields?: boolean;
100
+ /**
101
+ * Output path for the extracted schema file.
102
+ * Defaults to `schema.json` in the working directory.
103
+ */
104
+ path?: string;
105
+ /**
106
+ * Additional glob patterns to watch for schema changes in watch mode.
107
+ * These extend the default patterns:
108
+ * - `sanity.config.{js,jsx,ts,tsx,mjs}`
109
+ * - `schema*\/**\/*.{js,jsx,ts,tsx,mjs}`
110
+ */
111
+ watchPatterns?: string[];
112
+ /**
113
+ * The name of the workspace to generate a schema for. Required if your Sanity project has more than one
114
+ * workspace.
115
+ */
116
+ workspace?: string;
117
+ };
118
+ /** Defines the hostname and port that the development server should run on. hostname defaults to localhost, and port to 3333. */
119
+ server?: {
120
+ hostname?: string;
121
+ port?: number;
122
+ };
123
+ /** @deprecated Use deployment.appId */
124
+ studioHost?: string;
125
+ /**
126
+ * Configuration for Sanity typegen
127
+ */
128
+ typegen?: Partial<TypeGenConfig> & {
129
+ /**
130
+ * Enable typegen as part of sanity dev and sanity build.
131
+ * When enabled, types are generated on startup and when files change.
132
+ * Defaults to `false`
133
+ */
134
+ enabled?: boolean;
135
+ };
136
+ /**
137
+ * Enable Vite's experimental bundled dev mode for `sanity dev`. This serves bundled
138
+ * files during development, which can speed up startup and reloads for large projects.
139
+ * Defaults to `false`.
140
+ *
141
+ * Unstable: may change or be removed without notice while the underlying Vite
142
+ * feature (`experimental.bundledDev`) is experimental.
143
+ * {@link https://vite.dev/guide/rolldown#full-bundle-mode}
144
+ */
145
+ unstable_bundledDev?: boolean;
146
+ /** Exposes the default Vite configuration for custom apps and the Studio so it can be changed and extended. */
147
+ vite?: UserViteConfig;
148
+ }
149
+
150
+ /**
151
+ * @public
152
+ */
153
+ declare type CLITelemetryStore = TelemetryLogger<TelemetryUserProperties>;
154
+
155
+ declare interface DeferredEvent<
156
+ Data = unknown,
157
+ Event extends DefinedTelemetryLog<Data> = DefinedTelemetryLog<Data>,
158
+ > {
159
+ createdAt: string;
160
+ event: Event;
161
+ data: Data;
162
+ }
163
+
164
+ declare interface DefinedTelemetryLog<Schema> {
165
+ type: "log";
166
+ /** Unique name of the event */
167
+ name: string;
168
+ /** Event version. Increment this by 1 whenever the shape of the data changes in a non-backwards compatible way */
169
+ version: number;
170
+ /** Description of log event */
171
+ description?: string;
172
+ /**
173
+ * Max sample rate of this event.
174
+ * Calling telemetry.log(EventDefinition, data) repeatedly will submit at most one event every specified time interval (in milliseconds)
175
+ * */
176
+ maxSampleRate?: number;
177
+ /** Data schema. Will not be accessible at runtime */
178
+ schema: Schema;
179
+ }
180
+
181
+ declare interface DefinedTelemetryTrace<Data = void, Context = void> {
182
+ type: "trace";
183
+ /** Unique name of the trace */
184
+ name: string;
185
+ /** Trace version. Increment this by 1 whenever the shape of the data changes in a non-backwards compatible way */
186
+ version: number;
187
+ /** Description of trace */
188
+ description?: string;
189
+ /** Data schema. Will not be accessible at runtime */
190
+ schema: Data;
191
+ /** Contextual data schema. Will not be accessible at runtime */
192
+ context: Context;
193
+ }
194
+
195
+ declare type Flags<T extends typeof Command> = Interfaces.InferredFlags<
196
+ (typeof SanityCommand)["baseFlags"] & T["flags"]
197
+ >;
198
+
199
+ /**
200
+ * @public
201
+ */
202
+ declare interface GlobalCliClientOptions extends ClientConfig {
203
+ /**
204
+ * The API version to use for this client.
205
+ */
206
+ apiVersion: string;
207
+ /**
208
+ * Whether to require a user to be authenticated to use this client.
209
+ * Default: `false`.
210
+ * Throws an error if `true` and user is not authenticated.
211
+ */
212
+ requireUser?: boolean;
213
+ /**
214
+ * Whether to skip reading the stored CLI token. When `true`, the client will
215
+ * have no token unless one is explicitly provided.
216
+ * Default: `false`.
217
+ */
218
+ unauthenticated?: boolean;
219
+ }
220
+
221
+ declare interface Output {
222
+ error: Command["error"];
223
+ log: Command["log"];
224
+ warn: Command["warn"];
225
+ }
226
+
227
+ /**
228
+ * @public
229
+ */
230
+ declare interface ProjectCliClientOptions extends ClientConfig {
231
+ /**
232
+ * The API version to use for this client.
233
+ */
234
+ apiVersion: string;
235
+ /**
236
+ * The project ID to use for this client.
237
+ */
238
+ projectId: string;
239
+ /**
240
+ * The dataset to use for this client.
241
+ */
242
+ dataset?: string;
243
+ /**
244
+ * Whether to require a user to be authenticated to use this client.
245
+ * Default: `false`.
246
+ * Throws an error if `true` and user is not authenticated.
247
+ */
248
+ requireUser?: boolean;
249
+ }
250
+
251
+ /**
252
+ * Result of finding a project configuration
253
+ *
254
+ * @public
255
+ */
256
+ declare interface ProjectRootResult {
257
+ directory: string;
258
+ /**
259
+ * Path to the project configuration file, if found.
260
+ */
261
+ path: string;
262
+ /**
263
+ * Type of project root.
264
+ */
265
+ type: "app" | "studio";
266
+ }
267
+
268
+ export declare abstract class SanityCommand<T extends typeof Command>
269
+ extends Command
270
+ implements SanityCommandInterface
271
+ {
272
+ protected args: Args<T>;
273
+ protected flags: Flags<T>;
274
+ /**
275
+ * Get the global API client.
276
+ *
277
+ * @param args - The global API client options.
278
+ * @returns The global API client.
279
+ *
280
+ * @deprecated use `getGlobalCliClient` function directly instead.
281
+ */
282
+ protected getGlobalApiClient: (
283
+ args: GlobalCliClientOptions,
284
+ ) => Promise<SanityClient>;
285
+ /**
286
+ * Get the project API client.
287
+ *
288
+ * @param args - The project API client options.
289
+ * @returns The project API client.
290
+ *
291
+ * @deprecated use `getProjectCliClient` function directly instead.
292
+ */
293
+ protected getProjectApiClient: (
294
+ args: ProjectCliClientOptions,
295
+ ) => Promise<SanityClient>;
296
+ /**
297
+ * Helper for outputting to the console.
298
+ *
299
+ * @example
300
+ * ```ts
301
+ * this.output.log('Hello')
302
+ * this.output.warn('Warning')
303
+ * this.output.error('Error')
304
+ * ```
305
+ */
306
+ output: Output;
307
+ /**
308
+ * The telemetry store.
309
+ *
310
+ * @returns The telemetry store.
311
+ */
312
+ protected telemetry: CLITelemetryStore;
313
+ /**
314
+ * Report real command errors to the CLI command trace.
315
+ * User aborts (SIGINT, ExitPromptError) are not reported — the trace is left
316
+ * incomplete, which accurately represents that the command was interrupted.
317
+ */
318
+ protected catch(err: CommandError): Promise<void>;
319
+ /**
320
+ * Get the CLI config.
321
+ *
322
+ * @returns The CLI config.
323
+ */
324
+ getCliConfig(): Promise<CliConfig>;
325
+ /**
326
+ * Get the project ID from passed flags or (if not provided) the CLI config.
327
+ *
328
+ * Optionally accepts a `fallback` function that is called when no project ID
329
+ * can be determined from flags or config. This allows commands to provide
330
+ * interactive project selection while keeping the prompt logic in the CLI package.
331
+ *
332
+ * If the fallback throws a `NonInteractiveError` (e.g. because the terminal is
333
+ * not interactive), it falls through to the standard error with suggestions.
334
+ *
335
+ * Optionally accepts a `deprecatedFlagName` for commands that have a deprecated
336
+ * flag (e.g. `--project`) that should be checked after `--project-id` but before
337
+ * the CLI config.
338
+ *
339
+ * @returns The project ID.
340
+ */
341
+ getProjectId(options?: {
342
+ deprecatedFlagName?: string;
343
+ fallback?: () => Promise<string>;
344
+ }): Promise<string>;
345
+ /**
346
+ * Get the project's root directory by resolving the config
347
+ *
348
+ * @returns The project root result.
349
+ */
350
+ getProjectRoot(): Promise<ProjectRootResult>;
351
+ init(): Promise<void>;
352
+ /**
353
+ * Check if the command is running in unattended mode.
354
+ *
355
+ * This means the command should not ask for user input, instead using defaults where
356
+ * possible, and if that does not make sense (eg there's missing information), then we
357
+ * should error out (remember to exit with a non-zero code).
358
+ *
359
+ * Most commands should take an explicit `--yes` flag to enable unattended mode, but
360
+ * some commands may also be run in unattended mode if `process.stdin` is not a TTY
361
+ * (eg when running in a CI environment), or when `--json` asks for machine-readable
362
+ * output (a caller parsing JSON can't answer a prompt).
363
+ */
364
+ isUnattended(): boolean;
365
+ /**
366
+ * Resolver for checking if the terminal is interactive. Override in tests to provide mock values.
367
+ *
368
+ * @returns Whether the terminal is interactive.
369
+ */
370
+ resolveIsInteractive(): boolean;
371
+ /**
372
+ * Get the CLI config, returning an empty config if no project root is found.
373
+ *
374
+ * Use this instead of `getCliConfig()` in commands that can operate without a
375
+ * project directory (e.g. when `--project-id` and `--dataset` flags are provided).
376
+ *
377
+ * @returns The CLI config, or an empty config object if no project root is found.
378
+ */
379
+ protected tryGetCliConfig(): Promise<CliConfig>;
380
+ }
381
+
382
+ /**
383
+ * Interface for `SanityCommand`, a wrapper around OCLIF's Command class.
384
+ * Important to keep updated as `SanityCommand` evolves so that its mock implementation (enabling fast unit tests) stays up to date as well.
385
+ * @see https://oclif.io/docs/base_class/
386
+ */
387
+ export declare interface SanityCommandInterface {
388
+ getCliConfig: () => Promise<CliConfig>;
389
+ getProjectId: (options?: {
390
+ deprecatedFlagName?: string;
391
+ fallback?: () => Promise<string>;
392
+ }) => Promise<string>;
393
+ getProjectRoot: () => Promise<ProjectRootResult>;
394
+ isUnattended: () => boolean;
395
+ output: Output;
396
+ resolveIsInteractive: () => boolean;
397
+ }
398
+
399
+ /**
400
+ * Note that `sessionId` is removed from the signature of these functions
401
+ */
402
+ declare interface TelemetryLogger<UserProperties> {
403
+ updateUserProperties(properties: UserProperties): void;
404
+ resume(events: DeferredEvent[]): void;
405
+ log<Data>(event: DefinedTelemetryLog<Data>, data: Data): void;
406
+ log<Data extends void>(event: DefinedTelemetryLog<Data>): void;
407
+ trace<Data>(
408
+ event: DefinedTelemetryTrace<Data>,
409
+ context?: unknown,
410
+ ): TelemetryTrace<UserProperties, Data>;
411
+ }
412
+
413
+ declare interface TelemetryTrace<UserProperties, Data> {
414
+ start(): void;
415
+ log(data: Data): void;
416
+ error(error: Error): void;
417
+ complete(): void;
418
+ newContext(name: string): TelemetryLogger<UserProperties>;
419
+ await<P extends Promise<Data>>(promise: P): P;
420
+ await<P extends Promise<unknown>>(promise: P, finalData: Data): P;
421
+ }
422
+
423
+ /**
424
+ * @public
425
+ */
426
+ declare interface TelemetryUserProperties {
427
+ cliVersion: string;
428
+ cpuArchitecture: string;
429
+ machinePlatform: string;
430
+ runtime: string;
431
+ runtimeVersion: string;
432
+ dataset?: string;
433
+ projectId?: string;
434
+ }
435
+
436
+ declare interface TypeGenConfig {
437
+ formatGeneratedCode: boolean;
438
+ generates: string;
439
+ overloadClientMethods: boolean;
440
+ path: string | string[];
441
+ schema: string;
442
+ }
443
+
444
+ /**
445
+ * @public
446
+ */
447
+ declare type UserViteConfig =
448
+ | ((
449
+ config: InlineConfig,
450
+ env: ConfigEnv,
451
+ ) => InlineConfig | Promise<InlineConfig>)
452
+ | InlineConfig;
453
+
454
+ export {};