@sanity/cli-core 0.1.0-alpha.8 → 1.0.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.
- package/dist/SanityCommand.js +88 -5
- package/dist/SanityCommand.js.map +1 -1
- package/dist/_exports/request.d.ts +77 -0
- package/dist/_exports/request.js +7 -0
- package/dist/_exports/request.js.map +1 -0
- package/dist/_exports/ux.d.ts +75 -4
- package/dist/_exports/ux.js +2 -1
- package/dist/_exports/ux.js.map +1 -1
- package/dist/config/cli/getCliConfig.js +33 -33
- package/dist/config/cli/getCliConfig.js.map +1 -1
- package/dist/config/cli/getCliConfigSync.js +1 -1
- package/dist/config/cli/getCliConfigSync.js.map +1 -1
- package/dist/config/cli/schemas.js +7 -0
- package/dist/config/cli/schemas.js.map +1 -1
- package/dist/config/cli/types/cliConfig.js.map +1 -1
- package/dist/config/findProjectRoot.js +8 -4
- package/dist/config/findProjectRoot.js.map +1 -1
- package/dist/config/findProjectRootSync.js +7 -3
- package/dist/config/findProjectRootSync.js.map +1 -1
- package/dist/config/studio/getStudioConfig.js +0 -3
- package/dist/config/studio/getStudioConfig.js.map +1 -1
- package/dist/config/studio/getStudioWorkspaces.js +63 -0
- package/dist/config/studio/getStudioWorkspaces.js.map +1 -0
- package/dist/config/studio/isStudioConfig.js +19 -0
- package/dist/config/studio/isStudioConfig.js.map +1 -0
- package/dist/config/studio/readStudioConfig.worker.js +8 -34
- package/dist/config/studio/readStudioConfig.worker.js.map +1 -1
- package/dist/config/util/findStudioConfigPath.js +24 -3
- package/dist/config/util/findStudioConfigPath.js.map +1 -1
- package/dist/config/util/recursivelyResolveProjectRoot.js.map +1 -1
- package/dist/errors/NonInteractiveError.js +18 -0
- package/dist/errors/NonInteractiveError.js.map +1 -0
- package/dist/{util → errors}/NotFoundError.js +1 -1
- package/dist/errors/NotFoundError.js.map +1 -0
- package/dist/errors/ProjectRootNotFoundError.js +35 -0
- package/dist/errors/ProjectRootNotFoundError.js.map +1 -0
- package/dist/index.d.ts +1247 -36
- package/dist/index.js +14 -9
- package/dist/index.js.map +1 -1
- package/dist/loaders/studio/studioWorkerLoader.worker.js +102 -23
- package/dist/loaders/studio/studioWorkerLoader.worker.js.map +1 -1
- package/dist/loaders/studio/studioWorkerTask.js +55 -34
- package/dist/loaders/studio/studioWorkerTask.js.map +1 -1
- package/dist/loaders/tsx/tsxWorkerLoader.worker.js +3 -4
- package/dist/loaders/tsx/tsxWorkerLoader.worker.js.map +1 -1
- package/dist/loaders/tsx/tsxWorkerTask.js +4 -31
- package/dist/loaders/tsx/tsxWorkerTask.js.map +1 -1
- package/dist/request/createRequester.js +83 -0
- package/dist/request/createRequester.js.map +1 -0
- package/dist/services/apiClient.js +8 -4
- package/dist/services/apiClient.js.map +1 -1
- package/dist/services/cliUserConfig.js +5 -5
- package/dist/services/cliUserConfig.js.map +1 -1
- package/dist/services/getCliToken.js +2 -2
- package/dist/services/getCliToken.js.map +1 -1
- package/dist/telemetry/getTelemetryBaseInfo.js +33 -0
- package/dist/telemetry/getTelemetryBaseInfo.js.map +1 -0
- package/dist/telemetry/types.js +5 -0
- package/dist/telemetry/types.js.map +1 -0
- package/dist/util/doImport.js +2 -1
- package/dist/util/doImport.js.map +1 -1
- package/dist/util/environment/mockBrowserEnvironment.js +1 -0
- package/dist/util/environment/mockBrowserEnvironment.js.map +1 -1
- package/dist/util/getCliTelemetry.js +34 -0
- package/dist/util/getCliTelemetry.js.map +1 -0
- package/dist/util/getSanityUrl.js +4 -3
- package/dist/util/getSanityUrl.js.map +1 -1
- package/dist/util/importModule.js +32 -0
- package/dist/util/importModule.js.map +1 -0
- package/dist/util/isInteractive.js +1 -1
- package/dist/util/isInteractive.js.map +1 -1
- package/dist/util/isStaging.js +10 -0
- package/dist/util/isStaging.js.map +1 -0
- package/dist/util/normalizePath.js +12 -0
- package/dist/util/normalizePath.js.map +1 -0
- package/dist/util/promisifyWorker.js +72 -0
- package/dist/util/promisifyWorker.js.map +1 -0
- package/dist/util/readNDJSON.js +18 -0
- package/dist/util/readNDJSON.js.map +1 -0
- package/dist/util/readPackageJson.js +74 -0
- package/dist/util/readPackageJson.js.map +1 -0
- package/dist/ux/boxen.js +3 -0
- package/dist/ux/boxen.js.map +1 -0
- package/dist/ux/colorizeJson.js +6 -6
- package/dist/ux/colorizeJson.js.map +1 -1
- package/dist/ux/prompts.js +49 -1
- package/dist/ux/prompts.js.map +1 -1
- package/package.json +39 -31
- package/dist/SanityCommand.d.ts +0 -78
- package/dist/_exports/tree.d.ts +0 -1
- package/dist/_exports/tree.js +0 -3
- package/dist/_exports/tree.js.map +0 -1
- package/dist/config/cli/getCliConfig.d.ts +0 -16
- package/dist/config/cli/getCliConfig.worker.d.ts +0 -1
- package/dist/config/cli/getCliConfig.worker.js +0 -15
- package/dist/config/cli/getCliConfig.worker.js.map +0 -1
- package/dist/config/cli/getCliConfigSync.d.ts +0 -12
- package/dist/config/cli/schemas.d.ts +0 -104
- package/dist/config/cli/types/cliConfig.d.ts +0 -83
- package/dist/config/cli/types/userViteConfig.d.ts +0 -5
- package/dist/config/findProjectRoot.d.ts +0 -14
- package/dist/config/findProjectRootSync.d.ts +0 -27
- package/dist/config/studio/getStudioConfig.d.ts +0 -14
- package/dist/config/studio/readStudioConfig.d.ts +0 -96
- package/dist/config/studio/readStudioConfig.worker.d.ts +0 -1
- package/dist/config/util/configPathsSync.d.ts +0 -17
- package/dist/config/util/findAppConfigPath.d.ts +0 -8
- package/dist/config/util/findConfigsPaths.d.ts +0 -16
- package/dist/config/util/findStudioConfigPath.d.ts +0 -9
- package/dist/config/util/isSanityV2StudioRoot.d.ts +0 -8
- package/dist/config/util/recursivelyResolveProjectRoot.d.ts +0 -27
- package/dist/debug.d.ts +0 -15
- package/dist/loaders/studio/studioWorkerLoader.worker.d.ts +0 -1
- package/dist/loaders/studio/studioWorkerTask.d.ts +0 -40
- package/dist/loaders/tsx/tsxWorkerLoader.worker.d.ts +0 -1
- package/dist/loaders/tsx/tsxWorkerTask.d.ts +0 -28
- package/dist/services/apiClient.d.ts +0 -53
- package/dist/services/cliUserConfig.d.ts +0 -40
- package/dist/services/getCliToken.d.ts +0 -7
- package/dist/types.d.ts +0 -15
- package/dist/util/NotFoundError.d.ts +0 -20
- package/dist/util/NotFoundError.js.map +0 -1
- package/dist/util/createExpiringConfig.d.ts +0 -37
- package/dist/util/createExpiringConfig.js +0 -60
- package/dist/util/createExpiringConfig.js.map +0 -1
- package/dist/util/doImport.d.ts +0 -7
- package/dist/util/environment/getStudioEnvironmentVariables.d.ts +0 -12
- package/dist/util/environment/mockBrowserEnvironment.d.ts +0 -17
- package/dist/util/environment/setupBrowserStubs.d.ts +0 -10
- package/dist/util/environment/stubs.d.ts +0 -254
- package/dist/util/fileExists.d.ts +0 -9
- package/dist/util/generateHelpUrl.d.ts +0 -8
- package/dist/util/getEmptyAuth.d.ts +0 -5
- package/dist/util/getSanityEnvVar.d.ts +0 -19
- package/dist/util/getSanityUrl.d.ts +0 -5
- package/dist/util/getUserConfig.d.ts +0 -2
- package/dist/util/isCi.d.ts +0 -1
- package/dist/util/isInteractive.d.ts +0 -1
- package/dist/util/isRecord.d.ts +0 -8
- package/dist/util/isTrueish.d.ts +0 -1
- package/dist/util/parseStringFlag.d.ts +0 -10
- package/dist/util/parseStringFlag.js +0 -19
- package/dist/util/parseStringFlag.js.map +0 -1
- package/dist/util/readJsonFile.d.ts +0 -14
- package/dist/util/resolveLocalPackage.d.ts +0 -18
- package/dist/util/safeStructuredClone.d.ts +0 -8
- package/dist/util/tree.d.ts +0 -31
- package/dist/util/tree.js +0 -108
- package/dist/util/tree.js.map +0 -1
- package/dist/util/tryGetDefaultExport.d.ts +0 -5
- package/dist/util/writeJsonFile.d.ts +0 -9
- package/dist/ux/chalk.d.ts +0 -2
- package/dist/ux/chalk.js +0 -4
- package/dist/ux/chalk.js.map +0 -1
- package/dist/ux/colorizeJson.d.ts +0 -1
- package/dist/ux/formatObject.d.ts +0 -1
- package/dist/ux/formatObject.js +0 -9
- package/dist/ux/formatObject.js.map +0 -1
- package/dist/ux/logSymbols.d.ts +0 -1
- package/dist/ux/printKeyValue.d.ts +0 -1
- package/dist/ux/printKeyValue.js +0 -16
- package/dist/ux/printKeyValue.js.map +0 -1
- package/dist/ux/prompts.d.ts +0 -1
- package/dist/ux/spinner.d.ts +0 -1
- package/dist/ux/timer.d.ts +0 -12
package/dist/SanityCommand.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { Command } from '@oclif/core';
|
|
2
2
|
import { getCliConfig } from './config/cli/getCliConfig.js';
|
|
3
3
|
import { findProjectRoot } from './config/findProjectRoot.js';
|
|
4
|
+
import { subdebug } from './debug.js';
|
|
5
|
+
import { NonInteractiveError } from './errors/NonInteractiveError.js';
|
|
6
|
+
import { ProjectRootNotFoundError } from './errors/ProjectRootNotFoundError.js';
|
|
4
7
|
import { getGlobalCliClient, getProjectCliClient } from './services/apiClient.js';
|
|
8
|
+
import { getCliTelemetry } from './util/getCliTelemetry.js';
|
|
5
9
|
import { isInteractive } from './util/isInteractive.js';
|
|
10
|
+
const debug = subdebug('sanityCommand');
|
|
6
11
|
export class SanityCommand extends Command {
|
|
7
12
|
args;
|
|
8
13
|
flags;
|
|
@@ -37,20 +42,82 @@ export class SanityCommand extends Command {
|
|
|
37
42
|
warn: this.warn.bind(this)
|
|
38
43
|
};
|
|
39
44
|
/**
|
|
45
|
+
* The telemetry store.
|
|
46
|
+
*
|
|
47
|
+
* @returns The telemetry store.
|
|
48
|
+
*/ telemetry;
|
|
49
|
+
/**
|
|
40
50
|
* Get the CLI config.
|
|
41
51
|
*
|
|
42
52
|
* @returns The CLI config.
|
|
43
53
|
*/ async getCliConfig() {
|
|
44
54
|
const root = await this.getProjectRoot();
|
|
55
|
+
debug(`Using project root`, root);
|
|
45
56
|
return getCliConfig(root.directory);
|
|
46
57
|
}
|
|
47
58
|
/**
|
|
48
|
-
* Get the project ID from the CLI config.
|
|
59
|
+
* Get the project ID from passed flags or (if not provided) the CLI config.
|
|
60
|
+
*
|
|
61
|
+
* Optionally accepts a `fallback` function that is called when no project ID
|
|
62
|
+
* can be determined from flags or config. This allows commands to provide
|
|
63
|
+
* interactive project selection while keeping the prompt logic in the CLI package.
|
|
64
|
+
*
|
|
65
|
+
* If the fallback throws a `NonInteractiveError` (e.g. because the terminal is
|
|
66
|
+
* not interactive), it falls through to the standard error with suggestions.
|
|
67
|
+
*
|
|
68
|
+
* Optionally accepts a `deprecatedFlagName` for commands that have a deprecated
|
|
69
|
+
* flag (e.g. `--project`) that should be checked after `--project-id` but before
|
|
70
|
+
* the CLI config.
|
|
49
71
|
*
|
|
50
|
-
* @returns The project ID
|
|
51
|
-
*/ async getProjectId() {
|
|
52
|
-
const
|
|
53
|
-
|
|
72
|
+
* @returns The project ID.
|
|
73
|
+
*/ async getProjectId(options) {
|
|
74
|
+
const hasProjectFlag = this.ctor.flags != null && 'project-id' in this.ctor.flags;
|
|
75
|
+
// Check --project-id flag first
|
|
76
|
+
if (hasProjectFlag) {
|
|
77
|
+
const flagProjectId = 'project-id' in this.flags && typeof this.flags['project-id'] === 'string' ? this.flags['project-id'] : undefined;
|
|
78
|
+
if (flagProjectId) return flagProjectId;
|
|
79
|
+
}
|
|
80
|
+
// Check deprecated flag (e.g. --project) before CLI config
|
|
81
|
+
if (options?.deprecatedFlagName) {
|
|
82
|
+
const deprecatedValue = options.deprecatedFlagName in this.flags && typeof this.flags[options.deprecatedFlagName] === 'string' ? this.flags[options.deprecatedFlagName] : undefined;
|
|
83
|
+
if (deprecatedValue) return deprecatedValue;
|
|
84
|
+
}
|
|
85
|
+
// Fall back to CLI config
|
|
86
|
+
try {
|
|
87
|
+
const config = await this.getCliConfig();
|
|
88
|
+
const configProjectId = config.api?.projectId;
|
|
89
|
+
if (configProjectId) return configProjectId;
|
|
90
|
+
} catch (err) {
|
|
91
|
+
if (!(err instanceof ProjectRootNotFoundError)) throw err;
|
|
92
|
+
// No project root — fall through to fallback/error
|
|
93
|
+
}
|
|
94
|
+
// Offer interactive selection if a fallback was provided
|
|
95
|
+
if (options?.fallback) {
|
|
96
|
+
try {
|
|
97
|
+
return await options.fallback();
|
|
98
|
+
} catch (err) {
|
|
99
|
+
if (!(err instanceof NonInteractiveError)) throw err;
|
|
100
|
+
// Non-interactive: throw with actionable suggestions
|
|
101
|
+
throw new ProjectRootNotFoundError('Unable to determine project ID', {
|
|
102
|
+
cause: err,
|
|
103
|
+
suggestions: [
|
|
104
|
+
...hasProjectFlag ? [
|
|
105
|
+
'Providing a project ID: --project-id <project-id>'
|
|
106
|
+
] : [],
|
|
107
|
+
'Running this command from within a Sanity project directory',
|
|
108
|
+
'Running in an interactive terminal to get a project selection prompt'
|
|
109
|
+
]
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
throw new ProjectRootNotFoundError('Unable to determine project ID', {
|
|
114
|
+
suggestions: [
|
|
115
|
+
...hasProjectFlag ? [
|
|
116
|
+
'Providing a project ID: --project-id <project-id>'
|
|
117
|
+
] : [],
|
|
118
|
+
'Running this command from within a Sanity project directory'
|
|
119
|
+
]
|
|
120
|
+
});
|
|
54
121
|
}
|
|
55
122
|
/**
|
|
56
123
|
* Get the project's root directory by resolving the config
|
|
@@ -69,6 +136,7 @@ export class SanityCommand extends Command {
|
|
|
69
136
|
});
|
|
70
137
|
this.args = args;
|
|
71
138
|
this.flags = flags;
|
|
139
|
+
this.telemetry = getCliTelemetry();
|
|
72
140
|
await super.init();
|
|
73
141
|
}
|
|
74
142
|
/**
|
|
@@ -91,6 +159,21 @@ export class SanityCommand extends Command {
|
|
|
91
159
|
*/ resolveIsInteractive() {
|
|
92
160
|
return isInteractive();
|
|
93
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
* Get the CLI config, returning an empty config if no project root is found.
|
|
164
|
+
*
|
|
165
|
+
* Use this instead of `getCliConfig()` in commands that can operate without a
|
|
166
|
+
* project directory (e.g. when `--project-id` and `--dataset` flags are provided).
|
|
167
|
+
*
|
|
168
|
+
* @returns The CLI config, or an empty config object if no project root is found.
|
|
169
|
+
*/ async tryGetCliConfig() {
|
|
170
|
+
try {
|
|
171
|
+
return await this.getCliConfig();
|
|
172
|
+
} catch (err) {
|
|
173
|
+
if (!(err instanceof ProjectRootNotFoundError)) throw err;
|
|
174
|
+
return {};
|
|
175
|
+
}
|
|
176
|
+
}
|
|
94
177
|
}
|
|
95
178
|
|
|
96
179
|
//# sourceMappingURL=SanityCommand.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/SanityCommand.ts"],"sourcesContent":["import {Command, Interfaces} from '@oclif/core'\n\nimport {getCliConfig} from './config/cli/getCliConfig.js'\nimport {type CliConfig} from './config/cli/types/cliConfig.js'\nimport {findProjectRoot} from './config/findProjectRoot.js'\nimport {type ProjectRootResult} from './config/util/recursivelyResolveProjectRoot.js'\nimport {\n getGlobalCliClient,\n getProjectCliClient,\n type GlobalCliClientOptions,\n type ProjectCliClientOptions,\n} from './services/apiClient.js'\nimport {type Output} from './types.js'\nimport {isInteractive} from './util/isInteractive.js'\n\ntype Flags<T extends typeof Command> = Interfaces.InferredFlags<\n (typeof SanityCommand)['baseFlags'] & T['flags']\n>\n\ntype Args<T extends typeof Command> = Interfaces.InferredArgs<T['args']>\n\nexport abstract class SanityCommand<T extends typeof Command> extends Command {\n protected args!: Args<T>\n protected flags!: Flags<T>\n\n /**\n * Get the global API client.\n *\n * @param args - The global API client options.\n * @returns The global API client.\n *\n * @deprecated use `getGlobalCliClient` function directly instead.\n */\n protected getGlobalApiClient = (args: GlobalCliClientOptions) => getGlobalCliClient(args)\n\n /**\n * Get the project API client.\n *\n * @param args - The project API client options.\n * @returns The project API client.\n *\n * @deprecated use `getProjectCliClient` function directly instead.\n */\n protected getProjectApiClient = (args: ProjectCliClientOptions) => getProjectCliClient(args)\n\n /**\n * Helper for outputting to the console.\n *\n * @example\n * ```ts\n * this.output.log('Hello')\n * this.output.warn('Warning')\n * this.output.error('Error')\n * ```\n */\n protected output: Output = {\n error: this.error.bind(this),\n log: this.log.bind(this),\n warn: this.warn.bind(this),\n }\n\n /**\n * Get the CLI config.\n *\n * @returns The CLI config.\n */\n protected async getCliConfig(): Promise<CliConfig> {\n const root = await this.getProjectRoot()\n\n return getCliConfig(root.directory)\n }\n\n /**\n * Get the project ID from the CLI config.\n *\n * @returns The project ID or `undefined` if it's not set.\n */\n protected async getProjectId(): Promise<string | undefined> {\n const config = await this.getCliConfig()\n\n return config.api?.projectId\n }\n\n /**\n * Get the project's root directory by resolving the config\n *\n * @returns The project root result.\n */\n protected getProjectRoot(): Promise<ProjectRootResult> {\n return findProjectRoot(process.cwd())\n }\n\n public async init(): Promise<void> {\n const {args, flags} = await this.parse({\n args: this.ctor.args,\n baseFlags: (super.ctor as typeof SanityCommand).baseFlags,\n enableJsonFlag: this.ctor.enableJsonFlag,\n flags: this.ctor.flags,\n strict: this.ctor.strict,\n })\n\n this.args = args as Args<T>\n this.flags = flags as Flags<T>\n\n await super.init()\n }\n\n /**\n * Check if the command is running in unattended mode.\n *\n * This means the command should not ask for user input, instead using defaults where\n * possible, and if that does not make sense (eg there's missing information), then we\n * should error out (remember to exit with a non-zero code).\n *\n * Most commands should take an explicit `--yes` flag to enable unattended mode, but\n * some commands may also be run in unattended mode if `process.stdin` is not a TTY\n * (eg when running in a CI environment).\n */\n protected isUnattended(): boolean {\n return this.flags.yes || !this.resolveIsInteractive()\n }\n\n /**\n * Resolver for checking if the terminal is interactive. Override in tests to provide mock values.\n *\n * @returns Whether the terminal is interactive.\n */\n protected resolveIsInteractive(): boolean {\n return isInteractive()\n }\n}\n"],"names":["Command","getCliConfig","findProjectRoot","getGlobalCliClient","getProjectCliClient","isInteractive","SanityCommand","args","flags","getGlobalApiClient","getProjectApiClient","output","error","bind","log","warn","root","getProjectRoot","directory","getProjectId","config","api","projectId","process","cwd","init","parse","ctor","baseFlags","enableJsonFlag","strict","isUnattended","yes","resolveIsInteractive"],"mappings":"AAAA,SAAQA,OAAO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,IAAI,CAACG,MAAM;QAC1B;QAEA,IAAI,CAACvB,IAAI,GAAGA;QACZ,IAAI,CAACC,KAAK,GAAGA;QAEb,MAAM,KAAK,CAACiB;IACd;IAEA;;;;;;;;;;GAUC,GACD,AAAUM,eAAwB;QAChC,OAAO,IAAI,CAACvB,KAAK,CAACwB,GAAG,IAAI,CAAC,IAAI,CAACC,oBAAoB;IACrD;IAEA;;;;GAIC,GACD,AAAUA,uBAAgC;QACxC,OAAO5B;IACT;AACF"}
|
|
1
|
+
{"version":3,"sources":["../src/SanityCommand.ts"],"sourcesContent":["import {Command, Interfaces} from '@oclif/core'\n\nimport {getCliConfig} from './config/cli/getCliConfig.js'\nimport {type CliConfig} from './config/cli/types/cliConfig.js'\nimport {findProjectRoot} from './config/findProjectRoot.js'\nimport {type ProjectRootResult} from './config/util/recursivelyResolveProjectRoot.js'\nimport {subdebug} from './debug.js'\nimport {NonInteractiveError} from './errors/NonInteractiveError.js'\nimport {ProjectRootNotFoundError} from './errors/ProjectRootNotFoundError.js'\nimport {\n getGlobalCliClient,\n getProjectCliClient,\n type GlobalCliClientOptions,\n type ProjectCliClientOptions,\n} from './services/apiClient.js'\nimport {type CLITelemetryStore} from './telemetry/types.js'\nimport {type Output} from './types.js'\nimport {getCliTelemetry} from './util/getCliTelemetry.js'\nimport {isInteractive} from './util/isInteractive.js'\n\ntype Flags<T extends typeof Command> = Interfaces.InferredFlags<\n (typeof SanityCommand)['baseFlags'] & T['flags']\n>\n\ntype Args<T extends typeof Command> = Interfaces.InferredArgs<T['args']>\n\nconst debug = subdebug('sanityCommand')\n\nexport abstract class SanityCommand<T extends typeof Command> extends Command {\n protected args!: Args<T>\n protected flags!: Flags<T>\n\n /**\n * Get the global API client.\n *\n * @param args - The global API client options.\n * @returns The global API client.\n *\n * @deprecated use `getGlobalCliClient` function directly instead.\n */\n protected getGlobalApiClient = (args: GlobalCliClientOptions) => getGlobalCliClient(args)\n\n /**\n * Get the project API client.\n *\n * @param args - The project API client options.\n * @returns The project API client.\n *\n * @deprecated use `getProjectCliClient` function directly instead.\n */\n protected getProjectApiClient = (args: ProjectCliClientOptions) => getProjectCliClient(args)\n\n /**\n * Helper for outputting to the console.\n *\n * @example\n * ```ts\n * this.output.log('Hello')\n * this.output.warn('Warning')\n * this.output.error('Error')\n * ```\n */\n protected output: Output = {\n error: this.error.bind(this),\n log: this.log.bind(this),\n warn: this.warn.bind(this),\n }\n\n /**\n * The telemetry store.\n *\n * @returns The telemetry store.\n */\n protected telemetry!: CLITelemetryStore\n\n /**\n * Get the CLI config.\n *\n * @returns The CLI config.\n */\n protected async getCliConfig(): Promise<CliConfig> {\n const root = await this.getProjectRoot()\n\n debug(`Using project root`, root)\n return getCliConfig(root.directory)\n }\n\n /**\n * Get the project ID from passed flags or (if not provided) the CLI config.\n *\n * Optionally accepts a `fallback` function that is called when no project ID\n * can be determined from flags or config. This allows commands to provide\n * interactive project selection while keeping the prompt logic in the CLI package.\n *\n * If the fallback throws a `NonInteractiveError` (e.g. because the terminal is\n * not interactive), it falls through to the standard error with suggestions.\n *\n * Optionally accepts a `deprecatedFlagName` for commands that have a deprecated\n * flag (e.g. `--project`) that should be checked after `--project-id` but before\n * the CLI config.\n *\n * @returns The project ID.\n */\n protected async getProjectId(options?: {\n deprecatedFlagName?: string\n fallback?: () => Promise<string>\n }): Promise<string> {\n const hasProjectFlag = this.ctor.flags != null && 'project-id' in this.ctor.flags\n\n // Check --project-id flag first\n if (hasProjectFlag) {\n const flagProjectId =\n 'project-id' in this.flags && typeof this.flags['project-id'] === 'string'\n ? this.flags['project-id']\n : undefined\n\n if (flagProjectId) return flagProjectId\n }\n\n // Check deprecated flag (e.g. --project) before CLI config\n if (options?.deprecatedFlagName) {\n const deprecatedValue =\n options.deprecatedFlagName in this.flags &&\n typeof this.flags[options.deprecatedFlagName] === 'string'\n ? (this.flags[options.deprecatedFlagName] as string)\n : undefined\n\n if (deprecatedValue) return deprecatedValue\n }\n\n // Fall back to CLI config\n try {\n const config = await this.getCliConfig()\n const configProjectId = config.api?.projectId\n if (configProjectId) return configProjectId\n } catch (err) {\n if (!(err instanceof ProjectRootNotFoundError)) throw err\n // No project root — fall through to fallback/error\n }\n\n // Offer interactive selection if a fallback was provided\n if (options?.fallback) {\n try {\n return await options.fallback()\n } catch (err) {\n if (!(err instanceof NonInteractiveError)) throw err\n // Non-interactive: throw with actionable suggestions\n throw new ProjectRootNotFoundError('Unable to determine project ID', {\n cause: err,\n suggestions: [\n ...(hasProjectFlag ? ['Providing a project ID: --project-id <project-id>'] : []),\n 'Running this command from within a Sanity project directory',\n 'Running in an interactive terminal to get a project selection prompt',\n ],\n })\n }\n }\n\n throw new ProjectRootNotFoundError('Unable to determine project ID', {\n suggestions: [\n ...(hasProjectFlag ? ['Providing a project ID: --project-id <project-id>'] : []),\n 'Running this command from within a Sanity project directory',\n ],\n })\n }\n\n /**\n * Get the project's root directory by resolving the config\n *\n * @returns The project root result.\n */\n protected getProjectRoot(): Promise<ProjectRootResult> {\n return findProjectRoot(process.cwd())\n }\n\n public async init(): Promise<void> {\n const {args, flags} = await this.parse({\n args: this.ctor.args,\n baseFlags: (super.ctor as typeof SanityCommand).baseFlags,\n enableJsonFlag: this.ctor.enableJsonFlag,\n flags: this.ctor.flags,\n strict: this.ctor.strict,\n })\n\n this.args = args as Args<T>\n this.flags = flags as Flags<T>\n this.telemetry = getCliTelemetry()\n\n await super.init()\n }\n\n /**\n * Check if the command is running in unattended mode.\n *\n * This means the command should not ask for user input, instead using defaults where\n * possible, and if that does not make sense (eg there's missing information), then we\n * should error out (remember to exit with a non-zero code).\n *\n * Most commands should take an explicit `--yes` flag to enable unattended mode, but\n * some commands may also be run in unattended mode if `process.stdin` is not a TTY\n * (eg when running in a CI environment).\n */\n protected isUnattended(): boolean {\n return this.flags.yes || !this.resolveIsInteractive()\n }\n\n /**\n * Resolver for checking if the terminal is interactive. Override in tests to provide mock values.\n *\n * @returns Whether the terminal is interactive.\n */\n protected resolveIsInteractive(): boolean {\n return isInteractive()\n }\n\n /**\n * Get the CLI config, returning an empty config if no project root is found.\n *\n * Use this instead of `getCliConfig()` in commands that can operate without a\n * project directory (e.g. when `--project-id` and `--dataset` flags are provided).\n *\n * @returns The CLI config, or an empty config object if no project root is found.\n */\n protected async tryGetCliConfig(): Promise<CliConfig> {\n try {\n return await this.getCliConfig()\n } catch (err) {\n if (!(err instanceof ProjectRootNotFoundError)) throw err\n return {}\n }\n }\n}\n"],"names":["Command","getCliConfig","findProjectRoot","subdebug","NonInteractiveError","ProjectRootNotFoundError","getGlobalCliClient","getProjectCliClient","getCliTelemetry","isInteractive","debug","SanityCommand","args","flags","getGlobalApiClient","getProjectApiClient","output","error","bind","log","warn","telemetry","root","getProjectRoot","directory","getProjectId","options","hasProjectFlag","ctor","flagProjectId","undefined","deprecatedFlagName","deprecatedValue","config","configProjectId","api","projectId","err","fallback","cause","suggestions","process","cwd","init","parse","baseFlags","enableJsonFlag","strict","isUnattended","yes","resolveIsInteractive","tryGetCliConfig"],"mappings":"AAAA,SAAQA,OAAO,QAAmB,cAAa;AAE/C,SAAQC,YAAY,QAAO,+BAA8B;AAEzD,SAAQC,eAAe,QAAO,8BAA6B;AAE3D,SAAQC,QAAQ,QAAO,aAAY;AACnC,SAAQC,mBAAmB,QAAO,kCAAiC;AACnE,SAAQC,wBAAwB,QAAO,uCAAsC;AAC7E,SACEC,kBAAkB,EAClBC,mBAAmB,QAGd,0BAAyB;AAGhC,SAAQC,eAAe,QAAO,4BAA2B;AACzD,SAAQC,aAAa,QAAO,0BAAyB;AAQrD,MAAMC,QAAQP,SAAS;AAEvB,OAAO,MAAeQ,sBAAgDX;IAC1DY,KAAc;IACdC,MAAgB;IAE1B;;;;;;;GAOC,GACD,AAAUC,qBAAqB,CAACF,OAAiCN,mBAAmBM,MAAK;IAEzF;;;;;;;GAOC,GACD,AAAUG,sBAAsB,CAACH,OAAkCL,oBAAoBK,MAAK;IAE5F;;;;;;;;;GASC,GACD,AAAUI,SAAiB;QACzBC,OAA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;GAOC,GACD,MAAgB0C,kBAAsC;QACpD,IAAI;YACF,OAAO,MAAM,IAAI,CAAClD,YAAY;QAChC,EAAE,OAAOoC,KAAK;YACZ,IAAI,CAAEA,CAAAA,eAAehC,wBAAuB,GAAI,MAAMgC;YACtD,OAAO,CAAC;QACV;IACF;AACF"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import {agent} from 'get-it/middleware'
|
|
2
|
+
import {base} from 'get-it/middleware'
|
|
3
|
+
import {injectResponse} from 'get-it/middleware'
|
|
4
|
+
import {jsonRequest} from 'get-it/middleware'
|
|
5
|
+
import {jsonResponse} from 'get-it/middleware'
|
|
6
|
+
import {keepAlive} from 'get-it/middleware'
|
|
7
|
+
import {observable} from 'get-it/middleware'
|
|
8
|
+
import {progress} from 'get-it/middleware'
|
|
9
|
+
import {proxy} from 'get-it/middleware'
|
|
10
|
+
import {Requester} from 'get-it'
|
|
11
|
+
import {retry} from 'get-it/middleware'
|
|
12
|
+
import {urlEncoded} from 'get-it/middleware'
|
|
13
|
+
|
|
14
|
+
export {agent}
|
|
15
|
+
|
|
16
|
+
export {base}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Creates a `get-it` requester with a standard set of middleware.
|
|
20
|
+
*
|
|
21
|
+
* Default middleware (in order):
|
|
22
|
+
* 1. `httpErrors()` — throw on HTTP error status codes
|
|
23
|
+
* 2. `headers({'User-Agent': '@sanity/cli-core@<version>'})` — identify CLI requests
|
|
24
|
+
* 3. `debug({verbose: true, namespace: 'sanity:cli'})` — debug logging
|
|
25
|
+
* 4. `promise({onlyBody: true})` — return body directly (must be last)
|
|
26
|
+
*
|
|
27
|
+
* @param options - Optional configuration to disable or customize middleware
|
|
28
|
+
* @returns A configured `get-it` requester
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export declare function createRequester(options?: {middleware?: MiddlewareOptions}): Requester
|
|
32
|
+
|
|
33
|
+
export {injectResponse}
|
|
34
|
+
|
|
35
|
+
export {jsonRequest}
|
|
36
|
+
|
|
37
|
+
export {jsonResponse}
|
|
38
|
+
|
|
39
|
+
export {keepAlive}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Options for configuring individual middleware in {@link createRequester}.
|
|
43
|
+
*
|
|
44
|
+
* Each key corresponds to a middleware. Omitting a key uses the default,
|
|
45
|
+
* `false` disables it, and an object merges with the defaults.
|
|
46
|
+
*
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
export declare type MiddlewareOptions = {
|
|
50
|
+
debug?:
|
|
51
|
+
| false
|
|
52
|
+
| {
|
|
53
|
+
namespace?: string
|
|
54
|
+
verbose?: boolean
|
|
55
|
+
}
|
|
56
|
+
headers?: false | Record<string, string>
|
|
57
|
+
httpErrors?: false
|
|
58
|
+
promise?:
|
|
59
|
+
| false
|
|
60
|
+
| {
|
|
61
|
+
onlyBody?: boolean
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export {observable}
|
|
66
|
+
|
|
67
|
+
export {progress}
|
|
68
|
+
|
|
69
|
+
export {proxy}
|
|
70
|
+
|
|
71
|
+
export {Requester}
|
|
72
|
+
|
|
73
|
+
export {retry}
|
|
74
|
+
|
|
75
|
+
export {urlEncoded}
|
|
76
|
+
|
|
77
|
+
export {}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createRequester } from '../request/createRequester.js';
|
|
2
|
+
// Re-export non-default middleware from get-it for use alongside createRequester.
|
|
3
|
+
// Default middleware (httpErrors, headers, debug, promise) are applied automatically
|
|
4
|
+
// by createRequester and don't need to be imported separately.
|
|
5
|
+
export { agent, base, injectResponse, jsonRequest, jsonResponse, keepAlive, observable, progress, proxy, retry, urlEncoded } from 'get-it/middleware';
|
|
6
|
+
|
|
7
|
+
//# sourceMappingURL=request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/_exports/request.ts"],"sourcesContent":["export {createRequester, type MiddlewareOptions} from '../request/createRequester.js'\n\n// Re-export get-it types used by consumers of createRequester\nexport {type Requester} from 'get-it'\n\n// Re-export non-default middleware from get-it for use alongside createRequester.\n// Default middleware (httpErrors, headers, debug, promise) are applied automatically\n// by createRequester and don't need to be imported separately.\nexport {\n agent,\n base,\n injectResponse,\n jsonRequest,\n jsonResponse,\n keepAlive,\n observable,\n progress,\n proxy,\n retry,\n urlEncoded,\n} from 'get-it/middleware'\n"],"names":["createRequester","agent","base","injectResponse","jsonRequest","jsonResponse","keepAlive","observable","progress","proxy","retry","urlEncoded"],"mappings":"AAAA,SAAQA,eAAe,QAA+B,gCAA+B;AAKrF,kFAAkF;AAClF,qFAAqF;AACrF,+DAA+D;AAC/D,SACEC,KAAK,EACLC,IAAI,EACJC,cAAc,EACdC,WAAW,EACXC,YAAY,EACZC,SAAS,EACTC,UAAU,EACVC,QAAQ,EACRC,KAAK,EACLC,KAAK,EACLC,UAAU,QACL,oBAAmB"}
|
package/dist/_exports/ux.d.ts
CHANGED
|
@@ -1,4 +1,75 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import {default as boxen} from 'boxen'
|
|
2
|
+
import {Options as BoxenOptions} from 'boxen'
|
|
3
|
+
import {Boxes} from 'boxen'
|
|
4
|
+
import {CLIError} from '@oclif/core/errors'
|
|
5
|
+
import {CustomBorderStyle} from 'boxen'
|
|
6
|
+
import * as inquirer from '@inquirer/prompts'
|
|
7
|
+
import {default as logSymbols} from 'log-symbols'
|
|
8
|
+
import {Separator} from '@inquirer/prompts'
|
|
9
|
+
import {Spacing} from 'boxen'
|
|
10
|
+
import {Spinner} from 'ora'
|
|
11
|
+
import {default as spinner} from 'ora'
|
|
12
|
+
import {Ora as SpinnerInstance} from 'ora'
|
|
13
|
+
import {Options as SpinnerOptions} from 'ora'
|
|
14
|
+
import {oraPromise as spinnerPromise} from 'ora'
|
|
15
|
+
import {PromiseOptions as SpinnerPromiseOptions} from 'ora'
|
|
16
|
+
|
|
17
|
+
export {boxen}
|
|
18
|
+
|
|
19
|
+
export {BoxenOptions}
|
|
20
|
+
|
|
21
|
+
export {Boxes}
|
|
22
|
+
|
|
23
|
+
export declare const checkbox: typeof inquirer.checkbox
|
|
24
|
+
|
|
25
|
+
declare const confirm_2: typeof inquirer.confirm
|
|
26
|
+
export {confirm_2 as confirm}
|
|
27
|
+
|
|
28
|
+
export {CustomBorderStyle}
|
|
29
|
+
|
|
30
|
+
export declare const editor: typeof inquirer.editor
|
|
31
|
+
|
|
32
|
+
export declare const expand: typeof inquirer.expand
|
|
33
|
+
|
|
34
|
+
export declare const input: typeof inquirer.input
|
|
35
|
+
|
|
36
|
+
export {logSymbols}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Error thrown when a prompt is attempted in a non-interactive environment
|
|
40
|
+
* (e.g., CI, non-TTY, piped stdin). Callers can catch this specific error
|
|
41
|
+
* to provide appropriate fallback behavior.
|
|
42
|
+
*
|
|
43
|
+
* Extends `CLIError` to suppress stack traces in user-facing output.
|
|
44
|
+
*/
|
|
45
|
+
export declare class NonInteractiveError extends CLIError {
|
|
46
|
+
constructor(promptName: string)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export declare const number: typeof inquirer.number
|
|
50
|
+
|
|
51
|
+
export declare const password: typeof inquirer.password
|
|
52
|
+
|
|
53
|
+
export declare const rawlist: typeof inquirer.rawlist
|
|
54
|
+
|
|
55
|
+
export declare const search: typeof inquirer.search
|
|
56
|
+
|
|
57
|
+
export declare const select: typeof inquirer.select
|
|
58
|
+
|
|
59
|
+
export {Separator}
|
|
60
|
+
|
|
61
|
+
export {Spacing}
|
|
62
|
+
|
|
63
|
+
export {Spinner}
|
|
64
|
+
|
|
65
|
+
export {spinner}
|
|
66
|
+
|
|
67
|
+
export {SpinnerInstance}
|
|
68
|
+
|
|
69
|
+
export {SpinnerOptions}
|
|
70
|
+
|
|
71
|
+
export {spinnerPromise}
|
|
72
|
+
|
|
73
|
+
export {SpinnerPromiseOptions}
|
|
74
|
+
|
|
75
|
+
export {}
|
package/dist/_exports/ux.js
CHANGED
package/dist/_exports/ux.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/_exports/ux.ts"],"sourcesContent":["export * from '../ux/
|
|
1
|
+
{"version":3,"sources":["../../src/_exports/ux.ts"],"sourcesContent":["export {NonInteractiveError} from '../errors/NonInteractiveError.js'\nexport * from '../ux/boxen.js'\nexport * from '../ux/logSymbols.js'\nexport * from '../ux/prompts.js'\nexport * from '../ux/spinner.js'\n"],"names":["NonInteractiveError"],"mappings":"AAAA,SAAQA,mBAAmB,QAAO,mCAAkC;AACpE,cAAc,iBAAgB;AAC9B,cAAc,sBAAqB;AACnC,cAAc,mBAAkB;AAChC,cAAc,mBAAkB"}
|
|
@@ -1,25 +1,36 @@
|
|
|
1
|
-
import { getTsconfig } from 'get-tsconfig';
|
|
2
|
-
import { tsImport } from 'tsx/esm/api';
|
|
3
1
|
import { debug } from '../../debug.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { tryGetDefaultExport } from '../../util/tryGetDefaultExport.js';
|
|
2
|
+
import { NotFoundError } from '../../errors/NotFoundError.js';
|
|
3
|
+
import { importModule } from '../../util/importModule.js';
|
|
7
4
|
import { findPathForFiles } from '../util/findConfigsPaths.js';
|
|
8
5
|
import { cliConfigSchema } from './schemas.js';
|
|
6
|
+
const cache = new Map();
|
|
9
7
|
/**
|
|
10
8
|
* Get the CLI config for a project, given the root path.
|
|
11
9
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
10
|
+
* Results are cached in-memory keyed by rootPath for the lifetime of the
|
|
11
|
+
* process. Since the CLI always runs from a single project root, the config
|
|
12
|
+
* won't change during a command's execution, so caching avoids redundant
|
|
13
|
+
* filesystem reads and jiti imports from the prerun hook, SanityCommand
|
|
14
|
+
* helpers, and action files.
|
|
15
|
+
*
|
|
16
|
+
* If loading fails the cached promise is evicted so the next call retries.
|
|
18
17
|
*
|
|
19
18
|
* @param rootPath - Root path for the project, eg where `sanity.cli.(ts|js)` is located.
|
|
20
19
|
* @returns The CLI config
|
|
21
20
|
* @internal
|
|
22
|
-
*/ export
|
|
21
|
+
*/ export function getCliConfig(rootPath) {
|
|
22
|
+
const cached = cache.get(rootPath);
|
|
23
|
+
if (cached) {
|
|
24
|
+
return cached;
|
|
25
|
+
}
|
|
26
|
+
const promise = loadCliConfig(rootPath).catch((err)=>{
|
|
27
|
+
cache.delete(rootPath);
|
|
28
|
+
throw err;
|
|
29
|
+
});
|
|
30
|
+
cache.set(rootPath, promise);
|
|
31
|
+
return promise;
|
|
32
|
+
}
|
|
33
|
+
async function loadCliConfig(rootPath) {
|
|
23
34
|
const paths = await findPathForFiles(rootPath, [
|
|
24
35
|
'sanity.cli.ts',
|
|
25
36
|
'sanity.cli.js'
|
|
@@ -32,36 +43,25 @@ import { cliConfigSchema } from './schemas.js';
|
|
|
32
43
|
throw new Error(`Multiple CLI config files found (${configPaths.map((path)=>path.path).join(', ')})`);
|
|
33
44
|
}
|
|
34
45
|
const configPath = configPaths[0].path;
|
|
46
|
+
debug(`Loading CLI config from: ${configPath}`);
|
|
35
47
|
let cliConfig;
|
|
36
48
|
try {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
workerData: {
|
|
41
|
-
configPath
|
|
42
|
-
}
|
|
43
|
-
});
|
|
49
|
+
const result = await importModule(configPath);
|
|
50
|
+
debug('CLI config loaded: %o', result);
|
|
51
|
+
cliConfig = result;
|
|
44
52
|
} catch (err) {
|
|
45
53
|
debug('Failed to load CLI config in worker thread: %s', err);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const tsconfig = getTsconfig(rootPath);
|
|
49
|
-
// Ensure we get the default export (sometimes we get a bit of a mixed bag)
|
|
50
|
-
cliConfig = await tsImport(configPath, {
|
|
51
|
-
parentURL: import.meta.url,
|
|
52
|
-
tsconfig: tsconfig?.path ?? undefined
|
|
54
|
+
throw new Error('CLI config cannot be loaded', {
|
|
55
|
+
cause: err
|
|
53
56
|
});
|
|
54
|
-
cliConfig = tryGetDefaultExport(cliConfig);
|
|
55
|
-
if (!cliConfig) {
|
|
56
|
-
throw new Error('Invalid CLI config structure');
|
|
57
|
-
}
|
|
58
57
|
}
|
|
59
58
|
const { data, error, success } = cliConfigSchema.safeParse(cliConfig);
|
|
60
59
|
if (!success) {
|
|
61
|
-
|
|
60
|
+
debug(`Invalid CLI config: ${error.message}`);
|
|
61
|
+
throw new Error(`Invalid CLI config: ${error.message}`, {
|
|
62
|
+
cause: error
|
|
63
|
+
});
|
|
62
64
|
}
|
|
63
|
-
// There is a minor difference here because of the `vite` property and how the types
|
|
64
|
-
// aren't as specific as our manually typed `CliConfig` type, thus the cast.
|
|
65
65
|
return data;
|
|
66
66
|
}
|
|
67
67
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/config/cli/getCliConfig.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../src/config/cli/getCliConfig.ts"],"sourcesContent":["import {debug} from '../../debug.js'\nimport {NotFoundError} from '../../errors/NotFoundError.js'\nimport {importModule} from '../../util/importModule.js'\nimport {findPathForFiles} from '../util/findConfigsPaths.js'\nimport {cliConfigSchema} from './schemas.js'\nimport {type CliConfig} from './types/cliConfig.js'\n\nconst cache = new Map<string, Promise<CliConfig>>()\n\n/**\n * Get the CLI config for a project, given the root path.\n *\n * Results are cached in-memory keyed by rootPath for the lifetime of the\n * process. Since the CLI always runs from a single project root, the config\n * won't change during a command's execution, so caching avoids redundant\n * filesystem reads and jiti imports from the prerun hook, SanityCommand\n * helpers, and action files.\n *\n * If loading fails the cached promise is evicted so the next call retries.\n *\n * @param rootPath - Root path for the project, eg where `sanity.cli.(ts|js)` is located.\n * @returns The CLI config\n * @internal\n */\nexport function getCliConfig(rootPath: string): Promise<CliConfig> {\n const cached = cache.get(rootPath)\n if (cached) {\n return cached\n }\n\n const promise = loadCliConfig(rootPath).catch((err) => {\n cache.delete(rootPath)\n throw err\n })\n\n cache.set(rootPath, promise)\n return promise\n}\n\nasync function loadCliConfig(rootPath: string): Promise<CliConfig> {\n const paths = await findPathForFiles(rootPath, ['sanity.cli.ts', 'sanity.cli.js'])\n const configPaths = paths.filter((path) => path.exists)\n\n if (configPaths.length === 0) {\n throw new NotFoundError(`No CLI config found at ${rootPath}/sanity.cli.(ts|js)`)\n }\n\n if (configPaths.length > 1) {\n throw new Error(\n `Multiple CLI config files found (${configPaths.map((path) => path.path).join(', ')})`,\n )\n }\n\n const configPath = configPaths[0].path\n\n debug(`Loading CLI config from: ${configPath}`)\n\n let cliConfig: CliConfig | undefined\n try {\n const result = await importModule<CliConfig>(configPath)\n\n debug('CLI config loaded: %o', result)\n\n cliConfig = result\n } catch (err) {\n debug('Failed to load CLI config in worker thread: %s', err)\n\n throw new Error('CLI config cannot be loaded', {cause: err})\n }\n\n const {data, error, success} = cliConfigSchema.safeParse(cliConfig)\n if (!success) {\n debug(`Invalid CLI config: ${error.message}`)\n throw new Error(`Invalid CLI config: ${error.message}`, {cause: error})\n }\n\n return data\n}\n"],"names":["debug","NotFoundError","importModule","findPathForFiles","cliConfigSchema","cache","Map","getCliConfig","rootPath","cached","get","promise","loadCliConfig","catch","err","delete","set","paths","configPaths","filter","path","exists","length","Error","map","join","configPath","cliConfig","result","cause","data","error","success","safeParse","message"],"mappings":"AAAA,SAAQA,KAAK,QAAO,iBAAgB;AACpC,SAAQC,aAAa,QAAO,gCAA+B;AAC3D,SAAQC,YAAY,QAAO,6BAA4B;AACvD,SAAQC,gBAAgB,QAAO,8BAA6B;AAC5D,SAAQC,eAAe,QAAO,eAAc;AAG5C,MAAMC,QAAQ,IAAIC;AAElB;;;;;;;;;;;;;;CAcC,GACD,OAAO,SAASC,aAAaC,QAAgB;IAC3C,MAAMC,SAASJ,MAAMK,GAAG,CAACF;IACzB,IA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,7 +2,7 @@ import { existsSync } from 'node:fs';
|
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { register } from 'tsx/esm/api';
|
|
5
|
-
import { NotFoundError } from '../../
|
|
5
|
+
import { NotFoundError } from '../../errors/NotFoundError.js';
|
|
6
6
|
import { tryGetDefaultExport } from '../../util/tryGetDefaultExport.js';
|
|
7
7
|
import { cliConfigSchema } from './schemas.js';
|
|
8
8
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/config/cli/getCliConfigSync.ts"],"sourcesContent":["import {existsSync} from 'node:fs'\nimport {createRequire} from 'node:module'\nimport {join} from 'node:path'\n\nimport {register} from 'tsx/esm/api'\n\nimport {NotFoundError} from '../../
|
|
1
|
+
{"version":3,"sources":["../../../src/config/cli/getCliConfigSync.ts"],"sourcesContent":["import {existsSync} from 'node:fs'\nimport {createRequire} from 'node:module'\nimport {join} from 'node:path'\n\nimport {register} from 'tsx/esm/api'\n\nimport {NotFoundError} from '../../errors/NotFoundError.js'\nimport {tryGetDefaultExport} from '../../util/tryGetDefaultExport.js'\nimport {cliConfigSchema} from './schemas.js'\nimport {type CliConfig} from './types/cliConfig.js'\n\n/**\n * Get the CLI config for a project synchronously, given the root path.\n *\n * This loads the CLI config in the main thread using tsx/register for TypeScript support.\n * Note: This is a synchronous operation and does not use worker threads like the async version.\n *\n * @param rootPath - Root path for the project, eg where `sanity.cli.(ts|js)` is located.\n * @returns The CLI config\n * @internal\n */\nexport function getCliConfigSync(rootPath: string): CliConfig {\n const possiblePaths = ['sanity.cli.ts', 'sanity.cli.js'].map((file) => join(rootPath, file))\n const configPaths = possiblePaths.filter((path) => existsSync(path))\n\n if (configPaths.length === 0) {\n throw new NotFoundError(`No CLI config found at ${rootPath}/sanity.cli.(ts|js)`)\n }\n\n if (configPaths.length > 1) {\n throw new Error(`Multiple CLI config files found (${configPaths.join(', ')})`)\n }\n\n const configPath = configPaths[0]\n\n // Register tsx for TypeScript support\n const unregister = register()\n\n let cliConfig: CliConfig | undefined\n try {\n // Use createRequire for synchronous loading in ESM contexts\n // This works when tsx loader is active\n const require = createRequire(import.meta.url)\n const loaded = require(configPath)\n cliConfig = tryGetDefaultExport(loaded) as CliConfig | undefined\n } finally {\n unregister()\n }\n\n const {data, error, success} = cliConfigSchema.safeParse(cliConfig)\n if (!success) {\n throw new Error(`Invalid CLI config: ${error.message}`)\n }\n\n // There is a minor difference here because of the `vite` property and how the types\n // aren't as specific as our manually typed `CliConfig` type, thus the cast.\n return data as CliConfig\n}\n"],"names":["existsSync","createRequire","join","register","NotFoundError","tryGetDefaultExport","cliConfigSchema","getCliConfigSync","rootPath","possiblePaths","map","file","configPaths","filter","path","length","Error","configPath","unregister","cliConfig","require","url","loaded","data","error","success","safeParse","message"],"mappings":"AAAA,SAAQA,UAAU,QAAO,UAAS;AAClC,SAAQC,aAAa,QAAO,cAAa;AACzC,SAAQC,IAAI,QAAO,YAAW;AAE9B,SAAQC,QAAQ,QAAO,cAAa;AAEpC,SAAQC,aAAa,QAAO,gCAA+B;AAC3D,SAAQC,mBAAmB,QAAO,oCAAmC;AACrE,SAAQC,eAAe,QAAO,eAAc;AAG5C;;;;;;;;;CASC,GACD,OAAO,SAASC,iBAAiBC,QAAgB;IAC/C,MAAMC,gBAAgB;QAAC;QAAiB;KAAgB,CAACC,GAAG,CAAC,CAACC,OAAST,KAAKM,UAAUG;IACtF,MAAMC,cAAcH,cAAcI,MAAM,CAAC,CAACC,OAASd,WAAWc;IAE9D,IAAIF,YAAYG,MAAM,KAAK,GAAG;QAC5B,MAAM,IAAIX,cAAc,CAAC,uBAAuB,EAAEI,SAAS,mBAAmB,CAAC;IACjF;IAEA,IAAII,YAAYG,MAAM,GAAG,GAAG;QAC1B,MAAM,IAAIC,MAAM,CAAC,iCAAiC,EAAEJ,YAAYV,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/E;IAEA,MAAMe,aAAaL,WAAW,CAAC,EAAE;IAEjC,sCAAsC;IACtC,MAAMM,aAAaf;IAEnB,IAAIgB;IACJ,IAAI;QACF,4DAA4D;QAC5D,uCAAuC;QACvC,MAAMC,UAAUnB,cAAc,YAAYoB,GAAG;QAC7C,MAAMC,SAASF,QAAQH;QACvBE,YAAYd,oBAAoBiB;IAClC,SAAU;QACRJ;IACF;IAEA,MAAM,EAACK,IAAI,EAAEC,KAAK,EAAEC,OAAO,EAAC,GAAGnB,gBAAgBoB,SAAS,CAACP;IACzD,IAAI,CAACM,SAAS;QACZ,MAAM,IAAIT,MAAM,CAAC,oBAAoB,EAAEQ,MAAMG,OAAO,EAAE;IACxD;IAEA,oFAAoF;IACpF,4EAA4E;IAC5E,OAAOJ;AACT"}
|
|
@@ -40,6 +40,13 @@ import { z } from 'zod';
|
|
|
40
40
|
}).optional(),
|
|
41
41
|
reactCompiler: z.custom().optional(),
|
|
42
42
|
reactStrictMode: z.boolean().optional(),
|
|
43
|
+
schemaExtraction: z.object({
|
|
44
|
+
enabled: z.boolean().optional(),
|
|
45
|
+
enforceRequiredFields: z.boolean().optional(),
|
|
46
|
+
path: z.string().optional(),
|
|
47
|
+
watchPatterns: z.array(z.string()).optional(),
|
|
48
|
+
workspace: z.string().optional()
|
|
49
|
+
}).optional(),
|
|
43
50
|
server: z.object({
|
|
44
51
|
hostname: z.string().optional(),
|
|
45
52
|
port: z.number().optional()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/config/cli/schemas.ts"],"sourcesContent":["import {type TypeGenConfig} from '@sanity/codegen'\nimport {type PluginOptions as ReactCompilerConfig} from 'babel-plugin-react-compiler'\nimport {z} from 'zod'\n\nimport {type CliConfig} from './types/cliConfig'\nimport {type UserViteConfig} from './types/userViteConfig'\n\n/**\n * @public\n */\nexport const cliConfigSchema = z.object({\n api: z\n .object({\n dataset: z.string().optional(),\n projectId: z.string().optional(),\n })\n .optional(),\n\n app: z\n .object({\n entry: z.string().optional(),\n icon: z.string().optional(),\n id: z.string().optional(),\n organizationId: z.string().optional(),\n title: z.string().optional(),\n })\n .optional(),\n\n autoUpdates: z.boolean().optional(),\n\n deployment: z\n .object({\n appId: z.string().optional(),\n autoUpdates: z.boolean().optional(),\n })\n .optional(),\n\n graphql: z\n .array(\n z.object({\n filterSuffix: z.string().optional(),\n generation: z.enum(['gen1', 'gen2', 'gen3']).optional(),\n id: z.string().optional(),\n nonNullDocumentFields: z.boolean().optional(),\n playground: z.boolean().optional(),\n source: z.string().optional(),\n tag: z.string().optional(),\n workspace: z.string().optional(),\n }),\n )\n .optional(),\n\n mediaLibrary: z\n .object({\n aspectsPath: z.string().optional(),\n })\n .optional(),\n\n project: z\n .object({\n basePath: z.string().optional(),\n })\n .optional(),\n\n reactCompiler: z.custom<ReactCompilerConfig>().optional(),\n\n reactStrictMode: z.boolean().optional(),\n\n server: z\n .object({\n hostname: z.string().optional(),\n port: z.number().optional(),\n })\n .optional(),\n\n studioHost: z.string().optional(),\n\n vite: z.custom<UserViteConfig>().optional(),\n\n typegen: z.custom<TypeGenConfig>().optional(),\n}) satisfies z.ZodType<CliConfig>\n"],"names":["z","cliConfigSchema","object","api","dataset","string","optional","projectId","app","entry","icon","id","organizationId","title","autoUpdates","boolean","deployment","appId","graphql","array","filterSuffix","generation","enum","nonNullDocumentFields","playground","source","tag","workspace","mediaLibrary","aspectsPath","project","basePath","reactCompiler","custom","reactStrictMode","server","hostname","port","number","studioHost","vite","typegen"],"mappings":"AAEA,SAAQA,CAAC,QAAO,MAAK;AAKrB;;CAEC,GACD,OAAO,MAAMC,kBAAkBD,EAAEE,MAAM,CAAC;IACtCC,KAAKH,EACFE,MAAM,CAAC;QACNE,SAASJ,EAAEK,MAAM,GAAGC,QAAQ;QAC5BC,WAAWP,EAAEK,MAAM,GAAGC,QAAQ;IAChC,GACCA,QAAQ;IAEXE,KAAKR,EACFE,MAAM,CAAC;QACNO,OAAOT,EAAEK,MAAM,GAAGC,QAAQ;QAC1BI,MAAMV,EAAEK,MAA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'babel-plugin-react-compiler'\nimport {z} from 'zod'\n\nimport {type CliConfig} from './types/cliConfig'\nimport {type UserViteConfig} from './types/userViteConfig'\n\n/**\n * @public\n */\nexport const cliConfigSchema = z.object({\n api: z\n .object({\n dataset: z.string().optional(),\n projectId: z.string().optional(),\n })\n .optional(),\n\n app: z\n .object({\n entry: z.string().optional(),\n icon: z.string().optional(),\n id: z.string().optional(),\n organizationId: z.string().optional(),\n title: z.string().optional(),\n })\n .optional(),\n\n autoUpdates: z.boolean().optional(),\n\n deployment: z\n .object({\n appId: z.string().optional(),\n autoUpdates: z.boolean().optional(),\n })\n .optional(),\n\n graphql: z\n .array(\n z.object({\n filterSuffix: z.string().optional(),\n generation: z.enum(['gen1', 'gen2', 'gen3']).optional(),\n id: z.string().optional(),\n nonNullDocumentFields: z.boolean().optional(),\n playground: z.boolean().optional(),\n source: z.string().optional(),\n tag: z.string().optional(),\n workspace: z.string().optional(),\n }),\n )\n .optional(),\n\n mediaLibrary: z\n .object({\n aspectsPath: z.string().optional(),\n })\n .optional(),\n\n project: z\n .object({\n basePath: z.string().optional(),\n })\n .optional(),\n\n reactCompiler: z.custom<ReactCompilerConfig>().optional(),\n\n reactStrictMode: z.boolean().optional(),\n\n schemaExtraction: z\n .object({\n enabled: z.boolean().optional(),\n enforceRequiredFields: z.boolean().optional(),\n path: z.string().optional(),\n watchPatterns: z.array(z.string()).optional(),\n workspace: z.string().optional(),\n })\n .optional(),\n\n server: z\n .object({\n hostname: z.string().optional(),\n port: z.number().optional(),\n })\n .optional(),\n\n studioHost: z.string().optional(),\n\n vite: z.custom<UserViteConfig>().optional(),\n\n typegen: z.custom<Partial<TypeGenConfig> & {enabled?: boolean}>().optional(),\n}) satisfies z.ZodType<CliConfig>\n"],"names":["z","cliConfigSchema","object","api","dataset","string","optional","projectId","app","entry","icon","id","organizationId","title","autoUpdates","boolean","deployment","appId","graphql","array","filterSuffix","generation","enum","nonNullDocumentFields","playground","source","tag","workspace","mediaLibrary","aspectsPath","project","basePath","reactCompiler","custom","reactStrictMode","schemaExtraction","enabled","enforceRequiredFields","path","watchPatterns","server","hostname","port","number","studioHost","vite","typegen"],"mappings":"AAEA,SAAQA,CAAC,QAAO,MAAK;AAKrB;;CAEC,GACD,OAAO,MAAMC,kBAAkBD,EAAEE,MAAM,CAAC;IACtCC,KAAKH,EACFE,MAAM,CAAC;QACNE,SAASJ,EAAEK,MAAM,GAAGC,QAAQ;QAC5BC,WAAWP,EAAEK,MAAM,GAAGC,QAAQ;IAChC,GACCA,QAAQ;IAEXE,KAAKR,EACFE,MAAM,CAAC;QACNO,OAAOT,EAAEK,MAAM,GAAGC,QAAQ;QAC1BI,MAAMV,EAAEK,MAAM,GAAGC,QAAQ;QACzBK,IAAIX,EAAEK,MAAM,GAAGC,QAAQ;QACvBM,gBAAgBZ,EAAEK,MAAM,GAAGC,QAAQ;QACnCO,OAAOb,EAAEK,MAAM,GAAGC,QAAQ;IAC5B,GACCA,QAAQ;IAEXQ,aAAad,EAAEe,OAAO,GAAGT,QAAQ;IAEjCU,YAAYhB,EACTE,MAAM,CAAC;QACNe,OAAOjB,EAAEK,MAAM,GAAGC,QAAQ;QAC1BQ,aAAad,EAAEe,OAAO,GAAGT,QAAQ;IACnC,GACCA,QAAQ;IAEXY,SAASlB,EACNmB,KAAK,CACJnB,EAAEE,MAAM,CAAC;QACPkB,cAAcpB,EAAEK,MAAM,GAAGC,QAAQ;QACjCe,YAAYrB,EAAEsB,IAAI,CAAC;YAAC;YAAQ;YAAQ;SAAO,EAAEhB,QAAQ;QACrDK,IAAIX,EAAEK,MAAM,GAAGC,QAAQ;QACvBiB,uBAAuBvB,EAAEe,OAAO,GAAGT,QAAQ;QAC3CkB,YAAYxB,EAAEe,OAAO,GAAGT,QAAQ;QAChCmB,QAAQzB,EAAEK,MAAM,GAAGC,QAAQ;QAC3BoB,KAAK1B,EAAEK,MAAM,GAAGC,QAAQ;QACxBqB,WAAW3B,EAAEK,MAAM,GAAGC,QAAQ;IAChC,IAEDA,QAAQ;IAEXsB,cAAc5B,EACXE,MAAM,CAAC;QACN2B,aAAa7B,EAAEK,MAAM,GAAGC,QAAQ;IAClC,GACCA,QAAQ;IAEXwB,SAAS9B,EACNE,MAAM,CAAC;QACN6B,UAAU/B,EAAEK,MAAM,GAAGC,QAAQ;IAC/B,GACCA,QAAQ;IAEX0B,eAAehC,EAAEiC,MAAM,GAAwB3B,QAAQ;IAEvD4B,iBAAiBlC,EAAEe,OAAO,GAAGT,QAAQ;IAErC6B,kBAAkBnC,EACfE,MAAM,CAAC;QACNkC,SAASpC,EAAEe,OAAO,GAAGT,QAAQ;QAC7B+B,uBAAuBrC,EAAEe,OAAO,GAAGT,QAAQ;QAC3CgC,MAAMtC,EAAEK,MAAM,GAAGC,QAAQ;QACzBiC,eAAevC,EAAEmB,KAAK,CAACnB,EAAEK,MAAM,IAAIC,QAAQ;QAC3CqB,WAAW3B,EAAEK,MAAM,GAAGC,QAAQ;IAChC,GACCA,QAAQ;IAEXkC,QAAQxC,EACLE,MAAM,CAAC;QACNuC,UAAUzC,EAAEK,MAAM,GAAGC,QAAQ;QAC7BoC,MAAM1C,EAAE2C,MAAM,GAAGrC,QAAQ;IAC3B,GACCA,QAAQ;IAEXsC,YAAY5C,EAAEK,MAAM,GAAGC,QAAQ;IAE/BuC,MAAM7C,EAAEiC,MAAM,GAAmB3B,QAAQ;IAEzCwC,SAAS9C,EAAEiC,MAAM,GAAiD3B,QAAQ;AAC5E,GAAiC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/config/cli/types/cliConfig.ts"],"sourcesContent":["import {type TypeGenConfig} from '@sanity/codegen'\nimport {type PluginOptions as ReactCompilerConfig} from 'babel-plugin-react-compiler'\n\nimport {type UserViteConfig} from './userViteConfig'\n\n/**\n * @public\n */\nexport interface CliConfig {\n /** The project ID and dataset the Sanity CLI should use to run its commands */\n api?: {\n dataset?: string\n projectId?: string\n }\n\n /** Configuration for custom Sanity apps built with the App SDK */\n app?: {\n /** The entrypoint for your custom app. By default, `src/App.tsx` */\n entry?: string\n /** String encoding of an icon (typically an SVG) */\n icon?: string\n /** @deprecated Use deployment.appId */\n id?: string\n /** The ID for the Sanity organization that manages this application */\n organizationId?: string\n /** The title of the custom app. Used in Dashboard and in the browser tab */\n title?: string\n }\n\n /** @deprecated Use deployment.autoUpdates */\n autoUpdates?: boolean\n\n /** Options for custom app and Studio deployments */\n deployment?: {\n /**\n * The ID for your custom app or Studio. Generated when deploying your app or Studio for the first time.\n * Get your app ID by either:\n * 1. Checking the output of `sanity deploy`, or\n * 2. Checking your project’s Studio tab at https://sanity.io/manage\n *\n * @remarks This is required for all custom app deployments, and for Studios opting in to fine grained version control.\n * {@link https://www.sanity.io/docs/studio/latest-version-of-sanity#k0896ed4574b7}\n */\n appId?: string\n /**\n * Enable automatic updates for your Studio or custom app’s Sanity dependencies.\n * {@link https://www.sanity.io/docs/studio/latest-version-of-sanity}\n */\n autoUpdates?: boolean\n }\n\n /** Define the GraphQL APIs that the CLI can deploy and interact with */\n graphql?: Array<{\n filterSuffix?: string\n generation?: 'gen1' | 'gen2' | 'gen3'\n id?: string\n nonNullDocumentFields?: boolean\n playground?: boolean\n source?: string\n tag?: string\n workspace?: string\n }>\n\n /** Configuration for the Media Library */\n mediaLibrary?: {\n /** 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. */\n aspectsPath?: string\n }\n\n /** 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. */\n project?: {\n basePath?: string\n }\n\n /** Configuration options for React Compiler */\n reactCompiler?: ReactCompilerConfig\n\n /** Wraps the Studio in \\<React.StrictMode\\> root to aid in flagging potential problems related to concurrent features (startTransition, useTransition, useDeferredValue, Suspense). Can also be enabled by setting SANITY_STUDIO_REACT_STRICT_MODE=\"true\"|\"false\". It only applies to sanity dev in development mode and is ignored in sanity build and in production. Defaults to false. */\n reactStrictMode?: boolean\n\n /** Defines the hostname and port that the development server should run on. hostname defaults to localhost, and port to 3333. */\n server?: {\n hostname?: string\n port?: number\n }\n\n /** @deprecated Use deployment.appId */\n studioHost?: string\n\n /**\n * Configuration for Sanity typegen\n */\n typegen?: Partial<TypeGenConfig
|
|
1
|
+
{"version":3,"sources":["../../../../src/config/cli/types/cliConfig.ts"],"sourcesContent":["import {type TypeGenConfig} from '@sanity/codegen'\nimport {type PluginOptions as ReactCompilerConfig} from 'babel-plugin-react-compiler'\n\nimport {type UserViteConfig} from './userViteConfig'\n\n/**\n * @public\n */\nexport interface CliConfig {\n /** The project ID and dataset the Sanity CLI should use to run its commands */\n api?: {\n dataset?: string\n projectId?: string\n }\n\n /** Configuration for custom Sanity apps built with the App SDK */\n app?: {\n /** The entrypoint for your custom app. By default, `src/App.tsx` */\n entry?: string\n /** String encoding of an icon (typically an SVG) */\n icon?: string\n /** @deprecated Use deployment.appId */\n id?: string\n /** The ID for the Sanity organization that manages this application */\n organizationId?: string\n /** The title of the custom app. Used in Dashboard and in the browser tab */\n title?: string\n }\n\n /** @deprecated Use deployment.autoUpdates */\n autoUpdates?: boolean\n\n /** Options for custom app and Studio deployments */\n deployment?: {\n /**\n * The ID for your custom app or Studio. Generated when deploying your app or Studio for the first time.\n * Get your app ID by either:\n * 1. Checking the output of `sanity deploy`, or\n * 2. Checking your project’s Studio tab at https://sanity.io/manage\n *\n * @remarks This is required for all custom app deployments, and for Studios opting in to fine grained version control.\n * {@link https://www.sanity.io/docs/studio/latest-version-of-sanity#k0896ed4574b7}\n */\n appId?: string\n /**\n * Enable automatic updates for your Studio or custom app’s Sanity dependencies.\n * {@link https://www.sanity.io/docs/studio/latest-version-of-sanity}\n */\n autoUpdates?: boolean\n }\n\n /** Define the GraphQL APIs that the CLI can deploy and interact with */\n graphql?: Array<{\n filterSuffix?: string\n generation?: 'gen1' | 'gen2' | 'gen3'\n id?: string\n nonNullDocumentFields?: boolean\n playground?: boolean\n source?: string\n tag?: string\n workspace?: string\n }>\n\n /** Configuration for the Media Library */\n mediaLibrary?: {\n /** 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. */\n aspectsPath?: string\n }\n\n /** 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. */\n project?: {\n basePath?: string\n }\n\n /** Configuration options for React Compiler */\n reactCompiler?: ReactCompilerConfig\n\n /** Wraps the Studio in \\<React.StrictMode\\> root to aid in flagging potential problems related to concurrent features (startTransition, useTransition, useDeferredValue, Suspense). Can also be enabled by setting SANITY_STUDIO_REACT_STRICT_MODE=\"true\"|\"false\". It only applies to sanity dev in development mode and is ignored in sanity build and in production. Defaults to false. */\n reactStrictMode?: boolean\n\n /**\n * Configuration for schema extraction (`sanity schema extract`)\n */\n schemaExtraction?: {\n /**\n * Enable schema extraction as part of sanity dev and sanity build\n */\n enabled?: boolean\n\n /**\n * When true, schema fields marked as required will be non-optional in the output.\n * Defaults to `false`\n */\n enforceRequiredFields?: boolean\n\n /**\n * Output path for the extracted schema file.\n * Defaults to `schema.json` in the working directory.\n */\n path?: string\n\n /**\n * Additional glob patterns to watch for schema changes in watch mode.\n * These extend the default patterns:\n * - `sanity.config.{js,jsx,ts,tsx,mjs}`\n * - `schema*\\/**\\/*.{js,jsx,ts,tsx,mjs}`\n */\n watchPatterns?: string[]\n\n /**\n * The name of the workspace to generate a schema for. Required if your Sanity project has more than one\n * workspace.\n */\n workspace?: string\n }\n\n /** Defines the hostname and port that the development server should run on. hostname defaults to localhost, and port to 3333. */\n server?: {\n hostname?: string\n port?: number\n }\n\n /** @deprecated Use deployment.appId */\n studioHost?: string\n\n /**\n * Configuration for Sanity typegen\n */\n typegen?: Partial<TypeGenConfig> & {\n /**\n * Enable typegen as part of sanity dev and sanity build.\n * When enabled, types are generated on startup and when files change.\n * Defaults to `false`\n */\n enabled?: boolean\n }\n\n /** Exposes the default Vite configuration for custom apps and the Studio so it can be changed and extended. */\n vite?: UserViteConfig\n}\n"],"names":[],"mappings":"AAKA;;CAEC,GACD,WAmIC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { ProjectRootNotFoundError } from '../errors/ProjectRootNotFoundError.js';
|
|
1
2
|
import { findAppConfigPath } from './util/findAppConfigPath.js';
|
|
2
|
-
import {
|
|
3
|
+
import { tryFindStudioConfigPath } from './util/findStudioConfigPath.js';
|
|
3
4
|
import { recursivelyResolveProjectRoot } from './util/recursivelyResolveProjectRoot.js';
|
|
4
5
|
/**
|
|
5
6
|
* Resolve project root directory and type.
|
|
@@ -24,9 +25,12 @@ import { recursivelyResolveProjectRoot } from './util/recursivelyResolveProjectR
|
|
|
24
25
|
if (appProjectRoot) {
|
|
25
26
|
return appProjectRoot;
|
|
26
27
|
}
|
|
27
|
-
// If nothing is found throw
|
|
28
|
-
throw new
|
|
28
|
+
// If nothing is found throw a specific error
|
|
29
|
+
throw new ProjectRootNotFoundError('No project root found');
|
|
29
30
|
} catch (err) {
|
|
31
|
+
if (err instanceof ProjectRootNotFoundError) {
|
|
32
|
+
throw err;
|
|
33
|
+
}
|
|
30
34
|
const message = err instanceof Error ? err.message : `${err}`;
|
|
31
35
|
throw new Error(`Error occurred trying to resolve project root:\n${message}`);
|
|
32
36
|
}
|
|
@@ -40,7 +44,7 @@ import { recursivelyResolveProjectRoot } from './util/recursivelyResolveProjectR
|
|
|
40
44
|
* @returns A promise that resolves to an object if config is found, false otherwise
|
|
41
45
|
* @internal
|
|
42
46
|
*/ async function resolveProjectRootForStudio(basePath, iterations = 0) {
|
|
43
|
-
return recursivelyResolveProjectRoot(basePath,
|
|
47
|
+
return recursivelyResolveProjectRoot(basePath, tryFindStudioConfigPath, 'studio', iterations);
|
|
44
48
|
}
|
|
45
49
|
/**
|
|
46
50
|
* Recursively searches for a app project configuration file in the given directory and its parents.
|