@sanity/cli-core 0.0.0-20260410130107 → 0.0.0-20260416133835
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_exports/index.d.ts +103 -2
- package/dist/_exports/index.js +2 -0
- package/dist/_exports/index.js.map +1 -1
- package/dist/services/cliUserConfig.js +2 -4
- package/dist/services/cliUserConfig.js.map +1 -1
- package/dist/telemetry/getCliTelemetry.js +1 -1
- package/dist/telemetry/getCliTelemetry.js.map +1 -1
- package/dist/telemetry/noopTelemetry.js +23 -0
- package/dist/telemetry/noopTelemetry.js.map +1 -0
- package/dist/util/getSanityConfigDir.js +32 -0
- package/dist/util/getSanityConfigDir.js.map +1 -0
- package/package.json +6 -9
package/dist/_exports/index.d.ts
CHANGED
|
@@ -3,14 +3,12 @@ import { CLIError } from "@oclif/core/errors";
|
|
|
3
3
|
import { Command } from "@oclif/core";
|
|
4
4
|
import { CommandError } from "@oclif/core/interfaces";
|
|
5
5
|
import { ConfigEnv } from "vite";
|
|
6
|
-
import { ConsentStatus } from "@sanity/telemetry";
|
|
7
6
|
import debugIt from "debug";
|
|
8
7
|
import { InlineConfig } from "vite";
|
|
9
8
|
import { Interfaces } from "@oclif/core";
|
|
10
9
|
import { PluginOptions } from "babel-plugin-react-compiler";
|
|
11
10
|
import { SanityClient } from "sanity";
|
|
12
11
|
import { SanityClient as SanityClient_2 } from "@sanity/client";
|
|
13
|
-
import { TelemetryLogger } from "@sanity/telemetry";
|
|
14
12
|
import { URL as URL_2 } from "node:url";
|
|
15
13
|
import { Worker as Worker_2 } from "node:worker_threads";
|
|
16
14
|
import { WorkerOptions as WorkerOptions_2 } from "node:worker_threads";
|
|
@@ -215,6 +213,14 @@ export declare type ConsentInformation =
|
|
|
215
213
|
status: Extract<ConsentStatus, "unset">;
|
|
216
214
|
};
|
|
217
215
|
|
|
216
|
+
/**
|
|
217
|
+
* 'unknown' - we don't know if the user has consented or not (e.g. something went wrong)
|
|
218
|
+
* 'unset' - the user has not yet been asked for consent
|
|
219
|
+
* 'granted' - the user has consented
|
|
220
|
+
* 'denied' - the user has denied consent
|
|
221
|
+
*/
|
|
222
|
+
declare type ConsentStatus = "undetermined" | "unset" | "granted" | "denied";
|
|
223
|
+
|
|
218
224
|
/**
|
|
219
225
|
* Creates a new worker for a studio worker task.
|
|
220
226
|
*
|
|
@@ -256,6 +262,46 @@ export declare function createStudioWorker(
|
|
|
256
262
|
declare const debug_2: debugIt.Debugger;
|
|
257
263
|
export { debug_2 as debug };
|
|
258
264
|
|
|
265
|
+
declare interface DeferredEvent<
|
|
266
|
+
Data = unknown,
|
|
267
|
+
Event extends DefinedTelemetryLog<Data> = DefinedTelemetryLog<Data>,
|
|
268
|
+
> {
|
|
269
|
+
createdAt: string;
|
|
270
|
+
event: Event;
|
|
271
|
+
data: Data;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
declare interface DefinedTelemetryLog<Schema> {
|
|
275
|
+
type: "log";
|
|
276
|
+
/** Unique name of the event */
|
|
277
|
+
name: string;
|
|
278
|
+
/** Event version. Increment this by 1 whenever the shape of the data changes in a non-backwards compatible way */
|
|
279
|
+
version: number;
|
|
280
|
+
/** Description of log event */
|
|
281
|
+
description?: string;
|
|
282
|
+
/**
|
|
283
|
+
* Max sample rate of this event.
|
|
284
|
+
* Calling telemetry.log(EventDefinition, data) repeatedly will submit at most one event every specified time interval (in milliseconds)
|
|
285
|
+
* */
|
|
286
|
+
maxSampleRate?: number;
|
|
287
|
+
/** Data schema. Will not be accessible at runtime */
|
|
288
|
+
schema: Schema;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
declare interface DefinedTelemetryTrace<Data = void, Context = void> {
|
|
292
|
+
type: "trace";
|
|
293
|
+
/** Unique name of the trace */
|
|
294
|
+
name: string;
|
|
295
|
+
/** Trace version. Increment this by 1 whenever the shape of the data changes in a non-backwards compatible way */
|
|
296
|
+
version: number;
|
|
297
|
+
/** Description of trace */
|
|
298
|
+
description?: string;
|
|
299
|
+
/** Data schema. Will not be accessible at runtime */
|
|
300
|
+
schema: Data;
|
|
301
|
+
/** Contextual data schema. Will not be accessible at runtime */
|
|
302
|
+
context: Context;
|
|
303
|
+
}
|
|
304
|
+
|
|
259
305
|
/**
|
|
260
306
|
* This function is a replacement for built in dynamic import
|
|
261
307
|
* This handles the case for windows file paths especially for absolute paths.
|
|
@@ -425,6 +471,30 @@ export declare function getProjectCliClient({
|
|
|
425
471
|
...config
|
|
426
472
|
}: ProjectCliClientOptions): Promise<SanityClient_2>;
|
|
427
473
|
|
|
474
|
+
/**
|
|
475
|
+
* Returns the base Sanity configuration directory for the current user.
|
|
476
|
+
* For persistent user settings (auth tokens, preferences, etc.).
|
|
477
|
+
* Respects `SANITY_INTERNAL_ENV=staging` to isolate staging instances.
|
|
478
|
+
*
|
|
479
|
+
* Layout: `~/.config/sanity{-staging}/`
|
|
480
|
+
*
|
|
481
|
+
* @returns Absolute path to the config directory
|
|
482
|
+
* @internal
|
|
483
|
+
*/
|
|
484
|
+
export declare function getSanityConfigDir(): string;
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Returns the base Sanity data directory for the current user.
|
|
488
|
+
* For ephemeral runtime state (dev-server registries, caches, etc.).
|
|
489
|
+
* Respects `SANITY_INTERNAL_ENV=staging` to isolate staging instances.
|
|
490
|
+
*
|
|
491
|
+
* Layout: `~/.sanity{-staging}/`
|
|
492
|
+
*
|
|
493
|
+
* @returns Absolute path to the data directory
|
|
494
|
+
* @internal
|
|
495
|
+
*/
|
|
496
|
+
export declare function getSanityDataDir(): string;
|
|
497
|
+
|
|
428
498
|
/**
|
|
429
499
|
* Gets an environment variable with the appropriate Sanity prefix based on whether it's an app or studio.
|
|
430
500
|
*
|
|
@@ -648,6 +718,13 @@ export declare class NonInteractiveError extends CLIError {
|
|
|
648
718
|
constructor(promptName: string);
|
|
649
719
|
}
|
|
650
720
|
|
|
721
|
+
/**
|
|
722
|
+
* Fallback logger used when telemetry has not been initialized.
|
|
723
|
+
* Exported for use in tests only — do not use in plugins or external code.
|
|
724
|
+
* @internal
|
|
725
|
+
*/
|
|
726
|
+
export declare const noopLogger: CLITelemetryStore;
|
|
727
|
+
|
|
651
728
|
/**
|
|
652
729
|
* Normalizes a path for cross-platform comparison by converting backslashes to forward slashes.
|
|
653
730
|
* Useful for converting windows paths to unix paths.
|
|
@@ -1305,6 +1382,30 @@ declare interface TelemetryBaseInfo {
|
|
|
1305
1382
|
hashedToken: string;
|
|
1306
1383
|
}
|
|
1307
1384
|
|
|
1385
|
+
/**
|
|
1386
|
+
* Note that `sessionId` is removed from the signature of these functions
|
|
1387
|
+
*/
|
|
1388
|
+
declare interface TelemetryLogger<UserProperties> {
|
|
1389
|
+
updateUserProperties(properties: UserProperties): void;
|
|
1390
|
+
resume(events: DeferredEvent[]): void;
|
|
1391
|
+
log<Data>(event: DefinedTelemetryLog<Data>, data: Data): void;
|
|
1392
|
+
log<Data extends void>(event: DefinedTelemetryLog<Data>): void;
|
|
1393
|
+
trace<Data>(
|
|
1394
|
+
event: DefinedTelemetryTrace<Data>,
|
|
1395
|
+
context?: unknown,
|
|
1396
|
+
): TelemetryTrace<UserProperties, Data>;
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
declare interface TelemetryTrace<UserProperties, Data> {
|
|
1400
|
+
start(): void;
|
|
1401
|
+
log(data: Data): void;
|
|
1402
|
+
error(error: Error): void;
|
|
1403
|
+
complete(): void;
|
|
1404
|
+
newContext(name: string): TelemetryLogger<UserProperties>;
|
|
1405
|
+
await<P extends Promise<Data>>(promise: P): P;
|
|
1406
|
+
await<P extends Promise<unknown>>(promise: P, finalData: Data): P;
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1308
1409
|
/**
|
|
1309
1410
|
* @public
|
|
1310
1411
|
*/
|
package/dist/_exports/index.js
CHANGED
|
@@ -20,8 +20,10 @@ export * from '../services/cliUserConfig.js';
|
|
|
20
20
|
export * from '../services/getCliToken.js';
|
|
21
21
|
export { clearCliTelemetry, CLI_TELEMETRY_SYMBOL, getCliTelemetry, setCliTelemetry } from '../telemetry/getCliTelemetry.js';
|
|
22
22
|
export { getTelemetryBaseInfo } from '../telemetry/getTelemetryBaseInfo.js';
|
|
23
|
+
export { noopLogger } from '../telemetry/noopTelemetry.js';
|
|
23
24
|
export { doImport } from '../util/doImport.js';
|
|
24
25
|
export * from '../util/environment/mockBrowserEnvironment.js';
|
|
26
|
+
export * from '../util/getSanityConfigDir.js';
|
|
25
27
|
export * from '../util/getSanityEnvVar.js';
|
|
26
28
|
export * from '../util/getSanityUrl.js';
|
|
27
29
|
export * from '../util/importModule.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/_exports/index.ts"],"sourcesContent":["export * from '../config/cli/getCliConfig.js'\nexport * from '../config/cli/getCliConfigSync.js'\nexport {type CliConfig} from '../config/cli/types/cliConfig.js'\nexport {type UserViteConfig} from '../config/cli/types/userViteConfig.js'\nexport * from '../config/findProjectRoot.js'\nexport * from '../config/findProjectRootSync.js'\nexport * from '../config/studio/getStudioConfig.js'\nexport * from '../config/studio/getStudioWorkspaces.js'\nexport * from '../config/studio/isStudioConfig.js'\nexport * from '../config/util/findConfigsPaths.js'\nexport * from '../config/util/findStudioConfigPath.js'\nexport {type ProjectRootResult} from '../config/util/recursivelyResolveProjectRoot.js'\nexport * from '../debug.js'\nexport * from '../errors/NonInteractiveError.js'\nexport * from '../errors/NotFoundError.js'\nexport * from '../errors/ProjectRootNotFoundError.js'\nexport * from '../exitCodes.js'\nexport * from '../loaders/studio/studioWorkerTask.js'\nexport * from '../loaders/tsx/tsxWorkerTask.js'\nexport * from '../SanityCommand.js'\nexport * from '../services/apiClient.js'\nexport * from '../services/cliUserConfig.js'\nexport * from '../services/getCliToken.js'\nexport {\n clearCliTelemetry,\n CLI_TELEMETRY_SYMBOL,\n getCliTelemetry,\n setCliTelemetry,\n} from '../telemetry/getCliTelemetry.js'\nexport {getTelemetryBaseInfo} from '../telemetry/getTelemetryBaseInfo.js'\nexport {\n type CLITelemetryStore,\n type ConsentInformation,\n type TelemetryUserProperties,\n} from '../telemetry/types.js'\nexport {type Output, type SanityOrgUser} from '../types.js'\nexport {doImport} from '../util/doImport.js'\nexport * from '../util/environment/mockBrowserEnvironment.js'\nexport * from '../util/getSanityEnvVar.js'\nexport * from '../util/getSanityUrl.js'\nexport * from '../util/importModule.js'\nexport * from '../util/isCi.js'\nexport * from '../util/isInteractive.js'\nexport * from '../util/isStaging.js'\nexport * from '../util/normalizePath.js'\nexport * from '../util/promisifyWorker.js'\nexport * from '../util/readPackageJson.js'\nexport * from '../util/resolveLocalPackage.js'\nexport * from '../util/safeStructuredClone.js'\nexport * from '../ux/colorizeJson.js'\nexport * from '../ux/timer.js'\n"],"names":["clearCliTelemetry","CLI_TELEMETRY_SYMBOL","getCliTelemetry","setCliTelemetry","getTelemetryBaseInfo","doImport"],"mappings":"AAAA,cAAc,gCAA+B;AAC7C,cAAc,oCAAmC;AAGjD,cAAc,+BAA8B;AAC5C,cAAc,mCAAkC;AAChD,cAAc,sCAAqC;AACnD,cAAc,0CAAyC;AACvD,cAAc,qCAAoC;AAClD,cAAc,qCAAoC;AAClD,cAAc,yCAAwC;AAEtD,cAAc,cAAa;AAC3B,cAAc,mCAAkC;AAChD,cAAc,6BAA4B;AAC1C,cAAc,wCAAuC;AACrD,cAAc,kBAAiB;AAC/B,cAAc,wCAAuC;AACrD,cAAc,kCAAiC;AAC/C,cAAc,sBAAqB;AACnC,cAAc,2BAA0B;AACxC,cAAc,+BAA8B;AAC5C,cAAc,6BAA4B;AAC1C,SACEA,iBAAiB,EACjBC,oBAAoB,EACpBC,eAAe,EACfC,eAAe,QACV,kCAAiC;AACxC,SAAQC,oBAAoB,QAAO,uCAAsC;
|
|
1
|
+
{"version":3,"sources":["../../src/_exports/index.ts"],"sourcesContent":["export * from '../config/cli/getCliConfig.js'\nexport * from '../config/cli/getCliConfigSync.js'\nexport {type CliConfig} from '../config/cli/types/cliConfig.js'\nexport {type UserViteConfig} from '../config/cli/types/userViteConfig.js'\nexport * from '../config/findProjectRoot.js'\nexport * from '../config/findProjectRootSync.js'\nexport * from '../config/studio/getStudioConfig.js'\nexport * from '../config/studio/getStudioWorkspaces.js'\nexport * from '../config/studio/isStudioConfig.js'\nexport * from '../config/util/findConfigsPaths.js'\nexport * from '../config/util/findStudioConfigPath.js'\nexport {type ProjectRootResult} from '../config/util/recursivelyResolveProjectRoot.js'\nexport * from '../debug.js'\nexport * from '../errors/NonInteractiveError.js'\nexport * from '../errors/NotFoundError.js'\nexport * from '../errors/ProjectRootNotFoundError.js'\nexport * from '../exitCodes.js'\nexport * from '../loaders/studio/studioWorkerTask.js'\nexport * from '../loaders/tsx/tsxWorkerTask.js'\nexport * from '../SanityCommand.js'\nexport * from '../services/apiClient.js'\nexport * from '../services/cliUserConfig.js'\nexport * from '../services/getCliToken.js'\nexport {\n clearCliTelemetry,\n CLI_TELEMETRY_SYMBOL,\n getCliTelemetry,\n setCliTelemetry,\n} from '../telemetry/getCliTelemetry.js'\nexport {getTelemetryBaseInfo} from '../telemetry/getTelemetryBaseInfo.js'\nexport {noopLogger} from '../telemetry/noopTelemetry.js'\nexport {\n type CLITelemetryStore,\n type ConsentInformation,\n type TelemetryUserProperties,\n} from '../telemetry/types.js'\nexport {type Output, type SanityOrgUser} from '../types.js'\nexport {doImport} from '../util/doImport.js'\nexport * from '../util/environment/mockBrowserEnvironment.js'\nexport * from '../util/getSanityConfigDir.js'\nexport * from '../util/getSanityEnvVar.js'\nexport * from '../util/getSanityUrl.js'\nexport * from '../util/importModule.js'\nexport * from '../util/isCi.js'\nexport * from '../util/isInteractive.js'\nexport * from '../util/isStaging.js'\nexport * from '../util/normalizePath.js'\nexport * from '../util/promisifyWorker.js'\nexport * from '../util/readPackageJson.js'\nexport * from '../util/resolveLocalPackage.js'\nexport * from '../util/safeStructuredClone.js'\nexport * from '../ux/colorizeJson.js'\nexport * from '../ux/timer.js'\n"],"names":["clearCliTelemetry","CLI_TELEMETRY_SYMBOL","getCliTelemetry","setCliTelemetry","getTelemetryBaseInfo","noopLogger","doImport"],"mappings":"AAAA,cAAc,gCAA+B;AAC7C,cAAc,oCAAmC;AAGjD,cAAc,+BAA8B;AAC5C,cAAc,mCAAkC;AAChD,cAAc,sCAAqC;AACnD,cAAc,0CAAyC;AACvD,cAAc,qCAAoC;AAClD,cAAc,qCAAoC;AAClD,cAAc,yCAAwC;AAEtD,cAAc,cAAa;AAC3B,cAAc,mCAAkC;AAChD,cAAc,6BAA4B;AAC1C,cAAc,wCAAuC;AACrD,cAAc,kBAAiB;AAC/B,cAAc,wCAAuC;AACrD,cAAc,kCAAiC;AAC/C,cAAc,sBAAqB;AACnC,cAAc,2BAA0B;AACxC,cAAc,+BAA8B;AAC5C,cAAc,6BAA4B;AAC1C,SACEA,iBAAiB,EACjBC,oBAAoB,EACpBC,eAAe,EACfC,eAAe,QACV,kCAAiC;AACxC,SAAQC,oBAAoB,QAAO,uCAAsC;AACzE,SAAQC,UAAU,QAAO,gCAA+B;AAOxD,SAAQC,QAAQ,QAAO,sBAAqB;AAC5C,cAAc,gDAA+C;AAC7D,cAAc,gCAA+B;AAC7C,cAAc,6BAA4B;AAC1C,cAAc,0BAAyB;AACvC,cAAc,0BAAyB;AACvC,cAAc,kBAAiB;AAC/B,cAAc,2BAA0B;AACxC,cAAc,uBAAsB;AACpC,cAAc,2BAA0B;AACxC,cAAc,6BAA4B;AAC1C,cAAc,6BAA4B;AAC1C,cAAc,iCAAgC;AAC9C,cAAc,iCAAgC;AAC9C,cAAc,wBAAuB;AACrC,cAAc,iBAAgB"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { mkdirSync } from 'node:fs';
|
|
2
|
-
import { homedir } from 'node:os';
|
|
3
2
|
import { dirname, join as joinPath } from 'node:path';
|
|
4
3
|
import { z } from 'zod/mini';
|
|
5
4
|
import { debug } from '../debug.js';
|
|
5
|
+
import { getSanityConfigDir } from '../util/getSanityConfigDir.js';
|
|
6
6
|
import { readJsonFileSync } from '../util/readJsonFileSync.js';
|
|
7
7
|
import { writeJsonFileSync } from '../util/writeJsonFileSync.js';
|
|
8
8
|
import { clearCliTokenCache } from './cliTokenCache.js';
|
|
@@ -136,9 +136,7 @@ const cliUserConfigSchema = {
|
|
|
136
136
|
* @returns The path to the CLI configuration file.
|
|
137
137
|
* @internal
|
|
138
138
|
*/ function getCliUserConfigPath() {
|
|
139
|
-
|
|
140
|
-
const cliConfigPath = process.env.SANITY_CLI_CONFIG_PATH || joinPath(homedir(), '.config', `sanity${sanityEnvSuffix}`, 'config.json');
|
|
141
|
-
return cliConfigPath;
|
|
139
|
+
return process.env.SANITY_CLI_CONFIG_PATH || joinPath(getSanityConfigDir(), 'config.json');
|
|
142
140
|
}
|
|
143
141
|
|
|
144
142
|
//# sourceMappingURL=cliUserConfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/services/cliUserConfig.ts"],"sourcesContent":["import {mkdirSync} from 'node:fs'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/services/cliUserConfig.ts"],"sourcesContent":["import {mkdirSync} from 'node:fs'\nimport {dirname, join as joinPath} from 'node:path'\n\nimport {z} from 'zod/mini'\n\nimport {debug} from '../debug.js'\nimport {getSanityConfigDir} from '../util/getSanityConfigDir.js'\nimport {readJsonFileSync} from '../util/readJsonFileSync.js'\nimport {writeJsonFileSync} from '../util/writeJsonFileSync.js'\nimport {clearCliTokenCache} from './cliTokenCache.js'\n\nconst cliUserConfigSchema = {\n authToken: z.optional(z.string()),\n}\n\n/**\n * Set the config value for the given property.\n * Validates that the passed value adheres to the defined CLI config schema.\n *\n * @param prop - The property to set the value for\n * @param value - The value to set\n * @internal\n */\nexport function setCliUserConfig(prop: 'authToken', value: string | undefined): void {\n const config = readConfig()\n const result = cliUserConfigSchema[prop].safeParse(value)\n if (!result.success) {\n const message = result.error.issues\n .map(({message, path}) => `[${path.join('.')}] ${message}`)\n .join('\\n')\n\n throw new Error(`Invalid value for config property \"${prop}\": ${message}`)\n }\n\n const configPath = getCliUserConfigPath()\n mkdirSync(dirname(configPath), {recursive: true})\n\n // When value is undefined, explicitly delete the key rather than relying\n // on JSON.stringify silently dropping undefined values.\n if (value === undefined) {\n const {[prop]: _, ...rest} = config\n writeJsonFileSync(configPath, rest, {pretty: true})\n } else {\n writeJsonFileSync(configPath, {...config, [prop]: value}, {pretty: true})\n }\n\n // Invalidate the in-process token cache so subsequent getCliToken() calls\n // pick up the new value from disk.\n clearCliTokenCache()\n}\n\n/**\n * Get the config value for the given property\n *\n * @param prop - The property to get the value for\n * @returns The value of the given property\n * @internal\n */\nexport function getCliUserConfig(prop: 'authToken'): string | undefined {\n const config = readConfig()\n const result = cliUserConfigSchema[prop].safeParse(config[prop])\n if (!result.success) {\n debug('Ignoring invalid stored value for \"%s\", returning undefined', prop)\n return undefined\n }\n\n return result.data\n}\n\n/**\n * A raw key-value store for CLI user configuration.\n * Unlike the typed `getCliUserConfig`/`setCliUserConfig`, this operates on\n * arbitrary keys without schema validation.\n *\n * @public\n */\nexport interface ConfigStore {\n /** Remove a key from the config file. */\n delete: (key: string) => void\n /** Read a value by key. Returns `undefined` if the key does not exist. */\n get: (key: string) => unknown\n /** Write a value by key, merging it into the existing config. */\n set: (key: string, value: unknown) => void\n}\n\n/**\n * Get a key-value store backed by the CLI user configuration file\n * (`~/.config/sanity/config.json`).\n *\n * Each call to `get`, `set`, or `delete` performs a full synchronous\n * read-modify-write cycle. This is intentional: sync I/O prevents\n * intra-process race conditions that occurred with the previous async\n * (configstore-backed) implementation.\n *\n * Note: there is no file-level locking, so concurrent writes from\n * separate CLI processes could still conflict. In practice this is\n * unlikely since CLI config writes are rare and user-initiated.\n *\n * @returns A {@link ConfigStore} for the CLI config file\n * @public\n */\nexport function getUserConfig(): ConfigStore {\n return {\n get(key: string): unknown {\n const config = readConfig()\n return config[key]\n },\n\n set(key: string, value: unknown): void {\n const config = readConfig()\n const configPath = getCliUserConfigPath()\n mkdirSync(dirname(configPath), {recursive: true})\n writeJsonFileSync(configPath, {...config, [key]: value}, {pretty: true})\n if (key === 'authToken') clearCliTokenCache()\n },\n\n // No mkdirSync needed: if readConfig() succeeded the directory already exists.\n delete(key: string): void {\n const config = readConfig()\n if (!(key in config)) return\n const {[key]: _, ...rest} = config\n writeJsonFileSync(getCliUserConfigPath(), rest, {pretty: true})\n if (key === 'authToken') clearCliTokenCache()\n },\n }\n}\n\n/**\n * Read the whole configuration from file system. If the file does not exist,\n * is corrupt, or otherwise unreadable, an empty object is returned. This is\n * intentional: the config only holds recoverable data (auth tokens, telemetry\n * consent) so silently resetting is preferable to blocking the user.\n *\n * @returns The whole CLI configuration.\n * @internal\n */\nfunction readConfig(): Record<string, unknown> {\n try {\n const config = readJsonFileSync(getCliUserConfigPath())\n if (!config || typeof config !== 'object' || Array.isArray(config)) {\n throw new Error('Invalid config file - expected an object')\n }\n return config\n } catch (err: unknown) {\n debug('Failed to read CLI config file: %s', err instanceof Error ? err.message : `${err}`)\n return {}\n }\n}\n\n/**\n * Get the file system location for the CLI user configuration file.\n * Takes into account the active environment (staging vs production).\n * The file is located in the user's home directory under the `.config` directory.\n *\n * @returns The path to the CLI configuration file.\n * @internal\n */\nfunction getCliUserConfigPath() {\n return process.env.SANITY_CLI_CONFIG_PATH || joinPath(getSanityConfigDir(), 'config.json')\n}\n"],"names":["mkdirSync","dirname","join","joinPath","z","debug","getSanityConfigDir","readJsonFileSync","writeJsonFileSync","clearCliTokenCache","cliUserConfigSchema","authToken","optional","string","setCliUserConfig","prop","value","config","readConfig","result","safeParse","success","message","error","issues","map","path","Error","configPath","getCliUserConfigPath","recursive","undefined","_","rest","pretty","getCliUserConfig","data","getUserConfig","get","key","set","delete","Array","isArray","err","process","env","SANITY_CLI_CONFIG_PATH"],"mappings":"AAAA,SAAQA,SAAS,QAAO,UAAS;AACjC,SAAQC,OAAO,EAAEC,QAAQC,QAAQ,QAAO,YAAW;AAEnD,SAAQ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AG,CAACC,sBAAsB,IAAI5C,SAASG,sBAAsB;AAC9E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/telemetry/getCliTelemetry.ts"],"sourcesContent":["import {ux} from '@oclif/core'\nimport {noopLogger} from '
|
|
1
|
+
{"version":3,"sources":["../../src/telemetry/getCliTelemetry.ts"],"sourcesContent":["import {ux} from '@oclif/core'\n\nimport {noopLogger} from './noopTelemetry.js'\nimport {type CLITelemetryStore} from './types.js'\n\n/**\n * @public\n * Symbol used to store CLI telemetry state on globalThis.\n * Use the accessor functions instead of accessing this directly.\n */\nexport const CLI_TELEMETRY_SYMBOL = Symbol.for('sanity.cli.telemetry')\n\ntype TraceErrorReporter = (error: Error) => void\n\ninterface CliTelemetryState {\n logger: CLITelemetryStore\n\n reportTraceError?: TraceErrorReporter\n}\n\ntype GlobalWithTelemetry = typeof globalThis & {\n [CLI_TELEMETRY_SYMBOL]?: CliTelemetryState\n}\n\nfunction getState(): CliTelemetryState | undefined {\n return (globalThis as GlobalWithTelemetry)[CLI_TELEMETRY_SYMBOL]\n}\n\n/**\n * @public\n */\nexport function getCliTelemetry(): CLITelemetryStore {\n const state = getState()\n // This should never happen, but if it does, we return a noop logger to avoid errors.\n if (!state) {\n ux.warn('CLI telemetry not initialized, returning noop logger')\n return noopLogger\n }\n\n return state.logger\n}\n\n/**\n * Sets the global CLI telemetry state.\n * @internal\n */\nexport function setCliTelemetry(\n telemetry: CLITelemetryStore,\n options?: {reportTraceError?: TraceErrorReporter},\n): void {\n ;(globalThis as GlobalWithTelemetry)[CLI_TELEMETRY_SYMBOL] = {\n logger: telemetry,\n reportTraceError: options?.reportTraceError,\n }\n}\n\n/**\n * Reports an error to the CLI command trace. Called from SanityCommand.catch()\n * for real command errors (not user aborts).\n * @internal\n */\nexport function reportCliTraceError(error: Error): void {\n getState()?.reportTraceError?.(error)\n}\n\n/**\n * Clears the global CLI telemetry store.\n * @internal\n */\nexport function clearCliTelemetry(): void {\n const global = globalThis as GlobalWithTelemetry\n delete global[CLI_TELEMETRY_SYMBOL]\n}\n"],"names":["ux","noopLogger","CLI_TELEMETRY_SYMBOL","Symbol","for","getState","globalThis","getCliTelemetry","state","warn","logger","setCliTelemetry","telemetry","options","reportTraceError","reportCliTraceError","error","clearCliTelemetry","global"],"mappings":"AAAA,SAAQA,EAAE,QAAO,cAAa;AAE9B,SAAQC,UAAU,QAAO,qBAAoB;AAG7C;;;;CAIC,GACD,OAAO,MAAMC,uBAAuBC,OAAOC,GAAG,CAAC,wBAAuB;AActE,SAASC;IACP,OAAO,AAACC,UAAkC,CAACJ,qBAAqB;AAClE;AAEA;;CAEC,GACD,OAAO,SAASK;IACd,MAAMC,QAAQH;IACd,qFAAqF;IACrF,IAAI,CAACG,OAAO;QACVR,GAAGS,IAAI,CAAC;QACR,OAAOR;IACT;IAEA,OAAOO,MAAME,MAAM;AACrB;AAEA;;;CAGC,GACD,OAAO,SAASC,gBACdC,SAA4B,EAC5BC,OAAiD;;IAE/CP,UAAkC,CAACJ,qBAAqB,GAAG;QAC3DQ,QAAQE;QACRE,kBAAkBD,SAASC;IAC7B;AACF;AAEA;;;;CAIC,GACD,OAAO,SAASC,oBAAoBC,KAAY;IAC9CX,YAAYS,mBAAmBE;AACjC;AAEA;;;CAGC,GACD,OAAO,SAASC;IACd,MAAMC,SAASZ;IACf,OAAOY,MAAM,CAAChB,qBAAqB;AACrC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Inline noop implementation — avoids a runtime dependency on @sanity/telemetry
|
|
2
|
+
// (types-only usage keeps it as a devDependency). Explicit types ensure this
|
|
3
|
+
// stays structurally in sync with TelemetryLogger/TelemetryTrace.
|
|
4
|
+
const noopTrace = {
|
|
5
|
+
await: (promise)=>promise,
|
|
6
|
+
complete: ()=>{},
|
|
7
|
+
error: ()=>{},
|
|
8
|
+
log: ()=>{},
|
|
9
|
+
newContext: ()=>noopLogger,
|
|
10
|
+
start: ()=>{}
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Fallback logger used when telemetry has not been initialized.
|
|
14
|
+
* Exported for use in tests only — do not use in plugins or external code.
|
|
15
|
+
* @internal
|
|
16
|
+
*/ export const noopLogger = {
|
|
17
|
+
log: ()=>{},
|
|
18
|
+
resume: ()=>{},
|
|
19
|
+
trace: ()=>noopTrace,
|
|
20
|
+
updateUserProperties: ()=>{}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=noopTelemetry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/telemetry/noopTelemetry.ts"],"sourcesContent":["import {type TelemetryTrace} from '@sanity/telemetry'\n\nimport {type CLITelemetryStore, type TelemetryUserProperties} from './types.js'\n\n// Inline noop implementation — avoids a runtime dependency on @sanity/telemetry\n// (types-only usage keeps it as a devDependency). Explicit types ensure this\n// stays structurally in sync with TelemetryLogger/TelemetryTrace.\nconst noopTrace: TelemetryTrace<TelemetryUserProperties, never> = {\n await: <P extends Promise<unknown>>(promise: P): P => promise,\n complete: () => {},\n error: () => {},\n log: () => {},\n newContext: (): CLITelemetryStore => noopLogger,\n start: () => {},\n}\n\n/**\n * Fallback logger used when telemetry has not been initialized.\n * Exported for use in tests only — do not use in plugins or external code.\n * @internal\n */\nexport const noopLogger: CLITelemetryStore = {\n log: () => {},\n resume: () => {},\n trace: () => noopTrace,\n updateUserProperties: () => {},\n}\n"],"names":["noopTrace","await","promise","complete","error","log","newContext","noopLogger","start","resume","trace","updateUserProperties"],"mappings":"AAIA,gFAAgF;AAChF,6EAA6E;AAC7E,kEAAkE;AAClE,MAAMA,YAA4D;IAChEC,OAAO,CAA6BC,UAAkBA;IACtDC,UAAU,KAAO;IACjBC,OAAO,KAAO;IACdC,KAAK,KAAO;IACZC,YAAY,IAAyBC;IACrCC,OAAO,KAAO;AAChB;AAEA;;;;CAIC,GACD,OAAO,MAAMD,aAAgC;IAC3CF,KAAK,KAAO;IACZI,QAAQ,KAAO;IACfC,OAAO,IAAMV;IACbW,sBAAsB,KAAO;AAC/B,EAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { homedir } from 'node:os';
|
|
2
|
+
import { join as joinPath } from 'node:path';
|
|
3
|
+
import { isStaging } from './isStaging.js';
|
|
4
|
+
function envSuffix() {
|
|
5
|
+
return isStaging() ? '-staging' : '';
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Returns the base Sanity configuration directory for the current user.
|
|
9
|
+
* For persistent user settings (auth tokens, preferences, etc.).
|
|
10
|
+
* Respects `SANITY_INTERNAL_ENV=staging` to isolate staging instances.
|
|
11
|
+
*
|
|
12
|
+
* Layout: `~/.config/sanity{-staging}/`
|
|
13
|
+
*
|
|
14
|
+
* @returns Absolute path to the config directory
|
|
15
|
+
* @internal
|
|
16
|
+
*/ export function getSanityConfigDir() {
|
|
17
|
+
return joinPath(homedir(), '.config', `sanity${envSuffix()}`);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Returns the base Sanity data directory for the current user.
|
|
21
|
+
* For ephemeral runtime state (dev-server registries, caches, etc.).
|
|
22
|
+
* Respects `SANITY_INTERNAL_ENV=staging` to isolate staging instances.
|
|
23
|
+
*
|
|
24
|
+
* Layout: `~/.sanity{-staging}/`
|
|
25
|
+
*
|
|
26
|
+
* @returns Absolute path to the data directory
|
|
27
|
+
* @internal
|
|
28
|
+
*/ export function getSanityDataDir() {
|
|
29
|
+
return joinPath(homedir(), `.sanity${envSuffix()}`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=getSanityConfigDir.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/util/getSanityConfigDir.ts"],"sourcesContent":["import {homedir} from 'node:os'\nimport {join as joinPath} from 'node:path'\n\nimport {isStaging} from './isStaging.js'\n\nfunction envSuffix(): string {\n return isStaging() ? '-staging' : ''\n}\n\n/**\n * Returns the base Sanity configuration directory for the current user.\n * For persistent user settings (auth tokens, preferences, etc.).\n * Respects `SANITY_INTERNAL_ENV=staging` to isolate staging instances.\n *\n * Layout: `~/.config/sanity{-staging}/`\n *\n * @returns Absolute path to the config directory\n * @internal\n */\nexport function getSanityConfigDir(): string {\n return joinPath(homedir(), '.config', `sanity${envSuffix()}`)\n}\n\n/**\n * Returns the base Sanity data directory for the current user.\n * For ephemeral runtime state (dev-server registries, caches, etc.).\n * Respects `SANITY_INTERNAL_ENV=staging` to isolate staging instances.\n *\n * Layout: `~/.sanity{-staging}/`\n *\n * @returns Absolute path to the data directory\n * @internal\n */\nexport function getSanityDataDir(): string {\n return joinPath(homedir(), `.sanity${envSuffix()}`)\n}\n"],"names":["homedir","join","joinPath","isStaging","envSuffix","getSanityConfigDir","getSanityDataDir"],"mappings":"AAAA,SAAQA,OAAO,QAAO,UAAS;AAC/B,SAAQC,QAAQC,QAAQ,QAAO,YAAW;AAE1C,SAAQC,SAAS,QAAO,iBAAgB;AAExC,SAASC;IACP,OAAOD,cAAc,aAAa;AACpC;AAEA;;;;;;;;;CASC,GACD,OAAO,SAASE;IACd,OAAOH,SAASF,WAAW,WAAW,CAAC,MAAM,EAAEI,aAAa;AAC9D;AAEA;;;;;;;;;CASC,GACD,OAAO,SAASE;IACd,OAAOJ,SAASF,WAAW,CAAC,OAAO,EAAEI,aAAa;AACpD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/cli-core",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-20260416133835",
|
|
4
4
|
"description": "Sanity CLI core package",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -52,16 +52,16 @@
|
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@inquirer/prompts": "^8.3.0",
|
|
55
|
-
"@oclif/core": "^4.10.
|
|
55
|
+
"@oclif/core": "^4.10.5",
|
|
56
56
|
"@rexxars/jiti": "^2.6.2",
|
|
57
|
-
"@sanity/client": "^7.
|
|
57
|
+
"@sanity/client": "^7.21.0",
|
|
58
58
|
"babel-plugin-react-compiler": "^1.0.0",
|
|
59
59
|
"boxen": "^8.0.1",
|
|
60
60
|
"debug": "^4.4.3",
|
|
61
61
|
"get-it": "^8.7.0",
|
|
62
62
|
"get-tsconfig": "^4.13.7",
|
|
63
63
|
"import-meta-resolve": "^4.2.0",
|
|
64
|
-
"jsdom": "^29.0.
|
|
64
|
+
"jsdom": "^29.0.2",
|
|
65
65
|
"json-lexer": "^1.2.0",
|
|
66
66
|
"log-symbols": "^7.0.1",
|
|
67
67
|
"ora": "^9.0.0",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@eslint/compat": "^2.0.3",
|
|
77
|
-
"@sanity/pkg-utils": "^10.4.
|
|
77
|
+
"@sanity/pkg-utils": "^10.4.14",
|
|
78
78
|
"@sanity/telemetry": "^0.9.0",
|
|
79
79
|
"@swc/cli": "^0.8.1",
|
|
80
80
|
"@swc/core": "^1.15.24",
|
|
@@ -83,16 +83,13 @@
|
|
|
83
83
|
"@types/node": "^20.19.39",
|
|
84
84
|
"eslint": "^10.1.0",
|
|
85
85
|
"publint": "^0.3.18",
|
|
86
|
-
"sanity": "^5.
|
|
86
|
+
"sanity": "^5.20.0",
|
|
87
87
|
"typescript": "^5.9.3",
|
|
88
88
|
"vitest": "^4.1.2",
|
|
89
89
|
"@repo/package.config": "0.0.1",
|
|
90
90
|
"@repo/tsconfig": "3.70.0",
|
|
91
91
|
"@sanity/eslint-config-cli": "1.1.0"
|
|
92
92
|
},
|
|
93
|
-
"peerDependencies": {
|
|
94
|
-
"@sanity/telemetry": ">=0.9.0 <0.10.0"
|
|
95
|
-
},
|
|
96
93
|
"engines": {
|
|
97
94
|
"node": ">=20.19.1 <22 || >=22.12"
|
|
98
95
|
},
|