@sanity/cli-core 3.0.0 → 3.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 (64) hide show
  1. package/README.md +7 -6
  2. package/dist/NonInteractiveError-CSLT5y93.d.ts +13 -0
  3. package/dist/ProjectRootNotFoundError-RgthN9uy.d.ts +47 -0
  4. package/dist/SanityCommand.d.ts +26 -355
  5. package/dist/SanityCommand.js +5 -0
  6. package/dist/SanityCommand.js.map +1 -1
  7. package/dist/_exports/browser.d.ts +2 -21
  8. package/dist/_exports/config.d.ts +5 -661
  9. package/dist/_exports/debug.d.ts +4 -8
  10. package/dist/_exports/debug.js +3 -3
  11. package/dist/_exports/debug.js.map +1 -1
  12. package/dist/_exports/errors.d.ts +12 -77
  13. package/dist/_exports/index.d.ts +34 -1674
  14. package/dist/_exports/package-manager.d.ts +14 -207
  15. package/dist/_exports/request.d.ts +52 -69
  16. package/dist/_exports/request.js +5 -4
  17. package/dist/_exports/request.js.map +1 -1
  18. package/dist/_exports/schemas.d.ts +2 -235
  19. package/dist/_exports/tasks.d.ts +2 -120
  20. package/dist/_exports/telemetry.d.ts +2 -156
  21. package/dist/_exports/types.d.ts +9 -475
  22. package/dist/_exports/types.js.map +1 -1
  23. package/dist/_exports/undeploy.d.ts +38 -51
  24. package/dist/_exports/util.d.ts +6 -137
  25. package/dist/_exports/ux.d.ts +31 -102
  26. package/dist/apiClient-DXlF5ZV3.d.ts +65 -0
  27. package/dist/apiClient.d.ts +2 -79
  28. package/dist/apiClient.js +69 -47
  29. package/dist/apiClient.js.map +1 -1
  30. package/dist/cliConfig-DrUV6Wp6.d.ts +197 -0
  31. package/dist/config/cli/schemas.js.map +1 -1
  32. package/dist/config/cli/types/cliConfig.js.map +1 -1
  33. package/dist/errors/NonInteractiveError.js +2 -1
  34. package/dist/errors/NonInteractiveError.js.map +1 -1
  35. package/dist/errors/ProjectRootNotFoundError.js +2 -1
  36. package/dist/errors/ProjectRootNotFoundError.js.map +1 -1
  37. package/dist/errors/enrichAuthError.js +48 -0
  38. package/dist/errors/enrichAuthError.js.map +1 -0
  39. package/dist/errors/getErrorMessage.js +3 -1
  40. package/dist/errors/getErrorMessage.js.map +1 -1
  41. package/dist/executionContext.d.ts +21 -20
  42. package/dist/executionContext.js.map +1 -1
  43. package/dist/exitCodes.d.ts +3 -3
  44. package/dist/findStudioConfigPath-DeBa0pMT.d.ts +265 -0
  45. package/dist/getWorkspace-CU32E6Uo.d.ts +54 -0
  46. package/dist/mockBrowserEnvironment-BjFQPb2W.d.ts +19 -0
  47. package/dist/noopTelemetry-BJRIvASI.d.ts +64 -0
  48. package/dist/readPackageJson-Cr_lbjVR.d.ts +67 -0
  49. package/dist/recursivelyResolveProjectRoot-BE54uEP6.d.ts +18 -0
  50. package/dist/request/createRequester.js +39 -50
  51. package/dist/request/createRequester.js.map +1 -1
  52. package/dist/request/nodeReadableFromWeb.js +64 -0
  53. package/dist/request/nodeReadableFromWeb.js.map +1 -0
  54. package/dist/resolveLocalPackage-Dr-TNTyk.d.ts +78 -0
  55. package/dist/safeStructuredClone-CWB0MXmH.d.ts +58 -0
  56. package/dist/schemas-Y-KwP413.d.ts +100 -0
  57. package/dist/timer-Dwu2TIgB.d.ts +14 -0
  58. package/dist/tsxWorkerTask-CxG3fWbU.d.ts +97 -0
  59. package/dist/types-CwJLTYDj.d.ts +23 -0
  60. package/dist/types-ZNH3prAd.d.ts +91 -0
  61. package/dist/workbenchApp-CSYpReA-.d.ts +22 -0
  62. package/package.json +16 -12
  63. package/dist/request/createIsolatedRequester.js +0 -75
  64. package/dist/request/createIsolatedRequester.js.map +0 -1
@@ -1,1025 +1,26 @@
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 debugIt from "debug";
7
- import { InlineConfig } from "vite";
8
- import { Interfaces } from "@oclif/core";
9
- import { PluginOptions } from "babel-plugin-react-compiler";
10
- import { SanityClient } from "@sanity/client";
11
- import { SanityClient as SanityClient_2 } from "sanity";
12
- import { URL as URL_2 } from "node:url";
13
- import { Worker as Worker_2 } from "node:worker_threads";
1
+ import { i as getProjectCliClient, n as ProjectCliClientOptions, r as getGlobalCliClient, t as GlobalCliClientOptions } from "../apiClient-DXlF5ZV3.js";
2
+ import { i as ConfigStore, n as AppVisibility, r as CliConfig, s as UserViteConfig, t as APP_VISIBILITIES } from "../cliConfig-DrUV6Wp6.js";
3
+ import { t as ProjectRootResult } from "../recursivelyResolveProjectRoot-BE54uEP6.js";
4
+ import { n as ConsentInformation, r as TelemetryUserProperties, t as CLITelemetryStore } from "../types-ZNH3prAd.js";
5
+ import { n as RequireProps, r as SanityOrgUser, t as Output } from "../types-CwJLTYDj.js";
6
+ import { SanityCommand, SanityCommandInterface } from "../SanityCommand.js";
7
+ import { t as mockBrowserEnvironment } from "../mockBrowserEnvironment-BjFQPb2W.js";
8
+ import { a as getStudioWorkspaces, c as findProjectRoot, d as getCliConfigUncached, f as getCliToken, g as clearCliTokenCache, h as setCliUserConfig, i as isStudioConfig, l as getCliConfigSync, m as getUserConfig, n as tryFindStudioConfigPath, o as getStudioConfig, p as getCliUserConfig, r as findPathForFiles, s as findProjectRootSync, t as findStudioConfigPath, u as getCliConfig } from "../findStudioConfigPath-DeBa0pMT.js";
9
+ import { n as isWorkbenchApp, t as ApplicationType } from "../workbenchApp-CSYpReA-.js";
10
+ import { a as getSanityDataDir, i as getSanityConfigDir, n as getSanityUrl, r as getSanityEnvVar, t as getWorkspace } from "../getWorkspace-CU32E6Uo.js";
11
+ import { debug, subdebug } from "./debug.js";
12
+ import { t as NonInteractiveError } from "../NonInteractiveError-CSLT5y93.js";
13
+ import { i as isNotFoundError, n as isProjectRootNotFoundError, r as NotFoundError, t as ProjectRootNotFoundError } from "../ProjectRootNotFoundError-RgthN9uy.js";
14
+ import { exitCodes } from "../exitCodes.js";
15
+ import { n as createStudioWorker, r as studioWorkerTask, t as tsxWorkerTask } from "../tsxWorkerTask-CxG3fWbU.js";
16
+ import { a as getCliTelemetry, i as clearCliTelemetry, n as getTelemetryBaseInfo, o as reportCliTraceError, r as CLI_TELEMETRY_SYMBOL, s as setCliTelemetry, t as noopLogger } from "../noopTelemetry-BJRIvASI.js";
17
+ import { a as isCi, i as isInteractive, n as normalizePath, o as importModule, r as isStaging, s as doImport, t as safeStructuredClone } from "../safeStructuredClone-CWB0MXmH.js";
18
+ import { a as getLocalPackageVersion, i as getLocalPackageDir, n as resolveLocalPackageFrom, r as resolveLocalPackagePath, t as resolveLocalPackage } from "../resolveLocalPackage-Dr-TNTyk.js";
19
+ import { n as ReadPackageJsonOptions, r as readPackageJson, t as PackageJson } from "../readPackageJson-Cr_lbjVR.js";
20
+ import { n as colorizeJson, t as getTimer } from "../timer-Dwu2TIgB.js";
21
+ import { i as studioManifestSchema, n as StudioManifest, r as coreAppManifestSchema, t as CoreAppManifest } from "../schemas-Y-KwP413.js";
14
22
  import { WorkerOptions } from "node:worker_threads";
