@sanity/workbench-cli 2.17.0 → 2.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/_exports/_internal_worker_bus.d.ts +2 -2
  2. package/dist/_exports/deploy.d.ts +38 -6
  3. package/dist/_exports/deploy.js +2 -0
  4. package/dist/_exports/deploy.js.map +1 -1
  5. package/dist/_exports/dev.d.ts +4 -1
  6. package/dist/_exports/index.d.ts +67 -2
  7. package/dist/_exports/preview.d.ts +2 -0
  8. package/dist/_exports/{summarizeInterfaces-CpCUSMrz.d.ts → summarizeInterfaces-DGh6ARce.d.ts} +2 -2
  9. package/dist/_exports/undeploy.d.ts +1 -1
  10. package/dist/actions/build/webWorkers/workerBus.js.map +1 -1
  11. package/dist/actions/deploy/deploySummary.js +36 -0
  12. package/dist/actions/deploy/deploySummary.js.map +1 -0
  13. package/dist/actions/deploy/deployWorkbenchApp.js +21 -7
  14. package/dist/actions/deploy/deployWorkbenchApp.js.map +1 -1
  15. package/dist/actions/dev/appServerSupervisor.js +3 -1
  16. package/dist/actions/dev/appServerSupervisor.js.map +1 -1
  17. package/dist/actions/dev/bindDevShortcuts.js +33 -0
  18. package/dist/actions/dev/bindDevShortcuts.js.map +1 -0
  19. package/dist/actions/dev/deriveConfigs.js +1 -1
  20. package/dist/actions/dev/deriveConfigs.js.map +1 -1
  21. package/dist/actions/dev/devSummary.js +49 -0
  22. package/dist/actions/dev/devSummary.js.map +1 -0
  23. package/dist/actions/dev/startDevServerRegistration.js +16 -1
  24. package/dist/actions/dev/startDevServerRegistration.js.map +1 -1
  25. package/dist/actions/dev/startWorkbenchDev.js +46 -11
  26. package/dist/actions/dev/startWorkbenchDev.js.map +1 -1
  27. package/dist/actions/preview/serveBuiltApplication.js +12 -1
  28. package/dist/actions/preview/serveBuiltApplication.js.map +1 -1
  29. package/dist/actions/preview/startWorkbenchPreview.js +11 -0
  30. package/dist/actions/preview/startWorkbenchPreview.js.map +1 -1
  31. package/dist/actions/summary.js +19 -0
  32. package/dist/actions/summary.js.map +1 -0
  33. package/dist/appId.js +1 -1
  34. package/dist/appId.js.map +1 -1
  35. package/dist/defineApp.js +4 -3
  36. package/dist/defineApp.js.map +1 -1
  37. package/dist/readAppIcon.js +31 -0
  38. package/dist/readAppIcon.js.map +1 -0
  39. package/dist/services/applications.js +40 -0
  40. package/dist/services/applications.js.map +1 -1
  41. package/dist/services/organizations.js +14 -0
  42. package/dist/services/organizations.js.map +1 -0
  43. package/dist/services/users.js +24 -0
  44. package/dist/services/users.js.map +1 -0
  45. package/dist/webWorker.js.map +1 -1
  46. package/package.json +13 -13
  47. package/dist/_exports/webWorker-TWUbh0uo.d.ts +0 -123
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/actions/dev/deriveConfigs.ts"],"sourcesContent":["import {type CliConfig} from '@sanity/cli-core'\n\nimport {MEDIA_LIBRARY_CONFIG_CONTRACT_VERSION} from '../../contract.js'\nimport {resolveWorkbenchConfig} from '../../resolveWorkbenchConfig.js'\nimport {type DevServerManifest} from './registry.js'\n\n/** One forwarded interface record on the dev-server registry entry. */\nexport type DevServerInterface = NonNullable<DevServerManifest['interfaces']>[number]\n\n/** One forwarded config on the dev-server registry entry. */\nexport type DevServerConfig = NonNullable<DevServerManifest['configs']>[number]\n\n/**\n * The named source files a config's generated module is built from, dispatched\n * per app type — the projection the exposes-set id keys on, so the generic HMR\n * tracker owns none of the per-type shape. Throws on an app type it can't\n * handle, so a new config family has to register its shape here.\n */\nexport function deriveConfigEntries(config: DevServerConfig): {name: string; src: string}[] {\n switch (config.appType) {\n case 'media-library': {\n return config.fields.map((field) => ({name: field.name, src: field.src}))\n }\n default: {\n throw new Error(`Cannot derive entries for unknown config appType: ${config.appType}`)\n }\n }\n}\n\n/**\n * The fields' schema *values* can't serialize — the workbench loads them from\n * the federation module. `src` stays on so the exposes-set id keys on it and a\n * repoint rebuilds. `appType` routes the config to the singleton (no app id to\n * key on) and names the federation `moduleName`, so the alias no longer borrows\n * the app slug. `id` is a content hash of the entry — it fills the\n * installation-config id slot deployed apps get from the applications API,\n * and the workbench keys change detection on it. `version` is a string, like\n * the one Brett returns on a deployed `activeConfig`.\n */\nexport async function deriveConfigs(\n cliConfig: CliConfig | null | undefined,\n): Promise<DevServerConfig[]> {\n // Keyed on the config brand (its target `appType`), not on having fields — an\n // empty config is still a config; dev just has nothing local to load for it.\n const config = resolveWorkbenchConfig(cliConfig)\n if (!config) return []\n const entry = {\n appType: config.appType,\n fields: config.fields.map((field) => ({\n name: field.name,\n public: field.public,\n src: field.src,\n title: field.title,\n })),\n // A config keys on its target `appType`, not a fabricated slug.\n moduleName: config.appType,\n version: String(MEDIA_LIBRARY_CONFIG_CONTRACT_VERSION),\n }\n return [{...entry, id: await contentHash(JSON.stringify(entry))}]\n}\n\n/**\n * SHA-256 of a string, as hex, via the Web Crypto API — available in both Node\n * and the browser. `node:crypto` can't be used: the Vite dev server's dep scan\n * pulls this module into the browser graph.\n */\nasync function contentHash(input: string): Promise<string> {\n // eslint-disable-next-line n/no-unsupported-features/node-builtins -- the Web Crypto global is available on our Node target and in the browser\n const digest = await globalThis.crypto.subtle.digest('SHA-256', new TextEncoder().encode(input))\n return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, '0')).join('')\n}\n"],"names":["MEDIA_LIBRARY_CONFIG_CONTRACT_VERSION","resolveWorkbenchConfig","deriveConfigEntries","config","appType","fields","map","field","name","src","Error","deriveConfigs","cliConfig","entry","public","title","moduleName","version","String","id","contentHash","JSON","stringify","input","digest","globalThis","crypto","subtle","TextEncoder","encode","Array","from","Uint8Array","byte","toString","padStart","join"],"mappings":"AAEA,SAAQA,qCAAqC,QAAO,oBAAmB;AACvE,SAAQC,sBAAsB,QAAO,kCAAiC;AAStE;;;;;CAKC,GACD,OAAO,SAASC,oBAAoBC,MAAuB;IACzD,OAAQA,OAAOC,OAAO;QACpB,KAAK;YAAiB;gBACpB,OAAOD,OAAOE,MAAM,CAACC,GAAG,CAAC,CAACC,QAAW,CAAA;wBAACC,MAAMD,MAAMC,IAAI;wBAAEC,KAAKF,MAAME,GAAG;oBAAA,CAAA;YACxE;QACA;YAAS;gBACP,MAAM,IAAIC,MAAM,CAAC,kDAAkD,EAAEP,OAAOC,OAAO,EAAE;YACvF;IACF;AACF;AAEA;;;;;;;;;CASC,GACD,OAAO,eAAeO,cACpBC,SAAuC;IAEvC,8EAA8E;IAC9E,6EAA6E;IAC7E,MAAMT,SAASF,uBAAuBW;IACtC,IAAI,CAACT,QAAQ,OAAO,EAAE;IACtB,MAAMU,QAAQ;QACZT,SAASD,OAAOC,OAAO;QACvBC,QAAQF,OAAOE,MAAM,CAACC,GAAG,CAAC,CAACC,QAAW,CAAA;gBACpCC,MAAMD,MAAMC,IAAI;gBAChBM,QAAQP,MAAMO,MAAM;gBACpBL,KAAKF,MAAME,GAAG;gBACdM,OAAOR,MAAMQ,KAAK;YACpB,CAAA;QACA,gEAAgE;QAChEC,YAAYb,OAAOC,OAAO;QAC1Ba,SAASC,OAAOlB;IAClB;IACA,OAAO;QAAC;YAAC,GAAGa,KAAK;YAAEM,IAAI,MAAMC,YAAYC,KAAKC,SAAS,CAACT;QAAO;KAAE;AACnE;AAEA;;;;CAIC,GACD,eAAeO,YAAYG,KAAa;IACtC,+IAA+I;IAC/I,MAAMC,SAAS,MAAMC,WAAWC,MAAM,CAACC,MAAM,CAACH,MAAM,CAAC,WAAW,IAAII,cAAcC,MAAM,CAACN;IACzF,OAAOO,MAAMC,IAAI,CAAC,IAAIC,WAAWR,SAAS,CAACS,OAASA,KAAKC,QAAQ,CAAC,IAAIC,QAAQ,CAAC,GAAG,MAAMC,IAAI,CAAC;AAC/F"}
1
+ {"version":3,"sources":["../../../src/actions/dev/deriveConfigs.ts"],"sourcesContent":["import {type CliConfig} from '@sanity/cli-core'\n\nimport {MEDIA_LIBRARY_CONFIG_CONTRACT_VERSION} from '../../contract.js'\nimport {resolveWorkbenchConfig} from '../../resolveWorkbenchConfig.js'\nimport {type DevServerManifest} from './registry.js'\n\n/** One forwarded interface record on the dev-server registry entry. */\nexport type DevServerInterface = NonNullable<DevServerManifest['interfaces']>[number]\n\n/** One forwarded config on the dev-server registry entry. */\nexport type DevServerConfig = NonNullable<DevServerManifest['configs']>[number]\n\n/**\n * The named source files a config's generated module is built from, dispatched\n * per app type — the projection the exposes-set id keys on, so the generic HMR\n * tracker owns none of the per-type shape. Throws on an app type it can't\n * handle, so a new config family has to register its shape here.\n */\nexport function deriveConfigEntries(config: DevServerConfig): {name: string; src: string}[] {\n switch (config.appType) {\n case 'media-library': {\n return config.fields.map((field) => ({name: field.name, src: field.src}))\n }\n default: {\n throw new Error(`Cannot derive entries for unknown config appType: ${config.appType}`)\n }\n }\n}\n\n/**\n * The fields' schema *values* can't serialize — the workbench loads them from\n * the federation module. `src` stays on so the exposes-set id keys on it and a\n * repoint rebuilds. `appType` routes the config to the singleton (no app id to\n * key on) and names the federation `moduleName`, so the alias no longer borrows\n * the app slug. `id` is a content hash of the entry — it fills the\n * installation-config id slot deployed apps get from the applications API,\n * and the workbench keys change detection on it. `version` is a string, like\n * the one Brett returns on a deployed `activeConfig`.\n */\nexport async function deriveConfigs(\n cliConfig: CliConfig | null | undefined,\n): Promise<DevServerConfig[]> {\n // Keyed on the config brand (its target `appType`), not on having fields — an\n // empty config is still a config; dev just has nothing local to load for it.\n const config = resolveWorkbenchConfig(cliConfig)\n if (!config) return []\n const entry = {\n appType: config.appType,\n fields: config.fields.map((field) => ({\n name: field.name,\n public: field.public,\n src: field.src,\n title: field.title,\n })),\n // A config keys on its target `appType`, not a fabricated slug.\n moduleName: config.appType,\n version: String(MEDIA_LIBRARY_CONFIG_CONTRACT_VERSION),\n }\n return [{...entry, id: await contentHash(JSON.stringify(entry))}]\n}\n\n/**\n * SHA-256 of a string, as hex, via the Web Crypto API — available in both Node\n * and the browser. `node:crypto` can't be used: the Vite dev server's dep scan\n * pulls this module into the browser graph.\n */\nasync function contentHash(input: string): Promise<string> {\n // eslint-disable-next-line n-js/no-unsupported-features/node-builtins -- the Web Crypto global is available on our Node target and in the browser\n const digest = await globalThis.crypto.subtle.digest('SHA-256', new TextEncoder().encode(input))\n return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, '0')).join('')\n}\n"],"names":["MEDIA_LIBRARY_CONFIG_CONTRACT_VERSION","resolveWorkbenchConfig","deriveConfigEntries","config","appType","fields","map","field","name","src","Error","deriveConfigs","cliConfig","entry","public","title","moduleName","version","String","id","contentHash","JSON","stringify","input","digest","globalThis","crypto","subtle","TextEncoder","encode","Array","from","Uint8Array","byte","toString","padStart","join"],"mappings":"AAEA,SAAQA,qCAAqC,QAAO,oBAAmB;AACvE,SAAQC,sBAAsB,QAAO,kCAAiC;AAStE;;;;;CAKC,GACD,OAAO,SAASC,oBAAoBC,MAAuB;IACzD,OAAQA,OAAOC,OAAO;QACpB,KAAK;YAAiB;gBACpB,OAAOD,OAAOE,MAAM,CAACC,GAAG,CAAC,CAACC,QAAW,CAAA;wBAACC,MAAMD,MAAMC,IAAI;wBAAEC,KAAKF,MAAME,GAAG;oBAAA,CAAA;YACxE;QACA;YAAS;gBACP,MAAM,IAAIC,MAAM,CAAC,kDAAkD,EAAEP,OAAOC,OAAO,EAAE;YACvF;IACF;AACF;AAEA;;;;;;;;;CASC,GACD,OAAO,eAAeO,cACpBC,SAAuC;IAEvC,8EAA8E;IAC9E,6EAA6E;IAC7E,MAAMT,SAASF,uBAAuBW;IACtC,IAAI,CAACT,QAAQ,OAAO,EAAE;IACtB,MAAMU,QAAQ;QACZT,SAASD,OAAOC,OAAO;QACvBC,QAAQF,OAAOE,MAAM,CAACC,GAAG,CAAC,CAACC,QAAW,CAAA;gBACpCC,MAAMD,MAAMC,IAAI;gBAChBM,QAAQP,MAAMO,MAAM;gBACpBL,KAAKF,MAAME,GAAG;gBACdM,OAAOR,MAAMQ,KAAK;YACpB,CAAA;QACA,gEAAgE;QAChEC,YAAYb,OAAOC,OAAO;QAC1Ba,SAASC,OAAOlB;IAClB;IACA,OAAO;QAAC;YAAC,GAAGa,KAAK;YAAEM,IAAI,MAAMC,YAAYC,KAAKC,SAAS,CAACT;QAAO;KAAE;AACnE;AAEA;;;;CAIC,GACD,eAAeO,YAAYG,KAAa;IACtC,kJAAkJ;IAClJ,MAAMC,SAAS,MAAMC,WAAWC,MAAM,CAACC,MAAM,CAACH,MAAM,CAAC,WAAW,IAAII,cAAcC,MAAM,CAACN;IACzF,OAAOO,MAAMC,IAAI,CAAC,IAAIC,WAAWR,SAAS,CAACS,OAASA,KAAKC,QAAQ,CAAC,IAAIC,QAAQ,CAAC,GAAG,MAAMC,IAAI,CAAC;AAC/F"}
@@ -0,0 +1,49 @@
1
+ import { spinner } from '@sanity/cli-core/ux';
2
+ import { getOrganizationApplication } from '../../services/applications.js';
3
+ import { getOrganization } from '../../services/organizations.js';
4
+ import { getUser } from '../../services/users.js';
5
+ import { SUMMARY_LOOKUP_TIMEOUT_MS } from '../summary.js';
6
+ const PENDING = Symbol('pending');
7
+ export async function fetchDevSummaryDetails({ idOrSlug, organizationId }) {
8
+ if (!organizationId) return {};
9
+ const signal = AbortSignal.timeout(SUMMARY_LOOKUP_TIMEOUT_MS);
10
+ const organizationName = getOrganization(organizationId, signal).then((org)=>org.name).catch(()=>null);
11
+ if (!idOrSlug) {
12
+ return {
13
+ organizationName: await organizationName
14
+ };
15
+ }
16
+ let deployment;
17
+ try {
18
+ const application = await getOrganizationApplication(organizationId, idOrSlug, signal);
19
+ const active = application?.activeDeployment;
20
+ if (active) {
21
+ const deployedBy = await getUser(active.deployedBy, signal).then((user)=>user.displayName).catch(()=>null);
22
+ deployment = {
23
+ createdAt: active.createdAt,
24
+ deployedBy
25
+ };
26
+ } else {
27
+ deployment = null;
28
+ }
29
+ } catch {
30
+ // Left undefined: a failed lookup must not read as "not deployed".
31
+ }
32
+ return {
33
+ deployment,
34
+ organizationName: await organizationName
35
+ };
36
+ }
37
+ export async function waitForDevSummaryDetails(details) {
38
+ const settled = await Promise.race([
39
+ details,
40
+ new Promise((resolve)=>setImmediate(resolve, PENDING))
41
+ ]);
42
+ if (settled !== PENDING) return settled;
43
+ const spin = spinner('Loading organization and deployment details').start();
44
+ const result = await details;
45
+ spin.stop();
46
+ return result;
47
+ }
48
+
49
+ //# sourceMappingURL=devSummary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/actions/dev/devSummary.ts"],"sourcesContent":["import {spinner} from '@sanity/cli-core/ux'\n\nimport {getOrganizationApplication} from '../../services/applications.js'\nimport {getOrganization} from '../../services/organizations.js'\nimport {getUser} from '../../services/users.js'\nimport {SUMMARY_LOOKUP_TIMEOUT_MS} from '../summary.js'\n\nconst PENDING = Symbol('pending')\n\nexport interface DevSummaryDetails {\n /** `null` when the app has no active deployment, `undefined` when the lookup failed or was skipped. */\n deployment?: {createdAt: string; deployedBy: string | null} | null\n organizationName?: string | null\n}\n\nexport async function fetchDevSummaryDetails({\n idOrSlug,\n organizationId,\n}: {\n idOrSlug?: string\n organizationId?: string\n}): Promise<DevSummaryDetails> {\n if (!organizationId) return {}\n\n const signal = AbortSignal.timeout(SUMMARY_LOOKUP_TIMEOUT_MS)\n const organizationName = getOrganization(organizationId, signal)\n .then((org) => org.name)\n .catch(() => null)\n\n if (!idOrSlug) {\n return {organizationName: await organizationName}\n }\n\n let deployment: DevSummaryDetails['deployment']\n\n try {\n const application = await getOrganizationApplication(organizationId, idOrSlug, signal)\n const active = application?.activeDeployment\n\n if (active) {\n const deployedBy = await getUser(active.deployedBy, signal)\n .then((user) => user.displayName)\n .catch(() => null)\n deployment = {createdAt: active.createdAt, deployedBy}\n } else {\n deployment = null\n }\n } catch {\n // Left undefined: a failed lookup must not read as \"not deployed\".\n }\n\n return {deployment, organizationName: await organizationName}\n}\n\nexport async function waitForDevSummaryDetails(\n details: Promise<DevSummaryDetails>,\n): Promise<DevSummaryDetails> {\n const settled = await Promise.race([\n details,\n new Promise<typeof PENDING>((resolve) => setImmediate(resolve, PENDING)),\n ])\n\n if (settled !== PENDING) return settled\n\n const spin = spinner('Loading organization and deployment details').start()\n const result = await details\n spin.stop()\n\n return result\n}\n"],"names":["spinner","getOrganizationApplication","getOrganization","getUser","SUMMARY_LOOKUP_TIMEOUT_MS","PENDING","Symbol","fetchDevSummaryDetails","idOrSlug","organizationId","signal","AbortSignal","timeout","organizationName","then","org","name","catch","deployment","application","active","activeDeployment","deployedBy","user","displayName","createdAt","waitForDevSummaryDetails","details","settled","Promise","race","resolve","setImmediate","spin","start","result","stop"],"mappings":"AAAA,SAAQA,OAAO,QAAO,sBAAqB;AAE3C,SAAQC,0BAA0B,QAAO,iCAAgC;AACzE,SAAQC,eAAe,QAAO,kCAAiC;AAC/D,SAAQC,OAAO,QAAO,0BAAyB;AAC/C,SAAQC,yBAAyB,QAAO,gBAAe;AAEvD,MAAMC,UAAUC,OAAO;AAQvB,OAAO,eAAeC,uBAAuB,EAC3CC,QAAQ,EACRC,cAAc,EAIf;IACC,IAAI,CAACA,gBAAgB,OAAO,CAAC;IAE7B,MAAMC,SAASC,YAAYC,OAAO,CAACR;IACnC,MAAMS,mBAAmBX,gBAAgBO,gBAAgBC,QACtDI,IAAI,CAAC,CAACC,MAAQA,IAAIC,IAAI,EACtBC,KAAK,CAAC,IAAM;IAEf,IAAI,CAACT,UAAU;QACb,OAAO;YAACK,kBAAkB,MAAMA;QAAgB;IAClD;IAEA,IAAIK;IAEJ,IAAI;QACF,MAAMC,cAAc,MAAMlB,2BAA2BQ,gBAAgBD,UAAUE;QAC/E,MAAMU,SAASD,aAAaE;QAE5B,IAAID,QAAQ;YACV,MAAME,aAAa,MAAMnB,QAAQiB,OAAOE,UAAU,EAAEZ,QACjDI,IAAI,CAAC,CAACS,OAASA,KAAKC,WAAW,EAC/BP,KAAK,CAAC,IAAM;YACfC,aAAa;gBAACO,WAAWL,OAAOK,SAAS;gBAAEH;YAAU;QACvD,OAAO;YACLJ,aAAa;QACf;IACF,EAAE,OAAM;IACN,mEAAmE;IACrE;IAEA,OAAO;QAACA;QAAYL,kBAAkB,MAAMA;IAAgB;AAC9D;AAEA,OAAO,eAAea,yBACpBC,OAAmC;IAEnC,MAAMC,UAAU,MAAMC,QAAQC,IAAI,CAAC;QACjCH;QACA,IAAIE,QAAwB,CAACE,UAAYC,aAAaD,SAAS1B;KAChE;IAED,IAAIuB,YAAYvB,SAAS,OAAOuB;IAEhC,MAAMK,OAAOjC,QAAQ,+CAA+CkC,KAAK;IACzE,MAAMC,SAAS,MAAMR;IACrBM,KAAKG,IAAI;IAET,OAAOD;AACT"}
@@ -1,6 +1,8 @@
1
+ import { relative } from 'node:path';
1
2
  import { getCliConfigUncached } from '@sanity/cli-core';
2
3
  import { isWorkbenchApp, isWorkbenchConfig } from '../../defineApp.js';
3
4
  import { deriveInterfaces } from '../../deriveInterfaces.js';
5
+ import { readAppIcon, toUrlPath } from '../../readAppIcon.js';
4
6
  import { resolveWorkbenchConfig } from '../../resolveWorkbenchConfig.js';
5
7
  import { formatWorkbenchAppErrors, validateWorkbenchApp } from '../../validateWorkbenchApp.js';
6
8
  import { deriveConfigs } from './deriveConfigs.js';
@@ -81,12 +83,23 @@ import { startDevManifestWatcher } from './startDevManifestWatcher.js';
81
83
  configs,
82
84
  interfaces
83
85
  });
