@sanity/cli-core 0.0.0-20260410130107

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 (155) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -0
  3. package/dist/SanityCommand.js +196 -0
  4. package/dist/SanityCommand.js.map +1 -0
  5. package/dist/_exports/index.d.ts +1391 -0
  6. package/dist/_exports/index.js +39 -0
  7. package/dist/_exports/index.js.map +1 -0
  8. package/dist/_exports/package-manager.d.ts +33 -0
  9. package/dist/_exports/package-manager.js +3 -0
  10. package/dist/_exports/package-manager.js.map +1 -0
  11. package/dist/_exports/request.d.ts +79 -0
  12. package/dist/_exports/request.js +7 -0
  13. package/dist/_exports/request.js.map +1 -0
  14. package/dist/_exports/ux.d.ts +75 -0
  15. package/dist/_exports/ux.js +7 -0
  16. package/dist/_exports/ux.js.map +1 -0
  17. package/dist/config/cli/getCliConfig.js +68 -0
  18. package/dist/config/cli/getCliConfig.js.map +1 -0
  19. package/dist/config/cli/getCliConfigSync.js +51 -0
  20. package/dist/config/cli/getCliConfigSync.js.map +1 -0
  21. package/dist/config/cli/schemas.js +62 -0
  22. package/dist/config/cli/schemas.js.map +1 -0
  23. package/dist/config/cli/types/cliConfig.js +5 -0
  24. package/dist/config/cli/types/cliConfig.js.map +1 -0
  25. package/dist/config/cli/types/userViteConfig.js +5 -0
  26. package/dist/config/cli/types/userViteConfig.js.map +1 -0
  27. package/dist/config/findProjectRoot.js +62 -0
  28. package/dist/config/findProjectRoot.js.map +1 -0
  29. package/dist/config/findProjectRootSync.js +88 -0
  30. package/dist/config/findProjectRootSync.js.map +1 -0
  31. package/dist/config/studio/getStudioConfig.js +13 -0
  32. package/dist/config/studio/getStudioConfig.js.map +1 -0
  33. package/dist/config/studio/getStudioWorkspaces.js +63 -0
  34. package/dist/config/studio/getStudioWorkspaces.js.map +1 -0
  35. package/dist/config/studio/isStudioConfig.js +19 -0
  36. package/dist/config/studio/isStudioConfig.js.map +1 -0
  37. package/dist/config/studio/readStudioConfig.js +82 -0
  38. package/dist/config/studio/readStudioConfig.js.map +1 -0
  39. package/dist/config/studio/readStudioConfig.worker.js +25 -0
  40. package/dist/config/studio/readStudioConfig.worker.js.map +1 -0
  41. package/dist/config/util/configPathsSync.js +85 -0
  42. package/dist/config/util/configPathsSync.js.map +1 -0
  43. package/dist/config/util/findAppConfigPath.js +22 -0
  44. package/dist/config/util/findAppConfigPath.js.map +1 -0
  45. package/dist/config/util/findConfigsPaths.js +21 -0
  46. package/dist/config/util/findConfigsPaths.js.map +1 -0
  47. package/dist/config/util/findStudioConfigPath.js +52 -0
  48. package/dist/config/util/findStudioConfigPath.js.map +1 -0
  49. package/dist/config/util/isSanityV2StudioRoot.js +22 -0
  50. package/dist/config/util/isSanityV2StudioRoot.js.map +1 -0
  51. package/dist/config/util/recursivelyResolveProjectRoot.js +28 -0
  52. package/dist/config/util/recursivelyResolveProjectRoot.js.map +1 -0
  53. package/dist/debug.js +15 -0
  54. package/dist/debug.js.map +1 -0
  55. package/dist/errors/NonInteractiveError.js +18 -0
  56. package/dist/errors/NonInteractiveError.js.map +1 -0
  57. package/dist/errors/NotFoundError.js +27 -0
  58. package/dist/errors/NotFoundError.js.map +1 -0
  59. package/dist/errors/ProjectRootNotFoundError.js +35 -0
  60. package/dist/errors/ProjectRootNotFoundError.js.map +1 -0
  61. package/dist/exitCodes.js +17 -0
  62. package/dist/exitCodes.js.map +1 -0
  63. package/dist/loaders/studio/studioWorkerLoader.worker.js +205 -0
  64. package/dist/loaders/studio/studioWorkerLoader.worker.js.map +1 -0
  65. package/dist/loaders/studio/studioWorkerTask.js +90 -0
  66. package/dist/loaders/studio/studioWorkerTask.js.map +1 -0
  67. package/dist/loaders/tsx/tsxWorkerLoader.worker.js +11 -0
  68. package/dist/loaders/tsx/tsxWorkerLoader.worker.js.map +1 -0
  69. package/dist/loaders/tsx/tsxWorkerTask.js +34 -0
  70. package/dist/loaders/tsx/tsxWorkerTask.js.map +1 -0
  71. package/dist/request/createRequester.js +83 -0
  72. package/dist/request/createRequester.js.map +1 -0
  73. package/dist/services/apiClient.js +97 -0
  74. package/dist/services/apiClient.js.map +1 -0
  75. package/dist/services/cliTokenCache.js +25 -0
  76. package/dist/services/cliTokenCache.js.map +1 -0
  77. package/dist/services/cliUserConfig.js +144 -0
  78. package/dist/services/cliUserConfig.js.map +1 -0
  79. package/dist/services/getCliToken.js +26 -0
  80. package/dist/services/getCliToken.js.map +1 -0
  81. package/dist/telemetry/getCliTelemetry.js +47 -0
  82. package/dist/telemetry/getCliTelemetry.js.map +1 -0
  83. package/dist/telemetry/getTelemetryBaseInfo.js +33 -0
  84. package/dist/telemetry/getTelemetryBaseInfo.js.map +1 -0
  85. package/dist/telemetry/readNDJSON.js +18 -0
  86. package/dist/telemetry/readNDJSON.js.map +1 -0
  87. package/dist/telemetry/types.js +5 -0
  88. package/dist/telemetry/types.js.map +1 -0
  89. package/dist/types.js +5 -0
  90. package/dist/types.js.map +1 -0
  91. package/dist/util/doImport.js +17 -0
  92. package/dist/util/doImport.js.map +1 -0
  93. package/dist/util/environment/getStudioEnvironmentVariables.js +36 -0
  94. package/dist/util/environment/getStudioEnvironmentVariables.js.map +1 -0
  95. package/dist/util/environment/mockBrowserEnvironment.js +47 -0
  96. package/dist/util/environment/mockBrowserEnvironment.js.map +1 -0
  97. package/dist/util/environment/setupBrowserStubs.js +42 -0
  98. package/dist/util/environment/setupBrowserStubs.js.map +1 -0
  99. package/dist/util/environment/stubs.js +142 -0
  100. package/dist/util/environment/stubs.js.map +1 -0
  101. package/dist/util/fileExists.js +13 -0
  102. package/dist/util/fileExists.js.map +1 -0
  103. package/dist/util/generateHelpUrl.js +11 -0
  104. package/dist/util/generateHelpUrl.js.map +1 -0
  105. package/dist/util/getEmptyAuth.js +16 -0
  106. package/dist/util/getEmptyAuth.js.map +1 -0
  107. package/dist/util/getSanityEnvVar.js +24 -0
  108. package/dist/util/getSanityEnvVar.js.map +1 -0
  109. package/dist/util/getSanityUrl.js +9 -0
  110. package/dist/util/getSanityUrl.js.map +1 -0
  111. package/dist/util/importModule.js +32 -0
  112. package/dist/util/importModule.js.map +1 -0
  113. package/dist/util/isCi.js +7 -0
  114. package/dist/util/isCi.js.map +1 -0
  115. package/dist/util/isInteractive.js +5 -0
  116. package/dist/util/isInteractive.js.map +1 -0
  117. package/dist/util/isRecord.js +11 -0
  118. package/dist/util/isRecord.js.map +1 -0
  119. package/dist/util/isStaging.js +10 -0
  120. package/dist/util/isStaging.js.map +1 -0
  121. package/dist/util/isTrueish.js +10 -0
  122. package/dist/util/isTrueish.js.map +1 -0
  123. package/dist/util/normalizePath.js +12 -0
  124. package/dist/util/normalizePath.js.map +1 -0
  125. package/dist/util/packageManager.js +55 -0
  126. package/dist/util/packageManager.js.map +1 -0
  127. package/dist/util/promisifyWorker.js +72 -0
  128. package/dist/util/promisifyWorker.js.map +1 -0
  129. package/dist/util/readJsonFile.js +26 -0
  130. package/dist/util/readJsonFile.js.map +1 -0
  131. package/dist/util/readJsonFileSync.js +26 -0
  132. package/dist/util/readJsonFileSync.js.map +1 -0
  133. package/dist/util/readPackageJson.js +74 -0
  134. package/dist/util/readPackageJson.js.map +1 -0
  135. package/dist/util/resolveLocalPackage.js +82 -0
  136. package/dist/util/resolveLocalPackage.js.map +1 -0
  137. package/dist/util/safeStructuredClone.js +43 -0
  138. package/dist/util/safeStructuredClone.js.map +1 -0
  139. package/dist/util/tryGetDefaultExport.js +18 -0
  140. package/dist/util/tryGetDefaultExport.js.map +1 -0
  141. package/dist/util/writeJsonFileSync.js +19 -0
  142. package/dist/util/writeJsonFileSync.js.map +1 -0
  143. package/dist/ux/boxen.js +3 -0
  144. package/dist/ux/boxen.js.map +1 -0
  145. package/dist/ux/colorizeJson.js +32 -0
  146. package/dist/ux/colorizeJson.js.map +1 -0
  147. package/dist/ux/logSymbols.js +3 -0
  148. package/dist/ux/logSymbols.js.map +1 -0
  149. package/dist/ux/prompts.js +51 -0
  150. package/dist/ux/prompts.js.map +1 -0
  151. package/dist/ux/spinner.js +3 -0
  152. package/dist/ux/spinner.js.map +1 -0
  153. package/dist/ux/timer.js +29 -0
  154. package/dist/ux/timer.js.map +1 -0
  155. package/package.json +111 -0
