@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
@@ -0,0 +1,265 @@
1
+ import { i as ConfigStore, r as CliConfig } from "./cliConfig-DrUV6Wp6.js";
2
+ import { t as ProjectRootResult } from "./recursivelyResolveProjectRoot-BE54uEP6.js";
3
+ import { z } from "zod/mini";
4
+ import { Workspace } from "sanity";
5
+ /**
6
+ * Clear the in-process token cache so the next `getCliToken()` call
7
+ * re-reads from disk or the environment.
8
+ *
9
+ * Called automatically by `setCliUserConfig('authToken', ...)`.
10
+ *
11
+ * @internal
12
+ */
13
+ declare function clearCliTokenCache(): void;
14
+ /**
15
+ * Get the CLI authentication token from the environment or the config file
16
+ *
17
+ * @returns A promise that resolves to a CLI token, or undefined if no token is found
18
+ * @internal
19
+ */
20
+ declare function getCliToken(): Promise<string | undefined>;
21
+ /**
22
+ * Set the config value for the given property.
23
+ * Validates that the passed value adheres to the defined CLI config schema.
24
+ *
25
+ * @param prop - The property to set the value for
26
+ * @param value - The value to set
27
+ * @internal
28
+ */
29
+ declare function setCliUserConfig(prop: 'authToken', value: string | undefined): void;
30
+ /**
31
+ * Get the config value for the given property
32
+ *
33
+ * @param prop - The property to get the value for
34
+ * @returns The value of the given property
35
+ */
36
+ declare function getCliUserConfig(prop: 'authToken'): string | undefined;
37
+ /**
38
+ * Get a key-value store backed by the CLI user configuration file
39
+ * (`~/.config/sanity/config.json`).
40
+ *
41
+ * Each call to `get`, `set`, or `delete` performs a full synchronous
42
+ * read-modify-write cycle. This is intentional: sync I/O prevents
43
+ * intra-process race conditions that occurred with the previous async
44
+ * (configstore-backed) implementation.
45
+ *
46
+ * Note: there is no file-level locking, so concurrent writes from
47
+ * separate CLI processes could still conflict. In practice this is
48
+ * unlikely since CLI config writes are rare and user-initiated.
49
+ *
50
+ * @returns A {@link ConfigStore} for the CLI config file
51
+ * @public
52
+ */
53
+ declare function getUserConfig(): ConfigStore;
54
+ /**
55
+ * Get the CLI config for a project, given the root path.
56
+ *
57
+ * Results are cached in-memory keyed by rootPath for the lifetime of the
58
+ * process. Since the CLI always runs from a single project root, the config
59
+ * won't change during a command's execution, so caching avoids redundant
60
+ * filesystem reads and jiti imports from the prerun hook, SanityCommand
61
+ * helpers, and action files.
62
+ *
63
+ * If loading fails the cached promise is evicted so the next call retries.
64
+ *
65
+ * Long-lived processes that need to observe edits to `sanity.cli.(ts|js)`
66
+ * (e.g. a dev-server watcher) should use {@link getCliConfigUncached}
67
+ * instead — it bypasses both this in-memory cache and Node's module cache.
68
+ *
69
+ * @param rootPath - Root path for the project, eg where `sanity.cli.(ts|js)` is located.
70
+ * @returns The CLI config
71
+ * @internal
72
+ */
73
+ declare function getCliConfig(rootPath: string): Promise<CliConfig>;
74
+ /**
75
+ * Read the CLI config for a project from disk, bypassing both the
76
+ * `getCliConfig` in-memory cache and Node's module cache. Each call locates
77
+ * `sanity.cli.(ts|js)`, drops any prior jiti compilation from `require.cache`,
78
+ * re-imports, and re-validates.
79
+ *
80
+ * Use this when the config file is expected to change during the process's
81
+ * lifetime — typically a dev-server watcher that needs the new values picked
82
+ * up after each save. One-shot CLI invocations should prefer
83
+ * {@link getCliConfig} so the prerun hook, SanityCommand helpers, and action
84
+ * files share a single load.
85
+ *
86
+ * @param rootPath - Root path for the project, eg where `sanity.cli.(ts|js)` is located.
87
+ * @returns The freshly loaded CLI config
88
+ * @internal
89
+ */
90
+ declare function getCliConfigUncached(rootPath: string): Promise<CliConfig>;
91
+ /**
92
+ * Get the CLI config for a project synchronously, given the root path.
93
+ *
94
+ * This loads the CLI config in the main thread using tsx/register for TypeScript support.
95
+ * Note: This is a synchronous operation and does not use worker threads like the async version.
96
+ *
97
+ * @param rootPath - Root path for the project, eg where `sanity.cli.(ts|js)` is located.
98
+ * @returns The CLI config
99
+ * @internal
100
+ */
101
+ declare function getCliConfigSync(rootPath: string): CliConfig;
102
+ /**
103
+ * Resolve project root directory and type.
104
+ *
105
+ * Project root is:
106
+ * - `studio` - A pre-blueprints Sanity studio root (containing `sanity.config.(ts|js)`)
107
+ * - `app` - A Sanity app root (containing `sanity.cli.(ts|js)`)
108
+ *
109
+ * If a Sanity Studio v2/v1 root is found (containing `sanity.json` with `root: true`),
110
+ * an error is thrown, as v2/v1 is no longer supported.
111
+ *
112
+ * @internal
113
+ */
114
+ declare function findProjectRoot(cwd: string): Promise<ProjectRootResult>;
115
+ /**
116
+ * Resolve project root directory and type synchronously.
117
+ *
118
+ * Project root is:
119
+ * - `studio` - A pre-blueprints Sanity studio root (containing `sanity.config.(ts|js)`)
120
+ * - `app` - A Sanity app root (containing `sanity.cli.(ts|js)`)
121
+ *
122
+ * If a Sanity Studio v2/v1 root is found (containing `sanity.json` with `root: true`),
123
+ * an error is thrown, as v2/v1 is no longer supported.
124
+ *
125
+ * @param cwd - Current working directory to start searching from
126
+ * @returns Project root result
127
+ * @internal
128
+ */
129
+ declare function findProjectRootSync(cwd: string): ProjectRootResult;
130
+ declare const rawConfigSchema: z.ZodMiniUnion<readonly [z.ZodMiniArray<z.ZodMiniObject<{
131
+ basePath: z.ZodMiniOptional<z.ZodMiniString<string>>;
132
+ name: z.ZodMiniOptional<z.ZodMiniString<string>>;
133
+ plugins: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniUnknown>>;
134
+ schema: z.ZodMiniOptional<z.ZodMiniObject<{
135
+ name: z.ZodMiniOptional<z.ZodMiniString<string>>;
136
+ types: z.ZodMiniArray<z.ZodMiniObject<{}, z.core.$loose>>;
137
+ }, z.core.$loose>>;
138
+ title: z.ZodMiniOptional<z.ZodMiniString<string>>;
139
+ unstable_sources: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniObject<{
140
+ dataset: z.ZodMiniString<string>;
141
+ projectId: z.ZodMiniString<string>;
142
+ schema: z.ZodMiniObject<{
143
+ _original: z.ZodMiniObject<{
144
+ name: z.ZodMiniOptional<z.ZodMiniString<string>>;
145
+ types: z.ZodMiniArray<z.ZodMiniObject<{}, z.core.$loose>>;
146
+ }, z.core.$loose>;
147
+ }, z.core.$loose>;
148
+ }, z.core.$loose>>>;
149
+ dataset: z.ZodMiniString<string>;
150
+ projectId: z.ZodMiniString<string>;
151
+ }, z.core.$loose>>, z.ZodMiniObject<{
152
+ basePath: z.ZodMiniOptional<z.ZodMiniString<string>>;
153
+ name: z.ZodMiniOptional<z.ZodMiniString<string>>;
154
+ plugins: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniUnknown>>;
155
+ schema: z.ZodMiniOptional<z.ZodMiniObject<{
156
+ name: z.ZodMiniOptional<z.ZodMiniString<string>>;
157
+ types: z.ZodMiniArray<z.ZodMiniObject<{}, z.core.$loose>>;
158
+ }, z.core.$loose>>;
159
+ title: z.ZodMiniOptional<z.ZodMiniString<string>>;
160
+ unstable_sources: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniObject<{
161
+ dataset: z.ZodMiniString<string>;
162
+ projectId: z.ZodMiniString<string>;
163
+ schema: z.ZodMiniObject<{
164
+ _original: z.ZodMiniObject<{
165
+ name: z.ZodMiniOptional<z.ZodMiniString<string>>;
166
+ types: z.ZodMiniArray<z.ZodMiniObject<{}, z.core.$loose>>;
167
+ }, z.core.$loose>;
168
+ }, z.core.$loose>;
169
+ }, z.core.$loose>>>;
170
+ dataset: z.ZodMiniString<string>;
171
+ projectId: z.ZodMiniString<string>;
172
+ }, z.core.$loose>]>;
173
+ declare const resolvedConfigSchema: z.ZodMiniArray<z.ZodMiniObject<{
174
+ basePath: z.ZodMiniString<string>;
175
+ name: z.ZodMiniString<string>;
176
+ plugins: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniUnknown>>;
177
+ title: z.ZodMiniString<string>;
178
+ unstable_sources: z.ZodMiniArray<z.ZodMiniObject<{
179
+ dataset: z.ZodMiniString<string>;
180
+ projectId: z.ZodMiniString<string>;
181
+ schema: z.ZodMiniObject<{
182
+ _original: z.ZodMiniObject<{
183
+ name: z.ZodMiniOptional<z.ZodMiniString<string>>;
184
+ types: z.ZodMiniArray<z.ZodMiniObject<{}, z.core.$loose>>;
185
+ }, z.core.$loose>;
186
+ }, z.core.$loose>;
187
+ }, z.core.$loose>>;
188
+ dataset: z.ZodMiniString<string>;
189
+ projectId: z.ZodMiniString<string>;
190
+ schema: z.ZodMiniObject<{
191
+ _original: z.ZodMiniObject<{
192
+ name: z.ZodMiniOptional<z.ZodMiniString<string>>;
193
+ types: z.ZodMiniArray<z.ZodMiniObject<{}, z.core.$loose>>;
194
+ }, z.core.$loose>;
195
+ }, z.core.$loose>;
196
+ }, z.core.$loose>>;
197
+ type RawStudioConfig = z.infer<typeof rawConfigSchema>;
198
+ type ResolvedStudioConfig = z.infer<typeof resolvedConfigSchema>;
199
+ /**
200
+ * Get the studio config for a project, given the root path.
201
+ *
202
+ * @param rootPath - The root path for the project
203
+ * @returns The studio config (some properties may be missing)
204
+ * @public
205
+ */
206
+ declare function getStudioConfig(rootPath: string, options: {
207
+ resolvePlugins: true;
208
+ }): Promise<ResolvedStudioConfig>;
209
+ declare function getStudioConfig(rootPath: string, options: {
210
+ resolvePlugins: false;
211
+ }): Promise<RawStudioConfig>;
212
+ /**
213
+ * Resolves the workspaces from the studio config.
214
+ *
215
+ * NOTE: This function should only be called from a worker thread.
216
+ *
217
+ * @param configPath - The path to the studio config
218
+ * @returns The workspaces
219
+ * @internal
220
+ */
221
+ declare function getStudioWorkspaces(configPath: string): Promise<Workspace[]>;
222
+ /**
223
+ * Checks if the given value conforms to a minimum studio config shape.
224
+ *
225
+ * @param value - The value to check
226
+ * @returns Whether the value is a studio config
227
+ * @internal
228
+ */
229
+ declare function isStudioConfig(value: unknown): boolean;
230
+ /**
231
+ * @internal
232
+ */
233
+ interface PathResult {
234
+ exists: boolean;
235
+ path: string;
236
+ }
237
+ /**
238
+ * Finds the path for a given set of files.
239
+ *
240
+ * @param basePath - The base path to search for files.
241
+ * @param files - The files to search for.
242
+ * @internal
243
+ */
244
+ declare function findPathForFiles(basePath: string, files: string[]): Promise<PathResult[]>;
245
+ /**
246
+ * Resolves to a string containing the found config path, otherwise throws an error.
247
+ * Also throws if Sanity v2 studio root is found.
248
+ *
249
+ * @param basePath - The base path to start searching from
250
+ * @returns A promise that resolves to a string containing the found config path
251
+ * @throws On multiple config files found, if v2 studio root found, or no config found
252
+ * @internal
253
+ */
254
+ declare function findStudioConfigPath(basePath: string): Promise<string>;
255
+ /**
256
+ * Tries to find the studio config path, returning `undefined` if not found.
257
+ *
258
+ * @param basePath - The base path to start searching from
259
+ * @returns A promise that resolves to a string containing the found config path, or `undefined` if not found
260
+ * @throws On errors other than config not found
261
+ * @internal
262
+ */
263
+ declare function tryFindStudioConfigPath(basePath: string): Promise<string | undefined>;
264
+ export { getStudioWorkspaces as a, findProjectRoot as c, getCliConfigUncached as d, getCliToken as f, clearCliTokenCache as g, setCliUserConfig as h, isStudioConfig as i, getCliConfigSync as l, getUserConfig as m, tryFindStudioConfigPath as n, getStudioConfig as o, getCliUserConfig as p, findPathForFiles as r, findProjectRootSync as s, findStudioConfigPath as t, getCliConfig as u };
265
+ //# sourceMappingURL=findStudioConfigPath-DeBa0pMT.d.ts.map
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Returns the base Sanity configuration directory for the current user.
3
+ * For persistent user settings (auth tokens, preferences, etc.).
4
+ * Respects `SANITY_INTERNAL_ENV=staging` to isolate staging instances.
5
+ *
6
+ * Layout: `~/.config/sanity{-staging}/`
7
+ *
8
+ * @returns Absolute path to the config directory
9
+ * @internal
10
+ */
11
+ declare function getSanityConfigDir(): string;
12
+ /**
13
+ * Returns the base Sanity data directory for the current user.
14
+ * For ephemeral runtime state (dev-server registries, caches, etc.).
15
+ * Respects `SANITY_INTERNAL_ENV=staging` to isolate staging instances.
16
+ *
17
+ * Layout: `~/.sanity{-staging}/`
18
+ *
19
+ * @returns Absolute path to the data directory
20
+ * @internal
21
+ */
22
+ declare function getSanityDataDir(): string;
23
+ /**
24
+ * Gets an environment variable with the appropriate Sanity prefix based on whether it's an app or studio.
25
+ *
26
+ * @param suffix - The suffix for the environment variable (e.g., 'SERVER_HOSTNAME')
27
+ * @param isApp - Whether to use the app prefix (SANITY_APP_) or studio prefix (SANITY_STUDIO_)
28
+ * @returns The value of the environment variable, or undefined if not set
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * // For studio: SANITY_STUDIO_SERVER_HOSTNAME
33
+ * const studioHostname = getSanityEnvVar('SERVER_HOSTNAME', false)
34
+ *
35
+ * // For app: SANITY_APP_SERVER_HOSTNAME
36
+ * const appHostname = getSanityEnvVar('SERVER_HOSTNAME', true)
37
+ * ```
38
+ *
39
+ * @internal
40
+ */
41
+ declare function getSanityEnvVar(suffix: string, isApp: boolean): string | undefined;
42
+ /**
43
+ * @internal
44
+ * @returns The Sanity URL for the given path, using the correct domain based on the environment
45
+ */
46
+ declare function getSanityUrl(path?: string): string;
47
+ /**
48
+ * @internal
49
+ */
50
+ declare function getWorkspace<T extends {
51
+ name: string;
52
+ }>(workspaces: T[], workspaceName?: string): T;
53
+ export { getSanityDataDir as a, getSanityConfigDir as i, getSanityUrl as n, getSanityEnvVar as r, getWorkspace as t };
54
+ //# sourceMappingURL=getWorkspace-CU32E6Uo.d.ts.map
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Mocks a browser-like environment for processes in the main thread by:
3
+ * - Injecting browser globals (window, document, ResizeObserver, etc.)
4
+ * - Loading studio environment variables from the project's sanity installation into process.env
5
+ *
6
+ * This is useful for commands like `sanity exec` that have to run user scripts
7
+ * in the main thread of the process (but in a child process).
8
+ *
9
+ * Be cautious when using this, since it will pollute the global namespace with browser globals.
10
+ *
11
+ * If your code can run in a worker thread, you should use the `studioWorkerTask` function instead.
12
+ *
13
+ * @param basePath - The root path of the Sanity Studio project
14
+ * @returns A cleanup function that removes the injected globals and environment variables
15
+ * @internal
16
+ */
17
+ declare function mockBrowserEnvironment(basePath: string): Promise<() => void>;
18
+ export { mockBrowserEnvironment as t };
19
+ //# sourceMappingURL=mockBrowserEnvironment-BjFQPb2W.d.ts.map
@@ -0,0 +1,64 @@
1
+ import { t as CLITelemetryStore } from "./types-ZNH3prAd.js";
2
+ /**
3
+ * @public
4
+ * Symbol used to store CLI telemetry state on globalThis.
5
+ * Use the accessor functions instead of accessing this directly.
6
+ */
7
+ declare const CLI_TELEMETRY_SYMBOL: unique symbol;
8
+ type TraceErrorReporter = (error: Error) => void;
9
+ /**
10
+ * @public
11
+ */
12
+ declare function getCliTelemetry(): CLITelemetryStore;
13
+ /**
14
+ * Sets the global CLI telemetry state.
15
+ * @internal
16
+ */
17
+ declare function setCliTelemetry(telemetry: CLITelemetryStore, options?: {
18
+ reportTraceError?: TraceErrorReporter;
19
+ }): void;
20
+ /**
21
+ * Reports an error to the CLI command trace. Called from SanityCommand.catch()
22
+ * for real command errors (not user aborts).
23
+ * @internal
24
+ */
25
+ declare function reportCliTraceError(error: Error): void;
26
+ /**
27
+ * Clears the global CLI telemetry store.
28
+ * @internal
29
+ */
30
+ declare function clearCliTelemetry(): void;
31
+ /**
32
+ * Base information needed for telemetry file operations.
33
+ * Contains common data used by both file path generation and pattern matching.
34
+ */
35
+ interface TelemetryBaseInfo {
36
+ /** Base filename pattern without sessionId suffix */
37
+ basePattern: string;
38
+ /** Base directory where telemetry files are stored */
39
+ directory: string;
40
+ /** Environment: 'staging' or 'production' */
41
+ environment: string;
42
+ /** Hashed token (first 8 chars of SHA256) for privacy */
43
+ hashedToken: string;
44
+ }
45
+ /**
46
+ * Gets the base telemetry information needed for file operations.
47
+ *
48
+ * This shared utility extracts common logic used by:
49
+ * - `generateTelemetryFilePath` - for generating session-specific file paths
50
+ * - `findTelemetryFiles` - for discovering all telemetry files via glob patterns
51
+ *
52
+ * @returns Promise resolving to base telemetry information
53
+ * @throws Error if no auth token is found
54
+ * @internal
55
+ */
56
+ declare function getTelemetryBaseInfo(): Promise<TelemetryBaseInfo>;
57
+ /**
58
+ * Fallback logger used when telemetry has not been initialized.
59
+ * Exported for use in tests only — do not use in plugins or external code.
60
+ * @internal
61
+ */
62
+ declare const noopLogger: CLITelemetryStore;
63
+ export { getCliTelemetry as a, clearCliTelemetry as i, getTelemetryBaseInfo as n, reportCliTraceError as o, CLI_TELEMETRY_SYMBOL as r, setCliTelemetry as s, noopLogger as t };
64
+ //# sourceMappingURL=noopTelemetry-BJRIvASI.d.ts.map
@@ -0,0 +1,67 @@
1
+ import { z } from "zod/mini";
2
+ /**
3
+ * Comprehensive package.json schema including all common properties.
4
+ * Feel free to add properties to this,
5
+ * 🟠ℹ️ BUT ENSURE OPTIONAL STUFF IS ACTUALLY OPTIONAL ℹ️🟠
6
+ * 🟠ℹ️ SINCE THIS IS USED IN A NUMBER OF LOCATIONS WHERE ℹ️🟠
7
+ * 🟠ℹ️ WE CANNOT ENFORCE/GUARANTEE ANY PARTICULAR PROPS ℹ️🟠
8
+ */
9
+ declare const packageJsonSchema: z.ZodMiniObject<{
10
+ name: z.ZodMiniString<string>;
11
+ version: z.ZodMiniString<string>;
12
+ dependencies: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>>;
13
+ devDependencies: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>>;
14
+ peerDependencies: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>>;
15
+ exports: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniAny>>;
16
+ main: z.ZodMiniOptional<z.ZodMiniString<string>>;
17
+ types: z.ZodMiniOptional<z.ZodMiniString<string>>;
18
+ author: z.ZodMiniOptional<z.ZodMiniString<string>>;
19
+ description: z.ZodMiniOptional<z.ZodMiniString<string>>;
20
+ engines: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>>;
21
+ license: z.ZodMiniOptional<z.ZodMiniString<string>>;
22
+ private: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
23
+ repository: z.ZodMiniOptional<z.ZodMiniObject<{
24
+ type: z.ZodMiniString<string>;
25
+ url: z.ZodMiniString<string>;
26
+ }, z.core.$strip>>;
27
+ scripts: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>>;
28
+ type: z.ZodMiniOptional<z.ZodMiniEnum<{
29
+ module: "module";
30
+ commonjs: "commonjs";
31
+ }>>;
32
+ }, z.core.$loose>;
33
+ /**
34
+ * Comprehensive representation of a package.json file.
35
+ * Consolidates all properties from previous type definitions.
36
+ *
37
+ * @public
38
+ */
39
+ type PackageJson = z.infer<typeof packageJsonSchema>;
40
+ /**
41
+ * Options for reading package.json files
42
+ *
43
+ * @public
44
+ */
45
+ interface ReadPackageJsonOptions {
46
+ /**
47
+ * Default values to merge with the parsed package.json.
48
+ * Parsed values take precedence over defaults.
49
+ */
50
+ defaults?: Partial<PackageJson>;
51
+ /**
52
+ * Skip Zod schema validation. When true, the file is parsed but not validated.
53
+ * Defaults to false.
54
+ */
55
+ skipSchemaValidation?: boolean;
56
+ }
57
+ /**
58
+ * Read the `package.json` file at the given path
59
+ *
60
+ * @param filePath - Path to package.json to read
61
+ * @param options - Options object for controlling read behavior
62
+ * @returns The parsed package.json
63
+ * @public
64
+ */
65
+ declare function readPackageJson(filePath: string | URL, options?: ReadPackageJsonOptions): Promise<PackageJson>;
66
+ export { ReadPackageJsonOptions as n, readPackageJson as r, PackageJson as t };
67
+ //# sourceMappingURL=readPackageJson-Cr_lbjVR.d.ts.map
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Result of finding a project configuration
3
+ *
4
+ * @public
5
+ */
6
+ interface ProjectRootResult {
7
+ directory: string;
8
+ /**
9
+ * Path to the project configuration file, if found.
10
+ */
11
+ path: string;
12
+ /**
13
+ * Type of project root.
14
+ */
15
+ type: 'app' | 'studio';
16
+ }
17
+ export { ProjectRootResult as t };
18
+ //# sourceMappingURL=recursivelyResolveProjectRoot-BE54uEP6.d.ts.map
@@ -1,67 +1,56 @@
1
1
  import { readFileSync } from 'node:fs';