86
+ let liveServer = server;
84
87
  const watcher = await startDevManifestWatcher({
85
88
  // Re-derive every pass (don't omit): the registry patch is a shallow merge,
86
89
  // so omitting would wipe the registered set.
87
90
  extract: async (params)=>{
88
91
  const nextConfig = await getCliConfigUncached(params.workDir);
89
92
  reportConfigErrors(nextConfig.app, output);
93
+ let iconUrl;
94
+ if (isApp && isWorkbenchApp(nextConfig.app) && nextConfig.app.icon) {
95
+ // Read in full so an image a deploy would reject warns here, while editing.
96
+ const { file } = await readAppIcon(workDir, nextConfig.app.icon);
97
+ // Vite serves `public/` at the root, and warns on every request for `/public/...`.
98
+ const { base, publicDir, root } = liveServer.config;
99
+ const inPublicDir = Boolean(publicDir) && !relative(publicDir, file).startsWith('..');
100
+ const { host, https, port } = serverAddress(liveServer);
101
+ iconUrl = `${https ? 'https' : 'http'}://${host}:${port}${base}${toUrlPath(inPublicDir ? publicDir : root, file)}`;
102
+ }
90
103
  return {
91
104
  configs: await deriveConfigs(nextConfig),
92
105
  interfaces: deriveInterfaces(nextConfig.app, {
@@ -94,7 +107,8 @@ import { startDevManifestWatcher } from './startDevManifestWatcher.js';
94
107
  }),
95
108
  manifest: await extractManifest({
96
109
  ...params,
97
- applicationId: id
110
+ applicationId: id,
111
+ iconUrl
98
112
  })
99
113
  };
100
114
  },
@@ -122,6 +136,7 @@ import { startDevManifestWatcher } from './startDevManifestWatcher.js';
122
136
  interfaces: patch.interfaces
123
137
  });
124
138
  // The recreated server can bind a different port (non-strict ports).
