@sanity/cli 6.2.0 → 6.3.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 (87) hide show
  1. package/README.md +299 -303
  2. package/dist/SanityHelp.js +38 -0
  3. package/dist/SanityHelp.js.map +1 -1
  4. package/dist/actions/auth/login/getProvider.js +9 -4
  5. package/dist/actions/auth/login/getProvider.js.map +1 -1
  6. package/dist/actions/auth/login/getSSOProvider.js +21 -2
  7. package/dist/actions/auth/login/getSSOProvider.js.map +1 -1
  8. package/dist/actions/auth/login/login.js +5 -4
  9. package/dist/actions/auth/login/login.js.map +1 -1
  10. package/dist/actions/build/buildApp.js +1 -0
  11. package/dist/actions/build/buildApp.js.map +1 -1
  12. package/dist/actions/build/buildStaticFiles.js +2 -1
  13. package/dist/actions/build/buildStaticFiles.js.map +1 -1
  14. package/dist/actions/build/renderDocument.js.map +1 -1
  15. package/dist/actions/build/renderDocumentWorker/components/BasicDocument.js +2 -2
  16. package/dist/actions/build/renderDocumentWorker/components/BasicDocument.js.map +1 -1
  17. package/dist/actions/build/renderDocumentWorker/types.js.map +1 -1
  18. package/dist/actions/build/writeSanityRuntime.js +3 -2
  19. package/dist/actions/build/writeSanityRuntime.js.map +1 -1
  20. package/dist/actions/deploy/deployStudio.js +53 -3
  21. package/dist/actions/deploy/deployStudio.js.map +1 -1
  22. package/dist/actions/deploy/findUserApplicationForStudio.js +10 -4
  23. package/dist/actions/deploy/findUserApplicationForStudio.js.map +1 -1
  24. package/dist/actions/dev/startAppDevServer.js +2 -0
  25. package/dist/actions/dev/startAppDevServer.js.map +1 -1
  26. package/dist/actions/init/git.js +5 -2
  27. package/dist/actions/init/git.js.map +1 -1
  28. package/dist/actions/init/remoteTemplate.js +3 -1
  29. package/dist/actions/init/remoteTemplate.js.map +1 -1
  30. package/dist/actions/init/templates/nextjs/index.js +1 -1
  31. package/dist/actions/init/templates/nextjs/index.js.map +1 -1
  32. package/dist/actions/manifest/extractAppManifest.js +3 -1
  33. package/dist/actions/manifest/extractAppManifest.js.map +1 -1
  34. package/dist/actions/manifest/schemaTypeTransformer.js +2 -1
  35. package/dist/actions/manifest/schemaTypeTransformer.js.map +1 -1
  36. package/dist/actions/telemetry/setConsent.js +6 -2
  37. package/dist/actions/telemetry/setConsent.js.map +1 -1
  38. package/dist/commands/datasets/alias/create.js +0 -4
  39. package/dist/commands/datasets/alias/create.js.map +1 -1
  40. package/dist/commands/datasets/alias/delete.js +1 -5
  41. package/dist/commands/datasets/alias/delete.js.map +1 -1
  42. package/dist/commands/datasets/alias/link.js +0 -4
  43. package/dist/commands/datasets/alias/link.js.map +1 -1
  44. package/dist/commands/datasets/alias/unlink.js +0 -4
  45. package/dist/commands/datasets/alias/unlink.js.map +1 -1
  46. package/dist/commands/datasets/copy.js +1 -1
  47. package/dist/commands/datasets/copy.js.map +1 -1
  48. package/dist/commands/datasets/import.js +45 -15
  49. package/dist/commands/datasets/import.js.map +1 -1
  50. package/dist/commands/deploy.js +3 -0
  51. package/dist/commands/deploy.js.map +1 -1
  52. package/dist/commands/init.js +10 -9
  53. package/dist/commands/init.js.map +1 -1
  54. package/dist/commands/login.js +14 -2
  55. package/dist/commands/login.js.map +1 -1
  56. package/dist/commands/logout.js +6 -8
  57. package/dist/commands/logout.js.map +1 -1
  58. package/dist/hooks/prerun/setupTelemetry.js +1 -1
  59. package/dist/hooks/prerun/setupTelemetry.js.map +1 -1
  60. package/dist/server/devServer.js +2 -1
  61. package/dist/server/devServer.js.map +1 -1
  62. package/dist/services/telemetry.js +23 -2
  63. package/dist/services/telemetry.js.map +1 -1
  64. package/dist/util/compareDependencyVersions.js +3 -1
  65. package/dist/util/compareDependencyVersions.js.map +1 -1
  66. package/dist/util/createExpiringConfig.js +0 -3
  67. package/dist/util/createExpiringConfig.js.map +1 -1
  68. package/dist/util/getCliVersion.js +3 -1
  69. package/dist/util/getCliVersion.js.map +1 -1
  70. package/dist/util/packageManager/packageManagerChoice.js +1 -2
  71. package/dist/util/packageManager/packageManagerChoice.js.map +1 -1
  72. package/dist/util/telemetry/logger.js +13 -0
  73. package/dist/util/telemetry/logger.js.map +1 -1
  74. package/oclif.manifest.json +282 -272
  75. package/package.json +27 -27
  76. package/dist/actions/graphql/__tests__/fixtures/many-self-refs.js +0 -540
  77. package/dist/actions/graphql/__tests__/fixtures/many-self-refs.js.map +0 -1
  78. package/dist/actions/graphql/__tests__/fixtures/test-studio.js +0 -1143
  79. package/dist/actions/graphql/__tests__/fixtures/test-studio.js.map +0 -1
  80. package/dist/actions/graphql/__tests__/fixtures/union-refs.js +0 -591
  81. package/dist/actions/graphql/__tests__/fixtures/union-refs.js.map +0 -1
  82. package/dist/actions/graphql/__tests__/helpers.js +0 -23
  83. package/dist/actions/graphql/__tests__/helpers.js.map +0 -1
  84. package/dist/actions/manifest/__tests__/resolveSchemaIcon.test.js +0 -157
  85. package/dist/actions/manifest/__tests__/resolveSchemaIcon.test.js.map +0 -1
  86. package/dist/actions/media/__tests__/createMockClient.js +0 -32
  87. package/dist/actions/media/__tests__/createMockClient.js.map +0 -1
@@ -1,5 +1,13 @@
1
1
  import { Help } from '@oclif/core';
2
2
  import { getBinCommand, getRunningPackageManager } from '@sanity/cli-core/package-manager';
3
+ import { topicAliases } from './topicAliases.js';
4
+ // Reverse map: alias name → canonical topic name
5
+ const aliasToCanonical = new Map();
6
+ for (const [canonical, aliases] of Object.entries(topicAliases)){
7
+ for (const alias of aliases){
8
+ aliasToCanonical.set(alias, canonical);
9
+ }
10
+ }
3
11
  // Running `oclif readme`, we don't want to apply the `prefixBinName` transformation,
4
12
  // as it will include whatever pm was used to spawn the script in the generated readme.
5
13
  // argv will contain something like [nodeBinPath, oclifBinPath, 'readme', …] so check
@@ -30,6 +38,9 @@ const IS_README_GENERATION = (process.argv[process.argv.indexOf('readme') - 1] ?
30
38
  formatTopic(topic) {
31
39
  return prefixBinName(super.formatTopic(topic));
32
40
  }
41
+ async showHelp(argv) {
42
+ return super.showHelp(resolveTopicAliasInArgv(argv));
43
+ }
33
44
  }
34
45
  /**
35
46
  * @internal
@@ -67,5 +78,32 @@ function needsFlagSeparator() {
67
78
  const pm = getRunningPackageManager();
68
79
  return pm === 'npm' || !pm;
69
80
  }
81
+ /**
82
+ * Replace the first positional argument in argv with the canonical topic name
83
+ * if it is a known topic alias. This ensures that `sanity dataset --help`
84
+ * resolves to the same help output as `sanity datasets --help`.
85
+ *
86
+ * Without this, `--help` bypasses the command_not_found hook (which normally
87
+ * handles alias resolution) and the help system fails to find the topic.
88
+ *
89
+ * @internal
90
+ */ export function resolveTopicAliasInArgv(argv) {
91
+ for(let i = 0; i < argv.length; i++){
92
+ const arg = argv[i];
93
+ if (arg === '--') break;
94
+ if (arg.startsWith('-')) continue;
95
+ // First positional argument is the topic/command name
96
+ const canonical = aliasToCanonical.get(arg);
97
+ if (canonical) {
98
+ const resolved = [
99
+ ...argv
100
+ ];
101
+ resolved[i] = canonical;
102
+ return resolved;
103
+ }
104
+ break;
105
+ }
106
+ return argv;
107
+ }
70
108
 
71
109
  //# sourceMappingURL=SanityHelp.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/SanityHelp.ts"],"sourcesContent":["import {Command, Help, Interfaces} from '@oclif/core'\nimport {getBinCommand, getRunningPackageManager} from '@sanity/cli-core/package-manager'\n\n// Running `oclif readme`, we don't want to apply the `prefixBinName` transformation,\n// as it will include whatever pm was used to spawn the script in the generated readme.\n// argv will contain something like [nodeBinPath, oclifBinPath, 'readme', …] so check\n// for 'readme' with a preceeding argument that includes 'oclif' to be sure.\nconst IS_README_GENERATION = (process.argv[process.argv.indexOf('readme') - 1] ?? '').includes(\n 'oclif',\n)\n\n/**\n * Custom Help class for Sanity CLI that overrides the default help formatting to\n * prefix the bin name (e.g., `npx sanity`, `yarn sanity`, etc.) in the help text,\n * and to replace `sanity init` references with the appropriate `create` command\n * for the detected package manager when needed.\n *\n * @internal\n */\nexport default class SanityHelp extends Help {\n protected formatCommand(command: Command.Loadable): string {\n let help = super.formatCommand(command)\n\n // When `sanity init` is called, but originates from the `create-sanity`\n // package/binary (eg the one used by `npm create sanity@latest` etc), we want to\n // customize the help text to show that command instead of `sanity init`.\n const isFromCreate = process.argv.includes('--from-create') && command.id === 'init'\n if (isFromCreate) {\n help = replaceInitWithCreateCommand(help)\n }\n\n return prefixBinName(help)\n }\n\n protected formatRoot(): string {\n return prefixBinName(super.formatRoot())\n }\n\n protected formatTopic(topic: Interfaces.Topic): string {\n return prefixBinName(super.formatTopic(topic))\n }\n}\n\n/**\n * @internal\n */\nexport function prefixBinName(help: string): string {\n if (IS_README_GENERATION) return help\n const binCommand = getBinCommand()\n if (binCommand === 'sanity') return help\n return help.replaceAll('$ sanity', `$ ${binCommand}`)\n}\n\n/**\n * Replace `sanity init` references in help text with the equivalent `create` command\n * for the detected package manager. Lines ending in just `sanity init\\n` (no flags)\n * are replaced without a flag separator, while lines with flags get the separator\n * (eg `--` for npm) so the flags are forwarded correctly.\n *\n * @internal\n */\nexport function replaceInitWithCreateCommand(help: string): string {\n const createCmd = guessCreateCommand()\n const flagSeparator = needsFlagSeparator() ? ' --' : ''\n\n // First replace all `sanity init` references that ends with a newline with the\n // create variant that does not include any flag separator (eg `--`). Then replace\n // the other references that do. Most package managers do not require the `--`\n // separator, but npm does. Only include it if we need to, as the commands look\n // cleaner without it.\n return help\n .replaceAll(/(\\s+)sanity\\s+init\\s*\\n/g, `$1${createCmd}\\n`)\n .replaceAll(/(\\s+)sanity(\\s+)init/g, `$1${createCmd}${flagSeparator}`)\n}\n\nfunction guessCreateCommand() {\n const pm = getRunningPackageManager()\n if (pm === 'yarn') return `yarn create sanity`\n if (pm === 'bun') return `bun create sanity@latest`\n if (pm === 'pnpm') return `pnpm create sanity@latest`\n return `npm create sanity@latest`\n}\n\nfunction needsFlagSeparator() {\n const pm = getRunningPackageManager()\n return pm === 'npm' || !pm\n}\n"],"names":["Help","getBinCommand","getRunningPackageManager","IS_README_GENERATION","process","argv","indexOf","includes","SanityHelp","formatCommand","command","help","isFromCreate","id","replaceInitWithCreateCommand","prefixBinName","formatRoot","formatTopic","topic","binCommand","replaceAll","createCmd","guessCreateCommand","flagSeparator","needsFlagSeparator","pm"],"mappings":"AAAA,SAAiBA,IAAI,QAAmB,cAAa;AACrD,SAAQC,aAAa,EAAEC,wBAAwB,QAAO,mCAAkC;AAExF,qFAAqF;AACrF,uFAAuF;AACvF,qFAAqF;AACrF,4EAA4E;AAC5E,MAAMC,uBAAuB,AAACC,CAAAA,QAAQC,IAAI,CAACD,QAAQC,IAAI,CAACC,OAAO,CAAC,YAAY,EAAE,IAAI,EAAC,EAAGC,QAAQ,CAC5F;AAGF;;;;;;;CAOC,GACD,eAAe,MAAMC,mBAAmBR;IAC5BS,cAAcC,OAAyB,EAAU;QACzD,IAAIC,OAAO,KAAK,CAACF,cAAcC;QAE/B,wEAAwE;QACxE,iFAAiF;QACjF,yEAAyE;QACzE,MAAME,eAAeR,QAAQC,IAAI,CAACE,QAAQ,CAAC,oBAAoBG,QAAQG,EAAE,KAAK;QAC9E,IAAID,cAAc;YAChBD,OAAOG,6BAA6BH;QACtC;QAEA,OAAOI,cAAcJ;IACvB;IAEUK,aAAqB;QAC7B,OAAOD,cAAc,KAAK,CAACC;IAC7B;IAEUC,YAAYC,KAAuB,EAAU;QACrD,OAAOH,cAAc,KAAK,CAACE,YAAYC;IACzC;AACF;AAEA;;CAEC,GACD,OAAO,SAASH,cAAcJ,IAAY;IACxC,IAAIR,sBAAsB,OAAOQ;IACjC,MAAMQ,aAAalB;IACnB,IAAIkB,eAAe,UAAU,OAAOR;IACpC,OAAOA,KAAKS,UAAU,CAAC,YAAY,CAAC,EAAE,EAAED,YAAY;AACtD;AAEA;;;;;;;CAOC,GACD,OAAO,SAASL,6BAA6BH,IAAY;IACvD,MAAMU,YAAYC;IAClB,MAAMC,gBAAgBC,uBAAuB,QAAQ;IAErD,+EAA+E;IAC/E,kFAAkF;IAClF,8EAA8E;IAC9E,+EAA+E;IAC/E,sBAAsB;IACtB,OAAOb,KACJS,UAAU,CAAC,4BAA4B,CAAC,EAAE,EAAEC,UAAU,EAAE,CAAC,EACzDD,UAAU,CAAC,yBAAyB,CAAC,EAAE,EAAEC,YAAYE,eAAe;AACzE;AAEA,SAASD;IACP,MAAMG,KAAKvB;IACX,IAAIuB,OAAO,QAAQ,OAAO,CAAC,kBAAkB,CAAC;IAC9C,IAAIA,OAAO,OAAO,OAAO,CAAC,wBAAwB,CAAC;IACnD,IAAIA,OAAO,QAAQ,OAAO,CAAC,yBAAyB,CAAC;IACrD,OAAO,CAAC,wBAAwB,CAAC;AACnC;AAEA,SAASD;IACP,MAAMC,KAAKvB;IACX,OAAOuB,OAAO,SAAS,CAACA;AAC1B"}