2
2
  import { up as packageUp } from 'empathic/package';
3
- import { getIt } from 'get-it';
4
- import { debug, headers, httpErrors, promise } from 'get-it/middleware';
3
+ import { createRequester as createGetItRequester } from 'get-it';
4
+ import { debug as debugMiddleware } from 'get-it/middleware';
5
+ import { createDebug } from 'obug';
5
6
  import { getCliExecutionContext } from '../executionContext.js';
6
7
  let cachedPkg;
7
- /**
8
- * Creates a `get-it` requester with a standard set of middleware.
9
- *
10
- * Default middleware (in order):
11
- * 1. `httpErrors()` — throw on HTTP error status codes
12
- * 2. `headers({'User-Agent': '@sanity/cli-core@<version>'})` — identify CLI requests
13
- * 3. `debug({verbose: true, namespace: 'sanity:cli'})` — debug logging
14
- * 4. `promise({onlyBody: true})` — return body directly (must be last)
15
- *
16
- * @param options - Optional configuration to disable or customize middleware
17
- * @returns A configured `get-it` requester
18
- * @public
19
- */ export function createRequester(options) {
20
- const opts = options?.middleware;
21
- const middleware = [];
22
- // 1. httpErrors
23
- if (opts?.httpErrors !== false) {
24
- middleware.push(httpErrors());
25
- }
26
- // 2. headers
27
- if (opts?.headers !== false) {
28
- const customHeaders = typeof opts?.headers === 'object' ? opts.headers : {};
29
- const allHeaders = customHeaders['User-Agent'] ? {
30
- ...customHeaders
31
- } : {
32
- get ['User-Agent'] () {
33
- const pkg = getPackageInfo();
34
- return `${pkg.name}@${pkg.version}`;
35
- },
36
- ...customHeaders
37
- };
38
- middleware.push(headers(allHeaders));
39
- }
40
- // 3. debug
8
+ export function createRequester(options) {
9
+ const { debug, headers, middleware = [], ...getItOptions } = options ?? {};
41
10
  // A programmatic invocation must not inherit the embedding process's DEBUG setting or write request/response bodies outside its output sinks.
42
- if (!getCliExecutionContext() && opts?.debug !== false) {
11
+ const resolvedMiddleware = [
12
+ ...middleware
13
+ ];
14
+ if (!getCliExecutionContext() && debug !== false) {
43
15
  const debugDefaults = {
44
16
  namespace: 'sanity:cli',
45
17
  verbose: true
46
18
  };
47
- const customDebug = typeof opts?.debug === 'object' ? opts.debug : {};
48
- middleware.push(debug({
19
+ const customDebug = typeof debug === 'object' ? debug : {};
20
+ const { namespace, verbose } = {
49
21
  ...debugDefaults,
50
22
  ...customDebug
51
- }));
52
- }
53
- // 4. promise (must be last)
54
- if (opts?.promise !== false) {
55
- const promiseDefaults = {
56
- onlyBody: true
57
23
  };
58
- const customPromise = typeof opts?.promise === 'object' ? opts.promise : {};
59
- middleware.push(promise({
60
- ...promiseDefaults,
61
- ...customPromise
24
+ resolvedMiddleware.push(debugMiddleware({
25
+ log: createDebug(namespace),
26
+ verbose
62
27
  }));
63
28
  }
64
- return getIt(middleware);
29
+ return createGetItRequester({
30
+ ...getItOptions,
31
+ headers: resolveDefaultHeaders(headers),
32
+ middleware: resolvedMiddleware
33
+ });
34
+ }
35
+ /**
36
+ * Builds default headers, including a lazy User-Agent unless overridden or disabled.
37
+ *
38
+ * @internal
39
+ */ function resolveDefaultHeaders(headers) {
40
+ if (headers === false) {
41
+ return undefined;
42
+ }
43
+ const customHeaders = typeof headers === 'object' ? headers : {};
44
+ if (Object.keys(customHeaders).some((header)=>header.toLowerCase() === 'user-agent')) {
45
+ return customHeaders;
46
+ }
47
+ return {
48
+ get ['User-Agent'] () {
49
+ const pkg = getPackageInfo();
50
+ return `${pkg.name}@${pkg.version}`;
51
+ },
52
+ ...customHeaders
53
+ };
65
54
  }
66
55
  /**
67
56
  * Reads the nearest `package.json` to determine the name and version of the `@sanity/cli-core` package.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/request/createRequester.ts"],"sourcesContent":["import {readFileSync} from 'node:fs'\n\nimport {up as packageUp} from 'empathic/package'\nimport {getIt, type Requester} from 'get-it'\nimport {debug, headers, httpErrors, promise} from 'get-it/middleware'\n\nimport {getCliExecutionContext} from '../executionContext.js'\n\nlet cachedPkg: {name: string; version: string} | undefined\n\n/**\n * Options for configuring individual middleware in {@link createRequester}.\n *\n * Each key corresponds to a middleware. Omitting a key uses the default,\n * `false` disables it, and an object merges with the defaults.\n *\n * @public\n */\nexport type MiddlewareOptions = {\n debug?: false | {namespace?: string; verbose?: boolean}\n headers?: false | Record<string, string>\n httpErrors?: false\n promise?: false | {onlyBody?: boolean}\n}\n\n/**\n * Creates a `get-it` requester with a standard set of middleware.\n *\n * Default middleware (in order):\n * 1. `httpErrors()` — throw on HTTP error status codes\n * 2. `headers({'User-Agent': '@sanity/cli-core@<version>'})` — identify CLI requests\n * 3. `debug({verbose: true, namespace: 'sanity:cli'})` — debug logging\n * 4. `promise({onlyBody: true})` — return body directly (must be last)\n *\n * @param options - Optional configuration to disable or customize middleware\n * @returns A configured `get-it` requester\n * @public\n */\nexport function createRequester(options?: {middleware?: MiddlewareOptions}): Requester {\n const opts = options?.middleware\n\n const middleware = []\n\n // 1. httpErrors\n if (opts?.httpErrors !== false) {\n middleware.push(httpErrors())\n }\n\n // 2. headers\n if (opts?.headers !== false) {\n const customHeaders = typeof opts?.headers === 'object' ? opts.headers : {}\n const allHeaders = customHeaders['User-Agent']\n ? {...customHeaders}\n : {\n get ['User-Agent']() {\n const pkg = getPackageInfo()\n return `${pkg.name}@${pkg.version}`\n },\n ...customHeaders,\n }\n middleware.push(headers(allHeaders))\n }\n\n // 3. debug\n // A programmatic invocation must not inherit the embedding process's DEBUG setting or write request/response bodies outside its output sinks.\n if (!getCliExecutionContext() && opts?.debug !== false) {\n const debugDefaults = {namespace: 'sanity:cli', verbose: true}\n const customDebug = typeof opts?.debug === 'object' ? opts.debug : {}\n middleware.push(debug({...debugDefaults, ...customDebug}))\n }\n\n // 4. promise (must be last)\n if (opts?.promise !== false) {\n const promiseDefaults = {onlyBody: true}\n const customPromise = typeof opts?.promise === 'object' ? opts.promise : {}\n middleware.push(promise({...promiseDefaults, ...customPromise}))\n }\n\n return getIt(middleware)\n}\n\n/**\n * Reads the nearest `package.json` to determine the name and version of the `@sanity/cli-core` package.\n *\n * @returns The name and version of the package\n * @internal\n */\nfunction getPackageInfo(): {name: string; version: string} {\n if (cachedPkg) return cachedPkg\n\n const pkgPath = packageUp({cwd: import.meta.dirname})\n if (!pkgPath) {\n throw new Error('Unable to resolve @sanity/cli-core package root')\n }\n\n const packageJson = JSON.parse(readFileSync(pkgPath, 'utf8'))\n cachedPkg = {\n name: packageJson.name ?? '@sanity/cli-core',\n version: packageJson.version ?? '0.0.0',\n }\n return cachedPkg\n}\n"],"names":["readFileSync","up","packageUp","getIt","debug","headers","httpErrors","promise","getCliExecutionContext","cachedPkg","createRequester","options","opts","middleware","push","customHeaders","allHeaders","pkg","getPackageInfo","name","version","debugDefaults","namespace","verbose","customDebug","promiseDefaults","onlyBody","customPromise","pkgPath","cwd","dirname","Error","packageJson","JSON","parse"],"mappings":"AAAA,SAAQA,YAAY,QAAO,UAAS;AAEpC,SAAQC,MAAMC,SAAS,QAAO,mBAAkB;AAChD,SAAQC,KAAK,QAAuB,SAAQ;AAC5C,SAAQC,KAAK,EAAEC,OAAO,EAAEC,UAAU,EAAEC,OAAO,QAAO,oBAAmB;AAErE,SAAQC,sBAAsB,QAAO,yBAAwB;AAE7D,IAAIC;AAiBJ;;;;;;;;;;;;CAYC,GACD,OAAO,SAASC,gBAAgBC,OAA0C;IACxE,MAAMC,OAAOD,SAASE;IAEtB,MAAMA,aAAa,EAAE;IAErB,gBAAgB;IAChB,IAAID,MAAMN,eAAe,OAAO;QAC9BO,WAAWC,IAAI,CAACR;IAClB;IAEA,aAAa;IACb,IAAIM,MAAMP,YAAY,OAAO;QAC3B,MAAMU,gBAAgB,OAAOH,MAAMP,YAAY,WAAWO,KAAKP,OAAO,GAAG,CAAC;QAC1E,MAAMW,aAAaD,aAAa,CAAC,aAAa,GAC1C;YAAC,GAAGA,aAAa;QAAA,IACjB;YACE,IAAI,CAAC,aAAa,IAAG;gBACnB,MAAME,MAAMC;gBACZ,OAAO,GAAGD,IAAIE,IAAI,CAAC,CAAC,EAAEF,IAAIG,OAAO,EAAE;YACrC;YACA,GAAGL,aAAa;QAClB;QACJF,WAAWC,IAAI,CAACT,QAAQW;IAC1B;IAEA,WAAW;IACX,8IAA8I;IAC9I,IAAI,CAACR,4BAA4BI,MAAMR,UAAU,OAAO;QACtD,MAAMiB,gBAAgB;YAACC,WAAW;YAAcC,SAAS;QAAI;QAC7D,MAAMC,cAAc,OAAOZ,MAAMR,UAAU,WAAWQ,KAAKR,KAAK,GAAG,CAAC;QACpES,WAAWC,IAAI,CAACV,MAAM;YAAC,GAAGiB,aAAa;YAAE,GAAGG,WAAW;QAAA;IACzD;IAEA,4BAA4B;IAC5B,IAAIZ,MAAML,YAAY,OAAO;QAC3B,MAAMkB,kBAAkB;YAACC,UAAU;QAAI;QACvC,MAAMC,gBAAgB,OAAOf,MAAML,YAAY,WAAWK,KAAKL,OAAO,GAAG,CAAC;QAC1EM,WAAWC,IAAI,CAACP,QAAQ;YAAC,GAAGkB,eAAe;YAAE,GAAGE,aAAa;QAAA;IAC/D;IAEA,OAAOxB,MAAMU;AACf;AAEA;;;;;CAKC,GACD,SAASK;IACP,IAAIT,WAAW,OAAOA;IAEtB,MAAMmB,UAAU1B,UAAU;QAAC2B,KAAK,YAAYC,OAAO;IAAA;IACnD,IAAI,CAACF,SAAS;QACZ,MAAM,IAAIG,MAAM;IAClB;IAEA,MAAMC,cAAcC,KAAKC,KAAK,CAAClC,aAAa4B,SAAS;IACrDnB,YAAY;QACVU,MAAMa,YAAYb,IAAI,IAAI;QAC1BC,SAASY,YAAYZ,OAAO,IAAI;IAClC;IACA,OAAOX;AACT"}
1
+ {"version":3,"sources":["../../src/request/createRequester.ts"],"sourcesContent":["import {readFileSync} from 'node:fs'\n\nimport {up as packageUp} from 'empathic/package'\nimport {\n createRequester as createGetItRequester,\n type FetchHeaders,\n type RequesterOptions,\n type RequestFunction,\n type TransformMiddleware,\n type WrappingMiddleware,\n} from 'get-it'\nimport {debug as debugMiddleware} from 'get-it/middleware'\nimport {createDebug} from 'obug'\n\nimport {getCliExecutionContext} from '../executionContext.js'\n\nlet cachedPkg: {name: string; version: string} | undefined\n\n/**\n * Options for creating a Sanity CLI requester.\n *\n * Extends get-it v9's {@link RequesterOptions} with Sanity CLI defaults for\n * User-Agent headers and debug logging.\n *\n * @public\n */\nexport type CreateRequesterOptions = Omit<RequesterOptions, 'headers'> & {\n /**\n * Debug logging middleware. Defaults to enabled with namespace `sanity:cli`.\n * Pass `false` to disable.\n */\n debug?: false | {namespace?: string; verbose?: boolean}\n /**\n * Default headers for all requests.\n * Omitting uses a lazy User-Agent of `@sanity/cli-core@<version>`.\n * Pass `false` to send no default headers.\n */\n headers?: false | Record<string, string>\n}\n\n/**\n * Creates a get-it requester with Sanity CLI defaults.\n *\n * Defaults:\n * - User-Agent header: `@sanity/cli-core@<version>` (lazy)\n * - Debug logging via `DEBUG=sanity:cli` (verbose)\n * - HTTP error throwing on (get-it default)\n *\n * @param options - Optional configuration to customize or disable defaults\n * @returns A configured get-it request function\n * @public\n */\nexport function createRequester(\n options: CreateRequesterOptions & {as: 'json'},\n): RequestFunction<'json'>\nexport function createRequester(\n options: CreateRequesterOptions & {as: 'text'},\n): RequestFunction<'text'>\nexport function createRequester(\n options: CreateRequesterOptions & {as: 'stream'},\n): RequestFunction<'stream'>\nexport function createRequester(options?: CreateRequesterOptions): RequestFunction\nexport function createRequester(\n options?: CreateRequesterOptions,\n): RequestFunction<'json' | 'stream' | 'text' | undefined> {\n const {debug, headers, middleware = [], ...getItOptions} = options ?? {}\n\n // A programmatic invocation must not inherit the embedding process's DEBUG setting or write request/response bodies outside its output sinks.\n const resolvedMiddleware: Array<TransformMiddleware | WrappingMiddleware> = [...middleware]\n if (!getCliExecutionContext() && debug !== false) {\n const debugDefaults = {namespace: 'sanity:cli', verbose: true}\n const customDebug = typeof debug === 'object' ? debug : {}\n const {namespace, verbose} = {...debugDefaults, ...customDebug}\n resolvedMiddleware.push(debugMiddleware({log: createDebug(namespace), verbose}))\n }\n\n return createGetItRequester({\n ...getItOptions,\n headers: resolveDefaultHeaders(headers),\n middleware: resolvedMiddleware,\n })\n}\n\n/**\n * Builds default headers, including a lazy User-Agent unless overridden or disabled.\n *\n * @internal\n */\nfunction resolveDefaultHeaders(\n headers: false | Record<string, string> | undefined,\n): FetchHeaders | undefined {\n if (headers === false) {\n return undefined\n }\n\n const customHeaders = typeof headers === 'object' ? headers : {}\n if (Object.keys(customHeaders).some((header) => header.toLowerCase() === 'user-agent')) {\n return customHeaders\n }\n\n return {\n get ['User-Agent']() {\n const pkg = getPackageInfo()\n return `${pkg.name}@${pkg.version}`\n },\n ...customHeaders,\n }\n}\n\n/**\n * Reads the nearest `package.json` to determine the name and version of the `@sanity/cli-core` package.\n *\n * @returns The name and version of the package\n * @internal\n */\nfunction getPackageInfo(): {name: string; version: string} {\n if (cachedPkg) return cachedPkg\n\n const pkgPath = packageUp({cwd: import.meta.dirname})\n if (!pkgPath) {\n throw new Error('Unable to resolve @sanity/cli-core package root')\n }\n\n const packageJson = JSON.parse(readFileSync(pkgPath, 'utf8'))\n cachedPkg = {\n name: packageJson.name ?? '@sanity/cli-core',\n version: packageJson.version ?? '0.0.0',\n }\n return cachedPkg\n}\n"],"names":["readFileSync","up","packageUp","createRequester","createGetItRequester","debug","debugMiddleware","createDebug","getCliExecutionContext","cachedPkg","options","headers","middleware","getItOptions","resolvedMiddleware","debugDefaults","namespace","verbose","customDebug","push","log","resolveDefaultHeaders","undefined","customHeaders","Object","keys","some","header","toLowerCase","pkg","getPackageInfo","name","version","pkgPath","cwd","dirname","Error","packageJson","JSON","parse"],"mappings":"AAAA,SAAQA,YAAY,QAAO,UAAS;AAEpC,SAAQC,MAAMC,SAAS,QAAO,mBAAkB;AAChD,SACEC,mBAAmBC,oBAAoB,QAMlC,SAAQ;AACf,SAAQC,SAASC,eAAe,QAAO,oBAAmB;AAC1D,SAAQC,WAAW,QAAO,OAAM;AAEhC,SAAQC,sBAAsB,QAAO,yBAAwB;AAE7D,IAAIC;AA8CJ,OAAO,SAASN,gBACdO,OAAgC;IAEhC,MAAM,EAACL,KAAK,EAAEM,OAAO,EAAEC,aAAa,EAAE,EAAE,GAAGC,cAAa,GAAGH,WAAW,CAAC;IAEvE,8IAA8I;IAC9I,MAAMI,qBAAsE;WAAIF;KAAW;IAC3F,IAAI,CAACJ,4BAA4BH,UAAU,OAAO;QAChD,MAAMU,gBAAgB;YAACC,WAAW;YAAcC,SAAS;QAAI;QAC7D,MAAMC,cAAc,OAAOb,UAAU,WAAWA,QAAQ,CAAC;QACzD,MAAM,EAACW,SAAS,EAAEC,OAAO,EAAC,GAAG;YAAC,GAAGF,aAAa;YAAE,GAAGG,WAAW;QAAA;QAC9DJ,mBAAmBK,IAAI,CAACb,gBAAgB;YAACc,KAAKb,YAAYS;YAAYC;QAAO;IAC/E;IAEA,OAAOb,qBAAqB;QAC1B,GAAGS,YAAY;QACfF,SAASU,sBAAsBV;QAC/BC,YAAYE;IACd;AACF;AAEA;;;;CAIC,GACD,SAASO,sBACPV,OAAmD;IAEnD,IAAIA,YAAY,OAAO;QACrB,OAAOW;IACT;IAEA,MAAMC,gBAAgB,OAAOZ,YAAY,WAAWA,UAAU,CAAC;IAC/D,IAAIa,OAAOC,IAAI,CAACF,eAAeG,IAAI,CAAC,CAACC,SAAWA,OAAOC,WAAW,OAAO,eAAe;QACtF,OAAOL;IACT;IAEA,OAAO;QACL,IAAI,CAAC,aAAa,IAAG;YACnB,MAAMM,MAAMC;YACZ,OAAO,GAAGD,IAAIE,IAAI,CAAC,CAAC,EAAEF,IAAIG,OAAO,EAAE;QACrC;QACA,GAAGT,aAAa;IAClB;AACF;AAEA;;;;;CAKC,GACD,SAASO;IACP,IAAIrB,WAAW,OAAOA;IAEtB,MAAMwB,UAAU/B,UAAU;QAACgC,KAAK,YAAYC,OAAO;IAAA;IACnD,IAAI,CAACF,SAAS;QACZ,MAAM,IAAIG,MAAM;IAClB;IAEA,MAAMC,cAAcC,KAAKC,KAAK,CAACvC,aAAaiC,SAAS;IACrDxB,YAAY;QACVsB,MAAMM,YAAYN,IAAI,IAAI;QAC1BC,SAASK,YAAYL,OAAO,IAAI;IAClC;IACA,OAAOvB;AACT"}