139
+ if (rebuiltServer) liveServer = rebuiltServer;
125
140
  registration.update(rebuiltServer ? {
126
141
  ...patch,
127
142
  ...serverAddress(rebuiltServer)
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/actions/dev/startDevServerRegistration.ts"],"sourcesContent":["import {type CliConfig, getCliConfigUncached, type Output} from '@sanity/cli-core'\nimport {type ViteDevServer} from 'vite'\n\nimport {isWorkbenchApp, isWorkbenchConfig} from '../../defineApp.js'\nimport {deriveInterfaces} from '../../deriveInterfaces.js'\nimport {resolveWorkbenchConfig} from '../../resolveWorkbenchConfig.js'\nimport {formatWorkbenchAppErrors, validateWorkbenchApp} from '../../validateWorkbenchApp.js'\nimport {deriveConfigs} from './deriveConfigs.js'\nimport {trackExposesSet} from './exposesSetId.js'\nimport {\n dashboardPath,\n type DevServerManifest,\n getRegisteredServers,\n localAppIdentity,\n registerDevServer,\n} from './registry.js'\nimport {startDevManifestWatcher} from './startDevManifestWatcher.js'\n\ninterface DevServerRegistrationOptions {\n cliConfig: CliConfig\n /**\n * Extract the project manifest to inline into the registry. The caller owns the\n * studio-vs-app split (manifest formats are CLI-domain); registration re-derives\n * the interface set alongside it.\n */\n extractManifest: (params: {\n applicationId?: string\n configPath: string\n workDir: string\n }) => Promise<DevServerManifest['manifest']>\n isApp: boolean\n output: Output\n server: ViteDevServer\n workDir: string\n\n /**\n * Rebuild the app's federation remote when its interface set changes, awaited\n * *before* the registry patch — the patch reloads the workbench page, which must\n * re-fetch a remote that already exposes the new interface. Resolves with the\n * recreated server so the entry gets its actual address (non-strict ports may\n * shift it); must reject if the restart produces no server, so the set stays\n * uncommitted and the next save retries instead of advertising a dead port.\n */\n onInterfaceSetChange?: () => Promise<ViteDevServer>\n}\n\ninterface DevServerRegistrationHandle {\n close: () => Promise<void>\n\n /** Where the Dashboard opens this server; unset when it can't open it there. */\n path?: string\n}\n\n/**\n * Log any app validation errors without aborting. Unlike build and deploy, dev\n * stays up on an invalid app so the author sees the errors and fixes them live on\n * the next save. A config is not an app — it isn't validated by the app schema\n * (which would spuriously demand a slug/title), so skip it here.\n */\nfunction reportConfigErrors(app: CliConfig['app'], output: Output): void {\n if (isWorkbenchConfig(app)) return\n const errors = validateWorkbenchApp(app)\n if (errors.length === 0) return\n output.warn(formatWorkbenchAppErrors(errors))\n}\n\n/** The address the server actually bound — the live socket, which can differ from the configured port under non-strict ports. */\nfunction serverAddress(server: ViteDevServer) {\n const resolvedHost = server.config.server.host\n const addr = server.httpServer?.address()\n return {\n host: typeof resolvedHost === 'string' ? resolvedHost : 'localhost',\n https: Boolean(server.config.server.https),\n port: typeof addr === 'object' && addr ? addr.port : server.config.server.port,\n }\n}\n\n/**\n * Register the dev server in the registry and watch its config for manifest +\n * interface changes. The workbench reads the entry to locate and render the\n * server; the watcher keeps it current as `sanity.cli.ts` is edited.\n */\nexport async function startDevServerRegistration(\n options: DevServerRegistrationOptions,\n): Promise<DevServerRegistrationHandle> {\n const {cliConfig, extractManifest, isApp, onInterfaceSetChange, output, server, workDir} = options\n\n const {host: appHost, https, port: appPort} = serverAddress(server)\n\n reportConfigErrors(cliConfig.app, output)\n\n // Forwarded alongside (not inside) the manifest so the workbench renders local\n // panels/workers and reads the configs without a deploy.\n const interfaces = deriveInterfaces(cliConfig.app, {isApp})\n const configs = await deriveConfigs(cliConfig)\n\n const workbenchApp = isWorkbenchApp(cliConfig.app) ? cliConfig.app : undefined\n const config = resolveWorkbenchConfig(cliConfig)\n // A config runs alongside the app it configures, so give it its own id\n // namespace — sharing the app's slug would make the two indistinguishable here.\n const id = config ? `config:${config.appType}` : workbenchApp?.slug\n const applicationId = workbenchApp ? cliConfig.deployment?.appId : undefined\n // Identity is resolved and the reference composed here, so the workbench reads\n // both off the registry entry instead of recomposing them.\n const identity = workbenchApp ? localAppIdentity(workbenchApp) : undefined\n\n // The Dashboard tells local apps apart by their bus id and by the application\n // they stand in for.\n const organizationId = cliConfig.app?.organizationId\n const devServer = getRegisteredServers().find(\n (server) =>\n server.organizationId === organizationId &&\n (server.id === id || (applicationId && server.applicationId === applicationId)),\n )\n\n if (id && devServer) {\n const served =\n devServer.id === id\n ? `\"${id}\" is already served`\n : `\"${id}\" is the same application as \"${devServer.id}\", served`\n output.error(\n `${served} by another dev server running on port ${devServer.port}, ` +\n \"so the Dashboard can't tell them apart and this one stays out of it. Stop that server first.\",\n {exit: false},\n )\n return {close: async () => {}}\n }\n\n const registration = registerDevServer({\n applicationId,\n configs,\n host: appHost,\n https,\n id,\n interfaces,\n organizationId,\n port: appPort,\n projectId: cliConfig?.api?.projectId,\n ...identity,\n type: isApp ? 'coreApp' : 'studio',\n workDir,\n })\n\n const exposesSet = trackExposesSet({configs, interfaces})\n\n const watcher = await startDevManifestWatcher({\n // Re-derive every pass (don't omit): the registry patch is a shallow merge,\n // so omitting would wipe the registered set.\n extract: async (params) => {\n const nextConfig = await getCliConfigUncached(params.workDir)\n reportConfigErrors(nextConfig.app, output)\n return {\n configs: await deriveConfigs(nextConfig),\n interfaces: deriveInterfaces(nextConfig.app, {isApp}),\n manifest: await extractManifest({...params, applicationId: id}),\n }\n },\n // A studio's root resolves to `sanity.config.*` but its interfaces live in\n // `sanity.cli.*` — watch that too. Apps already root at `sanity.cli.*`.\n extraWatchFilenames: isApp ? undefined : ['sanity.cli.js', 'sanity.cli.ts'],\n output,\n update: async (patch) => {\n if (\n !exposesSet.changed({\n configs: patch.configs,\n interfaces: patch.interfaces,\n })\n ) {\n registration.update(patch)\n return\n }\n // Rebuild the remote *before* patching the registry — the patch reloads the\n // page, which must re-fetch a remote that already exposes the new interface.\n const rebuiltServer = await onInterfaceSetChange?.()\n // Commit only after a successful rebuild, so a thrown one retries next pass.\n exposesSet.commit({\n configs: patch.configs,\n interfaces: patch.interfaces,\n })\n // The recreated server can bind a different port (non-strict ports).\n registration.update(rebuiltServer ? {...patch, ...serverAddress(rebuiltServer)} : patch)\n },\n workDir,\n })\n\n return {\n close: async () => {\n registration.release()\n await watcher.close()\n },\n path: dashboardPath({\n id,\n interfaces,\n slug: identity?.slug,\n type: isApp ? 'coreApp' : 'studio',\n }),\n }\n}\n"],"names":["getCliConfigUncached","isWorkbenchApp","isWorkbenchConfig","deriveInterfaces","resolveWorkbenchConfig","formatWorkbenchAppErrors","validateWorkbenchApp","deriveConfigs","trackExposesSet","dashboardPath","getRegisteredServers","localAppIdentity","registerDevServer","startDevManifestWatcher","reportConfigErrors","app","output","errors","length","warn","serverAddress","server","resolvedHost","config","host","addr","httpServer","address","https","Boolean","port","startDevServerRegistration","options","cliConfig","extractManifest","isApp","onInterfaceSetChange","workDir","appHost","appPort","interfaces","configs","workbenchApp","undefined","id","appType","slug","applicationId","deployment","appId","identity","organizationId","devServer","find","served","error","exit","close","registration","projectId","api","type","exposesSet","watcher","extract","params","nextConfig","manifest","extraWatchFilenames","update","patch","changed","rebuiltServer","commit","release","path"],"mappings":"AAAA,SAAwBA,oBAAoB,QAAoB,mBAAkB;AAGlF,SAAQC,cAAc,EAAEC,iBAAiB,QAAO,qBAAoB;AACpE,SAAQC,gBAAgB,QAAO,4BAA2B;AAC1D,SAAQC,sBAAsB,QAAO,kCAAiC;AACtE,SAAQC,wBAAwB,EAAEC,oBAAoB,QAAO,gCAA+B;AAC5F,SAAQC,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AAMC,aAAa,MAAMlE,qBAAqBiE,OAAO5B,OAAO;YAC5DvB,mBAAmBoD,WAAWnD,GAAG,EAAEC;YACnC,OAAO;gBACLyB,SAAS,MAAMlC,cAAc2D;gBAC7B1B,YAAYrC,iBAAiB+D,WAAWnD,GAAG,EAAE;oBAACoB;gBAAK;gBACnDgC,UAAU,MAAMjC,gBAAgB;oBAAC,GAAG+B,MAAM;oBAAElB,eAAeH;gBAAE;YAC/D;QACF;QACA,2EAA2E;QAC3E,wEAAwE;QACxEwB,qBAAqBjC,QAAQQ,YAAY;YAAC;YAAiB;SAAgB;QAC3E3B;QACAqD,QAAQ,OAAOC;YACb,IACE,CAACR,WAAWS,OAAO,CAAC;gBAClB9B,SAAS6B,MAAM7B,OAAO;gBACtBD,YAAY8B,MAAM9B,UAAU;YAC9B,IACA;gBACAkB,aAAaW,MAAM,CAACC;gBACpB;YACF;YACA,4EAA4E;YAC5E,6EAA6E;YAC7E,MAAME,gBAAgB,MAAMpC;YAC5B,6EAA6E;YAC7E0B,WAAWW,MAAM,CAAC;gBAChBhC,SAAS6B,MAAM7B,OAAO;gBACtBD,YAAY8B,MAAM9B,UAAU;YAC9B;YACA,qEAAqE;YACrEkB,aAAaW,MAAM,CAACG,gBAAgB;gBAAC,GAAGF,KAAK;gBAAE,GAAGlD,cAAcoD,cAAc;YAAA,IAAIF;QACpF;QACAjC;IACF;IAEA,OAAO;QACLoB,OAAO;YACLC,aAAagB,OAAO;YACpB,MAAMX,QAAQN,KAAK;QACrB;QACAkB,MAAMlE,cAAc;YAClBmC;YACAJ;YACAM,MAAMI,UAAUJ;YAChBe,MAAM1B,QAAQ,YAAY;QAC5B;IACF;AACF"}
1
+ {"version":3,"sources":["../../../src/actions/dev/startDevServerRegistration.ts"],"sourcesContent":["import {relative} from 'node:path'\n\nimport {type CliConfig, getCliConfigUncached, type Output} from '@sanity/cli-core'\nimport {type ViteDevServer} from 'vite'\n\nimport {isWorkbenchApp, isWorkbenchConfig} from '../../defineApp.js'\nimport {deriveInterfaces} from '../../deriveInterfaces.js'\nimport {readAppIcon, toUrlPath} from '../../readAppIcon.js'\nimport {resolveWorkbenchConfig} from '../../resolveWorkbenchConfig.js'\nimport {formatWorkbenchAppErrors, validateWorkbenchApp} from '../../validateWorkbenchApp.js'\nimport {deriveConfigs} from './deriveConfigs.js'\nimport {trackExposesSet} from './exposesSetId.js'\nimport {\n dashboardPath,\n type DevServerManifest,\n getRegisteredServers,\n localAppIdentity,\n registerDevServer,\n} from './registry.js'\nimport {startDevManifestWatcher} from './startDevManifestWatcher.js'\n\ninterface DevServerRegistrationOptions {\n cliConfig: CliConfig\n /**\n * Extract the project manifest to inline into the registry. The caller owns the\n * studio-vs-app split (manifest formats are CLI-domain); registration re-derives\n * the interface set alongside it.\n */\n extractManifest: (params: {\n applicationId?: string\n configPath: string\n /** Where this server serves the app's icon. */\n iconUrl?: string\n workDir: string\n }) => Promise<DevServerManifest['manifest']>\n isApp: boolean\n output: Output\n server: ViteDevServer\n workDir: string\n\n /**\n * Rebuild the app's federation remote when its interface set changes, awaited\n * *before* the registry patch — the patch reloads the workbench page, which must\n * re-fetch a remote that already exposes the new interface. Resolves with the\n * recreated server so the entry gets its actual address (non-strict ports may\n * shift it); must reject if the restart produces no server, so the set stays\n * uncommitted and the next save retries instead of advertising a dead port.\n */\n onInterfaceSetChange?: () => Promise<ViteDevServer>\n}\n\ninterface DevServerRegistrationHandle {\n close: () => Promise<void>\n\n /** Where the Dashboard opens this server; unset when it can't open it there. */\n path?: string\n}\n\n/**\n * Log any app validation errors without aborting. Unlike build and deploy, dev\n * stays up on an invalid app so the author sees the errors and fixes them live on\n * the next save. A config is not an app — it isn't validated by the app schema\n * (which would spuriously demand a slug/title), so skip it here.\n */\nfunction reportConfigErrors(app: CliConfig['app'], output: Output): void {\n if (isWorkbenchConfig(app)) return\n const errors = validateWorkbenchApp(app)\n if (errors.length === 0) return\n output.warn(formatWorkbenchAppErrors(errors))\n}\n\n/** The address the server actually bound — the live socket, which can differ from the configured port under non-strict ports. */\nfunction serverAddress(server: ViteDevServer) {\n const resolvedHost = server.config.server.host\n const addr = server.httpServer?.address()\n return {\n host: typeof resolvedHost === 'string' ? resolvedHost : 'localhost',\n https: Boolean(server.config.server.https),\n port: typeof addr === 'object' && addr ? addr.port : server.config.server.port,\n }\n}\n\n/**\n * Register the dev server in the registry and watch its config for manifest +\n * interface changes. The workbench reads the entry to locate and render the\n * server; the watcher keeps it current as `sanity.cli.ts` is edited.\n */\nexport async function startDevServerRegistration(\n options: DevServerRegistrationOptions,\n): Promise<DevServerRegistrationHandle> {\n const {cliConfig, extractManifest, isApp, onInterfaceSetChange, output, server, workDir} = options\n\n const {host: appHost, https, port: appPort} = serverAddress(server)\n\n reportConfigErrors(cliConfig.app, output)\n\n // Forwarded alongside (not inside) the manifest so the workbench renders local\n // panels/workers and reads the configs without a deploy.\n const interfaces = deriveInterfaces(cliConfig.app, {isApp})\n const configs = await deriveConfigs(cliConfig)\n\n const workbenchApp = isWorkbenchApp(cliConfig.app) ? cliConfig.app : undefined\n const config = resolveWorkbenchConfig(cliConfig)\n // A config runs alongside the app it configures, so give it its own id\n // namespace — sharing the app's slug would make the two indistinguishable here.\n const id = config ? `config:${config.appType}` : workbenchApp?.slug\n const applicationId = workbenchApp ? cliConfig.deployment?.appId : undefined\n // Identity is resolved and the reference composed here, so the workbench reads\n // both off the registry entry instead of recomposing them.\n const identity = workbenchApp ? localAppIdentity(workbenchApp) : undefined\n\n // The Dashboard tells local apps apart by their bus id and by the application\n // they stand in for.\n const organizationId = cliConfig.app?.organizationId\n const devServer = getRegisteredServers().find(\n (server) =>\n server.organizationId === organizationId &&\n (server.id === id || (applicationId && server.applicationId === applicationId)),\n )\n\n if (id && devServer) {\n const served =\n devServer.id === id\n ? `\"${id}\" is already served`\n : `\"${id}\" is the same application as \"${devServer.id}\", served`\n output.error(\n `${served} by another dev server running on port ${devServer.port}, ` +\n \"so the Dashboard can't tell them apart and this one stays out of it. Stop that server first.\",\n {exit: false},\n )\n return {close: async () => {}}\n }\n\n const registration = registerDevServer({\n applicationId,\n configs,\n host: appHost,\n https,\n id,\n interfaces,\n organizationId,\n port: appPort,\n projectId: cliConfig?.api?.projectId,\n ...identity,\n type: isApp ? 'coreApp' : 'studio',\n workDir,\n })\n\n const exposesSet = trackExposesSet({configs, interfaces})\n let liveServer = server\n\n const watcher = await startDevManifestWatcher({\n // Re-derive every pass (don't omit): the registry patch is a shallow merge,\n // so omitting would wipe the registered set.\n extract: async (params) => {\n const nextConfig = await getCliConfigUncached(params.workDir)\n reportConfigErrors(nextConfig.app, output)\n\n let iconUrl: string | undefined\n if (isApp && isWorkbenchApp(nextConfig.app) && nextConfig.app.icon) {\n // Read in full so an image a deploy would reject warns here, while editing.\n const {file} = await readAppIcon(workDir, nextConfig.app.icon)\n // Vite serves `public/` at the root, and warns on every request for `/public/...`.\n const {base, publicDir, root} = liveServer.config\n const inPublicDir = Boolean(publicDir) && !relative(publicDir, file).startsWith('..')\n const {host, https, port} = serverAddress(liveServer)\n iconUrl = `${https ? 'https' : 'http'}://${host}:${port}${base}${toUrlPath(inPublicDir ? publicDir : root, file)}`\n }\n\n return {\n configs: await deriveConfigs(nextConfig),\n interfaces: deriveInterfaces(nextConfig.app, {isApp}),\n manifest: await extractManifest({...params, applicationId: id, iconUrl}),\n }\n },\n // A studio's root resolves to `sanity.config.*` but its interfaces live in\n // `sanity.cli.*` — watch that too. Apps already root at `sanity.cli.*`.\n extraWatchFilenames: isApp ? undefined : ['sanity.cli.js', 'sanity.cli.ts'],\n output,\n update: async (patch) => {\n if (\n !exposesSet.changed({\n configs: patch.configs,\n interfaces: patch.interfaces,\n })\n ) {\n registration.update(patch)\n return\n }\n // Rebuild the remote *before* patching the registry — the patch reloads the\n // page, which must re-fetch a remote that already exposes the new interface.\n const rebuiltServer = await onInterfaceSetChange?.()\n // Commit only after a successful rebuild, so a thrown one retries next pass.\n exposesSet.commit({\n configs: patch.configs,\n interfaces: patch.interfaces,\n })\n // The recreated server can bind a different port (non-strict ports).\n if (rebuiltServer) liveServer = rebuiltServer\n registration.update(rebuiltServer ? {...patch, ...serverAddress(rebuiltServer)} : patch)\n },\n workDir,\n })\n\n return {\n close: async () => {\n registration.release()\n await watcher.close()\n },\n path: dashboardPath({\n id,\n interfaces,\n slug: identity?.slug,\n type: isApp ? 'coreApp' : 'studio',\n }),\n }\n}\n"],"names":["relative","getCliConfigUncached","isWorkbenchApp","isWorkbenchConfig","deriveInterfaces","readAppIcon","toUrlPath","resolveWorkbenchConfig","formatWorkbenchAppErrors","validateWorkbenchApp","deriveConfigs","trackExposesSet","dashboardPath","getRegisteredServers","localAppIdentity","registerDevServer","startDevManifestWatcher","reportConfigErrors","app","output","errors","length","warn","serverAddress","server","resolvedHost","config","host","addr","httpServer","address","https","Boolean","port","startDevServerRegistration","options","cliConfig","extractManifest","isApp","onInterfaceSetChange","workDir","appHost","appPort","interfaces","configs","workbenchApp","undefined","id","appType","slug","applicationId","deployment","appId","identity","organizationId","devServer","find","served","error","exit","close","registration","projectId","api","type","exposesSet","liveServer","watcher","extract","params","nextConfig","iconUrl","icon","file","base","publicDir","root","inPublicDir","startsWith","manifest","extraWatchFilenames","update","patch","changed","rebuiltServer","commit","release","path"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,YAAW;AAElC,SAAwBC,oBAAoB,QAAoB,mBAAkB;AAGlF,SAAQC,cAAc,EAAEC,iBAAiB,QAAO,qBAAoB;AACpE,SAAQC,gBAAgB,QAAO,4BAA2B;AAC1D,SAAQC,WAAW,EAAEC,SAAS,QAAO,uBAAsB;AAC3D,SAAQC,sBAAsB,QAAO,kCAAiC;AACtE,SAAQC,wBAAwB,EAAEC,oBAAoB,QAAO,gCAA+B;AAC5F,SAAQC,aAAa,QAAO,qBAAoB;AAChD,SAAQC,eAAe,QAAO,oBAAmB;AACjD,SACEC,aAAa,EAEbC,oBAAoB,EACpBC,gBAAgB,EAChBC,iBAAiB,QACZ,gBAAe;AACtB,SAAQC,uBAAuB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yC,eAAelB,aAAakB;YAChCvB,aAAaoB,MAAM,CAACG,gBAAgB;gBAAC,GAAGF,KAAK;gBAAE,GAAG3D,cAAc6D,cAAc;YAAA,IAAIF;QACpF;QACA1C;IACF;IAEA,OAAO;QACLoB,OAAO;YACLC,aAAayB,OAAO;YACpB,MAAMnB,QAAQP,KAAK;QACrB;QACA2B,MAAM3E,cAAc;YAClBmC;YACAJ;YACAM,MAAMI,UAAUJ;YAChBe,MAAM1B,QAAQ,YAAY;QAC5B;IACF;AACF"}
@@ -1,6 +1,10 @@
1
1
  import { styleText } from 'node:util';
2
+ import { isWorkbenchApp } from '../../defineApp.js';
2
3
  import { createServerLifecycle, toDisplayHost } from '../../util/serverOrchestration.js';
4
+ import { formatSummary } from '../summary.js';
3
5
  import { startAppServerSupervisor } from './appServerSupervisor.js';
6
+ import { bindDevShortcuts } from './bindDevShortcuts.js';
7
+ import { fetchDevSummaryDetails, waitForDevSummaryDetails } from './devSummary.js';
4
8
  import { startDevServerRegistration } from './startDevServerRegistration.js';
5
9
  import { startWorkbenchDevServer, startWorkbenchRemoteCoordinator } from './startWorkbenchDevServer.js';
6
10
  /**
@@ -18,7 +22,6 @@ import { startWorkbenchDevServer, startWorkbenchRemoteCoordinator } from './star
18
22
  // shell) that still bridges the registry.
19
23
  if (process.env.SANITY_INTERNAL_IS_WORKBENCH_REMOTE === 'true') {
20
24
  const remote = await startAppServer({
21
- announceUrl: true,
22
25
  cliConfig,
23
26
  httpPort
24
27
  });
@@ -38,6 +41,13 @@ import { startWorkbenchDevServer, startWorkbenchRemoteCoordinator } from './star
38
41
  // Unwound in reverse on any failure or on close(): the watcher stops before
39
42
  // the app server, and the supervisor waits out an in-flight rebuild.
40
43
  const { close, closers, installSignalHandlers } = createServerLifecycle();
44
+ const startedAt = Date.now();
45
+ const app = isWorkbenchApp(cliConfig.app) ? cliConfig.app : undefined;
46
+ const organizationId = cliConfig.app?.organizationId;
47
+ const details = fetchDevSummaryDetails({
48
+ idOrSlug: app && (cliConfig.deployment?.appId ?? app.slug),
49
+ organizationId
50
+ });
41
51
  const workbench = await startWorkbenchDevServer({
42
52
  cacheDir,
43
53
  cliConfig,
@@ -51,13 +61,13 @@ import { startWorkbenchDevServer, startWorkbenchRemoteCoordinator } from './star
51
61
  // A running workbench owns the configured port; the app server takes the next.
52
62
  // Without one it claims the configured port and announces its own URL.
53
63
  const appPort = workbench.workbenchAvailable ? workbench.workbenchPort + 1 : httpPort;
54
- const announceUrl = !workbench.workbenchAvailable;
55
64
  const supervised = await startAppServerSupervisor({
56
65
  cliConfig,
57
- start: (config)=>startAppServer({
58
- announceUrl,
66
+ start: (config, { isRestarting } = {})=>startAppServer({
59
67
  cliConfig: config,
60
- httpPort: appPort
68
+ httpPort: appPort,
69
+ isRestarting,
70
+ quiet: workbench.workbenchAvailable
61
71
  }),
62
72
  workDir
63
73
  }).catch(async (err)=>{
@@ -94,14 +104,39 @@ import { startWorkbenchDevServer, startWorkbenchRemoteCoordinator } from './star
94
104
  await close();
95
105
  throw err;
96
106
  }
107
+ const durationMs = Date.now() - startedAt;
108
+ const { deployment, organizationName } = workbench.workbenchAvailable ? await waitForDevSummaryDetails(details) : {};
109
+ installSignalHandlers();
97
110
  if (workbench.workbenchAvailable) {
98
- const appUrl = `http://${toDisplayHost(workbench.httpHost)}:${workbench.workbenchPort}${dashboardAppPath ?? ''}`;
99
- output.log(`Dashboard dev server started at ${styleText([
100
- 'blue',
101
- 'underline'
102
- ], appUrl)}`);
111
+ const url = `http://${toDisplayHost(workbench.httpHost)}:${workbench.workbenchPort}${dashboardAppPath ?? ''}`;
112
+ let version = '';
113
+ if (deployment) {
114
+ const date = new Date(deployment.createdAt).toLocaleDateString('en-US', {
115
+ day: 'numeric',
116
+ month: 'short',
117
+ year: 'numeric'
118
+ });
119
+ const by = deployment.deployedBy ? ` by ${deployment.deployedBy}` : '';
120
+ version = `local preview ${styleText('dim', `· deployed ${date}${by}`)}`;
121
+ } else if (deployment === null) {
122
+ version = `local preview ${styleText('dim', '· not deployed')}`;
123
+ }
124
+ output.log(formatSummary({
125
+ durationMs,
126
+ heading: 'Sanity Dashboard ready',
127
+ isApp,
128
+ organization: organizationName ?? organizationId,
129
+ title: app?.title,
130
+ url,
131
+ version
132
+ }));
133
+ const quit = ()=>void close().then(()=>process.exit(0));
134
+ closers.push(bindDevShortcuts({
135
+ output,
136
+ quit,
137
+ url
138
+ }));
103
139
  }
104
- installSignalHandlers();
105
140
  return {
106
141
  close
107
142
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/actions/dev/startWorkbenchDev.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\nimport {type CliConfig, type Output} from '@sanity/cli-core'\n\nimport {createServerLifecycle, toDisplayHost} from '../../util/serverOrchestration.js'\nimport {type AppServerResult, startAppServerSupervisor} from './appServerSupervisor.js'\nimport {type DevServerManifest} from './registry.js'\nimport {startDevServerRegistration} from './startDevServerRegistration.js'\nimport {\n startWorkbenchDevServer,\n startWorkbenchRemoteCoordinator,\n} from './startWorkbenchDevServer.js'\n\nexport interface StartWorkbenchDevOptions {\n /** Directory for the workbench Vite server's dependency cache. */\n cacheDir: string\n /** CLI-domain `app.id`/`deployment.appId` deprecation check, run before registering. */\n checkForDeprecatedAppId: () => void\n cliConfig: CliConfig\n /** Extract the project manifest to inline into the registry (studio-vs-app handled by the CLI). */\n extractManifest: (params: {\n applicationId?: string\n configPath: string\n workDir: string\n }) => Promise<DevServerManifest['manifest']>\n httpHost: string | undefined\n httpPort: number\n isApp: boolean\n output: Output\n reactStrictMode: boolean\n /** Start the app/studio dev server — the CLI owns the server, this orchestrates it. */\n startAppServer: (params: {\n announceUrl: boolean\n cliConfig: CliConfig\n httpPort: number\n }) => Promise<AppServerResult>\n workDir: string\n}\n\n/**\n * Orchestrate the dev servers a workbench project needs: a singleton workbench\n * Vite server plus the app/studio dev server it renders, wired to the dev-server\n * registry so view/web worker edits re-sync live.\n *\n * A running workbench claims the configured port, so the app server binds the\n * next one. If the workbench can't start (package or port unavailable), the app\n * server falls back to the configured port and announces its own URL, exactly as\n * a plain `sanity dev` would.\n */\nexport async function startWorkbenchDev(\n options: StartWorkbenchDevOptions,\n): Promise<{close: () => Promise<void>}> {\n const {\n cacheDir,\n checkForDeprecatedAppId,\n cliConfig,\n extractManifest,\n httpHost,\n httpPort,\n isApp,\n output,\n reactStrictMode,\n startAppServer,\n workDir,\n } = options\n\n // The remote can't render itself, so it runs as a plain app server (not the\n // shell) that still bridges the registry.\n if (process.env.SANITY_INTERNAL_IS_WORKBENCH_REMOTE === 'true') {\n const remote = await startAppServer({announceUrl: true, cliConfig, httpPort})\n if (!remote.started) return {close: async () => {}}\n\n const coordinator = startWorkbenchRemoteCoordinator({server: remote.server})\n\n return {\n close: async () => {\n await coordinator.close()\n await remote.close()\n },\n }\n }\n\n // Unwound in reverse on any failure or on close(): the watcher stops before\n // the app server, and the supervisor waits out an in-flight rebuild.\n const {close, closers, installSignalHandlers} = createServerLifecycle()\n\n const workbench = await startWorkbenchDevServer({\n cacheDir,\n cliConfig,\n httpHost,\n httpPort,\n output,\n reactStrictMode,\n workDir,\n })\n closers.push(workbench.close)\n\n // A running workbench owns the configured port; the app server takes the next.\n // Without one it claims the configured port and announces its own URL.\n const appPort = workbench.workbenchAvailable ? workbench.workbenchPort + 1 : httpPort\n const announceUrl = !workbench.workbenchAvailable\n\n const supervised = await startAppServerSupervisor({\n cliConfig,\n start: (config) => startAppServer({announceUrl, cliConfig: config, httpPort: appPort}),\n workDir,\n }).catch(async (err) => {\n await close()\n throw err\n })\n\n if (!supervised.started) {\n // The app server already reported why (e.g. missing organization id). Hand\n // back a close that releases the workbench lock; nothing else came up.\n return {close}\n }\n const {supervisor} = supervised\n closers.push(supervisor.close)\n\n let dashboardAppPath: string | undefined\n try {\n // The deprecated-id check and manifest extractor are CLI-domain, injected here.\n checkForDeprecatedAppId()\n const registration = await startDevServerRegistration({\n cliConfig,\n extractManifest,\n isApp,\n onInterfaceSetChange: () => supervisor.rebuild(),\n output,\n server: supervisor.server,\n workDir,\n })\n closers.push(registration.close)\n dashboardAppPath = registration.path\n } catch (err) {\n // Registration runs after both servers are up; a failure here would leak the\n // workbench lock and dev servers without this teardown.\n await close()\n throw err\n }\n\n if (workbench.workbenchAvailable) {\n const appUrl = `http://${toDisplayHost(workbench.httpHost)}:${workbench.workbenchPort}${dashboardAppPath ?? ''}`\n output.log(`Dashboard dev server started at ${styleText(['blue', 'underline'], appUrl)}`)\n }\n\n installSignalHandlers()\n\n return {close}\n}\n"],"names":["styleText","createServerLifecycle","toDisplayHost","startAppServerSupervisor","startDevServerRegistration","startWorkbenchDevServer","startWorkbenchRemoteCoordinator","startWorkbenchDev","options","cacheDir","checkForDeprecatedAppId","cliConfig","extractManifest","httpHost","httpPort","isApp","output","reactStrictMode","startAppServer","workDir","process","env","SANITY_INTERNAL_IS_WORKBENCH_REMOTE","remote","announceUrl","started","close","coordinator","server","closers","installSignalHandlers","workbench","push","appPort","workbenchAvailable","workbenchPort","supervised","start","config","catch","err","supervisor","dashboardAppPath","registration","onInterfaceSetChange","rebuild","path","appUrl","log"],"mappings":"AAAA,SAAQA,SAAS,QAAO,YAAW;AAInC,SAAQC,qBAAqB,EAAEC,aAAa,QAAO,oCAAmC;AACtF,SAA8BC,wBAAwB,QAAO,2BAA0B;AAEvF,SAAQC,0BAA0B,QAAO,kCAAiC;AAC1E,SACEC,uBAAuB,EACvBC,+BAA+B,QAC1B,+BAA8B;AA4BrC;;;;;;;;;CASC,GACD,OAAO,eAAeC,kBACpBC,OAAiC;IAEjC,MAAM,EACJC,QAAQ,EACRC,uBAAuB,EACvBC,SAAS,EACTC,eAAe,EACfC,QAAQ,EACRC,QAAQ,EACRC,KAAK,EACLC,MAAM,EACNC,eAAe,EACfC,cAAc,EACdC,OAAO,EACR,GAAGX;IAEJ,4EAA4E;IAC5E,0CAA0C;IAC1C,IAAIY,QAAQC,GAAG,CAACC,mCAAmC,KAAK,QAAQ;QAC9D,MAAMC,SAAS,MAAML,eAA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gB,mBAAmBC,aAAaG,IAAI;IACtC,EAAE,OAAON,KAAK;QACZ,6EAA6E;QAC7E,wDAAwD;QACxD,MAAMd;QACN,MAAMc;IACR;IAEA,IAAIT,UAAUG,kBAAkB,EAAE;QAChC,MAAMa,SAAS,CAAC,OAAO,EAAE7C,cAAc6B,UAAUlB,QAAQ,EAAE,CAAC,EAAEkB,UAAUI,aAAa,GAAGO,oBAAoB,IAAI;QAChH1B,OAAOgC,GAAG,CAAC,CAAC,gCAAgC,EAAEhD,UAAU;YAAC;YAAQ;SAAY,EAAE+C,SAAS;IAC1F;IAEAjB;IAEA,OAAO;QAACJ;IAAK;AACf"}
1
+ {"version":3,"sources":["../../../src/actions/dev/startWorkbenchDev.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\nimport {type CliConfig, type Output} from '@sanity/cli-core'\n\nimport {isWorkbenchApp} from '../../defineApp.js'\nimport {createServerLifecycle, toDisplayHost} from '../../util/serverOrchestration.js'\nimport {formatSummary} from '../summary.js'\nimport {type AppServerResult, startAppServerSupervisor} from './appServerSupervisor.js'\nimport {bindDevShortcuts} from './bindDevShortcuts.js'\nimport {fetchDevSummaryDetails, waitForDevSummaryDetails} from './devSummary.js'\nimport {type DevServerManifest} from './registry.js'\nimport {startDevServerRegistration} from './startDevServerRegistration.js'\nimport {\n startWorkbenchDevServer,\n startWorkbenchRemoteCoordinator,\n} from './startWorkbenchDevServer.js'\n\nexport interface StartWorkbenchDevOptions {\n /** Directory for the workbench Vite server's dependency cache. */\n cacheDir: string\n /** CLI-domain `app.id`/`deployment.appId` deprecation check, run before registering. */\n checkForDeprecatedAppId: () => void\n cliConfig: CliConfig\n /** Extract the project manifest to inline into the registry (studio-vs-app handled by the CLI). */\n extractManifest: (params: {\n applicationId?: string\n configPath: string\n /** Where the app server serves the app's icon. */\n iconUrl?: string\n workDir: string\n }) => Promise<DevServerManifest['manifest']>\n httpHost: string | undefined\n httpPort: number\n isApp: boolean\n output: Output\n reactStrictMode: boolean\n /** Start the app/studio dev server — the CLI owns the server, this orchestrates it. */\n startAppServer: (params: {\n cliConfig: CliConfig\n httpPort: number\n isRestarting?: boolean\n quiet?: boolean\n }) => Promise<AppServerResult>\n workDir: string\n}\n\n/**\n * Orchestrate the dev servers a workbench project needs: a singleton workbench\n * Vite server plus the app/studio dev server it renders, wired to the dev-server\n * registry so view/web worker edits re-sync live.\n *\n * A running workbench claims the configured port, so the app server binds the\n * next one. If the workbench can't start (package or port unavailable), the app\n * server falls back to the configured port and announces its own URL, exactly as\n * a plain `sanity dev` would.\n */\nexport async function startWorkbenchDev(\n options: StartWorkbenchDevOptions,\n): Promise<{close: () => Promise<void>}> {\n const {\n cacheDir,\n checkForDeprecatedAppId,\n cliConfig,\n extractManifest,\n httpHost,\n httpPort,\n isApp,\n output,\n reactStrictMode,\n startAppServer,\n workDir,\n } = options\n\n // The remote can't render itself, so it runs as a plain app server (not the\n // shell) that still bridges the registry.\n if (process.env.SANITY_INTERNAL_IS_WORKBENCH_REMOTE === 'true') {\n const remote = await startAppServer({cliConfig, httpPort})\n if (!remote.started) return {close: async () => {}}\n\n const coordinator = startWorkbenchRemoteCoordinator({server: remote.server})\n\n return {\n close: async () => {\n await coordinator.close()\n await remote.close()\n },\n }\n }\n\n // Unwound in reverse on any failure or on close(): the watcher stops before\n // the app server, and the supervisor waits out an in-flight rebuild.\n const {close, closers, installSignalHandlers} = createServerLifecycle()\n const startedAt = Date.now()\n const app = isWorkbenchApp(cliConfig.app) ? cliConfig.app : undefined\n const organizationId = cliConfig.app?.organizationId\n const details = fetchDevSummaryDetails({\n idOrSlug: app && (cliConfig.deployment?.appId ?? app.slug),\n organizationId,\n })\n\n const workbench = await startWorkbenchDevServer({\n cacheDir,\n cliConfig,\n httpHost,\n httpPort,\n output,\n reactStrictMode,\n workDir,\n })\n closers.push(workbench.close)\n\n // A running workbench owns the configured port; the app server takes the next.\n // Without one it claims the configured port and announces its own URL.\n const appPort = workbench.workbenchAvailable ? workbench.workbenchPort + 1 : httpPort\n\n const supervised = await startAppServerSupervisor({\n cliConfig,\n start: (config, {isRestarting} = {}) =>\n startAppServer({\n cliConfig: config,\n httpPort: appPort,\n isRestarting,\n quiet: workbench.workbenchAvailable,\n }),\n workDir,\n }).catch(async (err) => {\n await close()\n throw err\n })\n\n if (!supervised.started) {\n // The app server already reported why (e.g. missing organization id). Hand\n // back a close that releases the workbench lock; nothing else came up.\n return {close}\n }\n const {supervisor} = supervised\n closers.push(supervisor.close)\n\n let dashboardAppPath: string | undefined\n try {\n // The deprecated-id check and manifest extractor are CLI-domain, injected here.\n checkForDeprecatedAppId()\n const registration = await startDevServerRegistration({\n cliConfig,\n extractManifest,\n isApp,\n onInterfaceSetChange: () => supervisor.rebuild(),\n output,\n server: supervisor.server,\n workDir,\n })\n closers.push(registration.close)\n dashboardAppPath = registration.path\n } catch (err) {\n // Registration runs after both servers are up; a failure here would leak the\n // workbench lock and dev servers without this teardown.\n await close()\n throw err\n }\n\n const durationMs = Date.now() - startedAt\n const {deployment, organizationName} = workbench.workbenchAvailable\n ? await waitForDevSummaryDetails(details)\n : {}\n\n installSignalHandlers()\n\n if (workbench.workbenchAvailable) {\n const url = `http://${toDisplayHost(workbench.httpHost)}:${workbench.workbenchPort}${dashboardAppPath ?? ''}`\n let version = ''\n\n if (deployment) {\n const date = new Date(deployment.createdAt).toLocaleDateString('en-US', {\n day: 'numeric',\n month: 'short',\n year: 'numeric',\n })\n const by = deployment.deployedBy ? ` by ${deployment.deployedBy}` : ''\n version = `local preview ${styleText('dim', `· deployed ${date}${by}`)}`\n } else if (deployment === null) {\n version = `local preview ${styleText('dim', '· not deployed')}`\n }\n\n output.log(\n formatSummary({\n durationMs,\n heading: 'Sanity Dashboard ready',\n isApp,\n organization: organizationName ?? organizationId,\n title: app?.title,\n url,\n version,\n }),\n )\n\n const quit = () => void close().then(() => process.exit(0))\n closers.push(bindDevShortcuts({output, quit, url}))\n }\n\n return {close}\n}\n"],"names":["styleText","isWorkbenchApp","createServerLifecycle","toDisplayHost","formatSummary","startAppServerSupervisor","bindDevShortcuts","fetchDevSummaryDetails","waitForDevSummaryDetails","startDevServerRegistration","startWorkbenchDevServer","startWorkbenchRemoteCoordinator","startWorkbenchDev","options","cacheDir","checkForDeprecatedAppId","cliConfig","extractManifest","httpHost","httpPort","isApp","output","reactStrictMode","startAppServer","workDir","process","env","SANITY_INTERNAL_IS_WORKBENCH_REMOTE","remote","started","close","coordinator","server","closers","installSignalHandlers","startedAt","Date","now","app","undefined","organizationId","details","idOrSlug","deployment","appId","slug","workbench","push","appPort","workbenchAvailable","workbenchPort","supervised","start","config","isRestarting","quiet","catch","err","supervisor","dashboardAppPath","registration","onInterfaceSetChange","rebuild","path","durationMs","organizationName","url","version","date","createdAt","toLocaleDateString","day","month","year","by","deployedBy","log","heading","organization","title","quit","then","exit"],"mappings":"AAAA,SAAQA,SAAS,QAAO,YAAW;AAInC,SAAQC,cAAc,QAAO,qBAAoB;AACjD,SAAQC,qBAAqB,EAAEC,aAAa,QAAO,oCAAmC;AACtF,SAAQC,aAAa,QAAO,gBAAe;AAC3C,SAA8BC,wBAAwB,QAAO,2BAA0B;AACvF,SAAQC,gBAAgB,QAAO,wBAAuB;AACtD,SAAQC,sBAAsB,EAAEC,wBAAwB,QAAO,kBAAiB;AAEhF,SAAQC,0BAA0B,QAAO,kCAAiC;AAC1E,SACEC,uBAAuB,EACvBC,+BAA+B,QAC1B,+BAA8B;AA+BrC;;;;;;;;;CASC,GACD,OAAO,eAAeC,kBACpBC,OAAiC;IAEjC,MAAM,EACJC,QAAQ,EACRC,uBAAuB,EACvBC,SAAS,EACTC,eAAe,EACfC,QAAQ,EACRC,QAAQ,EACRC,KAAK,EACLC,MAAM,EACNC,eAAe,EACfC,cAAc,EACdC,OAAO,EACR,GAAGX;IAEJ,4EAA4E;IAC5E,0CAA0C;IAC1C,IAAIY,QAAQC,GAAG,CAACC,mCAAmC,KAAK,QAAQ;QAC9D,MAAMC,SAAS,MAAML,eAAe;YAACP;YAAWG;QAA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BzB;YAClCuC,OAAOzC,KAAKyC;YACZb;YACAC;QACF;QAGF,MAAMa,OAAO,IAAM,KAAKlD,QAAQmD,IAAI,CAAC,IAAMxD,QAAQyD,IAAI,CAAC;QACxDjD,QAAQc,IAAI,CAACzC,iBAAiB;YAACe;YAAQ2D;YAAMd;QAAG;IAClD;IAEA,OAAO;QAACpC;IAAK;AACf"}
@@ -11,7 +11,7 @@ const previewDebug = subdebug('preview');
11
11
  * `readBuiltManifest`) so the command shows the same "run sanity build" hint the
12
12
  * studio preview path does; real I/O errors surface as themselves.
13
13
  */ export async function serveBuiltApplication(options) {
14
- const { cacheDir, httpHost, httpPort, outDir, workDir } = options;
14
+ const { cacheDir, httpHost, httpPort, icon, outDir, workDir } = options;
15
15
  await readBuiltManifest(outDir);
16
16
  const config = {
17
17
  // Serve at the root so `mf-manifest.json` and its `publicPath: 'auto'` chunks
@@ -25,6 +25,17 @@ const previewDebug = subdebug('preview');
25
25
  configFile: false,
26
26
  logLevel: 'warn',
27
27
  mode: 'production',
28
+ plugins: icon ? [
29
+ {
30
+ configurePreviewServer (server) {
31
+ server.middlewares.use(icon.path, (_req, res)=>{
32
+ res.setHeader('Content-Type', icon.contentType);
33
+ res.end(icon.image);
34
+ });
35
+ },
36
+ name: 'sanity:app-icon'
37
+ }
38
+ ] : [],
28
39
  preview: {
29
40
  host: httpHost,
30
41
  port: httpPort,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/actions/preview/serveBuiltApplication.ts"],"sourcesContent":["import {subdebug} from '@sanity/cli-core'\nimport {type InlineConfig, preview} from 'vite'\n\nimport {readBuiltManifest} from '../build/readBuiltManifest.js'\n\nconst previewDebug = subdebug('preview')\n\nexport interface BuiltApplicationServer {\n close: () => Promise<void>\n /** Routable host the remote is reachable at, for the registry's remote URL. */\n host: string\n /** Port Vite bound — may differ from the requested one under non-strict ports. */\n port: number\n}\n\n/**\n * Serve a built workbench app's `dist` as static files over a Vite `preview`\n * server, so its manifest and referenced assets are reachable exactly as\n * a live `sanity dev` remote would be — the workbench then federates it in.\n *\n * A missing federation build surfaces as `BUILD_NOT_FOUND` (from\n * `readBuiltManifest`) so the command shows the same \"run sanity build\" hint the\n * studio preview path does; real I/O errors surface as themselves.\n */\nexport async function serveBuiltApplication(options: {\n cacheDir: string\n httpHost: string\n httpPort: number\n outDir: string\n workDir: string\n}): Promise<BuiltApplicationServer> {\n const {cacheDir, httpHost, httpPort, outDir, workDir} = options\n\n await readBuiltManifest(outDir)\n\n const config: InlineConfig = {\n // Serve at the root so `mf-manifest.json` and its `publicPath: 'auto'` chunks\n // resolve under the registered remote URL.\n base: '/',\n // Needed for vite to serve `outDir` itself rather than `outDir/dist`.\n build: {outDir},\n cacheDir,\n configFile: false,\n logLevel: 'warn',\n mode: 'production',\n preview: {host: httpHost, port: httpPort, strictPort: false},\n root: workDir,\n }\n\n previewDebug('Serving built remote from %s', outDir)\n const server = await preview(config)\n\n const addr = server.httpServer.address()\n const port = typeof addr === 'object' && addr ? addr.port : httpPort\n\n return {\n // Drop idle keep-alive sockets so shutdown doesn't stall on a browser that\n // kept the connection open — otherwise `close` waits out the teardown grace.\n // `closeAllConnections` isn't on Vite's `HttpServer` type, but is on the\n // underlying node server (18.2+); the optional call tolerates its absence.\n close: () =>\n new Promise((resolve, reject) => {\n server.httpServer.close((err) => (err ? reject(err) : resolve()))\n ;(server.httpServer as {closeAllConnections?: () => void}).closeAllConnections?.()\n }),\n host: httpHost,\n port,\n }\n}\n"],"names":["subdebug","preview","readBuiltManifest","previewDebug","serveBuiltApplication","options","cacheDir","httpHost","httpPort","outDir","workDir","config","base","build","configFile","logLevel","mode","host","port","strictPort","root","server","addr","httpServer","address","close","Promise","resolve","reject","err","closeAllConnections"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,mBAAkB;AACzC,SAA2BC,OAAO,QAAO,OAAM;AAE/C,SAAQC,iBAAiB,QAAO,gCAA+B;AAE/D,MAAMC,eAAeH,SAAS;AAU9B;;;;;;;;CAQC,GACD,OAAO,eAAeI,sBAAsBC,OAM3C;IACC,MAAM,EAACC,QAAQ,EAAEC,QAAQ,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,OAAO,EAAC,GAAGL;IAExD,MAAMH,kBAAkBO;IAExB,MAAME,SAAuB;QAC3B,8EAA8E;QAC9E,2CAA2C;QAC3CC,MAAM;QACN,sEAAsE;QACtEC,OAAO;YAACJ;QAAM;QACdH;QACAQ,YAAY;QACZC,UAAU;QACVC,MAAM;QACNf,SAAS;YAACgB,MAAMV;YAAUW,MAAMV;YAAUW,YAAY;QAAK;QAC3DC,MAAMV;IACR;IAEAP,aAAa,gCAAgCM;IAC7C,MAAMY,SAAS,MAAMpB,QAAQU;IAE7B,MAAMW,OAAOD,OAAOE,UAAU,CAACC,OAAO;IACtC,MAAMN,OAAO,OAAOI,SAAS,YAAYA,OAAOA,KAAKJ,IAAI,GAAGV;IAE5D,OAAO;QACL,2EAA2E;QAC3E,6EAA6E;QAC7E,yEAAyE;QACzE,2EAA2E;QAC3EiB,OAAO,IACL,IAAIC,QAAQ,CAACC,SAASC;gBACpBP,OAAOE,UAAU,CAACE,KAAK,CAAC,CAACI,MAASA,MAAMD,OAAOC,OAAOF;gBACpDN,OAAOE,UAAU,CAAwCO,mBAAmB;YAChF;QACFb,MAAMV;QACNW;IACF;AACF"}
1
+ {"version":3,"sources":["../../../src/actions/preview/serveBuiltApplication.ts"],"sourcesContent":["import {subdebug} from '@sanity/cli-core'\nimport {type ImageFile} from '@sanity/cli-core/images'\nimport {type InlineConfig, preview} from 'vite'\n\nimport {readBuiltManifest} from '../build/readBuiltManifest.js'\n\nconst previewDebug = subdebug('preview')\n\nexport interface BuiltApplicationServer {\n close: () => Promise<void>\n /** Routable host the remote is reachable at, for the registry's remote URL. */\n host: string\n /** Port Vite bound — may differ from the requested one under non-strict ports. */\n port: number\n}\n\n/**\n * Serve a built workbench app's `dist` as static files over a Vite `preview`\n * server, so its manifest and referenced assets are reachable exactly as\n * a live `sanity dev` remote would be — the workbench then federates it in.\n *\n * A missing federation build surfaces as `BUILD_NOT_FOUND` (from\n * `readBuiltManifest`) so the command shows the same \"run sanity build\" hint the\n * studio preview path does; real I/O errors surface as themselves.\n */\nexport async function serveBuiltApplication(options: {\n cacheDir: string\n httpHost: string\n httpPort: number\n /** The app's icon, served at `path`: it lives in the project, not in `outDir`. */\n icon?: ImageFile & {path: string}\n outDir: string\n workDir: string\n}): Promise<BuiltApplicationServer> {\n const {cacheDir, httpHost, httpPort, icon, outDir, workDir} = options\n\n await readBuiltManifest(outDir)\n\n const config: InlineConfig = {\n // Serve at the root so `mf-manifest.json` and its `publicPath: 'auto'` chunks\n // resolve under the registered remote URL.\n base: '/',\n // Needed for vite to serve `outDir` itself rather than `outDir/dist`.\n build: {outDir},\n cacheDir,\n configFile: false,\n logLevel: 'warn',\n mode: 'production',\n plugins: icon\n ? [\n {\n configurePreviewServer(server) {\n server.middlewares.use(icon.path, (_req, res) => {\n res.setHeader('Content-Type', icon.contentType)\n res.end(icon.image)\n })\n },\n name: 'sanity:app-icon',\n },\n ]\n : [],\n preview: {host: httpHost, port: httpPort, strictPort: false},\n root: workDir,\n }\n\n previewDebug('Serving built remote from %s', outDir)\n const server = await preview(config)\n\n const addr = server.httpServer.address()\n const port = typeof addr === 'object' && addr ? addr.port : httpPort\n\n return {\n // Drop idle keep-alive sockets so shutdown doesn't stall on a browser that\n // kept the connection open — otherwise `close` waits out the teardown grace.\n // `closeAllConnections` isn't on Vite's `HttpServer` type, but is on the\n // underlying node server (18.2+); the optional call tolerates its absence.\n close: () =>\n new Promise((resolve, reject) => {\n server.httpServer.close((err) => (err ? reject(err) : resolve()))\n ;(server.httpServer as {closeAllConnections?: () => void}).closeAllConnections?.()\n }),\n host: httpHost,\n port,\n }\n}\n"],"names":["subdebug","preview","readBuiltManifest","previewDebug","serveBuiltApplication","options","cacheDir","httpHost","httpPort","icon","outDir","workDir","config","base","build","configFile","logLevel","mode","plugins","configurePreviewServer","server","middlewares","use","path","_req","res","setHeader","contentType","end","image","name","host","port","strictPort","root","addr","httpServer","address","close","Promise","resolve","reject","err","closeAllConnections"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,mBAAkB;AAEzC,SAA2BC,OAAO,QAAO,OAAM;AAE/C,SAAQC,iBAAiB,QAAO,gCAA+B;AAE/D,MAAMC,eAAeH,SAAS;AAU9B;;;;;;;;CAQC,GACD,OAAO,eAAeI,sBAAsBC,OAQ3C;IACC,MAAM,EAACC,QAAQ,EAAEC,QAAQ,EAAEC,QAAQ,EAAEC,IAAI,EAAEC,MAAM,EAAEC,OAAO,EAAC,GAAGN;IAE9D,MAAMH,kBAAkBQ;IAExB,MAAME,SAAuB;QAC3B,8EAA8E;QAC9E,2CAA2C;QAC3CC,MAAM;QACN,sEAAsE;QACtEC,OAAO;YAACJ;QAAM;QACdJ;QACAS,YAAY;QACZC,UAAU;QACVC,MAAM;QACNC,SAAST,OACL;YACE;gBACEU,wBAAuBC,MAAM;oBAC3BA,OAAOC,WAAW,CAACC,GAAG,CAACb,KAAKc,IAAI,EAAE,CAACC,MAAMC;wBACvCA,IAAIC,SAAS,CAAC,gBAAgBjB,KAAKkB,WAAW;wBAC9CF,IAAIG,GAAG,CAACnB,KAAKoB,KAAK;oBACpB;gBACF;gBACAC,MAAM;YACR;SACD,GACD,EAAE;QACN7B,SAAS;YAAC8B,MAAMxB;YAAUyB,MAAMxB;YAAUyB,YAAY;QAAK;QAC3DC,MAAMvB;IACR;IAEAR,aAAa,gCAAgCO;IAC7C,MAAMU,SAAS,MAAMnB,QAAQW;IAE7B,MAAMuB,OAAOf,OAAOgB,UAAU,CAACC,OAAO;IACtC,MAAML,OAAO,OAAOG,SAAS,YAAYA,OAAOA,KAAKH,IAAI,GAAGxB;IAE5D,OAAO;QACL,2EAA2E;QAC3E,6EAA6E;QAC7E,yEAAyE;QACzE,2EAA2E;QAC3E8B,OAAO,IACL,IAAIC,QAAQ,CAACC,SAASC;gBACpBrB,OAAOgB,UAAU,CAACE,KAAK,CAAC,CAACI,MAASA,MAAMD,OAAOC,OAAOF;gBACpDpB,OAAOgB,UAAU,CAAwCO,mBAAmB;YAChF;QACFZ,MAAMxB;QACNyB;IACF;AACF"}
@@ -3,7 +3,9 @@ import path from 'node:path';
3
3
  import { styleText } from 'node:util';
4
4
  import { findProjectRoot } from '@sanity/cli-core';
5
5
  import { buildAppId, SANITY_APP_ID_FILE } from '../../appId.js';
6
+ import { isWorkbenchApp } from '../../defineApp.js';
6
7
  import { deriveInterfaces } from '../../deriveInterfaces.js';
8
+ import { readAppIcon, toUrlPath } from '../../readAppIcon.js';
7
9
  import { resolveWorkbenchApp } from '../../resolveWorkbenchApp.js';
8
10
  import { createServerLifecycle, toDisplayHost } from '../../util/serverOrchestration.js';
9
11
  import { deriveConfigs } from '../dev/deriveConfigs.js';
@@ -22,6 +24,13 @@ import { serveBuiltApplication } from './serveBuiltApplication.js';
22
24
  * own URL.
23
25
  */ export async function startWorkbenchPreview(options) {
24
26
  const { cacheDir, checkForDeprecatedAppId, cliConfig, extractManifest, httpHost, httpPort, isApp, outDir, output, reactStrictMode, workDir } = options;
27
+ // Read before any server starts, so a bad icon path fails with nothing to tear down.
28
+ const iconPath = isApp && isWorkbenchApp(cliConfig.app) ? cliConfig.app.icon : undefined;
29
+ const icon = iconPath ? await readAppIcon(workDir, iconPath) : undefined;
30
+ const servedIcon = icon && {
31
+ ...icon,
32
+ path: `/${toUrlPath(workDir, icon.file)}`
33
+ };
25
34
  const { close, closers, installSignalHandlers } = createServerLifecycle();
26
35
  const workbench = await startWorkbenchDevServer({
27
36
  cacheDir,
@@ -38,6 +47,7 @@ import { serveBuiltApplication } from './serveBuiltApplication.js';
38
47
  cacheDir,
39
48
  httpHost,
40
49
  httpPort: remotePort,
50
+ icon: servedIcon,
41
51
  outDir,
42
52
  workDir
43
53
  }).catch(async (err)=>{
@@ -70,6 +80,7 @@ import { serveBuiltApplication } from './serveBuiltApplication.js';
70
80
  manifest: await extractManifest({
71
81
  applicationId: id,
72
82
  configPath,
83
+ iconUrl: servedIcon && `http://${remote.host}:${remote.port}${servedIcon.path}`,
73
84
  workDir
74
85
  }),
75
86
  manifestUpdatedAt: new Date().toISOString(),
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/actions/preview/startWorkbenchPreview.ts"],"sourcesContent":["import {readFile} from 'node:fs/promises'\nimport path from 'node:path'\nimport {styleText} from 'node:util'\n\nimport {type CliConfig, findProjectRoot, type Output} from '@sanity/cli-core'\n\nimport {buildAppId, SANITY_APP_ID_FILE} from '../../appId.js'\nimport {deriveInterfaces} from '../../deriveInterfaces.js'\nimport {resolveWorkbenchApp} from '../../resolveWorkbenchApp.js'\nimport {createServerLifecycle, toDisplayHost} from '../../util/serverOrchestration.js'\nimport {deriveConfigs} from '../dev/deriveConfigs.js'\nimport {\n dashboardPath,\n type DevServerManifest,\n localAppIdentity,\n registerDevServer,\n} from '../dev/registry.js'\nimport {startWorkbenchDevServer} from '../dev/startWorkbenchDevServer.js'\nimport {serveBuiltApplication} from './serveBuiltApplication.js'\n\nexport interface StartWorkbenchPreviewOptions {\n /** Directory for the workbench Vite server's dependency cache. */\n cacheDir: string\n /** CLI-domain `app.id`/`deployment.appId` deprecation check, run before registering. */\n checkForDeprecatedAppId: () => void\n cliConfig: CliConfig\n /** Extract the project manifest to inline into the registry (studio-vs-app handled by the CLI). */\n extractManifest: (params: {\n applicationId?: string\n configPath: string\n workDir: string\n }) => Promise<DevServerManifest['manifest']>\n httpHost: string\n httpPort: number\n isApp: boolean\n /** The built `dist` directory to serve as the federation remote. */\n outDir: string\n output: Output\n reactStrictMode: boolean\n workDir: string\n}\n\n/**\n * `sanity start` for a workbench app: serve a production build the way dev serves\n * a live one. The same singleton workbench shell renders it and the same registry\n * advertises it — only the remote differs, static files from the build output\n * instead of a live Vite dev server. There's no config watcher or rebuild: a\n * build is fixed, so nothing re-syncs.\n *\n * A running workbench claims the configured port, so the built remote binds the\n * next one. Without one the remote takes the configured port and announces its\n * own URL.\n */\nexport async function startWorkbenchPreview(\n options: StartWorkbenchPreviewOptions,\n): Promise<{close: () => Promise<void>}> {\n const {\n cacheDir,\n checkForDeprecatedAppId,\n cliConfig,\n extractManifest,\n httpHost,\n httpPort,\n isApp,\n outDir,\n output,\n reactStrictMode,\n workDir,\n } = options\n\n const {close, closers, installSignalHandlers} = createServerLifecycle()\n\n const workbench = await startWorkbenchDevServer({\n cacheDir,\n cliConfig,\n httpHost,\n httpPort,\n output,\n reactStrictMode,\n workDir,\n })\n closers.push(workbench.close)\n\n const remotePort = workbench.workbenchAvailable ? workbench.workbenchPort + 1 : httpPort\n\n const remote = await serveBuiltApplication({\n cacheDir,\n httpHost,\n httpPort: remotePort,\n outDir,\n workDir,\n }).catch(async (err) => {\n await close()\n throw err\n })\n closers.push(remote.close)\n\n let dashboardAppPath: string | undefined\n try {\n // Callers provide CLI-only validation and manifest extraction to keep them\n // out of workbench-cli.\n checkForDeprecatedAppId()\n const configPath = (await findProjectRoot(workDir)).path\n const workbench = resolveWorkbenchApp(cliConfig)\n\n if (!workbench) {\n throw new Error(\n '`sanity start` was invoked in an application that is not set up for the Dashboard',\n )\n }\n const inlinedId = await readInlinedAppId(outDir)\n const configs = await deriveConfigs(cliConfig)\n const id = inlinedId ?? (await buildAppId(workbench))\n const interfaces = deriveInterfaces(cliConfig.app, {isApp})\n const registration = registerDevServer({\n applicationId: cliConfig.deployment?.appId,\n configs,\n host: remote.host,\n id,\n interfaces,\n manifest: await extractManifest({applicationId: id, configPath, workDir}),\n manifestUpdatedAt: new Date().toISOString(),\n port: remote.port,\n projectId: cliConfig?.api?.projectId,\n ...localAppIdentity(workbench),\n type: isApp ? 'coreApp' : 'studio',\n workDir,\n })\n closers.push(async () => registration.release())\n dashboardAppPath = dashboardPath({\n id,\n interfaces,\n slug: workbench.slug,\n type: isApp ? 'coreApp' : 'studio',\n })\n } catch (err) {\n await close()\n throw err\n }\n\n if (workbench.workbenchAvailable) {\n const appUrl = `http://${toDisplayHost(workbench.httpHost)}:${workbench.workbenchPort}${dashboardAppPath ?? ''}`\n output.log(`Dashboard preview server started at ${styleText(['blue', 'underline'], appUrl)}`)\n } else {\n const remoteUrl = `http://${toDisplayHost(remote.host)}:${remote.port}`\n output.log(`Serving build at ${styleText(['blue', 'underline'], remoteUrl)}`)\n }\n\n installSignalHandlers()\n\n return {close}\n}\n\n/** The id the build inlined into its bundle, or undefined when absent. */\nasync function readInlinedAppId(outDir: string): Promise<string | undefined> {\n try {\n return (await readFile(path.join(outDir, SANITY_APP_ID_FILE), 'utf8')).trim() || undefined\n } catch {\n return undefined\n }\n}\n"],"names":["readFile","path","styleText","findProjectRoot","buildAppId","SANITY_APP_ID_FILE","deriveInterfaces","resolveWorkbenchApp","createServerLifecycle","toDisplayHost","deriveConfigs","dashboardPath","localAppIdentity","registerDevServer","startWorkbenchDevServer","serveBuiltApplication","startWorkbenchPreview","options","cacheDir","checkForDeprecatedAppId","cliConfig","extractManifest","httpHost","httpPort","isApp","outDir","output","reactStrictMode","workDir","close","closers","installSignalHandlers","workbench","push","remotePort","workbenchAvailable","workbenchPort","remote","catch","err","dashboardAppPath","configPath","Error","inlinedId","readInlinedAppId","configs","id","interfaces","app","registration","applicationId","deployment","appId","host","manifest","manifestUpdatedAt","Date","toISOString","port","projectId","api","type","release","slug","appUrl","log","remoteUrl","join","trim","undefined"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,mBAAkB;AACzC,OAAOC,UAAU,YAAW;AAC5B,SAAQC,SAAS,QAAO,YAAW;AAEnC,SAAwBC,eAAe,QAAoB,mBAAkB;AAE7E,SAAQC,UAAU,EAAEC,kBAAkB,QAAO,iBAAgB;AAC7D,SAAQC,gBAAgB,QAAO,4BAA2B;AAC1D,SAAQC,mBAAmB,QAAO,+BAA8B;AAChE,SAAQC,qBAAqB,EAAEC,aAAa,QAAO,oCAAmC;AACtF,SAAQC,aAAa,QAAO,0BAAyB;AACrD,SACEC,aAAa,EAEbC,gBAAgB,EAChBC,iBAAiB,QACZ,qBAAoB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cesContent":["import {readFile} from 'node:fs/promises'\nimport path from 'node:path'\nimport {styleText} from 'node:util'\n\nimport {type CliConfig, findProjectRoot, type Output} from '@sanity/cli-core'\n\nimport {buildAppId, SANITY_APP_ID_FILE} from '../../appId.js'\nimport {isWorkbenchApp} from '../../defineApp.js'\nimport {deriveInterfaces} from '../../deriveInterfaces.js'\nimport {readAppIcon, toUrlPath} from '../../readAppIcon.js'\nimport {resolveWorkbenchApp} from '../../resolveWorkbenchApp.js'\nimport {createServerLifecycle, toDisplayHost} from '../../util/serverOrchestration.js'\nimport {deriveConfigs} from '../dev/deriveConfigs.js'\nimport {\n dashboardPath,\n type DevServerManifest,\n localAppIdentity,\n registerDevServer,\n} from '../dev/registry.js'\nimport {startWorkbenchDevServer} from '../dev/startWorkbenchDevServer.js'\nimport {serveBuiltApplication} from './serveBuiltApplication.js'\n\nexport interface StartWorkbenchPreviewOptions {\n /** Directory for the workbench Vite server's dependency cache. */\n cacheDir: string\n /** CLI-domain `app.id`/`deployment.appId` deprecation check, run before registering. */\n checkForDeprecatedAppId: () => void\n cliConfig: CliConfig\n /** Extract the project manifest to inline into the registry (studio-vs-app handled by the CLI). */\n extractManifest: (params: {\n applicationId?: string\n configPath: string\n /** Where the preview serves the app's icon. */\n iconUrl?: string\n workDir: string\n }) => Promise<DevServerManifest['manifest']>\n httpHost: string\n httpPort: number\n isApp: boolean\n /** The built `dist` directory to serve as the federation remote. */\n outDir: string\n output: Output\n reactStrictMode: boolean\n workDir: string\n}\n\n/**\n * `sanity start` for a workbench app: serve a production build the way dev serves\n * a live one. The same singleton workbench shell renders it and the same registry\n * advertises it — only the remote differs, static files from the build output\n * instead of a live Vite dev server. There's no config watcher or rebuild: a\n * build is fixed, so nothing re-syncs.\n *\n * A running workbench claims the configured port, so the built remote binds the\n * next one. Without one the remote takes the configured port and announces its\n * own URL.\n */\nexport async function startWorkbenchPreview(\n options: StartWorkbenchPreviewOptions,\n): Promise<{close: () => Promise<void>}> {\n const {\n cacheDir,\n checkForDeprecatedAppId,\n cliConfig,\n extractManifest,\n httpHost,\n httpPort,\n isApp,\n outDir,\n output,\n reactStrictMode,\n workDir,\n } = options\n\n // Read before any server starts, so a bad icon path fails with nothing to tear down.\n const iconPath = isApp && isWorkbenchApp(cliConfig.app) ? cliConfig.app.icon : undefined\n const icon = iconPath ? await readAppIcon(workDir, iconPath) : undefined\n const servedIcon = icon && {...icon, path: `/${toUrlPath(workDir, icon.file)}`}\n\n const {close, closers, installSignalHandlers} = createServerLifecycle()\n\n const workbench = await startWorkbenchDevServer({\n cacheDir,\n cliConfig,\n httpHost,\n httpPort,\n output,\n reactStrictMode,\n workDir,\n })\n closers.push(workbench.close)\n\n const remotePort = workbench.workbenchAvailable ? workbench.workbenchPort + 1 : httpPort\n\n const remote = await serveBuiltApplication({\n cacheDir,\n httpHost,\n httpPort: remotePort,\n icon: servedIcon,\n outDir,\n workDir,\n }).catch(async (err) => {\n await close()\n throw err\n })\n closers.push(remote.close)\n\n let dashboardAppPath: string | undefined\n try {\n // Callers provide CLI-only validation and manifest extraction to keep them\n // out of workbench-cli.\n checkForDeprecatedAppId()\n const configPath = (await findProjectRoot(workDir)).path\n const workbench = resolveWorkbenchApp(cliConfig)\n\n if (!workbench) {\n throw new Error(\n '`sanity start` was invoked in an application that is not set up for the Dashboard',\n )\n }\n const inlinedId = await readInlinedAppId(outDir)\n const configs = await deriveConfigs(cliConfig)\n const id = inlinedId ?? (await buildAppId(workbench))\n const interfaces = deriveInterfaces(cliConfig.app, {isApp})\n const registration = registerDevServer({\n applicationId: cliConfig.deployment?.appId,\n configs,\n host: remote.host,\n id,\n interfaces,\n manifest: await extractManifest({\n applicationId: id,\n configPath,\n iconUrl: servedIcon && `http://${remote.host}:${remote.port}${servedIcon.path}`,\n workDir,\n }),\n manifestUpdatedAt: new Date().toISOString(),\n port: remote.port,\n projectId: cliConfig?.api?.projectId,\n ...localAppIdentity(workbench),\n type: isApp ? 'coreApp' : 'studio',\n workDir,\n })\n closers.push(async () => registration.release())\n dashboardAppPath = dashboardPath({\n id,\n interfaces,\n slug: workbench.slug,\n type: isApp ? 'coreApp' : 'studio',\n })\n } catch (err) {\n await close()\n throw err\n }\n\n if (workbench.workbenchAvailable) {\n const appUrl = `http://${toDisplayHost(workbench.httpHost)}:${workbench.workbenchPort}${dashboardAppPath ?? ''}`\n output.log(`Dashboard preview server started at ${styleText(['blue', 'underline'], appUrl)}`)\n } else {\n const remoteUrl = `http://${toDisplayHost(remote.host)}:${remote.port}`\n output.log(`Serving build at ${styleText(['blue', 'underline'], remoteUrl)}`)\n }\n\n installSignalHandlers()\n\n return {close}\n}\n\n/** The id the build inlined into its bundle, or undefined when absent. */\nasync function readInlinedAppId(outDir: string): Promise<string | undefined> {\n try {\n return (await readFile(path.join(outDir, SANITY_APP_ID_FILE), 'utf8')).trim() || undefined\n } catch {\n return undefined\n }\n}\n"],"names":["readFile","path","styleText","findProjectRoot","buildAppId","SANITY_APP_ID_FILE","isWorkbenchApp","deriveInterfaces","readAppIcon","toUrlPath","resolveWorkbenchApp","createServerLifecycle","toDisplayHost","deriveConfigs","dashboardPath","localAppIdentity","registerDevServer","startWorkbenchDevServer","serveBuiltApplication","startWorkbenchPreview","options","cacheDir","checkForDeprecatedAppId","cliConfig","extractManifest","httpHost","httpPort","isApp","outDir","output","reactStrictMode","workDir","iconPath","app","icon","undefined","servedIcon","file","close","closers","installSignalHandlers","workbench","push","remotePort","workbenchAvailable","workbenchPort","remote","catch","err","dashboardAppPath","configPath","Error","inlinedId","readInlinedAppId","configs","id","interfaces","registration","applicationId","deployment","appId","host","manifest","iconUrl","port","manifestUpdatedAt","Date","toISOString","projectId","api","type","release","slug","appUrl","log","remoteUrl","join","trim"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,mBAAkB;AACzC,OAAOC,UAAU,YAAW;AAC5B,SAAQC,SAAS,QAAO,YAAW;AAEnC,SAAwBC,eAAe,QAAoB,mBAAkB;AAE7E,SAAQC,UAAU,EAAEC,kBAAkB,QAA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AAkB,EAAE;QAChC,MAAM6B,SAAS,CAAC,OAAO,EAAE7D,cAAc6B,UAAUhB,QAAQ,EAAE,CAAC,EAAEgB,UAAUI,aAAa,GAAGI,oBAAoB,IAAI;QAChHpB,OAAO6C,GAAG,CAAC,CAAC,oCAAoC,EAAExE,UAAU;YAAC;YAAQ;SAAY,EAAEuE,SAAS;IAC9F,OAAO;QACL,MAAME,YAAY,CAAC,OAAO,EAAE/D,cAAckC,OAAOe,IAAI,EAAE,CAAC,EAAEf,OAAOkB,IAAI,EAAE;QACvEnC,OAAO6C,GAAG,CAAC,CAAC,iBAAiB,EAAExE,UAAU;YAAC;YAAQ;SAAY,EAAEyE,YAAY;IAC9E;IAEAnC;IAEA,OAAO;QAACF;IAAK;AACf;AAEA,wEAAwE,GACxE,eAAee,iBAAiBzB,MAAc;IAC5C,IAAI;QACF,OAAO,AAAC,CAAA,MAAM5B,SAASC,KAAK2E,IAAI,CAAChD,QAAQvB,qBAAqB,OAAM,EAAGwE,IAAI,MAAM1C;IACnF,EAAE,OAAM;QACN,OAAOA;IACT;AACF"}
@@ -0,0 +1,19 @@
1
+ import { styleText } from 'node:util';
2
+ export const SUMMARY_LOOKUP_TIMEOUT_MS = 3000;
3
+ export function formatSummary({ durationMs, heading, isApp, organization, title, url, version }) {
4
+ const seconds = (durationMs / 1000).toFixed(1);
5
+ const titleRow = title ? `\n ${(isApp ? 'App' : 'Studio').padEnd(12)} ${title}` : '';
6
+ const link = styleText([
7
+ 'blue',
8
+ 'underline'
9
+ ], url);
10
+ const versionRow = version ? `\n Version ${version}` : '';
11
+ return `
12
+ ${heading} in ${seconds}s
13
+
14
+ Organization ${organization}${titleRow}
15
+ URL ${link}${versionRow}
16
+ `;
17
+ }
18
+
19
+ //# sourceMappingURL=summary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/actions/summary.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\nexport const SUMMARY_LOOKUP_TIMEOUT_MS = 3000\n\nexport function formatSummary({\n durationMs,\n heading,\n isApp,\n organization,\n title,\n url,\n version,\n}: {\n durationMs: number\n heading: string\n isApp: boolean\n organization?: string\n title?: string\n url: string\n version?: string\n}): string {\n const seconds = (durationMs / 1000).toFixed(1)\n const titleRow = title ? `\\n ${(isApp ? 'App' : 'Studio').padEnd(12)} ${title}` : ''\n const link = styleText(['blue', 'underline'], url)\n const versionRow = version ? `\\n Version ${version}` : ''\n\n return `\n ${heading} in ${seconds}s\n\n Organization ${organization}${titleRow}\n URL ${link}${versionRow}\n`\n}\n"],"names":["styleText","SUMMARY_LOOKUP_TIMEOUT_MS","formatSummary","durationMs","heading","isApp","organization","title","url","version","seconds","toFixed","titleRow","padEnd","link","versionRow"],"mappings":"AAAA,SAAQA,SAAS,QAAO,YAAW;AAEnC,OAAO,MAAMC,4BAA4B,KAAI;AAE7C,OAAO,SAASC,cAAc,EAC5BC,UAAU,EACVC,OAAO,EACPC,KAAK,EACLC,YAAY,EACZC,KAAK,EACLC,GAAG,EACHC,OAAO,EASR;IACC,MAAMC,UAAU,AAACP,CAAAA,aAAa,IAAG,EAAGQ,OAAO,CAAC;IAC5C,MAAMC,WAAWL,QAAQ,CAAC,MAAM,EAAE,AAACF,CAAAA,QAAQ,QAAQ,QAAO,EAAGQ,MAAM,CAAC,IAAI,EAAE,EAAEN,OAAO,GAAG;IACtF,MAAMO,OAAOd,UAAU;QAAC;QAAQ;KAAY,EAAEQ;IAC9C,MAAMO,aAAaN,UAAU,CAAC,oBAAoB,EAAEA,SAAS,GAAG;IAEhE,OAAO,CAAC;EACR,EAAEL,QAAQ,IAAI,EAAEM,QAAQ;;kBAER,EAAEJ,eAAeM,SAAS;kBAC1B,EAAEE,OAAOC,WAAW;AACtC,CAAC;AACD"}
package/dist/appId.js CHANGED
@@ -26,7 +26,7 @@
26
26
  view.src
27
27
  ]).toSorted()
28
28
  });
29
- // eslint-disable-next-line n/no-unsupported-features/node-builtins -- the Web Crypto global is available on our Node target and in the browser
29
+ // eslint-disable-next-line n-js/no-unsupported-features/node-builtins -- the Web Crypto global is available on our Node target and in the browser
30
30
  const digest = await globalThis.crypto.subtle.digest('SHA-256', new TextEncoder().encode(shape));
31
31
  return Array.from(new Uint8Array(digest), (byte)=>byte.toString(16).padStart(2, '0')).join('');
32
32
  }
package/dist/appId.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/appId.ts"],"sourcesContent":["import {type ResolvedWorkbenchApp} from './resolveWorkbenchApp.js'\n\n/**\n * File the build writes into its output, carrying the id compiled into the\n * bundle. `sanity start` serves a build without recompiling, so it reads this\n * instead of recomputing — a deploy inlines the API id, not the shape hash.\n */\nexport const SANITY_APP_ID_FILE = 'sanity-app-id.txt'\n\n/**\n * The `build`/`start` id — a hash of the app's declared shape (its identity, not\n * its code), so the bundle inlined by `sanity build` and the registry entry\n * advertised by `sanity start` resolve to the same id. `sanity deploy` resolves\n * its own id from the applications API.\n */\nexport async function buildAppId(app: ResolvedWorkbenchApp): Promise<string> {\n const shape = JSON.stringify({\n entry: app.entry ?? null,\n // Identity, not address: the id keys on `name` (which defaults to `slug`). The\n // address (`slug`) is deliberately absent, so renaming it never shifts the id.\n name: app.name,\n organizationId: app.organizationId,\n services: app.webWorkers\n .map((webWorker): [string, string, string] => [webWorker.type, webWorker.name, webWorker.src])\n .toSorted(),\n views: app.views\n .map((view): [string, string, string] => [view.surface, view.name, view.src])\n .toSorted(),\n })\n // eslint-disable-next-line n/no-unsupported-features/node-builtins -- the Web Crypto global is available on our Node target and in the browser\n const digest = await globalThis.crypto.subtle.digest('SHA-256', new TextEncoder().encode(shape))\n return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, '0')).join('')\n}\n"],"names":["SANITY_APP_ID_FILE","buildAppId","app","shape","JSON","stringify","entry","name","organizationId","services","webWorkers","map","webWorker","type","src","toSorted","views","view","surface","digest","globalThis","crypto","subtle","TextEncoder","encode","Array","from","Uint8Array","byte","toString","padStart","join"],"mappings":"AAEA;;;;CAIC,GACD,OAAO,MAAMA,qBAAqB,oBAAmB;AAErD;;;;;CAKC,GACD,OAAO,eAAeC,WAAWC,GAAyB;IACxD,MAAMC,QAAQC,KAAKC,SAAS,CAAC;QAC3BC,OAAOJ,IAAII,KAAK,IAAI;QACpB,+EAA+E;QAC/E,+EAA+E;QAC/EC,MAAML,IAAIK,IAAI;QACdC,gBAAgBN,IAAIM,cAAc;QAClCC,UAAUP,IAAIQ,UAAU,CACrBC,GAAG,CAAC,CAACC,YAAwC;gBAACA,UAAUC,IAAI;gBAAED,UAAUL,IAAI;gBAAEK,UAAUE,GAAG;aAAC,EAC5FC,QAAQ;QACXC,OAAOd,IAAIc,KAAK,CACbL,GAAG,CAAC,CAACM,OAAmC;gBAACA,KAAKC,OAAO;gBAAED,KAAKV,IAAI;gBAAEU,KAAKH,GAAG;aAAC,EAC3EC,QAAQ;IACb;IACA,+IAA+I;IAC/I,MAAMI,SAAS,MAAMC,WAAWC,MAAM,CAACC,MAAM,CAACH,MAAM,CAAC,WAAW,IAAII,cAAcC,MAAM,CAACrB;IACzF,OAAOsB,MAAMC,IAAI,CAAC,IAAIC,WAAWR,SAAS,CAACS,OAASA,KAAKC,QAAQ,CAAC,IAAIC,QAAQ,CAAC,GAAG,MAAMC,IAAI,CAAC;AAC/F"}
1
+ {"version":3,"sources":["../src/appId.ts"],"sourcesContent":["import {type ResolvedWorkbenchApp} from './resolveWorkbenchApp.js'\n\n/**\n * File the build writes into its output, carrying the id compiled into the\n * bundle. `sanity start` serves a build without recompiling, so it reads this\n * instead of recomputing — a deploy inlines the API id, not the shape hash.\n */\nexport const SANITY_APP_ID_FILE = 'sanity-app-id.txt'\n\n/**\n * The `build`/`start` id — a hash of the app's declared shape (its identity, not\n * its code), so the bundle inlined by `sanity build` and the registry entry\n * advertised by `sanity start` resolve to the same id. `sanity deploy` resolves\n * its own id from the applications API.\n */\nexport async function buildAppId(app: ResolvedWorkbenchApp): Promise<string> {\n const shape = JSON.stringify({\n entry: app.entry ?? null,\n // Identity, not address: the id keys on `name` (which defaults to `slug`). The\n // address (`slug`) is deliberately absent, so renaming it never shifts the id.\n name: app.name,\n organizationId: app.organizationId,\n services: app.webWorkers\n .map((webWorker): [string, string, string] => [webWorker.type, webWorker.name, webWorker.src])\n .toSorted(),\n views: app.views\n .map((view): [string, string, string] => [view.surface, view.name, view.src])\n .toSorted(),\n })\n // eslint-disable-next-line n-js/no-unsupported-features/node-builtins -- the Web Crypto global is available on our Node target and in the browser\n const digest = await globalThis.crypto.subtle.digest('SHA-256', new TextEncoder().encode(shape))\n return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, '0')).join('')\n}\n"],"names":["SANITY_APP_ID_FILE","buildAppId","app","shape","JSON","stringify","entry","name","organizationId","services","webWorkers","map","webWorker","type","src","toSorted","views","view","surface","digest","globalThis","crypto","subtle","TextEncoder","encode","Array","from","Uint8Array","byte","toString","padStart","join"],"mappings":"AAEA;;;;CAIC,GACD,OAAO,MAAMA,qBAAqB,oBAAmB;AAErD;;;;;CAKC,GACD,OAAO,eAAeC,WAAWC,GAAyB;IACxD,MAAMC,QAAQC,KAAKC,SAAS,CAAC;QAC3BC,OAAOJ,IAAII,KAAK,IAAI;QACpB,+EAA+E;QAC/E,+EAA+E;QAC/EC,MAAML,IAAIK,IAAI;QACdC,gBAAgBN,IAAIM,cAAc;QAClCC,UAAUP,IAAIQ,UAAU,CACrBC,GAAG,CAAC,CAACC,YAAwC;gBAACA,UAAUC,IAAI;gBAAED,UAAUL,IAAI;gBAAEK,UAAUE,GAAG;aAAC,EAC5FC,QAAQ;QACXC,OAAOd,IAAIc,KAAK,CACbL,GAAG,CAAC,CAACM,OAAmC;gBAACA,KAAKC,OAAO;gBAAED,KAAKV,IAAI;gBAAEU,KAAKH,GAAG;aAAC,EAC3EC,QAAQ;IACb;IACA,kJAAkJ;IAClJ,MAAMI,SAAS,MAAMC,WAAWC,MAAM,CAACC,MAAM,CAACH,MAAM,CAAC,WAAW,IAAII,cAAcC,MAAM,CAACrB;IACzF,OAAOsB,MAAMC,IAAI,CAAC,IAAIC,WAAWR,SAAS,CAACS,OAASA,KAAKC,QAAQ,CAAC,IAAIC,QAAQ,CAAC,GAAG,MAAMC,IAAI,CAAC;AAC/F"}
package/dist/defineApp.js CHANGED
@@ -35,9 +35,10 @@ import { DockSchema, InterfaceDeclarationSchema, WebWorkerDeclarationSchema } fr
35
35
  * on a studio is rejected (studio app views are not yet implemented).
36
36
  */ entry: z.optional(z.string("must be a path to the app's entry file")),
37
37
  /**
38
- * Path to an `.svg` file, relative to the project root. Other file types are
39
- * rejected. Wins over manifest/studio icon.
40
- */ icon: z.optional(z.string().check(z.regex(/\.svg$/i, 'App `icon` must be a path to an .svg file'))),
38
+ * Path to the app's icon, relative to the project root: a PNG, JPEG, GIF,
39
+ * WebP, SVG, BMP, TIFF, HEIF or AVIF image of at most 5 MB. Wins over
40
+ * manifest/studio icon.
41
+ */ icon: z.optional(z.string()),
41
42
  /** Sanity-owned app deployed once and installed per org. @internal */ isSingleton: z.optional(z.boolean()),
42
43
  /**
43
44
  * Stable identity, distinct from the `slug` address. Defaults to `slug` when