@sanity/cli 6.6.0 → 6.7.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 (183) hide show
  1. package/README.md +12 -4
  2. package/dist/actions/auth/login/login.js +4 -1
  3. package/dist/actions/auth/login/login.js.map +1 -1
  4. package/dist/actions/build/buildApp.js +4 -5
  5. package/dist/actions/build/buildApp.js.map +1 -1
  6. package/dist/actions/build/buildStaticFiles.js +12 -4
  7. package/dist/actions/build/buildStaticFiles.js.map +1 -1
  8. package/dist/actions/build/buildStudio.js +6 -14
  9. package/dist/actions/build/buildStudio.js.map +1 -1
  10. package/dist/actions/build/{getStudioEnvironmentVariables.js → getEnvironmentVariables.js} +15 -19
  11. package/dist/actions/build/getEnvironmentVariables.js.map +1 -0
  12. package/dist/actions/deploy/deployStudio.js +1 -2
  13. package/dist/actions/deploy/deployStudio.js.map +1 -1
  14. package/dist/actions/deploy/deployStudioSchemasAndManifests.js +1 -2
  15. package/dist/actions/deploy/deployStudioSchemasAndManifests.js.map +1 -1
  16. package/dist/actions/deploy/deployStudioSchemasAndManifests.worker.js +1 -1
  17. package/dist/actions/deploy/deployStudioSchemasAndManifests.worker.js.map +1 -1
  18. package/dist/actions/dev/startStudioDevServer.js +1 -1
  19. package/dist/actions/dev/startStudioDevServer.js.map +1 -1
  20. package/dist/actions/documents/validateDocuments.worker.js +1 -2
  21. package/dist/actions/documents/validateDocuments.worker.js.map +1 -1
  22. package/dist/actions/graphql/SchemaError.js +1 -1
  23. package/dist/actions/graphql/SchemaError.js.map +1 -1
  24. package/dist/actions/init/initAction.js +32 -1
  25. package/dist/actions/init/initAction.js.map +1 -1
  26. package/dist/actions/init/scaffoldTemplate.js +32 -18
  27. package/dist/actions/init/scaffoldTemplate.js.map +1 -1
  28. package/dist/actions/init/templates/index.js +2 -0
  29. package/dist/actions/init/templates/index.js.map +1 -1
  30. package/dist/actions/init/templates/pageBuilder.js +32 -0
  31. package/dist/actions/init/templates/pageBuilder.js.map +1 -0
  32. package/dist/actions/init/types.js +2 -1
  33. package/dist/actions/init/types.js.map +1 -1
  34. package/dist/actions/manifest/extractManifest.js +1 -1
  35. package/dist/actions/manifest/extractManifest.js.map +1 -1
  36. package/dist/actions/manifest/extractManifest.worker.js +1 -1
  37. package/dist/actions/manifest/extractManifest.worker.js.map +1 -1
  38. package/dist/actions/mcp/editorConfigs.js +51 -11
  39. package/dist/actions/mcp/editorConfigs.js.map +1 -1
  40. package/dist/actions/mcp/promptForMCPSetup.js +16 -11
  41. package/dist/actions/mcp/promptForMCPSetup.js.map +1 -1
  42. package/dist/actions/mcp/setupMCP.js +180 -61
  43. package/dist/actions/mcp/setupMCP.js.map +1 -1
  44. package/dist/actions/mcp/types.js.map +1 -1
  45. package/dist/actions/schema/deploySchemas.js +1 -1
  46. package/dist/actions/schema/deploySchemas.js.map +1 -1
  47. package/dist/actions/schema/extractSanityWorkspace.worker.js +1 -1
  48. package/dist/actions/schema/extractSanityWorkspace.worker.js.map +1 -1
  49. package/dist/actions/schema/extractSchema.js +1 -4
  50. package/dist/actions/schema/extractSchema.js.map +1 -1
  51. package/dist/actions/schema/extractSchemaWatcher.js +1 -4
  52. package/dist/actions/schema/extractSchemaWatcher.js.map +1 -1
  53. package/dist/actions/schema/getExtractOptions.js +8 -18
  54. package/dist/actions/schema/getExtractOptions.js.map +1 -1
  55. package/dist/actions/schema/types.js +0 -6
  56. package/dist/actions/schema/types.js.map +1 -1
  57. package/dist/actions/schema/validateAction.js +1 -1
  58. package/dist/actions/schema/validateAction.js.map +1 -1
  59. package/dist/actions/schema/validateSchema.worker.js +1 -2
  60. package/dist/actions/schema/validateSchema.worker.js.map +1 -1
  61. package/dist/actions/schema/watchExtractSchema.js +1 -1
  62. package/dist/actions/schema/watchExtractSchema.js.map +1 -1
  63. package/dist/actions/skills/readSkillState.js +54 -0
  64. package/dist/actions/skills/readSkillState.js.map +1 -0
  65. package/dist/actions/skills/setupSkills.js +73 -0
  66. package/dist/actions/skills/setupSkills.js.map +1 -0
  67. package/dist/commands/build.js +9 -22
  68. package/dist/commands/build.js.map +1 -1
  69. package/dist/commands/cors/add.js +5 -5
  70. package/dist/commands/cors/add.js.map +1 -1
  71. package/dist/commands/datasets/export.js +9 -0
  72. package/dist/commands/datasets/export.js.map +1 -1
  73. package/dist/commands/docs/read.js +33 -12
  74. package/dist/commands/docs/read.js.map +1 -1
  75. package/dist/commands/init.js +12 -1
  76. package/dist/commands/init.js.map +1 -1
  77. package/dist/commands/manifest/extract.js +1 -2
  78. package/dist/commands/manifest/extract.js.map +1 -1
  79. package/dist/commands/mcp/configure.js +2 -1
  80. package/dist/commands/mcp/configure.js.map +1 -1
  81. package/dist/commands/schemas/deploy.js +1 -2
  82. package/dist/commands/schemas/deploy.js.map +1 -1
  83. package/dist/exports/_internal.d.ts +2 -1
  84. package/dist/exports/_internal.js +1 -1
  85. package/dist/exports/_internal.js.map +1 -1
  86. package/dist/server/devServer.js +25 -4
  87. package/dist/server/devServer.js.map +1 -1
  88. package/dist/server/previewServer.js +1 -1
  89. package/dist/server/previewServer.js.map +1 -1
  90. package/dist/services/mcp.js +1 -1
  91. package/dist/services/mcp.js.map +1 -1
  92. package/dist/telemetry/init.telemetry.js.map +1 -1
  93. package/oclif.manifest.json +134 -118
  94. package/package.json +15 -16
  95. package/templates/page-builder/README.md +9 -0
  96. package/templates/page-builder/schemaTypes/hero.js +31 -0
  97. package/templates/page-builder/schemaTypes/index.js +19 -0
  98. package/templates/page-builder/static/.gitkeep +0 -0
  99. package/dist/actions/build/buildDebug.js +0 -4
  100. package/dist/actions/build/buildDebug.js.map +0 -1
  101. package/dist/actions/build/buildVendorDependencies.js +0 -149
  102. package/dist/actions/build/buildVendorDependencies.js.map +0 -1
  103. package/dist/actions/build/checkStudioDependencyVersions.js +0 -155
  104. package/dist/actions/build/checkStudioDependencyVersions.js.map +0 -1
  105. package/dist/actions/build/createExternalFromImportMap.js +0 -11
  106. package/dist/actions/build/createExternalFromImportMap.js.map +0 -1
  107. package/dist/actions/build/decorateIndexWithAutoGeneratedWarning.js +0 -13
  108. package/dist/actions/build/decorateIndexWithAutoGeneratedWarning.js.map +0 -1
  109. package/dist/actions/build/decorateIndexWithBridgeScript.js +0 -17
  110. package/dist/actions/build/decorateIndexWithBridgeScript.js.map +0 -1
  111. package/dist/actions/build/decorateIndexWithStagingScript.js +0 -16
  112. package/dist/actions/build/decorateIndexWithStagingScript.js.map +0 -1
  113. package/dist/actions/build/getAppEnvVars.js +0 -9
  114. package/dist/actions/build/getAppEnvVars.js.map +0 -1
  115. package/dist/actions/build/getEntryModule.js +0 -46
  116. package/dist/actions/build/getEntryModule.js.map +0 -1
  117. package/dist/actions/build/getPossibleDocumentComponentLocations.js +0 -11
  118. package/dist/actions/build/getPossibleDocumentComponentLocations.js.map +0 -1
  119. package/dist/actions/build/getStudioEnvVars.js +0 -9
  120. package/dist/actions/build/getStudioEnvVars.js.map +0 -1
  121. package/dist/actions/build/getStudioEnvironmentVariables.js.map +0 -1
  122. package/dist/actions/build/getViteConfig.js +0 -219
  123. package/dist/actions/build/getViteConfig.js.map +0 -1
  124. package/dist/actions/build/normalizeBasePath.js +0 -9
  125. package/dist/actions/build/normalizeBasePath.js.map +0 -1
  126. package/dist/actions/build/renderDocument.js +0 -50
  127. package/dist/actions/build/renderDocument.js.map +0 -1
  128. package/dist/actions/build/renderDocument.worker.js +0 -9
  129. package/dist/actions/build/renderDocument.worker.js.map +0 -1
  130. package/dist/actions/build/renderDocumentWorker/addTimestampImportMapScriptToHtml.js +0 -79
  131. package/dist/actions/build/renderDocumentWorker/addTimestampImportMapScriptToHtml.js.map +0 -1
  132. package/dist/actions/build/renderDocumentWorker/components/BasicDocument.js +0 -61
  133. package/dist/actions/build/renderDocumentWorker/components/BasicDocument.js.map +0 -1
  134. package/dist/actions/build/renderDocumentWorker/components/DefaultDocument.js +0 -165
  135. package/dist/actions/build/renderDocumentWorker/components/DefaultDocument.js.map +0 -1
  136. package/dist/actions/build/renderDocumentWorker/components/Favicons.js +0 -28
  137. package/dist/actions/build/renderDocumentWorker/components/Favicons.js.map +0 -1
  138. package/dist/actions/build/renderDocumentWorker/components/GlobalErrorHandler.js +0 -178
  139. package/dist/actions/build/renderDocumentWorker/components/GlobalErrorHandler.js.map +0 -1
  140. package/dist/actions/build/renderDocumentWorker/components/NoJavascript.js +0 -51
  141. package/dist/actions/build/renderDocumentWorker/components/NoJavascript.js.map +0 -1
  142. package/dist/actions/build/renderDocumentWorker/getDocumentComponent.js +0 -41
  143. package/dist/actions/build/renderDocumentWorker/getDocumentComponent.js.map +0 -1
  144. package/dist/actions/build/renderDocumentWorker/getDocumentHtml.js +0 -55
  145. package/dist/actions/build/renderDocumentWorker/getDocumentHtml.js.map +0 -1
  146. package/dist/actions/build/renderDocumentWorker/renderDocumentWorker.js +0 -31
  147. package/dist/actions/build/renderDocumentWorker/renderDocumentWorker.js.map +0 -1
  148. package/dist/actions/build/renderDocumentWorker/tryLoadDocumentComponent.js +0 -30
  149. package/dist/actions/build/renderDocumentWorker/tryLoadDocumentComponent.js.map +0 -1
  150. package/dist/actions/build/renderDocumentWorker/types.js +0 -5
  151. package/dist/actions/build/renderDocumentWorker/types.js.map +0 -1
  152. package/dist/actions/build/writeSanityRuntime.js +0 -64
  153. package/dist/actions/build/writeSanityRuntime.js.map +0 -1
  154. package/dist/actions/docs/normalizeDocsPath.js +0 -15
  155. package/dist/actions/docs/normalizeDocsPath.js.map +0 -1
  156. package/dist/actions/schema/extractSanitySchema.worker.js +0 -33
  157. package/dist/actions/schema/extractSanitySchema.worker.js.map +0 -1
  158. package/dist/actions/schema/formatSchemaValidation.js +0 -78
  159. package/dist/actions/schema/formatSchemaValidation.js.map +0 -1
  160. package/dist/actions/schema/matchSchemaPattern.js +0 -22
  161. package/dist/actions/schema/matchSchemaPattern.js.map +0 -1
  162. package/dist/actions/schema/runSchemaExtraction.js +0 -39
  163. package/dist/actions/schema/runSchemaExtraction.js.map +0 -1
  164. package/dist/actions/schema/utils/SchemaExtractionError.js +0 -10
  165. package/dist/actions/schema/utils/SchemaExtractionError.js.map +0 -1
  166. package/dist/actions/schema/utils/extractValidationFromSchemaError.js +0 -12
  167. package/dist/actions/schema/utils/extractValidationFromSchemaError.js.map +0 -1
  168. package/dist/constants.js +0 -8
  169. package/dist/constants.js.map +0 -1
  170. package/dist/server/vite/plugin-sanity-build-entries.js +0 -67
  171. package/dist/server/vite/plugin-sanity-build-entries.js.map +0 -1
  172. package/dist/server/vite/plugin-sanity-favicons.js +0 -72
  173. package/dist/server/vite/plugin-sanity-favicons.js.map +0 -1
  174. package/dist/server/vite/plugin-sanity-runtime-rewrite.js +0 -18
  175. package/dist/server/vite/plugin-sanity-runtime-rewrite.js.map +0 -1
  176. package/dist/server/vite/plugin-schema-extraction.js +0 -201
  177. package/dist/server/vite/plugin-schema-extraction.js.map +0 -1
  178. package/dist/telemetry/build.telemetry.js +0 -13
  179. package/dist/telemetry/build.telemetry.js.map +0 -1
  180. package/dist/telemetry/extractSchema.telemetry.js +0 -18
  181. package/dist/telemetry/extractSchema.telemetry.js.map +0 -1
  182. package/dist/util/getWorkspace.js +0 -18
  183. package/dist/util/getWorkspace.js.map +0 -1