@@ -0,0 +1,1391 @@
1
+ import { ClientConfig } from "@sanity/client";
2
+ import { CLIError } from "@oclif/core/errors";
3
+ import { Command } from "@oclif/core";
4
+ import { CommandError } from "@oclif/core/interfaces";
5
+ import { ConfigEnv } from "vite";
6
+ import { ConsentStatus } from "@sanity/telemetry";
7
+ import debugIt from "debug";
8
+ import { InlineConfig } from "vite";
9
+ import { Interfaces } from "@oclif/core";
10
+ import { PluginOptions } from "babel-plugin-react-compiler";
11
+ import { SanityClient } from "sanity";
12
+ import { SanityClient as SanityClient_2 } from "@sanity/client";
13
+ import { TelemetryLogger } from "@sanity/telemetry";
14
+ import { URL as URL_2 } from "node:url";
15
+ import { Worker as Worker_2 } from "node:worker_threads";
16
+ import { WorkerOptions as WorkerOptions_2 } from "node:worker_threads";
17
+ import { Workspace } from "sanity";
18
+ import { z } from "zod/mini";
19
+
20
+ declare type Args<T extends typeof Command> = Interfaces.InferredArgs<
21
+ T["args"]
22
+ >;
23
+
24
+ /**
25
+ * Clears the global CLI telemetry store.
26
+ * @internal
27
+ */
28
+ export declare function clearCliTelemetry(): void;
29
+
30
+ /**
31
+ * Clear the in-process token cache so the next `getCliToken()` call
32
+ * re-reads from disk or the environment.
33
+ *
34
+ * Called automatically by `setCliUserConfig('authToken', ...)`.
35
+ *
36
+ * @internal
37
+ */
38
+ export declare function clearCliTokenCache(): void;
39
+
40
+ /**
41
+ * @public
42
+ * Symbol used to store CLI telemetry state on globalThis.
43
+ * Use the accessor functions instead of accessing this directly.
44
+ */
45
+ export declare const CLI_TELEMETRY_SYMBOL: unique symbol;
46
+
47
+ /**
48
+ * @public
49
+ */
50
+ export declare interface CliConfig {
51
+ /** The project ID and dataset the Sanity CLI should use to run its commands */
52
+ api?: {
53
+ dataset?: string;
54
+ projectId?: string;
55
+ };
56
+ /** Configuration for custom Sanity apps built with the App SDK */
57
+ app?: {
58
+ /** The entrypoint for your custom app. By default, `src/App.tsx` */
59
+ entry?: string;
60
+ /**
61
+ * Path to an icon file relative to project root.
62
+ * The file must be an SVG.
63
+ */
64
+ icon?: string;
65
+ /** @deprecated Use deployment.appId */
66
+ id?: string;
67
+ /** The ID for the Sanity organization that manages this application */
68
+ organizationId?: string;
69
+ /** The title of the custom app, as it is seen in Dashboard UI */
70
+ title?: string;
71
+ };
72
+ /** @deprecated Use deployment.autoUpdates */
73
+ autoUpdates?: boolean;
74
+ /** Options for custom app and Studio deployments */
75
+ deployment?: {
76
+ /**
77
+ * The ID for your custom app or Studio. Generated when deploying your app or Studio for the first time.
78
+ * Get your app ID by either:
79
+ * 1. Checking the output of `sanity deploy`, or
80
+ * 2. Checking your project’s Studio tab at https://sanity.io/manage
81
+ *
82
+ * @remarks This is required for all custom app deployments, and for Studios opting in to fine grained version control.
83
+ * {@link https://www.sanity.io/docs/studio/latest-version-of-sanity#k0896ed4574b7}
84
+ */
85
+ appId?: string;
86
+ /**
87
+ * Enable automatic updates for your Studio or custom app’s Sanity dependencies.
88
+ * {@link https://www.sanity.io/docs/studio/latest-version-of-sanity}
89
+ */
90
+ autoUpdates?: boolean;
91
+ };
92
+ /**
93
+ * Enable federated builds & dev environments for your studio or application.
94
+ * @experimental
95
+ */
96
+ federation?: {
97
+ enabled: boolean;
98
+ };
99
+ /** Define the GraphQL APIs that the CLI can deploy and interact with */
100
+ graphql?: Array<{
101
+ filterSuffix?: string;
102
+ generation?: "gen1" | "gen2" | "gen3";
103
+ id?: string;
104
+ nonNullDocumentFields?: boolean;
105
+ playground?: boolean;
106
+ source?: string;
107
+ tag?: string;
108
+ workspace?: string;
109
+ }>;
110
+ /** Configuration for the Media Library */
111
+ mediaLibrary?: {
112
+ /** 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. */
113
+ aspectsPath?: string;
114
+ };
115
+ /** 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. */
116
+ project?: {
117
+ basePath?: string;
118
+ };
119
+ /** Configuration options for React Compiler */
120
+ reactCompiler?: PluginOptions;
121
+ /** 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 false. */
122
+ reactStrictMode?: boolean;
123
+ /**
124
+ * Configuration for schema extraction (`sanity schema extract`)
125
+ */
126
+ schemaExtraction?: {
127
+ /**
128
+ * Enable schema extraction as part of sanity dev and sanity build
129
+ */
130
+ enabled?: boolean;
131
+ /**
132
+ * When true, schema fields marked as required will be non-optional in the output.
133
+ * Defaults to `false`
134
+ */
135
+ enforceRequiredFields?: boolean;
136
+ /**
137
+ * Output path for the extracted schema file.
138
+ * Defaults to `schema.json` in the working directory.
139
+ */
140
+ path?: string;
141
+ /**
142
+ * Additional glob patterns to watch for schema changes in watch mode.
143
+ * These extend the default patterns:
144
+ * - `sanity.config.{js,jsx,ts,tsx,mjs}`
145
+ * - `schema*\/**\/*.{js,jsx,ts,tsx,mjs}`
146
+ */
147
+ watchPatterns?: string[];
148
+ /**
149
+ * The name of the workspace to generate a schema for. Required if your Sanity project has more than one
150
+ * workspace.
151
+ */
152
+ workspace?: string;
153
+ };
154
+ /** Defines the hostname and port that the development server should run on. hostname defaults to localhost, and port to 3333. */
155
+ server?: {
156
+ hostname?: string;
157
+ port?: number;
158
+ };
159
+ /** @deprecated Use deployment.appId */
160
+ studioHost?: string;
161
+ /**
162
+ * Configuration for Sanity typegen
163
+ */
164
+ typegen?: Partial<TypeGenConfig> & {
165
+ /**
166
+ * Enable typegen as part of sanity dev and sanity build.
167
+ * When enabled, types are generated on startup and when files change.
168
+ * Defaults to `false`
169
+ */
170
+ enabled?: boolean;
171
+ };
172
+ /** Exposes the default Vite configuration for custom apps and the Studio so it can be changed and extended. */
173
+ vite?: UserViteConfig;
174
+ }
175
+
176
+ /**
177
+ * @public
178
+ */
179
+ export declare type CLITelemetryStore =
180
+ TelemetryLogger<TelemetryUserProperties>;
181
+
182
+ export declare function colorizeJson(input: unknown): string;
183
+
184
+ /**
185
+ * A raw key-value store for CLI user configuration.
186
+ * Unlike the typed `getCliUserConfig`/`setCliUserConfig`, this operates on
187
+ * arbitrary keys without schema validation.
188
+ *
189
+ * @public
190
+ */
191
+ export declare interface ConfigStore {
192
+ /** Remove a key from the config file. */
193
+ delete: (key: string) => void;
194
+ /** Read a value by key. Returns `undefined` if the key does not exist. */
195
+ get: (key: string) => unknown;
196
+ /** Write a value by key, merging it into the existing config. */
197
+ set: (key: string, value: unknown) => void;
198
+ }
199
+
200
+ export declare type ConsentInformation =
201
+ | {
202
+ reason: "fetchError" | "unauthenticated";
203
+ status: Extract<ConsentStatus, "undetermined">;
204
+ }
205
+ | {
206
+ reason?: "localOverride";
207
+ status: Extract<ConsentStatus, "denied">;
208
+ }
209
+ | {
210
+ reason?: never;
211
+ status: Extract<ConsentStatus, "granted">;
212
+ }
213
+ | {
214
+ reason?: never;
215
+ status: Extract<ConsentStatus, "unset">;
216
+ };
217
+
218
+ /**
219
+ * Creates a new worker for a studio worker task.
220
+ *
221
+ * This uses a combination of vite for "bundling" + jsdom for emulating a browser
222
+ * environment under the hood, which means that the same thing that will work in vite
223
+ * _should_ work in the worker - to a degree. If the user has defined any typescript
224
+ * path aliases, these will have to be added as aliases to the vite config - the same
225
+ * behavior as you would see with regular vite. Other things that are accounted for:
226
+ *
227
+ * - TypeScript support (+JSX, enums and other "compilation needed" features)
228
+ * - CSS, font and other file imports will resolve to a file path
229
+ * - CSS module imports will resolve to a javascript object of class names
230
+ * - Environment variables are available both as `import.meta.env` and `process.env`,
231
+ * and `.env` files are loaded in the same way that they would in a Sanity studio.
232
+ * - Browser globals not available in a Node.js environment but _are_ provided by JSDOM
233
+ * are defined directly to the Node environment as globals. While this polutes the
234
+ * global namespace, it is done only in the worker thread.
235
+ * - Certain browser globals that are _not_ available in JSDOM are also provided to the
236
+ * global namespace - things like `requestIdleCallback`, `IntersectionObserver` etc.
237
+ * These are provided with a minimal stub implementation to make them not crash.
238
+ *
239
+ * @param filePath - Path to the worker file (`.ts` works and is encouraged)
240
+ * @param options - Options to pass to the worker
241
+ * @returns A promise that resolves with the message from the worker
242
+ * @throws If the file does not exist
243
+ * @throws If the worker exits with a non-zero code
244
+ * @internal
245
+ */
246
+ export declare function createStudioWorker(
247
+ filePath: URL,
248
+ options: StudioWorkerTaskOptions,
249
+ ): Worker_2;
250
+
251
+ /**
252
+ * `debug` instance for the CLI
253
+ *
254
+ * @internal
255
+ */
256
+ declare const debug_2: debugIt.Debugger;
257
+ export { debug_2 as debug };
258
+
259
+ /**
260
+ * This function is a replacement for built in dynamic import
261
+ * This handles the case for windows file paths especially for absolute paths.
262
+ *
263
+ * @param source - File path
264
+ */
265
+ export declare function doImport(source: string): Promise<any>;
266
+
267
+ /**
268
+ * Standard exit codes for CLI commands.
269
+ *
270
+ * - 0, 1, 2 align with oclif defaults and Unix convention.
271
+ * - 3 is application-defined (oclif does not use it).
272
+ * - 130 follows the Unix convention of 128 + signal number (SIGINT = 2).
273
+ *
274
+ * @see CLAUDE.md "Exit Code Convention" for usage guidance and examples.
275
+ */
276
+ export declare const exitCodes: {
277
+ /** Something went wrong that is not the user's fault (API errors, network, missing config, etc.). */
278
+ readonly RUNTIME_ERROR: 1;
279
+ /** The user interrupted via Ctrl+C (128 + SIGINT). Handled by SanityCommand.catch(). */
280
+ readonly SIGINT: 130;
281
+ /** Command completed normally. */
282
+ readonly SUCCESS: 0;
283
+ /** The user provided invalid input (bad args, unknown flags, validation failures). */
284
+ readonly USAGE_ERROR: 2;
285
+ /** The user declined a confirmation or chose not to proceed. */
286
+ readonly USER_ABORT: 3;
287
+ };
288
+
289
+ /**
290
+ * Finds the path for a given set of files.
291
+ *
292
+ * @param basePath - The base path to search for files.
293
+ * @param files - The files to search for.
294
+ * @internal
295
+ */
296
+ export declare function findPathForFiles(
297
+ basePath: string,
298
+ files: string[],
299
+ ): Promise<PathResult[]>;
300
+
301
+ /**
302
+ * Resolve project root directory and type.
303
+ *
304
+ * Project root is:
305
+ * - `studio` - A pre-blueprints Sanity studio root (containing `sanity.config.(ts|js)`)
306
+ * - `app` - A Sanity app root (containing `sanity.cli.(ts|js)`)
307
+ *
308
+ * If a Sanity Studio v2/v1 root is found (containing `sanity.json` with `root: true`),
309
+ * an error is thrown, as v2/v1 is no longer supported.
310
+ *
311
+ * @internal
312
+ */
313
+ export declare function findProjectRoot(
314
+ cwd: string,
315
+ ): Promise<ProjectRootResult>;
316
+
317
+ /**
318
+ * Resolve project root directory and type synchronously.
319
+ *
320
+ * Project root is:
321
+ * - `studio` - A pre-blueprints Sanity studio root (containing `sanity.config.(ts|js)`)
322
+ * - `app` - A Sanity app root (containing `sanity.cli.(ts|js)`)
323
+ *
324
+ * If a Sanity Studio v2/v1 root is found (containing `sanity.json` with `root: true`),
325
+ * an error is thrown, as v2/v1 is no longer supported.
326
+ *
327
+ * @param cwd - Current working directory to start searching from
328
+ * @returns Project root result
329
+ * @internal
330
+ */
331
+ export declare function findProjectRootSync(cwd: string): ProjectRootResult;
332
+
333
+ /**
334
+ * Resolves to a string containing the found config path, otherwise throws an error.
335
+ * Also throws if Sanity v2 studio root is found.
336
+ *
337
+ * @param basePath - The base path to start searching from
338
+ * @returns A promise that resolves to a string containing the found config path
339
+ * @throws On multiple config files found, if v2 studio root found, or no config found
340
+ * @internal
341
+ */
342
+ export declare function findStudioConfigPath(basePath: string): Promise<string>;
343
+
344
+ declare type Flags<T extends typeof Command> = Interfaces.InferredFlags<
345
+ (typeof SanityCommand)["baseFlags"] & T["flags"]
346
+ >;
347
+
348
+ /**
349
+ * Get the CLI config for a project, given the root path.
350
+ *
351
+ * Results are cached in-memory keyed by rootPath for the lifetime of the
352
+ * process. Since the CLI always runs from a single project root, the config
353
+ * won't change during a command's execution, so caching avoids redundant
354
+ * filesystem reads and jiti imports from the prerun hook, SanityCommand
355
+ * helpers, and action files.
356
+ *
357
+ * If loading fails the cached promise is evicted so the next call retries.
358
+ *
359
+ * @param rootPath - Root path for the project, eg where `sanity.cli.(ts|js)` is located.
360
+ * @returns The CLI config
361
+ * @internal
362
+ */
363
+ export declare function getCliConfig(rootPath: string): Promise<CliConfig>;
364
+
365
+ /**
366
+ * Get the CLI config for a project synchronously, given the root path.
367
+ *
368
+ * This loads the CLI config in the main thread using tsx/register for TypeScript support.
369
+ * Note: This is a synchronous operation and does not use worker threads like the async version.
370
+ *
371
+ * @param rootPath - Root path for the project, eg where `sanity.cli.(ts|js)` is located.
372
+ * @returns The CLI config
373
+ * @internal
374
+ */
375
+ export declare function getCliConfigSync(rootPath: string): CliConfig;
376
+
377
+ /**
378
+ * @public
379
+ */
380
+ export declare function getCliTelemetry(): CLITelemetryStore;
381
+
382
+ /**
383
+ * Get the CLI authentication token from the environment or the config file
384
+ *
385
+ * @returns A promise that resolves to a CLI token, or undefined if no token is found
386
+ * @internal
387
+ */
388
+ export declare function getCliToken(): Promise<string | undefined>;
389
+
390
+ /**
391
+ * Get the config value for the given property
392
+ *
393
+ * @param prop - The property to get the value for
394
+ * @returns The value of the given property
395
+ * @internal
396
+ */
397
+ export declare function getCliUserConfig(prop: "authToken"): string | undefined;
398
+
399
+ /**
400
+ * Create a "global" (unscoped) Sanity API client.
401
+ *
402
+ * @public
403
+ *
404
+ * @param options - The options to use for the client.
405
+ * @returns Promise that resolves to a configured Sanity API client.
406
+ */
407
+ export declare function getGlobalCliClient({
408
+ requireUser,
409
+ token: providedToken,
410
+ unauthenticated,
411
+ ...config
412
+ }: GlobalCliClientOptions): Promise<SanityClient_2>;
413
+
414
+ /**
415
+ * Create a "project" (scoped) Sanity API client.
416
+ *
417
+ * @public
418
+ *
419
+ * @param options - The options to use for the client.
420
+ * @returns Promise that resolves to a configured Sanity API client.
421
+ */
422
+ export declare function getProjectCliClient({
423
+ requireUser,
424
+ token: providedToken,
425
+ ...config
426
+ }: ProjectCliClientOptions): Promise<SanityClient_2>;
427
+
428
+ /**
429
+ * Gets an environment variable with the appropriate Sanity prefix based on whether it's an app or studio.
430
+ *
431
+ * @param suffix - The suffix for the environment variable (e.g., 'SERVER_HOSTNAME')
432
+ * @param isApp - Whether to use the app prefix (SANITY_APP_) or studio prefix (SANITY_STUDIO_)
433
+ * @returns The value of the environment variable, or undefined if not set
434
+ *
435
+ * @example
436
+ * ```ts
437
+ * // For studio: SANITY_STUDIO_SERVER_HOSTNAME
438
+ * const studioHostname = getSanityEnvVar('SERVER_HOSTNAME', false)
439
+ *
440
+ * // For app: SANITY_APP_SERVER_HOSTNAME
441
+ * const appHostname = getSanityEnvVar('SERVER_HOSTNAME', true)
442
+ * ```
443
+ *
444
+ * @internal
445
+ */
446
+ export declare function getSanityEnvVar(
447
+ suffix: string,
448
+ isApp: boolean,
449
+ ): string | undefined;
450
+
451
+ /**
452
+ * @internal
453
+ * @returns The Sanity URL for the given path, using the correct domain based on the environment
454
+ */
455
+ export declare function getSanityUrl(path?: string): string;
456
+
457
+ /**
458
+ * Get the studio config for a project, given the root path.
459
+ *
460
+ * @param rootPath - The root path for the project
461
+ * @returns The studio config (some properties may be missing)
462
+ * @public
463
+ */
464
+ export declare function getStudioConfig(
465
+ rootPath: string,
466
+ options: {
467
+ resolvePlugins: true;
468
+ },
469
+ ): Promise<ResolvedStudioConfig>;
470
+
471
+ export declare function getStudioConfig(
472
+ rootPath: string,
473
+ options: {
474
+ resolvePlugins: false;
475
+ },
476
+ ): Promise<RawStudioConfig>;
477
+
478
+ /**
479
+ * Resolves the workspaces from the studio config.
480
+ *
481
+ * NOTE: This function should only be called from a worker thread.
482
+ *
483
+ * @param configPath - The path to the studio config
484
+ * @returns The workspaces
485
+ * @internal
486
+ */
487
+ export declare function getStudioWorkspaces(
488
+ configPath: string,
489
+ ): Promise<Workspace[]>;
490
+
491
+ /**
492
+ * Gets the base telemetry information needed for file operations.
493
+ *
494
+ * This shared utility extracts common logic used by:
495
+ * - `generateTelemetryFilePath` - for generating session-specific file paths
496
+ * - `findTelemetryFiles` - for discovering all telemetry files via glob patterns
497
+ *
498
+ * @returns Promise resolving to base telemetry information
499
+ * @throws Error if no auth token is found
500
+ * @internal
501
+ */
502
+ export declare function getTelemetryBaseInfo(): Promise<TelemetryBaseInfo>;
503
+
504
+ /**
505
+ * Starts a terminal timer
506
+ *
507
+ * @internal
508
+ */
509
+ export declare function getTimer(): TimeMeasurer;
510
+
511
+ /**
512
+ * Get a key-value store backed by the CLI user configuration file
513
+ * (`~/.config/sanity/config.json`).
514
+ *
515
+ * Each call to `get`, `set`, or `delete` performs a full synchronous
516
+ * read-modify-write cycle. This is intentional: sync I/O prevents
517
+ * intra-process race conditions that occurred with the previous async
518
+ * (configstore-backed) implementation.
519
+ *
520
+ * Note: there is no file-level locking, so concurrent writes from
521
+ * separate CLI processes could still conflict. In practice this is
522
+ * unlikely since CLI config writes are rare and user-initiated.
523
+ *
524
+ * @returns A {@link ConfigStore} for the CLI config file
525
+ * @public
526
+ */
527
+ export declare function getUserConfig(): ConfigStore;
528
+
529
+ /**
530
+ * @public
531
+ */
532
+ export declare interface GlobalCliClientOptions extends ClientConfig {
533
+ /**
534
+ * The API version to use for this client.
535
+ */
536
+ apiVersion: string;
537
+ /**
538
+ * Whether to require a user to be authenticated to use this client.
539
+ * Default: `false`.
540
+ * Throws an error if `true` and user is not authenticated.
541
+ */
542
+ requireUser?: boolean;
543
+ /**
544
+ * Whether to skip reading the stored CLI token. When `true`, the client will
545
+ * have no token unless one is explicitly provided.
546
+ * Default: `false`.
547
+ */
548
+ unauthenticated?: boolean;
549
+ }
550
+
551
+ /**
552
+ * Imports a module using jiti and returns its exports.
553
+ * This is a thin wrapper around tsx to allow swapping out the underlying implementation in the future if needed.
554
+ *
555
+ * @param filePath - Path to the module to import.
556
+ * @param options - Options for the importModule function.
557
+ * @returns The exported module.
558
+ *
559
+ * @internal
560
+ */
561
+ export declare function importModule<T = unknown>(
562
+ filePath: string | URL,
563
+ options?: ImportModuleOptions,
564
+ ): Promise<T>;
565
+
566
+ declare interface ImportModuleOptions {
567
+ /**
568
+ * Whether to return the default export of the module.
569
+ * Default: true
570
+ */
571
+ default?: boolean;
572
+ /**
573
+ * Path to the tsconfig file to use for the import. If not provided, the tsconfig
574
+ * will be inferred from the nearest `tsconfig.json` file.
575
+ */
576
+ tsconfigPath?: string;
577
+ }
578
+
579
+ export declare const isCi: () => boolean;
580
+
581
+ export declare function isInteractive(): boolean;
582
+
583
+ /**
584
+ * Returns whether or not the given error is a `NotFoundError`
585
+ *
586
+ * @param err - The error to check
587
+ * @returns `true` if the error is a `NotFoundError`, `false` otherwise
588
+ * @internal
589
+ */
590
+ export declare function isNotFoundError(err: unknown): err is NotFoundError;
591
+
592
+ /**
593
+ * Returns whether or not the given error is a `ProjectRootNotFoundError`
594
+ *
595
+ * @param err - The error to check
596
+ * @returns `true` if the error is a `ProjectRootNotFoundError`, `false` otherwise
597
+ * @internal
598
+ */
599
+ export declare function isProjectRootNotFoundError(
600
+ err: unknown,
601
+ ): err is ProjectRootNotFoundError;
602
+
603
+ /**
604
+ * Checks if the environment is staging.
605
+ *
606
+ * @returns True if the environment is staging, false otherwise
607
+ * @internal
608
+ */
609
+ export declare function isStaging(): boolean;
610
+
611
+ /**
612
+ * Checks if the given value conforms to a minimum studio config shape.
613
+ *
614
+ * @param value - The value to check
615
+ * @returns Whether the value is a studio config
616
+ * @internal
617
+ */
618
+ export declare function isStudioConfig(value: unknown): boolean;
619
+
620
+ /**
621
+ * Mocks a browser-like environment for processes in the main thread by:
622
+ * - Injecting browser globals (window, document, ResizeObserver, etc.)
623
+ * - Loading studio environment variables from the project's sanity installation into process.env
624
+ *
625
+ * This is useful for commands like `sanity exec` that have to run user scripts
626
+ * in the main thread of the process (but in a child process).
627
+ *
628
+ * Be cautious when using this, since it will pollute the global namespace with browser globals.
629
+ *
630
+ * If your code can run in a worker thread, you should use the `studioWorkerTask` function instead.
631
+ *
632
+ * @param basePath - The root path of the Sanity Studio project
633
+ * @returns A cleanup function that removes the injected globals and environment variables
634
+ * @internal
635
+ */
636
+ export declare function mockBrowserEnvironment(
637
+ basePath: string,
638
+ ): Promise<() => void>;
639
+
640
+ /**
641
+ * Error thrown when a prompt is attempted in a non-interactive environment
642
+ * (e.g., CI, non-TTY, piped stdin). Callers can catch this specific error
643
+ * to provide appropriate fallback behavior.
644
+ *
645
+ * Extends `CLIError` to suppress stack traces in user-facing output.
646
+ */
647
+ export declare class NonInteractiveError extends CLIError {
648
+ constructor(promptName: string);
649
+ }
650
+
651
+ /**
652
+ * Normalizes a path for cross-platform comparison by converting backslashes to forward slashes.
653
+ * Useful for converting windows paths to unix paths.
654
+ *
655
+ * @param path - Path to normalize
656
+ * @returns Normalized path with forward slashes
657
+ * @public
658
+ */
659
+ export declare function normalizePath(path: string): string;
660
+
661
+ /**
662
+ * Error thrown when a file or directory is not found
663
+ *
664
+ * `code` is always `ENOENT` to mirror Node.js behavior when a file is not found
665
+ *
666
+ * @internal
667
+ */
668
+ export declare class NotFoundError extends Error {
669
+ code: string;
670
+ path?: string;
671
+ constructor(message: string, path?: string);
672
+ }
673
+
674
+ export declare interface Output {
675
+ error: Command["error"];
676
+ log: Command["log"];
677
+ warn: Command["warn"];
678
+ }
679
+
680
+ /**
681
+ * Comprehensive representation of a package.json file.
682
+ * Consolidates all properties from previous type definitions.
683
+ *
684
+ * @public
685
+ */
686
+ export declare type PackageJson = z.infer<typeof packageJsonSchema>;
687
+
688
+ /**
689
+ * Comprehensive package.json schema including all common properties.
690
+ * Feel free to add properties to this,
691
+ * 🟠ℹ️ BUT ENSURE OPTIONAL STUFF IS ACTUALLY OPTIONAL ℹ️🟠
692
+ * 🟠ℹ️ SINCE THIS IS USED IN A NUMBER OF LOCATIONS WHERE ℹ️🟠
693
+ * 🟠ℹ️ WE CANNOT ENFORCE/GUARANTEE ANY PARTICULAR PROPS ℹ️🟠
694
+ */
695
+ declare const packageJsonSchema: z.ZodMiniObject<
696
+ {
697
+ name: z.ZodMiniString<string>;
698
+ version: z.ZodMiniString<string>;
699
+ dependencies: z.ZodMiniOptional<
700
+ z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>
701
+ >;
702
+ devDependencies: z.ZodMiniOptional<
703
+ z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>
704
+ >;
705
+ peerDependencies: z.ZodMiniOptional<
706
+ z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>
707
+ >;
708
+ exports: z.ZodMiniOptional<
709
+ z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniAny>
710
+ >;
711
+ main: z.ZodMiniOptional<z.ZodMiniString<string>>;
712
+ types: z.ZodMiniOptional<z.ZodMiniString<string>>;
713
+ author: z.ZodMiniOptional<z.ZodMiniString<string>>;
714
+ description: z.ZodMiniOptional<z.ZodMiniString<string>>;
715
+ engines: z.ZodMiniOptional<
716
+ z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>
717
+ >;
718
+ license: z.ZodMiniOptional<z.ZodMiniString<string>>;
719
+ private: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
720
+ repository: z.ZodMiniOptional<
721
+ z.ZodMiniObject<
722
+ {
723
+ type: z.ZodMiniString<string>;
724
+ url: z.ZodMiniString<string>;
725
+ },
726
+ z.core.$strip
727
+ >
728
+ >;
729
+ scripts: z.ZodMiniOptional<
730
+ z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>
731
+ >;
732
+ type: z.ZodMiniOptional<
733
+ z.ZodMiniEnum<{
734
+ module: "module";
735
+ commonjs: "commonjs";
736
+ }>
737
+ >;
738
+ },
739
+ z.core.$loose
740
+ >;
741
+
742
+ /**
743
+ * @internal
744
+ */
745
+ declare interface PathResult {
746
+ exists: boolean;
747
+ path: string;
748
+ }
749
+
750
+ /**
751
+ * @public
752
+ */
753
+ export declare interface ProjectCliClientOptions extends ClientConfig {
754
+ /**
755
+ * The API version to use for this client.
756
+ */
757
+ apiVersion: string;
758
+ /**
759
+ * The project ID to use for this client.
760
+ */
761
+ projectId: string;
762
+ /**
763
+ * The dataset to use for this client.
764
+ */
765
+ dataset?: string;
766
+ /**
767
+ * Whether to require a user to be authenticated to use this client.
768
+ * Default: `false`.
769
+ * Throws an error if `true` and user is not authenticated.
770
+ */
771
+ requireUser?: boolean;
772
+ }
773
+
774
+ /**
775
+ * Error thrown when a project root directory cannot be found.
776
+ *
777
+ * This occurs when the CLI is run outside a Sanity project directory
778
+ * (one containing `sanity.config.(ts|js)` or `sanity.cli.(ts|js)`).
779
+ *
780
+ * Extends `CLIError` to suppress stack traces in user-facing output.
781
+ *
782
+ * @internal
783
+ */
784
+ export declare class ProjectRootNotFoundError extends CLIError {
785
+ constructor(
786
+ message: string,
787
+ options?: {
788
+ cause?: Error;
789
+ suggestions?: string[];
790
+ },
791
+ );
792
+ }
793
+
794
+ /**
795
+ * Result of finding a project configuration
796
+ *
797
+ * @public
798
+ */
799
+ export declare interface ProjectRootResult {
800
+ directory: string;
801
+ /**
802
+ * Path to the project configuration file, if found.
803
+ */
804
+ path: string;
805
+ /**
806
+ * Type of project root.
807
+ */
808
+ type: "app" | "studio";
809
+ }
810
+
811
+ /**
812
+ * Creates a Node.js Worker from the given file path and options, and wraps it
813
+ * in a Promise that resolves with the first message the worker sends, and
814
+ * rejects on error, message deserialization failure, or non-zero exit code.
815
+ * The worker is terminated after a message or error is received.
816
+ *
817
+ * @param filePath - URL to the worker file
818
+ * @param options - Options to pass to the Worker constructor
819
+ * @returns A promise that resolves with the first message from the worker
820
+ * @throws If the worker emits an error, a message deserialization error, or exits with a non-zero code
821
+ * @internal
822
+ */
823
+ export declare function promisifyWorker<T = unknown>(
824
+ filePath: URL,
825
+ options?: PromisifyWorkerOptions,
826
+ ): Promise<T>;
827
+
828
+ declare interface PromisifyWorkerOptions extends WorkerOptions_2 {
829
+ /** Optional timeout in milliseconds. If the worker does not respond within this time, it will be terminated and the promise rejected. */
830
+ timeout?: number;
831
+ }
832
+
833
+ declare const rawConfigSchema: z.ZodMiniUnion<
834
+ readonly [
835
+ z.ZodMiniArray<
836
+ z.ZodMiniObject<
837
+ {
838
+ basePath: z.ZodMiniOptional<z.ZodMiniString<string>>;
839
+ name: z.ZodMiniOptional<z.ZodMiniString<string>>;
840
+ plugins: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniUnknown>>;
841
+ schema: z.ZodMiniOptional<
842
+ z.ZodMiniObject<
843
+ {
844
+ name: z.ZodMiniOptional<z.ZodMiniString<string>>;
845
+ types: z.ZodMiniArray<z.ZodMiniObject<{}, z.core.$loose>>;
846
+ },
847
+ z.core.$loose
848
+ >
849
+ >;
850
+ title: z.ZodMiniOptional<z.ZodMiniString<string>>;
851
+ unstable_sources: z.ZodMiniOptional<
852
+ z.ZodMiniArray<
853
+ z.ZodMiniObject<
854
+ {
855
+ dataset: z.ZodMiniString<string>;
856
+ projectId: z.ZodMiniString<string>;
857
+ schema: z.ZodMiniObject<
858
+ {
859
+ _original: z.ZodMiniObject<
860
+ {
861
+ name: z.ZodMiniOptional<z.ZodMiniString<string>>;
862
+ types: z.ZodMiniArray<
863
+ z.ZodMiniObject<{}, z.core.$loose>
864
+ >;
865
+ },
866
+ z.core.$loose
867
+ >;
868
+ },
869
+ z.core.$loose
870
+ >;
871
+ },
872
+ z.core.$loose
873
+ >
874
+ >
875
+ >;
876
+ dataset: z.ZodMiniString<string>;
877
+ projectId: z.ZodMiniString<string>;
878
+ },
879
+ z.core.$loose
880
+ >
881
+ >,
882
+ z.ZodMiniObject<
883
+ {
884
+ basePath: z.ZodMiniOptional<z.ZodMiniString<string>>;
885
+ name: z.ZodMiniOptional<z.ZodMiniString<string>>;
886
+ plugins: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniUnknown>>;
887
+ schema: z.ZodMiniOptional<
888
+ z.ZodMiniObject<
889
+ {
890
+ name: z.ZodMiniOptional<z.ZodMiniString<string>>;
891
+ types: z.ZodMiniArray<z.ZodMiniObject<{}, z.core.$loose>>;
892
+ },
893
+ z.core.$loose
894
+ >
895
+ >;
896
+ title: z.ZodMiniOptional<z.ZodMiniString<string>>;
897
+ unstable_sources: z.ZodMiniOptional<
898
+ z.ZodMiniArray<
899
+ z.ZodMiniObject<
900
+ {
901
+ dataset: z.ZodMiniString<string>;
902
+ projectId: z.ZodMiniString<string>;
903
+ schema: z.ZodMiniObject<
904
+ {
905
+ _original: z.ZodMiniObject<
906
+ {
907
+ name: z.ZodMiniOptional<z.ZodMiniString<string>>;
908
+ types: z.ZodMiniArray<
909
+ z.ZodMiniObject<{}, z.core.$loose>
910
+ >;
911
+ },
912
+ z.core.$loose
913
+ >;
914
+ },
915
+ z.core.$loose
916
+ >;
917
+ },
918
+ z.core.$loose
919
+ >
920
+ >
921
+ >;
922
+ dataset: z.ZodMiniString<string>;
923
+ projectId: z.ZodMiniString<string>;
924
+ },
925
+ z.core.$loose
926
+ >,
927
+ ]
928
+ >;
929
+
930
+ declare type RawStudioConfig = z.infer<typeof rawConfigSchema>;
931
+
932
+ /**
933
+ * Read the `package.json` file at the given path
934
+ *
935
+ * @param filePath - Path to package.json to read
936
+ * @param options - Options object for controlling read behavior
937
+ * @returns The parsed package.json
938
+ * @public
939
+ */
940
+ export declare function readPackageJson(
941
+ filePath: string | URL,
942
+ options?: ReadPackageJsonOptions,
943
+ ): Promise<PackageJson>;
944
+
945
+ /**
946
+ * Options for reading package.json files
947
+ *
948
+ * @public
949
+ */
950
+ export declare interface ReadPackageJsonOptions {
951
+ /**
952
+ * Default values to merge with the parsed package.json.
953
+ * Parsed values take precedence over defaults.
954
+ */
955
+ defaults?: Partial<PackageJson>;
956
+ /**
957
+ * Skip Zod schema validation. When true, the file is parsed but not validated.
958
+ * Defaults to false.
959
+ */
960
+ skipSchemaValidation?: boolean;
961
+ }
962
+
963
+ declare type RequireProps<T, K extends keyof T> = Omit<T, K> &
964
+ Required<Pick<T, K>>;
965
+
966
+ declare const resolvedConfigSchema: z.ZodMiniArray<
967
+ z.ZodMiniObject<
968
+ {
969
+ basePath: z.ZodMiniString<string>;
970
+ name: z.ZodMiniString<string>;
971
+ plugins: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniUnknown>>;
972
+ title: z.ZodMiniString<string>;
973
+ unstable_sources: z.ZodMiniArray<
974
+ z.ZodMiniObject<
975
+ {
976
+ dataset: z.ZodMiniString<string>;
977
+ projectId: z.ZodMiniString<string>;
978
+ schema: z.ZodMiniObject<
979
+ {
980
+ _original: z.ZodMiniObject<
981
+ {
982
+ name: z.ZodMiniOptional<z.ZodMiniString<string>>;
983
+ types: z.ZodMiniArray<z.ZodMiniObject<{}, z.core.$loose>>;
984
+ },
985
+ z.core.$loose
986
+ >;
987
+ },
988
+ z.core.$loose
989
+ >;
990
+ },
991
+ z.core.$loose
992
+ >
993
+ >;
994
+ dataset: z.ZodMiniString<string>;
995
+ projectId: z.ZodMiniString<string>;
996
+ schema: z.ZodMiniObject<
997
+ {
998
+ _original: z.ZodMiniObject<
999
+ {
1000
+ name: z.ZodMiniOptional<z.ZodMiniString<string>>;
1001
+ types: z.ZodMiniArray<z.ZodMiniObject<{}, z.core.$loose>>;
1002
+ },
1003
+ z.core.$loose
1004
+ >;
1005
+ },
1006
+ z.core.$loose
1007
+ >;
1008
+ },
1009
+ z.core.$loose
1010
+ >
1011
+ >;
1012
+
1013
+ declare type ResolvedStudioConfig = z.infer<typeof resolvedConfigSchema>;
1014
+
1015
+ /**
1016
+ * Resolves and imports a package from the local project's node_modules,
1017
+ * relative to the given working directory. This avoids circular dependencies
1018
+ * and ensures the correct version of the package is used.
1019
+ *
1020
+ * @param packageName - The name of the package to resolve (e.g., 'sanity')
1021
+ * @param workDir - The working directory to resolve the package from
1022
+ * @returns The imported module
1023
+ * @throws If the package cannot be resolved or imported
1024
+ *
1025
+ * @example
1026
+ * ```ts
1027
+ * const {createSchema} = await resolveLocalPackage('sanity', workDir)
1028
+ * ```
1029
+ *
1030
+ * @internal
1031
+ */
1032
+ export declare function resolveLocalPackage<T = unknown>(
1033
+ packageName: string,
1034
+ workDir: string,
1035
+ ): Promise<T>;
1036
+
1037
+ /**
1038
+ * Resolves and imports a package relative to another resolved module URL.
1039
+ * Useful for resolving transitive dependencies that may not be directly
1040
+ * accessible from the project root (e.g., in pnpm strict mode).
1041
+ *
1042
+ * @param packageName - The name of the package to resolve
1043
+ * @param parentUrl - The URL of the parent module to resolve from
1044
+ * @returns The imported module
1045
+ * @throws If the package cannot be resolved or imported
1046
+ *
1047
+ * @example
1048
+ * ```ts
1049
+ * const sanityUrl = resolveLocalPackagePath('sanity', workDir)
1050
+ * const ui = await resolveLocalPackageFrom<typeof import('@sanity/ui')>('@sanity/ui', sanityUrl)
1051
+ * ```
1052
+ *
1053
+ * @internal
1054
+ */
1055
+ export declare function resolveLocalPackageFrom<T = unknown>(
1056
+ packageName: string,
1057
+ parentUrl: URL,
1058
+ ): Promise<T>;
1059
+
1060
+ /**
1061
+ * Resolves the URL of a package from the local project's node_modules,
1062
+ * relative to the given working directory, without importing it.
1063
+ *
1064
+ * @param packageName - The name of the package to resolve (e.g., 'sanity')
1065
+ * @param workDir - The working directory to resolve the package from
1066
+ * @returns The resolved URL of the package entry point
1067
+ * @throws If the package cannot be resolved
1068
+ *
1069
+ * @example
1070
+ * ```ts
1071
+ * // Resolve a transitive dependency via its parent package:
1072
+ * const sanityUrl = resolveLocalPackagePath('sanity', workDir)
1073
+ * const uiUrl = resolveLocalPackagePathFrom('@sanity/ui', sanityUrl)
1074
+ * ```
1075
+ *
1076
+ * @internal
1077
+ */
1078
+ export declare function resolveLocalPackagePath(
1079
+ packageName: string,
1080
+ workDir: string,
1081
+ ): URL;
1082
+
1083
+ /**
1084
+ * `structuredClone()`, but doesn't throw on non-clonable values - instead it drops them.
1085
+ *
1086
+ * @param obj - The object to clone.
1087
+ * @returns The cloned object.
1088
+ * @internal
1089
+ */
1090
+ export declare function safeStructuredClone<T>(obj: T): T;
1091
+
1092
+ export declare abstract class SanityCommand<
1093
+ T extends typeof Command,
1094
+ > extends Command {
1095
+ protected args: Args<T>;
1096
+ protected flags: Flags<T>;
1097
+ /**
1098
+ * Get the global API client.
1099
+ *
1100
+ * @param args - The global API client options.
1101
+ * @returns The global API client.
1102
+ *
1103
+ * @deprecated use `getGlobalCliClient` function directly instead.
1104
+ */
1105
+ protected getGlobalApiClient: (
1106
+ args: GlobalCliClientOptions,
1107
+ ) => Promise<SanityClient>;
1108
+ /**
1109
+ * Get the project API client.
1110
+ *
1111
+ * @param args - The project API client options.
1112
+ * @returns The project API client.
1113
+ *
1114
+ * @deprecated use `getProjectCliClient` function directly instead.
1115
+ */
1116
+ protected getProjectApiClient: (
1117
+ args: ProjectCliClientOptions,
1118
+ ) => Promise<SanityClient>;
1119
+ /**
1120
+ * Helper for outputting to the console.
1121
+ *
1122
+ * @example
1123
+ * ```ts
1124
+ * this.output.log('Hello')
1125
+ * this.output.warn('Warning')
1126
+ * this.output.error('Error')
1127
+ * ```
1128
+ */
1129
+ protected output: Output;
1130
+ /**
1131
+ * The telemetry store.
1132
+ *
1133
+ * @returns The telemetry store.
1134
+ */
1135
+ protected telemetry: CLITelemetryStore;
1136
+ /**
1137
+ * Report real command errors to the CLI command trace.
1138
+ * User aborts (SIGINT, ExitPromptError) are not reported — the trace is left
1139
+ * incomplete, which accurately represents that the command was interrupted.
1140
+ */
1141
+ protected catch(err: CommandError): Promise<void>;
1142
+ /**
1143
+ * Get the CLI config.
1144
+ *
1145
+ * @returns The CLI config.
1146
+ */
1147
+ protected getCliConfig(): Promise<CliConfig>;
1148
+ /**
1149
+ * Get the project ID from passed flags or (if not provided) the CLI config.
1150
+ *
1151
+ * Optionally accepts a `fallback` function that is called when no project ID
1152
+ * can be determined from flags or config. This allows commands to provide
1153
+ * interactive project selection while keeping the prompt logic in the CLI package.
1154
+ *
1155
+ * If the fallback throws a `NonInteractiveError` (e.g. because the terminal is
1156
+ * not interactive), it falls through to the standard error with suggestions.
1157
+ *
1158
+ * Optionally accepts a `deprecatedFlagName` for commands that have a deprecated
1159
+ * flag (e.g. `--project`) that should be checked after `--project-id` but before
1160
+ * the CLI config.
1161
+ *
1162
+ * @returns The project ID.
1163
+ */
1164
+ protected getProjectId(options?: {
1165
+ deprecatedFlagName?: string;
1166
+ fallback?: () => Promise<string>;
1167
+ }): Promise<string>;
1168
+ /**
1169
+ * Get the project's root directory by resolving the config
1170
+ *
1171
+ * @returns The project root result.
1172
+ */
1173
+ protected getProjectRoot(): Promise<ProjectRootResult>;
1174
+ init(): Promise<void>;
1175
+ /**
1176
+ * Check if the command is running in unattended mode.
1177
+ *
1178
+ * This means the command should not ask for user input, instead using defaults where
1179
+ * possible, and if that does not make sense (eg there's missing information), then we
1180
+ * should error out (remember to exit with a non-zero code).
1181
+ *
1182
+ * Most commands should take an explicit `--yes` flag to enable unattended mode, but
1183
+ * some commands may also be run in unattended mode if `process.stdin` is not a TTY
1184
+ * (eg when running in a CI environment).
1185
+ */
1186
+ protected isUnattended(): boolean;
1187
+ /**
1188
+ * Resolver for checking if the terminal is interactive. Override in tests to provide mock values.
1189
+ *
1190
+ * @returns Whether the terminal is interactive.
1191
+ */
1192
+ protected resolveIsInteractive(): boolean;
1193
+ /**
1194
+ * Get the CLI config, returning an empty config if no project root is found.
1195
+ *
1196
+ * Use this instead of `getCliConfig()` in commands that can operate without a
1197
+ * project directory (e.g. when `--project-id` and `--dataset` flags are provided).
1198
+ *
1199
+ * @returns The CLI config, or an empty config object if no project root is found.
1200
+ */
1201
+ protected tryGetCliConfig(): Promise<CliConfig>;
1202
+ }
1203
+
1204
+ export declare type SanityOrgUser = {
1205
+ email: string;
1206
+ id: string;
1207
+ name: string;
1208
+ profileImage?: string;
1209
+ provider: "github" | "google" | "sanity" | `saml-${string}`;
1210
+ tosAcceptedAt?: string;
1211
+ };
1212
+
1213
+ /**
1214
+ * Sets the global CLI telemetry state.
1215
+ * @internal
1216
+ */
1217
+ export declare function setCliTelemetry(
1218
+ telemetry: CLITelemetryStore,
1219
+ options?: {
1220
+ reportTraceError?: TraceErrorReporter;
1221
+ },
1222
+ ): void;
1223
+
1224
+ /**
1225
+ * Set the config value for the given property.
1226
+ * Validates that the passed value adheres to the defined CLI config schema.
1227
+ *
1228
+ * @param prop - The property to set the value for
1229
+ * @param value - The value to set
1230
+ * @internal
1231
+ */
1232
+ export declare function setCliUserConfig(
1233
+ prop: "authToken",
1234
+ value: string | undefined,
1235
+ ): void;
1236
+
1237
+ /**
1238
+ * Executes a worker file in a Sanity Studio browser context.
1239
+ *
1240
+ * This uses a combination of vite for "bundling" + jsdom for emulating a browser
1241
+ * environment under the hood, which means that the same thing that will work in vite
1242
+ * _should_ work in the worker - to a degree. If the user has defined any typescript
1243
+ * path aliases, these will have to be added as aliases to the vite config - the same
1244
+ * behavior as you would see with regular vite. Other things that are accounted for:
1245
+ *
1246
+ * - TypeScript support (+JSX, enums and other "compilation needed" features)
1247
+ * - CSS, font and other file imports will resolve to a file path
1248
+ * - CSS module imports will resolve to a javascript object of class names
1249
+ * - Environment variables are available both as `import.meta.env` and `process.env`,
1250
+ * and `.env` files are loaded in the same way that they would in a Sanity studio.
1251
+ * - Browser globals not available in a Node.js environment but _are_ provided by JSDOM
1252
+ * are defined directly to the Node environment as globals. While this polutes the
1253
+ * global namespace, it is done only in the worker thread.
1254
+ * - Certain browser globals that are _not_ available in JSDOM are also provided to the
1255
+ * global namespace - things like `requestIdleCallback`, `IntersectionObserver` etc.
1256
+ * These are provided with a minimal stub implementation to make them not crash.
1257
+ *
1258
+ * @param filePath - Path to the worker file (`.ts` works and is encouraged)
1259
+ * @param options - Options to pass to the worker
1260
+ * @returns A promise that resolves with the message from the worker
1261
+ * @throws If the file does not exist
1262
+ * @throws If the worker exits with a non-zero code
1263
+ * @internal
1264
+ */
1265
+ export declare function studioWorkerTask<T = unknown>(
1266
+ filePath: URL,
1267
+ options: StudioWorkerTaskOptions,
1268
+ ): Promise<T>;
1269
+
1270
+ /**
1271
+ * Options for the studio worker task
1272
+ *
1273
+ * @internal
1274
+ */
1275
+ declare interface StudioWorkerTaskOptions extends RequireProps<
1276
+ WorkerOptions_2,
1277
+ "name"
1278
+ > {
1279
+ studioRootPath: string;
1280
+ /** Optional timeout in milliseconds. If the worker does not respond within this time, it will be terminated and the promise rejected. */
1281
+ timeout?: number;
1282
+ }
1283
+
1284
+ /**
1285
+ * Get a `debug` instance which extends the CLI debug instance with the given namespace,
1286
+ * eg namespace would be `sanity:cli:<providedNamespace>`
1287
+ *
1288
+ * @param namespace - The namespace to extend the CLI debug instance with
1289
+ * @returns The extended `debug` instance
1290
+ */
1291
+ export declare const subdebug: (namespace: string) => debugIt.Debugger;
1292
+
1293
+ /**
1294
+ * Base information needed for telemetry file operations.
1295
+ * Contains common data used by both file path generation and pattern matching.
1296
+ */
1297
+ declare interface TelemetryBaseInfo {
1298
+ /** Base filename pattern without sessionId suffix */
1299
+ basePattern: string;
1300
+ /** Base directory where telemetry files are stored */
1301
+ directory: string;
1302
+ /** Environment: 'staging' or 'production' */
1303
+ environment: string;
1304
+ /** Hashed token (first 8 chars of SHA256) for privacy */
1305
+ hashedToken: string;
1306
+ }
1307
+
1308
+ /**
1309
+ * @public
1310
+ */
1311
+ export declare interface TelemetryUserProperties {
1312
+ cliVersion: string;
1313
+ cpuArchitecture: string;
1314
+ machinePlatform: string;
1315
+ runtime: string;
1316
+ runtimeVersion: string;
1317
+ dataset?: string;
1318
+ projectId?: string;
1319
+ }
1320
+
1321
+ declare interface TimeMeasurer {
1322
+ end: (name: string) => number;
1323
+ getTimings: () => Record<string, number>;
1324
+ start: (name: string) => void;
1325
+ }
1326
+
1327
+ declare type TraceErrorReporter = (error: Error) => void;
1328
+
1329
+ /**
1330
+ * Tries to find the studio config path, returning `undefined` if not found.
1331
+ *
1332
+ * @param basePath - The base path to start searching from
1333
+ * @returns A promise that resolves to a string containing the found config path, or `undefined` if not found
1334
+ * @throws On errors other than config not found
1335
+ * @internal
1336
+ */
1337
+ export declare function tryFindStudioConfigPath(
1338
+ basePath: string,
1339
+ ): Promise<string | undefined>;
1340
+
1341
+ /**
1342
+ * Executes a worker file with tsx registered. This means you can import other
1343
+ * typescript with fairly rich syntax, and still have that only apply to the worker
1344
+ * thread instead of the full parent process. The worker should emit a message when
1345
+ * complete using `parentPort`. Once it has received a single message will resolve the
1346
+ * returned promise with that message. If you are expecting multiple messages, you will
1347
+ * have to implement another method ;)
1348
+ *
1349
+ * @param filePath - Path to the worker file
1350
+ * @param options - Options to pass to the worker
1351
+ * @returns A promise that resolves with the message from the worker
1352
+ * @throws If the file does not exist
1353
+ * @throws If the worker exits with a non-zero code
1354
+ * @internal
1355
+ */
1356
+ export declare function tsxWorkerTask<T = unknown>(
1357
+ filePath: URL_2,
1358
+ options: TsxWorkerTaskOptions,
1359
+ ): Promise<T>;
1360
+
1361
+ /**
1362
+ * Options for the tsx worker task
1363
+ *
1364
+ * @internal
1365
+ */
1366
+ declare interface TsxWorkerTaskOptions extends RequireProps<
1367
+ WorkerOptions_2,
1368
+ "name"
1369
+ > {
1370
+ rootPath: string;
1371
+ }
1372
+
1373
+ declare interface TypeGenConfig {
1374
+ formatGeneratedCode: boolean;
1375
+ generates: string;
1376
+ overloadClientMethods: boolean;
1377
+ path: string | string[];
1378
+ schema: string;
1379
+ }
1380
+
1381
+ /**
1382
+ * @public
1383
+ */
1384
+ export declare type UserViteConfig =
1385
+ | ((
1386
+ config: InlineConfig,
1387
+ env: ConfigEnv,
1388
+ ) => InlineConfig | Promise<InlineConfig>)
1389
+ | InlineConfig;
1390
+
1391
+ export {};