@sanity/cli-core 0.0.0-20260612071721 → 0.0.0-20260612080517
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/_exports/index.d.ts
CHANGED
|
@@ -747,13 +747,12 @@ export declare function isStudioConfig(value: unknown): boolean;
|
|
|
747
747
|
|
|
748
748
|
/**
|
|
749
749
|
* Whether `app` is a branded `unstable_defineApp(...)` result — the sole
|
|
750
|
-
* workbench opt-in.
|
|
751
|
-
*
|
|
752
|
-
*
|
|
753
|
-
*
|
|
754
|
-
*
|
|
755
|
-
*
|
|
756
|
-
* to `DefineAppInput['views' | 'services']` downstream.
|
|
750
|
+
* workbench opt-in. Narrows to the shared `app` config plus the workbench-only
|
|
751
|
+
* fields a branded result carries: its `name`, dock panel `views`, and
|
|
752
|
+
* background worker `services`. The shape is inlined rather than a named export
|
|
753
|
+
* since callers reach it only through this predicate; `type` uses the same
|
|
754
|
+
* literals the `DefineAppInput` schema does so `views`/`services` stay
|
|
755
|
+
* assignable to `DefineAppInput['views' | 'services']` downstream.
|
|
757
756
|
*/
|
|
758
757
|
export declare function isWorkbenchApp(
|
|
759
758
|
app: CliConfig["app"],
|
|
@@ -3,22 +3,22 @@ import { join } from 'node:path';
|
|
|
3
3
|
import { cliConfigSchema } from './schemas.js';
|
|
4
4
|
/**
|
|
5
5
|
* The brand `unstable_defineApp` stamps on its result, registered in the global
|
|
6
|
-
* symbol registry.
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
6
|
+
* symbol registry. `unstable_defineApp` lives in `@sanity/cli-build`, which
|
|
7
|
+
* depends on cli-core — so cli-core can't import the brand without a cycle, and
|
|
8
|
+
* wouldn't pull the build package into startup just for this identity check
|
|
9
|
+
* anyway (cli-core is the hot path for every CLI command, most of which never
|
|
10
|
+
* touch workbench). `Symbol.for` keys the same global symbol `unstable_defineApp`
|
|
11
|
+
* stamps, so the check is identical; the only shared contract is the symbol
|
|
12
|
+
* string, which cli-core mirrors (see `APPLICATION_TYPES` below).
|
|
12
13
|
*/ const WORKBENCH_APP_BRAND = Symbol.for('sanity.workbench.defineApp');
|
|
13
14
|
/**
|
|
14
15
|
* Whether `app` is a branded `unstable_defineApp(...)` result — the sole
|
|
15
|
-
* workbench opt-in.
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* to `DefineAppInput['views' | 'services']` downstream.
|
|
16
|
+
* workbench opt-in. Narrows to the shared `app` config plus the workbench-only
|
|
17
|
+
* fields a branded result carries: its `name`, dock panel `views`, and
|
|
18
|
+
* background worker `services`. The shape is inlined rather than a named export
|
|
19
|
+
* since callers reach it only through this predicate; `type` uses the same
|
|
20
|
+
* literals the `DefineAppInput` schema does so `views`/`services` stay
|
|
21
|
+
* assignable to `DefineAppInput['views' | 'services']` downstream.
|
|
22
22
|
*/ export function isWorkbenchApp(app) {
|
|
23
23
|
return typeof app === 'object' && app !== null && WORKBENCH_APP_BRAND in app;
|
|
24
24
|
}
|
|
@@ -30,9 +30,9 @@ const STUDIO_CONFIG_FILES = [
|
|
|
30
30
|
'sanity.config.mjs',
|
|
31
31
|
'sanity.config.cjs'
|
|
32
32
|
];
|
|
33
|
-
// Mirrors `@sanity/
|
|
34
|
-
// is a pure identity wrapper that doesn't validate its
|
|
35
|
-
// the first place an explicit `applicationType` can be checked.
|
|
33
|
+
// Mirrors the `ApplicationType` enum in `@sanity/cli-build`'s `defineApp` schema.
|
|
34
|
+
// `unstable_defineApp` is a pure identity wrapper that doesn't validate its
|
|
35
|
+
// input, so the loader is the first place an explicit `applicationType` can be checked.
|
|
36
36
|
const APPLICATION_TYPES = [
|
|
37
37
|
'coreApp',
|
|
38
38
|
'studio',
|
|
@@ -56,7 +56,7 @@ function isApplicationType(value) {
|
|
|
56
56
|
* The branded `app` bypasses the legacy `app` object schema (which would strip
|
|
57
57
|
* its identity fields and the brand symbol); every other field is still
|
|
58
58
|
* validated. The brand is preserved so downstream code relies on the
|
|
59
|
-
* `isWorkbenchApp` identity (
|
|
59
|
+
* `isWorkbenchApp` identity (above) instead of a flag.
|
|
60
60
|
*
|
|
61
61
|
* Resolves `applicationType` here — as early as possible — so studio-vs-app
|
|
62
62
|
* classification is settled once and read off the app everywhere else. The
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/config/cli/workbenchApp.ts"],"sourcesContent":["import {existsSync} from 'node:fs'\nimport {join} from 'node:path'\n\nimport {cliConfigSchema} from './schemas.js'\nimport {type CliConfig} from './types/cliConfig.js'\n\n/**\n * The brand `unstable_defineApp` stamps on its result, registered in the global\n * symbol registry.
|
|
1
|
+
{"version":3,"sources":["../../../src/config/cli/workbenchApp.ts"],"sourcesContent":["import {existsSync} from 'node:fs'\nimport {join} from 'node:path'\n\nimport {cliConfigSchema} from './schemas.js'\nimport {type CliConfig} from './types/cliConfig.js'\n\n/**\n * The brand `unstable_defineApp` stamps on its result, registered in the global\n * symbol registry. `unstable_defineApp` lives in `@sanity/cli-build`, which\n * depends on cli-core — so cli-core can't import the brand without a cycle, and\n * wouldn't pull the build package into startup just for this identity check\n * anyway (cli-core is the hot path for every CLI command, most of which never\n * touch workbench). `Symbol.for` keys the same global symbol `unstable_defineApp`\n * stamps, so the check is identical; the only shared contract is the symbol\n * string, which cli-core mirrors (see `APPLICATION_TYPES` below).\n */\nconst WORKBENCH_APP_BRAND = Symbol.for('sanity.workbench.defineApp')\n\n/**\n * Whether `app` is a branded `unstable_defineApp(...)` result — the sole\n * workbench opt-in. Narrows to the shared `app` config plus the workbench-only\n * fields a branded result carries: its `name`, dock panel `views`, and\n * background worker `services`. The shape is inlined rather than a named export\n * since callers reach it only through this predicate; `type` uses the same\n * literals the `DefineAppInput` schema does so `views`/`services` stay\n * assignable to `DefineAppInput['views' | 'services']` downstream.\n */\nexport function isWorkbenchApp(app: CliConfig['app']): app is NonNullable<CliConfig['app']> & {\n name: string\n services?: {name: string; src: string; type: 'worker'}[]\n views?: {name: string; src: string; type: 'panel'}[]\n} {\n return typeof app === 'object' && app !== null && WORKBENCH_APP_BRAND in app\n}\n\nconst STUDIO_CONFIG_FILES = [\n 'sanity.config.ts',\n 'sanity.config.tsx',\n 'sanity.config.js',\n 'sanity.config.jsx',\n 'sanity.config.mjs',\n 'sanity.config.cjs',\n]\n\n// Mirrors the `ApplicationType` enum in `@sanity/cli-build`'s `defineApp` schema.\n// `unstable_defineApp` is a pure identity wrapper that doesn't validate its\n// input, so the loader is the first place an explicit `applicationType` can be checked.\nconst APPLICATION_TYPES = [\n 'coreApp',\n 'studio',\n 'canvas',\n 'dashboard',\n 'media-library',\n 'system',\n] as const\ntype ApplicationType = (typeof APPLICATION_TYPES)[number]\n\nfunction isApplicationType(value: unknown): value is ApplicationType {\n return typeof value === 'string' && (APPLICATION_TYPES as readonly string[]).includes(value)\n}\n\n/**\n * Infer the application type for a workbench app when `unstable_defineApp`\n * didn't set one: a project with a `sanity.config.*` is a studio, otherwise a\n * core (SDK) app. An explicit `applicationType` always wins.\n */\nfunction detectApplicationType(projectDir: string): ApplicationType {\n return STUDIO_CONFIG_FILES.some((file) => existsSync(join(projectDir, file)))\n ? 'studio'\n : 'coreApp'\n}\n\n/**\n * Parse a config whose `app` is a branded `unstable_defineApp(...)` result.\n * The branded `app` bypasses the legacy `app` object schema (which would strip\n * its identity fields and the brand symbol); every other field is still\n * validated. The brand is preserved so downstream code relies on the\n * `isWorkbenchApp` identity (above) instead of a flag.\n *\n * Resolves `applicationType` here — as early as possible — so studio-vs-app\n * classification is settled once and read off the app everywhere else. The\n * resolved value lands on a clone, never the caller's object, so re-parsing the\n * same `app` for a different directory can't inherit a stale inference.\n */\nexport function parseWorkbenchCliConfig(cliConfig: unknown, projectDir: string): CliConfig {\n const {app, ...rest} = cliConfig as Record<string, unknown> & {\n app: Record<string, unknown> & {applicationType?: string}\n }\n const {data, error, success} = cliConfigSchema.safeParse(rest)\n if (!success) {\n throw new Error(`Invalid CLI config: ${error.message}`, {cause: error})\n }\n\n const explicit = app.applicationType\n if (explicit !== undefined && !isApplicationType(explicit)) {\n throw new Error(\n `Invalid \\`applicationType\\` \"${explicit}\" in \\`unstable_defineApp\\` — expected one of: ${APPLICATION_TYPES.join(', ')}`,\n )\n }\n const applicationType = explicit ?? detectApplicationType(projectDir)\n\n // Clone the branded app rather than mutating the caller's object. Copying own\n // property descriptors carries over the non-enumerable `unstable_defineApp`\n // brand, which a spread would drop.\n const resolvedApp = Object.defineProperties({}, Object.getOwnPropertyDescriptors(app)) as Record<\n string,\n unknown\n >\n resolvedApp.applicationType = applicationType\n\n return {...data, app: resolvedApp} as CliConfig\n}\n"],"names":["existsSync","join","cliConfigSchema","WORKBENCH_APP_BRAND","Symbol","for","isWorkbenchApp","app","STUDIO_CONFIG_FILES","APPLICATION_TYPES","isApplicationType","value","includes","detectApplicationType","projectDir","some","file","parseWorkbenchCliConfig","cliConfig","rest","data","error","success","safeParse","Error","message","cause","explicit","applicationType","undefined","resolvedApp","Object","defineProperties","getOwnPropertyDescriptors"],"mappings":"AAAA,SAAQA,UAAU,QAAO,UAAS;AAClC,SAAQC,IAAI,QAAO,YAAW;AAE9B,SAAQC,eAAe,QAAO,eAAc;AAG5C;;;;;;;;;CASC,GACD,MAAMC,sBAAsBC,OAAOC,GAAG,CAAC;AAEvC;;;;;;;;CAQC,GACD,OAAO,SAASC,eAAeC,GAAqB;IAKlD,OAAO,OAAOA,QAAQ,YAAYA,QAAQ,QAAQJ,uBAAuBI;AAC3E;AAEA,MAAMC,sBAAsB;IAC1B;IACA;IACA;IACA;IACA;IACA;CACD;AAED,kFAAkF;AAClF,4EAA4E;AAC5E,wFAAwF;AACxF,MAAMC,oBAAoB;IACxB;IACA;IACA;IACA;IACA;IACA;CACD;AAGD,SAASC,kBAAkBC,KAAc;IACvC,OAAO,OAAOA,UAAU,YAAY,AAACF,kBAAwCG,QAAQ,CAACD;AACxF;AAEA;;;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