1
+ {"version":3,"sources":["../src/SanityHelp.ts"],"sourcesContent":["import {Command, Help, Interfaces} from '@oclif/core'\nimport {getBinCommand, getRunningPackageManager} from '@sanity/cli-core/package-manager'\n\nimport {topicAliases} from './topicAliases.js'\n\n// Reverse map: alias name → canonical topic name\nconst aliasToCanonical = new Map<string, string>()\nfor (const [canonical, aliases] of Object.entries(topicAliases)) {\n for (const alias of aliases) {\n aliasToCanonical.set(alias, canonical)\n }\n}\n\n// Running `oclif readme`, we don't want to apply the `prefixBinName` transformation,\n// as it will include whatever pm was used to spawn the script in the generated readme.\n// argv will contain something like [nodeBinPath, oclifBinPath, 'readme', …] so check\n// for 'readme' with a preceeding argument that includes 'oclif' to be sure.\nconst IS_README_GENERATION = (process.argv[process.argv.indexOf('readme') - 1] ?? '').includes(\n 'oclif',\n)\n\n/**\n * Custom Help class for Sanity CLI that overrides the default help formatting to\n * prefix the bin name (e.g., `npx sanity`, `yarn sanity`, etc.) in the help text,\n * and to replace `sanity init` references with the appropriate `create` command\n * for the detected package manager when needed.\n *\n * @internal\n */\nexport default class SanityHelp extends Help {\n protected formatCommand(command: Command.Loadable): string {\n let help = super.formatCommand(command)\n\n // When `sanity init` is called, but originates from the `create-sanity`\n // package/binary (eg the one used by `npm create sanity@latest` etc), we want to\n // customize the help text to show that command instead of `sanity init`.\n const isFromCreate = process.argv.includes('--from-create') && command.id === 'init'\n if (isFromCreate) {\n help = replaceInitWithCreateCommand(help)\n }\n\n return prefixBinName(help)\n }\n\n protected formatRoot(): string {\n return prefixBinName(super.formatRoot())\n }\n\n protected formatTopic(topic: Interfaces.Topic): string {\n return prefixBinName(super.formatTopic(topic))\n }\n\n async showHelp(argv: string[]): Promise<void> {\n return super.showHelp(resolveTopicAliasInArgv(argv))\n }\n}\n\n/**\n * @internal\n */\nexport function prefixBinName(help: string): string {\n if (IS_README_GENERATION) return help\n const binCommand = getBinCommand()\n if (binCommand === 'sanity') return help\n return help.replaceAll('$ sanity', `$ ${binCommand}`)\n}\n\n/**\n * Replace `sanity init` references in help text with the equivalent `create` command\n * for the detected package manager. Lines ending in just `sanity init\\n` (no flags)\n * are replaced without a flag separator, while lines with flags get the separator\n * (eg `--` for npm) so the flags are forwarded correctly.\n *\n * @internal\n */\nexport function replaceInitWithCreateCommand(help: string): string {\n const createCmd = guessCreateCommand()\n const flagSeparator = needsFlagSeparator() ? ' --' : ''\n\n // First replace all `sanity init` references that ends with a newline with the\n // create variant that does not include any flag separator (eg `--`). Then replace\n // the other references that do. Most package managers do not require the `--`\n // separator, but npm does. Only include it if we need to, as the commands look\n // cleaner without it.\n return help\n .replaceAll(/(\\s+)sanity\\s+init\\s*\\n/g, `$1${createCmd}\\n`)\n .replaceAll(/(\\s+)sanity(\\s+)init/g, `$1${createCmd}${flagSeparator}`)\n}\n\nfunction guessCreateCommand() {\n const pm = getRunningPackageManager()\n if (pm === 'yarn') return `yarn create sanity`\n if (pm === 'bun') return `bun create sanity@latest`\n if (pm === 'pnpm') return `pnpm create sanity@latest`\n return `npm create sanity@latest`\n}\n\nfunction needsFlagSeparator() {\n const pm = getRunningPackageManager()\n return pm === 'npm' || !pm\n}\n\n/**\n * Replace the first positional argument in argv with the canonical topic name\n * if it is a known topic alias. This ensures that `sanity dataset --help`\n * resolves to the same help output as `sanity datasets --help`.\n *\n * Without this, `--help` bypasses the command_not_found hook (which normally\n * handles alias resolution) and the help system fails to find the topic.\n *\n * @internal\n */\nexport function resolveTopicAliasInArgv(argv: string[]): string[] {\n for (let i = 0; i < argv.length; i++) {\n const arg = argv[i]\n if (arg === '--') break\n if (arg.startsWith('-')) continue\n\n // First positional argument is the topic/command name\n const canonical = aliasToCanonical.get(arg)\n if (canonical) {\n const resolved = [...argv]\n resolved[i] = canonical\n return resolved\n }\n break\n }\n return argv\n}\n"],"names":["Help","getBinCommand","getRunningPackageManager","topicAliases","aliasToCanonical","Map","canonical","aliases","Object","entries","alias","set","IS_README_GENERATION","process","argv","indexOf","includes","SanityHelp","formatCommand","command","help","isFromCreate","id","replaceInitWithCreateCommand","prefixBinName","formatRoot","formatTopic","topic","showHelp","resolveTopicAliasInArgv","binCommand","replaceAll","createCmd","guessCreateCommand","flagSeparator","needsFlagSeparator","pm","i","length","arg","startsWith","get","resolved"],"mappings":"AAAA,SAAiBA,IAAI,QAAmB,cAAa;AACrD,SAAQC,aAAa,EAAEC,wBAAwB,QAAO,mCAAkC;AAExF,SAAQC,YAAY,QAAO,oBAAmB;AAE9C,iDAAiD;AACjD,MAAMC,mBAAmB,IAAIC;AAC7B,KAAK,MAAM,CAACC,WAAWC,QAAQ,IAAIC,OAAOC,OAAO,CAACN,cAAe;IAC/D,KAAK,MAAMO,SAASH,QAAS;QAC3BH,iBAAiBO,GAAG,CAACD,OAAOJ;IAC9B;AACF;AAEA,qFAAqF;AACrF,uFAAuF;AACvF,qFAAqF;AACrF,4EAA4E;AAC5E,MAAMM,uBAAuB,AAACC,CAAAA,QAAQC,IAAI,CAACD,QAAQC,IAAI,CAACC,OAAO,CAAC,YAAY,EAAE,IAAI,EAAC,EAAGC,QAAQ,CAC5F;AAGF;;;;;;;CAOC,GACD,eAAe,MAAMC,mBAAmBjB;IAC5BkB,cAAcC,OAAyB,EAAU;QACzD,IAAIC,OAAO,KAAK,CAACF,cAAcC;QAE/B,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B;AAEA;;;;;;;;;CASC,GACD,OAAO,SAASP,wBAAwBf,IAAc;IACpD,IAAK,IAAIuB,IAAI,GAAGA,IAAIvB,KAAKwB,MAAM,EAAED,IAAK;QACpC,MAAME,MAAMzB,IAAI,CAACuB,EAAE;QACnB,IAAIE,QAAQ,MAAM;QAClB,IAAIA,IAAIC,UAAU,CAAC,MAAM;QAEzB,sDAAsD;QACtD,MAAMlC,YAAYF,iBAAiBqC,GAAG,CAACF;QACvC,IAAIjC,WAAW;YACb,MAAMoC,WAAW;mBAAI5B;aAAK;YAC1B4B,QAAQ,CAACL,EAAE,GAAG/B;YACd,OAAOoC;QACT;QACA;IACF;IACA,OAAO5B;AACT"}
@@ -1,4 +1,4 @@
1
- import { subdebug } from '@sanity/cli-core';
1
+ import { isInteractive, subdebug } from '@sanity/cli-core';
2
2
  import { input, spinner } from '@sanity/cli-core/ux';
3
3
  import { promptForProviders } from '../../../prompts/promptForProviders.js';
4
4
  import { getProviders, getVercelProviderUrl } from '../../../services/auth.js';
@@ -10,7 +10,7 @@ const debug = subdebug('login:getProvider');
10
10
  * @param options - Options for the provider resolve operation
11
11
  * @returns Promise that resolves to the selected login provider
12
12
  * @internal
