@sanity/cli-core 3.0.0 → 3.1.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/README.md +7 -6
- package/dist/NonInteractiveError-CSLT5y93.d.ts +13 -0
- package/dist/ProjectRootNotFoundError-RgthN9uy.d.ts +47 -0
- package/dist/SanityCommand.d.ts +26 -355
- package/dist/SanityCommand.js +5 -0
- package/dist/SanityCommand.js.map +1 -1
- package/dist/_exports/browser.d.ts +2 -21
- package/dist/_exports/config.d.ts +5 -661
- package/dist/_exports/debug.d.ts +4 -8
- package/dist/_exports/debug.js +3 -3
- package/dist/_exports/debug.js.map +1 -1
- package/dist/_exports/errors.d.ts +12 -77
- package/dist/_exports/index.d.ts +34 -1674
- package/dist/_exports/package-manager.d.ts +14 -207
- package/dist/_exports/request.d.ts +52 -69
- package/dist/_exports/request.js +5 -4
- package/dist/_exports/request.js.map +1 -1
- package/dist/_exports/schemas.d.ts +2 -235
- package/dist/_exports/tasks.d.ts +2 -120
- package/dist/_exports/telemetry.d.ts +2 -156
- package/dist/_exports/types.d.ts +9 -475
- package/dist/_exports/undeploy.d.ts +38 -51
- package/dist/_exports/util.d.ts +6 -137
- package/dist/_exports/ux.d.ts +31 -102
- package/dist/apiClient-DXlF5ZV3.d.ts +65 -0
- package/dist/apiClient.d.ts +2 -79
- package/dist/apiClient.js +69 -47
- package/dist/apiClient.js.map +1 -1
- package/dist/cliConfig-CbW8neMv.d.ts +171 -0
- package/dist/errors/enrichAuthError.js +48 -0
- package/dist/errors/enrichAuthError.js.map +1 -0
- package/dist/errors/getErrorMessage.js +3 -1
- package/dist/errors/getErrorMessage.js.map +1 -1
- package/dist/executionContext.d.ts +21 -20
- package/dist/executionContext.js.map +1 -1
- package/dist/exitCodes.d.ts +3 -3
- package/dist/findStudioConfigPath-DcKlHhyW.d.ts +265 -0
- package/dist/getWorkspace-CU32E6Uo.d.ts +54 -0
- package/dist/mockBrowserEnvironment-BjFQPb2W.d.ts +19 -0
- package/dist/noopTelemetry-BJRIvASI.d.ts +64 -0
- package/dist/readPackageJson-Cr_lbjVR.d.ts +67 -0
- package/dist/recursivelyResolveProjectRoot-BE54uEP6.d.ts +18 -0
- package/dist/request/createRequester.js +39 -50
- package/dist/request/createRequester.js.map +1 -1
- package/dist/request/nodeReadableFromWeb.js +64 -0
- package/dist/request/nodeReadableFromWeb.js.map +1 -0
- package/dist/resolveLocalPackage-Dr-TNTyk.d.ts +78 -0
- package/dist/safeStructuredClone-CWB0MXmH.d.ts +58 -0
- package/dist/schemas-DRCVXpyW.d.ts +140 -0
- package/dist/timer-Dwu2TIgB.d.ts +14 -0
- package/dist/tsxWorkerTask-CxG3fWbU.d.ts +97 -0
- package/dist/types-CwJLTYDj.d.ts +23 -0
- package/dist/types-ZNH3prAd.d.ts +91 -0
- package/dist/workbenchApp-Dhtbsuhn.d.ts +22 -0
- package/package.json +9 -10
- package/dist/request/createIsolatedRequester.js +0 -75
- package/dist/request/createIsolatedRequester.js.map +0 -1
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the base Sanity configuration directory for the current user.
|
|
3
|
+
* For persistent user settings (auth tokens, preferences, etc.).
|
|
4
|
+
* Respects `SANITY_INTERNAL_ENV=staging` to isolate staging instances.
|
|
5
|
+
*
|
|
6
|
+
* Layout: `~/.config/sanity{-staging}/`
|
|
7
|
+
*
|
|
8
|
+
* @returns Absolute path to the config directory
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
declare function getSanityConfigDir(): string;
|
|
12
|
+
/**
|
|
13
|
+
* Returns the base Sanity data directory for the current user.
|
|
14
|
+
* For ephemeral runtime state (dev-server registries, caches, etc.).
|
|
15
|
+
* Respects `SANITY_INTERNAL_ENV=staging` to isolate staging instances.
|
|
16
|
+
*
|
|
17
|
+
* Layout: `~/.sanity{-staging}/`
|
|
18
|
+
*
|
|
19
|
+
* @returns Absolute path to the data directory
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
declare function getSanityDataDir(): string;
|
|
23
|
+
/**
|
|
24
|
+
* Gets an environment variable with the appropriate Sanity prefix based on whether it's an app or studio.
|
|
25
|
+
*
|
|
26
|
+
* @param suffix - The suffix for the environment variable (e.g., 'SERVER_HOSTNAME')
|
|
27
|
+
* @param isApp - Whether to use the app prefix (SANITY_APP_) or studio prefix (SANITY_STUDIO_)
|
|
28
|
+
* @returns The value of the environment variable, or undefined if not set
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* // For studio: SANITY_STUDIO_SERVER_HOSTNAME
|
|
33
|
+
* const studioHostname = getSanityEnvVar('SERVER_HOSTNAME', false)
|
|
34
|
+
*
|
|
35
|
+
* // For app: SANITY_APP_SERVER_HOSTNAME
|
|
36
|
+
* const appHostname = getSanityEnvVar('SERVER_HOSTNAME', true)
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
declare function getSanityEnvVar(suffix: string, isApp: boolean): string | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* @internal
|
|
44
|
+
* @returns The Sanity URL for the given path, using the correct domain based on the environment
|
|
45
|
+
*/
|
|
46
|
+
declare function getSanityUrl(path?: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
declare function getWorkspace<T extends {
|
|
51
|
+
name: string;
|
|
52
|
+
}>(workspaces: T[], workspaceName?: string): T;
|
|
53
|
+
export { getSanityDataDir as a, getSanityConfigDir as i, getSanityUrl as n, getSanityEnvVar as r, getWorkspace as t };
|
|
54
|
+
//# sourceMappingURL=getWorkspace-CU32E6Uo.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mocks a browser-like environment for processes in the main thread by:
|
|
3
|
+
* - Injecting browser globals (window, document, ResizeObserver, etc.)
|
|
4
|
+
* - Loading studio environment variables from the project's sanity installation into process.env
|
|
5
|
+
*
|
|
6
|
+
* This is useful for commands like `sanity exec` that have to run user scripts
|
|
7
|
+
* in the main thread of the process (but in a child process).
|
|
8
|
+
*
|
|
9
|
+
* Be cautious when using this, since it will pollute the global namespace with browser globals.
|
|
10
|
+
*
|
|
11
|
+
* If your code can run in a worker thread, you should use the `studioWorkerTask` function instead.
|
|
12
|
+
*
|
|
13
|
+
* @param basePath - The root path of the Sanity Studio project
|
|
14
|
+
* @returns A cleanup function that removes the injected globals and environment variables
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
declare function mockBrowserEnvironment(basePath: string): Promise<() => void>;
|
|
18
|
+
export { mockBrowserEnvironment as t };
|
|
19
|
+
//# sourceMappingURL=mockBrowserEnvironment-BjFQPb2W.d.ts.map
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { t as CLITelemetryStore } from "./types-ZNH3prAd.js";
|
|
2
|
+
/**
|
|
3
|
+
* @public
|
|
4
|
+
* Symbol used to store CLI telemetry state on globalThis.
|
|
5
|
+
* Use the accessor functions instead of accessing this directly.
|
|
6
|
+
*/
|
|
7
|
+
declare const CLI_TELEMETRY_SYMBOL: unique symbol;
|
|
8
|
+
type TraceErrorReporter = (error: Error) => void;
|
|
9
|
+
/**
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
declare function getCliTelemetry(): CLITelemetryStore;
|
|
13
|
+
/**
|
|
14
|
+
* Sets the global CLI telemetry state.
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
declare function setCliTelemetry(telemetry: CLITelemetryStore, options?: {
|
|
18
|
+
reportTraceError?: TraceErrorReporter;
|
|
19
|
+
}): void;
|
|
20
|
+
/**
|
|
21
|
+
* Reports an error to the CLI command trace. Called from SanityCommand.catch()
|
|
22
|
+
* for real command errors (not user aborts).
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
declare function reportCliTraceError(error: Error): void;
|
|
26
|
+
/**
|
|
27
|
+
* Clears the global CLI telemetry store.
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
declare function clearCliTelemetry(): void;
|
|
31
|
+
/**
|
|
32
|
+
* Base information needed for telemetry file operations.
|
|
33
|
+
* Contains common data used by both file path generation and pattern matching.
|
|
34
|
+
*/
|
|
35
|
+
interface TelemetryBaseInfo {
|
|
36
|
+
/** Base filename pattern without sessionId suffix */
|
|
37
|
+
basePattern: string;
|
|
38
|
+
/** Base directory where telemetry files are stored */
|
|
39
|
+
directory: string;
|
|
40
|
+
/** Environment: 'staging' or 'production' */
|
|
41
|
+
environment: string;
|
|
42
|
+
/** Hashed token (first 8 chars of SHA256) for privacy */
|
|
43
|
+
hashedToken: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Gets the base telemetry information needed for file operations.
|
|
47
|
+
*
|
|
48
|
+
* This shared utility extracts common logic used by:
|
|
49
|
+
* - `generateTelemetryFilePath` - for generating session-specific file paths
|
|
50
|
+
* - `findTelemetryFiles` - for discovering all telemetry files via glob patterns
|
|
51
|
+
*
|
|
52
|
+
* @returns Promise resolving to base telemetry information
|
|
53
|
+
* @throws Error if no auth token is found
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
56
|
+
declare function getTelemetryBaseInfo(): Promise<TelemetryBaseInfo>;
|
|
57
|
+
/**
|
|
58
|
+
* Fallback logger used when telemetry has not been initialized.
|
|
59
|
+
* Exported for use in tests only — do not use in plugins or external code.
|
|
60
|
+
* @internal
|
|
61
|
+
*/
|
|
62
|
+
declare const noopLogger: CLITelemetryStore;
|
|
63
|
+
export { getCliTelemetry as a, clearCliTelemetry as i, getTelemetryBaseInfo as n, reportCliTraceError as o, CLI_TELEMETRY_SYMBOL as r, setCliTelemetry as s, noopLogger as t };
|
|
64
|
+
//# sourceMappingURL=noopTelemetry-BJRIvASI.d.ts.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { z } from "zod/mini";
|
|
2
|
+
/**
|
|
3
|
+
* Comprehensive package.json schema including all common properties.
|
|
4
|
+
* Feel free to add properties to this,
|
|
5
|
+
* 🟠ℹ️ BUT ENSURE OPTIONAL STUFF IS ACTUALLY OPTIONAL ℹ️🟠
|
|
6
|
+
* 🟠ℹ️ SINCE THIS IS USED IN A NUMBER OF LOCATIONS WHERE ℹ️🟠
|
|
7
|
+
* 🟠ℹ️ WE CANNOT ENFORCE/GUARANTEE ANY PARTICULAR PROPS ℹ️🟠
|
|
8
|
+
*/
|
|
9
|
+
declare const packageJsonSchema: z.ZodMiniObject<{
|
|
10
|
+
name: z.ZodMiniString<string>;
|
|
11
|
+
version: z.ZodMiniString<string>;
|
|
12
|
+
dependencies: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>>;
|
|
13
|
+
devDependencies: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>>;
|
|
14
|
+
peerDependencies: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>>;
|
|
15
|
+
exports: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniAny>>;
|
|
16
|
+
main: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
17
|
+
types: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
18
|
+
author: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
19
|
+
description: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
20
|
+
engines: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>>;
|
|
21
|
+
license: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
22
|
+
private: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
|
|
23
|
+
repository: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
24
|
+
type: z.ZodMiniString<string>;
|
|
25
|
+
url: z.ZodMiniString<string>;
|
|
26
|
+
}, z.core.$strip>>;
|
|
27
|
+
scripts: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>>;
|
|
28
|
+
type: z.ZodMiniOptional<z.ZodMiniEnum<{
|
|
29
|
+
module: "module";
|
|
30
|
+
commonjs: "commonjs";
|
|
31
|
+
}>>;
|
|
32
|
+
}, z.core.$loose>;
|
|
33
|
+
/**
|
|
34
|
+
* Comprehensive representation of a package.json file.
|
|
35
|
+
* Consolidates all properties from previous type definitions.
|
|
36
|
+
*
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
type PackageJson = z.infer<typeof packageJsonSchema>;
|
|
40
|
+
/**
|
|
41
|
+
* Options for reading package.json files
|
|
42
|
+
*
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
interface ReadPackageJsonOptions {
|
|
46
|
+
/**
|
|
47
|
+
* Default values to merge with the parsed package.json.
|
|
48
|
+
* Parsed values take precedence over defaults.
|
|
49
|
+
*/
|
|
50
|
+
defaults?: Partial<PackageJson>;
|
|
51
|
+
/**
|
|
52
|
+
* Skip Zod schema validation. When true, the file is parsed but not validated.
|
|
53
|
+
* Defaults to false.
|
|
54
|
+
*/
|
|
55
|
+
skipSchemaValidation?: boolean;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Read the `package.json` file at the given path
|
|
59
|
+
*
|
|
60
|
+
* @param filePath - Path to package.json to read
|
|
61
|
+
* @param options - Options object for controlling read behavior
|
|
62
|
+
* @returns The parsed package.json
|
|
63
|
+
* @public
|
|
64
|
+
*/
|
|
65
|
+
declare function readPackageJson(filePath: string | URL, options?: ReadPackageJsonOptions): Promise<PackageJson>;
|
|
66
|
+
export { ReadPackageJsonOptions as n, readPackageJson as r, PackageJson as t };
|
|
67
|
+
//# sourceMappingURL=readPackageJson-Cr_lbjVR.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result of finding a project configuration
|
|
3
|
+
*
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
interface ProjectRootResult {
|
|
7
|
+
directory: string;
|
|
8
|
+
/**
|
|
9
|
+
* Path to the project configuration file, if found.
|
|
10
|
+
*/
|
|
11
|
+
path: string;
|
|
12
|
+
/**
|
|
13
|
+
* Type of project root.
|
|
14
|
+
*/
|
|
15
|
+
type: 'app' | 'studio';
|
|
16
|
+
}
|
|
17
|
+
export { ProjectRootResult as t };
|
|
18
|
+
//# sourceMappingURL=recursivelyResolveProjectRoot-BE54uEP6.d.ts.map
|
|
@@ -1,67 +1,56 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { up as packageUp } from 'empathic/package';
|
|
3
|
-
import {
|
|
4
|
-
import { debug
|
|
3
|
+
import { createRequester as createGetItRequester } from 'get-it';
|
|
4
|
+
import { debug as debugMiddleware } from 'get-it/middleware';
|
|
5
|
+
import { createDebug } from 'obug';
|
|
5
6
|
import { getCliExecutionContext } from '../executionContext.js';
|
|
6
7
|
let cachedPkg;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*
|
|
10
|
-
* Default middleware (in order):
|
|
11
|
-
* 1. `httpErrors()` — throw on HTTP error status codes
|
|
12
|
-
* 2. `headers({'User-Agent': '@sanity/cli-core@<version>'})` — identify CLI requests
|
|
13
|
-
* 3. `debug({verbose: true, namespace: 'sanity:cli'})` — debug logging
|
|
14
|
-
* 4. `promise({onlyBody: true})` — return body directly (must be last)
|
|
15
|
-
*
|
|
16
|
-
* @param options - Optional configuration to disable or customize middleware
|
|
17
|
-
* @returns A configured `get-it` requester
|
|
18
|
-
* @public
|
|
19
|
-
*/ export function createRequester(options) {
|
|
20
|
-
const opts = options?.middleware;
|
|
21
|
-
const middleware = [];
|
|
22
|
-
// 1. httpErrors
|
|
23
|
-
if (opts?.httpErrors !== false) {
|
|
24
|
-
middleware.push(httpErrors());
|
|
25
|
-
}
|
|
26
|
-
// 2. headers
|
|
27
|
-
if (opts?.headers !== false) {
|
|
28
|
-
const customHeaders = typeof opts?.headers === 'object' ? opts.headers : {};
|
|
29
|
-
const allHeaders = customHeaders['User-Agent'] ? {
|
|
30
|
-
...customHeaders
|
|
31
|
-
} : {
|
|
32
|
-
get ['User-Agent'] () {
|
|
33
|
-
const pkg = getPackageInfo();
|
|
34
|
-
return `${pkg.name}@${pkg.version}`;
|
|
35
|
-
},
|
|
36
|
-
...customHeaders
|
|
37
|
-
};
|
|
38
|
-
middleware.push(headers(allHeaders));
|
|
39
|
-
}
|
|
40
|
-
// 3. debug
|
|
8
|
+
export function createRequester(options) {
|
|
9
|
+
const { debug, headers, middleware = [], ...getItOptions } = options ?? {};
|
|
41
10
|
// A programmatic invocation must not inherit the embedding process's DEBUG setting or write request/response bodies outside its output sinks.
|
|
42
|
-
|
|
11
|
+
const resolvedMiddleware = [
|
|
12
|
+
...middleware
|
|
13
|
+
];
|
|
14
|
+
if (!getCliExecutionContext() && debug !== false) {
|
|
43
15
|
const debugDefaults = {
|
|
44
16
|
namespace: 'sanity:cli',
|
|
45
17
|
verbose: true
|
|
46
18
|
};
|
|
47
|
-
const customDebug = typeof
|
|
48
|
-
|
|
19
|
+
const customDebug = typeof debug === 'object' ? debug : {};
|
|
20
|
+
const { namespace, verbose } = {
|
|
49
21
|
...debugDefaults,
|
|
50
22
|
...customDebug
|
|
51
|
-
}));
|
|
52
|
-
}
|
|
53
|
-
// 4. promise (must be last)
|
|
54
|
-
if (opts?.promise !== false) {
|
|
55
|
-
const promiseDefaults = {
|
|
56
|
-
onlyBody: true
|
|
57
23
|
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
...customPromise
|
|
24
|
+
resolvedMiddleware.push(debugMiddleware({
|
|
25
|
+
log: createDebug(namespace),
|
|
26
|
+
verbose
|
|
62
27
|
}));
|
|
63
28
|
}
|
|
64
|
-
return
|
|
29
|
+
return createGetItRequester({
|
|
30
|
+
...getItOptions,
|
|
31
|
+
headers: resolveDefaultHeaders(headers),
|
|
32
|
+
middleware: resolvedMiddleware
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Builds default headers, including a lazy User-Agent unless overridden or disabled.
|
|
37
|
+
*
|
|
38
|
+
* @internal
|
|
39
|
+
*/ function resolveDefaultHeaders(headers) {
|
|
40
|
+
if (headers === false) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
const customHeaders = typeof headers === 'object' ? headers : {};
|
|
44
|
+
if (Object.keys(customHeaders).some((header)=>header.toLowerCase() === 'user-agent')) {
|
|
45
|
+
return customHeaders;
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
get ['User-Agent'] () {
|
|
49
|
+
const pkg = getPackageInfo();
|
|
50
|
+
return `${pkg.name}@${pkg.version}`;
|
|
51
|
+
},
|
|
52
|
+
...customHeaders
|
|
53
|
+
};
|
|
65
54
|
}
|
|
66
55
|
/**
|
|
67
56
|
* Reads the nearest `package.json` to determine the name and version of the `@sanity/cli-core` package.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/request/createRequester.ts"],"sourcesContent":["import {readFileSync} from 'node:fs'\n\nimport {up as packageUp} from 'empathic/package'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/request/createRequester.ts"],"sourcesContent":["import {readFileSync} from 'node:fs'\n\nimport {up as packageUp} from 'empathic/package'\nimport {\n createRequester as createGetItRequester,\n type FetchHeaders,\n type RequesterOptions,\n type RequestFunction,\n type TransformMiddleware,\n type WrappingMiddleware,\n} from 'get-it'\nimport {debug as debugMiddleware} from 'get-it/middleware'\nimport {createDebug} from 'obug'\n\nimport {getCliExecutionContext} from '../executionContext.js'\n\nlet cachedPkg: {name: string; version: string} | undefined\n\n/**\n * Options for creating a Sanity CLI requester.\n *\n * Extends get-it v9's {@link RequesterOptions} with Sanity CLI defaults for\n * User-Agent headers and debug logging.\n *\n * @public\n */\nexport type CreateRequesterOptions = Omit<RequesterOptions, 'headers'> & {\n /**\n * Debug logging middleware. Defaults to enabled with namespace `sanity:cli`.\n * Pass `false` to disable.\n */\n debug?: false | {namespace?: string; verbose?: boolean}\n /**\n * Default headers for all requests.\n * Omitting uses a lazy User-Agent of `@sanity/cli-core@<version>`.\n * Pass `false` to send no default headers.\n */\n headers?: false | Record<string, string>\n}\n\n/**\n * Creates a get-it requester with Sanity CLI defaults.\n *\n * Defaults:\n * - User-Agent header: `@sanity/cli-core@<version>` (lazy)\n * - Debug logging via `DEBUG=sanity:cli` (verbose)\n * - HTTP error throwing on (get-it default)\n *\n * @param options - Optional configuration to customize or disable defaults\n * @returns A configured get-it request function\n * @public\n */\nexport function createRequester(\n options: CreateRequesterOptions & {as: 'json'},\n): RequestFunction<'json'>\nexport function createRequester(\n options: CreateRequesterOptions & {as: 'text'},\n): RequestFunction<'text'>\nexport function createRequester(\n options: CreateRequesterOptions & {as: 'stream'},\n): RequestFunction<'stream'>\nexport function createRequester(options?: CreateRequesterOptions): RequestFunction\nexport function createRequester(\n options?: CreateRequesterOptions,\n): RequestFunction<'json' | 'stream' | 'text' | undefined> {\n const {debug, headers, middleware = [], ...getItOptions} = options ?? {}\n\n // A programmatic invocation must not inherit the embedding process's DEBUG setting or write request/response bodies outside its output sinks.\n const resolvedMiddleware: Array<TransformMiddleware | WrappingMiddleware> = [...middleware]\n if (!getCliExecutionContext() && debug !== false) {\n const debugDefaults = {namespace: 'sanity:cli', verbose: true}\n const customDebug = typeof debug === 'object' ? debug : {}\n const {namespace, verbose} = {...debugDefaults, ...customDebug}\n resolvedMiddleware.push(debugMiddleware({log: createDebug(namespace), verbose}))\n }\n\n return createGetItRequester({\n ...getItOptions,\n headers: resolveDefaultHeaders(headers),\n middleware: resolvedMiddleware,\n })\n}\n\n/**\n * Builds default headers, including a lazy User-Agent unless overridden or disabled.\n *\n * @internal\n */\nfunction resolveDefaultHeaders(\n headers: false | Record<string, string> | undefined,\n): FetchHeaders | undefined {\n if (headers === false) {\n return undefined\n }\n\n const customHeaders = typeof headers === 'object' ? headers : {}\n if (Object.keys(customHeaders).some((header) => header.toLowerCase() === 'user-agent')) {\n return customHeaders\n }\n\n return {\n get ['User-Agent']() {\n const pkg = getPackageInfo()\n return `${pkg.name}@${pkg.version}`\n },\n ...customHeaders,\n }\n}\n\n/**\n * Reads the nearest `package.json` to determine the name and version of the `@sanity/cli-core` package.\n *\n * @returns The name and version of the package\n * @internal\n */\nfunction getPackageInfo(): {name: string; version: string} {\n if (cachedPkg) return cachedPkg\n\n const pkgPath = packageUp({cwd: import.meta.dirname})\n if (!pkgPath) {\n throw new Error('Unable to resolve @sanity/cli-core package root')\n }\n\n const packageJson = JSON.parse(readFileSync(pkgPath, 'utf8'))\n cachedPkg = {\n name: packageJson.name ?? '@sanity/cli-core',\n version: packageJson.version ?? '0.0.0',\n }\n return cachedPkg\n}\n"],"names":["readFileSync","up","packageUp","createRequester","createGetItRequester","debug","debugMiddleware","createDebug","getCliExecutionContext","cachedPkg","options","headers","middleware","getItOptions","resolvedMiddleware","debugDefaults","namespace","verbose","customDebug","push","log","resolveDefaultHeaders","undefined","customHeaders","Object","keys","some","header","toLowerCase","pkg","getPackageInfo","name","version","pkgPath","cwd","dirname","Error","packageJson","JSON","parse"],"mappings":"AAAA,SAAQA,YAAY,QAAO,UAAS;AAEpC,SAAQC,MAAMC,SAAS,QAAO,mBAAkB;AAChD,SACEC,mBAAmBC,oBAAoB,QAMlC,SAAQ;AACf,SAAQC,SAASC,eAAe,QAAO,oBAAmB;AAC1D,SAAQC,WAAW,QAAO,OAAM;AAEhC,SAAQC,sBAAsB,QAAO,yBAAwB;AAE7D,IAAIC;AA8CJ,OAAO,SAASN,gBACdO,OAAgC;IAEhC,MAAM,EAACL,KAAK,EAAEM,OAAO,EAAEC,aAAa,EAAE,EAAE,GAAGC,cAAa,GAAGH,WAAW,CAAC;IAEvE,8IAA8I;IAC9I,MAAMI,qBAAsE;WAAIF;KAAW;IAC3F,IAAI,CAACJ,4BAA4BH,UAAU,OAAO;QAChD,MAAMU,gBAAgB;YAACC,WAAW;YAAcC,SAAS;QAAI;QAC7D,MAAMC,cAAc,OAAOb,UAAU,WAAWA,QAAQ,CAAC;QACzD,MAAM,EAACW,SAAS,EAAEC,OAAO,EAAC,GAAG;YAAC,GAAGF,aAAa;YAAE,GAAGG,WAAW;QAAA;QAC9DJ,mBAAmBK,IAAI,CAACb,gBAAgB;YAACc,KAAKb,YAAYS;YAAYC;QAAO;IAC/E;IAEA,OAAOb,qBAAqB;QAC1B,GAAGS,YAAY;QACfF,SAASU,sBAAsBV;QAC/BC,YAAYE;IACd;AACF;AAEA;;;;CAIC,GACD,SAASO,sBACPV,OAAmD;IAEnD,IAAIA,YAAY,OAAO;QACrB,OAAOW;IACT;IAEA,MAAMC,gBAAgB,OAAOZ,YAAY,WAAWA,UAAU,CAAC;IAC/D,IAAIa,OAAOC,IAAI,CAACF,eAAeG,IAAI,CAAC,CAACC,SAAWA,OAAOC,WAAW,OAAO,eAAe;QACtF,OAAOL;IACT;IAEA,OAAO;QACL,IAAI,CAAC,aAAa,IAAG;YACnB,MAAMM,MAAMC;YACZ,OAAO,GAAGD,IAAIE,IAAI,CAAC,CAAC,EAAEF,IAAIG,OAAO,EAAE;QACrC;QACA,GAAGT,aAAa;IAClB;AACF;AAEA;;;;;CAKC,GACD,SAASO;IACP,IAAIrB,WAAW,OAAOA;IAEtB,MAAMwB,UAAU/B,UAAU;QAACgC,KAAK,YAAYC,OAAO;IAAA;IACnD,IAAI,CAACF,SAAS;QACZ,MAAM,IAAIG,MAAM;IAClB;IAEA,MAAMC,cAAcC,KAAKC,KAAK,CAACvC,aAAaiC,SAAS;IACrDxB,YAAY;QACVsB,MAAMM,YAAYN,IAAI,IAAI;QAC1BC,SAASK,YAAYL,OAAO,IAAI;IAClC;IACA,OAAOvB;AACT"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Readable } from 'node:stream';
|
|
2
|
+
/**
|
|
3
|
+
* Convert a Web `ReadableStream` to a Node.js `Readable`.
|
|
4
|
+
*
|
|
5
|
+
* Prefer this over `Readable.fromWeb()` while the CLI engines range includes
|
|
6
|
+
* Node versions where `fromWeb` is still experimental (`>=22.12 <22.17`).
|
|
7
|
+
*
|
|
8
|
+
* @param stream - Web readable stream of bytes
|
|
9
|
+
* @returns A Node.js readable stream yielding the same chunks
|
|
10
|
+
* @public
|
|
11
|
+
*/ export function nodeReadableFromWeb(stream) {
|
|
12
|
+
const reader = stream.getReader();
|
|
13
|
+
let reading = false;
|
|
14
|
+
let ended = false;
|
|
15
|
+
let released = false;
|
|
16
|
+
const releaseLock = ()=>{
|
|
17
|
+
if (released) return;
|
|
18
|
+
released = true;
|
|
19
|
+
reader.releaseLock();
|
|
20
|
+
};
|
|
21
|
+
return new Readable({
|
|
22
|
+
destroy (error, callback) {
|
|
23
|
+
if (ended) {
|
|
24
|
+
releaseLock();
|
|
25
|
+
callback(error);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
ended = true;
|
|
29
|
+
reader.cancel(error ?? undefined).then(()=>{
|
|
30
|
+
releaseLock();
|
|
31
|
+
callback(error);
|
|
32
|
+
}, (cancelError)=>{
|
|
33
|
+
releaseLock();
|
|
34
|
+
callback(error ?? toError(cancelError));
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
read () {
|
|
38
|
+
if (reading || ended) return;
|
|
39
|
+
reading = true;
|
|
40
|
+
reader.read().then(({ done, value })=>{
|
|
41
|
+
reading = false;
|
|
42
|
+
if (ended) return;
|
|
43
|
+
if (done) {
|
|
44
|
+
ended = true;
|
|
45
|
+
releaseLock();
|
|
46
|
+
this.push(null);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
this.push(value);
|
|
50
|
+
}, (error)=>{
|
|
51
|
+
reading = false;
|
|
52
|
+
if (ended) return;
|
|
53
|
+
ended = true;
|
|
54
|
+
releaseLock();
|
|
55
|
+
this.destroy(toError(error));
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function toError(error) {
|
|
61
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=nodeReadableFromWeb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/request/nodeReadableFromWeb.ts"],"sourcesContent":["import {Readable} from 'node:stream'\n\n/**\n * Convert a Web `ReadableStream` to a Node.js `Readable`.\n *\n * Prefer this over `Readable.fromWeb()` while the CLI engines range includes\n * Node versions where `fromWeb` is still experimental (`>=22.12 <22.17`).\n *\n * @param stream - Web readable stream of bytes\n * @returns A Node.js readable stream yielding the same chunks\n * @public\n */\nexport function nodeReadableFromWeb(stream: ReadableStream<Uint8Array>): Readable {\n const reader = stream.getReader()\n let reading = false\n let ended = false\n let released = false\n\n const releaseLock = () => {\n if (released) return\n released = true\n reader.releaseLock()\n }\n\n return new Readable({\n destroy(error, callback) {\n if (ended) {\n releaseLock()\n callback(error)\n return\n }\n\n ended = true\n reader.cancel(error ?? undefined).then(\n () => {\n releaseLock()\n callback(error)\n },\n (cancelError: unknown) => {\n releaseLock()\n callback(error ?? toError(cancelError))\n },\n )\n },\n read() {\n if (reading || ended) return\n reading = true\n reader.read().then(\n ({done, value}) => {\n reading = false\n if (ended) return\n if (done) {\n ended = true\n releaseLock()\n this.push(null)\n return\n }\n this.push(value)\n },\n (error: unknown) => {\n reading = false\n if (ended) return\n ended = true\n releaseLock()\n this.destroy(toError(error))\n },\n )\n },\n })\n}\n\nfunction toError(error: unknown): Error {\n return error instanceof Error ? error : new Error(String(error))\n}\n"],"names":["Readable","nodeReadableFromWeb","stream","reader","getReader","reading","ended","released","releaseLock","destroy","error","callback","cancel","undefined","then","cancelError","toError","read","done","value","push","Error","String"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,cAAa;AAEpC;;;;;;;;;CASC,GACD,OAAO,SAASC,oBAAoBC,MAAkC;IACpE,MAAMC,SAASD,OAAOE,SAAS;IAC/B,IAAIC,UAAU;IACd,IAAIC,QAAQ;IACZ,IAAIC,WAAW;IAEf,MAAMC,cAAc;QAClB,IAAID,UAAU;QACdA,WAAW;QACXJ,OAAOK,WAAW;IACpB;IAEA,OAAO,IAAIR,SAAS;QAClBS,SAAQC,KAAK,EAAEC,QAAQ;YACrB,IAAIL,OAAO;gBACTE;gBACAG,SAASD;gBACT;YACF;YAEAJ,QAAQ;YACRH,OAAOS,MAAM,CAACF,SAASG,WAAWC,IAAI,CACpC;gBACEN;gBACAG,SAASD;YACX,GACA,CAACK;gBACCP;gBACAG,SAASD,SAASM,QAAQD;YAC5B;QAEJ;QACAE;YACE,IAAIZ,WAAWC,OAAO;YACtBD,UAAU;YACVF,OAAOc,IAAI,GAAGH,IAAI,CAChB,CAAC,EAACI,IAAI,EAAEC,KAAK,EAAC;gBACZd,UAAU;gBACV,IAAIC,OAAO;gBACX,IAAIY,MAAM;oBACRZ,QAAQ;oBACRE;oBACA,IAAI,CAACY,IAAI,CAAC;oBACV;gBACF;gBACA,IAAI,CAACA,IAAI,CAACD;YACZ,GACA,CAACT;gBACCL,UAAU;gBACV,IAAIC,OAAO;gBACXA,QAAQ;gBACRE;gBACA,IAAI,CAACC,OAAO,CAACO,QAAQN;YACvB;QAEJ;IACF;AACF;AAEA,SAASM,QAAQN,KAAc;IAC7B,OAAOA,iBAAiBW,QAAQX,QAAQ,IAAIW,MAAMC,OAAOZ;AAC3D"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the version of a package installed locally.
|
|
3
|
+
*
|
|
4
|
+
* @param moduleName - The name of the package in npm.
|
|
5
|
+
* @param workDir - The working directory to resolve the module from. (aka project root)
|
|
6
|
+
* @returns The version of the package installed locally.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
declare function getLocalPackageVersion(moduleName: string, workDir: string): Promise<string | null>;
|
|
10
|
+
/**
|
|
11
|
+
* Resolve the filesystem directory of a locally installed package using Node
|
|
12
|
+
* module resolution. Works correctly with hoisted packages in monorepos/workspaces,
|
|
13
|
+
* pnpm symlinks, and other non-standard node_modules layouts.
|
|
14
|
+
*
|
|
15
|
+
* @param moduleName - The name of the package in npm.
|
|
16
|
+
* @param workDir - The working directory to resolve the module from. (aka project root)
|
|
17
|
+
* @returns The absolute path to the package directory.
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
declare function getLocalPackageDir(moduleName: string, workDir: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Resolves and imports a package from the local project's node_modules,
|
|
23
|
+
* relative to the given working directory. This avoids circular dependencies
|
|
24
|
+
* and ensures the correct version of the package is used.
|
|
25
|
+
*
|
|
26
|
+
* @param packageName - The name of the package to resolve (e.g., 'sanity')
|
|
27
|
+
* @param workDir - The working directory to resolve the package from
|
|
28
|
+
* @returns The imported module
|
|
29
|
+
* @throws If the package cannot be resolved or imported
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* const {createSchema} = await resolveLocalPackage('sanity', workDir)
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
declare function resolveLocalPackage<T = unknown>(packageName: string, workDir: string): Promise<T>;
|
|
39
|
+
/**
|
|
40
|
+
* Resolves the URL of a package from the local project's node_modules,
|
|
41
|
+
* relative to the given working directory, without importing it.
|
|
42
|
+
*
|
|
43
|
+
* @param packageName - The name of the package to resolve (e.g., 'sanity')
|
|
44
|
+
* @param workDir - The working directory to resolve the package from
|
|
45
|
+
* @returns The resolved URL of the package entry point
|
|
46
|
+
* @throws If the package cannot be resolved
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* // Resolve a transitive dependency via its parent package:
|
|
51
|
+
* const sanityUrl = resolveLocalPackagePath('sanity', workDir)
|
|
52
|
+
* const uiUrl = resolveLocalPackagePathFrom('@sanity/ui', sanityUrl)
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
declare function resolveLocalPackagePath(packageName: string, workDir: string): URL;
|
|
58
|
+
/**
|
|
59
|
+
* Resolves and imports a package relative to another resolved module URL.
|
|
60
|
+
* Useful for resolving transitive dependencies that may not be directly
|
|
61
|
+
* accessible from the project root (e.g., in pnpm strict mode).
|
|
62
|
+
*
|
|
63
|
+
* @param packageName - The name of the package to resolve
|
|
64
|
+
* @param parentUrl - The URL of the parent module to resolve from
|
|
65
|
+
* @returns The imported module
|
|
66
|
+
* @throws If the package cannot be resolved or imported
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* const sanityUrl = resolveLocalPackagePath('sanity', workDir)
|
|
71
|
+
* const ui = await resolveLocalPackageFrom<typeof import('@sanity/ui')>('@sanity/ui', sanityUrl)
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* @internal
|
|
75
|
+
*/
|
|
76
|
+
declare function resolveLocalPackageFrom<T = unknown>(packageName: string, parentUrl: URL): Promise<T>;
|
|
77
|
+
export { getLocalPackageVersion as a, getLocalPackageDir as i, resolveLocalPackageFrom as n, resolveLocalPackagePath as r, resolveLocalPackage as t };
|
|
78
|
+
//# sourceMappingURL=resolveLocalPackage-Dr-TNTyk.d.ts.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function is a replacement for built in dynamic import
|
|
3
|
+
* This handles the case for windows file paths especially for absolute paths.
|
|
4
|
+
*
|
|
5
|
+
* @param source - File path
|
|
6
|
+
*/
|
|
7
|
+
declare function doImport(source: string): Promise<any>;
|
|
8
|
+
interface ImportModuleOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Whether to return the default export of the module.
|
|
11
|
+
* Default: true
|
|
12
|
+
*/
|
|
13
|
+
default?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Path to the tsconfig file to use for the import. If not provided, the tsconfig
|
|
16
|
+
* will be inferred from the nearest `tsconfig.json` file.
|
|
17
|
+
*/
|
|
18
|
+
tsconfigPath?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Imports a module using jiti and returns its exports.
|
|
22
|
+
* This is a thin wrapper around tsx to allow swapping out the underlying implementation in the future if needed.
|
|
23
|
+
*
|
|
24
|
+
* @param filePath - Path to the module to import.
|
|
25
|
+
* @param options - Options for the importModule function.
|
|
26
|
+
* @returns The exported module.
|
|
27
|
+
*
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
declare function importModule<T = unknown>(filePath: string | URL, options?: ImportModuleOptions): Promise<T>;
|
|
31
|
+
declare const isCi: () => boolean;
|
|
32
|
+
declare function isInteractive(): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Checks if the environment is staging.
|
|
35
|
+
*
|
|
36
|
+
* @returns True if the environment is staging, false otherwise
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
declare function isStaging(): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Normalizes a path for cross-platform comparison by converting backslashes to forward slashes.
|
|
42
|
+
* Useful for converting windows paths to unix paths.
|
|
43
|
+
*
|
|
44
|
+
* @param path - Path to normalize
|
|
45
|
+
* @returns Normalized path with forward slashes
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
declare function normalizePath(path: string): string;
|
|
49
|
+
/**
|
|
50
|
+
* `structuredClone()`, but doesn't throw on non-clonable values - instead it drops them.
|
|
51
|
+
*
|
|
52
|
+
* @param obj - The object to clone.
|
|
53
|
+
* @returns The cloned object.
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
56
|
+
declare function safeStructuredClone<T>(obj: T): T;
|
|
57
|
+
export { isCi as a, isInteractive as i, normalizePath as n, importModule as o, isStaging as r, doImport as s, safeStructuredClone as t };
|
|
58
|
+
//# sourceMappingURL=safeStructuredClone-CWB0MXmH.d.ts.map
|