15
- import { Workspace } from "sanity";
16
- import { z } from "zod/mini";
17
-
18
- /**
19
- * Dashboard visibility an application can declare. Mirrors Brett's canonical
20
- * `VISIBILITIES` — the source of truth lives in the application service.
21
- * @public
22
- */
23
- export declare const APP_VISIBILITIES: readonly [
24
- "default",
25
- "unlisted",
26
- "disabled",
27
- ];
28
-
29
- declare const APPLICATION_TYPES: readonly [
30
- "coreApp",
31
- "studio",
32
- "canvas",
33
- "dashboard",
34
- "media-library",
35
- ];
36
-
37
- /** The resolved kind of a workbench app — `studio` or one of the SDK app types. */
38
- export declare type ApplicationType = (typeof APPLICATION_TYPES)[number];
39
-
40
- /** @public */
41
- export declare type AppVisibility = (typeof APP_VISIBILITIES)[number];
42
-
43
- declare type Args<T extends typeof Command> = Interfaces.InferredArgs<
44
- T["args"]
45
- >;
46
-
47
- /**
48
- * Clears the global CLI telemetry store.
49
- * @internal
50
- */
51
- export declare function clearCliTelemetry(): void;
52
-
53
- /**
54
- * Clear the in-process token cache so the next `getCliToken()` call
55
- * re-reads from disk or the environment.
56
- *
57
- * Called automatically by `setCliUserConfig('authToken', ...)`.
58
- *
59
- * @internal
60
- */
61
- export declare function clearCliTokenCache(): void;
62
-
63
- /**
64
- * @public
65
- * Symbol used to store CLI telemetry state on globalThis.
66
- * Use the accessor functions instead of accessing this directly.
67
- */
68
- export declare const CLI_TELEMETRY_SYMBOL: unique symbol;
69
-
70
- /**
71
- * @public
72
- */
73
- export declare interface CliConfig {
74
- /** The project ID and dataset the Sanity CLI should use to run its commands */
75
- api?: {
76
- dataset?: string;
77
- projectId?: string;
78
- };
79
- /** Configuration for custom Sanity apps built with the App SDK */
80
- app?: {
81
- /** The entrypoint for your custom app. By default, `src/App.tsx` */
82
- entry?: string;
83
- /**
84
- * Path to an icon file relative to project root.
85
- * The file must be an SVG.
86
- */
87
- icon?: string;
88
- /** @deprecated Use deployment.appId */
89
- id?: string;
90
- /** The ID for the Sanity organization that manages this application */
91
- organizationId?: string;
92
- /** The title of the custom app, as it is seen in Dashboard UI */
93
- title?: string;
94
- /** Dashboard visibility of the application. Defaults to `default`. */
95
- visibility?: AppVisibility;
96
- };
97
- /** @deprecated Use deployment.autoUpdates */
98
- autoUpdates?: boolean;
99
- /** Options for custom app and Studio deployments */
100
- deployment?: {
101
- /**
102
- * The ID for your custom app or Studio. Generated when deploying your app or Studio for the first time.
103
- * Get your app ID by either:
104
- * 1. Checking the output of `sanity deploy`, or
105
- * 2. Checking your project’s Studio tab at https://sanity.io/manage
106
- *
107
- * @remarks This is required for all custom app deployments, and for Studios opting in to fine grained version control.
108
- * {@link https://www.sanity.io/docs/studio/latest-version-of-sanity#k0896ed4574b7}
109
- */
110
- appId?: string;
111
- /**
112
- * Enable automatic updates for your Studio or custom app’s Sanity dependencies.
113
- * {@link https://www.sanity.io/docs/studio/latest-version-of-sanity}
114
- */
115
- autoUpdates?: boolean;
116
- };
117
- /** Define the GraphQL APIs that the CLI can deploy and interact with */
118
- graphql?: Array<{
119
- filterSuffix?: string;
120
- generation?: "gen1" | "gen2" | "gen3";
121
- id?: string;
122
- nonNullDocumentFields?: boolean;
123
- playground?: boolean;
124
- source?: string;
125
- tag?: string;
126
- workspace?: string;
127
- }>;
128
- /** Configuration for the Media Library */
129
- mediaLibrary?: {
130
- /** 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. */
131
- aspectsPath?: string;
132
- };
133
- /** 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. */
134
- project?: {
135
- basePath?: string;
136
- };
137
- /** Configuration options for React Compiler */
138
- reactCompiler?: boolean | PluginOptions;
139
- /** 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. */
140
- reactStrictMode?: boolean;
141
- /**
142
- * Configuration for schema extraction (`sanity schema extract`)
143
- */
144
- schemaExtraction?: {
145
- /**
146
- * Enable schema extraction as part of sanity dev and sanity build
147
- */
148
- enabled?: boolean;
149
- /**
150
- * When true, schema fields marked as required will be non-optional in the output.
151
- * Defaults to `false`
152
- */
153
- enforceRequiredFields?: boolean;
154
- /**
155
- * Output path for the extracted schema file.
156
- * Defaults to `schema.json` in the working directory.
157
- */
158
- path?: string;
159
- /**
160
- * Additional glob patterns to watch for schema changes in watch mode.
161
- * These extend the default patterns:
162
- * - `sanity.config.{js,jsx,ts,tsx,mjs}`
163
- * - `schema*\/**\/*.{js,jsx,ts,tsx,mjs}`
164
- */
165
- watchPatterns?: string[];
166
- /**
167
- * The name of the workspace to generate a schema for. Required if your Sanity project has more than one
168
- * workspace.
169
- */
170
- workspace?: string;
171
- };
172
- /** Defines the hostname and port that the development server should run on. hostname defaults to localhost, and port to 3333. */
173
- server?: {
174
- hostname?: string;
175
- port?: number;
176
- };
177
- /** @deprecated Use deployment.appId */
178
- studioHost?: string;
179
- /**
180
- * Configuration for Sanity typegen
181
- */
182
- typegen?: Partial<TypeGenConfig> & {
183
- /**
184
- * Enable typegen as part of sanity dev and sanity build.
185
- * When enabled, types are generated on startup and when files change.
186
- * Defaults to `false`
187
- */
188
- enabled?: boolean;
189
- };
190
- /**
191
- * Enable Vite's experimental bundled dev mode for `sanity dev`. This serves bundled
192
- * files during development, which can speed up startup and reloads for large projects.
193
- * Defaults to `false`.
194
- *
195
- * Unstable: may change or be removed without notice while the underlying Vite
196
- * feature (`experimental.bundledDev`) is experimental.
197
- * {@link https://vite.dev/guide/rolldown#full-bundle-mode}
198
- */
199
- unstable_bundledDev?: boolean;
200
- /** Exposes the default Vite configuration for custom apps and the Studio so it can be changed and extended. */
201
- vite?: UserViteConfig;
202
- }
203
-
204
- /**
205
- * @public
206
- */
207
- export declare type CLITelemetryStore =
208
- TelemetryLogger<TelemetryUserProperties>;
209
-
210
- export declare function colorizeJson(input: unknown): string;
211
-
212
- /**
213
- * A raw key-value store for CLI user configuration.
214
- * Unlike the typed `getCliUserConfig`/`setCliUserConfig`, this operates on
215
- * arbitrary keys without schema validation.
216
- *
217
- * @public
218
- */
219
- export declare interface ConfigStore {
220
- /** Remove a key from the config file. */
221
- delete: (key: string) => void;
222
- /** Read a value by key. Returns `undefined` if the key does not exist. */
223
- get: (key: string) => unknown;
224
- /** Write a value by key, merging it into the existing config. */
225
- set: (key: string, value: unknown) => void;
226
- }
227
-
228
- export declare type ConsentInformation =
229
- | {
230
- reason: "fetchError" | "unauthenticated";
231
- status: Extract<ConsentStatus, "undetermined">;
232
- }
233
- | {
234
- reason?: "localOverride";
235
- status: Extract<ConsentStatus, "denied">;
236
- }
237
- | {
238
- reason?: never;
239
- status: Extract<ConsentStatus, "granted">;
240
- }
241
- | {
242
- reason?: never;
243
- status: Extract<ConsentStatus, "unset">;
244
- };
245
-
246
- /**
247
- * 'unknown' - we don't know if the user has consented or not (e.g. something went wrong)
248
- * 'unset' - the user has not yet been asked for consent
249
- * 'granted' - the user has consented
250
- * 'denied' - the user has denied consent
251
- */
252
- declare type ConsentStatus = "undetermined" | "unset" | "granted" | "denied";
253
-
254
- export declare type CoreAppManifest = z.infer<typeof coreAppManifestSchema>;
255
-
256
- /**
257
- * Core-app application manifest. Mirrors the workbench's
258
- * `CoreAppUserApplicationManifest` schema. Strictly validated via zod since the
259
- * CLI produces the payload in full.
260
- */
261
- export declare const coreAppManifestSchema: z.ZodMiniObject<
262
- {
263
- group: z.ZodMiniOptional<z.ZodMiniString<string>>;
264
- icon: z.ZodMiniOptional<z.ZodMiniString<string>>;
265
- priority: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
266
- slug: z.ZodMiniOptional<z.ZodMiniString<string>>;
267
- title: z.ZodMiniOptional<z.ZodMiniString<string>>;
268
- version: z.ZodMiniString<string>;
269
- },
270
- z.core.$strip
271
- >;
272
-
273
- /**
274
- * Creates a new worker for a studio worker task.
275
- *
276
- * This uses a combination of vite for "bundling" + jsdom for emulating a browser
277
- * environment under the hood, which means that the same thing that will work in vite
278
- * _should_ work in the worker - to a degree. If the user has defined any typescript
279
- * path aliases, these will have to be added as aliases to the vite config - the same
280
- * behavior as you would see with regular vite. Other things that are accounted for:
281
- *
282
- * - TypeScript support (+JSX, enums and other "compilation needed" features)
283
- * - CSS, font and other file imports will resolve to a file path
284
- * - CSS module imports will resolve to a javascript object of class names
285
- * - Environment variables are available both as `import.meta.env` and `process.env`,
286
- * and `.env` files are loaded in the same way that they would in a Sanity studio.
287
- * - Browser globals not available in a Node.js environment but _are_ provided by JSDOM
288
- * are defined directly to the Node environment as globals. While this polutes the
289
- * global namespace, it is done only in the worker thread.
290
- * - Certain browser globals that are _not_ available in JSDOM are also provided to the
291
- * global namespace - things like `requestIdleCallback`, `IntersectionObserver` etc.
292
- * These are provided with a minimal stub implementation to make them not crash.
293
- *
294
- * @param filePath - Path to the worker file (`.ts` works and is encouraged)
295
- * @param options - Options to pass to the worker
296
- * @returns A promise that resolves with the message from the worker
297
- * @throws If the file does not exist
298
- * @throws If the worker exits with a non-zero code
299
- * @internal
300
- */
301
- export declare function createStudioWorker(
302
- filePath: URL,
303
- options: StudioWorkerTaskOptions,
304
- ): Worker_2;
305
-
306
- /**
307
- * `debug` instance for the CLI
308
- *
309
- * @internal
310
- */
311
- declare const debug_2: debugIt.Debugger;
312
- export { debug_2 as debug };
313
-
314
- declare interface DeferredEvent<
315
- Data = unknown,
316
- Event extends DefinedTelemetryLog<Data> = DefinedTelemetryLog<Data>,
317
- > {
318
- createdAt: string;
319
- event: Event;
320
- data: Data;
321
- }
322
-
323
- declare interface DefinedTelemetryLog<Schema> {
324
- type: "log";
325
- /** Unique name of the event */
326
- name: string;
327
- /** Event version. Increment this by 1 whenever the shape of the data changes in a non-backwards compatible way */
328
- version: number;
329
- /** Description of log event */
330
- description?: string;
331
- /**
332
- * Max sample rate of this event.
333
- * Calling telemetry.log(EventDefinition, data) repeatedly will submit at most one event every specified time interval (in milliseconds)
334
- * */
335
- maxSampleRate?: number;
336
- /** Data schema. Will not be accessible at runtime */
337
- schema: Schema;
338
- }
339
-
340
- declare interface DefinedTelemetryTrace<Data = void, Context = void> {
341
- type: "trace";
342
- /** Unique name of the trace */
343
- name: string;
344
- /** Trace version. Increment this by 1 whenever the shape of the data changes in a non-backwards compatible way */
345
- version: number;
346
- /** Description of trace */
347
- description?: string;
348
- /** Data schema. Will not be accessible at runtime */
349
- schema: Data;
350
- /** Contextual data schema. Will not be accessible at runtime */
351
- context: Context;
352
- }
353
-
354
- /**
355
- * This function is a replacement for built in dynamic import
356
- * This handles the case for windows file paths especially for absolute paths.
357
- *
358
- * @param source - File path
359
- */
360
- export declare function doImport(source: string): Promise<any>;
361
-
362
- /**
363
- * Standard exit codes for CLI commands.
364
- *
365
- * - 0, 1, 2 align with oclif defaults and Unix convention.
366
- * - 3 is application-defined (oclif does not use it).
367
- * - 130 follows the Unix convention of 128 + signal number (SIGINT = 2).
368
- *
369
- * @see CLAUDE.md "Exit Code Convention" for usage guidance and examples.
370
- */
371
- export declare const exitCodes: {
372
- /** Something went wrong that is not the user's fault (API errors, network, missing config, etc.). */
373
- readonly RUNTIME_ERROR: 1;
374
- /** The user interrupted via Ctrl+C (128 + SIGINT). Handled by SanityCommand.catch(). */
375
- readonly SIGINT: 130;
376
- /** Command completed normally. */
377
- readonly SUCCESS: 0;
378
- /** The user provided invalid input (bad args, unknown flags, validation failures). */
379
- readonly USAGE_ERROR: 2;
380
- /** The user declined a confirmation or chose not to proceed. */
381
- readonly USER_ABORT: 3;
382
- };
383
-
384
- /**
385
- * Finds the path for a given set of files.
386
- *
387
- * @param basePath - The base path to search for files.
388
- * @param files - The files to search for.
389
- * @internal
390
- */
391
- export declare function findPathForFiles(
392
- basePath: string,
393
- files: string[],
394
- ): Promise<PathResult[]>;
395
-
396
- /**
397
- * Resolve project root directory and type.
398
- *
399
- * Project root is:
400
- * - `studio` - A pre-blueprints Sanity studio root (containing `sanity.config.(ts|js)`)
401
- * - `app` - A Sanity app root (containing `sanity.cli.(ts|js)`)
402
- *
403
- * If a Sanity Studio v2/v1 root is found (containing `sanity.json` with `root: true`),
404
- * an error is thrown, as v2/v1 is no longer supported.
405
- *
406
- * @internal
407
- */
408
- export declare function findProjectRoot(
409
- cwd: string,
410
- ): Promise<ProjectRootResult>;
411
-
412
- /**
413
- * Resolve project root directory and type synchronously.
414
- *
415
- * Project root is:
416
- * - `studio` - A pre-blueprints Sanity studio root (containing `sanity.config.(ts|js)`)
417
- * - `app` - A Sanity app root (containing `sanity.cli.(ts|js)`)
418
- *
419
- * If a Sanity Studio v2/v1 root is found (containing `sanity.json` with `root: true`),
420
- * an error is thrown, as v2/v1 is no longer supported.
421
- *
422
- * @param cwd - Current working directory to start searching from
423
- * @returns Project root result
424
- * @internal
425
- */
426
- export declare function findProjectRootSync(cwd: string): ProjectRootResult;
427
-
428
- /**
429
- * Resolves to a string containing the found config path, otherwise throws an error.
430
- * Also throws if Sanity v2 studio root is found.
431
- *
432
- * @param basePath - The base path to start searching from
433
- * @returns A promise that resolves to a string containing the found config path
434
- * @throws On multiple config files found, if v2 studio root found, or no config found
435
- * @internal
436
- */
437
- export declare function findStudioConfigPath(basePath: string): Promise<string>;
438
-
439
- declare type Flags<T extends typeof Command> = Interfaces.InferredFlags<
440
- (typeof SanityCommand)["baseFlags"] & T["flags"]
441
- >;
442
-
443
- /**
444
- * Get the CLI config for a project, given the root path.
445
- *
446
- * Results are cached in-memory keyed by rootPath for the lifetime of the
447
- * process. Since the CLI always runs from a single project root, the config
448
- * won't change during a command's execution, so caching avoids redundant
449
- * filesystem reads and jiti imports from the prerun hook, SanityCommand
450
- * helpers, and action files.
451
- *
452
- * If loading fails the cached promise is evicted so the next call retries.
453
- *
454
- * Long-lived processes that need to observe edits to `sanity.cli.(ts|js)`
455
- * (e.g. a dev-server watcher) should use {@link getCliConfigUncached}
456
- * instead — it bypasses both this in-memory cache and Node's module cache.
457
- *
458
- * @param rootPath - Root path for the project, eg where `sanity.cli.(ts|js)` is located.
459
- * @returns The CLI config
460
- * @internal
461
- */
462
- export declare function getCliConfig(rootPath: string): Promise<CliConfig>;
463
-
464
- /**
465
- * Get the CLI config for a project synchronously, given the root path.
466
- *
467
- * This loads the CLI config in the main thread using tsx/register for TypeScript support.
468
- * Note: This is a synchronous operation and does not use worker threads like the async version.
469
- *
470
- * @param rootPath - Root path for the project, eg where `sanity.cli.(ts|js)` is located.
471
- * @returns The CLI config
472
- * @internal
473
- */
474
- export declare function getCliConfigSync(rootPath: string): CliConfig;
475
-
476
- /**
477
- * Read the CLI config for a project from disk, bypassing both the
478
- * `getCliConfig` in-memory cache and Node's module cache. Each call locates
479
- * `sanity.cli.(ts|js)`, drops any prior jiti compilation from `require.cache`,
480
- * re-imports, and re-validates.
481
- *
482
- * Use this when the config file is expected to change during the process's
483
- * lifetime — typically a dev-server watcher that needs the new values picked
484
- * up after each save. One-shot CLI invocations should prefer
485
- * {@link getCliConfig} so the prerun hook, SanityCommand helpers, and action
486
- * files share a single load.
487
- *
488
- * @param rootPath - Root path for the project, eg where `sanity.cli.(ts|js)` is located.
489
- * @returns The freshly loaded CLI config
490
- * @internal
491
- */
492
- export declare function getCliConfigUncached(
493
- rootPath: string,
494
- ): Promise<CliConfig>;
495
-
496
- /**
497
- * @public
498
- */
499
- export declare function getCliTelemetry(): CLITelemetryStore;
500
-
501
- /**
502
- * Get the CLI authentication token from the environment or the config file
503
- *
504
- * @returns A promise that resolves to a CLI token, or undefined if no token is found
505
- * @internal
506
- */
507
- export declare function getCliToken(): Promise<string | undefined>;
508
-
509
- /**
510
- * Get the config value for the given property
511
- *
512
- * @param prop - The property to get the value for
513
- * @returns The value of the given property
514
- */
515
- export declare function getCliUserConfig(prop: "authToken"): string | undefined;
516
-
517
- /**
518
- * Create a "global" (unscoped) Sanity API client.
519
- *
520
- * @public
521
- *
522
- * @param options - The options to use for the client.
523
- * @returns Promise that resolves to a configured Sanity API client.
524
- */
525
- export declare function getGlobalCliClient({
526
- requireUser,
527
- token: providedToken,
528
- unauthenticated,
529
- ...config
530
- }: GlobalCliClientOptions): Promise<SanityClient>;
531
-
532
- /**
533
- * Resolve the filesystem directory of a locally installed package using Node
534
- * module resolution. Works correctly with hoisted packages in monorepos/workspaces,
535
- * pnpm symlinks, and other non-standard node_modules layouts.
536
- *
537
- * @param moduleName - The name of the package in npm.
538
- * @param workDir - The working directory to resolve the module from. (aka project root)
539
- * @returns The absolute path to the package directory.
540
- * @internal
541
- */
542
- export declare function getLocalPackageDir(
543
- moduleName: string,
544
- workDir: string,
545
- ): string;
546
-
547
- /**
548
- * Get the version of a package installed locally.
549
- *
550
- * @param moduleName - The name of the package in npm.
551
- * @param workDir - The working directory to resolve the module from. (aka project root)
552
- * @returns The version of the package installed locally.
553
- * @internal
554
- */
555
- export declare function getLocalPackageVersion(
556
- moduleName: string,
557
- workDir: string,
558
- ): Promise<string | null>;
559
-
560
- /**
561
- * Create a "project" (scoped) Sanity API client.
562
- *
563
- * @public
564
- *
565
- * @param options - The options to use for the client.
566
- * @returns Promise that resolves to a configured Sanity API client.
567
- */
568
- export declare function getProjectCliClient({
569
- requireUser,
570
- token: providedToken,
571
- ...config
572
- }: ProjectCliClientOptions): Promise<SanityClient>;
573
-
574
- /**
575
- * Returns the base Sanity configuration directory for the current user.
576
- * For persistent user settings (auth tokens, preferences, etc.).
577
- * Respects `SANITY_INTERNAL_ENV=staging` to isolate staging instances.
578
- *
579
- * Layout: `~/.config/sanity{-staging}/`
580
- *
581
- * @returns Absolute path to the config directory
582
- * @internal
583
- */
584
- export declare function getSanityConfigDir(): string;
585
-
586
- /**
587
- * Returns the base Sanity data directory for the current user.
588
- * For ephemeral runtime state (dev-server registries, caches, etc.).
589
- * Respects `SANITY_INTERNAL_ENV=staging` to isolate staging instances.
590
- *
591
- * Layout: `~/.sanity{-staging}/`
592
- *
593
- * @returns Absolute path to the data directory
594
- * @internal
595
- */
596
- export declare function getSanityDataDir(): string;
597
-
598
- /**
599
- * Gets an environment variable with the appropriate Sanity prefix based on whether it's an app or studio.
600
- *
601
- * @param suffix - The suffix for the environment variable (e.g., 'SERVER_HOSTNAME')
602
- * @param isApp - Whether to use the app prefix (SANITY_APP_) or studio prefix (SANITY_STUDIO_)
603
- * @returns The value of the environment variable, or undefined if not set
604
- *
605
- * @example
606
- * ```ts
607
- * // For studio: SANITY_STUDIO_SERVER_HOSTNAME
608
- * const studioHostname = getSanityEnvVar('SERVER_HOSTNAME', false)
609
- *
610
- * // For app: SANITY_APP_SERVER_HOSTNAME
611
- * const appHostname = getSanityEnvVar('SERVER_HOSTNAME', true)
612
- * ```
613
- *
614
- * @internal
615
- */
616
- export declare function getSanityEnvVar(
617
- suffix: string,
618
- isApp: boolean,
619
- ): string | undefined;
620
-
621
- /**
622
- * @internal
623
- * @returns The Sanity URL for the given path, using the correct domain based on the environment
624
- */
625
- export declare function getSanityUrl(path?: string): string;
626
-
627
- /**
628
- * Get the studio config for a project, given the root path.
629
- *
630
- * @param rootPath - The root path for the project
631
- * @returns The studio config (some properties may be missing)
632
- * @public
633
- */
634
- export declare function getStudioConfig(
635
- rootPath: string,
636
- options: {
637
- resolvePlugins: true;
638
- },
639
- ): Promise<ResolvedStudioConfig>;
640
-
641
- export declare function getStudioConfig(
642
- rootPath: string,
643
- options: {
644
- resolvePlugins: false;
645
- },
646
- ): Promise<RawStudioConfig>;
647
-
648
- /**
649
- * Resolves the workspaces from the studio config.
650
- *
651
- * NOTE: This function should only be called from a worker thread.
652
- *
653
- * @param configPath - The path to the studio config
654
- * @returns The workspaces
655
- * @internal
656
- */
657
- export declare function getStudioWorkspaces(
658
- configPath: string,
659
- ): Promise<Workspace[]>;
660
-
661
- /**
662
- * Gets the base telemetry information needed for file operations.
663
- *
664
- * This shared utility extracts common logic used by:
665
- * - `generateTelemetryFilePath` - for generating session-specific file paths
666
- * - `findTelemetryFiles` - for discovering all telemetry files via glob patterns
667
- *
668
- * @returns Promise resolving to base telemetry information
669
- * @throws Error if no auth token is found
670
- * @internal
671
- */
672
- export declare function getTelemetryBaseInfo(): Promise<TelemetryBaseInfo>;
673
-
674
- /**
675
- * Starts a terminal timer
676
- *
677
- * @internal
678
- */
679
- export declare function getTimer(): TimeMeasurer;
680
-
681
- /**
682
- * Get a key-value store backed by the CLI user configuration file
683
- * (`~/.config/sanity/config.json`).
684
- *
685
- * Each call to `get`, `set`, or `delete` performs a full synchronous
686
- * read-modify-write cycle. This is intentional: sync I/O prevents
687
- * intra-process race conditions that occurred with the previous async
688
- * (configstore-backed) implementation.
689
- *
690
- * Note: there is no file-level locking, so concurrent writes from
691
- * separate CLI processes could still conflict. In practice this is
692
- * unlikely since CLI config writes are rare and user-initiated.
693
- *
694
- * @returns A {@link ConfigStore} for the CLI config file
695
- * @public
696
- */
697
- export declare function getUserConfig(): ConfigStore;
698
-
699
- /**
700
- * @internal
701
- */
702
- export declare function getWorkspace<
703
- T extends {
704
- name: string;
705
- },
706
- >(workspaces: T[], workspaceName?: string): T;
707
-
708
- /**
709
- * @public
710
- */
711
- export declare interface GlobalCliClientOptions extends ClientConfig {
712
- /**
713
- * The API version to use for this client.
714
- */
715
- apiVersion: string;
716
- /**
717
- * Whether to require a user to be authenticated to use this client.
718
- * Default: `false`.
719
- * Throws an error if `true` and user is not authenticated.
720
- */
721
- requireUser?: boolean;
722
- /**
723
- * Whether to skip reading the stored CLI token. When `true`, the client will
724
- * have no token unless one is explicitly provided.
725
- * Default: `false`.
726
- */
727
- unauthenticated?: boolean;
728
- }
729
-
730
- /**
731
- * Imports a module using jiti and returns its exports.
732
- * This is a thin wrapper around tsx to allow swapping out the underlying implementation in the future if needed.
733
- *
734
- * @param filePath - Path to the module to import.
735
- * @param options - Options for the importModule function.
736
- * @returns The exported module.
737
- *
738
- * @internal
739
- */
740
- export declare function importModule<T = unknown>(
741
- filePath: string | URL,
742
- options?: ImportModuleOptions,
743
- ): Promise<T>;
744
-
745
- declare interface ImportModuleOptions {
746
- /**
747
- * Whether to return the default export of the module.
748
- * Default: true
749
- */
750
- default?: boolean;
751
- /**
752
- * Path to the tsconfig file to use for the import. If not provided, the tsconfig
753
- * will be inferred from the nearest `tsconfig.json` file.
754
- */
755
- tsconfigPath?: string;
756
- }
757
-
758
- export declare const isCi: () => boolean;
759
-
760
- export declare function isInteractive(): boolean;
761
-
762
- /**
763
- * Returns whether or not the given error is a `NotFoundError`
764
- *
765
- * @param err - The error to check
766
- * @returns `true` if the error is a `NotFoundError`, `false` otherwise
767
- * @internal
768
- */
769
- export declare function isNotFoundError(err: unknown): err is NotFoundError;
770
-
771
- /**
772
- * Returns whether or not the given error is a `ProjectRootNotFoundError`
773
- *
774
- * @param err - The error to check
775
- * @returns `true` if the error is a `ProjectRootNotFoundError`, `false` otherwise
776
- * @internal
777
- */
778
- export declare function isProjectRootNotFoundError(
779
- err: unknown,
780
- ): err is ProjectRootNotFoundError;
781
-
782
- /**
783
- * Checks if the environment is staging.
784
- *
785
- * @returns True if the environment is staging, false otherwise
786
- * @internal
787
- */
788
- export declare function isStaging(): boolean;
789
-
790
- /**
791
- * Checks if the given value conforms to a minimum studio config shape.
792
- *
793
- * @param value - The value to check
794
- * @returns Whether the value is a studio config
795
- * @internal
796
- */
797
- export declare function isStudioConfig(value: unknown): boolean;
798
-
799
- /**
800
- * Boolean brand check — used for config-load routing, kept exported for
801
- * backward compatibility. For the typed narrowing (the app's declared fields),
802
- * use `isWorkbenchApp` from `@sanity/workbench-cli`, derived from the schema.
803
- */
804
- export declare function isWorkbenchApp(app: CliConfig["app"]): boolean;
805
-
806
- /**
807
- * Mocks a browser-like environment for processes in the main thread by:
808
- * - Injecting browser globals (window, document, ResizeObserver, etc.)
809
- * - Loading studio environment variables from the project's sanity installation into process.env
810
- *
811
- * This is useful for commands like `sanity exec` that have to run user scripts
812
- * in the main thread of the process (but in a child process).
813
- *
814
- * Be cautious when using this, since it will pollute the global namespace with browser globals.
815
- *
816
- * If your code can run in a worker thread, you should use the `studioWorkerTask` function instead.
817
- *
818
- * @param basePath - The root path of the Sanity Studio project
819
- * @returns A cleanup function that removes the injected globals and environment variables
820
- * @internal
821
- */
822
- export declare function mockBrowserEnvironment(
823
- basePath: string,
824
- ): Promise<() => void>;
825
-
826
- /**
827
- * Error thrown when a prompt is attempted in a non-interactive environment
828
- * (e.g., CI, non-TTY, piped stdin). Callers can catch this specific error
829
- * to provide appropriate fallback behavior.
830
- *
831
- * Extends `CLIError` to suppress stack traces in user-facing output.
832
- */
833
- export declare class NonInteractiveError extends CLIError {
834
- constructor(promptName: string);
835
- }
836
-
837
- /**
838
- * Fallback logger used when telemetry has not been initialized.
839
- * Exported for use in tests only — do not use in plugins or external code.
840
- * @internal
841
- */
842
- export declare const noopLogger: CLITelemetryStore;
843
-
844
- /**
845
- * Normalizes a path for cross-platform comparison by converting backslashes to forward slashes.
846
- * Useful for converting windows paths to unix paths.
847
- *
848
- * @param path - Path to normalize
849
- * @returns Normalized path with forward slashes
850
- * @public
851
- */
852
- export declare function normalizePath(path: string): string;
853
-
854
- /**
855
- * Error thrown when a file or directory is not found
856
- *
857
- * `code` is always `ENOENT` to mirror Node.js behavior when a file is not found
858
- *
859
- * @internal
860
- */
861
- export declare class NotFoundError extends Error {
862
- code: string;
863
- path?: string;
864
- constructor(message: string, path?: string);
865
- }
866
-
867
- export declare interface Output {
868
- error: Command["error"];
869
- log: Command["log"];
870
- warn: Command["warn"];
871
- }
872
-
873
- /**
874
- * Comprehensive representation of a package.json file.
875
- * Consolidates all properties from previous type definitions.
876
- *
877
- * @public
878
- */
879
- export declare type PackageJson = z.infer<typeof packageJsonSchema>;
880
-
881
- /**
882
- * Comprehensive package.json schema including all common properties.
883
- * Feel free to add properties to this,
884
- * 🟠ℹ️ BUT ENSURE OPTIONAL STUFF IS ACTUALLY OPTIONAL ℹ️🟠
885
- * 🟠ℹ️ SINCE THIS IS USED IN A NUMBER OF LOCATIONS WHERE ℹ️🟠
886
- * 🟠ℹ️ WE CANNOT ENFORCE/GUARANTEE ANY PARTICULAR PROPS ℹ️🟠
887
- */
888
- declare const packageJsonSchema: z.ZodMiniObject<
889
- {
890
- name: z.ZodMiniString<string>;
891
- version: z.ZodMiniString<string>;
892
- dependencies: z.ZodMiniOptional<
893
- z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>
894
- >;
895
- devDependencies: z.ZodMiniOptional<
896
- z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>
897
- >;
898
- peerDependencies: z.ZodMiniOptional<
899
- z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>
900
- >;
901
- exports: z.ZodMiniOptional<
902
- z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniAny>
903
- >;
904
- main: z.ZodMiniOptional<z.ZodMiniString<string>>;
905
- types: z.ZodMiniOptional<z.ZodMiniString<string>>;
906
- author: z.ZodMiniOptional<z.ZodMiniString<string>>;
907
- description: z.ZodMiniOptional<z.ZodMiniString<string>>;
908
- engines: z.ZodMiniOptional<
909
- z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>
910
- >;
911
- license: z.ZodMiniOptional<z.ZodMiniString<string>>;
912
- private: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
913
- repository: z.ZodMiniOptional<
914
- z.ZodMiniObject<
915
- {
916
- type: z.ZodMiniString<string>;
917
- url: z.ZodMiniString<string>;
918
- },
919
- z.core.$strip
920
- >
921
- >;
922
- scripts: z.ZodMiniOptional<
923
- z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>
924
- >;
925
- type: z.ZodMiniOptional<
926
- z.ZodMiniEnum<{
927
- module: "module";
928
- commonjs: "commonjs";
929
- }>
930
- >;
931
- },
932
- z.core.$loose
933
- >;
934
-
935
- /**
936
- * @internal
937
- */
938
- declare interface PathResult {
939
- exists: boolean;
940
- path: string;
941
- }
942
-
943
- /**
944
- * @public
945
- */
946
- export declare interface ProjectCliClientOptions extends ClientConfig {
947
- /**
948
- * The API version to use for this client.
949
- */
950
- apiVersion: string;
951
- /**
952
- * The project ID to use for this client.
953
- */
954
- projectId: string;
955
- /**
956
- * The dataset to use for this client.
957
- */
958
- dataset?: string;
959
- /**
960
- * Whether to require a user to be authenticated to use this client.
961
- * Default: `false`.
962
- * Throws an error if `true` and user is not authenticated.
963
- */
964
- requireUser?: boolean;
965
- }
966
-
967
- /**
968
- * Error thrown when a project root directory cannot be found.
969
- *
970
- * This occurs when the CLI is run outside a Sanity project directory
971
- * (one containing `sanity.config.(ts|js)` or `sanity.cli.(ts|js)`).
972
- *
973
- * Extends `CLIError` to suppress stack traces in user-facing output.
974
- *
975
- * @internal
976
- */
977
- export declare class ProjectRootNotFoundError extends CLIError {
978
- constructor(
979
- message: string,
980
- options?: {
981
- cause?: Error;
982
- suggestions?: string[];
983
- },
984
- );
985
- }
986
-
987
- /**
988
- * Result of finding a project configuration
989
- *
990
- * @public
991
- */
992
- export declare interface ProjectRootResult {
993
- directory: string;
994
- /**
995
- * Path to the project configuration file, if found.
996
- */
997
- path: string;
998
- /**
999
- * Type of project root.
1000
- */
1001
- type: "app" | "studio";
1002
- }
1003
-
1004
- /**
1005
- * Creates a Node.js Worker from the given file path and options, and wraps it
1006
- * in a Promise that resolves with the first message the worker sends, and
1007
- * rejects on error, message deserialization failure, or non-zero exit code.
1008
- * By default, the worker is terminated after a message or error is received.
1009
- * Callers can instead unref it and allow natural process teardown.
1010
- *
1011
- * @param filePath - URL to the worker file
1012
- * @param options - Options to pass to the Worker constructor
1013
- * @returns A promise that resolves with the first message from the worker
1014
- * @throws If the worker emits an error, a message deserialization error, or exits with a non-zero code
1015
- * @internal
1016
- */
1017
- export declare function promisifyWorker<T = unknown>(
1018
- filePath: URL,
1019
- options?: PromisifyWorkerOptions,
1020
- ): Promise<T>;
1021
-
1022
- declare interface PromisifyWorkerOptions extends WorkerOptions {
23
+ interface PromisifyWorkerOptions extends WorkerOptions {
1023
24
  /**
1024
25
  * Whether to forcibly terminate the worker after settling. Disable this for
1025
26
  * workers that host native addons (e.g. rolldown via Vite 8) whose threads
@@ -1032,660 +33,19 @@ declare interface PromisifyWorkerOptions extends WorkerOptions {
1032
33
  /** Optional timeout in milliseconds. If the worker does not respond within this time, the promise is rejected. */
1033
34
  timeout?: number;
1034
35
  }
1035
-
1036
- declare const rawConfigSchema: z.ZodMiniUnion<
1037
- readonly [
1038
- z.ZodMiniArray<
1039
- z.ZodMiniObject<
1040
- {
1041
- basePath: z.ZodMiniOptional<z.ZodMiniString<string>>;
1042
- name: z.ZodMiniOptional<z.ZodMiniString<string>>;
1043
- plugins: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniUnknown>>;
1044
- schema: z.ZodMiniOptional<
1045
- z.ZodMiniObject<
1046
- {
1047
- name: z.ZodMiniOptional<z.ZodMiniString<string>>;
1048
- types: z.ZodMiniArray<z.ZodMiniObject<{}, z.core.$loose>>;
1049
- },
1050
- z.core.$loose
1051
- >
1052
- >;
1053
- title: z.ZodMiniOptional<z.ZodMiniString<string>>;
1054
- unstable_sources: z.ZodMiniOptional<
1055
- z.ZodMiniArray<
1056
- z.ZodMiniObject<
1057
- {
1058
- dataset: z.ZodMiniString<string>;
1059
- projectId: z.ZodMiniString<string>;
1060
- schema: z.ZodMiniObject<
1061
- {
1062
- _original: z.ZodMiniObject<
1063
- {
1064
- name: z.ZodMiniOptional<z.ZodMiniString<string>>;
1065
- types: z.ZodMiniArray<
1066
- z.ZodMiniObject<{}, z.core.$loose>
1067
- >;
1068
- },
1069
- z.core.$loose
1070
- >;
1071
- },
1072
- z.core.$loose
1073
- >;
1074
- },
1075
- z.core.$loose
1076
- >
1077
- >
1078
- >;
1079
- dataset: z.ZodMiniString<string>;
1080
- projectId: z.ZodMiniString<string>;
1081
- },
1082
- z.core.$loose
1083
- >
1084
- >,
1085
- z.ZodMiniObject<
1086
- {
1087
- basePath: z.ZodMiniOptional<z.ZodMiniString<string>>;
1088
- name: z.ZodMiniOptional<z.ZodMiniString<string>>;
1089
- plugins: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniUnknown>>;
1090
- schema: z.ZodMiniOptional<
1091
- z.ZodMiniObject<
1092
- {
1093
- name: z.ZodMiniOptional<z.ZodMiniString<string>>;
1094
- types: z.ZodMiniArray<z.ZodMiniObject<{}, z.core.$loose>>;
1095
- },
1096
- z.core.$loose
1097
- >
1098
- >;
1099
- title: z.ZodMiniOptional<z.ZodMiniString<string>>;
1100
- unstable_sources: z.ZodMiniOptional<
1101
- z.ZodMiniArray<
1102
- z.ZodMiniObject<
1103
- {
1104
- dataset: z.ZodMiniString<string>;
1105
- projectId: z.ZodMiniString<string>;
1106
- schema: z.ZodMiniObject<
1107
- {
1108
- _original: z.ZodMiniObject<
1109
- {
1110
- name: z.ZodMiniOptional<z.ZodMiniString<string>>;
1111
- types: z.ZodMiniArray<
1112
- z.ZodMiniObject<{}, z.core.$loose>
1113
- >;
1114
- },
1115
- z.core.$loose
1116
- >;
1117
- },
1118
- z.core.$loose
1119
- >;
1120
- },
1121
- z.core.$loose
1122
- >
1123
- >
1124
- >;
1125
- dataset: z.ZodMiniString<string>;
1126
- projectId: z.ZodMiniString<string>;
1127
- },
1128
- z.core.$loose
1129
- >,
1130
- ]
1131
- >;
1132
-
1133
- declare type RawStudioConfig = z.infer<typeof rawConfigSchema>;
1134
-
1135
- /**
1136
- * Read the `package.json` file at the given path
1137
- *
1138
- * @param filePath - Path to package.json to read
1139
- * @param options - Options object for controlling read behavior
1140
- * @returns The parsed package.json
1141
- * @public
1142
- */
1143
- export declare function readPackageJson(
1144
- filePath: string | URL,
1145
- options?: ReadPackageJsonOptions,
1146
- ): Promise<PackageJson>;
1147
-
1148
- /**
1149
- * Options for reading package.json files
1150
- *
1151
- * @public
1152
- */
1153
- export declare interface ReadPackageJsonOptions {
1154
- /**
1155
- * Default values to merge with the parsed package.json.
1156
- * Parsed values take precedence over defaults.
1157
- */
1158
- defaults?: Partial<PackageJson>;
1159
- /**
1160
- * Skip Zod schema validation. When true, the file is parsed but not validated.
1161
- * Defaults to false.
1162
- */
1163
- skipSchemaValidation?: boolean;
1164
- }
1165
-
1166
- /**
1167
- * Reports an error to the CLI command trace. Called from SanityCommand.catch()
1168
- * for real command errors (not user aborts).
1169
- * @internal
1170
- */
1171
- export declare function reportCliTraceError(error: Error): void;
1172
-
1173
- export declare type RequireProps<T, K extends keyof T> = Omit<T, K> &
1174
- Required<Pick<T, K>>;
1175
-
1176
- declare const resolvedConfigSchema: z.ZodMiniArray<
1177
- z.ZodMiniObject<
1178
- {
1179
- basePath: z.ZodMiniString<string>;
1180
- name: z.ZodMiniString<string>;
1181
- plugins: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniUnknown>>;
1182
- title: z.ZodMiniString<string>;
1183
- unstable_sources: z.ZodMiniArray<
1184
- z.ZodMiniObject<
1185
- {
1186
- dataset: z.ZodMiniString<string>;
1187
- projectId: z.ZodMiniString<string>;
1188
- schema: z.ZodMiniObject<
1189
- {
1190
- _original: z.ZodMiniObject<
1191
- {
1192
- name: z.ZodMiniOptional<z.ZodMiniString<string>>;
1193
- types: z.ZodMiniArray<z.ZodMiniObject<{}, z.core.$loose>>;
1194
- },
1195
- z.core.$loose
1196
- >;
1197
- },
1198
- z.core.$loose
1199
- >;
1200
- },
1201
- z.core.$loose
1202
- >
1203
- >;
1204
- dataset: z.ZodMiniString<string>;
1205
- projectId: z.ZodMiniString<string>;
1206
- schema: z.ZodMiniObject<
1207
- {
1208
- _original: z.ZodMiniObject<
1209
- {
1210
- name: z.ZodMiniOptional<z.ZodMiniString<string>>;
1211
- types: z.ZodMiniArray<z.ZodMiniObject<{}, z.core.$loose>>;
1212
- },
1213
- z.core.$loose
1214
- >;
1215
- },
1216
- z.core.$loose
1217
- >;
1218
- },
1219
- z.core.$loose
1220
- >
1221
- >;
1222
-
1223
- declare type ResolvedStudioConfig = z.infer<typeof resolvedConfigSchema>;
1224
-
1225
- /**
1226
- * Resolves and imports a package from the local project's node_modules,
1227
- * relative to the given working directory. This avoids circular dependencies
1228
- * and ensures the correct version of the package is used.
1229
- *
1230
- * @param packageName - The name of the package to resolve (e.g., 'sanity')
1231
- * @param workDir - The working directory to resolve the package from
1232
- * @returns The imported module
1233
- * @throws If the package cannot be resolved or imported
1234
- *
1235
- * @example
1236
- * ```ts
1237
- * const {createSchema} = await resolveLocalPackage('sanity', workDir)
1238
- * ```
1239
- *
1240
- * @internal
1241
- */
1242
- export declare function resolveLocalPackage<T = unknown>(
1243
- packageName: string,
1244
- workDir: string,
1245
- ): Promise<T>;
1246
-
1247
- /**
1248
- * Resolves and imports a package relative to another resolved module URL.
1249
- * Useful for resolving transitive dependencies that may not be directly
1250
- * accessible from the project root (e.g., in pnpm strict mode).
1251
- *
1252
- * @param packageName - The name of the package to resolve
1253
- * @param parentUrl - The URL of the parent module to resolve from
1254
- * @returns The imported module
1255
- * @throws If the package cannot be resolved or imported
1256
- *
1257
- * @example
1258
- * ```ts
1259
- * const sanityUrl = resolveLocalPackagePath('sanity', workDir)
1260
- * const ui = await resolveLocalPackageFrom<typeof import('@sanity/ui')>('@sanity/ui', sanityUrl)
1261
- * ```
1262
- *
1263
- * @internal
1264
- */
1265
- export declare function resolveLocalPackageFrom<T = unknown>(
1266
- packageName: string,
1267
- parentUrl: URL,
1268
- ): Promise<T>;
1269
-
1270
- /**
1271
- * Resolves the URL of a package from the local project's node_modules,
1272
- * relative to the given working directory, without importing it.
1273
- *
1274
- * @param packageName - The name of the package to resolve (e.g., 'sanity')
1275
- * @param workDir - The working directory to resolve the package from
1276
- * @returns The resolved URL of the package entry point
1277
- * @throws If the package cannot be resolved
1278
- *
1279
- * @example
1280
- * ```ts
1281
- * // Resolve a transitive dependency via its parent package:
1282
- * const sanityUrl = resolveLocalPackagePath('sanity', workDir)
1283
- * const uiUrl = resolveLocalPackagePathFrom('@sanity/ui', sanityUrl)
1284
- * ```
1285
- *
1286
- * @internal
1287
- */
1288
- export declare function resolveLocalPackagePath(
1289
- packageName: string,
1290
- workDir: string,
1291
- ): URL;
1292
-
1293
36
  /**
1294
- * `structuredClone()`, but doesn't throw on non-clonable values - instead it drops them.
1295
- *
1296
- * @param obj - The object to clone.
1297
- * @returns The cloned object.
1298
- * @internal
1299
- */
1300
- export declare function safeStructuredClone<T>(obj: T): T;
1301
-
1302
- export declare abstract class SanityCommand<T extends typeof Command>
1303
- extends Command
1304
- implements SanityCommandInterface
1305
- {
1306
- protected args: Args<T>;
1307
- protected flags: Flags<T>;
1308
- /**
1309
- * Get the global API client.
1310
- *
1311
- * @param args - The global API client options.
1312
- * @returns The global API client.
1313
- *
1314
- * @deprecated use `getGlobalCliClient` function directly instead.
1315
- */
1316
- protected getGlobalApiClient: (
1317
- args: GlobalCliClientOptions,
1318
- ) => Promise<SanityClient_2>;
1319
- /**
1320
- * Get the project API client.
1321
- *
1322
- * @param args - The project API client options.
1323
- * @returns The project API client.
1324
- *
1325
- * @deprecated use `getProjectCliClient` function directly instead.
1326
- */
1327
- protected getProjectApiClient: (
1328
- args: ProjectCliClientOptions,
1329
- ) => Promise<SanityClient_2>;
1330
- /**
1331
- * Helper for outputting to the console.
1332
- *
1333
- * @example
1334
- * ```ts
1335
- * this.output.log('Hello')
1336
- * this.output.warn('Warning')
1337
- * this.output.error('Error')
1338
- * ```
1339
- */
1340
- output: Output;
1341
- /**
1342
- * The telemetry store.
1343
- *
1344
- * @returns The telemetry store.
1345
- */
1346
- protected telemetry: CLITelemetryStore;
1347
- /**
1348
- * Report real command errors to the CLI command trace.
1349
- * User aborts (SIGINT, ExitPromptError) are not reported — the trace is left
1350
- * incomplete, which accurately represents that the command was interrupted.
1351
- */
1352
- protected catch(err: CommandError): Promise<void>;
1353
- /**
1354
- * Get the CLI config.
1355
- *
1356
- * @returns The CLI config.
1357
- */
1358
- getCliConfig(): Promise<CliConfig>;
1359
- /**
1360
- * Get the project ID from passed flags or (if not provided) the CLI config.
1361
- *
1362
- * Optionally accepts a `fallback` function that is called when no project ID
1363
- * can be determined from flags or config. This allows commands to provide
1364
- * interactive project selection while keeping the prompt logic in the CLI package.
1365
- *
1366
- * If the fallback throws a `NonInteractiveError` (e.g. because the terminal is
1367
- * not interactive), it falls through to the standard error with suggestions.
1368
- *
1369
- * Optionally accepts a `deprecatedFlagName` for commands that have a deprecated
1370
- * flag (e.g. `--project`) that should be checked after `--project-id` but before
1371
- * the CLI config.
1372
- *
1373
- * @returns The project ID.
1374
- */
1375
- getProjectId(options?: {
1376
- deprecatedFlagName?: string;
1377
- fallback?: () => Promise<string>;
1378
- }): Promise<string>;
1379
- /**
1380
- * Get the project's root directory by resolving the config
1381
- *
1382
- * @returns The project root result.
1383
- */
1384
- getProjectRoot(): Promise<ProjectRootResult>;
1385
- init(): Promise<void>;
1386
- /**
1387
- * Check if the command is running in unattended mode.
1388
- *
1389
- * This means the command should not ask for user input, instead using defaults where
1390
- * possible, and if that does not make sense (eg there's missing information), then we
1391
- * should error out (remember to exit with a non-zero code).
1392
- *
1393
- * Most commands should take an explicit `--yes` flag to enable unattended mode, but
1394
- * some commands may also be run in unattended mode if `process.stdin` is not a TTY
1395
- * (eg when running in a CI environment), or when `--json` asks for machine-readable
1396
- * output (a caller parsing JSON can't answer a prompt).
1397
- */
1398
- isUnattended(): boolean;
1399
- /**
1400
- * Write to stdout — or, when running under an execution context (e.g. from
1401
- * an MCP server), to the context's `stdout` sink. Mirrors oclif's `log`
1402
- * semantics: suppressed when `--json` is enabled, printf-style formatting.
1403
- */
1404
- log(message?: string, ...args: unknown[]): void;
1405
- /**
1406
- * Pretty-print JSON to stdout — or plain (un-colorized) JSON to the
1407
- * execution context's `stdout` sink, so programmatic callers don't have to
1408
- * strip ANSI codes.
1409
- */
1410
- logJson(json: unknown): void;
1411
- /**
1412
- * Like `log`, but for stderr / the context's `stderr` sink.
1413
- */
1414
- logToStderr(message?: string, ...args: unknown[]): void;
1415
- /**
1416
- * Resolver for checking if the terminal is interactive. Override in tests to provide mock values.
1417
- *
1418
- * @returns Whether the terminal is interactive.
1419
- */
1420
- resolveIsInteractive(): boolean;
1421
- /**
1422
- * Execute an already-constructed command without oclif's static runner:
1423
- * `Command.run()` performs a full `Config.load()` — filesystem reads, env
1424
- * consultation, and a process-global config cache write — on every call,
1425
- * which programmatic invocations must not repeat per request.
1426
- */
1427
- runInExecutionContext<TResult>(): Promise<TResult>;
1428
- /**
1429
- * Get the CLI config, returning an empty config if no project root is found.
1430
- *
1431
- * Use this instead of `getCliConfig()` in commands that can operate without a
1432
- * project directory (e.g. when `--project-id` and `--dataset` flags are provided).
1433
- *
1434
- * @returns The CLI config, or an empty config object if no project root is found.
1435
- */
1436
- protected tryGetCliConfig(): Promise<CliConfig>;
1437
- /**
1438
- * Emit a warning — routed to the execution context's `stderr` sink when one
1439
- * is active, otherwise through oclif's standard warning printer.
1440
- */
1441
- warn(input: Error | string): Error | string;
1442
- }
1443
-
1444
- /**
1445
- * Interface for `SanityCommand`, a wrapper around OCLIF's Command class.
1446
- * Important to keep updated as `SanityCommand` evolves so that its mock implementation (enabling fast unit tests) stays up to date as well.
1447
- * @see https://oclif.io/docs/base_class/
1448
- */
1449
- export declare interface SanityCommandInterface {
1450
- getCliConfig: () => Promise<CliConfig>;
1451
- getProjectId: (options?: {
1452
- deprecatedFlagName?: string;
1453
- fallback?: () => Promise<string>;
1454
- }) => Promise<string>;
1455
- getProjectRoot: () => Promise<ProjectRootResult>;
1456
- isUnattended: () => boolean;
1457
- output: Output;
1458
- resolveIsInteractive: () => boolean;
1459
- }
1460
-
1461
- export declare type SanityOrgUser = {
1462
- /**
1463
- * Null when authenticating with an API token rather than a user account —
1464
- * robot tokens resolve to a user whose `email` and `familyName` are null.
1465
- * Use `getUserDisplayName()` for anything user-facing.
1466
- */
1467
- email: string | null;
1468
- id: string;
1469
- name: string;
1470
- profileImage?: string;
1471
- /** `sanity-token` is returned when authenticating with an API token. */
1472
- provider: "github" | "google" | "sanity" | "sanity-token" | `saml-${string}`;
1473
- tosAcceptedAt?: string;
1474
- };
1475
-
1476
- /**
1477
- * Sets the global CLI telemetry state.
1478
- * @internal
1479
- */
1480
- export declare function setCliTelemetry(
1481
- telemetry: CLITelemetryStore,
1482
- options?: {
1483
- reportTraceError?: TraceErrorReporter;
1484
- },
1485
- ): void;
1486
-
1487
- /**
1488
- * Set the config value for the given property.
1489
- * Validates that the passed value adheres to the defined CLI config schema.
1490
- *
1491
- * @param prop - The property to set the value for
1492
- * @param value - The value to set
1493
- * @internal
1494
- */
1495
- export declare function setCliUserConfig(
1496
- prop: "authToken",
1497
- value: string | undefined,
1498
- ): void;
1499
-
1500
- export declare type StudioManifest = z.infer<typeof studioManifestSchema>;
1501
-
1502
- /**
1503
- * Studio application manifest (serialized `create-manifest.json`). Kept loose so
1504
- * the CLI isn't coupled to the workbench's evolving client-side schema — the
1505
- * workbench consumer is authoritative on the inner shape. See its
1506
- * `ClientManifest` for the fields clients expect.
1507
- */
1508
- export declare const studioManifestSchema: z.ZodMiniRecord<
1509
- z.ZodMiniString<string>,
1510
- z.ZodMiniUnknown
1511
- >;
1512
-
1513
- /**
1514
- * Executes a worker file in a Sanity Studio browser context.
1515
- *
1516
- * This uses a combination of vite for "bundling" + jsdom for emulating a browser
1517
- * environment under the hood, which means that the same thing that will work in vite
1518
- * _should_ work in the worker - to a degree. If the user has defined any typescript
1519
- * path aliases, these will have to be added as aliases to the vite config - the same
1520
- * behavior as you would see with regular vite. Other things that are accounted for:
1521
- *
1522
- * - TypeScript support (+JSX, enums and other "compilation needed" features)
1523
- * - CSS, font and other file imports will resolve to a file path
1524
- * - CSS module imports will resolve to a javascript object of class names
1525
- * - Environment variables are available both as `import.meta.env` and `process.env`,
1526
- * and `.env` files are loaded in the same way that they would in a Sanity studio.
1527
- * - Browser globals not available in a Node.js environment but _are_ provided by JSDOM
1528
- * are defined directly to the Node environment as globals. While this polutes the
1529
- * global namespace, it is done only in the worker thread.
1530
- * - Certain browser globals that are _not_ available in JSDOM are also provided to the
1531
- * global namespace - things like `requestIdleCallback`, `IntersectionObserver` etc.
1532
- * These are provided with a minimal stub implementation to make them not crash.
1533
- *
1534
- * @param filePath - Path to the worker file (`.ts` works and is encouraged)
1535
- * @param options - Options to pass to the worker
1536
- * @returns A promise that resolves with the message from the worker
1537
- * @throws If the file does not exist
1538
- * @throws If the worker exits with a non-zero code
1539
- * @internal
1540
- */
1541
- export declare function studioWorkerTask<T = unknown>(
1542
- filePath: URL,
1543
- options: StudioWorkerTaskOptions,
1544
- ): Promise<T>;
1545
-
1546
- /**
1547
- * Options for the studio worker task
1548
- *
1549
- * @internal
1550
- */
1551
- declare interface StudioWorkerTaskOptions extends RequireProps<
1552
- WorkerOptions,
1553
- "name"
1554
- > {
1555
- studioRootPath: string;
1556
- /** Optional timeout in milliseconds. If the worker does not respond within this time, the promise is rejected. */
1557
- timeout?: number;
1558
- }
1559
-
1560
- /**
1561
- * Get a `debug` instance which extends the CLI debug instance with the given namespace,
1562
- * eg namespace would be `sanity:cli:<providedNamespace>`
1563
- *
1564
- * @param namespace - The namespace to extend the CLI debug instance with
1565
- * @returns The extended `debug` instance
1566
- */
1567
- export declare const subdebug: (namespace: string) => debugIt.Debugger;
1568
-
1569
- /**
1570
- * Base information needed for telemetry file operations.
1571
- * Contains common data used by both file path generation and pattern matching.
1572
- */
1573
- declare interface TelemetryBaseInfo {
1574
- /** Base filename pattern without sessionId suffix */
1575
- basePattern: string;
1576
- /** Base directory where telemetry files are stored */
1577
- directory: string;
1578
- /** Environment: 'staging' or 'production' */
1579
- environment: string;
1580
- /** Hashed token (first 8 chars of SHA256) for privacy */
1581
- hashedToken: string;
1582
- }
1583
-
1584
- /**
1585
- * Note that `sessionId` is removed from the signature of these functions
1586
- */
1587
- declare interface TelemetryLogger<UserProperties> {
1588
- updateUserProperties(properties: UserProperties): void;
1589
- resume(events: DeferredEvent[]): void;
1590
- log<Data>(event: DefinedTelemetryLog<Data>, data: Data): void;
1591
- log<Data extends void>(event: DefinedTelemetryLog<Data>): void;
1592
- trace<Data>(
1593
- event: DefinedTelemetryTrace<Data>,
1594
- context?: unknown,
1595
- ): TelemetryTrace<UserProperties, Data>;
1596
- }
1597
-
1598
- declare interface TelemetryTrace<UserProperties, Data> {
1599
- start(): void;
1600
- log(data: Data): void;
1601
- error(error: Error): void;
1602
- complete(): void;
1603
- newContext(name: string): TelemetryLogger<UserProperties>;
1604
- await<P extends Promise<Data>>(promise: P): P;
1605
- await<P extends Promise<unknown>>(promise: P, finalData: Data): P;
1606
- }
1607
-
1608
- /**
1609
- * @public
1610
- */
1611
- export declare interface TelemetryUserProperties {
1612
- cliVersion: string;
1613
- cpuArchitecture: string;
1614
- machinePlatform: string;
1615
- runtime: string;
1616
- runtimeVersion: string;
1617
- dataset?: string;
1618
- projectId?: string;
1619
- }
1620
-
1621
- declare interface TimeMeasurer {
1622
- end: (name: string) => number;
1623
- getTimings: () => Record<string, number>;
1624
- start: (name: string) => void;
1625
- }
1626
-
1627
- declare type TraceErrorReporter = (error: Error) => void;
1628
-
1629
- /**
1630
- * Tries to find the studio config path, returning `undefined` if not found.
1631
- *
1632
- * @param basePath - The base path to start searching from
1633
- * @returns A promise that resolves to a string containing the found config path, or `undefined` if not found
1634
- * @throws On errors other than config not found
1635
- * @internal
1636
- */
1637
- export declare function tryFindStudioConfigPath(
1638
- basePath: string,
1639
- ): Promise<string | undefined>;
1640
-
1641
- /**
1642
- * Executes a worker file with tsx registered. This means you can import other
1643
- * typescript with fairly rich syntax, and still have that only apply to the worker
1644
- * thread instead of the full parent process. The worker should emit a message when
1645
- * complete using `parentPort`. Once it has received a single message will resolve the
1646
- * returned promise with that message. If you are expecting multiple messages, you will
1647
- * have to implement another method ;)
1648
- *
1649
- * @param filePath - Path to the worker file
1650
- * @param options - Options to pass to the worker
1651
- * @returns A promise that resolves with the message from the worker
1652
- * @throws If the file does not exist
1653
- * @throws If the worker exits with a non-zero code
1654
- * @internal
1655
- */
1656
- export declare function tsxWorkerTask<T = unknown>(
1657
- filePath: URL_2,
1658
- options: TsxWorkerTaskOptions,
1659
- ): Promise<T>;
1660
-
1661
- /**
1662
- * Options for the tsx worker task
37
+ * Creates a Node.js Worker from the given file path and options, and wraps it
38
+ * in a Promise that resolves with the first message the worker sends, and
39
+ * rejects on error, message deserialization failure, or non-zero exit code.
40
+ * By default, the worker is terminated after a message or error is received.
41
+ * Callers can instead unref it and allow natural process teardown.
1663
42
  *
43
+ * @param filePath - URL to the worker file
44
+ * @param options - Options to pass to the Worker constructor
45
+ * @returns A promise that resolves with the first message from the worker
46
+ * @throws If the worker emits an error, a message deserialization error, or exits with a non-zero code
1664
47
  * @internal
1665
48
  */
1666
- declare interface TsxWorkerTaskOptions extends RequireProps<
1667
- WorkerOptions,
1668
- "name"
1669
- > {
1670
- rootPath: string;
1671
- }
1672
-
1673
- declare interface TypeGenConfig {
1674
- formatGeneratedCode: boolean;
1675
- generates: string;
1676
- overloadClientMethods: boolean;
1677
- path: string | string[];
1678
- schema: string;
1679
- }
1680
-
1681
- /**
1682
- * @public
1683
- */
1684
- export declare type UserViteConfig =
1685
- | ((
1686
- config: InlineConfig,
1687
- env: ConfigEnv,
1688
- ) => InlineConfig | Promise<InlineConfig>)
1689
- | InlineConfig;
1690
-
1691
- export {};
49
+ declare function promisifyWorker<T = unknown>(filePath: URL, options?: PromisifyWorkerOptions): Promise<T>;
50
+ export { APP_VISIBILITIES, type AppVisibility, type ApplicationType, type CLITelemetryStore, CLI_TELEMETRY_SYMBOL, type CliConfig, type ConfigStore, type ConsentInformation, type CoreAppManifest, type GlobalCliClientOptions, NonInteractiveError, NotFoundError, type Output, type PackageJson, type ProjectCliClientOptions, ProjectRootNotFoundError, type ProjectRootResult, type ReadPackageJsonOptions, type RequireProps, SanityCommand, type SanityCommandInterface, type SanityOrgUser, type StudioManifest, type TelemetryUserProperties, type UserViteConfig, clearCliTelemetry, clearCliTokenCache, colorizeJson, coreAppManifestSchema, createStudioWorker, debug, doImport, exitCodes, findPathForFiles, findProjectRoot, findProjectRootSync, findStudioConfigPath, getCliConfig, getCliConfigSync, getCliConfigUncached, getCliTelemetry, getCliToken, getCliUserConfig, getGlobalCliClient, getLocalPackageDir, getLocalPackageVersion, getProjectCliClient, getSanityConfigDir, getSanityDataDir, getSanityEnvVar, getSanityUrl, getStudioConfig, getStudioWorkspaces, getTelemetryBaseInfo, getTimer, getUserConfig, getWorkspace, importModule, isCi, isInteractive, isNotFoundError, isProjectRootNotFoundError, isStaging, isStudioConfig, isWorkbenchApp, mockBrowserEnvironment, noopLogger, normalizePath, promisifyWorker, readPackageJson, reportCliTraceError, resolveLocalPackage, resolveLocalPackageFrom, resolveLocalPackagePath, safeStructuredClone, setCliTelemetry, setCliUserConfig, studioManifestSchema, studioWorkerTask, subdebug, tryFindStudioConfigPath, tsxWorkerTask };
51
+ //# sourceMappingURL=index.d.ts.map