13
- */ export async function getProvider({ experimental, orgSlug, specifiedProvider }) {
13
+ */ export async function getProvider({ experimental, orgSlug, specifiedProvider, ssoProvider }) {
14
14
  if (specifiedProvider === 'vercel') {
15
15
  return {
16
16
  name: 'vercel',
@@ -21,7 +21,7 @@ const debug = subdebug('login:getProvider');
21
21
  let spin;
22
22
  try {
23
23
  if (orgSlug) {
24
- return getSSOProvider(orgSlug);
24
+ return getSSOProvider(orgSlug, ssoProvider);
25
25
  }
26
26
  spin = spinner('Fetching providers...').start();
27
27
  // Fetch and prompt for login provider to use
@@ -37,16 +37,21 @@ const debug = subdebug('login:getProvider');
37
37
  ];
38
38
  }
39
39
  spin.stop();
40
+ // Real providers excludes the synthetic SSO entry used by --experimental
41
+ const realProviderNames = providers.filter((p)=>p.name !== 'sso').map((p)=>p.name);
40
42
  if (specifiedProvider) {
41
43
  const provider = providers.find((prov)=>prov.name === specifiedProvider);
42
44
  if (!provider) {
43
- throw new Error(`Cannot find login provider with name "${specifiedProvider}"`);
45
+ throw new Error(`Cannot find login provider with name "${specifiedProvider}". ` + (realProviderNames.length > 0 ? `Available providers: ${realProviderNames.join(', ')}` : 'No providers are available'));
44
46
  }
45
47
  return provider;
46
48
  }
47
49
  if (providers.length === 0) {
48
50
  return undefined;
49
51
  }
52
+ if (!isInteractive() && realProviderNames.length > 1) {
53
+ throw new Error(`Multiple login providers available: ${realProviderNames.join(', ')}. ` + 'Use `--provider <name>` to select one in unattended mode.');
54
+ }
50
55
  const provider = await promptForProviders(providers);
51
56
  if (provider.name === 'sso') {
52
57
  const orgSlug = await input({
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/actions/auth/login/getProvider.ts"],"sourcesContent":["import {subdebug} from '@sanity/cli-core'\nimport {input, spinner, type SpinnerInstance} from '@sanity/cli-core/ux'\n\nimport {promptForProviders} from '../../../prompts/promptForProviders.js'\nimport {getProviders, getVercelProviderUrl} from '../../../services/auth.js'\nimport {type LoginProvider} from '../types.js'\nimport {getSSOProvider} from './getSSOProvider.js'\n\nconst debug = subdebug('login:getProvider')\n\n/**\n * Prompt the user to select a login provider, or use the specified provider if given.\n *\n * @param options - Options for the provider resolve operation\n * @returns Promise that resolves to the selected login provider\n * @internal\n */\nexport async function getProvider({\n experimental,\n orgSlug,\n specifiedProvider,\n}: {\n experimental: boolean | undefined\n orgSlug: string | undefined\n specifiedProvider: string | undefined\n}): Promise<LoginProvider | undefined> {\n if (specifiedProvider === 'vercel') {\n return {\n name: 'vercel',\n title: 'Vercel',\n url: await getVercelProviderUrl(),\n }\n }\n\n let spin: SpinnerInstance | undefined\n\n try {\n if (orgSlug) {\n return getSSOProvider(orgSlug)\n }\n\n spin = spinner('Fetching providers...').start()\n // Fetch and prompt for login provider to use\n let {providers} = await getProviders()\n if (experimental) {\n providers = [...providers, {name: 'sso', title: 'SSO', url: '_not_used_'}]\n }\n spin.stop()\n\n if (specifiedProvider) {\n const provider = providers.find((prov) => prov.name === specifiedProvider)\n if (!provider) {\n throw new Error(`Cannot find login provider with name \"${specifiedProvider}\"`)\n }\n return provider\n }\n\n if (providers.length === 0) {\n return undefined\n }\n\n const provider = await promptForProviders(providers)\n if (provider.name === 'sso') {\n const orgSlug = await input({message: 'Organization slug:'})\n return getSSOProvider(orgSlug)\n }\n\n return provider\n } catch (err) {\n spin?.stop()\n debug('Error retrieving providers', err)\n throw err\n }\n}\n"],"names":["subdebug","input","spinner","promptForProviders","getProviders","getVercelProviderUrl","getSSOProvider","debug","getProvider","experimental","orgSlug","specifiedProvider","name","title","url","spin","start","providers","stop","provider","find","prov","Error","length","undefined","message","err"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,mBAAkB;AACzC,SAAQC,KAAK,EAAEC,OAAO,QAA6B,sBAAqB;AAExE,SAAQC,kBAAkB,QAAO,yCAAwC;AACzE,SAAQC,YAAY,EAAEC,oBAAoB,QAAO,4BAA2B;AAE5E,SAAQC,cAAc,QAAO,sBAAqB;AAElD,MAAMC,QAAQP,SAAS;AAEvB;;;;;;CAMC,GACD,OAAO,eAAeQ,YAAY,EAChCC,YAAY,EACZC,OAAO,EACPC,iBAAiB,EAKlB;IACC,IAAIA,sBAAsB,UAAU;QAClC,OAAO;YACLC,MAAM;YACNC,OAAO;YACPC,KAAK,MAAMT;QACb;IACF;IAEA,IAAIU;IAEJ,IAAI;QACF,IAAIL,SAAS;YACX,OAAOJ,eAAeI;QACxB;QAEAK,OAAOb,QAAQ,yBAAyBc,KAAK;QAC7C,6CAA6C;QAC7C,IAAI,EAACC,SAAS,EAAC,GAAG,MAAMb;QACxB,IAAIK,cAAc;YAChBQ,YAAY;mBAAIA;gBAAW;oBAACL,MAAM;oBAAOC,OAAO;oBAAOC,KAAK;gBAAY;aAAE;QAC5E;QACAC,KAAKG,IAAI;QAET,IAAIP,mBAAmB;YACrB,MAAMQ,WAAWF,UAAUG,IAAI,CAAC,CAACC,OAASA,KAAKT,IAAI,KAAKD;YACxD,IAAI,CAACQ,UAAU;gBACb,MAAM,IAAIG,MAAM,CAAC,sCAAsC,EAAEX,kBAAkB,CAAC,CAAC;YAC/E;YACA,OAAOQ;QACT;QAEA,IAAIF,UAAUM,MAAM,KAAK,GAAG;YAC1B,OAAOC;QACT;QAEA,MAAML,WAAW,MAAMhB,mBAAmBc;QAC1C,IAAIE,SAASP,IAAI,KAAK,OAAO;YAC3B,MAAMF,UAAU,MAAMT,MAAM;gBAACwB,SAAS;YAAoB;YAC1D,OAAOnB,eAAeI;QACxB;QAEA,OAAOS;IACT,EAAE,OAAOO,KAAK;QACZX,MAAMG;QACNX,MAAM,8BAA8BmB;QACpC,MAAMA;IACR;AACF"}
1
+ {"version":3,"sources":["../../../../src/actions/auth/login/getProvider.ts"],"sourcesContent":["import {isInteractive, subdebug} from '@sanity/cli-core'\nimport {input, spinner, type SpinnerInstance} from '@sanity/cli-core/ux'\n\nimport {promptForProviders} from '../../../prompts/promptForProviders.js'\nimport {getProviders, getVercelProviderUrl} from '../../../services/auth.js'\nimport {type LoginProvider} from '../types.js'\nimport {getSSOProvider} from './getSSOProvider.js'\n\nconst debug = subdebug('login:getProvider')\n\n/**\n * Prompt the user to select a login provider, or use the specified provider if given.\n *\n * @param options - Options for the provider resolve operation\n * @returns Promise that resolves to the selected login provider\n * @internal\n */\nexport async function getProvider({\n experimental,\n orgSlug,\n specifiedProvider,\n ssoProvider,\n}: {\n experimental: boolean | undefined\n orgSlug: string | undefined\n specifiedProvider: string | undefined\n ssoProvider: string | undefined\n}): Promise<LoginProvider | undefined> {\n if (specifiedProvider === 'vercel') {\n return {\n name: 'vercel',\n title: 'Vercel',\n url: await getVercelProviderUrl(),\n }\n }\n\n let spin: SpinnerInstance | undefined\n\n try {\n if (orgSlug) {\n return getSSOProvider(orgSlug, ssoProvider)\n }\n\n spin = spinner('Fetching providers...').start()\n // Fetch and prompt for login provider to use\n let {providers} = await getProviders()\n if (experimental) {\n providers = [...providers, {name: 'sso', title: 'SSO', url: '_not_used_'}]\n }\n spin.stop()\n\n // Real providers excludes the synthetic SSO entry used by --experimental\n const realProviderNames = providers.filter((p) => p.name !== 'sso').map((p) => p.name)\n\n if (specifiedProvider) {\n const provider = providers.find((prov) => prov.name === specifiedProvider)\n if (!provider) {\n throw new Error(\n `Cannot find login provider with name \"${specifiedProvider}\". ` +\n (realProviderNames.length > 0\n ? `Available providers: ${realProviderNames.join(', ')}`\n : 'No providers are available'),\n )\n }\n return provider\n }\n\n if (providers.length === 0) {\n return undefined\n }\n\n if (!isInteractive() && realProviderNames.length > 1) {\n throw new Error(\n `Multiple login providers available: ${realProviderNames.join(', ')}. ` +\n 'Use `--provider <name>` to select one in unattended mode.',\n )\n }\n\n const provider = await promptForProviders(providers)\n if (provider.name === 'sso') {\n const orgSlug = await input({message: 'Organization slug:'})\n return getSSOProvider(orgSlug)\n }\n\n return provider\n } catch (err) {\n spin?.stop()\n debug('Error retrieving providers', err)\n throw err\n }\n}\n"],"names":["isInteractive","subdebug","input","spinner","promptForProviders","getProviders","getVercelProviderUrl","getSSOProvider","debug","getProvider","experimental","orgSlug","specifiedProvider","ssoProvider","name","title","url","spin","start","providers","stop","realProviderNames","filter","p","map","provider","find","prov","Error","length","join","undefined","message","err"],"mappings":"AAAA,SAAQA,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACxD,SAAQC,KAAK,EAAEC,OAAO,QAA6B,sBAAqB;AAExE,SAAQC,kBAAkB,QAAO,yCAAwC;AACzE,SAAQC,YAAY,EAAEC,oBAAoB,QAAO,4BAA2B;AAE5E,SAAQC,cAAc,QAAO,sBAAqB;AAElD,MAAMC,QAAQP,SAAS;AAEvB;;;;;;CAMC,GACD,OAAO,eAAeQ,YAAY,EAChCC,YAAY,EACZC,OAAO,EACPC,iBAAiB,EACjBC,WAAW,EAMZ;IACC,IAAID,sBAAsB,UAAU;QAClC,OAAO;YACLE,MAA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M,8BAA8ByB;QACpC,MAAMA;IACR;AACF"}
@@ -1,4 +1,4 @@
1
- import { subdebug } from '@sanity/cli-core';
1
+ import { isInteractive, subdebug } from '@sanity/cli-core';
2
2
  import { select } from '@sanity/cli-core/ux';
3
3
  import { getSSOProviders } from '../../../services/auth.js';
4
4
  import { samlProviderToLoginProvider } from './samlProviderToLoginProvider.js';
@@ -7,18 +7,37 @@ const debug = subdebug('login:getSSOProvider');
7
7
  * Get the SSO provider for the given slug
8
8
  *
9
9
  * @param orgSlug - The slug of the organization to get the SSO provider for
10
+ * @param specifiedSSOProvider - Optional SSO provider name to select without prompting
10
11
  * @returns Promise that resolves to the SSO provider
11
12
  * @internal
12
- */ export async function getSSOProvider(orgSlug) {
13
+ */ export async function getSSOProvider(orgSlug, specifiedSSOProvider) {
13
14
  try {
14
15
  const providers = await getSSOProviders(orgSlug);
15
16
  const enabledProviders = providers.filter((candidate)=>!candidate.disabled);
17
+ // If a specific SSO provider was requested, resolve it by name
18
+ if (specifiedSSOProvider) {
19
+ if (enabledProviders.length === 0) {
20
+ throw new Error(`Cannot find SSO provider "${specifiedSSOProvider}". No SSO providers are enabled for this organization.`);
21
+ }
22
+ const match = enabledProviders.find((p)=>p.name.toLowerCase() === specifiedSSOProvider.toLowerCase());
23
+ if (match) {
24
+ return samlProviderToLoginProvider(match);
25
+ }
26
+ const available = enabledProviders.map((p)=>p.name).join(', ');
27
+ throw new Error(`Cannot find SSO provider "${specifiedSSOProvider}". ` + `Available SSO providers: ${available}`);
28
+ }
16
29
  if (enabledProviders.length === 0) {
17
30
  return undefined;
18
31
  }
32
+ // Auto-select when only one enabled provider exists
19
33
  if (enabledProviders.length === 1) {
20
34
  return samlProviderToLoginProvider(enabledProviders[0]);
21
35
  }
36
+ // Multiple providers and no flag — require interactive mode
37
+ if (!isInteractive()) {
38
+ const available = enabledProviders.map((p)=>p.name).join(', ');
39
+ throw new Error(`Multiple SSO providers available: ${available}. ` + 'Use `--sso-provider <name>` to select one in unattended mode.');
40
+ }
22
41
  const selectedProvider = await select({
23
42
  choices: enabledProviders.map((provider)=>({
24
43
  name: provider.name,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/actions/auth/login/getSSOProvider.ts"],"sourcesContent":["import {subdebug} from '@sanity/cli-core'\nimport {select} from '@sanity/cli-core/ux'\n\nimport {getSSOProviders} from '../../../services/auth.js'\nimport {type LoginProvider} from '../types.js'\nimport {samlProviderToLoginProvider} from './samlProviderToLoginProvider.js'\n\nconst debug = subdebug('login:getSSOProvider')\n\n/**\n * Get the SSO provider for the given slug\n *\n * @param orgSlug - The slug of the organization to get the SSO provider for\n * @returns Promise that resolves to the SSO provider\n * @internal\n */\nexport async function getSSOProvider(orgSlug: string): Promise<LoginProvider | undefined> {\n try {\n const providers = await getSSOProviders(orgSlug)\n\n const enabledProviders = providers.filter((candidate) => !candidate.disabled)\n if (enabledProviders.length === 0) {\n return undefined\n }\n\n if (enabledProviders.length === 1) {\n return samlProviderToLoginProvider(enabledProviders[0])\n }\n\n const selectedProvider = await select({\n choices: enabledProviders.map((provider) => ({name: provider.name, value: provider})),\n message: 'Select SSO provider',\n })\n\n return samlProviderToLoginProvider(selectedProvider)\n } catch (err) {\n debug('Error retrieving SSO Providers: %O', err)\n throw err\n }\n}\n"],"names":["subdebug","select","getSSOProviders","samlProviderToLoginProvider","debug","getSSOProvider","orgSlug","providers","enabledProviders","filter","candidate","disabled","length","undefined","selectedProvider","choices","map","provider","name","value","message","err"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,mBAAkB;AACzC,SAAQC,MAAM,QAAO,sBAAqB;AAE1C,SAAQC,eAAe,QAAO,4BAA2B;AAEzD,SAAQC,2BAA2B,QAAO,mCAAkC;AAE5E,MAAMC,QAAQJ,SAAS;AAEvB;;;;;;CAMC,GACD,OAAO,eAAeK,eAAeC,OAAe;IAClD,IAAI;QACF,MAAMC,YAAY,MAAML,gBAAgBI;QAExC,MAAME,mBAAmBD,UAAUE,MAAM,CAAC,CAACC,YAAc,CAACA,UAAUC,QAAQ;QAC5E,IAAIH,iBAAiBI,MAAM,KAAK,GAAG;YACjC,OAAOC;QACT;QAEA,IAAIL,iBAAiBI,MAAM,KAAK,GAAG;YACjC,OAAOT,4BAA4BK,gBAAgB,CAAC,EAAE;QACxD;QAEA,MAAMM,mBAAmB,MAAMb,OAAO;YACpCc,SAASP,iBAAiBQ,GAAG,CAAC,CAACC,WAAc,CAAA;oBAACC,MAAMD,SAASC,IAAI;oBAAEC,OAAOF;gBAAQ,CAAA;YAClFG,SAAS;QACX;QAEA,OAAOjB,4BAA4BW;IACrC,EAAE,OAAOO,KAAK;QACZjB,MAAM,sCAAsCiB;QAC5C,MAAMA;IACR;AACF"}
1
+ {"version":3,"sources":["../../../../src/actions/auth/login/getSSOProvider.ts"],"sourcesContent":["import {isInteractive, subdebug} from '@sanity/cli-core'\nimport {select} from '@sanity/cli-core/ux'\n\nimport {getSSOProviders} from '../../../services/auth.js'\nimport {type LoginProvider} from '../types.js'\nimport {samlProviderToLoginProvider} from './samlProviderToLoginProvider.js'\n\nconst debug = subdebug('login:getSSOProvider')\n\n/**\n * Get the SSO provider for the given slug\n *\n * @param orgSlug - The slug of the organization to get the SSO provider for\n * @param specifiedSSOProvider - Optional SSO provider name to select without prompting\n * @returns Promise that resolves to the SSO provider\n * @internal\n */\nexport async function getSSOProvider(\n orgSlug: string,\n specifiedSSOProvider?: string,\n): Promise<LoginProvider | undefined> {\n try {\n const providers = await getSSOProviders(orgSlug)\n\n const enabledProviders = providers.filter((candidate) => !candidate.disabled)\n\n // If a specific SSO provider was requested, resolve it by name\n if (specifiedSSOProvider) {\n if (enabledProviders.length === 0) {\n throw new Error(\n `Cannot find SSO provider \"${specifiedSSOProvider}\". No SSO providers are enabled for this organization.`,\n )\n }\n const match = enabledProviders.find(\n (p) => p.name.toLowerCase() === specifiedSSOProvider.toLowerCase(),\n )\n\n if (match) {\n return samlProviderToLoginProvider(match)\n }\n\n const available = enabledProviders.map((p) => p.name).join(', ')\n throw new Error(\n `Cannot find SSO provider \"${specifiedSSOProvider}\". ` +\n `Available SSO providers: ${available}`,\n )\n }\n\n if (enabledProviders.length === 0) {\n return undefined\n }\n\n // Auto-select when only one enabled provider exists\n if (enabledProviders.length === 1) {\n return samlProviderToLoginProvider(enabledProviders[0])\n }\n\n // Multiple providers and no flag — require interactive mode\n if (!isInteractive()) {\n const available = enabledProviders.map((p) => p.name).join(', ')\n throw new Error(\n `Multiple SSO providers available: ${available}. ` +\n 'Use `--sso-provider <name>` to select one in unattended mode.',\n )\n }\n\n const selectedProvider = await select({\n choices: enabledProviders.map((provider) => ({name: provider.name, value: provider})),\n message: 'Select SSO provider',\n })\n\n return samlProviderToLoginProvider(selectedProvider)\n } catch (err) {\n debug('Error retrieving SSO Providers: %O', err)\n throw err\n }\n}\n"],"names":["isInteractive","subdebug","select","getSSOProviders","samlProviderToLoginProvider","debug","getSSOProvider","orgSlug","specifiedSSOProvider","providers","enabledProviders","filter","candidate","disabled","length","Error","match","find","p","name","toLowerCase","available","map","join","undefined","selectedProvider","choices","provider","value","message","err"],"mappings":"AAAA,SAAQA,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AACxD,SAAQC,MAAM,QAAO,sBAAqB;AAE1C,SAAQC,eAAe,QAAO,4BAA2B;AAEzD,SAAQC,2BAA2B,QAAO,mCAAkC;AAE5E,MAAMC,QAAQJ,SAAS;AAEvB;;;;;;;CAOC,GACD,OAAO,eAAeK,eACpBC,OAAe,EACfC,oBAA6B;IAE7B,IAAI;QACF,MAAMC,YAAY,MAAMN,gBAAgBI;QAExC,MAAMG,mBAAmBD,UAAUE,MAAM,CAAC,CAACC,YAAc,CAACA,UAAUC,QAAQ;QAE5E,+DAA+D;QAC/D,IAAIL,sBAAsB;YACxB,IAAIE,iBAAiBI,MAAM,KAAK,GAAG;gBACjC,MAAM,IAAIC,MACR,CAAC,0BAA0B,EAAEP,qBAAqB,sDAAsD,CAAC;YAE7G;YACA,MAAMQ,QAAQN,iBAAiBO,IAAI,CACjC,CAACC,IAAMA,EAAEC,IAAI,CAACC,WAAW,OAAOZ,qBAAqBY,WAAW;YAGlE,IAAIJ,OAAO;gBACT,OAAOZ,4BAA4BY;YACrC;YAEA,MAAMK,YAAYX,iBAAiBY,GAAG,CAAC,CAACJ,IAAMA,EAAEC,IAAI,EAAEI,IAAI,CAAC;YAC3D,MAAM,IAAIR,MACR,CAAC,0BAA0B,EAAEP,qBAAqB,GAAG,CAAC,GACpD,CAAC,yBAAyB,EAAEa,WAAW;QAE7C;QAEA,IAAIX,iBAAiBI,MAAM,KAAK,GAAG;YACjC,OAAOU;QACT;QAEA,oDAAoD;QACpD,IAAId,iBAAiBI,MAAM,KAAK,GAAG;YACjC,OAAOV,4BAA4BM,gBAAgB,CAAC,EAAE;QACxD;QAEA,4DAA4D;QAC5D,IAAI,CAACV,iBAAiB;YACpB,MAAMqB,YAAYX,iBAAiBY,GAAG,CAAC,CAACJ,IAAMA,EAAEC,IAAI,EAAEI,IAAI,CAAC;YAC3D,MAAM,IAAIR,MACR,CAAC,kCAAkC,EAAEM,UAAU,EAAE,CAAC,GAChD;QAEN;QAEA,MAAMI,mBAAmB,MAAMvB,OAAO;YACpCwB,SAAShB,iBAAiBY,GAAG,CAAC,CAACK,WAAc,CAAA;oBAACR,MAAMQ,SAASR,IAAI;oBAAES,OAAOD;gBAAQ,CAAA;YAClFE,SAAS;QACX;QAEA,OAAOzB,4BAA4BqB;IACrC,EAAE,OAAOK,KAAK;QACZzB,MAAM,sCAAsCyB;QAC5C,MAAMA;IACR;AACF"}
@@ -1,4 +1,4 @@
1
- import { getCliToken, setCliUserConfig, subdebug } from '@sanity/cli-core';
1
+ import { getCliToken, getUserConfig, setCliUserConfig, subdebug } from '@sanity/cli-core';
2
2
  import { spinner } from '@sanity/cli-core/ux';
3
3
  import open from 'open';
4
4
  import { logout } from '../../../services/auth.js';
@@ -25,7 +25,8 @@ const debug = subdebug('login');
25
25
  const provider = await getProvider({
26
26
  experimental: options.experimental,
27
27
  orgSlug: options.sso,
28
- specifiedProvider: options.provider
28
+ specifiedProvider: options.provider,
29
+ ssoProvider: options.ssoProvider
29
30
  });
30
31
  trace.log({
31
32
  provider: provider?.name,
@@ -62,9 +63,9 @@ const debug = subdebug('login');
62
63
  });
63
64
  }
64
65
  // Store the token
65
- await setCliUserConfig('authToken', authToken);
66
+ setCliUserConfig('authToken', authToken);
66
67
  // Clear cached telemetry consent
67
- await setCliUserConfig('telemetryConsent', undefined);
68
+ getUserConfig().delete('telemetryConsent');
68
69
  // If we had a session previously, attempt to clear it
69
70
  if (hasExistingToken) {
70
71
  await logout(previousToken).catch((err)=>{
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/actions/auth/login/login.ts"],"sourcesContent":["import {\n type CLITelemetryStore,\n getCliToken,\n type Output,\n setCliUserConfig,\n subdebug,\n} from '@sanity/cli-core'\nimport {spinner} from '@sanity/cli-core/ux'\nimport open from 'open'\n\nimport {logout} from '../../../services/auth.js'\nimport {LoginTrace} from '../../../telemetry/login.telemetry.js'\nimport {canLaunchBrowser} from '../../../util/canLaunchBrowser.js'\nimport {startServerForTokenCallback} from '../authServer.js'\nimport {getProvider} from './getProvider.js'\n\nconst debug = subdebug('login')\n\ninterface LoginOptions {\n output: Output\n\n telemetry: CLITelemetryStore\n\n experimental?: boolean\n open?: boolean\n provider?: string\n sso?: string\n}\n\n/**\n * Trigger the authentication flow for the CLI.\n *\n * NOTE: This uses terminal prompts and will not work for non-interactive/programmatic uses.\n *\n * @param options - Options for the login operation\n * @returns Promise that resolves when the login operation is complete\n * @throws Will throw if login fails or is cancelled\n * @internal\n */\nexport async function login(options: LoginOptions) {\n const {output, telemetry} = options\n const previousToken = await getCliToken()\n const hasExistingToken = Boolean(previousToken)\n\n const trace = telemetry.trace(LoginTrace)\n trace.start()\n\n const provider = await getProvider({\n experimental: options.experimental,\n orgSlug: options.sso,\n specifiedProvider: options.provider,\n })\n\n trace.log({provider: provider?.name, step: 'selectProvider'})\n\n if (provider === undefined) {\n throw new Error('No authentication providers found')\n }\n\n const {loginUrl, server, token: tokenPromise} = await startServerForTokenCallback(provider.url)\n\n trace.log({step: 'waitForToken'})\n\n // Open a browser on the login page (or tell the user to)\n const shouldLaunchBrowser = canLaunchBrowser() && options.open !== false\n const actionText = shouldLaunchBrowser ? 'Opening browser at' : 'Please open a browser at'\n\n output.log(`\\n${actionText} ${loginUrl.href}\\n`)\n\n const spin = spinner('Waiting for browser login to complete... Press Ctrl + C to cancel').start()\n\n if (shouldLaunchBrowser) {\n open(loginUrl.href)\n }\n\n // Wait for a success/error on the HTTP callback server\n let authToken: string\n try {\n authToken = (await tokenPromise).token\n spin.stop()\n } catch (err: unknown) {\n spin.stop()\n trace.error(err as Error)\n debug('Error retrieving token: %O', err)\n throw err\n } finally {\n await new Promise<void>((resolve) => {\n server.close(() => resolve())\n })\n }\n\n // Store the token\n await setCliUserConfig('authToken', authToken)\n\n // Clear cached telemetry consent\n await setCliUserConfig('telemetryConsent', undefined)\n\n // If we had a session previously, attempt to clear it\n if (hasExistingToken) {\n await logout(previousToken).catch((err) => {\n const statusCode = err && err.response && err.response.statusCode\n if (statusCode !== 401) {\n output.warn('Failed to invalidate previous session')\n }\n })\n }\n\n trace.complete()\n}\n"],"names":["getCliToken","setCliUserConfig","subdebug","spinner","open","logout","LoginTrace","canLaunchBrowser","startServerForTokenCallback","getProvider","debug","login","options","output","telemetry","previousToken","hasExistingToken","Boolean","trace","start","provider","experimental","orgSlug","sso","specifiedProvider","log","name","step","undefined","Error","loginUrl","server","token","tokenPromise","url","shouldLaunchBrowser","actionText","href","spin","authToken","stop","err","error","Promise","resolve","close","catch","statusCode","response","warn","complete"],"mappings":"AAAA,SAEEA,WAAW,EAEXC,gBAAgB,EAChBC,QAAQ,QACH,mBAAkB;AACzB,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,OAAOC,UAAU,OAAM;AAEvB,SAAQC,MAAM,QAAO,4BAA2B;AAChD,SAAQC,UAAU,QAAO,wCAAu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,IAAI;QACTtB,MAAMwB,KAAK,CAACD;QACZ/B,MAAM,8BAA8B+B;QACpC,MAAMA;IACR,SAAU;QACR,MAAM,IAAIE,QAAc,CAACC;YACvBb,OAAOc,KAAK,CAAC,IAAMD;QACrB;IACF;IAEA,kBAAkB;IAClB,MAAM3C,iBAAiB,aAAasC;IAEpC,iCAAiC;IACjC,MAAMtC,iBAAiB,oBAAoB2B;IAE3C,sDAAsD;IACtD,IAAIZ,kBAAkB;QACpB,MAAMX,OAAOU,eAAe+B,KAAK,CAAC,CAACL;YACjC,MAAMM,aAAaN,OAAOA,IAAIO,QAAQ,IAAIP,IAAIO,QAAQ,CAACD,UAAU;YACjE,IAAIA,eAAe,KAAK;gBACtBlC,OAAOoC,IAAI,CAAC;YACd;QACF;IACF;IAEA/B,MAAMgC,QAAQ;AAChB"}
1
+ {"version":3,"sources":["../../../../src/actions/auth/login/login.ts"],"sourcesContent":["import {\n type CLITelemetryStore,\n getCliToken,\n getUserConfig,\n type Output,\n setCliUserConfig,\n subdebug,\n} from '@sanity/cli-core'\nimport {spinner} from '@sanity/cli-core/ux'\nimport open from 'open'\n\nimport {logout} from '../../../services/auth.js'\nimport {LoginTrace} from '../../../telemetry/login.telemetry.js'\nimport {canLaunchBrowser} from '../../../util/canLaunchBrowser.js'\nimport {startServerForTokenCallback} from '../authServer.js'\nimport {getProvider} from './getProvider.js'\n\nconst debug = subdebug('login')\n\ninterface LoginOptions {\n output: Output\n\n telemetry: CLITelemetryStore\n\n experimental?: boolean\n open?: boolean\n provider?: string\n sso?: string\n ssoProvider?: string\n}\n\n/**\n * Trigger the authentication flow for the CLI.\n *\n * NOTE: This uses terminal prompts and will not work for non-interactive/programmatic uses.\n *\n * @param options - Options for the login operation\n * @returns Promise that resolves when the login operation is complete\n * @throws Will throw if login fails or is cancelled\n * @internal\n */\nexport async function login(options: LoginOptions) {\n const {output, telemetry} = options\n const previousToken = await getCliToken()\n const hasExistingToken = Boolean(previousToken)\n\n const trace = telemetry.trace(LoginTrace)\n trace.start()\n\n const provider = await getProvider({\n experimental: options.experimental,\n orgSlug: options.sso,\n specifiedProvider: options.provider,\n ssoProvider: options.ssoProvider,\n })\n\n trace.log({provider: provider?.name, step: 'selectProvider'})\n\n if (provider === undefined) {\n throw new Error('No authentication providers found')\n }\n\n const {loginUrl, server, token: tokenPromise} = await startServerForTokenCallback(provider.url)\n\n trace.log({step: 'waitForToken'})\n\n // Open a browser on the login page (or tell the user to)\n const shouldLaunchBrowser = canLaunchBrowser() && options.open !== false\n const actionText = shouldLaunchBrowser ? 'Opening browser at' : 'Please open a browser at'\n\n output.log(`\\n${actionText} ${loginUrl.href}\\n`)\n\n const spin = spinner('Waiting for browser login to complete... Press Ctrl + C to cancel').start()\n\n if (shouldLaunchBrowser) {\n open(loginUrl.href)\n }\n\n // Wait for a success/error on the HTTP callback server\n let authToken: string\n try {\n authToken = (await tokenPromise).token\n spin.stop()\n } catch (err: unknown) {\n spin.stop()\n trace.error(err as Error)\n debug('Error retrieving token: %O', err)\n throw err\n } finally {\n await new Promise<void>((resolve) => {\n server.close(() => resolve())\n })\n }\n\n // Store the token\n setCliUserConfig('authToken', authToken)\n\n // Clear cached telemetry consent\n getUserConfig().delete('telemetryConsent')\n\n // If we had a session previously, attempt to clear it\n if (hasExistingToken) {\n await logout(previousToken).catch((err) => {\n const statusCode = err && err.response && err.response.statusCode\n if (statusCode !== 401) {\n output.warn('Failed to invalidate previous session')\n }\n })\n }\n\n trace.complete()\n}\n"],"names":["getCliToken","getUserConfig","setCliUserConfig","subdebug","spinner","open","logout","LoginTrace","canLaunchBrowser","startServerForTokenCallback","getProvider","debug","login","options","output","telemetry","previousToken","hasExistingToken","Boolean","trace","start","provider","experimental","orgSlug","sso","specifiedProvider","ssoProvider","log","name","step","undefined","Error","loginUrl","server","token","tokenPromise","url","shouldLaunchBrowser","actionText","href","spin","authToken","stop","err","error","Promise","resolve","close","delete","catch","statusCode","response","warn","complete"],"mappings":"AAAA,SAEEA,WAAW,EACXC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IAE/F,IAAIiB,qBAAqB;QACvBhC,KAAK2B,SAASO,IAAI;IACpB;IAEA,uDAAuD;IACvD,IAAIE;IACJ,IAAI;QACFA,YAAY,AAAC,CAAA,MAAMN,YAAW,EAAGD,KAAK;QACtCM,KAAKE,IAAI;IACX,EAAE,OAAOC,KAAc;QACrBH,KAAKE,IAAI;QACTvB,MAAMyB,KAAK,CAACD;QACZhC,MAAM,8BAA8BgC;QACpC,MAAMA;IACR,SAAU;QACR,MAAM,IAAIE,QAAc,CAACC;YACvBb,OAAOc,KAAK,CAAC,IAAMD;QACrB;IACF;IAEA,kBAAkB;IAClB5C,iBAAiB,aAAauC;IAE9B,iCAAiC;IACjCxC,gBAAgB+C,MAAM,CAAC;IAEvB,sDAAsD;IACtD,IAAI/B,kBAAkB;QACpB,MAAMX,OAAOU,eAAeiC,KAAK,CAAC,CAACN;YACjC,MAAMO,aAAaP,OAAOA,IAAIQ,QAAQ,IAAIR,IAAIQ,QAAQ,CAACD,UAAU;YACjE,IAAIA,eAAe,KAAK;gBACtBpC,OAAOsC,IAAI,CAAC;YACd;QACF;IACF;IAEAjC,MAAMkC,QAAQ;AAChB"}
@@ -158,6 +158,7 @@ import { handlePrereleaseVersions } from './handlePrereleaseVersions.js';
158
158
  try {
159
159
  timer.start('bundleStudio');
160
160
  const bundle = await buildStaticFiles({
161
+ appTitle: cliConfig && 'app' in cliConfig ? cliConfig.app?.title : undefined,
161
162
  basePath,
162
163
  cwd: workDir,
163
164
  entry: cliConfig && 'app' in cliConfig ? cliConfig.app?.entry : undefined,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/actions/build/buildApp.ts"],"sourcesContent":["import {rm} from 'node:fs/promises'\nimport path from 'node:path'\nimport {styleText} from 'node:util'\n\nimport {getCliTelemetry, getTimer, isInteractive} from '@sanity/cli-core'\nimport {confirm, logSymbols, spinner, type SpinnerInstance} from '@sanity/cli-core/ux'\nimport semver from 'semver'\n\nimport {AppBuildTrace} from '../../telemetry/build.telemetry.js'\nimport {getAppId} from '../../util/appId.js'\nimport {compareDependencyVersions} from '../../util/compareDependencyVersions.js'\nimport {getLocalPackageVersion} from '../../util/getLocalPackageVersion.js'\nimport {formatModuleSizes, sortModulesBySize} from '../../util/moduleFormatUtils.js'\nimport {warnAboutMissingAppId} from '../../util/warnAboutMissingAppId.js'\nimport {buildDebug} from './buildDebug.js'\nimport {buildStaticFiles} from './buildStaticFiles.js'\nimport {buildVendorDependencies} from './buildVendorDependencies.js'\nimport {determineBasePath} from './determineBasePath.js'\nimport {getAppEnvVars} from './getAppEnvVars.js'\nimport {getAutoUpdatesImportMap} from './getAutoUpdatesImportMap.js'\nimport {handlePrereleaseVersions} from './handlePrereleaseVersions.js'\nimport {type BuildOptions} from './types.js'\n\n/**\n * Build the Sanity app.\n *\n * @internal\n */\nexport async function buildApp(options: BuildOptions): Promise<void> {\n const {cliConfig, flags, outDir, output, workDir} = options\n let {autoUpdatesEnabled} = options\n const unattendedMode = flags.yes\n const timer = getTimer()\n\n const defaultOutputDir = path.resolve(path.join(workDir, 'dist'))\n const outputDir = path.resolve(outDir || defaultOutputDir)\n\n const appId = getAppId(cliConfig)\n\n const installedSdkVersion = await getLocalPackageVersion('@sanity/sdk-react', workDir)\n const installedSanityVersion = await getLocalPackageVersion('sanity', workDir)\n\n if (!installedSdkVersion) {\n output.error(`Failed to find installed @sanity/sdk-react version`, {exit: 1})\n return\n }\n\n let autoUpdatesImports = {}\n\n if (autoUpdatesEnabled) {\n // Get the clean version without build metadata: https://semver.org/#spec-item-10\n const cleanSDKVersion = semver.parse(installedSdkVersion)?.version\n if (!cleanSDKVersion) {\n output.error(`Failed to parse installed SDK version: ${installedSdkVersion}`, {exit: 1})\n return\n }\n\n // Sanity might not be installed, but if it is, we want to auto update it.\n const cleanSanityVersion = semver.parse(installedSanityVersion)?.version\n\n const autoUpdatedPackages = [\n {name: '@sanity/sdk', version: cleanSDKVersion},\n {name: '@sanity/sdk-react', version: cleanSDKVersion},\n ...(cleanSanityVersion ? [{name: 'sanity' as const, version: cleanSanityVersion}] : []),\n ]\n autoUpdatesImports = getAutoUpdatesImportMap(autoUpdatedPackages, {appId})\n\n output.log(`${logSymbols.info} Building with auto-updates enabled`)\n\n // Warn if auto updates enabled but no appId configured.\n // Skip when called from deploy, since deploy handles appId itself\n // (prompts the user and tells them to add it to config).\n if (!appId && !options.calledFromDeploy) {\n warnAboutMissingAppId({appType: 'app', output})\n }\n\n // Check the versions\n const {mismatched, unresolvedPrerelease} = await compareDependencyVersions(\n autoUpdatedPackages,\n workDir,\n {appId},\n )\n\n if (unresolvedPrerelease.length > 0) {\n await handlePrereleaseVersions({output, unattendedMode, unresolvedPrerelease})\n autoUpdatesImports = {}\n autoUpdatesEnabled = false\n }\n\n if (mismatched.length > 0 && autoUpdatesEnabled) {\n const versionMismatchWarning =\n `The following local package versions are different from the versions currently served at runtime.\\n` +\n `When using auto updates, we recommend that you test locally with the same versions before deploying. \\n\\n` +\n `${mismatched.map((mod) => ` - ${mod.pkg} (local version: ${mod.installed}, runtime version: ${mod.remote})`).join('\\n')}`\n\n // If it is non-interactive or in unattended mode, we don't want to prompt\n if (isInteractive() && !unattendedMode) {\n const shouldContinue = await confirm({\n default: false,\n message: styleText('yellow', `${versionMismatchWarning} \\n\\nContinue anyway?`),\n })\n\n if (!shouldContinue) {\n output.error('Declined to continue with build', {exit: 1})\n return\n }\n } else {\n // if non-interactive or unattended, just show the warning\n output.warn(versionMismatchWarning)\n }\n }\n }\n\n const envVarKeys = getAppEnvVars()\n if (envVarKeys.length > 0) {\n output.log('\\nIncluding the following environment variables as part of the JavaScript bundle:')\n for (const key of envVarKeys) output.log(`- ${key}`)\n output.log('')\n }\n\n let shouldClean = true\n if (outputDir !== defaultOutputDir && !unattendedMode && isInteractive()) {\n shouldClean = await confirm({\n default: true,\n message: `Do you want to delete the existing directory (${outputDir}) first?`,\n })\n }\n\n // Determine base path for built app\n const basePath = determineBasePath(cliConfig, 'app', output)\n\n let spin: SpinnerInstance\n if (shouldClean) {\n timer.start('cleanOutputFolder')\n spin = spinner('Clean output folder').start()\n await rm(outputDir, {force: true, recursive: true})\n const cleanDuration = timer.end('cleanOutputFolder')\n spin.text = `Clean output folder (${cleanDuration.toFixed(0)}ms)`\n spin.succeed()\n }\n\n spin = spinner(`Building Sanity application`).start()\n\n const trace = getCliTelemetry().trace(AppBuildTrace)\n trace.start()\n\n let importMap: {imports?: Record<string, string>} | undefined\n\n if (autoUpdatesEnabled) {\n importMap = {\n imports: {\n ...(await buildVendorDependencies({basePath, cwd: workDir, isApp: true, outputDir})),\n ...autoUpdatesImports,\n },\n }\n }\n\n try {\n timer.start('bundleStudio')\n\n const bundle = await buildStaticFiles({\n basePath,\n cwd: workDir,\n entry: cliConfig && 'app' in cliConfig ? cliConfig.app?.entry : undefined,\n importMap,\n isApp: true,\n minify: Boolean(flags.minify),\n outputDir,\n reactCompiler:\n cliConfig && 'reactCompiler' in cliConfig ? cliConfig.reactCompiler : undefined,\n sourceMap: Boolean(flags['source-maps']),\n vite: cliConfig && 'vite' in cliConfig ? cliConfig.vite : undefined,\n })\n\n trace.log({\n outputSize: bundle.chunks\n .flatMap((chunk) => chunk.modules.flatMap((mod) => mod.renderedLength))\n .reduce((sum, n) => sum + n, 0),\n })\n const buildDuration = timer.end('bundleStudio')\n\n spin.text = `Build Sanity application (${buildDuration.toFixed(0)}ms)`\n spin.succeed()\n\n if (flags.stats) {\n output.log('\\nLargest module files:')\n output.log(formatModuleSizes(sortModulesBySize(bundle.chunks).slice(0, 15)))\n }\n\n trace.complete()\n } catch (error) {\n spin.fail()\n trace.error(error)\n const message = error instanceof Error ? error.message : String(error)\n buildDebug(`Failed to build Sanity application`, {error})\n output.error(`Failed to build Sanity application: ${message}`, {exit: 1})\n }\n}\n"],"names":["rm","path","styleText","getCliTelemetry","getTimer","isInteractive","confirm","logSymbols","spinner","semver","AppBuildTrace","getAppId","compareDependencyVersions","getLocalPackageVersion","formatModuleSizes","sortModulesBySize","warnAboutMissingAppId","buildDebug","buildStaticFiles","buildVendorDependencies","determineBasePath","getAppEnvVars","getAutoUpdatesImportMap","handlePrereleaseVersions","buildApp","options","cliConfig","flags","outDir","output","workDir","autoUpdatesEnabled","unattendedMode","yes","timer","defaultOutputDir","resolve","join","outputDir","appId","installedSdkVersion","installedSanityVersion","error","exit","autoUpdatesImports","cleanSDKVersion","parse","version","cleanSanityVersion","autoUpdatedPackages","name","log","info","calledFromDeploy","appType","mismatched","unresolvedPrerelease","length","versionMismatchWarning","map","mod","pkg","installed","remote","shouldContinue","default","message","warn","envVarKeys","key","shouldClean","basePath","spin","start","force","recursive","cleanDuration","end","text","toFixed","succeed","trace","importMap","imports","cwd","isApp","bundle","entry","app","undefined","minify","Boolean","reactCompiler","sourceMap","vite","outputSize","chunks","flatMap","chunk","modules","renderedLength","reduce","sum","n","buildDuration","stats","slice","complete","fail","Error","String"],"mappings":"AAAA,SAAQA,EAAE,QAAO,mBAAkB;AACnC,OAAOC,UAAU,YAAW;AAC5B,SAAQC,SAAS,QAAO,YAAW;AAEnC,SAAQC,eAAe,EAAEC,QAAQ,EAAEC,aAAa,QAAO,mBAAkB;AACzE,SAAQC,OAAO,EAAEC,UAAU,EAAEC,OAAO,QAA6B,sBAAqB;AACtF,OAAOC,YAAY,SAAQ;AAE3B,SAAQC,aAAa,QAAO,qCAAoC;AAChE,SAAQC,QAAQ,QAAO,sBAAqB;AAC5C,SAAQC,yBAAyB,QAAO,0CAAyC;AACjF,SAAQC,sBAAsB,QAAO,uCAAsC;AAC3E,SAAQC,iBAAiB,EAAEC,iBAAiB,QAAO,kCAAiC;AACpF,SAAQC,qBAAqB,QAAO,sCAAqC;AACzE,SAAQC,UAAU,QAAO,kBAAiB;AAC1C,SAAQC,gBAAgB,QAAO,wBAAuB;AACtD,SAAQC,uBAAuB,QAAO,+BAA8B;AACpE,SAAQC,iBAAiB,QAAO,yBAAwB;AACxD,SAAQC,aAAa,QAAO,qBAAoB;AAChD,SAAQC,uBAAuB,QAAO,+BAA8B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,GAAGH;YACxEI,WAAWF,QAAQhE,KAAK,CAAC,cAAc;YACvCmE,MAAMpE,aAAa,UAAUA,YAAYA,UAAUoE,IAAI,GAAGL;QAC5D;QAEAR,MAAM9B,GAAG,CAAC;YACR4C,YAAYT,OAAOU,MAAM,CACtBC,OAAO,CAAC,CAACC,QAAUA,MAAMC,OAAO,CAACF,OAAO,CAAC,CAACrC,MAAQA,IAAIwC,cAAc,GACpEC,MAAM,CAAC,CAACC,KAAKC,IAAMD,MAAMC,GAAG;QACjC;QACA,MAAMC,gBAAgBtE,MAAM2C,GAAG,CAAC;QAEhCL,KAAKM,IAAI,GAAG,CAAC,0BAA0B,EAAE0B,cAAczB,OAAO,CAAC,GAAG,GAAG,CAAC;QACtEP,KAAKQ,OAAO;QAEZ,IAAIrD,MAAM8E,KAAK,EAAE;YACf5E,OAAOsB,GAAG,CAAC;YACXtB,OAAOsB,GAAG,CAACrC,kBAAkBC,kBAAkBuE,OAAOU,MAAM,EAAEU,KAAK,CAAC,GAAG;QACzE;QAEAzB,MAAM0B,QAAQ;IAChB,EAAE,OAAOjE,OAAO;QACd8B,KAAKoC,IAAI;QACT3B,MAAMvC,KAAK,CAACA;QACZ,MAAMwB,UAAUxB,iBAAiBmE,QAAQnE,MAAMwB,OAAO,GAAG4C,OAAOpE;QAChEzB,WAAW,CAAC,kCAAkC,CAAC,EAAE;YAACyB;QAAK;QACvDb,OAAOa,KAAK,CAAC,CAAC,oCAAoC,EAAEwB,SAAS,EAAE;YAACvB,MAAM;QAAC;IACzE;AACF"}
1
+ {"version":3,"sources":["../../../src/actions/build/buildApp.ts"],"sourcesContent":["import {rm} from 'node:fs/promises'\nimport path from 'node:path'\nimport {styleText} from 'node:util'\n\nimport {getCliTelemetry, getTimer, isInteractive} from '@sanity/cli-core'\nimport {confirm, logSymbols, spinner, type SpinnerInstance} from '@sanity/cli-core/ux'\nimport semver from 'semver'\n\nimport {AppBuildTrace} from '../../telemetry/build.telemetry.js'\nimport {getAppId} from '../../util/appId.js'\nimport {compareDependencyVersions} from '../../util/compareDependencyVersions.js'\nimport {getLocalPackageVersion} from '../../util/getLocalPackageVersion.js'\nimport {formatModuleSizes, sortModulesBySize} from '../../util/moduleFormatUtils.js'\nimport {warnAboutMissingAppId} from '../../util/warnAboutMissingAppId.js'\nimport {buildDebug} from './buildDebug.js'\nimport {buildStaticFiles} from './buildStaticFiles.js'\nimport {buildVendorDependencies} from './buildVendorDependencies.js'\nimport {determineBasePath} from './determineBasePath.js'\nimport {getAppEnvVars} from './getAppEnvVars.js'\nimport {getAutoUpdatesImportMap} from './getAutoUpdatesImportMap.js'\nimport {handlePrereleaseVersions} from './handlePrereleaseVersions.js'\nimport {type BuildOptions} from './types.js'\n\n/**\n * Build the Sanity app.\n *\n * @internal\n */\nexport async function buildApp(options: BuildOptions): Promise<void> {\n const {cliConfig, flags, outDir, output, workDir} = options\n let {autoUpdatesEnabled} = options\n const unattendedMode = flags.yes\n const timer = getTimer()\n\n const defaultOutputDir = path.resolve(path.join(workDir, 'dist'))\n const outputDir = path.resolve(outDir || defaultOutputDir)\n\n const appId = getAppId(cliConfig)\n\n const installedSdkVersion = await getLocalPackageVersion('@sanity/sdk-react', workDir)\n const installedSanityVersion = await getLocalPackageVersion('sanity', workDir)\n\n if (!installedSdkVersion) {\n output.error(`Failed to find installed @sanity/sdk-react version`, {exit: 1})\n return\n }\n\n let autoUpdatesImports = {}\n\n if (autoUpdatesEnabled) {\n // Get the clean version without build metadata: https://semver.org/#spec-item-10\n const cleanSDKVersion = semver.parse(installedSdkVersion)?.version\n if (!cleanSDKVersion) {\n output.error(`Failed to parse installed SDK version: ${installedSdkVersion}`, {exit: 1})\n return\n }\n\n // Sanity might not be installed, but if it is, we want to auto update it.\n const cleanSanityVersion = semver.parse(installedSanityVersion)?.version\n\n const autoUpdatedPackages = [\n {name: '@sanity/sdk', version: cleanSDKVersion},\n {name: '@sanity/sdk-react', version: cleanSDKVersion},\n ...(cleanSanityVersion ? [{name: 'sanity' as const, version: cleanSanityVersion}] : []),\n ]\n autoUpdatesImports = getAutoUpdatesImportMap(autoUpdatedPackages, {appId})\n\n output.log(`${logSymbols.info} Building with auto-updates enabled`)\n\n // Warn if auto updates enabled but no appId configured.\n // Skip when called from deploy, since deploy handles appId itself\n // (prompts the user and tells them to add it to config).\n if (!appId && !options.calledFromDeploy) {\n warnAboutMissingAppId({appType: 'app', output})\n }\n\n // Check the versions\n const {mismatched, unresolvedPrerelease} = await compareDependencyVersions(\n autoUpdatedPackages,\n workDir,\n {appId},\n )\n\n if (unresolvedPrerelease.length > 0) {\n await handlePrereleaseVersions({output, unattendedMode, unresolvedPrerelease})\n autoUpdatesImports = {}\n autoUpdatesEnabled = false\n }\n\n if (mismatched.length > 0 && autoUpdatesEnabled) {\n const versionMismatchWarning =\n `The following local package versions are different from the versions currently served at runtime.\\n` +\n `When using auto updates, we recommend that you test locally with the same versions before deploying. \\n\\n` +\n `${mismatched.map((mod) => ` - ${mod.pkg} (local version: ${mod.installed}, runtime version: ${mod.remote})`).join('\\n')}`\n\n // If it is non-interactive or in unattended mode, we don't want to prompt\n if (isInteractive() && !unattendedMode) {\n const shouldContinue = await confirm({\n default: false,\n message: styleText('yellow', `${versionMismatchWarning} \\n\\nContinue anyway?`),\n })\n\n if (!shouldContinue) {\n output.error('Declined to continue with build', {exit: 1})\n return\n }\n } else {\n // if non-interactive or unattended, just show the warning\n output.warn(versionMismatchWarning)\n }\n }\n }\n\n const envVarKeys = getAppEnvVars()\n if (envVarKeys.length > 0) {\n output.log('\\nIncluding the following environment variables as part of the JavaScript bundle:')\n for (const key of envVarKeys) output.log(`- ${key}`)\n output.log('')\n }\n\n let shouldClean = true\n if (outputDir !== defaultOutputDir && !unattendedMode && isInteractive()) {\n shouldClean = await confirm({\n default: true,\n message: `Do you want to delete the existing directory (${outputDir}) first?`,\n })\n }\n\n // Determine base path for built app\n const basePath = determineBasePath(cliConfig, 'app', output)\n\n let spin: SpinnerInstance\n if (shouldClean) {\n timer.start('cleanOutputFolder')\n spin = spinner('Clean output folder').start()\n await rm(outputDir, {force: true, recursive: true})\n const cleanDuration = timer.end('cleanOutputFolder')\n spin.text = `Clean output folder (${cleanDuration.toFixed(0)}ms)`\n spin.succeed()\n }\n\n spin = spinner(`Building Sanity application`).start()\n\n const trace = getCliTelemetry().trace(AppBuildTrace)\n trace.start()\n\n let importMap: {imports?: Record<string, string>} | undefined\n\n if (autoUpdatesEnabled) {\n importMap = {\n imports: {\n ...(await buildVendorDependencies({basePath, cwd: workDir, isApp: true, outputDir})),\n ...autoUpdatesImports,\n },\n }\n }\n\n try {\n timer.start('bundleStudio')\n\n const bundle = await buildStaticFiles({\n appTitle: cliConfig && 'app' in cliConfig ? cliConfig.app?.title : undefined,\n basePath,\n cwd: workDir,\n entry: cliConfig && 'app' in cliConfig ? cliConfig.app?.entry : undefined,\n importMap,\n isApp: true,\n minify: Boolean(flags.minify),\n outputDir,\n reactCompiler:\n cliConfig && 'reactCompiler' in cliConfig ? cliConfig.reactCompiler : undefined,\n sourceMap: Boolean(flags['source-maps']),\n vite: cliConfig && 'vite' in cliConfig ? cliConfig.vite : undefined,\n })\n\n trace.log({\n outputSize: bundle.chunks\n .flatMap((chunk) => chunk.modules.flatMap((mod) => mod.renderedLength))\n .reduce((sum, n) => sum + n, 0),\n })\n const buildDuration = timer.end('bundleStudio')\n\n spin.text = `Build Sanity application (${buildDuration.toFixed(0)}ms)`\n spin.succeed()\n\n if (flags.stats) {\n output.log('\\nLargest module files:')\n output.log(formatModuleSizes(sortModulesBySize(bundle.chunks).slice(0, 15)))\n }\n\n trace.complete()\n } catch (error) {\n spin.fail()\n trace.error(error)\n const message = error instanceof Error ? error.message : String(error)\n buildDebug(`Failed to build Sanity application`, {error})\n output.error(`Failed to build Sanity application: ${message}`, {exit: 1})\n }\n}\n"],"names":["rm","path","styleText","getCliTelemetry","getTimer","isInteractive","confirm","logSymbols","spinner","semver","AppBuildTrace","getAppId","compareDependencyVersions","getLocalPackageVersion","formatModuleSizes","sortModulesBySize","warnAboutMissingAppId","buildDebug","buildStaticFiles","buildVendorDependencies","determineBasePath","getAppEnvVars","getAutoUpdatesImportMap","handlePrereleaseVersions","buildApp","options","cliConfig","flags","outDir","output","workDir","autoUpdatesEnabled","unattendedMode","yes","timer","defaultOutputDir","resolve","join","outputDir","appId","installedSdkVersion","installedSanityVersion","error","exit","autoUpdatesImports","cleanSDKVersion","parse","version","cleanSanityVersion","autoUpdatedPackages","name","log","info","calledFromDeploy","appType","mismatched","unresolvedPrerelease","length","versionMismatchWarning","map","mod","pkg","installed","remote","shouldContinue","default","message","warn","envVarKeys","key","shouldClean","basePath","spin","start","force","recursive","cleanDuration","end","text","toFixed","succeed","trace","importMap","imports","cwd","isApp","bundle","appTitle","app","title","undefined","entry","minify","Boolean","reactCompiler","sourceMap","vite","outputSize","chunks","flatMap","chunk","modules","renderedLength","reduce","sum","n","buildDuration","stats","slice","complete","fail","Error","String"],"mappings":"AAAA,SAAQA,EAAE,QAAO,mBAAkB;AACnC,OAAOC,UAAU,YAAW;AAC5B,SAAQC,SAAS,QAAO,YAAW;AAEnC,SAAQC,eAAe,EAAEC,QAAQ,EAAEC,aAAa,QAAO,mBAAkB;AACzE,SAAQC,OAAO,EAAEC,UAAU,EAAEC,OAAO,QAA6B,sBAAqB;AACtF,OAAOC,YAAY,SAAQ;AAE3B,SAAQC,aAAa,QAAO,qCAAoC;AAChE,SAAQC,QAAQ,QAAO,sBAAqB;AAC5C,SAAQC,yBAAyB,QAAO,0CAAyC;AACjF,SAAQC,sBAAsB,QAAO,uCAAsC;AAC3E,SAAQC,iBAAiB,EAAEC,iBAAiB,QAAO,kCAAiC;AACpF,SAAQC,qBAAqB,QAAO,sCAAqC;AACzE,SAAQC,UAAU,QAAO,kBAAiB;AAC1C,SAAQC,gBAAgB,QAAO,wBAAuB;AACtD,SAAQC,uBAAuB,QAAO,+BAA8B;AACpE,SAAQC,iBAAiB,QAAO,yBAAwB;AACxD,SAAQC,aAAa,QAAO,qBAAoB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OAAO;YACPO,QAAQC,QAAQlE,MAAMiE,MAAM;YAC5BtD;YACAwD,eACEpE,aAAa,mBAAmBA,YAAYA,UAAUoE,aAAa,GAAGJ;YACxEK,WAAWF,QAAQlE,KAAK,CAAC,cAAc;YACvCqE,MAAMtE,aAAa,UAAUA,YAAYA,UAAUsE,IAAI,GAAGN;QAC5D;QAEAT,MAAM9B,GAAG,CAAC;YACR8C,YAAYX,OAAOY,MAAM,CACtBC,OAAO,CAAC,CAACC,QAAUA,MAAMC,OAAO,CAACF,OAAO,CAAC,CAACvC,MAAQA,IAAI0C,cAAc,GACpEC,MAAM,CAAC,CAACC,KAAKC,IAAMD,MAAMC,GAAG;QACjC;QACA,MAAMC,gBAAgBxE,MAAM2C,GAAG,CAAC;QAEhCL,KAAKM,IAAI,GAAG,CAAC,0BAA0B,EAAE4B,cAAc3B,OAAO,CAAC,GAAG,GAAG,CAAC;QACtEP,KAAKQ,OAAO;QAEZ,IAAIrD,MAAMgF,KAAK,EAAE;YACf9E,OAAOsB,GAAG,CAAC;YACXtB,OAAOsB,GAAG,CAACrC,kBAAkBC,kBAAkBuE,OAAOY,MAAM,EAAEU,KAAK,CAAC,GAAG;QACzE;QAEA3B,MAAM4B,QAAQ;IAChB,EAAE,OAAOnE,OAAO;QACd8B,KAAKsC,IAAI;QACT7B,MAAMvC,KAAK,CAACA;QACZ,MAAMwB,UAAUxB,iBAAiBqE,QAAQrE,MAAMwB,OAAO,GAAG8C,OAAOtE;QAChEzB,WAAW,CAAC,kCAAkC,CAAC,EAAE;YAACyB;QAAK;QACvDb,OAAOa,KAAK,CAAC,CAAC,oCAAoC,EAAEwB,SAAS,EAAE;YAACvB,MAAM;QAAC;IACzE;AACF"}
@@ -10,9 +10,10 @@ import { writeSanityRuntime } from './writeSanityRuntime.js';
10
10
  *
11
11
  * @internal
12
12
  */ export async function buildStaticFiles(options) {
13
- const { basePath, cwd, entry, importMap, isApp, minify = true, outputDir, reactCompiler, sourceMap = false, vite: extendViteConfig } = options;
13
+ const { appTitle, basePath, cwd, entry, importMap, isApp, minify = true, outputDir, reactCompiler, sourceMap = false, vite: extendViteConfig } = options;
14
14
  buildDebug('Writing Sanity runtime files');
15
15
  await writeSanityRuntime({
16
+ appTitle,
16
17
  basePath,
17
18
  cwd,
18
19
  entry,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/actions/build/buildStaticFiles.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {type UserViteConfig} from '@sanity/cli-core'\nimport {type PluginOptions as ReactCompilerConfig} from 'babel-plugin-react-compiler'\nimport {build} from 'vite'\n\nimport {copyDir} from '../../util/copyDir.js'\nimport {buildDebug} from './buildDebug.js'\nimport {extendViteConfigWithUserConfig, finalizeViteConfig, getViteConfig} from './getViteConfig.js'\nimport {writeFavicons} from './writeFavicons.js'\nimport {writeSanityRuntime} from './writeSanityRuntime.js'\n\nexport interface ChunkModule {\n name: string\n originalLength: number\n renderedLength: number\n}\n\nexport interface ChunkStats {\n modules: ChunkModule[]\n name: string\n}\n\ninterface StaticBuildOptions {\n basePath: string\n cwd: string\n outputDir: string\n\n entry?: string\n importMap?: {imports?: Record<string, string>}\n isApp?: boolean\n minify?: boolean\n profile?: boolean\n reactCompiler?: ReactCompilerConfig\n sourceMap?: boolean\n vite?: UserViteConfig\n}\n\n/**\n * Builds static files\n *\n * @internal\n */\nexport async function buildStaticFiles(\n options: StaticBuildOptions,\n): Promise<{chunks: ChunkStats[]}> {\n const {\n basePath,\n cwd,\n entry,\n importMap,\n isApp,\n minify = true,\n outputDir,\n reactCompiler,\n sourceMap = false,\n vite: extendViteConfig,\n } = options\n\n buildDebug('Writing Sanity runtime files')\n await writeSanityRuntime({\n basePath,\n cwd,\n entry,\n isApp,\n reactStrictMode: false,\n watch: false,\n })\n\n buildDebug('Resolving vite config')\n const mode = 'production'\n let viteConfig = await getViteConfig({\n basePath,\n cwd,\n importMap,\n isApp,\n minify,\n mode,\n outputDir,\n reactCompiler,\n sourceMap,\n })\n\n if (extendViteConfig) {\n viteConfig = await extendViteConfigWithUserConfig(\n {command: 'build', mode},\n viteConfig,\n extendViteConfig,\n )\n viteConfig = await finalizeViteConfig(viteConfig)\n }\n\n const fromPath = path.join(cwd, 'static')\n // Copy files placed in /static to the built /static\n buildDebug(`Copying static files from ${fromPath} to output dir`)\n const staticPath = path.join(outputDir, 'static')\n await copyDir(fromPath, staticPath)\n\n // Write favicons, not overwriting ones that already exist, to static folder\n buildDebug('Writing favicons to output dir')\n const faviconBasePath = `${basePath.replace(/\\/+$/, '')}/static`\n await writeFavicons(faviconBasePath, staticPath)\n\n buildDebug('Bundling using vite')\n const bundle = await build(viteConfig)\n buildDebug('Bundling complete')\n\n // For typescript only - this shouldn't ever be the case given we're not watching\n if (Array.isArray(bundle) || !('output' in bundle)) {\n return {chunks: []}\n }\n\n const stats: ChunkStats[] = []\n for (const chunk of bundle.output) {\n if (chunk.type !== 'chunk') {\n continue\n }\n\n stats.push({\n modules: Object.entries(chunk.modules).map(([rawFilePath, chunkModule]) => {\n const filePath = rawFilePath.startsWith('\\u0000')\n ? rawFilePath.slice('\\u0000'.length)\n : rawFilePath\n\n return {\n name: path.isAbsolute(filePath) ? path.relative(cwd, filePath) : filePath,\n originalLength: chunkModule.originalLength,\n renderedLength: chunkModule.renderedLength,\n }\n }),\n name: chunk.name,\n })\n }\n\n return {chunks: stats}\n}\n"],"names":["path","build","copyDir","buildDebug","extendViteConfigWithUserConfig","finalizeViteConfig","getViteConfig","writeFavicons","writeSanityRuntime","buildStaticFiles","options","basePath","cwd","entry","importMap","isApp","minify","outputDir","reactCompiler","sourceMap","vite","extendViteConfig","reactStrictMode","watch","mode","viteConfig","command","fromPath","join","staticPath","faviconBasePath","replace","bundle","Array","isArray","chunks","stats","chunk","output","type","push","modules","Object","entries","map","rawFilePath","chunkModule","filePath","startsWith","slice","length","name","isAbsolute","relative","originalLength","renderedLength"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAI5B,SAAQC,KAAK,QAAO,OAAM;AA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A,YAAYA,MAAK,GAAI;QAClD,OAAO;YAACG,QAAQ,EAAE;QAAA;IACpB;IAEA,MAAMC,QAAsB,EAAE;IAC9B,KAAK,MAAMC,SAASL,OAAOM,MAAM,CAAE;QACjC,IAAID,MAAME,IAAI,KAAK,SAAS;YAC1B;QACF;QAEAH,MAAMI,IAAI,CAAC;YACTC,SAASC,OAAOC,OAAO,CAACN,MAAMI,OAAO,EAAEG,GAAG,CAAC,CAAC,CAACC,aAAaC,YAAY;gBACpE,MAAMC,WAAWF,YAAYG,UAAU,CAAC,YACpCH,YAAYI,KAAK,CAAC,SAASC,MAAM,IACjCL;gBAEJ,OAAO;oBACLM,MAAMnD,KAAKoD,UAAU,CAACL,YAAY/C,KAAKqD,QAAQ,CAACzC,KAAKmC,YAAYA;oBACjEO,gBAAgBR,YAAYQ,cAAc;oBAC1CC,gBAAgBT,YAAYS,cAAc;gBAC5C;YACF;YACAJ,MAAMd,MAAMc,IAAI;QAClB;IACF;IAEA,OAAO;QAAChB,QAAQC;IAAK;AACvB"}
1
+ {"version":3,"sources":["../../../src/actions/build/buildStaticFiles.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {type UserViteConfig} from '@sanity/cli-core'\nimport {type PluginOptions as ReactCompilerConfig} from 'babel-plugin-react-compiler'\nimport {build} from 'vite'\n\nimport {copyDir} from '../../util/copyDir.js'\nimport {buildDebug} from './buildDebug.js'\nimport {extendViteConfigWithUserConfig, finalizeViteConfig, getViteConfig} from './getViteConfig.js'\nimport {writeFavicons} from './writeFavicons.js'\nimport {writeSanityRuntime} from './writeSanityRuntime.js'\n\nexport interface ChunkModule {\n name: string\n originalLength: number\n renderedLength: number\n}\n\nexport interface ChunkStats {\n modules: ChunkModule[]\n name: string\n}\n\ninterface StaticBuildOptions {\n basePath: string\n cwd: string\n outputDir: string\n\n appTitle?: string\n entry?: string\n importMap?: {imports?: Record<string, string>}\n isApp?: boolean\n minify?: boolean\n profile?: boolean\n reactCompiler?: ReactCompilerConfig\n sourceMap?: boolean\n vite?: UserViteConfig\n}\n\n/**\n * Builds static files\n *\n * @internal\n */\nexport async function buildStaticFiles(\n options: StaticBuildOptions,\n): Promise<{chunks: ChunkStats[]}> {\n const {\n appTitle,\n basePath,\n cwd,\n entry,\n importMap,\n isApp,\n minify = true,\n outputDir,\n reactCompiler,\n sourceMap = false,\n vite: extendViteConfig,\n } = options\n\n buildDebug('Writing Sanity runtime files')\n await writeSanityRuntime({\n appTitle,\n basePath,\n cwd,\n entry,\n isApp,\n reactStrictMode: false,\n watch: false,\n })\n\n buildDebug('Resolving vite config')\n const mode = 'production'\n let viteConfig = await getViteConfig({\n basePath,\n cwd,\n importMap,\n isApp,\n minify,\n mode,\n outputDir,\n reactCompiler,\n sourceMap,\n })\n\n if (extendViteConfig) {\n viteConfig = await extendViteConfigWithUserConfig(\n {command: 'build', mode},\n viteConfig,\n extendViteConfig,\n )\n viteConfig = await finalizeViteConfig(viteConfig)\n }\n\n const fromPath = path.join(cwd, 'static')\n // Copy files placed in /static to the built /static\n buildDebug(`Copying static files from ${fromPath} to output dir`)\n const staticPath = path.join(outputDir, 'static')\n await copyDir(fromPath, staticPath)\n\n // Write favicons, not overwriting ones that already exist, to static folder\n buildDebug('Writing favicons to output dir')\n const faviconBasePath = `${basePath.replace(/\\/+$/, '')}/static`\n await writeFavicons(faviconBasePath, staticPath)\n\n buildDebug('Bundling using vite')\n const bundle = await build(viteConfig)\n buildDebug('Bundling complete')\n\n // For typescript only - this shouldn't ever be the case given we're not watching\n if (Array.isArray(bundle) || !('output' in bundle)) {\n return {chunks: []}\n }\n\n const stats: ChunkStats[] = []\n for (const chunk of bundle.output) {\n if (chunk.type !== 'chunk') {\n continue\n }\n\n stats.push({\n modules: Object.entries(chunk.modules).map(([rawFilePath, chunkModule]) => {\n const filePath = rawFilePath.startsWith('\\u0000')\n ? rawFilePath.slice('\\u0000'.length)\n : rawFilePath\n\n return {\n name: path.isAbsolute(filePath) ? path.relative(cwd, filePath) : filePath,\n originalLength: chunkModule.originalLength,\n renderedLength: chunkModule.renderedLength,\n }\n }),\n name: chunk.name,\n })\n }\n\n return {chunks: stats}\n}\n"],"names":["path","build","copyDir","buildDebug","extendViteConfigWithUserConfig","finalizeViteConfig","getViteConfig","writeFavicons","writeSanityRuntime","buildStaticFiles","options","appTitle","basePath","cwd","entry","importMap","isApp","minify","outputDir","reactCompiler","sourceMap","vite","extendViteConfig","reactStrictMode","watch","mode","viteConfig","command","fromPath","join","staticPath","faviconBasePath","replace","bundle","Array","isArray","chunks","stats","chunk","output","type","push","modules","Object","entries","map","rawFilePath","chunkModule","filePath","startsWith","slice","length","name","isAbsolute","relative","originalLength","renderedLength"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAI5B,SAAQC,KAAK,QAAO,OAAM;AAE1B,SAAQC,OAAO,QAAO,wBAAuB;AAC7C,SAAQC,UAAU,QAAO,kBAAiB;AAC1C,SAAQC,8BAA8B,EAAEC,kBAAkB,EAAEC,aAAa,QAAO,qBAAoB;AACpG,SAAQC,aAAa,QAAO,qBAAoB;AAChD,SAAQC,kBAAkB,QAAO,0BAAyB;AA6B1D;;;;CAIC,GACD,OAAO,eAAeC,iBACpBC,OAA2B;IAE3B,MAAM,EACJC,QAAQ,EACRC,QAAQ,EACRC,GAAG,EACHC,KAAK,EACLC,SAAS,EACTC,KAAK,EACLC,SAAS,IAAI,EACbC,SAAS,EACTC,aAAa,EACbC,YAAY,KAAK,EACjBC,MAAMC,gBAAgB,EACvB,GAAGZ;IAEJP,WAAW;IACX,MAAMK,mBAAmB;QACvBG;QACAC;QACAC;QACAC;QACAE;QACAO,iBAAiB;QACjBC,OAAO;IACT;IAEArB,WAAW;IACX,MAAMsB,OAAO;IACb,IAAIC,aAAa,MAAMpB,cAAc;QACnCM;QACAC;QACAE;QACAC;QACAC;QACAQ;QACAP;QACAC;QACAC;IACF;IAEA,IAAIE,kBAAkB;QACpBI,aAAa,MAAMtB,+BACjB;YAACuB,SAAS;YAASF;QAAI,GACvBC,YACAJ;QAEFI,aAAa,MAAMrB,mBAAmBqB;IACxC;IAEA,MAAME,WAAW5B,KAAK6B,IAAI,CAAChB,KAAK;IAChC,oDAAoD;IACpDV,WAAW,CAAC,0BAA0B,EAAEyB,SAAS,cAAc,CAAC;IAChE,MAAME,aAAa9B,KAAK6B,IAAI,CAACX,WAAW;IACxC,MAAMhB,QAAQ0B,UAAUE;IAExB,4EAA4E;IAC5E3B,WAAW;IACX,MAAM4B,kBAAkB,GAAGnB,SAASoB,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC;IAChE,MAAMzB,cAAcwB,iBAAiBD;IAErC3B,WAAW;IACX,MAAM8B,SAAS,MAAMhC,MAAMyB;IAC3BvB,WAAW;IAEX,iFAAiF;IACjF,IAAI+B,MAAMC,OAAO,CAACF,WAAW,CAAE,CAAA,YAAYA,MAAK,GAAI;QAClD,OAAO;YAACG,QAAQ,EAAE;QAAA;IACpB;IAEA,MAAMC,QAAsB,EAAE;IAC9B,KAAK,MAAMC,SAASL,OAAOM,MAAM,CAAE;QACjC,IAAID,MAAME,IAAI,KAAK,SAAS;YAC1B;QACF;QAEAH,MAAMI,IAAI,CAAC;YACTC,SAASC,OAAOC,OAAO,CAACN,MAAMI,OAAO,EAAEG,GAAG,CAAC,CAAC,CAACC,aAAaC,YAAY;gBACpE,MAAMC,WAAWF,YAAYG,UAAU,CAAC,YACpCH,YAAYI,KAAK,CAAC,SAASC,MAAM,IACjCL;gBAEJ,OAAO;oBACLM,MAAMpD,KAAKqD,UAAU,CAACL,YAAYhD,KAAKsD,QAAQ,CAACzC,KAAKmC,YAAYA;oBACjEO,gBAAgBR,YAAYQ,cAAc;oBAC1CC,gBAAgBT,YAAYS,cAAc;gBAC5C;YACF;YACAJ,MAAMd,MAAMc,IAAI;QAClB;IACF;IAEA,OAAO;QAAChB,QAAQC;IAAK;AACvB"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/actions/build/renderDocument.ts"],"sourcesContent":["import {ux} from '@oclif/core'\nimport {tsxWorkerTask} from '@sanity/cli-core'\n\nimport {buildDebug} from './buildDebug.js'\n\ninterface DocumentProps {\n basePath: string\n\n css?: string[]\n entryPath?: string\n}\n\ninterface RenderDocumentOptions {\n studioRootPath: string\n\n importMap?: {\n imports?: Record<string, string>\n }\n isApp?: boolean\n props?: DocumentProps\n}\n\nconst hasWarnedAbout = new Set<string>()\n\ninterface RenderDocumentWorkerResult {\n type: 'error' | 'result' | 'warning'\n\n html?: string\n message?: string | string[]\n warnKey?: string\n}\n\nexport async function renderDocument(options: RenderDocumentOptions): Promise<string> {\n buildDebug('Starting worker thread for %s', import.meta.url)\n try {\n const msg = await tsxWorkerTask<RenderDocumentWorkerResult>(\n new URL(`renderDocument.worker.js`, import.meta.url),\n {\n name: 'renderDocument',\n rootPath: options.studioRootPath,\n workerData: {...options, shouldWarn: true},\n },\n )\n\n if (msg.type === 'warning') {\n if (msg.warnKey && hasWarnedAbout.has(msg.warnKey)) {\n return ''\n }\n\n if (Array.isArray(msg.message)) {\n for (const warning of msg.message) {\n ux.warn(warning)\n }\n } else if (msg.message) {\n ux.warn(msg.message)\n }\n\n if (msg.warnKey) {\n hasWarnedAbout.add(msg.warnKey)\n }\n return ''\n }\n\n if (msg.type === 'error') {\n buildDebug('Error from worker: %s', msg.message || 'Unknown error')\n throw new Error(\n Array.isArray(msg.message)\n ? msg.message.join('\\n')\n : msg.message || 'Document rendering worker stopped with an unknown error',\n )\n }\n\n if (msg.type === 'result') {\n if (!msg.html) {\n throw new Error('Document rendering worker stopped with an unknown error')\n }\n\n buildDebug('Document HTML rendered, %d bytes', msg.html.length)\n return msg.html\n }\n\n throw new Error('Unknown message type')\n } catch (err) {\n buildDebug('Worker errored: %s', err.message)\n throw err\n }\n}\n"],"names":["ux","tsxWorkerTask","buildDebug","hasWarnedAbout","Set","renderDocument","options","url","msg","URL","name","rootPath","studioRootPath","workerData","shouldWarn","type","warnKey","has","Array","isArray","message","warning","warn","add","Error","join","html","length","err"],"mappings":"AAAA,SA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OAAOnB,IAAIkB,IAAI;QACjB;QAEA,MAAM,IAAIF,MAAM;IAClB,EAAE,OAAOI,KAAK;QACZ1B,WAAW,sBAAsB0B,IAAIR,OAAO;QAC5C,MAAMQ;IACR;AACF"}
1
+ {"version":3,"sources":["../../../src/actions/build/renderDocument.ts"],"sourcesContent":["import {ux} from '@oclif/core'\nimport {tsxWorkerTask} from '@sanity/cli-core'\n\nimport {buildDebug} from './buildDebug.js'\n\ninterface DocumentProps {\n basePath: string\n\n css?: string[]\n entryPath?: string\n title?: string\n}\n\ninterface RenderDocumentOptions {\n studioRootPath: string\n\n importMap?: {\n imports?: Record<string, string>\n }\n isApp?: boolean\n props?: DocumentProps\n}\n\nconst hasWarnedAbout = new Set<string>()\n\ninterface RenderDocumentWorkerResult {\n type: 'error' | 'result' | 'warning'\n\n html?: string\n message?: string | string[]\n warnKey?: string\n}\n\nexport async function renderDocument(options: RenderDocumentOptions): Promise<string> {\n buildDebug('Starting worker thread for %s', import.meta.url)\n try {\n const msg = await tsxWorkerTask<RenderDocumentWorkerResult>(\n new URL(`renderDocument.worker.js`, import.meta.url),\n {\n name: 'renderDocument',\n rootPath: options.studioRootPath,\n workerData: {...options, shouldWarn: true},\n },\n )\n\n if (msg.type === 'warning') {\n if (msg.warnKey && hasWarnedAbout.has(msg.warnKey)) {\n return ''\n }\n\n if (Array.isArray(msg.message)) {\n for (const warning of msg.message) {\n ux.warn(warning)\n }\n } else if (msg.message) {\n ux.warn(msg.message)\n }\n\n if (msg.warnKey) {\n hasWarnedAbout.add(msg.warnKey)\n }\n return ''\n }\n\n if (msg.type === 'error') {\n buildDebug('Error from worker: %s', msg.message || 'Unknown error')\n throw new Error(\n Array.isArray(msg.message)\n ? msg.message.join('\\n')\n : msg.message || 'Document rendering worker stopped with an unknown error',\n )\n }\n\n if (msg.type === 'result') {\n if (!msg.html) {\n throw new Error('Document rendering worker stopped with an unknown error')\n }\n\n buildDebug('Document HTML rendered, %d bytes', msg.html.length)\n return msg.html\n }\n\n throw new Error('Unknown message type')\n } catch (err) {\n buildDebug('Worker errored: %s', err.message)\n throw err\n }\n}\n"],"names":["ux","tsxWorkerTask","buildDebug","hasWarnedAbout","Set","renderDocument","options","url","msg","URL","name","rootPath","studioRootPath","workerData","shouldWarn","type","warnKey","has","Array","isArray","message","warning","warn","add","Error","join","html","length","err"],"mappings":"AAAA,SAAQA,EAAE,QAAO,cAAa;AAC9B,SAAQC,aAAa,QAAO,mBAAkB;AAE9C,SAAQC,UAAU,QAAO,kBAAiB;AAoB1C,MAAMC,iBAAiB,IAAIC;AAU3B,OAAO,eAAeC,eAAeC,OAA8B;IACjEJ,WAAW,iCAAiC,YAAYK,GAAG;IAC3D,IAAI;QACF,MAAMC,MAAM,MAAMP,cAChB,IAAIQ,IAAI,CAAC,wBAAwB,CAAC,EAAE,YAAYF,GAAG,GACnD;YACEG,MAAM;YACNC,UAAUL,QAAQM,cAAc;YAChCC,YAAY;gBAAC,GAAGP,OAAO;gBAAEQ,YAAY;YAAI;QAC3C;QAGF,IAAIN,IAAIO,IAAI,KAAK,WAAW;YAC1B,IAAIP,IAAIQ,OAAO,IAAIb,eAAec,GAAG,CAACT,IAAIQ,OAAO,GAAG;gBAClD,OAAO;YACT;YAEA,IAAIE,MAAMC,OAAO,CAACX,IAAIY,OAAO,GAAG;gBAC9B,KAAK,MAAMC,WAAWb,IAAIY,OAAO,CAAE;oBACjCpB,GAAGsB,IAAI,CAACD;gBACV;YACF,OAAO,IAAIb,IAAIY,OAAO,EAAE;gBACtBpB,GAAGsB,IAAI,CAACd,IAAIY,OAAO;YACrB;YAEA,IAAIZ,IAAIQ,OAAO,EAAE;gBACfb,eAAeoB,GAAG,CAACf,IAAIQ,OAAO;YAChC;YACA,OAAO;QACT;QAEA,IAAIR,IAAIO,IAAI,KAAK,SAAS;YACxBb,WAAW,yBAAyBM,IAAIY,OAAO,IAAI;YACnD,MAAM,IAAII,MACRN,MAAMC,OAAO,CAACX,IAAIY,OAAO,IACrBZ,IAAIY,OAAO,CAACK,IAAI,CAAC,QACjBjB,IAAIY,OAAO,IAAI;QAEvB;QAEA,IAAIZ,IAAIO,IAAI,KAAK,UAAU;YACzB,IAAI,CAACP,IAAIkB,IAAI,EAAE;gBACb,MAAM,IAAIF,MAAM;YAClB;YAEAtB,WAAW,oCAAoCM,IAAIkB,IAAI,CAACC,MAAM;YAC9D,OAAOnB,IAAIkB,IAAI;QACjB;QAEA,MAAM,IAAIF,MAAM;IAClB,EAAE,OAAOI,KAAK;QACZ1B,WAAW,sBAAsB0B,IAAIR,OAAO;QAC5C,MAAMQ;IACR;AACF"}
@@ -10,7 +10,7 @@ const EMPTY_ARRAY = [];
10
10
  * This is the equivalent of DefaultDocument for non-studio apps.
11
11
  * @internal
12
12
  */ export function BasicDocument(props) {
13
- const { css = EMPTY_ARRAY, entryPath } = props;
13
+ const { css = EMPTY_ARRAY, entryPath, title } = props;
14
14
  return /*#__PURE__*/ _jsxs("html", {
15
15
  lang: "en",
16
16
  children: [
@@ -33,7 +33,7 @@ const EMPTY_ARRAY = [];
33
33
  }),
34
34
  /*#__PURE__*/ _jsx(Favicons, {}),
35
35
  /*#__PURE__*/ _jsx("title", {
36
- children: "Sanity CORE App"
36
+ children: title || 'Sanity App'
37
37
  }),
38
38
  /*#__PURE__*/ _jsx(GlobalErrorHandler, {}),
39
39
  css.map((href)=>/*#__PURE__*/ _jsx("link", {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/actions/build/renderDocumentWorker/components/BasicDocument.tsx"],"sourcesContent":["/**\n * App HTML Document, this is in the _internal package\n * to avoid importing styled-components from sanity package\n */\n\nimport {type JSX} from 'react'\n\nimport {Favicons} from './Favicons.js'\nimport {GlobalErrorHandler} from './GlobalErrorHandler.js'\nimport {NoJavascript} from './NoJavascript.js'\n\n/**\n * @internal\n */\ninterface BasicDocumentProps {\n entryPath: string\n\n // Currently unused, but kept for potential future use\n basePath?: string\n css?: string[]\n}\n\nconst EMPTY_ARRAY: never[] = []\n\n/**\n * This is the equivalent of DefaultDocument for non-studio apps.\n * @internal\n */\nexport function BasicDocument(props: BasicDocumentProps): JSX.Element {\n const {css = EMPTY_ARRAY, entryPath} = props\n\n return (\n <html lang=\"en\">\n <head>\n <meta charSet=\"utf-8\" />\n <meta content=\"width=device-width, initial-scale=1, viewport-fit=cover\" name=\"viewport\" />\n <meta content=\"noindex\" name=\"robots\" />\n <meta content=\"same-origin\" name=\"referrer\" />\n\n <Favicons />\n <title>Sanity CORE App</title>\n <GlobalErrorHandler />\n\n {css.map((href) => (\n <link href={href} key={href} rel=\"stylesheet\" />\n ))}\n </head>\n <body>\n <div id=\"root\" />\n <script src={entryPath} type=\"module\" />\n <NoJavascript />\n </body>\n </html>\n )\n}\n"],"names":["Favicons","GlobalErrorHandler","NoJavascript","EMPTY_ARRAY","BasicDocument","props","css","entryPath","html","lang","head","meta","charSet","content","name","title","map","href","link","rel","body","div","id","script","src","type"],"mappings":"AAAA;;;CAGC;AAID,SAAQA,QAAQ,QAAO,gBAAe;AACtC,SAAQC,kBAAkB,QAAO,0BAAyB;AAC1D,SAAQC,YAAY,QAAO,oBAAmB;AAa9C,MAAMC,cAAuB,EAAE;AAE/B;;;CAGC,GACD,OAAO,SAASC,cAAcC,KAAyB;IACrD,MAAM,EAACC,MAAMH,WAAW,EAAEI,SAAS,EAAC,GAAGF;IAEvC,qBACE,MAACG;QAAKC,MAAK;;0BACT,MAACC;;kCACC,KAACC;wBAAKC,SAAQ;;kCACd,KAACD;wBAAKE,SAAQ;wBAA0DC,MAAK;;kCAC7E,KAACH;wBAAKE,SAAQ;wBAAUC,MAAK;;kCAC7B,KAACH;wBAAKE,SAAQ;wBAAcC,MAAK;;kCAEjC,KAACd;kCACD,KAACe;kCAAM;;kCACP,KAACd;oBAEAK,IAAIU,GAAG,CAAC,CAACC,qBACR,KAACC;4BAAKD,MAAMA;4BAAiBE,KAAI;2BAAVF;;;0BAG3B,MAACG;;kCACC,KAACC;wBAAIC,IAAG;;kCACR,KAACC;wBAAOC,KAAKjB;wBAAWkB,MAAK;;kCAC7B,KAACvB;;;;;AAIT"}
1
+ {"version":3,"sources":["../../../../../src/actions/build/renderDocumentWorker/components/BasicDocument.tsx"],"sourcesContent":["/**\n * App HTML Document, this is in the _internal package\n * to avoid importing styled-components from sanity package\n */\n\nimport {type JSX} from 'react'\n\nimport {Favicons} from './Favicons.js'\nimport {GlobalErrorHandler} from './GlobalErrorHandler.js'\nimport {NoJavascript} from './NoJavascript.js'\n\n/**\n * @internal\n */\ninterface BasicDocumentProps {\n entryPath: string\n\n // Currently unused, but kept for potential future use\n basePath?: string\n\n css?: string[]\n title?: string\n}\n\nconst EMPTY_ARRAY: never[] = []\n\n/**\n * This is the equivalent of DefaultDocument for non-studio apps.\n * @internal\n */\nexport function BasicDocument(props: BasicDocumentProps): JSX.Element {\n const {css = EMPTY_ARRAY, entryPath, title} = props\n\n return (\n <html lang=\"en\">\n <head>\n <meta charSet=\"utf-8\" />\n <meta content=\"width=device-width, initial-scale=1, viewport-fit=cover\" name=\"viewport\" />\n <meta content=\"noindex\" name=\"robots\" />\n <meta content=\"same-origin\" name=\"referrer\" />\n\n <Favicons />\n <title>{title || 'Sanity App'}</title>\n <GlobalErrorHandler />\n\n {css.map((href) => (\n <link href={href} key={href} rel=\"stylesheet\" />\n ))}\n </head>\n <body>\n <div id=\"root\" />\n <script src={entryPath} type=\"module\" />\n <NoJavascript />\n </body>\n </html>\n )\n}\n"],"names":["Favicons","GlobalErrorHandler","NoJavascript","EMPTY_ARRAY","BasicDocument","props","css","entryPath","title","html","lang","head","meta","charSet","content","name","map","href","link","rel","body","div","id","script","src","type"],"mappings":"AAAA;;;CAGC;AAID,SAAQA,QAAQ,QAAO,gBAAe;AACtC,SAAQC,kBAAkB,QAAO,0BAAyB;AAC1D,SAAQC,YAAY,QAAO,oBAAmB;AAe9C,MAAMC,cAAuB,EAAE;AAE/B;;;CAGC,GACD,OAAO,SAASC,cAAcC,KAAyB;IACrD,MAAM,EAACC,MAAMH,WAAW,EAAEI,SAAS,EAAEC,KAAK,EAAC,GAAGH;IAE9C,qBACE,MAACI;QAAKC,MAAK;;0BACT,MAACC;;kCACC,KAACC;wBAAKC,SAAQ;;kCACd,KAACD;wBAAKE,SAAQ;wBAA0DC,MAAK;;kCAC7E,KAACH;wBAAKE,SAAQ;wBAAUC,MAAK;;kCAC7B,KAACH;wBAAKE,SAAQ;wBAAcC,MAAK;;kCAEjC,KAACf;kCACD,KAACQ;kCAAOA,SAAS;;kCACjB,KAACP;oBAEAK,IAAIU,GAAG,CAAC,CAACC,qBACR,KAACC;4BAAKD,MAAMA;4BAAiBE,KAAI;2BAAVF;;;0BAG3B,MAACG;;kCACC,KAACC;wBAAIC,IAAG;;kCACR,KAACC;wBAAOC,KAAKjB;wBAAWkB,MAAK;;kCAC7B,KAACvB;;;;;AAIT"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/actions/build/renderDocumentWorker/types.ts"],"sourcesContent":["/**\n * @internal\n */\nexport interface DocumentProps {\n basePath: string\n\n css?: string[]\n entryPath?: string\n}\n"],"names":[],"mappings":"AAAA;;CAEC,GACD,WAKC"}
1
+ {"version":3,"sources":["../../../../src/actions/build/renderDocumentWorker/types.ts"],"sourcesContent":["/**\n * @internal\n */\nexport interface DocumentProps {\n basePath: string\n\n css?: string[]\n entryPath?: string\n title?: string\n}\n"],"names":[],"mappings":"AAAA;;CAEC,GACD,WAMC"}
@@ -17,7 +17,7 @@ import { renderDocument } from './renderDocument.js';
17
17
  * @returns A watcher instance if watch is enabled, undefined otherwise
18
18
  * @internal
19
19
  */ export async function writeSanityRuntime(options) {
20
- const { basePath, cwd, entry, isApp, reactStrictMode, watch } = options;
20
+ const { appTitle, basePath, cwd, entry, isApp, reactStrictMode, watch } = options;
21
21
  const runtimeDir = path.join(cwd, '.sanity', 'runtime');
22
22
  buildDebug('Making runtime directory');
23
23
  await fs.mkdir(runtimeDir, {
@@ -29,7 +29,8 @@ import { renderDocument } from './renderDocument.js';
29
29
  isApp,
30
30
  props: {
31
31
  basePath: basePath || '/',
32
- entryPath: `/${toForwardSlashes(path.relative(cwd, path.join(runtimeDir, 'app.js')))}`
32
+ entryPath: `/${toForwardSlashes(path.relative(cwd, path.join(runtimeDir, 'app.js')))}`,
33
+ title: appTitle
33
34
  },
34
35
  studioRootPath: cwd
35
36
  })));
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/actions/build/writeSanityRuntime.ts"],"sourcesContent":["import fs from 'node:fs/promises'\nimport path from 'node:path'\n\nimport {tryFindStudioConfigPath} from '@sanity/cli-core'\nimport {watch as chokidarWatch, type FSWatcher} from 'chokidar'\n\nimport {toForwardSlashes} from '../../util/toForwardSlashes.js'\nimport {buildDebug} from './buildDebug.js'\nimport {decorateIndexWithAutoGeneratedWarning} from './decorateIndexWithAutoGeneratedWarning.js'\nimport {decorateIndexWithBridgeScript} from './decorateIndexWithBridgeScript.js'\nimport {getEntryModule} from './getEntryModule.js'\nimport {getPossibleDocumentComponentLocations} from './getPossibleDocumentComponentLocations.js'\nimport {renderDocument} from './renderDocument.js'\n\ninterface RuntimeOptions {\n cwd: string\n reactStrictMode: boolean\n watch: boolean\n\n basePath?: string\n entry?: string\n isApp?: boolean\n}\n\n/**\n * Generates the `.sanity/runtime` directory, and optionally watches for custom\n * document files, rebuilding when they change\n *\n * @param options - Current working directory (Sanity root dir), and whether or not to watch\n * @returns A watcher instance if watch is enabled, undefined otherwise\n * @internal\n */\nexport async function writeSanityRuntime(options: RuntimeOptions): Promise<FSWatcher | undefined> {\n const {basePath, cwd, entry, isApp, reactStrictMode, watch} = options\n const runtimeDir = path.join(cwd, '.sanity', 'runtime')\n\n buildDebug('Making runtime directory')\n await fs.mkdir(runtimeDir, {recursive: true})\n\n async function renderAndWriteDocument() {\n buildDebug('Rendering document template')\n const indexHtml = decorateIndexWithBridgeScript(\n decorateIndexWithAutoGeneratedWarning(\n await renderDocument({\n isApp,\n props: {\n basePath: basePath || '/',\n entryPath: `/${toForwardSlashes(path.relative(cwd, path.join(runtimeDir, 'app.js')))}`,\n },\n studioRootPath: cwd,\n }),\n ),\n )\n\n buildDebug('Writing index.html to runtime directory')\n await fs.writeFile(path.join(runtimeDir, 'index.html'), indexHtml)\n }\n\n let watcher: FSWatcher | undefined\n\n if (watch) {\n watcher = chokidarWatch(getPossibleDocumentComponentLocations(cwd)).on('all', () =>\n renderAndWriteDocument(),\n )\n }\n\n await renderAndWriteDocument()\n\n buildDebug('Writing app.js to runtime directory')\n let relativeConfigLocation: string | null = null\n if (!isApp) {\n const studioConfigPath = await tryFindStudioConfigPath(cwd)\n relativeConfigLocation = studioConfigPath\n ? toForwardSlashes(path.relative(runtimeDir, studioConfigPath))\n : null\n }\n\n const relativeEntry = toForwardSlashes(\n path.relative(runtimeDir, path.resolve(cwd, entry || './src/App')),\n )\n const appJsContent = getEntryModule({\n basePath,\n entry: relativeEntry,\n isApp,\n reactStrictMode,\n relativeConfigLocation,\n })\n await fs.writeFile(path.join(runtimeDir, 'app.js'), appJsContent)\n\n return watcher\n}\n"],"names":["fs","path","tryFindStudioConfigPath","watch","chokidarWatch","toForwardSlashes","buildDebug","decorateIndexWithAutoGeneratedWarning","decorateIndexWithBridgeScript","getEntryModule","getPossibleDocumentComponentLocations","renderDocument","writeSanityRuntime","options","basePath","cwd","entry","isApp","reactStrictMode","runtimeDir","join","mkdir","recursive","renderAndWriteDocument","indexHtml","props","entryPath","relative","studioRootPath","writeFile","watcher","on","relativeConfigLocation","studioConfigPath","relativeEntry","resolve","appJsContent"],"mappings":"AAAA,OAAOA,QAAQ,mBAAkB;AACjC,OAAOC,UAAU,YAAW;AAE5B,SAAQC,uBAAuB,QAAO,mBAAkB;AACxD,SAAQC,SAASC,aAAa,QAAuB,WAAU;AAE/D,SAAQC,gBAAgB,QAAO,iCAAgC;AAC/D,SAAQC,UAAU,QAAO,kBAAiB;AAC1C,SAAQC,qCAAqC,QAAO,6CAA4C;AAChG,SAAQC,6BAA6B,QAAO,qCAAoC;AAChF,SAAQC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,KAAKmB,IAAI,CAACD,YAAY,WAAWiB;IAEpD,OAAON;AACT"}
1
+ {"version":3,"sources":["../../../src/actions/build/writeSanityRuntime.ts"],"sourcesContent":["import fs from 'node:fs/promises'\nimport path from 'node:path'\n\nimport {tryFindStudioConfigPath} from '@sanity/cli-core'\nimport {watch as chokidarWatch, type FSWatcher} from 'chokidar'\n\nimport {toForwardSlashes} from '../../util/toForwardSlashes.js'\nimport {buildDebug} from './buildDebug.js'\nimport {decorateIndexWithAutoGeneratedWarning} from './decorateIndexWithAutoGeneratedWarning.js'\nimport {decorateIndexWithBridgeScript} from './decorateIndexWithBridgeScript.js'\nimport {getEntryModule} from './getEntryModule.js'\nimport {getPossibleDocumentComponentLocations} from './getPossibleDocumentComponentLocations.js'\nimport {renderDocument} from './renderDocument.js'\n\ninterface RuntimeOptions {\n cwd: string\n reactStrictMode: boolean\n watch: boolean\n\n appTitle?: string\n basePath?: string\n entry?: string\n isApp?: boolean\n}\n\n/**\n * Generates the `.sanity/runtime` directory, and optionally watches for custom\n * document files, rebuilding when they change\n *\n * @param options - Current working directory (Sanity root dir), and whether or not to watch\n * @returns A watcher instance if watch is enabled, undefined otherwise\n * @internal\n */\nexport async function writeSanityRuntime(options: RuntimeOptions): Promise<FSWatcher | undefined> {\n const {appTitle, basePath, cwd, entry, isApp, reactStrictMode, watch} = options\n const runtimeDir = path.join(cwd, '.sanity', 'runtime')\n\n buildDebug('Making runtime directory')\n await fs.mkdir(runtimeDir, {recursive: true})\n\n async function renderAndWriteDocument() {\n buildDebug('Rendering document template')\n const indexHtml = decorateIndexWithBridgeScript(\n decorateIndexWithAutoGeneratedWarning(\n await renderDocument({\n isApp,\n props: {\n basePath: basePath || '/',\n entryPath: `/${toForwardSlashes(path.relative(cwd, path.join(runtimeDir, 'app.js')))}`,\n title: appTitle,\n },\n studioRootPath: cwd,\n }),\n ),\n )\n\n buildDebug('Writing index.html to runtime directory')\n await fs.writeFile(path.join(runtimeDir, 'index.html'), indexHtml)\n }\n\n let watcher: FSWatcher | undefined\n\n if (watch) {\n watcher = chokidarWatch(getPossibleDocumentComponentLocations(cwd)).on('all', () =>\n renderAndWriteDocument(),\n )\n }\n\n await renderAndWriteDocument()\n\n buildDebug('Writing app.js to runtime directory')\n let relativeConfigLocation: string | null = null\n if (!isApp) {\n const studioConfigPath = await tryFindStudioConfigPath(cwd)\n relativeConfigLocation = studioConfigPath\n ? toForwardSlashes(path.relative(runtimeDir, studioConfigPath))\n : null\n }\n\n const relativeEntry = toForwardSlashes(\n path.relative(runtimeDir, path.resolve(cwd, entry || './src/App')),\n )\n const appJsContent = getEntryModule({\n basePath,\n entry: relativeEntry,\n isApp,\n reactStrictMode,\n relativeConfigLocation,\n })\n await fs.writeFile(path.join(runtimeDir, 'app.js'), appJsContent)\n\n return watcher\n}\n"],"names":["fs","path","tryFindStudioConfigPath","watch","chokidarWatch","toForwardSlashes","buildDebug","decorateIndexWithAutoGeneratedWarning","decorateIndexWithBridgeScript","getEntryModule","getPossibleDocumentComponentLocations","renderDocument","writeSanityRuntime","options","appTitle","basePath","cwd","entry","isApp","reactStrictMode","runtimeDir","join","mkdir","recursive","renderAndWriteDocument","indexHtml","props","entryPath","relative","title","studioRootPath","writeFile","watcher","on","relativeConfigLocation","studioConfigPath","relativeEntry","resolve","appJsContent"],"mappings":"AAAA,OAAOA,QAAQ,mBAAkB;AACjC,OAAOC,UAAU,YAAW;AAE5B,SAAQC,uBAAuB,QAAO,mBAAkB;AACxD,SAAQC,SAASC,aAAa,QAAuB,WAAU;AAE/D,SAAQC,gBAAgB,QAAO,iCAAgC;AAC/D,SAAQC,UAAU,QAAO,kBAAiB;AAC1C,SAAQC,qCAAqC,QAAO,6CAA4C;AAChG,SAAQC,6BAA6B,QAAO,qCAAoC;AAChF,SAAQC,cAAc,QAAO,sBAAqB;AAClD,SAAQC,qCAAqC,QAAO,6CAA4C;AAChG,SAAQC,cAAc,QAAO,sBAAqB;AAalD;;;;;;;CAOC,GACD,OAAO,eAAeC,mB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