package/README.md CHANGED
@@ -408,8 +408,8 @@ FLAGS
408
408
  DESCRIPTION
409
409
  Destroy a remote Stack deployment and its resources
410
410
 
411
- Permanently removes the remote Stack and all its provisioned resources. Your local Blueprint files remain untouched,
412
- allowing you to redeploy later with 'blueprints init' + 'blueprints deploy'.
411
+ Permanently removes the remote Stack and all its provisioned resources. Your Blueprint manifest and resource files
412
+ remain intact; "stackId" is unset in your local config.
413
413
 
414
414
  This is a destructive operation. You will be prompted to confirm unless --force is specified.
415
415
 
@@ -529,9 +529,17 @@ EXAMPLES
529
529
 
530
530
  $ sanity blueprints init --blueprint-type <json|js|ts>
531
531
 
532
- $ sanity blueprints init --blueprint-type <json|js|ts> --project-id <projectId> --stack-id <stackId>
532
+ $ sanity blueprints init --organization-id <organizationId>
533
533
 
534
- $ sanity blueprints init --blueprint-type <json|js|ts> --stack-name <stackName>
534
+ $ sanity blueprints init --project-id <projectId>
535
+
536
+ $ sanity blueprints init --stack-name <newStackName>
537
+
538
+ $ sanity blueprints init --stack-id <existingStackId>
539
+
540
+ $ sanity blueprints init new-stack --type <json|js|ts> --org <organizationId> --name <newStackName>
541
+
542
+ $ sanity blueprints init old-stack --type <json|js|ts> --project-id <projectId> --stack-id <existingStackId>
535
543
  ```
536
544
 
537
545
  ## `sanity blueprints logs`
@@ -56,7 +56,10 @@ const debug = subdebug('login');
56
56
  const shouldLaunchBrowser = canLaunchBrowser() && options.open !== false;
57
57
  const actionText = shouldLaunchBrowser ? 'Opening browser at' : 'Please open a browser at';
58
58
  output.log(`\n${actionText} ${loginUrl.href}\n`);
59
- const spin = spinner('Waiting for browser login to complete... Press Ctrl + C to cancel').start();
59
+ const spin = spinner({
60
+ discardStdin: false,
61
+ text: 'Waiting for browser login to complete... Press Ctrl + C to cancel'
62
+ }).start();
60
63
  if (shouldLaunchBrowser) {
61
64
  open(loginUrl.href);
62
65
  }
@@ -1 +1 @@
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 {isHttpError} from '@sanity/client'\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'\nimport {isSanityApiToken, validateToken} from './validateToken.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 token?: string\n}\n\n/**\n * Trigger the authentication flow for the CLI.\n *\n * NOTE: Without a token option, this uses terminal prompts and will not work for\n * 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\n const trace = telemetry.trace(LoginTrace)\n trace.start()\n\n if (typeof options.token === 'string') {\n try {\n const authToken = await validateToken(options.token)\n await storeAuthToken(authToken, previousToken, output)\n trace.complete()\n } catch (err: unknown) {\n trace.error(err as Error)\n throw err\n }\n return\n }\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 await storeAuthToken(authToken, previousToken, output)\n\n trace.complete()\n}\n\nasync function storeAuthToken(\n authToken: string,\n previousToken: string | undefined,\n output: Output,\n) {\n setCliUserConfig('authToken', authToken)\n getUserConfig().delete('telemetryConsent')\n\n // If we had a session previously, attempt to clear it\n if (previousToken && previousToken !== authToken) {\n await invalidateAuthToken(previousToken, output)\n }\n}\n\nasync function invalidateAuthToken(token: string, output: Output) {\n try {\n if (await isSanityApiToken(token)) return\n } catch (err) {\n if (isHttpError(err) && err.statusCode === 401) return\n }\n\n try {\n await logout(token)\n } catch (err) {\n if (!isHttpError(err) || err.statusCode !== 401) {\n output.warn('Failed to invalidate previous session')\n }\n }\n}\n"],"names":["getCliToken","getUserConfig","setCliUserConfig","subdebug","spinner","isHttpError","open","logout","LoginTrace","canLaunchBrowser","startServerForTokenCallback","getProvider","isSanityApiToken","validateToken","debug","login","options","output","telemetry","previousToken","trace","start","token","authToken","storeAuthToken","complete","err","error","provider","experimental","orgSlug","sso","specifiedProvider","ssoProvider","log","name","step","undefined","Error","loginUrl","server","tokenPromise","url","shouldLaunchBrowser","actionText","href","spin","stop","Promise","resolve","close","delete","invalidateAuthToken","statusCode","warn"],"mappings":"AAAA,SAEEA,WAAW,EACXC,aAAa,EAEbC,gBAAgB,EAChBC,QAAQ,QACH,mBAAkB;AACzB,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,SAAQC,WAAW,QAAO,iBAAgB;AAC1C,OAAOC,UAAU,OAAM;AAEvB,SAAQC,MAAM,QAAO,4BAA2B;AAChD,SAAQC,UAAU,QAAO,wCAAuC;AAChE,SAAQC,gBAAgB,QAAO,oCAAmC;AAClE,SAAQC,2BAA2B,QAAO,mBAAkB;AAC5D,SAAQC,WAAW,QAAO,mBAAkB;AAC5C,SAAQC,gBAAgB,EAAEC,aAAa,QAAO,qBAAoB;AAElE,MAAMC,QAAQX,SAAS;AAevB;;;;;;;;;;CAUC,GACD,OAAO,eAAeY,MAAMC,OAAqB;IAC/C,MAAM,EAACC,MAAM,EAAEC,SAAS,EAAC,GAAGF;IAC5B,MAAMG,gBAAgB,MAAMnB;IAE5B,MAAMoB,QAAQF,UAAUE,KAAK,CAACZ;IAC9BY,MAAMC,KAAK;IAEX,IAAI,OAAOL,QAAQM,KAAK,KAAK,UAAU;QACrC,IAAI;YACF,MAAMC,Y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AAMzB,eAAeD,WAAWJ,eAAeF;IAE/CG,MAAMK,QAAQ;AAChB;AAEA,eAAeD,eACbD,SAAiB,EACjBJ,aAAiC,EACjCF,MAAc;IAEdf,iBAAiB,aAAaqB;IAC9BtB,gBAAgBkD,MAAM,CAAC;IAEvB,sDAAsD;IACtD,IAAIhC,iBAAiBA,kBAAkBI,WAAW;QAChD,MAAM6B,oBAAoBjC,eAAeF;IAC3C;AACF;AAEA,eAAemC,oBAAoB9B,KAAa,EAAEL,MAAc;IAC9D,IAAI;QACF,IAAI,MAAML,iBAAiBU,QAAQ;IACrC,EAAE,OAAOI,KAAK;QACZ,IAAIrB,YAAYqB,QAAQA,IAAI2B,UAAU,KAAK,KAAK;IAClD;IAEA,IAAI;QACF,MAAM9C,OAAOe;IACf,EAAE,OAAOI,KAAK;QACZ,IAAI,CAACrB,YAAYqB,QAAQA,IAAI2B,UAAU,KAAK,KAAK;YAC/CpC,OAAOqC,IAAI,CAAC;QACd;IACF;AACF"}
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 {isHttpError} from '@sanity/client'\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'\nimport {isSanityApiToken, validateToken} from './validateToken.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 token?: string\n}\n\n/**\n * Trigger the authentication flow for the CLI.\n *\n * NOTE: Without a token option, this uses terminal prompts and will not work for\n * 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\n const trace = telemetry.trace(LoginTrace)\n trace.start()\n\n if (typeof options.token === 'string') {\n try {\n const authToken = await validateToken(options.token)\n await storeAuthToken(authToken, previousToken, output)\n trace.complete()\n } catch (err: unknown) {\n trace.error(err as Error)\n throw err\n }\n return\n }\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({\n discardStdin: false, // dont swallow ctrl-c\n text: 'Waiting for browser login to complete... Press Ctrl + C to cancel',\n }).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 await storeAuthToken(authToken, previousToken, output)\n\n trace.complete()\n}\n\nasync function storeAuthToken(\n authToken: string,\n previousToken: string | undefined,\n output: Output,\n) {\n setCliUserConfig('authToken', authToken)\n getUserConfig().delete('telemetryConsent')\n\n // If we had a session previously, attempt to clear it\n if (previousToken && previousToken !== authToken) {\n await invalidateAuthToken(previousToken, output)\n }\n}\n\nasync function invalidateAuthToken(token: string, output: Output) {\n try {\n if (await isSanityApiToken(token)) return\n } catch (err) {\n if (isHttpError(err) && err.statusCode === 401) return\n }\n\n try {\n await logout(token)\n } catch (err) {\n if (!isHttpError(err) || err.statusCode !== 401) {\n output.warn('Failed to invalidate previous session')\n }\n }\n}\n"],"names":["getCliToken","getUserConfig","setCliUserConfig","subdebug","spinner","isHttpError","open","logout","LoginTrace","canLaunchBrowser","startServerForTokenCallback","getProvider","isSanityApiToken","validateToken","debug","login","options","output","telemetry","previousToken","trace","start","token","authToken","storeAuthToken","complete","err","error","provider","experimental","orgSlug","sso","specifiedProvider","ssoProvider","log","name","step","undefined","Error","loginUrl","server","tokenPromise","url","shouldLaunchBrowser","actionText","href","spin","discardStdin","text","stop","Promise","resolve","close","delete","invalidateAuthToken","statusCode","warn"],"mappings":"AAAA,SAEEA,WAAW,EACXC,aAAa,EAEbC,gBAAgB,EAChBC,QAAQ,QACH,mBAAkB;AACzB,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,SAAQC,WAAW,QAAO,iBAAgB;AAC1C,OAAOC,UAAU,OAAM;AAEvB,SAAQC,MAAM,QAAO,4BAA2B;AAChD,SAAQC,UAAU,QAAO,wCAAuC;AAChE,SAAQC,gBAAgB,QAAO,oCAAmC;AAClE,SAAQC,2BAA2B,QAAO,mBAAkB;AAC5D,SAAQC,WAAW,QAAO,mBAAkB;AAC5C,SAAQC,gBAAgB,EAAEC,aAAa,QAAO,qBAAoB;AAElE,MAAMC,QAAQX,SAAS;AAevB;;;;;;;;;;CAUC,GACD,OAAO,eAAeY,MAAMC,OAAqB;IAC/C,MAAM,EAACC,MAAM,EAAEC,SAAS,EAAC,GAAGF;IAC5B,MAAMG,gBAAgB,MAAMnB;IAE5B,MAAMoB,QAAQF,UAAUE,KAAK,CAACZ;IAC9BY,MAAMC,KAAK;IAEX,IAAI,OAAOL,QAAQM,KAAK,KAAK,UAAU;QACrC,IAAI;YACF,MAAMC,YAAY,MAAMV,cAAcG,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IAEA,MAAM3B,eAAeD,WAAWJ,eAAeF;IAE/CG,MAAMK,QAAQ;AAChB;AAEA,eAAeD,eACbD,SAAiB,EACjBJ,aAAiC,EACjCF,MAAc;IAEdf,iBAAiB,aAAaqB;IAC9BtB,gBAAgBoD,MAAM,CAAC;IAEvB,sDAAsD;IACtD,IAAIlC,iBAAiBA,kBAAkBI,WAAW;QAChD,MAAM+B,oBAAoBnC,eAAeF;IAC3C;AACF;AAEA,eAAeqC,oBAAoBhC,KAAa,EAAEL,MAAc;IAC9D,IAAI;QACF,IAAI,MAAML,iBAAiBU,QAAQ;IACrC,EAAE,OAAOI,KAAK;QACZ,IAAIrB,YAAYqB,QAAQA,IAAI6B,UAAU,KAAK,KAAK;IAClD;IAEA,IAAI;QACF,MAAMhD,OAAOe;IACf,EAAE,OAAOI,KAAK;QACZ,IAAI,CAACrB,YAAYqB,QAAQA,IAAI6B,UAAU,KAAK,KAAK;YAC/CtC,OAAOuC,IAAI,CAAC;QACd;IACF;AACF"}
@@ -1,20 +1,18 @@
1
1
  import { rm } from 'node:fs/promises';
2
2
  import path from 'node:path';
3
3
  import { styleText } from 'node:util';
4
+ import { AppBuildTrace, buildDebug, buildVendorDependencies } from '@sanity/cli-build/_internal/build';
4
5
  import { getCliTelemetry, getLocalPackageVersion, getTimer, isInteractive } from '@sanity/cli-core';
5
6
  import { confirm, logSymbols, spinner } from '@sanity/cli-core/ux';
6
7
  import { parse as semverParse } from 'semver';
7
- import { AppBuildTrace } from '../../telemetry/build.telemetry.js';
8
8
  import { getAppId } from '../../util/appId.js';
9
9
  import { compareDependencyVersions } from '../../util/compareDependencyVersions.js';
10
10
  import { formatModuleSizes, sortModulesBySize } from '../../util/moduleFormatUtils.js';
11
11
  import { warnAboutMissingAppId } from '../../util/warnAboutMissingAppId.js';
12
- import { buildDebug } from './buildDebug.js';
13
12
  import { buildStaticFiles } from './buildStaticFiles.js';
14
- import { buildVendorDependencies } from './buildVendorDependencies.js';
15
13
  import { determineBasePath } from './determineBasePath.js';
16
- import { getAppEnvVars } from './getAppEnvVars.js';
17
14
  import { getAutoUpdatesCssUrls, getAutoUpdatesImportMap } from './getAutoUpdatesImportMap.js';
15
+ import { getAppEnvironmentVariables } from './getEnvironmentVariables.js';
18
16
  import { handlePrereleaseVersions } from './handlePrereleaseVersions.js';
19
17
  /**
20
18
  * Build the Sanity app.
@@ -45,6 +43,7 @@ import { handlePrereleaseVersions } from './handlePrereleaseVersions.js';
45
43
  * Internal build app that avoids depending on flags for CLI config.
46
44
  * @param options - options for the build
47
45
  */ async function internalBuildApp(options) {
46
+ buildDebug(`Building app`);
48
47
  const { appId, determineBasePath, outDir, output, workDir } = options;
49
48
  let { autoUpdatesEnabled } = options;
50
49
  const unattendedMode = options.unattendedMode;
@@ -139,7 +138,7 @@ import { handlePrereleaseVersions } from './handlePrereleaseVersions.js';
139
138
  }
140
139
  }
141
140
  }
142
- const envVarKeys = getAppEnvVars();
141
+ const envVarKeys = Object.keys(getAppEnvironmentVariables());
143
142
  if (envVarKeys.length > 0) {
144
143
  output.log('\nIncluding the following environment variables as part of the JavaScript bundle:');
145
144
  for (const key of envVarKeys)output.log(`- ${key}`);
@@ -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 {\n type CliConfig,\n getCliTelemetry,\n getLocalPackageVersion,\n getTimer,\n isInteractive,\n type Output,\n UserViteConfig,\n} from '@sanity/cli-core'\nimport {confirm, logSymbols, spinner, type SpinnerInstance} from '@sanity/cli-core/ux'\nimport {parse as semverParse} from 'semver'\n\nimport {AppBuildTrace} from '../../telemetry/build.telemetry.js'\nimport {getAppId} from '../../util/appId.js'\nimport {compareDependencyVersions} from '../../util/compareDependencyVersions.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 {getAutoUpdatesCssUrls, getAutoUpdatesImportMap} from './getAutoUpdatesImportMap.js'\nimport {handlePrereleaseVersions} from './handlePrereleaseVersions.js'\nimport {type BuildOptions} from './types.js'\n\ninterface InternalBuildOptions {\n appId: string | undefined\n appTitle: string | undefined\n autoUpdatesEnabled: boolean\n calledFromDeploy: boolean | undefined\n determineBasePath: () => string\n entry: string | undefined\n minify: boolean\n outDir: string | undefined\n output: Output\n reactCompiler: CliConfig['reactCompiler']\n schemaExtraction: CliConfig['schemaExtraction']\n sourceMap: boolean\n stats: boolean\n unattendedMode: boolean\n vite: UserViteConfig | undefined\n workDir: string\n}\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\n await internalBuildApp({\n appId: getAppId(cliConfig),\n appTitle: cliConfig && 'app' in cliConfig ? cliConfig.app?.title : undefined,\n autoUpdatesEnabled: options.autoUpdatesEnabled,\n calledFromDeploy: options.calledFromDeploy,\n determineBasePath: () => determineBasePath(cliConfig, 'app', output),\n entry: cliConfig && 'app' in cliConfig ? cliConfig.app?.entry : undefined,\n minify: flags.minify,\n outDir,\n output,\n reactCompiler: cliConfig && 'reactCompiler' in cliConfig ? cliConfig.reactCompiler : undefined,\n schemaExtraction: cliConfig?.schemaExtraction,\n sourceMap: Boolean(flags['source-maps']),\n stats: flags.stats,\n unattendedMode: flags.yes,\n vite: cliConfig.vite,\n workDir,\n })\n}\n\n/**\n * Internal build app that avoids depending on flags for CLI config.\n * @param options - options for the build\n */\nasync function internalBuildApp(options: InternalBuildOptions): Promise<void> {\n const {appId, determineBasePath, outDir, output, workDir} = options\n let {autoUpdatesEnabled} = options\n const unattendedMode = options.unattendedMode\n const timer = getTimer()\n\n const defaultOutputDir = path.resolve(path.join(workDir, 'dist'))\n const outputDir = path.resolve(outDir || defaultOutputDir)\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 let autoUpdatesCssUrls: string[] = []\n\n if (autoUpdatesEnabled) {\n // Get the clean version without build metadata: https://semver.org/#spec-item-10\n const cleanSDKVersion = semverParse(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 = semverParse(installedSanityVersion)?.version\n\n const autoUpdatedPackages = [\n {name: '@sanity/sdk', version: cleanSDKVersion},\n {name: '@sanity/sdk-react', version: cleanSDKVersion},\n ...(cleanSanityVersion\n ? [{cssFile: 'index.css', name: 'sanity' as const, version: cleanSanityVersion}]\n : []),\n ]\n autoUpdatesImports = getAutoUpdatesImportMap(autoUpdatedPackages, {appId})\n autoUpdatesCssUrls = getAutoUpdatesCssUrls(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 autoUpdatesCssUrls = []\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 const basePath = determineBasePath()\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: options.appTitle,\n autoUpdatesCssUrls: autoUpdatesCssUrls.length > 0 ? autoUpdatesCssUrls : undefined,\n basePath,\n cwd: workDir,\n entry: options.entry,\n importMap,\n isApp: true,\n minify: options.minify,\n outputDir,\n reactCompiler: options.reactCompiler,\n schemaExtraction: options.schemaExtraction,\n sourceMap: options.sourceMap,\n vite: options.vite,\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 (options.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","getLocalPackageVersion","getTimer","isInteractive","confirm","logSymbols","spinner","parse","semverParse","AppBuildTrace","getAppId","compareDependencyVersions","formatModuleSizes","sortModulesBySize","warnAboutMissingAppId","buildDebug","buildStaticFiles","buildVendorDependencies","determineBasePath","getAppEnvVars","getAutoUpdatesCssUrls","getAutoUpdatesImportMap","handlePrereleaseVersions","buildApp","options","cliConfig","flags","outDir","output","workDir","internalBuildApp","appId","appTitle","app","title","undefined","autoUpdatesEnabled","calledFromDeploy","entry","minify","reactCompiler","schemaExtraction","sourceMap","Boolean","stats","unattendedMode","yes","vite","timer","defaultOutputDir","resolve","join","outputDir","installedSdkVersion","installedSanityVersion","error","exit","autoUpdatesImports","autoUpdatesCssUrls","cleanSDKVersion","version","cleanSanityVersion","autoUpdatedPackages","name","cssFile","log","info","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","outputSize","chunks","flatMap","chunk","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}
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 {AppBuildTrace, buildDebug, buildVendorDependencies} from '@sanity/cli-build/_internal/build'\nimport {\n type CliConfig,\n getCliTelemetry,\n getLocalPackageVersion,\n getTimer,\n isInteractive,\n type Output,\n UserViteConfig,\n} from '@sanity/cli-core'\nimport {confirm, logSymbols, spinner, type SpinnerInstance} from '@sanity/cli-core/ux'\nimport {parse as semverParse} from 'semver'\n\nimport {getAppId} from '../../util/appId.js'\nimport {compareDependencyVersions} from '../../util/compareDependencyVersions.js'\nimport {formatModuleSizes, sortModulesBySize} from '../../util/moduleFormatUtils.js'\nimport {warnAboutMissingAppId} from '../../util/warnAboutMissingAppId.js'\nimport {buildStaticFiles} from './buildStaticFiles.js'\nimport {determineBasePath} from './determineBasePath.js'\nimport {getAutoUpdatesCssUrls, getAutoUpdatesImportMap} from './getAutoUpdatesImportMap.js'\nimport {getAppEnvironmentVariables} from './getEnvironmentVariables.js'\nimport {handlePrereleaseVersions} from './handlePrereleaseVersions.js'\nimport {type BuildOptions} from './types.js'\n\ninterface InternalBuildOptions {\n appId: string | undefined\n appTitle: string | undefined\n autoUpdatesEnabled: boolean\n calledFromDeploy: boolean | undefined\n determineBasePath: () => string\n entry: string | undefined\n minify: boolean\n outDir: string | undefined\n output: Output\n reactCompiler: CliConfig['reactCompiler']\n schemaExtraction: CliConfig['schemaExtraction']\n sourceMap: boolean\n stats: boolean\n unattendedMode: boolean\n vite: UserViteConfig | undefined\n workDir: string\n}\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\n await internalBuildApp({\n appId: getAppId(cliConfig),\n appTitle: cliConfig && 'app' in cliConfig ? cliConfig.app?.title : undefined,\n autoUpdatesEnabled: options.autoUpdatesEnabled,\n calledFromDeploy: options.calledFromDeploy,\n determineBasePath: () => determineBasePath(cliConfig, 'app', output),\n entry: cliConfig && 'app' in cliConfig ? cliConfig.app?.entry : undefined,\n minify: flags.minify,\n outDir,\n output,\n reactCompiler: cliConfig && 'reactCompiler' in cliConfig ? cliConfig.reactCompiler : undefined,\n schemaExtraction: cliConfig?.schemaExtraction,\n sourceMap: Boolean(flags['source-maps']),\n stats: flags.stats,\n unattendedMode: flags.yes,\n vite: cliConfig.vite,\n workDir,\n })\n}\n\n/**\n * Internal build app that avoids depending on flags for CLI config.\n * @param options - options for the build\n */\nasync function internalBuildApp(options: InternalBuildOptions): Promise<void> {\n buildDebug(`Building app`)\n\n const {appId, determineBasePath, outDir, output, workDir} = options\n let {autoUpdatesEnabled} = options\n const unattendedMode = options.unattendedMode\n\n const timer = getTimer()\n\n const defaultOutputDir = path.resolve(path.join(workDir, 'dist'))\n const outputDir = path.resolve(outDir || defaultOutputDir)\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 let autoUpdatesCssUrls: string[] = []\n\n if (autoUpdatesEnabled) {\n // Get the clean version without build metadata: https://semver.org/#spec-item-10\n const cleanSDKVersion = semverParse(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 = semverParse(installedSanityVersion)?.version\n\n const autoUpdatedPackages = [\n {name: '@sanity/sdk', version: cleanSDKVersion},\n {name: '@sanity/sdk-react', version: cleanSDKVersion},\n ...(cleanSanityVersion\n ? [{cssFile: 'index.css', name: 'sanity' as const, version: cleanSanityVersion}]\n : []),\n ]\n autoUpdatesImports = getAutoUpdatesImportMap(autoUpdatedPackages, {appId})\n autoUpdatesCssUrls = getAutoUpdatesCssUrls(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 autoUpdatesCssUrls = []\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 = Object.keys(getAppEnvironmentVariables())\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 const basePath = determineBasePath()\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: options.appTitle,\n autoUpdatesCssUrls: autoUpdatesCssUrls.length > 0 ? autoUpdatesCssUrls : undefined,\n basePath,\n cwd: workDir,\n entry: options.entry,\n importMap,\n isApp: true,\n minify: options.minify,\n outputDir,\n reactCompiler: options.reactCompiler,\n schemaExtraction: options.schemaExtraction,\n sourceMap: options.sourceMap,\n vite: options.vite,\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 (options.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","AppBuildTrace","buildDebug","buildVendorDependencies","getCliTelemetry","getLocalPackageVersion","getTimer","isInteractive","confirm","logSymbols","spinner","parse","semverParse","getAppId","compareDependencyVersions","formatModuleSizes","sortModulesBySize","warnAboutMissingAppId","buildStaticFiles","determineBasePath","getAutoUpdatesCssUrls","getAutoUpdatesImportMap","getAppEnvironmentVariables","handlePrereleaseVersions","buildApp","options","cliConfig","flags","outDir","output","workDir","internalBuildApp","appId","appTitle","app","title","undefined","autoUpdatesEnabled","calledFromDeploy","entry","minify","reactCompiler","schemaExtraction","sourceMap","Boolean","stats","unattendedMode","yes","vite","timer","defaultOutputDir","resolve","join","outputDir","installedSdkVersion","installedSanityVersion","error","exit","autoUpdatesImports","autoUpdatesCssUrls","cleanSDKVersion","version","cleanSanityVersion","autoUpdatedPackages","name","cssFile","log","info","appType","mismatched","unresolvedPrerelease","length","versionMismatchWarning","map","mod","pkg","installed","remote","shouldContinue","default","message","warn","envVarKeys","Object","keys","key","shouldClean","basePath","spin","start","force","recursive","cleanDuration","end","text","toFixed","succeed","trace","importMap","imports","cwd","isApp","bundle","outputSize","chunks","flatMap","chunk","modules","renderedLength","reduce","sum","n","buildDuration","slice","complete","fail","Error","String"],"mappings":"AAAA,SAAQA,EAAE,QAAO,mBAAkB;AACnC,OAAOC,UAAU,YAAW;AAC5B,SAAQC,SAAS,QAAO,YAAW;AAEnC,SAAQC,aAAa,EAAEC,UAAU,EAAEC,uBAAuB,QAAO,oCAAmC;AACpG,SAEEC,eAAe,EACfC,sBAAsB,EACtBC,QAAQ,EACRC,aAAa,QAGR,mBAAkB;AACzB,SAAQC,OAAO,EAAEC,UAAU,EAAEC,OAAO,QAA6B,sBAAqB;AACtF,SAAQC,SAASC,WAAW,QAAO,SAAQ;AAE3C,SAAQC,QAAQ,QAAO,sBAAqB;AAC5C,SAAQC,yBAAyB,QAAO,0CAAyC;AACjF,SAAQC,iBAAiB,EAAEC,iBAAiB,QAAO,kCAAiC;AACpF,SAAQC,qBAAqB,QAAO,sCAAqC;AACzE,SAAQC,gBAAgB,QAAO,wBAAuB;AACtD,SAAQC,iBAAiB,QAAO,yBAAwB;AACxD,SAAQC,qBAAqB,EAAEC,uBAAuB,QAAO,+BAA8B;AAC3F,SAAQC,0BAA0B,QAAO,+BAA8B;AACvE,SAAQC,w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AAO,CAAC,GAAG,GAAG,CAAC;QACtEP,KAAKQ,OAAO;QAEZ,IAAIvE,QAAQoB,KAAK,EAAE;YACjBhB,OAAOqC,GAAG,CAAC;YACXrC,OAAOqC,GAAG,CAACnD,kBAAkBC,kBAAkBsF,OAAOE,MAAM,EAAES,KAAK,CAAC,GAAG;QACzE;QAEAhB,MAAMiB,QAAQ;IAChB,EAAE,OAAO1D,OAAO;QACdgC,KAAK2B,IAAI;QACTlB,MAAMzC,KAAK,CAACA;QACZ,MAAMwB,UAAUxB,iBAAiB4D,QAAQ5D,MAAMwB,OAAO,GAAGqC,OAAO7D;QAChEtD,WAAW,CAAC,kCAAkC,CAAC,EAAE;YAACsD;QAAK;QACvD3B,OAAO2B,KAAK,CAAC,CAAC,oCAAoC,EAAEwB,SAAS,EAAE;YAACvB,MAAM;QAAC;IACzE;AACF"}
@@ -1,9 +1,7 @@
1
1
  import path from 'node:path';
2
- import { copyDir, writeFavicons } from '@sanity/cli-build/_internal';
2
+ import { buildDebug, copyDir, extendViteConfigWithUserConfig, finalizeViteConfig, getViteConfig, writeFavicons, writeSanityRuntime } from '@sanity/cli-build/_internal/build';
3
3
  import { build } from 'vite';
4
- import { buildDebug } from './buildDebug.js';
5
- import { extendViteConfigWithUserConfig, finalizeViteConfig, getViteConfig } from './getViteConfig.js';
6
- import { writeSanityRuntime } from './writeSanityRuntime.js';
4
+ import { getAppEnvironmentVariables, getStudioEnvironmentVariables } from './getEnvironmentVariables.js';
7
5
  /**
8
6
  * Builds static files
9
7
  *
@@ -20,12 +18,22 @@ import { writeSanityRuntime } from './writeSanityRuntime.js';
20
18
  reactStrictMode: false,
21
19
  watch: false
22
20
  });
21
+ function getEnvironmentVariables() {
22
+ return isApp ? getAppEnvironmentVariables({
23
+ jsonEncode: true,
24
+ prefix: 'process.env.'
25
+ }) : getStudioEnvironmentVariables({
26
+ jsonEncode: true,
27
+ prefix: 'process.env.'
28
+ });
29
+ }
23
30
  buildDebug('Resolving vite config');
24
31
  const mode = 'production';
25
32
  let viteConfig = await getViteConfig({
26
33
  autoUpdatesCssUrls,
27
34
  basePath,
28
35
  cwd,
36
+ getEnvironmentVariables,
29
37
  importMap,
30
38
  isApp,
31
39
  minify,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/actions/build/buildStaticFiles.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {copyDir, writeFavicons} from '@sanity/cli-build/_internal'\nimport {type CliConfig, type UserViteConfig} from '@sanity/cli-core'\nimport {type PluginOptions as ReactCompilerConfig} from 'babel-plugin-react-compiler'\nimport {build} from 'vite'\n\nimport {buildDebug} from './buildDebug.js'\nimport {extendViteConfigWithUserConfig, finalizeViteConfig, getViteConfig} from './getViteConfig.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 autoUpdatesCssUrls?: string[]\n entry?: string\n importMap?: {imports?: Record<string, string>}\n isApp?: boolean\n minify?: boolean\n profile?: boolean\n reactCompiler?: ReactCompilerConfig\n schemaExtraction?: CliConfig['schemaExtraction']\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 autoUpdatesCssUrls,\n basePath,\n cwd,\n entry,\n importMap,\n isApp,\n minify = true,\n outputDir,\n reactCompiler,\n schemaExtraction,\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 autoUpdatesCssUrls,\n basePath,\n cwd,\n importMap,\n isApp,\n minify,\n mode,\n outputDir,\n reactCompiler,\n schemaExtraction,\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","copyDir","writeFavicons","build","buildDebug","extendViteConfigWithUserConfig","finalizeViteConfig","getViteConfig","writeSanityRuntime","buildStaticFiles","options","appTitle","autoUpdatesCssUrls","basePath","cwd","entry","importMap","isApp","minify","outputDir","reactCompiler","schemaExtraction","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;AAE5B,SAAQC,OAAO,EAAEC,aAAa,QAAO,8BAA6B;AAGlE,SAAQC,KAAK,QAAO,OAAM;AAE1B,SAAQC,UAAU,QAAO,kBAAiB;AAC1C,SAAQC,8BAA8B,EAAEC,kBAAkB,EAAEC,aAAa,QAAO,qBAAoB;AACpG,SAAQC,kBAAkB,QAAO,0BAAyB;AA+B1D;;;;CAIC,GACD,OAAO,eAAeC,iBACpBC,OAA2B;IAE3B,MAAM,EACJC,QAAQ,EACRC,kBAAkB,EAClBC,QAAQ,EACRC,GAAG,EACHC,KAAK,EACLC,SAAS,EACTC,KAAK,EACLC,SAAS,IAAI,EACbC,SAAS,EACTC,aAAa,EACbC,gBAAgB,EAChBC,YAAY,KAAK,EACjBC,MAAMC,gBAAgB,EACvB,GAAGd;IAEJN,WAAW;IACX,MAAMI,mBAAmB;QACvBG;QACAE;QACAC;QACAC;QACAE;QACAQ,iBAAiB;QACjBC,OAAO;IACT;IAEAtB,WAAW;IACX,MAAMuB,OAAO;IACb,IAAIC,aAAa,MAAMrB,cAAc;QACnCK;QACAC;QACAC;QACAE;QACAC;QACAC;QACAS;QACAR;QACAC;QACAC;QACAC;IACF;IAEA,IAAIE,kBAAkB;QACpBI,aAAa,MAAMvB,+BACjB;YAACwB,SAAS;YAASF;QAAI,GACvBC,YACAJ;QAEFI,aAAa,MAAMtB,mBAAmBsB;IACxC;IAEA,MAAME,WAAW9B,KAAK+B,IAAI,CAACjB,KAAK;IAChC,oDAAoD;IACpDV,WAAW,CAAC,0BAA0B,EAAE0B,SAAS,cAAc,CAAC;IAChE,MAAME,aAAahC,KAAK+B,IAAI,CAACZ,WAAW;IACxC,MAAMlB,QAAQ6B,UAAUE;IAExB,4EAA4E;IAC5E5B,WAAW;IACX,MAAM6B,kBAAkB,GAAGpB,SAASqB,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC;IAChE,MAAMhC,cAAc+B,iBAAiBD;IAErC5B,WAAW;IACX,MAAM+B,SAAS,MAAMhC,MAAMyB;IAC3BxB,WAAW;IAEX,iFAAiF;IACjF,IAAIgC,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,MAAMtD,KAAKuD,UAAU,CAACL,YAAYlD,KAAKwD,QAAQ,CAAC1C,KAAKoC,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 {\n buildDebug,\n copyDir,\n extendViteConfigWithUserConfig,\n finalizeViteConfig,\n getViteConfig,\n writeFavicons,\n writeSanityRuntime,\n} from '@sanity/cli-build/_internal/build'\nimport {type CliConfig, type UserViteConfig} from '@sanity/cli-core'\nimport {type PluginOptions as ReactCompilerConfig} from 'babel-plugin-react-compiler'\nimport {build} from 'vite'\n\nimport {\n getAppEnvironmentVariables,\n getStudioEnvironmentVariables,\n} from './getEnvironmentVariables.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 autoUpdatesCssUrls?: string[]\n entry?: string\n importMap?: {imports?: Record<string, string>}\n isApp?: boolean\n minify?: boolean\n profile?: boolean\n reactCompiler?: ReactCompilerConfig\n schemaExtraction?: CliConfig['schemaExtraction']\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 autoUpdatesCssUrls,\n basePath,\n cwd,\n entry,\n importMap,\n isApp,\n minify = true,\n outputDir,\n reactCompiler,\n schemaExtraction,\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 function getEnvironmentVariables() {\n return isApp\n ? getAppEnvironmentVariables({jsonEncode: true, prefix: 'process.env.'})\n : getStudioEnvironmentVariables({jsonEncode: true, prefix: 'process.env.'})\n }\n\n buildDebug('Resolving vite config')\n const mode = 'production'\n let viteConfig = await getViteConfig({\n autoUpdatesCssUrls,\n basePath,\n cwd,\n getEnvironmentVariables,\n importMap,\n isApp,\n minify,\n mode,\n outputDir,\n reactCompiler,\n schemaExtraction,\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","buildDebug","copyDir","extendViteConfigWithUserConfig","finalizeViteConfig","getViteConfig","writeFavicons","writeSanityRuntime","build","getAppEnvironmentVariables","getStudioEnvironmentVariables","buildStaticFiles","options","appTitle","autoUpdatesCssUrls","basePath","cwd","entry","importMap","isApp","minify","outputDir","reactCompiler","schemaExtraction","sourceMap","vite","extendViteConfig","reactStrictMode","watch","getEnvironmentVariables","jsonEncode","prefix","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;AAE5B,SACEC,UAAU,EACVC,OAAO,EACPC,8BAA8B,EAC9BC,kBAAkB,EAClBC,aAAa,EACbC,aAAa,EACbC,kBAAkB,QACb,oCAAmC;AAG1C,SAAQC,KAAK,QAAO,OAAM;AAE1B,SACEC,0BAA0B,EAC1BC,6BAA6B,QACxB,+BAA8B;AA+BrC;;;;CAIC,GACD,OAAO,eAAeC,iBACpBC,OAA2B;IAE3B,MAAM,EAC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AAMC,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,MAAM3D,KAAK4D,UAAU,CAACL,YAAYvD,KAAK6D,QAAQ,CAAC7C,KAAKuC,YAAYA;oBACjEO,gBAAgBR,YAAYQ,cAAc;oBAC1CC,gBAAgBT,YAAYS,cAAc;gBAC5C;YACF;YACAJ,MAAMd,MAAMc,IAAI;QAClB;IACF;IAEA,OAAO;QAAChB,QAAQC;IAAK;AACvB"}
@@ -1,10 +1,10 @@
1
1
  import { rm } from 'node:fs/promises';
2
2
  import path from 'node:path';
3
3
  import { styleText } from 'node:util';
4
+ import { buildDebug, buildVendorDependencies, checkStudioDependencyVersions, StudioBuildTrace } from '@sanity/cli-build/_internal/build';
4
5
  import { getCliTelemetry, getLocalPackageVersion, getTimer, isInteractive } from '@sanity/cli-core';
5
6
  import { confirm, logSymbols, select, spinner } from '@sanity/cli-core/ux';
6
7
  import { parse as semverParse } from 'semver';
7
- import { StudioBuildTrace } from '../../telemetry/build.telemetry.js';
8
8
  import { getAppId } from '../../util/appId.js';
9
9
  import { compareDependencyVersions } from '../../util/compareDependencyVersions.js';
10
10
  import { determineIsApp } from '../../util/determineIsApp.js';
@@ -12,27 +12,18 @@ import { formatModuleSizes, sortModulesBySize } from '../../util/moduleFormatUti
12
12
  import { getPackageManagerChoice } from '../../util/packageManager/packageManagerChoice.js';
13
13
  import { upgradePackages } from '../../util/packageManager/upgradePackages.js';
14
14
  import { warnAboutMissingAppId } from '../../util/warnAboutMissingAppId.js';
15
- import { buildDebug } from './buildDebug.js';
16
15
  import { buildStaticFiles } from './buildStaticFiles.js';
17
- import { buildVendorDependencies } from './buildVendorDependencies.js';
18
16
  import { checkRequiredDependencies } from './checkRequiredDependencies.js';
19
- import { checkStudioDependencyVersions } from './checkStudioDependencyVersions.js';
20
17
  import { determineBasePath } from './determineBasePath.js';
21
18
  import { getAutoUpdatesCssUrls, getAutoUpdatesImportMap } from './getAutoUpdatesImportMap.js';
22
- import { getStudioEnvVars } from './getStudioEnvVars.js';
19
+ import { getStudioEnvironmentVariables } from './getEnvironmentVariables.js';
23
20
  import { handlePrereleaseVersions } from './handlePrereleaseVersions.js';
24
- import { shouldAutoUpdate } from './shouldAutoUpdate.js';
25
21
  /**
26
22
  * Build the Sanity Studio.
27
23
  *
28
24
  * @internal
29
25
  */ export async function buildStudio(options) {
30
26
  const { calledFromDeploy, cliConfig, flags, outDir, output, workDir } = options;
31
- const autoUpdatesEnabled = options.calledFromDeploy ? options.autoUpdatesEnabled : shouldAutoUpdate({
32
- cliConfig,
33
- flags,
34
- output
35
- });
36
27
  const upgradePkgs = async (options)=>{
37
28
  await upgradePackages({
38
29
  packageManager: (await getPackageManagerChoice(workDir, {
@@ -46,7 +37,7 @@ import { shouldAutoUpdate } from './shouldAutoUpdate.js';
46
37
  };
47
38
  await internalBuildStudio({
48
39
  appId: getAppId(cliConfig),
49
- autoUpdatesEnabled,
40
+ autoUpdatesEnabled: options.autoUpdatesEnabled,
50
41
  calledFromDeploy,
51
42
  determineBasePath: ()=>determineBasePath(cliConfig, 'studio', output),
52
43
  isApp: determineIsApp(cliConfig),
@@ -68,9 +59,9 @@ import { shouldAutoUpdate } from './shouldAutoUpdate.js';
68
59
  * Internal build studio that avoids depending on flags for CLI config.
69
60
  * @param options - options for the build
70
61
  */ async function internalBuildStudio(options) {
62
+ buildDebug(`Building studio`);
71
63
  const timer = getTimer();
72
64
  const { appId, determineBasePath, isApp, minify, outDir, output, projectId, reactCompiler, schemaExtraction, sourceMap, stats, unattendedMode, upgradePackages, vite, workDir } = options;
73
- let autoUpdatesEnabled = options.autoUpdatesEnabled;
74
65
  const defaultOutputDir = path.resolve(path.join(workDir, 'dist'));
75
66
  const outputDir = path.resolve(outDir || defaultOutputDir);
76
67
  await checkStudioDependencyVersions(workDir, output);
@@ -81,6 +72,7 @@ import { shouldAutoUpdate } from './shouldAutoUpdate.js';
81
72
  output,
82
73
  workDir
83
74
  });
75
+ let autoUpdatesEnabled = options.autoUpdatesEnabled;
84
76
  let autoUpdatesImports = {};
85
77
  let autoUpdatesCssUrls = [];
86
78
  if (autoUpdatesEnabled) {
@@ -190,7 +182,7 @@ import { shouldAutoUpdate } from './shouldAutoUpdate.js';
190
182
  }
191
183
  }
192
184
  }
193
- const envVarKeys = getStudioEnvVars();
185
+ const envVarKeys = Object.keys(getStudioEnvironmentVariables());
194
186
  if (envVarKeys.length > 0) {
195
187
  output.log('\nIncluding the following environment variables as part of the JavaScript bundle:');
196
188
  for (const key of envVarKeys){
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/actions/build/buildStudio.ts"],"sourcesContent":["import {rm} from 'node:fs/promises'\nimport path from 'node:path'\nimport {styleText} from 'node:util'\n\nimport {\n type CliConfig,\n getCliTelemetry,\n getLocalPackageVersion,\n getTimer,\n isInteractive,\n type Output,\n UserViteConfig,\n} from '@sanity/cli-core'\nimport {confirm, logSymbols, select, spinner, type SpinnerInstance} from '@sanity/cli-core/ux'\nimport {parse as semverParse} from 'semver'\n\nimport {StudioBuildTrace} from '../../telemetry/build.telemetry.js'\nimport {getAppId} from '../../util/appId.js'\nimport {compareDependencyVersions} from '../../util/compareDependencyVersions.js'\nimport {determineIsApp} from '../../util/determineIsApp.js'\nimport {formatModuleSizes, sortModulesBySize} from '../../util/moduleFormatUtils.js'\nimport {getPackageManagerChoice} from '../../util/packageManager/packageManagerChoice.js'\nimport {upgradePackages} from '../../util/packageManager/upgradePackages.js'\nimport {warnAboutMissingAppId} from '../../util/warnAboutMissingAppId.js'\nimport {buildDebug} from './buildDebug.js'\nimport {buildStaticFiles} from './buildStaticFiles.js'\nimport {buildVendorDependencies} from './buildVendorDependencies.js'\nimport {checkRequiredDependencies} from './checkRequiredDependencies.js'\nimport {checkStudioDependencyVersions} from './checkStudioDependencyVersions.js'\nimport {determineBasePath} from './determineBasePath.js'\nimport {getAutoUpdatesCssUrls, getAutoUpdatesImportMap} from './getAutoUpdatesImportMap.js'\nimport {getStudioEnvVars} from './getStudioEnvVars.js'\nimport {handlePrereleaseVersions} from './handlePrereleaseVersions.js'\nimport {shouldAutoUpdate} from './shouldAutoUpdate.js'\nimport {type BuildOptions} from './types.js'\n\ninterface InternalBuildOptions {\n appId: string | undefined\n autoUpdatesEnabled: boolean\n calledFromDeploy: boolean | undefined\n determineBasePath: () => string\n isApp: boolean\n minify: boolean\n outDir: string | undefined\n output: Output\n projectId: string | undefined\n reactCompiler: CliConfig['reactCompiler']\n schemaExtraction: CliConfig['schemaExtraction']\n sourceMap: boolean\n stats: boolean\n unattendedMode: boolean\n upgradePackages(options: {packages: [name: string, version: string][]}): Promise<void>\n vite: UserViteConfig | undefined\n workDir: string\n}\n\n/**\n * Build the Sanity Studio.\n *\n * @internal\n */\nexport async function buildStudio(options: BuildOptions): Promise<void> {\n const {calledFromDeploy, cliConfig, flags, outDir, output, workDir} = options\n\n const autoUpdatesEnabled = options.calledFromDeploy\n ? options.autoUpdatesEnabled\n : shouldAutoUpdate({cliConfig, flags, output})\n\n const upgradePkgs = async (options: {\n packages: [name: string, version: string][]\n }): Promise<void> => {\n await upgradePackages(\n {\n packageManager: (await getPackageManagerChoice(workDir, {interactive: false})).chosen,\n packages: options.packages,\n },\n {output, workDir},\n )\n }\n\n await internalBuildStudio({\n appId: getAppId(cliConfig),\n autoUpdatesEnabled,\n calledFromDeploy,\n determineBasePath: () => determineBasePath(cliConfig, 'studio', output),\n isApp: determineIsApp(cliConfig),\n minify: Boolean(flags.minify),\n outDir,\n output,\n projectId: cliConfig?.api?.projectId,\n reactCompiler: cliConfig.reactCompiler,\n schemaExtraction: cliConfig.schemaExtraction,\n sourceMap: Boolean(flags['source-maps']),\n stats: flags.stats,\n unattendedMode: Boolean(flags.yes),\n upgradePackages: upgradePkgs,\n vite: cliConfig.vite,\n workDir,\n })\n}\n\n/**\n * Internal build studio that avoids depending on flags for CLI config.\n * @param options - options for the build\n */\nasync function internalBuildStudio(options: InternalBuildOptions): Promise<void> {\n const timer = getTimer()\n const {\n appId,\n determineBasePath,\n isApp,\n minify,\n outDir,\n output,\n projectId,\n reactCompiler,\n schemaExtraction,\n sourceMap,\n stats,\n unattendedMode,\n upgradePackages,\n vite,\n workDir,\n } = options\n let autoUpdatesEnabled = options.autoUpdatesEnabled\n const defaultOutputDir = path.resolve(path.join(workDir, 'dist'))\n const outputDir = path.resolve(outDir || defaultOutputDir)\n\n await checkStudioDependencyVersions(workDir, output)\n\n // If the check resulted in a dependency install, the CLI command will be re-run,\n // thus we want to exit early\n const {installedSanityVersion} = await checkRequiredDependencies({\n isApp,\n output,\n workDir,\n })\n\n let autoUpdatesImports = {}\n let autoUpdatesCssUrls: string[] = []\n\n if (autoUpdatesEnabled) {\n // Get the clean version without build metadata: https://semver.org/#spec-item-10\n const cleanSanityVersion = semverParse(installedSanityVersion)?.version\n if (!cleanSanityVersion) {\n throw new Error(`Failed to parse installed Sanity version: ${installedSanityVersion}`)\n }\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: 'studio', output, projectId})\n }\n\n const installedVisionVersion = await getLocalPackageVersion('@sanity/vision', workDir)\n const cleanVisionVersion = installedVisionVersion\n ? semverParse(installedVisionVersion)?.version\n : undefined\n\n const sanityDependencies = [\n {cssFile: 'index.css', name: 'sanity', version: cleanSanityVersion},\n ...(cleanVisionVersion\n ? [{cssFile: 'index.css', name: '@sanity/vision' as const, version: cleanVisionVersion}]\n : [{name: '@sanity/vision' as const, version: cleanSanityVersion}]),\n ]\n autoUpdatesImports = getAutoUpdatesImportMap(sanityDependencies, {appId})\n\n autoUpdatesCssUrls = getAutoUpdatesCssUrls(sanityDependencies, {appId})\n\n // Check the versions\n const {mismatched, unresolvedPrerelease} = await compareDependencyVersions(\n sanityDependencies,\n workDir,\n {appId},\n )\n\n if (unresolvedPrerelease.length > 0) {\n await handlePrereleaseVersions({output, unattendedMode, unresolvedPrerelease})\n autoUpdatesImports = {}\n autoUpdatesCssUrls = []\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 choice = await select({\n choices: [\n {\n name: `Upgrade local versions (recommended). You will need to run the build command again`,\n value: 'upgrade',\n },\n {\n name: `Upgrade and proceed with build`,\n value: 'upgrade-and-proceed',\n },\n {\n name: `Continue anyway`,\n value: 'continue',\n },\n {name: 'Cancel', value: 'cancel'},\n ],\n default: 'upgrade',\n message: styleText(\n 'yellow',\n `${logSymbols.warning} ${versionMismatchWarning}\\n\\nDo you want to upgrade local versions before deploying?`,\n ),\n })\n\n if (choice === 'cancel') {\n output.error('Declined to continue with build', {exit: 1})\n return\n }\n\n if (choice === 'upgrade' || choice === 'upgrade-and-proceed') {\n await upgradePackages({\n packages: mismatched.map((res) => [res.pkg, res.remote]),\n })\n\n if (choice === 'upgrade') {\n return\n }\n }\n } else {\n // if non-interactive or unattended, just show the warning\n output.warn(versionMismatchWarning)\n }\n }\n }\n\n const envVarKeys = getStudioEnvVars()\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) {\n output.log(`- ${key}`)\n }\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 studio\n const basePath = determineBasePath()\n\n if (schemaExtraction?.enabled) {\n output.log(`${logSymbols.info} Building with schema extraction enabled`)\n }\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(`Build Sanity Studio`).start()\n\n const trace = getCliTelemetry().trace(StudioBuildTrace)\n trace.start()\n\n let importMap\n\n if (autoUpdatesEnabled) {\n importMap = {\n imports: {\n ...(await buildVendorDependencies({basePath, cwd: workDir, isApp: false, outputDir})),\n ...autoUpdatesImports,\n },\n }\n }\n\n try {\n timer.start('bundleStudio')\n\n const bundle = await buildStaticFiles({\n autoUpdatesCssUrls: autoUpdatesCssUrls.length > 0 ? autoUpdatesCssUrls : undefined,\n basePath,\n cwd: workDir,\n importMap,\n minify,\n outputDir,\n reactCompiler,\n schemaExtraction,\n sourceMap,\n vite,\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 Studio (${buildDuration.toFixed(0)}ms)`\n spin.succeed()\n\n trace.complete()\n if (stats) {\n output.log('\\nLargest module files:')\n output.log(formatModuleSizes(sortModulesBySize(bundle.chunks).slice(0, 15)))\n }\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 Studio`, {error})\n output.error(`Failed to build Sanity Studio: ${message}`, {exit: 1})\n }\n}\n"],"names":["rm","path","styleText","getCliTelemetry","getLocalPackageVersion","getTimer","isInteractive","confirm","logSymbols","select","spinner","parse","semverParse","StudioBuildTrace","getAppId","compareDependencyVersions","determineIsApp","formatModuleSizes","sortModulesBySize","getPackageManagerChoice","upgradePackages","warnAboutMissingAppId","buildDebug","buildStaticFiles","buildVendorDependencies","checkRequiredDependencies","checkStudioDependencyVersions","determineBasePath","getAutoUpdatesCssUrls","getAutoUpdatesImportMap","getStudioEnvVars","handlePrereleaseVersions","shouldAutoUpdate","buildStudio","options","calledFromDeploy","cliConfig","flags","outDir","output","workDir","autoUpdatesEnabled","upgradePkgs","packageManager","interactive","chosen","packages","internalBuildStudio","appId","isApp","minify","Boolean","projectId","api","reactCompiler","schemaExtraction","sourceMap","stats","unattendedMode","yes","vite","timer","defaultOutputDir","resolve","join","outputDir","installedSanityVersion","autoUpdatesImports","autoUpdatesCssUrls","cleanSanityVersion","version","Error","log","info","appType","installedVisionVersion","cleanVisionVersion","undefined","sanityDependencies","cssFile","name","mismatched","unresolvedPrerelease","length","versionMismatchWarning","map","mod","pkg","installed","remote","choice","choices","value","default","message","warning","error","exit","res","warn","envVarKeys","key","shouldClean","basePath","enabled","spin","start","force","recursive","cleanDuration","end","text","toFixed","succeed","trace","importMap","imports","cwd","bundle","outputSize","chunks","flatMap","chunk","modules","renderedLength","reduce","sum","n","buildDuration","complete","slice","fail","String"],"mappings":"AAAA,SAAQA,EAAE,QAAO,mBAAkB;AACnC,OAAOC,UAAU,YAAW;AAC5B,SAAQC,SAAS,QAAO,YAAW;AAEnC,SAEEC,eAAe,EACfC,sBAAsB,EACtBC,QAAQ,EACRC,aAAa,QAGR,mBAAkB;AACzB,SAAQC,OAAO,EAAEC,UAAU,EAAEC,MAAM,EAAEC,OAAO,QAA6B,sBAAqB;AAC9F,SAAQC,SAASC,WAAW,QAAO,SAAQ;AAE3C,SAAQC,gBAAgB,QAAO,qCAAoC;AACnE,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M,IAAI,GAAG,CAAC,qBAAqB,EAAEiB,cAAchB,OAAO,CAAC,GAAG,GAAG,CAAC;QACjEP,KAAKQ,OAAO;QAEZC,MAAMe,QAAQ;QACd,IAAIxE,OAAO;YACTlB,OAAOiC,GAAG,CAAC;YACXjC,OAAOiC,GAAG,CAACvD,kBAAkBC,kBAAkBoG,OAAOE,MAAM,EAAEU,KAAK,CAAC,GAAG;QACzE;IACF,EAAE,OAAOlC,OAAO;QACdS,KAAK0B,IAAI;QACTjB,MAAMlB,KAAK,CAACA;QACZ,MAAMF,UAAUE,iBAAiBzB,QAAQyB,MAAMF,OAAO,GAAGsC,OAAOpC;QAChE1E,WAAW,CAAC,6BAA6B,CAAC,EAAE;YAAC0E;QAAK;QAClDzD,OAAOyD,KAAK,CAAC,CAAC,+BAA+B,EAAEF,SAAS,EAAE;YAACG,MAAM;QAAC;IACpE;AACF"}
1
+ {"version":3,"sources":["../../../src/actions/build/buildStudio.ts"],"sourcesContent":["import {rm} from 'node:fs/promises'\nimport path from 'node:path'\nimport {styleText} from 'node:util'\n\nimport {\n buildDebug,\n buildVendorDependencies,\n checkStudioDependencyVersions,\n StudioBuildTrace,\n} from '@sanity/cli-build/_internal/build'\nimport {\n type CliConfig,\n getCliTelemetry,\n getLocalPackageVersion,\n getTimer,\n isInteractive,\n type Output,\n UserViteConfig,\n} from '@sanity/cli-core'\nimport {confirm, logSymbols, select, spinner, type SpinnerInstance} from '@sanity/cli-core/ux'\nimport {parse as semverParse} from 'semver'\n\nimport {getAppId} from '../../util/appId.js'\nimport {compareDependencyVersions} from '../../util/compareDependencyVersions.js'\nimport {determineIsApp} from '../../util/determineIsApp.js'\nimport {formatModuleSizes, sortModulesBySize} from '../../util/moduleFormatUtils.js'\nimport {getPackageManagerChoice} from '../../util/packageManager/packageManagerChoice.js'\nimport {upgradePackages} from '../../util/packageManager/upgradePackages.js'\nimport {warnAboutMissingAppId} from '../../util/warnAboutMissingAppId.js'\nimport {buildStaticFiles} from './buildStaticFiles.js'\nimport {checkRequiredDependencies} from './checkRequiredDependencies.js'\nimport {determineBasePath} from './determineBasePath.js'\nimport {getAutoUpdatesCssUrls, getAutoUpdatesImportMap} from './getAutoUpdatesImportMap.js'\nimport {getStudioEnvironmentVariables} from './getEnvironmentVariables.js'\nimport {handlePrereleaseVersions} from './handlePrereleaseVersions.js'\nimport {type BuildOptions} from './types.js'\n\ninterface InternalBuildOptions {\n appId: string | undefined\n autoUpdatesEnabled: boolean\n calledFromDeploy: boolean | undefined\n determineBasePath: () => string\n isApp: boolean\n minify: boolean\n outDir: string | undefined\n output: Output\n projectId: string | undefined\n reactCompiler: CliConfig['reactCompiler']\n schemaExtraction: CliConfig['schemaExtraction']\n sourceMap: boolean\n stats: boolean\n unattendedMode: boolean\n upgradePackages(options: {packages: [name: string, version: string][]}): Promise<void>\n vite: UserViteConfig | undefined\n workDir: string\n}\n\n/**\n * Build the Sanity Studio.\n *\n * @internal\n */\nexport async function buildStudio(options: BuildOptions): Promise<void> {\n const {calledFromDeploy, cliConfig, flags, outDir, output, workDir} = options\n\n const upgradePkgs = async (options: {\n packages: [name: string, version: string][]\n }): Promise<void> => {\n await upgradePackages(\n {\n packageManager: (await getPackageManagerChoice(workDir, {interactive: false})).chosen,\n packages: options.packages,\n },\n {output, workDir},\n )\n }\n\n await internalBuildStudio({\n appId: getAppId(cliConfig),\n autoUpdatesEnabled: options.autoUpdatesEnabled,\n calledFromDeploy,\n determineBasePath: () => determineBasePath(cliConfig, 'studio', output),\n isApp: determineIsApp(cliConfig),\n minify: Boolean(flags.minify),\n outDir,\n output,\n projectId: cliConfig?.api?.projectId,\n reactCompiler: cliConfig.reactCompiler,\n schemaExtraction: cliConfig.schemaExtraction,\n sourceMap: Boolean(flags['source-maps']),\n stats: flags.stats,\n unattendedMode: Boolean(flags.yes),\n upgradePackages: upgradePkgs,\n vite: cliConfig.vite,\n workDir,\n })\n}\n\n/**\n * Internal build studio that avoids depending on flags for CLI config.\n * @param options - options for the build\n */\nasync function internalBuildStudio(options: InternalBuildOptions): Promise<void> {\n buildDebug(`Building studio`)\n\n const timer = getTimer()\n const {\n appId,\n determineBasePath,\n isApp,\n minify,\n outDir,\n output,\n projectId,\n reactCompiler,\n schemaExtraction,\n sourceMap,\n stats,\n unattendedMode,\n upgradePackages,\n vite,\n workDir,\n } = options\n const defaultOutputDir = path.resolve(path.join(workDir, 'dist'))\n const outputDir = path.resolve(outDir || defaultOutputDir)\n\n await checkStudioDependencyVersions(workDir, output)\n\n // If the check resulted in a dependency install, the CLI command will be re-run,\n // thus we want to exit early\n const {installedSanityVersion} = await checkRequiredDependencies({\n isApp,\n output,\n workDir,\n })\n\n let autoUpdatesEnabled = options.autoUpdatesEnabled\n\n let autoUpdatesImports = {}\n let autoUpdatesCssUrls: string[] = []\n\n if (autoUpdatesEnabled) {\n // Get the clean version without build metadata: https://semver.org/#spec-item-10\n const cleanSanityVersion = semverParse(installedSanityVersion)?.version\n if (!cleanSanityVersion) {\n throw new Error(`Failed to parse installed Sanity version: ${installedSanityVersion}`)\n }\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: 'studio', output, projectId})\n }\n\n const installedVisionVersion = await getLocalPackageVersion('@sanity/vision', workDir)\n const cleanVisionVersion = installedVisionVersion\n ? semverParse(installedVisionVersion)?.version\n : undefined\n\n const sanityDependencies = [\n {cssFile: 'index.css', name: 'sanity', version: cleanSanityVersion},\n ...(cleanVisionVersion\n ? [{cssFile: 'index.css', name: '@sanity/vision' as const, version: cleanVisionVersion}]\n : [{name: '@sanity/vision' as const, version: cleanSanityVersion}]),\n ]\n autoUpdatesImports = getAutoUpdatesImportMap(sanityDependencies, {appId})\n\n autoUpdatesCssUrls = getAutoUpdatesCssUrls(sanityDependencies, {appId})\n\n // Check the versions\n const {mismatched, unresolvedPrerelease} = await compareDependencyVersions(\n sanityDependencies,\n workDir,\n {appId},\n )\n\n if (unresolvedPrerelease.length > 0) {\n await handlePrereleaseVersions({output, unattendedMode, unresolvedPrerelease})\n autoUpdatesImports = {}\n autoUpdatesCssUrls = []\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 choice = await select({\n choices: [\n {\n name: `Upgrade local versions (recommended). You will need to run the build command again`,\n value: 'upgrade',\n },\n {\n name: `Upgrade and proceed with build`,\n value: 'upgrade-and-proceed',\n },\n {\n name: `Continue anyway`,\n value: 'continue',\n },\n {name: 'Cancel', value: 'cancel'},\n ],\n default: 'upgrade',\n message: styleText(\n 'yellow',\n `${logSymbols.warning} ${versionMismatchWarning}\\n\\nDo you want to upgrade local versions before deploying?`,\n ),\n })\n\n if (choice === 'cancel') {\n output.error('Declined to continue with build', {exit: 1})\n return\n }\n\n if (choice === 'upgrade' || choice === 'upgrade-and-proceed') {\n await upgradePackages({\n packages: mismatched.map((res) => [res.pkg, res.remote]),\n })\n\n if (choice === 'upgrade') {\n return\n }\n }\n } else {\n // if non-interactive or unattended, just show the warning\n output.warn(versionMismatchWarning)\n }\n }\n }\n\n const envVarKeys = Object.keys(getStudioEnvironmentVariables())\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) {\n output.log(`- ${key}`)\n }\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 studio\n const basePath = determineBasePath()\n\n if (schemaExtraction?.enabled) {\n output.log(`${logSymbols.info} Building with schema extraction enabled`)\n }\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(`Build Sanity Studio`).start()\n\n const trace = getCliTelemetry().trace(StudioBuildTrace)\n trace.start()\n\n let importMap\n\n if (autoUpdatesEnabled) {\n importMap = {\n imports: {\n ...(await buildVendorDependencies({basePath, cwd: workDir, isApp: false, outputDir})),\n ...autoUpdatesImports,\n },\n }\n }\n\n try {\n timer.start('bundleStudio')\n\n const bundle = await buildStaticFiles({\n autoUpdatesCssUrls: autoUpdatesCssUrls.length > 0 ? autoUpdatesCssUrls : undefined,\n basePath,\n cwd: workDir,\n importMap,\n minify,\n outputDir,\n reactCompiler,\n schemaExtraction,\n sourceMap,\n vite,\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 Studio (${buildDuration.toFixed(0)}ms)`\n spin.succeed()\n\n trace.complete()\n if (stats) {\n output.log('\\nLargest module files:')\n output.log(formatModuleSizes(sortModulesBySize(bundle.chunks).slice(0, 15)))\n }\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 Studio`, {error})\n output.error(`Failed to build Sanity Studio: ${message}`, {exit: 1})\n }\n}\n"],"names":["rm","path","styleText","buildDebug","buildVendorDependencies","checkStudioDependencyVersions","StudioBuildTrace","getCliTelemetry","getLocalPackageVersion","getTimer","isInteractive","confirm","logSymbols","select","spinner","parse","semverParse","getAppId","compareDependencyVersions","determineIsApp","formatModuleSizes","sortModulesBySize","getPackageManagerChoice","upgradePackages","warnAboutMissingAppId","buildStaticFiles","checkRequiredDependencies","determineBasePath","getAutoUpdatesCssUrls","getAutoUpdatesImportMap","getStudioEnvironmentVariables","handlePrereleaseVersions","buildStudio","options","calledFromDeploy","cliConfig","flags","outDir","output","workDir","upgradePkgs","packageManager","interactive","chosen","packages","internalBuildStudio","appId","autoUpdatesEnabled","isApp","minify","Boolean","projectId","api","reactCompiler","schemaExtraction","sourceMap","stats","unattendedMode","yes","vite","timer","defaultOutputDir","resolve","join","outputDir","installedSanityVersion","autoUpdatesImports","autoUpdatesCssUrls","cleanSanityVersion","version","Error","log","info","appType","installedVisionVersion","cleanVisionVersion","undefined","sanityDependencies","cssFile","name","mismatched","unresolvedPrerelease","length","versionMismatchWarning","map","mod","pkg","installed","remote","choice","choices","value","default","message","warning","error","exit","res","warn","envVarKeys","Object","keys","key","shouldClean","basePath","enabled","spin","start","force","recursive","cleanDuration","end","text","toFixed","succeed","trace","importMap","imports","cwd","bundle","outputSize","chunks","flatMap","chunk","modules","renderedLength","reduce","sum","n","buildDuration","complete","slice","fail","String"],"mappings":"AAAA,SAAQA,EAAE,QAAO,mBAAkB;AACnC,OAAOC,UAAU,YAAW;AAC5B,SAAQC,SAAS,QAAO,YAAW;AAEnC,SACEC,UAAU,EACVC,uBAAuB,EACvBC,6BAA6B,EAC7BC,gBAAgB,QACX,oCAAmC;AAC1C,SAEEC,eAAe,EACfC,sBAAsB,EACtBC,QAAQ,EACRC,aAAa,QAGR,mBAAkB;AACzB,SAAQC,OAAO,EAAEC,UAAU,EAAEC,MAAM,EAAEC,OAAO,QAA6B,sBAAqB;AAC9F,SAAQC,SAASC,WAAW,QAAO,SAAQ;AAE3C,SAAQC,QAAQ,QAAO,sBAAqB;AAC5C,SAAQC,yBAAyB,QAAO,0CAAyC;AACjF,SAAQC,cAAc,QAAO,+BAA8B;AAC3D,SAAQC,iBAAiB,EAAEC,iBAAiB,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QACTjB,MAAMpB,KAAK,CAACA;QACZ,MAAMF,UAAUE,iBAAiBzB,QAAQyB,MAAMF,OAAO,GAAGwC,OAAOtC;QAChE5F,WAAW,CAAC,6BAA6B,CAAC,EAAE;YAAC4F;QAAK;QAClDzD,OAAOyD,KAAK,CAAC,CAAC,+BAA+B,EAAEF,SAAS,EAAE;YAACG,MAAM;QAAC;IACpE;AACF"}
@@ -1,6 +1,6 @@
1
1
  import { loadEnv } from '../../util/loadEnv.js';
2
- const envPrefix = 'SANITY_STUDIO_';
3
2
  const appEnvPrefix = 'SANITY_APP_';
3
+ const studioEnvPrefix = 'SANITY_STUDIO_';
4
4
  /**
5
5
  * Get environment variables prefixed with SANITY_STUDIO_, as an object.
6
6
  *
@@ -15,20 +15,10 @@ const appEnvPrefix = 'SANITY_APP_';
15
15
  *
16
16
  * @public
17
17
  */ export function getStudioEnvironmentVariables(options = {}) {
18
- const { envFile = false, jsonEncode = false, prefix = '' } = options;
19
- const fullEnv = envFile ? {
20
- ...process.env,
21
- ...loadEnv(envFile.mode, envFile.envDir || process.cwd(), [
22
- envPrefix
23
- ])
24
- } : process.env;
25
- const studioEnv = {};
26
- for(const key in fullEnv){
27
- if (key.startsWith(envPrefix)) {
28
- studioEnv[`${prefix}${key}`] = jsonEncode ? JSON.stringify(fullEnv[key] || '') : fullEnv[key] || '';
29
- }
30
- }
31
- return studioEnv;
18
+ return getEnvironmentVariables({
19
+ ...options,
20
+ varTypePrefix: studioEnvPrefix
21
+ });
32
22
  }
33
23
  /**
34
24
  * Get environment variables prefixed with SANITY_APP_, as an object.
@@ -39,20 +29,26 @@ const appEnvPrefix = 'SANITY_APP_';
39
29
  *
40
30
  * @internal
41
31
  */ export function getAppEnvironmentVariables(options = {}) {
42
- const { envFile = false, jsonEncode = false, prefix = '' } = options;
32
+ return getEnvironmentVariables({
33
+ ...options,
34
+ varTypePrefix: appEnvPrefix
35
+ });
36
+ }
37
+ function getEnvironmentVariables(options) {
38
+ const { envFile = false, jsonEncode = false, prefix = '', varTypePrefix } = options;
43
39
  const fullEnv = envFile ? {
44
40
  ...process.env,
45
41
  ...loadEnv(envFile.mode, envFile.envDir || process.cwd(), [
46
- appEnvPrefix
42
+ varTypePrefix
47
43
  ])
48
44
  } : process.env;
49
45
  const appEnv = {};
50
46
  for(const key in fullEnv){
51
- if (key.startsWith(appEnvPrefix)) {
47
+ if (key.startsWith(varTypePrefix)) {
52
48
  appEnv[`${prefix}${key}`] = jsonEncode ? JSON.stringify(fullEnv[key] || '') : fullEnv[key] || '';
53
49
  }
54
50
  }
55
51
  return appEnv;
56
52
  }
57
53
 
58
- //# sourceMappingURL=getStudioEnvironmentVariables.js.map
54
+ //# sourceMappingURL=getEnvironmentVariables.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/actions/build/getEnvironmentVariables.ts"],"sourcesContent":["import {loadEnv} from '../../util/loadEnv.js'\n\nconst appEnvPrefix = 'SANITY_APP_'\nconst studioEnvPrefix = 'SANITY_STUDIO_'\n\n/**\n * The params for the `getStudioEnvironmentVariables` and `getAppEnvironmentVariables` function\n * that gets Studio/App-focused environment variables.\n *\n * @public\n */\nexport interface StudioEnvVariablesOptions {\n /**\n * When specified includes environment variables from dotenv files (`.env`), in the same way the studio does.\n * A `mode` must be specified, usually `development`\n * or `production`, which will load the corresponding `.env.development` or `.env.production`.\n * To specify where to look for the dotenv files, specify `options.envFile.envDir`.\n */\n envFile?: false | {envDir?: string; mode: string}\n /**\n * When specified, JSON-encodes the values, which is handy if you want to pass\n * this to a bundlers hardcoded defines, such as Vite's `define` or Webpack's `DefinePlugin`.\n */\n jsonEncode?: boolean\n /**\n * When specified adds a prefix to the environment variable keys,\n * eg: `getStudioEnvironmentVariables({prefix: 'process.env.'})`\n */\n prefix?: string\n}\n\n/**\n * Get environment variables prefixed with SANITY_STUDIO_, as an object.\n *\n * @param options - Options for the environment variable loading\n * {@link StudioEnvVariablesOptions}\n * @returns Object of studio environment variables\n *\n * @example\n * ```tsx\n * getStudioEnvironmentVariables({prefix: 'process.env.', jsonEncode: true})\n * ```\n *\n * @public\n */\nexport function getStudioEnvironmentVariables(\n options: StudioEnvVariablesOptions = {},\n): Record<string, string> {\n return getEnvironmentVariables({...options, varTypePrefix: studioEnvPrefix})\n}\n\n/**\n * Get environment variables prefixed with SANITY_APP_, as an object.\n *\n * @param options - Options for the environment variable loading\n * {@link StudioEnvVariablesOptions}\n * @returns Object of app environment variables\n *\n * @internal\n */\nexport function getAppEnvironmentVariables(\n options: StudioEnvVariablesOptions = {},\n): Record<string, string> {\n return getEnvironmentVariables({...options, varTypePrefix: appEnvPrefix})\n}\n\nfunction getEnvironmentVariables(\n options: StudioEnvVariablesOptions & {varTypePrefix: string},\n): Record<string, string> {\n const {envFile = false, jsonEncode = false, prefix = '', varTypePrefix} = options\n const fullEnv = envFile\n ? {...process.env, ...loadEnv(envFile.mode, envFile.envDir || process.cwd(), [varTypePrefix])}\n : process.env\n\n const appEnv: Record<string, string> = {}\n for (const key in fullEnv) {\n if (key.startsWith(varTypePrefix)) {\n appEnv[`${prefix}${key}`] = jsonEncode\n ? JSON.stringify(fullEnv[key] || '')\n : fullEnv[key] || ''\n }\n }\n return appEnv\n}\n"],"names":["loadEnv","appEnvPrefix","studioEnvPrefix","getStudioEnvironmentVariables","options","getEnvironmentVariables","varTypePrefix","getAppEnvironmentVariables","envFile","jsonEncode","prefix","fullEnv","process","env","mode","envDir","cwd","appEnv","key","startsWith","JSON","stringify"],"mappings":"AAAA,SAAQA,OAAO,QAAO,wBAAuB;AAE7C,MAAMC,eAAe;AACrB,MAAMC,kBAAkB;AA4BxB;;;;;;;;;;;;;CAaC,GACD,OAAO,SAASC,8BACdC,UAAqC,CAAC,CAAC;IAEvC,OAAOC,wBAAwB;QAAC,GAAGD,OAAO;QAAEE,eAAeJ;IAAe;AAC5E;AAEA;;;;;;;;CAQC,GACD,OAAO,SAASK,2BACdH,UAAqC,CAAC,CAAC;IAEvC,OAAOC,wBAAwB;QAAC,GAAGD,OAAO;QAAEE,eAAeL;IAAY;AACzE;AAEA,SAASI,wBACPD,OAA4D;IAE5D,MAAM,EAACI,UAAU,KAAK,EAAEC,aAAa,KAAK,EAAEC,SAAS,EAAE,EAAEJ,aAAa,EAAC,GAAGF;IAC1E,MAAMO,UAAUH,UACZ;QAAC,GAAGI,QAAQC,GAAG;QAAE,GAAGb,QAAQQ,QAAQM,IAAI,EAAEN,QAAQO,MAAM,IAAIH,QAAQI,GAAG,IAAI;YAACV;SAAc,CAAC;IAAA,IAC3FM,QAAQC,GAAG;IAEf,MAAMI,SAAiC,CAAC;IACxC,IAAK,MAAMC,OAAOP,QAAS;QACzB,IAAIO,IAAIC,UAAU,CAACb,gBAAgB;YACjCW,MAAM,CAAC,GAAGP,SAASQ,KAAK,CAAC,GAAGT,aACxBW,KAAKC,SAAS,CAACV,OAAO,CAACO,IAAI,IAAI,MAC/BP,OAAO,CAACO,IAAI,IAAI;QACtB;IACF;IACA,OAAOD;AACT"}
@@ -2,6 +2,7 @@ import { basename, dirname } from 'node:path';
2
2
  import { styleText } from 'node:util';
3
3
  import { createGzip } from 'node:zlib';
4
4
  import { CLIError } from '@oclif/core/errors';
5
+ import { formatSchemaValidation, SchemaExtractionError } from '@sanity/cli-build/_internal/extract';
5
6
  import { exitCodes, getLocalPackageVersion } from '@sanity/cli-core';
6
7
  import { spinner } from '@sanity/cli-core/ux';
7
8
  import { pack } from 'tar-fs';
@@ -10,8 +11,6 @@ import { getAppId } from '../../util/appId.js';
10
11
  import { NO_PROJECT_ID } from '../../util/errorMessages.js';
11
12
  import { buildStudio } from '../build/buildStudio.js';
12
13
  import { shouldAutoUpdate } from '../build/shouldAutoUpdate.js';
13
- import { formatSchemaValidation } from '../schema/formatSchemaValidation.js';
14
- import { SchemaExtractionError } from '../schema/utils/SchemaExtractionError.js';
15
14
  import { checkDir } from './checkDir.js';
16
15
  import { createStudioUserApplication } from './createStudioUserApplication.js';
17
16
  import { deployDebug } from './deployDebug.js';