@sanity/cli-core 0.1.0-alpha.8 → 1.0.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 (165) hide show
  1. package/dist/SanityCommand.js +88 -5
  2. package/dist/SanityCommand.js.map +1 -1
  3. package/dist/_exports/request.d.ts +77 -0
  4. package/dist/_exports/request.js +7 -0
  5. package/dist/_exports/request.js.map +1 -0
  6. package/dist/_exports/ux.d.ts +75 -4
  7. package/dist/_exports/ux.js +2 -1
  8. package/dist/_exports/ux.js.map +1 -1
  9. package/dist/config/cli/getCliConfig.js +33 -33
  10. package/dist/config/cli/getCliConfig.js.map +1 -1
  11. package/dist/config/cli/getCliConfigSync.js +1 -1
  12. package/dist/config/cli/getCliConfigSync.js.map +1 -1
  13. package/dist/config/cli/schemas.js +7 -0
  14. package/dist/config/cli/schemas.js.map +1 -1
  15. package/dist/config/cli/types/cliConfig.js.map +1 -1
  16. package/dist/config/findProjectRoot.js +8 -4
  17. package/dist/config/findProjectRoot.js.map +1 -1
  18. package/dist/config/findProjectRootSync.js +7 -3
  19. package/dist/config/findProjectRootSync.js.map +1 -1
  20. package/dist/config/studio/getStudioConfig.js +0 -3
  21. package/dist/config/studio/getStudioConfig.js.map +1 -1
  22. package/dist/config/studio/getStudioWorkspaces.js +63 -0
  23. package/dist/config/studio/getStudioWorkspaces.js.map +1 -0
  24. package/dist/config/studio/isStudioConfig.js +19 -0
  25. package/dist/config/studio/isStudioConfig.js.map +1 -0
  26. package/dist/config/studio/readStudioConfig.worker.js +8 -34
  27. package/dist/config/studio/readStudioConfig.worker.js.map +1 -1
  28. package/dist/config/util/findStudioConfigPath.js +24 -3
  29. package/dist/config/util/findStudioConfigPath.js.map +1 -1
  30. package/dist/config/util/recursivelyResolveProjectRoot.js.map +1 -1
  31. package/dist/errors/NonInteractiveError.js +18 -0
  32. package/dist/errors/NonInteractiveError.js.map +1 -0
  33. package/dist/{util → errors}/NotFoundError.js +1 -1
  34. package/dist/errors/NotFoundError.js.map +1 -0
  35. package/dist/errors/ProjectRootNotFoundError.js +35 -0
  36. package/dist/errors/ProjectRootNotFoundError.js.map +1 -0
  37. package/dist/index.d.ts +1247 -36
  38. package/dist/index.js +14 -9
  39. package/dist/index.js.map +1 -1
  40. package/dist/loaders/studio/studioWorkerLoader.worker.js +102 -23
  41. package/dist/loaders/studio/studioWorkerLoader.worker.js.map +1 -1
  42. package/dist/loaders/studio/studioWorkerTask.js +55 -34
  43. package/dist/loaders/studio/studioWorkerTask.js.map +1 -1
  44. package/dist/loaders/tsx/tsxWorkerLoader.worker.js +3 -4
  45. package/dist/loaders/tsx/tsxWorkerLoader.worker.js.map +1 -1
  46. package/dist/loaders/tsx/tsxWorkerTask.js +4 -31
  47. package/dist/loaders/tsx/tsxWorkerTask.js.map +1 -1
  48. package/dist/request/createRequester.js +83 -0
  49. package/dist/request/createRequester.js.map +1 -0
  50. package/dist/services/apiClient.js +8 -4
  51. package/dist/services/apiClient.js.map +1 -1
  52. package/dist/services/cliUserConfig.js +5 -5
  53. package/dist/services/cliUserConfig.js.map +1 -1
  54. package/dist/services/getCliToken.js +2 -2
  55. package/dist/services/getCliToken.js.map +1 -1
  56. package/dist/telemetry/getTelemetryBaseInfo.js +33 -0
  57. package/dist/telemetry/getTelemetryBaseInfo.js.map +1 -0
  58. package/dist/telemetry/types.js +5 -0
  59. package/dist/telemetry/types.js.map +1 -0
  60. package/dist/util/doImport.js +2 -1
  61. package/dist/util/doImport.js.map +1 -1
  62. package/dist/util/environment/mockBrowserEnvironment.js +1 -0
  63. package/dist/util/environment/mockBrowserEnvironment.js.map +1 -1
  64. package/dist/util/getCliTelemetry.js +34 -0
  65. package/dist/util/getCliTelemetry.js.map +1 -0
  66. package/dist/util/getSanityUrl.js +4 -3
  67. package/dist/util/getSanityUrl.js.map +1 -1
  68. package/dist/util/importModule.js +32 -0
  69. package/dist/util/importModule.js.map +1 -0
  70. package/dist/util/isInteractive.js +1 -1
  71. package/dist/util/isInteractive.js.map +1 -1
  72. package/dist/util/isStaging.js +10 -0
  73. package/dist/util/isStaging.js.map +1 -0
  74. package/dist/util/normalizePath.js +12 -0
  75. package/dist/util/normalizePath.js.map +1 -0
  76. package/dist/util/promisifyWorker.js +72 -0
  77. package/dist/util/promisifyWorker.js.map +1 -0
  78. package/dist/util/readNDJSON.js +18 -0
  79. package/dist/util/readNDJSON.js.map +1 -0
  80. package/dist/util/readPackageJson.js +74 -0
  81. package/dist/util/readPackageJson.js.map +1 -0
  82. package/dist/ux/boxen.js +3 -0
  83. package/dist/ux/boxen.js.map +1 -0
  84. package/dist/ux/colorizeJson.js +6 -6
  85. package/dist/ux/colorizeJson.js.map +1 -1
  86. package/dist/ux/prompts.js +49 -1
  87. package/dist/ux/prompts.js.map +1 -1
  88. package/package.json +39 -31
  89. package/dist/SanityCommand.d.ts +0 -78
  90. package/dist/_exports/tree.d.ts +0 -1
  91. package/dist/_exports/tree.js +0 -3
  92. package/dist/_exports/tree.js.map +0 -1
  93. package/dist/config/cli/getCliConfig.d.ts +0 -16
  94. package/dist/config/cli/getCliConfig.worker.d.ts +0 -1
  95. package/dist/config/cli/getCliConfig.worker.js +0 -15
  96. package/dist/config/cli/getCliConfig.worker.js.map +0 -1
  97. package/dist/config/cli/getCliConfigSync.d.ts +0 -12
  98. package/dist/config/cli/schemas.d.ts +0 -104
  99. package/dist/config/cli/types/cliConfig.d.ts +0 -83
  100. package/dist/config/cli/types/userViteConfig.d.ts +0 -5
  101. package/dist/config/findProjectRoot.d.ts +0 -14
  102. package/dist/config/findProjectRootSync.d.ts +0 -27
  103. package/dist/config/studio/getStudioConfig.d.ts +0 -14
  104. package/dist/config/studio/readStudioConfig.d.ts +0 -96
  105. package/dist/config/studio/readStudioConfig.worker.d.ts +0 -1
  106. package/dist/config/util/configPathsSync.d.ts +0 -17
  107. package/dist/config/util/findAppConfigPath.d.ts +0 -8
  108. package/dist/config/util/findConfigsPaths.d.ts +0 -16
  109. package/dist/config/util/findStudioConfigPath.d.ts +0 -9
  110. package/dist/config/util/isSanityV2StudioRoot.d.ts +0 -8
  111. package/dist/config/util/recursivelyResolveProjectRoot.d.ts +0 -27
  112. package/dist/debug.d.ts +0 -15
  113. package/dist/loaders/studio/studioWorkerLoader.worker.d.ts +0 -1
  114. package/dist/loaders/studio/studioWorkerTask.d.ts +0 -40
  115. package/dist/loaders/tsx/tsxWorkerLoader.worker.d.ts +0 -1
  116. package/dist/loaders/tsx/tsxWorkerTask.d.ts +0 -28
  117. package/dist/services/apiClient.d.ts +0 -53
  118. package/dist/services/cliUserConfig.d.ts +0 -40
  119. package/dist/services/getCliToken.d.ts +0 -7
  120. package/dist/types.d.ts +0 -15
  121. package/dist/util/NotFoundError.d.ts +0 -20
  122. package/dist/util/NotFoundError.js.map +0 -1
  123. package/dist/util/createExpiringConfig.d.ts +0 -37
  124. package/dist/util/createExpiringConfig.js +0 -60
  125. package/dist/util/createExpiringConfig.js.map +0 -1
  126. package/dist/util/doImport.d.ts +0 -7
  127. package/dist/util/environment/getStudioEnvironmentVariables.d.ts +0 -12
  128. package/dist/util/environment/mockBrowserEnvironment.d.ts +0 -17
  129. package/dist/util/environment/setupBrowserStubs.d.ts +0 -10
  130. package/dist/util/environment/stubs.d.ts +0 -254
  131. package/dist/util/fileExists.d.ts +0 -9
  132. package/dist/util/generateHelpUrl.d.ts +0 -8
  133. package/dist/util/getEmptyAuth.d.ts +0 -5
  134. package/dist/util/getSanityEnvVar.d.ts +0 -19
  135. package/dist/util/getSanityUrl.d.ts +0 -5
  136. package/dist/util/getUserConfig.d.ts +0 -2
  137. package/dist/util/isCi.d.ts +0 -1
  138. package/dist/util/isInteractive.d.ts +0 -1
  139. package/dist/util/isRecord.d.ts +0 -8
  140. package/dist/util/isTrueish.d.ts +0 -1
  141. package/dist/util/parseStringFlag.d.ts +0 -10
  142. package/dist/util/parseStringFlag.js +0 -19
  143. package/dist/util/parseStringFlag.js.map +0 -1
  144. package/dist/util/readJsonFile.d.ts +0 -14
  145. package/dist/util/resolveLocalPackage.d.ts +0 -18
  146. package/dist/util/safeStructuredClone.d.ts +0 -8
  147. package/dist/util/tree.d.ts +0 -31
  148. package/dist/util/tree.js +0 -108
  149. package/dist/util/tree.js.map +0 -1
  150. package/dist/util/tryGetDefaultExport.d.ts +0 -5
  151. package/dist/util/writeJsonFile.d.ts +0 -9
  152. package/dist/ux/chalk.d.ts +0 -2
  153. package/dist/ux/chalk.js +0 -4
  154. package/dist/ux/chalk.js.map +0 -1
  155. package/dist/ux/colorizeJson.d.ts +0 -1
  156. package/dist/ux/formatObject.d.ts +0 -1
  157. package/dist/ux/formatObject.js +0 -9
  158. package/dist/ux/formatObject.js.map +0 -1
  159. package/dist/ux/logSymbols.d.ts +0 -1
  160. package/dist/ux/printKeyValue.d.ts +0 -1
  161. package/dist/ux/printKeyValue.js +0 -16
  162. package/dist/ux/printKeyValue.js.map +0 -1
  163. package/dist/ux/prompts.d.ts +0 -1
  164. package/dist/ux/spinner.d.ts +0 -1
  165. package/dist/ux/timer.d.ts +0 -12
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/config/findProjectRoot.ts"],"sourcesContent":["import {findAppConfigPath} from './util/findAppConfigPath.js'\nimport {findStudioConfigPath} from './util/findStudioConfigPath.js'\nimport {\n type ProjectRootResult,\n recursivelyResolveProjectRoot,\n} from './util/recursivelyResolveProjectRoot.js'\n\n/**\n * Resolve project root directory and type.\n *\n * Project root is:\n * - `studio` - A pre-blueprints Sanity studio root (containing `sanity.config.(ts|js)`)\n * - `app` - A Sanity app root (containing `sanity.cli.(ts|js)`)\n *\n * If a Sanity Studio v2/v1 root is found (containing `sanity.json` with `root: true`),\n * an error is thrown, as v2/v1 is no longer supported.\n *\n * @internal\n */\nexport async function findProjectRoot(cwd: string): Promise<ProjectRootResult> {\n try {\n // First try to find a studio project root, looks for `sanity.config.(ts|js)`\n const studioProjectRoot = await resolveProjectRootForStudio(cwd)\n if (studioProjectRoot) {\n return studioProjectRoot\n }\n\n // Second try to find a app project root, looks for `sanity.cli.(ts|js)`\n const appProjectRoot = await resolveProjectRootForApp(cwd)\n if (appProjectRoot) {\n return appProjectRoot\n }\n\n // If nothing is found throw an error\n throw new Error('No project root found')\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : `${err}`\n throw new Error(`Error occurred trying to resolve project root:\\n${message}`)\n }\n}\n\n/**\n * Recursively searches for a project configuration file in the given directory and its parents.\n * Throws if Sanity v2 studio root is found.\n *\n * @param basePath - The base path to start searching from\n * @param iterations - Current iteration count, passed internally to prevent infinite recursion.\n * @returns A promise that resolves to an object if config is found, false otherwise\n * @internal\n */\nasync function resolveProjectRootForStudio(\n basePath: string,\n iterations = 0,\n): Promise<false | ProjectRootResult> {\n return recursivelyResolveProjectRoot(basePath, findStudioConfigPath, 'studio', iterations)\n}\n\n/**\n * Recursively searches for a app project configuration file in the given directory and its parents.\n *\n * @param basePath - The base path to start searching from\n * @param iterations - Current iteration count, passed internally to prevent infinite recursion.\n * @returns A promise that resolves to an object if config is found, false otherwise\n * @internal\n */\nasync function resolveProjectRootForApp(\n basePath: string,\n iterations = 0,\n): Promise<false | ProjectRootResult> {\n return recursivelyResolveProjectRoot(basePath, findAppConfigPath, 'app', iterations)\n}\n"],"names":["findAppConfigPath","findStudioConfigPath","recursivelyResolveProjectRoot","findProjectRoot","cwd","studioProjectRoot","resolveProjectRootForStudio","appProjectRoot","resolveProjectRootForApp","Error","err","message","basePath","iterations"],"mappings":"AAAA,SAAQA,iBAAiB,QAAO,8BAA6B;AAC7D,SAAQC,oBAAoB,QAAO,iCAAgC;AACnE,SAEEC,6BAA6B,QACxB,0CAAyC;AAEhD;;;;;;;;;;;CAWC,GACD,OAAO,eAAeC,gBAAgBC,GAAW;IAC/C,IAAI;QACF,6EAA6E;QAC7E,MAAMC,oBAAoB,MAAMC,4BAA4BF;QAC5D,IAAIC,mBAAmB;YACrB,OAAOA;QACT;QAEA,wEAAwE;QACxE,MAAME,iBAAiB,MAAMC,yBAAyBJ;QACtD,IAAIG,gBAAgB;YAClB,OAAOA;QACT;QAEA,qCAAqC;QACrC,MAAM,IAAIE,MAAM;IAClB,EAAE,OAAOC,KAAc;QACrB,MAAMC,UAAUD,eAAeD,QAAQC,IAAIC,OAAO,GAAG,GAAGD,KAAK;QAC7D,MAAM,IAAID,MAAM,CAAC,gDAAgD,EAAEE,SAAS;IAC9E;AACF;AAEA;;;;;;;;CAQC,GACD,eAAeL,4BACbM,QAAgB,EAChBC,aAAa,CAAC;IAEd,OAAOX,8BAA8BU,UAAUX,sBAAsB,UAAUY;AACjF;AAEA;;;;;;;CAOC,GACD,eAAeL,yBACbI,QAAgB,EAChBC,aAAa,CAAC;IAEd,OAAOX,8BAA8BU,UAAUZ,mBAAmB,OAAOa;AAC3E"}
1
+ {"version":3,"sources":["../../src/config/findProjectRoot.ts"],"sourcesContent":["import {ProjectRootNotFoundError} from '../errors/ProjectRootNotFoundError.js'\nimport {findAppConfigPath} from './util/findAppConfigPath.js'\nimport {tryFindStudioConfigPath} from './util/findStudioConfigPath.js'\nimport {\n type ProjectRootResult,\n recursivelyResolveProjectRoot,\n} from './util/recursivelyResolveProjectRoot.js'\n\n/**\n * Resolve project root directory and type.\n *\n * Project root is:\n * - `studio` - A pre-blueprints Sanity studio root (containing `sanity.config.(ts|js)`)\n * - `app` - A Sanity app root (containing `sanity.cli.(ts|js)`)\n *\n * If a Sanity Studio v2/v1 root is found (containing `sanity.json` with `root: true`),\n * an error is thrown, as v2/v1 is no longer supported.\n *\n * @internal\n */\nexport async function findProjectRoot(cwd: string): Promise<ProjectRootResult> {\n try {\n // First try to find a studio project root, looks for `sanity.config.(ts|js)`\n const studioProjectRoot = await resolveProjectRootForStudio(cwd)\n if (studioProjectRoot) {\n return studioProjectRoot\n }\n\n // Second try to find a app project root, looks for `sanity.cli.(ts|js)`\n const appProjectRoot = await resolveProjectRootForApp(cwd)\n if (appProjectRoot) {\n return appProjectRoot\n }\n\n // If nothing is found throw a specific error\n throw new ProjectRootNotFoundError('No project root found')\n } catch (err: unknown) {\n if (err instanceof ProjectRootNotFoundError) {\n throw err\n }\n const message = err instanceof Error ? err.message : `${err}`\n throw new Error(`Error occurred trying to resolve project root:\\n${message}`)\n }\n}\n\n/**\n * Recursively searches for a project configuration file in the given directory and its parents.\n * Throws if Sanity v2 studio root is found.\n *\n * @param basePath - The base path to start searching from\n * @param iterations - Current iteration count, passed internally to prevent infinite recursion.\n * @returns A promise that resolves to an object if config is found, false otherwise\n * @internal\n */\nasync function resolveProjectRootForStudio(\n basePath: string,\n iterations = 0,\n): Promise<false | ProjectRootResult> {\n return recursivelyResolveProjectRoot(basePath, tryFindStudioConfigPath, 'studio', iterations)\n}\n\n/**\n * Recursively searches for a app project configuration file in the given directory and its parents.\n *\n * @param basePath - The base path to start searching from\n * @param iterations - Current iteration count, passed internally to prevent infinite recursion.\n * @returns A promise that resolves to an object if config is found, false otherwise\n * @internal\n */\nasync function resolveProjectRootForApp(\n basePath: string,\n iterations = 0,\n): Promise<false | ProjectRootResult> {\n return recursivelyResolveProjectRoot(basePath, findAppConfigPath, 'app', iterations)\n}\n"],"names":["ProjectRootNotFoundError","findAppConfigPath","tryFindStudioConfigPath","recursivelyResolveProjectRoot","findProjectRoot","cwd","studioProjectRoot","resolveProjectRootForStudio","appProjectRoot","resolveProjectRootForApp","err","message","Error","basePath","iterations"],"mappings":"AAAA,SAAQA,wBAAwB,QAAO,wCAAuC;AAC9E,SAAQC,iBAAiB,QAAO,8BAA6B;AAC7D,SAAQC,uBAAuB,QAAO,iCAAgC;AACtE,SAEEC,6BAA6B,QACxB,0CAAyC;AAEhD;;;;;;;;;;;CAWC,GACD,OAAO,eAAeC,gBAAgBC,GAAW;IAC/C,IAAI;QACF,6EAA6E;QAC7E,MAAMC,oBAAoB,MAAMC,4BAA4BF;QAC5D,IAAIC,mBAAmB;YACrB,OAAOA;QACT;QAEA,wEAAwE;QACxE,MAAME,iBAAiB,MAAMC,yBAAyBJ;QACtD,IAAIG,gBAAgB;YAClB,OAAOA;QACT;QAEA,6CAA6C;QAC7C,MAAM,IAAIR,yBAAyB;IACrC,EAAE,OAAOU,KAAc;QACrB,IAAIA,eAAeV,0BAA0B;YAC3C,MAAMU;QACR;QACA,MAAMC,UAAUD,eAAeE,QAAQF,IAAIC,OAAO,GAAG,GAAGD,KAAK;QAC7D,MAAM,IAAIE,MAAM,CAAC,gDAAgD,EAAED,SAAS;IAC9E;AACF;AAEA;;;;;;;;CAQC,GACD,eAAeJ,4BACbM,QAAgB,EAChBC,aAAa,CAAC;IAEd,OAAOX,8BAA8BU,UAAUX,yBAAyB,UAAUY;AACpF;AAEA;;;;;;;CAOC,GACD,eAAeL,yBACbI,QAAgB,EAChBC,aAAa,CAAC;IAEd,OAAOX,8BAA8BU,UAAUZ,mBAAmB,OAAOa;AAC3E"}
@@ -1,4 +1,5 @@
1
1
  import { dirname, resolve } from 'node:path';
2
+ import { ProjectRootNotFoundError } from '../errors/ProjectRootNotFoundError.js';
2
3
  import { findAppConfigPathSync, findStudioConfigPathSync } from './util/configPathsSync.js';
3
4
  /**
4
5
  * Generic recursive search function for project configuration files (synchronous version).
@@ -9,7 +10,7 @@ import { findAppConfigPathSync, findStudioConfigPathSync } from './util/configPa
9
10
  * @param iterations - Current iteration count, passed internally to prevent infinite recursion
10
11
  * @returns An object if config is found, false otherwise
11
12
  * @internal
12
- */ export function recursivelyResolveProjectRootSync(basePath, findConfigFn, projectType, iterations = 0) {
13
+ */ function recursivelyResolveProjectRootSync(basePath, findConfigFn, projectType, iterations = 0) {
13
14
  const configPath = findConfigFn(basePath);
14
15
  if (configPath) {
15
16
  return {
@@ -50,9 +51,12 @@ import { findAppConfigPathSync, findStudioConfigPathSync } from './util/configPa
50
51
  if (appProjectRoot) {
51
52
  return appProjectRoot;
52
53
  }
53
- // If nothing is found throw an error
54
- throw new Error(`No project root found in ${cwd}`);
54
+ // If nothing is found throw a specific error
55
+ throw new ProjectRootNotFoundError(`No project root found in ${cwd}`);
55
56
  } catch (err) {
57
+ if (err instanceof ProjectRootNotFoundError) {
58
+ throw err;
59
+ }
56
60
  const message = err instanceof Error ? err.message : `${err}`;
57
61
  throw new Error(`Error occurred trying to resolve project root:\n${message}`);
58
62
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/config/findProjectRootSync.ts"],"sourcesContent":["import {dirname, resolve} from 'node:path'\n\nimport {findAppConfigPathSync, findStudioConfigPathSync} from './util/configPathsSync.js'\nimport {ProjectRootResult} from './util/recursivelyResolveProjectRoot.js'\n\n/**\n * Generic recursive search function for project configuration files (synchronous version).\n *\n * @param basePath - The base path to start searching from\n * @param findConfigFn - Function that looks for config files in a given directory\n * @param projectType - The type of project ('app' | 'studio')\n * @param iterations - Current iteration count, passed internally to prevent infinite recursion\n * @returns An object if config is found, false otherwise\n * @internal\n */\nexport function recursivelyResolveProjectRootSync(\n basePath: string,\n findConfigFn: (path: string) => string | undefined,\n projectType: 'app' | 'studio',\n iterations = 0,\n): false | ProjectRootResult {\n const configPath = findConfigFn(basePath)\n\n if (configPath) {\n return {\n directory: dirname(configPath),\n path: configPath,\n type: projectType,\n }\n }\n\n const parentDir = resolve(basePath, '..')\n if (parentDir === basePath || iterations > 50) {\n // Reached root (or max depth), give up\n return false\n }\n\n return recursivelyResolveProjectRootSync(parentDir, findConfigFn, projectType, iterations + 1)\n}\n\n/**\n * Resolve project root directory and type synchronously.\n *\n * Project root is:\n * - `studio` - A pre-blueprints Sanity studio root (containing `sanity.config.(ts|js)`)\n * - `app` - A Sanity app root (containing `sanity.cli.(ts|js)`)\n *\n * If a Sanity Studio v2/v1 root is found (containing `sanity.json` with `root: true`),\n * an error is thrown, as v2/v1 is no longer supported.\n *\n * @param cwd - Current working directory to start searching from\n * @returns Project root result\n * @internal\n */\nexport function findProjectRootSync(cwd: string): ProjectRootResult {\n try {\n // First try to find a studio project root, looks for `sanity.config.(ts|js)`\n const studioProjectRoot = resolveProjectRootForStudioSync(cwd)\n if (studioProjectRoot) {\n return studioProjectRoot\n }\n\n // Second try to find a app project root, looks for `sanity.cli.(ts|js)`\n const appProjectRoot = resolveProjectRootForAppSync(cwd)\n if (appProjectRoot) {\n return appProjectRoot\n }\n\n // If nothing is found throw an error\n throw new Error(`No project root found in ${cwd}`)\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : `${err}`\n throw new Error(`Error occurred trying to resolve project root:\\n${message}`)\n }\n}\n\n/**\n * Recursively searches for a project configuration file in the given directory and its parents.\n * Throws if Sanity v2 studio root is found.\n *\n * @param basePath - The base path to start searching from\n * @param iterations - Current iteration count, passed internally to prevent infinite recursion.\n * @returns An object if config is found, false otherwise\n * @internal\n */\nfunction resolveProjectRootForStudioSync(\n basePath: string,\n iterations = 0,\n): false | ProjectRootResult {\n return recursivelyResolveProjectRootSync(basePath, findStudioConfigPathSync, 'studio', iterations)\n}\n\n/**\n * Recursively searches for a app project configuration file in the given directory and its parents.\n *\n * @param basePath - The base path to start searching from\n * @param iterations - Current iteration count, passed internally to prevent infinite recursion.\n * @returns An object if config is found, false otherwise\n * @internal\n */\nfunction resolveProjectRootForAppSync(basePath: string, iterations = 0): false | ProjectRootResult {\n return recursivelyResolveProjectRootSync(basePath, findAppConfigPathSync, 'app', iterations)\n}\n"],"names":["dirname","resolve","findAppConfigPathSync","findStudioConfigPathSync","recursivelyResolveProjectRootSync","basePath","findConfigFn","projectType","iterations","configPath","directory","path","type","parentDir","findProjectRootSync","cwd","studioProjectRoot","resolveProjectRootForStudioSync","appProjectRoot","resolveProjectRootForAppSync","Error","err","message"],"mappings":"AAAA,SAAQA,OAAO,EAAEC,OAAO,QAAO,YAAW;AAE1C,SAAQC,qBAAqB,EAAEC,wBAAwB,QAAO,4BAA2B;AAGzF;;;;;;;;;CASC,GACD,OAAO,SAASC,kCACdC,QAAgB,EAChBC,YAAkD,EAClDC,WAA6B,EAC7BC,aAAa,CAAC;IAEd,MAAMC,aAAaH,aAAaD;IAEhC,IAAII,YAAY;QACd,OAAO;YACLC,WAAWV,QAAQS;YACnBE,MAAMF;YACNG,MAAML;QACR;IACF;IAEA,MAAMM,YAAYZ,QAAQI,UAAU;IACpC,IAAIQ,cAAcR,YAAYG,aAAa,IAAI;QAC7C,uCAAuC;QACvC,OAAO;IACT;IAEA,OAAOJ,kCAAkCS,WAAWP,cAAcC,aAAaC,aAAa;AAC9F;AAEA;;;;;;;;;;;;;CAaC,GACD,OAAO,SAASM,oBAAoBC,GAAW;IAC7C,IAAI;QACF,6EAA6E;QAC7E,MAAMC,oBAAoBC,gCAAgCF;QAC1D,IAAIC,mBAAmB;YACrB,OAAOA;QACT;QAEA,wEAAwE;QACxE,MAAME,iBAAiBC,6BAA6BJ;QACpD,IAAIG,gBAAgB;YAClB,OAAOA;QACT;QAEA,qCAAqC;QACrC,MAAM,IAAIE,MAAM,CAAC,yBAAyB,EAAEL,KAAK;IACnD,EAAE,OAAOM,KAAc;QACrB,MAAMC,UAAUD,eAAeD,QAAQC,IAAIC,OAAO,GAAG,GAAGD,KAAK;QAC7D,MAAM,IAAID,MAAM,CAAC,gDAAgD,EAAEE,SAAS;IAC9E;AACF;AAEA;;;;;;;;CAQC,GACD,SAASL,gCACPZ,QAAgB,EAChBG,aAAa,CAAC;IAEd,OAAOJ,kCAAkCC,UAAUF,0BAA0B,UAAUK;AACzF;AAEA;;;;;;;CAOC,GACD,SAASW,6BAA6Bd,QAAgB,EAAEG,aAAa,CAAC;IACpE,OAAOJ,kCAAkCC,UAAUH,uBAAuB,OAAOM;AACnF"}
1
+ {"version":3,"sources":["../../src/config/findProjectRootSync.ts"],"sourcesContent":["import {dirname, resolve} from 'node:path'\n\nimport {ProjectRootNotFoundError} from '../errors/ProjectRootNotFoundError.js'\nimport {findAppConfigPathSync, findStudioConfigPathSync} from './util/configPathsSync.js'\nimport {ProjectRootResult} from './util/recursivelyResolveProjectRoot.js'\n\n/**\n * Generic recursive search function for project configuration files (synchronous version).\n *\n * @param basePath - The base path to start searching from\n * @param findConfigFn - Function that looks for config files in a given directory\n * @param projectType - The type of project ('app' | 'studio')\n * @param iterations - Current iteration count, passed internally to prevent infinite recursion\n * @returns An object if config is found, false otherwise\n * @internal\n */\nfunction recursivelyResolveProjectRootSync(\n basePath: string,\n findConfigFn: (path: string) => string | undefined,\n projectType: 'app' | 'studio',\n iterations = 0,\n): false | ProjectRootResult {\n const configPath = findConfigFn(basePath)\n\n if (configPath) {\n return {\n directory: dirname(configPath),\n path: configPath,\n type: projectType,\n }\n }\n\n const parentDir = resolve(basePath, '..')\n if (parentDir === basePath || iterations > 50) {\n // Reached root (or max depth), give up\n return false\n }\n\n return recursivelyResolveProjectRootSync(parentDir, findConfigFn, projectType, iterations + 1)\n}\n\n/**\n * Resolve project root directory and type synchronously.\n *\n * Project root is:\n * - `studio` - A pre-blueprints Sanity studio root (containing `sanity.config.(ts|js)`)\n * - `app` - A Sanity app root (containing `sanity.cli.(ts|js)`)\n *\n * If a Sanity Studio v2/v1 root is found (containing `sanity.json` with `root: true`),\n * an error is thrown, as v2/v1 is no longer supported.\n *\n * @param cwd - Current working directory to start searching from\n * @returns Project root result\n * @internal\n */\nexport function findProjectRootSync(cwd: string): ProjectRootResult {\n try {\n // First try to find a studio project root, looks for `sanity.config.(ts|js)`\n const studioProjectRoot = resolveProjectRootForStudioSync(cwd)\n if (studioProjectRoot) {\n return studioProjectRoot\n }\n\n // Second try to find a app project root, looks for `sanity.cli.(ts|js)`\n const appProjectRoot = resolveProjectRootForAppSync(cwd)\n if (appProjectRoot) {\n return appProjectRoot\n }\n\n // If nothing is found throw a specific error\n throw new ProjectRootNotFoundError(`No project root found in ${cwd}`)\n } catch (err: unknown) {\n if (err instanceof ProjectRootNotFoundError) {\n throw err\n }\n const message = err instanceof Error ? err.message : `${err}`\n throw new Error(`Error occurred trying to resolve project root:\\n${message}`)\n }\n}\n\n/**\n * Recursively searches for a project configuration file in the given directory and its parents.\n * Throws if Sanity v2 studio root is found.\n *\n * @param basePath - The base path to start searching from\n * @param iterations - Current iteration count, passed internally to prevent infinite recursion.\n * @returns An object if config is found, false otherwise\n * @internal\n */\nfunction resolveProjectRootForStudioSync(\n basePath: string,\n iterations = 0,\n): false | ProjectRootResult {\n return recursivelyResolveProjectRootSync(basePath, findStudioConfigPathSync, 'studio', iterations)\n}\n\n/**\n * Recursively searches for a app project configuration file in the given directory and its parents.\n *\n * @param basePath - The base path to start searching from\n * @param iterations - Current iteration count, passed internally to prevent infinite recursion.\n * @returns An object if config is found, false otherwise\n * @internal\n */\nfunction resolveProjectRootForAppSync(basePath: string, iterations = 0): false | ProjectRootResult {\n return recursivelyResolveProjectRootSync(basePath, findAppConfigPathSync, 'app', iterations)\n}\n"],"names":["dirname","resolve","ProjectRootNotFoundError","findAppConfigPathSync","findStudioConfigPathSync","recursivelyResolveProjectRootSync","basePath","findConfigFn","projectType","iterations","configPath","directory","path","type","parentDir","findProjectRootSync","cwd","studioProjectRoot","resolveProjectRootForStudioSync","appProjectRoot","resolveProjectRootForAppSync","err","message","Error"],"mappings":"AAAA,SAAQA,OAAO,EAAEC,OAAO,QAAO,YAAW;AAE1C,SAAQC,wBAAwB,QAAO,wCAAuC;AAC9E,SAAQC,qBAAqB,EAAEC,wBAAwB,QAAO,4BAA2B;AAGzF;;;;;;;;;CASC,GACD,SAASC,kCACPC,QAAgB,EAChBC,YAAkD,EAClDC,WAA6B,EAC7BC,aAAa,CAAC;IAEd,MAAMC,aAAaH,aAAaD;IAEhC,IAAII,YAAY;QACd,OAAO;YACLC,WAAWX,QAAQU;YACnBE,MAAMF;YACNG,MAAML;QACR;IACF;IAEA,MAAMM,YAAYb,QAAQK,UAAU;IACpC,IAAIQ,cAAcR,YAAYG,aAAa,IAAI;QAC7C,uCAAuC;QACvC,OAAO;IACT;IAEA,OAAOJ,kCAAkCS,WAAWP,cAAcC,aAAaC,aAAa;AAC9F;AAEA;;;;;;;;;;;;;CAaC,GACD,OAAO,SAASM,oBAAoBC,GAAW;IAC7C,IAAI;QACF,6EAA6E;QAC7E,MAAMC,oBAAoBC,gCAAgCF;QAC1D,IAAIC,mBAAmB;YACrB,OAAOA;QACT;QAEA,wEAAwE;QACxE,MAAME,iBAAiBC,6BAA6BJ;QACpD,IAAIG,gBAAgB;YAClB,OAAOA;QACT;QAEA,6CAA6C;QAC7C,MAAM,IAAIjB,yBAAyB,CAAC,yBAAyB,EAAEc,KAAK;IACtE,EAAE,OAAOK,KAAc;QACrB,IAAIA,eAAenB,0BAA0B;YAC3C,MAAMmB;QACR;QACA,MAAMC,UAAUD,eAAeE,QAAQF,IAAIC,OAAO,GAAG,GAAGD,KAAK;QAC7D,MAAM,IAAIE,MAAM,CAAC,gDAAgD,EAAED,SAAS;IAC9E;AACF;AAEA;;;;;;;;CAQC,GACD,SAASJ,gCACPZ,QAAgB,EAChBG,aAAa,CAAC;IAEd,OAAOJ,kCAAkCC,UAAUF,0BAA0B,UAAUK;AACzF;AAEA;;;;;;;CAOC,GACD,SAASW,6BAA6Bd,QAAgB,EAAEG,aAAa,CAAC;IACpE,OAAOJ,kCAAkCC,UAAUH,uBAAuB,OAAOM;AACnF"}
@@ -2,9 +2,6 @@ import { findStudioConfigPath } from '../util/findStudioConfigPath.js';
2
2
  import { readStudioConfig } from './readStudioConfig.js';
3
3
  export async function getStudioConfig(rootPath, options) {
4
4
  const studioConfigPath = await findStudioConfigPath(rootPath);
5
- if (!studioConfigPath) {
6
- throw new Error(`Unable to find studio configuration file in ${rootPath}`);
7
- }
8
5
  // TypeScript is not being very clever with our overloads :(
9
6
  return options.resolvePlugins ? readStudioConfig(studioConfigPath, {
10
7
  resolvePlugins: true
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/config/studio/getStudioConfig.ts"],"sourcesContent":["import {findStudioConfigPath} from '../util/findStudioConfigPath.js'\nimport {\n type RawStudioConfig,\n readStudioConfig,\n type ReadStudioConfigOptions,\n type ResolvedStudioConfig,\n} from './readStudioConfig.js'\n\n/**\n * Get the studio config for a project, given the root path.\n *\n * @param rootPath - The root path for the project\n * @returns The studio config (some properties may be missing)\n * @internal\n */\nexport async function getStudioConfig(\n rootPath: string,\n options: {resolvePlugins: true},\n): Promise<ResolvedStudioConfig>\n\nexport async function getStudioConfig(\n rootPath: string,\n options: {resolvePlugins: false},\n): Promise<RawStudioConfig>\n\nexport async function getStudioConfig(\n rootPath: string,\n options: ReadStudioConfigOptions,\n): Promise<RawStudioConfig | ResolvedStudioConfig> {\n const studioConfigPath = await findStudioConfigPath(rootPath)\n if (!studioConfigPath) {\n throw new Error(`Unable to find studio configuration file in ${rootPath}`)\n }\n\n // TypeScript is not being very clever with our overloads :(\n return options.resolvePlugins\n ? readStudioConfig(studioConfigPath, {resolvePlugins: true})\n : readStudioConfig(studioConfigPath, {resolvePlugins: false})\n}\n"],"names":["findStudioConfigPath","readStudioConfig","getStudioConfig","rootPath","options","studioConfigPath","Error","resolvePlugins"],"mappings":"AAAA,SAAQA,oBAAoB,QAAO,kCAAiC;AACpE,SAEEC,gBAAgB,QAGX,wBAAuB;AAmB9B,OAAO,eAAeC,gBACpBC,QAAgB,EAChBC,OAAgC;IAEhC,MAAMC,mBAAmB,MAAML,qBAAqBG;IACpD,IAAI,CAACE,kBAAkB;QACrB,MAAM,IAAIC,MAAM,CAAC,4CAA4C,EAAEH,UAAU;IAC3E;IAEA,4DAA4D;IAC5D,OAAOC,QAAQG,cAAc,GACzBN,iBAAiBI,kBAAkB;QAACE,gBAAgB;IAAI,KACxDN,iBAAiBI,kBAAkB;QAACE,gBAAgB;IAAK;AAC/D"}
1
+ {"version":3,"sources":["../../../src/config/studio/getStudioConfig.ts"],"sourcesContent":["import {findStudioConfigPath} from '../util/findStudioConfigPath.js'\nimport {\n type RawStudioConfig,\n readStudioConfig,\n type ReadStudioConfigOptions,\n type ResolvedStudioConfig,\n} from './readStudioConfig.js'\n\n/**\n * Get the studio config for a project, given the root path.\n *\n * @param rootPath - The root path for the project\n * @returns The studio config (some properties may be missing)\n * @public\n */\nexport async function getStudioConfig(\n rootPath: string,\n options: {resolvePlugins: true},\n): Promise<ResolvedStudioConfig>\n\nexport async function getStudioConfig(\n rootPath: string,\n options: {resolvePlugins: false},\n): Promise<RawStudioConfig>\n\nexport async function getStudioConfig(\n rootPath: string,\n options: ReadStudioConfigOptions,\n): Promise<RawStudioConfig | ResolvedStudioConfig> {\n const studioConfigPath = await findStudioConfigPath(rootPath)\n\n // TypeScript is not being very clever with our overloads :(\n return options.resolvePlugins\n ? readStudioConfig(studioConfigPath, {resolvePlugins: true})\n : readStudioConfig(studioConfigPath, {resolvePlugins: false})\n}\n"],"names":["findStudioConfigPath","readStudioConfig","getStudioConfig","rootPath","options","studioConfigPath","resolvePlugins"],"mappings":"AAAA,SAAQA,oBAAoB,QAAO,kCAAiC;AACpE,SAEEC,gBAAgB,QAGX,wBAAuB;AAmB9B,OAAO,eAAeC,gBACpBC,QAAgB,EAChBC,OAAgC;IAEhC,MAAMC,mBAAmB,MAAML,qBAAqBG;IAEpD,4DAA4D;IAC5D,OAAOC,QAAQE,cAAc,GACzBL,iBAAiBI,kBAAkB;QAACC,gBAAgB;IAAI,KACxDL,iBAAiBI,kBAAkB;QAACC,gBAAgB;IAAK;AAC/D"}
@@ -0,0 +1,63 @@
1
+ import { stat } from 'node:fs/promises';
2
+ import { dirname } from 'node:path';
3
+ import { isMainThread } from 'node:worker_threads';
4
+ import { firstValueFrom, of } from 'rxjs';
5
+ import { subdebug } from '../../debug.js';
6
+ import { doImport } from '../../util/doImport.js';
7
+ import { getEmptyAuth } from '../../util/getEmptyAuth.js';
8
+ import { resolveLocalPackage } from '../../util/resolveLocalPackage.js';
9
+ import { findStudioConfigPath } from '../util/findStudioConfigPath.js';
10
+ import { isStudioConfig } from './isStudioConfig.js';
11
+ const debug = subdebug('worker:getStudioWorkspaces');
12
+ /**
13
+ * Resolves the workspaces from the studio config.
14
+ *
15
+ * NOTE: This function should only be called from a worker thread.
16
+ *
17
+ * @param configPath - The path to the studio config
18
+ * @returns The workspaces
19
+ * @internal
20
+ */ export async function getStudioWorkspaces(configPath) {
21
+ if (isMainThread) {
22
+ throw new Error('getStudioWorkspaces should only be called from a worker thread');
23
+ }
24
+ const isDirectory = (await stat(configPath)).isDirectory();
25
+ if (isDirectory) {
26
+ configPath = await findStudioConfigPath(configPath);
27
+ }
28
+ debug('Finding studio config path %s', configPath);
29
+ let config = await doImport(configPath);
30
+ debug('Imported config %o', config);
31
+ if (!isStudioConfig(config)) {
32
+ if (!('default' in config) || !isStudioConfig(config.default)) {
33
+ debug('Invalid studio config format in "%s"', configPath);
34
+ throw new TypeError(`Invalid studio config format in "${configPath}"`);
35
+ }
36
+ config = config.default;
37
+ }
38
+ const workDir = dirname(configPath);
39
+ debug('Work dir %s', workDir);
40
+ const { resolveConfig } = await resolveLocalPackage('sanity', workDir);
41
+ if (typeof resolveConfig !== 'function') {
42
+ throw new TypeError('Expected `resolveConfig` from `sanity` to be a function');
43
+ }
44
+ // We will also want to stub out some configuration - we don't need to resolve the
45
+ // users' logged in state, for instance - so let's disable the auth implementation.
46
+ const rawWorkspaces = Array.isArray(config) ? config : [
47
+ {
48
+ ...config,
49
+ basePath: config.basePath || '/',
50
+ name: config.name || 'default'
51
+ }
52
+ ];
53
+ const unauthedWorkspaces = rawWorkspaces.map((workspace)=>({
54
+ ...workspace,
55
+ auth: {
56
+ state: of(getEmptyAuth())
57
+ }
58
+ }));
59
+ debug('Unauthed workspaces %o', unauthedWorkspaces);
60
+ return firstValueFrom(resolveConfig(unauthedWorkspaces));
61
+ }
62
+
63
+ //# sourceMappingURL=getStudioWorkspaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/config/studio/getStudioWorkspaces.ts"],"sourcesContent":["import {stat} from 'node:fs/promises'\nimport {dirname} from 'node:path'\nimport {isMainThread} from 'node:worker_threads'\n\nimport {firstValueFrom, of} from 'rxjs'\nimport {type Workspace} from 'sanity'\n\nimport {subdebug} from '../../debug.js'\nimport {doImport} from '../../util/doImport.js'\nimport {getEmptyAuth} from '../../util/getEmptyAuth.js'\nimport {resolveLocalPackage} from '../../util/resolveLocalPackage.js'\nimport {findStudioConfigPath} from '../util/findStudioConfigPath.js'\nimport {isStudioConfig} from './isStudioConfig.js'\n\nconst debug = subdebug('worker:getStudioWorkspaces')\n\n/**\n * Resolves the workspaces from the studio config.\n *\n * NOTE: This function should only be called from a worker thread.\n *\n * @param configPath - The path to the studio config\n * @returns The workspaces\n * @internal\n */\nexport async function getStudioWorkspaces(configPath: string): Promise<Workspace[]> {\n if (isMainThread) {\n throw new Error('getStudioWorkspaces should only be called from a worker thread')\n }\n const isDirectory = (await stat(configPath)).isDirectory()\n if (isDirectory) {\n configPath = await findStudioConfigPath(configPath)\n }\n debug('Finding studio config path %s', configPath)\n let config = await doImport(configPath)\n\n debug('Imported config %o', config)\n if (!isStudioConfig(config)) {\n if (!('default' in config) || !isStudioConfig(config.default)) {\n debug('Invalid studio config format in \"%s\"', configPath)\n throw new TypeError(`Invalid studio config format in \"${configPath}\"`)\n }\n\n config = config.default\n }\n\n const workDir = dirname(configPath)\n debug('Work dir %s', workDir)\n const {resolveConfig} = await resolveLocalPackage<typeof import('sanity')>('sanity', workDir)\n if (typeof resolveConfig !== 'function') {\n throw new TypeError('Expected `resolveConfig` from `sanity` to be a function')\n }\n\n // We will also want to stub out some configuration - we don't need to resolve the\n // users' logged in state, for instance - so let's disable the auth implementation.\n const rawWorkspaces = Array.isArray(config)\n ? config\n : [{...config, basePath: config.basePath || '/', name: config.name || 'default'}]\n\n const unauthedWorkspaces = rawWorkspaces.map((workspace) => ({\n ...workspace,\n auth: {state: of(getEmptyAuth())},\n }))\n\n debug('Unauthed workspaces %o', unauthedWorkspaces)\n\n return firstValueFrom(resolveConfig(unauthedWorkspaces))\n}\n"],"names":["stat","dirname","isMainThread","firstValueFrom","of","subdebug","doImport","getEmptyAuth","resolveLocalPackage","findStudioConfigPath","isStudioConfig","debug","getStudioWorkspaces","configPath","Error","isDirectory","config","default","TypeError","workDir","resolveConfig","rawWorkspaces","Array","isArray","basePath","name","unauthedWorkspaces","map","workspace","auth","state"],"mappings":"AAAA,SAAQA,IAAI,QAAO,mBAAkB;AACrC,SAAQC,OAAO,QAAO,YAAW;AACjC,SAAQC,YAAY,QAAO,sBAAqB;AAEhD,SAAQC,cAAc,EAAEC,EAAE,QAAO,OAAM;AAGvC,SAAQC,QAAQ,QAAO,iBAAgB;AACvC,SAAQC,QAAQ,QAAO,yBAAwB;AAC/C,SAAQC,YAAY,QAAO,6BAA4B;AACvD,SAAQC,mBAAmB,QAAO,oCAAmC;AACrE,SAAQC,oBAAoB,QAAO,kCAAiC;AACpE,SAAQC,cAAc,QAAO,sBAAqB;AAElD,MAAMC,QAAQN,SAAS;AAEvB;;;;;;;;CAQC,GACD,OAAO,eAAeO,oBAAoBC,UAAkB;IAC1D,IAAIX,cAAc;QAChB,MAAM,IAAIY,MAAM;IAClB;IACA,MAAMC,cAAc,AAAC,CAAA,MAAMf,KAAKa,WAAU,EAAGE,WAAW;IACxD,IAAIA,aAAa;QACfF,aAAa,MAAMJ,qBAAqBI;IAC1C;IACAF,MAAM,iCAAiCE;IACvC,IAAIG,SAAS,MAAMV,SAASO;IAE5BF,MAAM,sBAAsBK;IAC5B,IAAI,CAACN,eAAeM,SAAS;QAC3B,IAAI,CAAE,CAAA,aAAaA,MAAK,KAAM,CAACN,eAAeM,OAAOC,OAAO,GAAG;YAC7DN,MAAM,wCAAwCE;YAC9C,MAAM,IAAIK,UAAU,CAAC,iCAAiC,EAAEL,WAAW,CAAC,CAAC;QACvE;QAEAG,SAASA,OAAOC,OAAO;IACzB;IAEA,MAAME,UAAUlB,QAAQY;IACxBF,MAAM,eAAeQ;IACrB,MAAM,EAACC,aAAa,EAAC,GAAG,MAAMZ,oBAA6C,UAAUW;IACrF,IAAI,OAAOC,kBAAkB,YAAY;QACvC,MAAM,IAAIF,UAAU;IACtB;IAEA,kFAAkF;IAClF,mFAAmF;IACnF,MAAMG,gBAAgBC,MAAMC,OAAO,CAACP,UAChCA,SACA;QAAC;YAAC,GAAGA,MAAM;YAAEQ,UAAUR,OAAOQ,QAAQ,IAAI;YAAKC,MAAMT,OAAOS,IAAI,IAAI;QAAS;KAAE;IAEnF,MAAMC,qBAAqBL,cAAcM,GAAG,CAAC,CAACC,YAAe,CAAA;YAC3D,GAAGA,SAAS;YACZC,MAAM;gBAACC,OAAO1B,GAAGG;YAAe;QAClC,CAAA;IAEAI,MAAM,0BAA0Be;IAEhC,OAAOvB,eAAeiB,cAAcM;AACtC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Checks if the given value conforms to a minimum studio config shape.
3
+ *
4
+ * @param value - The value to check
5
+ * @returns Whether the value is a studio config
6
+ * @internal
7
+ */ export function isStudioConfig(value) {
8
+ if (Array.isArray(value)) {
9
+ return value.every((item)=>isStudioConfig(item));
10
+ }
11
+ // Only actual properties marked as required by typescript are `projectId` and `dataset`,
12
+ // so this is a pretty weak check - but better than nothing.
13
+ if (typeof value === 'object' && value !== null) {
14
+ return 'projectId' in value && typeof value.projectId === 'string' && 'dataset' in value && typeof value.dataset === 'string';
15
+ }
16
+ return false;
17
+ }
18
+
19
+ //# sourceMappingURL=isStudioConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/config/studio/isStudioConfig.ts"],"sourcesContent":["/**\n * Checks if the given value conforms to a minimum studio config shape.\n *\n * @param value - The value to check\n * @returns Whether the value is a studio config\n * @internal\n */\nexport function isStudioConfig(value: unknown): boolean {\n if (Array.isArray(value)) {\n return value.every((item) => isStudioConfig(item))\n }\n\n // Only actual properties marked as required by typescript are `projectId` and `dataset`,\n // so this is a pretty weak check - but better than nothing.\n if (typeof value === 'object' && value !== null) {\n return (\n 'projectId' in value &&\n typeof value.projectId === 'string' &&\n 'dataset' in value &&\n typeof value.dataset === 'string'\n )\n }\n\n return false\n}\n"],"names":["isStudioConfig","value","Array","isArray","every","item","projectId","dataset"],"mappings":"AAAA;;;;;;CAMC,GACD,OAAO,SAASA,eAAeC,KAAc;IAC3C,IAAIC,MAAMC,OAAO,CAACF,QAAQ;QACxB,OAAOA,MAAMG,KAAK,CAAC,CAACC,OAASL,eAAeK;IAC9C;IAEA,yFAAyF;IACzF,4DAA4D;IAC5D,IAAI,OAAOJ,UAAU,YAAYA,UAAU,MAAM;QAC/C,OACE,eAAeA,SACf,OAAOA,MAAMK,SAAS,KAAK,YAC3B,aAAaL,SACb,OAAOA,MAAMM,OAAO,KAAK;IAE7B;IAEA,OAAO;AACT"}
@@ -1,51 +1,25 @@
1
- import { pathToFileURL } from 'node:url';
2
1
  import { isMainThread, parentPort, workerData } from 'node:worker_threads';
3
- import { moduleResolve } from 'import-meta-resolve';
4
2
  import { z } from 'zod';
3
+ import { subdebug } from '../../debug.js';
5
4
  import { doImport } from '../../util/doImport.js';
6
- import { getEmptyAuth } from '../../util/getEmptyAuth.js';
7
5
  import { safeStructuredClone } from '../../util/safeStructuredClone.js';
6
+ import { getStudioWorkspaces } from './getStudioWorkspaces.js';
8
7
  if (isMainThread || !parentPort) {
9
8
  throw new Error('Should only be run in a worker!');
10
9
  }
10
+ const debug = subdebug('readStudioConfig.worker');
11
11
  const { configPath, resolvePlugins } = z.object({
12
12
  configPath: z.string(),
13
13
  resolvePlugins: z.boolean()
14
14
  }).parse(workerData);
15
+ debug('Parsing config path %s', configPath);
15
16
  let { default: config } = await doImport(configPath);
17
+ debug('Imported config %o', config);
16
18
  if (resolvePlugins) {
17
- // If we need to resolve plugins, we need to import and use the `resolveConfig`
18
- // function from the `sanity` package. This package should be installed in the users'
19
- // studio project, not as part of the CLI - so we need to resolve the full path of the
20
- // Sanity package relative to the studio.
21
- const configUrl = pathToFileURL(configPath);
22
- const sanityUrl = await moduleResolve('sanity', configUrl);
23
- const { resolveConfig } = await doImport(sanityUrl.href);
24
- if (typeof resolveConfig !== 'function') {
25
- throw new TypeError('Expected `resolveConfig` from `sanity` to be a function');
26
- }
27
- // We'll want to use some observable tooling, but we'd prefer to use something
28
- // compatible with what the studio uses internally, thus try to load RxJS from the
29
- // sanity module path instead of installing it as a dependency locally.
30
- const rxjsPath = (await moduleResolve('rxjs', sanityUrl)).href;
31
- const { firstValueFrom, of } = await doImport(rxjsPath);
32
- // We will also want to stub out some configuration - we don't need to resolve the
33
- // users' logged in state, for instance - so let's disable the auth implementation.
34
- const workspaces = Array.isArray(config) ? config : [
35
- config
36
- ];
37
- workspaces.map((workspace)=>{
38
- workspace.auth = {
39
- state: of(getEmptyAuth())
40
- };
41
- });
42
- config = await firstValueFrom(resolveConfig(config));
19
+ debug('Resolving workspaces');
20
+ config = await getStudioWorkspaces(configPath);
21
+ debug('Resolved workspaces %o', config);
43
22
  }
44
23
  parentPort.postMessage(safeStructuredClone(config));
45
- // Explicitly exit the process to avoid any dangling references from keeping
46
- // the process alive after resolving it's main task
47
- setImmediate(()=>{
48
- process.exit(1);
49
- });
50
24
 
51
25
  //# sourceMappingURL=readStudioConfig.worker.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/config/studio/readStudioConfig.worker.ts"],"sourcesContent":["import {pathToFileURL} from 'node:url'\nimport {isMainThread, parentPort, workerData} from 'node:worker_threads'\n\nimport {moduleResolve} from 'import-meta-resolve'\nimport {z} from 'zod'\n\nimport {doImport} from '../../util/doImport.js'\nimport {getEmptyAuth} from '../../util/getEmptyAuth.js'\nimport {safeStructuredClone} from '../../util/safeStructuredClone.js'\n\nif (isMainThread || !parentPort) {\n throw new Error('Should only be run in a worker!')\n}\n\nconst {configPath, resolvePlugins} = z\n .object({configPath: z.string(), resolvePlugins: z.boolean()})\n .parse(workerData)\n\nlet {default: config} = await doImport(configPath)\n\nif (resolvePlugins) {\n // If we need to resolve plugins, we need to import and use the `resolveConfig`\n // function from the `sanity` package. This package should be installed in the users'\n // studio project, not as part of the CLI - so we need to resolve the full path of the\n // Sanity package relative to the studio.\n const configUrl = pathToFileURL(configPath)\n\n const sanityUrl = await moduleResolve('sanity', configUrl)\n const {resolveConfig} = await doImport(sanityUrl.href)\n if (typeof resolveConfig !== 'function') {\n throw new TypeError('Expected `resolveConfig` from `sanity` to be a function')\n }\n\n // We'll want to use some observable tooling, but we'd prefer to use something\n // compatible with what the studio uses internally, thus try to load RxJS from the\n // sanity module path instead of installing it as a dependency locally.\n const rxjsPath = (await moduleResolve('rxjs', sanityUrl)).href\n const {firstValueFrom, of} = await doImport(rxjsPath)\n\n // We will also want to stub out some configuration - we don't need to resolve the\n // users' logged in state, for instance - so let's disable the auth implementation.\n const workspaces = Array.isArray(config) ? config : [config]\n workspaces.map((workspace) => {\n workspace.auth = {state: of(getEmptyAuth())}\n })\n\n config = await firstValueFrom(resolveConfig(config))\n}\n\nparentPort.postMessage(safeStructuredClone(config))\n\n// Explicitly exit the process to avoid any dangling references from keeping\n// the process alive after resolving it's main task\nsetImmediate(() => {\n process.exit(1)\n})\n"],"names":["pathToFileURL","isMainThread","parentPort","workerData","moduleResolve","z","doImport","getEmptyAuth","safeStructuredClone","Error","configPath","resolvePlugins","object","string","boolean","parse","default","config","configUrl","sanityUrl","resolveConfig","href","TypeError","rxjsPath","firstValueFrom","of","workspaces","Array","isArray","map","workspace","auth","state","postMessage","setImmediate","process","exit"],"mappings":"AAAA,SAAQA,aAAa,QAAO,WAAU;AACtC,SAAQC,YAAY,EAAEC,UAAU,EAAEC,UAAU,QAAO,sBAAqB;AAExE,SAAQC,aAAa,QAAO,sBAAqB;AACjD,SAAQC,CAAC,QAAO,MAAK;AAErB,SAAQC,QAAQ,QAAO,yBAAwB;AAC/C,SAAQC,YAAY,QAAO,6BAA4B;AACvD,SAAQC,mBAAmB,QAAO,oCAAmC;AAErE,IAAIP,gBAAgB,CAACC,YAAY;IAC/B,MAAM,IAAIO,MAAM;AAClB;AAEA,MAAM,EAACC,UAAU,EAAEC,cAAc,EAAC,GAAGN,EAClCO,MAAM,CAAC;IAACF,YAAYL,EAAEQ,MAAM;IAAIF,gBAAgBN,EAAES,OAAO;AAAE,GAC3DC,KAAK,CAACZ;AAET,IAAI,EAACa,SAASC,MAAM,EAAC,GAAG,MAAMX,SAASI;AAEvC,IAAIC,gBAAgB;IAClB,+EAA+E;IAC/E,qFAAqF;IACrF,sFAAsF;IACtF,yCAAyC;IACzC,MAAMO,YAAYlB,cAAcU;IAEhC,MAAMS,YAAY,MAAMf,cAAc,UAAUc;IAChD,MAAM,EAACE,aAAa,EAAC,GAAG,MAAMd,SAASa,UAAUE,IAAI;IACrD,IAAI,OAAOD,kBAAkB,YAAY;QACvC,MAAM,IAAIE,UAAU;IACtB;IAEA,8EAA8E;IAC9E,kFAAkF;IAClF,uEAAuE;IACvE,MAAMC,WAAW,AAAC,CAAA,MAAMnB,cAAc,QAAQe,UAAS,EAAGE,IAAI;IAC9D,MAAM,EAACG,cAAc,EAAEC,EAAE,EAAC,GAAG,MAAMnB,SAASiB;IAE5C,kFAAkF;IAClF,mFAAmF;IACnF,MAAMG,aAAaC,MAAMC,OAAO,CAACX,UAAUA,SAAS;QAACA;KAAO;IAC5DS,WAAWG,GAAG,CAAC,CAACC;QACdA,UAAUC,IAAI,GAAG;YAACC,OAAOP,GAAGlB;QAAe;IAC7C;IAEAU,SAAS,MAAMO,eAAeJ,cAAcH;AAC9C;AAEAf,WAAW+B,WAAW,CAACzB,oBAAoBS;AAE3C,4EAA4E;AAC5E,mDAAmD;AACnDiB,aAAa;IACXC,QAAQC,IAAI,CAAC;AACf"}
1
+ {"version":3,"sources":["../../../src/config/studio/readStudioConfig.worker.ts"],"sourcesContent":["import {isMainThread, parentPort, workerData} from 'node:worker_threads'\n\nimport {z} from 'zod'\n\nimport {subdebug} from '../../debug.js'\nimport {doImport} from '../../util/doImport.js'\nimport {safeStructuredClone} from '../../util/safeStructuredClone.js'\nimport {getStudioWorkspaces} from './getStudioWorkspaces.js'\n\nif (isMainThread || !parentPort) {\n throw new Error('Should only be run in a worker!')\n}\n\nconst debug = subdebug('readStudioConfig.worker')\n\nconst {configPath, resolvePlugins} = z\n .object({configPath: z.string(), resolvePlugins: z.boolean()})\n .parse(workerData)\n\ndebug('Parsing config path %s', configPath)\n\nlet {default: config} = await doImport(configPath)\n\ndebug('Imported config %o', config)\n\nif (resolvePlugins) {\n debug('Resolving workspaces')\n config = await getStudioWorkspaces(configPath)\n debug('Resolved workspaces %o', config)\n}\n\nparentPort.postMessage(safeStructuredClone(config))\n"],"names":["isMainThread","parentPort","workerData","z","subdebug","doImport","safeStructuredClone","getStudioWorkspaces","Error","debug","configPath","resolvePlugins","object","string","boolean","parse","default","config","postMessage"],"mappings":"AAAA,SAAQA,YAAY,EAAEC,UAAU,EAAEC,UAAU,QAAO,sBAAqB;AAExE,SAAQC,CAAC,QAAO,MAAK;AAErB,SAAQC,QAAQ,QAAO,iBAAgB;AACvC,SAAQC,QAAQ,QAAO,yBAAwB;AAC/C,SAAQC,mBAAmB,QAAO,oCAAmC;AACrE,SAAQC,mBAAmB,QAAO,2BAA0B;AAE5D,IAAIP,gBAAgB,CAACC,YAAY;IAC/B,MAAM,IAAIO,MAAM;AAClB;AAEA,MAAMC,QAAQL,SAAS;AAEvB,MAAM,EAACM,UAAU,EAAEC,cAAc,EAAC,GAAGR,EAClCS,MAAM,CAAC;IAACF,YAAYP,EAAEU,MAAM;IAAIF,gBAAgBR,EAAEW,OAAO;AAAE,GAC3DC,KAAK,CAACb;AAETO,MAAM,0BAA0BC;AAEhC,IAAI,EAACM,SAASC,MAAM,EAAC,GAAG,MAAMZ,SAASK;AAEvCD,MAAM,sBAAsBQ;AAE5B,IAAIN,gBAAgB;IAClBF,MAAM;IACNQ,SAAS,MAAMV,oBAAoBG;IACnCD,MAAM,0BAA0BQ;AAClC;AAEAhB,WAAWiB,WAAW,CAACZ,oBAAoBW"}
@@ -2,11 +2,12 @@ import { basename } from 'node:path';
2
2
  import { findPathForFiles } from './findConfigsPaths.js';
3
3
  import { isSanityV2StudioRoot } from './isSanityV2StudioRoot.js';
4
4
  /**
5
- * Resolves to a string containing the found config path, or `false` if not found.
6
- * Throws if Sanity v2 studio root is found.
5
+ * Resolves to a string containing the found config path, otherwise throws an error.
6
+ * Also throws if Sanity v2 studio root is found.
7
7
  *
8
8
  * @param basePath - The base path to start searching from
9
- * @returns A promise that resolves to a string containing the found config path, or `undefined` if not found
9
+ * @returns A promise that resolves to a string containing the found config path
10
+ * @throws On multiple config files found, if v2 studio root found, or no config found
10
11
  * @internal
11
12
  */ export async function findStudioConfigPath(basePath) {
12
13
  if (await isSanityV2StudioRoot(basePath)) {
@@ -26,6 +27,26 @@ import { isSanityV2StudioRoot } from './isSanityV2StudioRoot.js';
26
27
  if (configPaths.length === 1) {
27
28
  return configPaths[0].path;
28
29
  }
30
+ throw new ConfigNotFoundError(`No studio config file found at ${basePath}`);
31
+ }
32
+ /**
33
+ * Tries to find the studio config path, returning `undefined` if not found.
34
+ *
35
+ * @param basePath - The base path to start searching from
36
+ * @returns A promise that resolves to a string containing the found config path, or `undefined` if not found
37
+ * @throws On errors other than config not found
38
+ * @internal
39
+ */ export async function tryFindStudioConfigPath(basePath) {
40
+ try {
41
+ return await findStudioConfigPath(basePath);
42
+ } catch (err) {
43
+ if (err instanceof ConfigNotFoundError) {
44
+ return undefined;
45
+ }
46
+ throw err;
47
+ }
48
+ }
49
+ class ConfigNotFoundError extends Error {
29
50
  }
30
51
 
31
52
  //# sourceMappingURL=findStudioConfigPath.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/config/util/findStudioConfigPath.ts"],"sourcesContent":["import {basename} from 'node:path'\n\nimport {findPathForFiles} from './findConfigsPaths.js'\nimport {isSanityV2StudioRoot} from './isSanityV2StudioRoot.js'\n\n/**\n * Resolves to a string containing the found config path, or `false` if not found.\n * Throws if Sanity v2 studio root is found.\n *\n * @param basePath - The base path to start searching from\n * @returns A promise that resolves to a string containing the found config path, or `undefined` if not found\n * @internal\n */\nexport async function findStudioConfigPath(basePath: string): Promise<string | undefined> {\n if (await isSanityV2StudioRoot(basePath)) {\n throw new Error(\n `Found 'sanity.json' at ${basePath} - Sanity Studio < v3 is no longer supported`,\n )\n }\n\n const paths = await findPathForFiles(basePath, [\n 'sanity.config.ts',\n 'sanity.config.tsx',\n 'sanity.config.js',\n 'sanity.config.jsx',\n ])\n\n const configPaths = paths.filter((path) => path.exists)\n if (configPaths.length > 1) {\n const baseNames = configPaths.map((config) => config.path).map((path) => basename(path))\n throw new Error(`Multiple studio config files found (${baseNames.join(', ')})`)\n }\n\n if (configPaths.length === 1) {\n return configPaths[0].path\n }\n}\n"],"names":["basename","findPathForFiles","isSanityV2StudioRoot","findStudioConfigPath","basePath","Error","paths","configPaths","filter","path","exists","length","baseNames","map","config","join"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,YAAW;AAElC,SAAQC,gBAAgB,QAAO,wBAAuB;AACtD,SAAQC,oBAAoB,QAAO,4BAA2B;AAE9D;;;;;;;CAOC,GACD,OAAO,eAAeC,qBAAqBC,QAAgB;IACzD,IAAI,MAAMF,qBAAqBE,WAAW;QACxC,MAAM,IAAIC,MACR,CAAC,uBAAuB,EAAED,SAAS,4CAA4C,CAAC;IAEpF;IAEA,MAAME,QAAQ,MAAML,iBAAiBG,UAAU;QAC7C;QACA;QACA;QACA;KACD;IAED,MAAMG,cAAcD,MAAME,MAAM,CAAC,CAACC,OAASA,KAAKC,MAAM;IACtD,IAAIH,YAAYI,MAAM,GAAG,GAAG;QAC1B,MAAMC,YAAYL,YAAYM,GAAG,CAAC,CAACC,SAAWA,OAAOL,IAAI,EAAEI,GAAG,CAAC,CAACJ,OAAST,SAASS;QAClF,MAAM,IAAIJ,MAAM,CAAC,oCAAoC,EAAEO,UAAUG,IAAI,CAAC,MAAM,CAAC,CAAC;IAChF;IAEA,IAAIR,YAAYI,MAAM,KAAK,GAAG;QAC5B,OAAOJ,WAAW,CAAC,EAAE,CAACE,IAAI;IAC5B;AACF"}
1
+ {"version":3,"sources":["../../../src/config/util/findStudioConfigPath.ts"],"sourcesContent":["import {basename} from 'node:path'\n\nimport {findPathForFiles} from './findConfigsPaths.js'\nimport {isSanityV2StudioRoot} from './isSanityV2StudioRoot.js'\n\n/**\n * Resolves to a string containing the found config path, otherwise throws an error.\n * Also throws if Sanity v2 studio root is found.\n *\n * @param basePath - The base path to start searching from\n * @returns A promise that resolves to a string containing the found config path\n * @throws On multiple config files found, if v2 studio root found, or no config found\n * @internal\n */\nexport async function findStudioConfigPath(basePath: string): Promise<string> {\n if (await isSanityV2StudioRoot(basePath)) {\n throw new Error(\n `Found 'sanity.json' at ${basePath} - Sanity Studio < v3 is no longer supported`,\n )\n }\n\n const paths = await findPathForFiles(basePath, [\n 'sanity.config.ts',\n 'sanity.config.tsx',\n 'sanity.config.js',\n 'sanity.config.jsx',\n ])\n\n const configPaths = paths.filter((path) => path.exists)\n if (configPaths.length > 1) {\n const baseNames = configPaths.map((config) => config.path).map((path) => basename(path))\n throw new Error(`Multiple studio config files found (${baseNames.join(', ')})`)\n }\n\n if (configPaths.length === 1) {\n return configPaths[0].path\n }\n\n throw new ConfigNotFoundError(`No studio config file found at ${basePath}`)\n}\n\n/**\n * Tries to find the studio config path, returning `undefined` if not found.\n *\n * @param basePath - The base path to start searching from\n * @returns A promise that resolves to a string containing the found config path, or `undefined` if not found\n * @throws On errors other than config not found\n * @internal\n */\nexport async function tryFindStudioConfigPath(basePath: string): Promise<string | undefined> {\n try {\n return await findStudioConfigPath(basePath)\n } catch (err) {\n if (err instanceof ConfigNotFoundError) {\n return undefined\n }\n throw err\n }\n}\n\nclass ConfigNotFoundError extends Error {}\n"],"names":["basename","findPathForFiles","isSanityV2StudioRoot","findStudioConfigPath","basePath","Error","paths","configPaths","filter","path","exists","length","baseNames","map","config","join","ConfigNotFoundError","tryFindStudioConfigPath","err","undefined"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,YAAW;AAElC,SAAQC,gBAAgB,QAAO,wBAAuB;AACtD,SAAQC,oBAAoB,QAAO,4BAA2B;AAE9D;;;;;;;;CAQC,GACD,OAAO,eAAeC,qBAAqBC,QAAgB;IACzD,IAAI,MAAMF,qBAAqBE,WAAW;QACxC,MAAM,IAAIC,MACR,CAAC,uBAAuB,EAAED,SAAS,4CAA4C,CAAC;IAEpF;IAEA,MAAME,QAAQ,MAAML,iBAAiBG,UAAU;QAC7C;QACA;QACA;QACA;KACD;IAED,MAAMG,cAAcD,MAAME,MAAM,CAAC,CAACC,OAASA,KAAKC,MAAM;IACtD,IAAIH,YAAYI,MAAM,GAAG,GAAG;QAC1B,MAAMC,YAAYL,YAAYM,GAAG,CAAC,CAACC,SAAWA,OAAOL,IAAI,EAAEI,GAAG,CAAC,CAACJ,OAAST,SAASS;QAClF,MAAM,IAAIJ,MAAM,CAAC,oCAAoC,EAAEO,UAAUG,IAAI,CAAC,MAAM,CAAC,CAAC;IAChF;IAEA,IAAIR,YAAYI,MAAM,KAAK,GAAG;QAC5B,OAAOJ,WAAW,CAAC,EAAE,CAACE,IAAI;IAC5B;IAEA,MAAM,IAAIO,oBAAoB,CAAC,+BAA+B,EAAEZ,UAAU;AAC5E;AAEA;;;;;;;CAOC,GACD,OAAO,eAAea,wBAAwBb,QAAgB;IAC5D,IAAI;QACF,OAAO,MAAMD,qBAAqBC;IACpC,EAAE,OAAOc,KAAK;QACZ,IAAIA,eAAeF,qBAAqB;YACtC,OAAOG;QACT;QACA,MAAMD;IACR;AACF;AAEA,MAAMF,4BAA4BX;AAAO"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/config/util/recursivelyResolveProjectRoot.ts"],"sourcesContent":["import {dirname, resolve} from 'node:path'\n\n/**\n * Result of finding a project configuration\n *\n * @internal\n */\nexport interface ProjectRootResult {\n directory: string\n /**\n * Path to the project configuration file, if found.\n */\n path: string\n /**\n * Type of project root.\n */\n type: 'app' | 'studio'\n}\n\n/**\n * Generic recursive search function for project configuration files.\n *\n * @param basePath - The base path to start searching from\n * @param findConfigFn - Function that looks for config files in a given directory\n * @param projectType - The type of project ('app' | 'studio')\n * @param iterations - Current iteration count, passed internally to prevent infinite recursion\n * @returns A promise that resolves to an object if config is found, false otherwise\n * @internal\n */\nexport async function recursivelyResolveProjectRoot(\n basePath: string,\n findConfigFn: (path: string) => Promise<string | undefined>,\n projectType: 'app' | 'studio',\n iterations = 0,\n): Promise<false | ProjectRootResult> {\n const configPath = await findConfigFn(basePath)\n\n if (configPath) {\n return {\n directory: dirname(configPath),\n path: configPath,\n type: projectType,\n }\n }\n\n const parentDir = resolve(basePath, '..')\n if (parentDir === basePath || iterations > 50) {\n // Reached root (or max depth), give up\n return false\n }\n\n return recursivelyResolveProjectRoot(parentDir, findConfigFn, projectType, iterations + 1)\n}\n"],"names":["dirname","resolve","recursivelyResolveProjectRoot","basePath","findConfigFn","projectType","iterations","configPath","directory","path","type","parentDir"],"mappings":"AAAA,SAAQA,OAAO,EAAEC,OAAO,QAAO,YAAW;AAmB1C;;;;;;;;;CASC,GACD,OAAO,eAAeC,8BACpBC,QAAgB,EAChBC,YAA2D,EAC3DC,WAA6B,EAC7BC,aAAa,CAAC;IAEd,MAAMC,aAAa,MAAMH,aAAaD;IAEtC,IAAII,YAAY;QACd,OAAO;YACLC,WAAWR,QAAQO;YACnBE,MAAMF;YACNG,MAAML;QACR;IACF;IAEA,MAAMM,YAAYV,QAAQE,UAAU;IACpC,IAAIQ,cAAcR,YAAYG,aAAa,IAAI;QAC7C,uCAAuC;QACvC,OAAO;IACT;IAEA,OAAOJ,8BAA8BS,WAAWP,cAAcC,aAAaC,aAAa;AAC1F"}
1
+ {"version":3,"sources":["../../../src/config/util/recursivelyResolveProjectRoot.ts"],"sourcesContent":["import {dirname, resolve} from 'node:path'\n\n/**\n * Result of finding a project configuration\n *\n * @public\n */\nexport interface ProjectRootResult {\n directory: string\n /**\n * Path to the project configuration file, if found.\n */\n path: string\n /**\n * Type of project root.\n */\n type: 'app' | 'studio'\n}\n\n/**\n * Generic recursive search function for project configuration files.\n *\n * @param basePath - The base path to start searching from\n * @param findConfigFn - Function that looks for config files in a given directory\n * @param projectType - The type of project ('app' | 'studio')\n * @param iterations - Current iteration count, passed internally to prevent infinite recursion\n * @returns A promise that resolves to an object if config is found, false otherwise\n * @internal\n */\nexport async function recursivelyResolveProjectRoot(\n basePath: string,\n findConfigFn: (path: string) => Promise<string | undefined>,\n projectType: 'app' | 'studio',\n iterations = 0,\n): Promise<false | ProjectRootResult> {\n const configPath = await findConfigFn(basePath)\n\n if (configPath) {\n return {\n directory: dirname(configPath),\n path: configPath,\n type: projectType,\n }\n }\n\n const parentDir = resolve(basePath, '..')\n if (parentDir === basePath || iterations > 50) {\n // Reached root (or max depth), give up\n return false\n }\n\n return recursivelyResolveProjectRoot(parentDir, findConfigFn, projectType, iterations + 1)\n}\n"],"names":["dirname","resolve","recursivelyResolveProjectRoot","basePath","findConfigFn","projectType","iterations","configPath","directory","path","type","parentDir"],"mappings":"AAAA,SAAQA,OAAO,EAAEC,OAAO,QAAO,YAAW;AAmB1C;;;;;;;;;CASC,GACD,OAAO,eAAeC,8BACpBC,QAAgB,EAChBC,YAA2D,EAC3DC,WAA6B,EAC7BC,aAAa,CAAC;IAEd,MAAMC,aAAa,MAAMH,aAAaD;IAEtC,IAAII,YAAY;QACd,OAAO;YACLC,WAAWR,QAAQO;YACnBE,MAAMF;YACNG,MAAML;QACR;IACF;IAEA,MAAMM,YAAYV,QAAQE,UAAU;IACpC,IAAIQ,cAAcR,YAAYG,aAAa,IAAI;QAC7C,uCAAuC;QACvC,OAAO;IACT;IAEA,OAAOJ,8BAA8BS,WAAWP,cAAcC,aAAaC,aAAa;AAC1F"}
@@ -0,0 +1,18 @@
1
+ import { CLIError } from '@oclif/core/errors';
2
+ /**
3
+ * Error thrown when a prompt is attempted in a non-interactive environment
4
+ * (e.g., CI, non-TTY, piped stdin). Callers can catch this specific error
5
+ * to provide appropriate fallback behavior.
6
+ *
7
+ * Extends `CLIError` to suppress stack traces in user-facing output.
8
+ */ export class NonInteractiveError extends CLIError {
9
+ constructor(promptName){
10
+ super(`Cannot run "${promptName}" prompt in a non-interactive environment. ` + 'Provide the required value via flags or environment variables, or run in an interactive terminal.', {
11
+ code: 'NON_INTERACTIVE',
12
+ exit: 1
13
+ });
14
+ this.name = 'NonInteractiveError';
15
+ }
16
+ }
17
+
18
+ //# sourceMappingURL=NonInteractiveError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/errors/NonInteractiveError.ts"],"sourcesContent":["import {CLIError} from '@oclif/core/errors'\n\n/**\n * Error thrown when a prompt is attempted in a non-interactive environment\n * (e.g., CI, non-TTY, piped stdin). Callers can catch this specific error\n * to provide appropriate fallback behavior.\n *\n * Extends `CLIError` to suppress stack traces in user-facing output.\n */\nexport class NonInteractiveError extends CLIError {\n constructor(promptName: string) {\n super(\n `Cannot run \"${promptName}\" prompt in a non-interactive environment. ` +\n 'Provide the required value via flags or environment variables, or run in an interactive terminal.',\n {code: 'NON_INTERACTIVE', exit: 1},\n )\n this.name = 'NonInteractiveError'\n }\n}\n"],"names":["CLIError","NonInteractiveError","promptName","code","exit","name"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,qBAAoB;AAE3C;;;;;;CAMC,GACD,OAAO,MAAMC,4BAA4BD;IACvC,YAAYE,UAAkB,CAAE;QAC9B,KAAK,CACH,CAAC,YAAY,EAAEA,WAAW,2CAA2C,CAAC,GACpE,qGACF;YAACC,MAAM;YAAmBC,MAAM;QAAC;QAEnC,IAAI,CAACC,IAAI,GAAG;IACd;AACF"}
@@ -1,4 +1,4 @@
1
- import { isRecord } from './isRecord.js';
1
+ import { isRecord } from '../util/isRecord.js';
2
2
  /**
3
3
  * Error thrown when a file or directory is not found
4
4
  *
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/errors/NotFoundError.ts"],"sourcesContent":["import {isRecord} from '../util/isRecord.js'\n\n/**\n * Error thrown when a file or directory is not found\n *\n * `code` is always `ENOENT` to mirror Node.js behavior when a file is not found\n *\n * @internal\n */\nexport class NotFoundError extends Error {\n code = 'ENOENT'\n path?: string\n\n constructor(message: string, path?: string) {\n super(message)\n this.path = path\n this.name = 'NotFoundError'\n }\n}\n\n/**\n * Returns whether or not the given error is a `NotFoundError`\n *\n * @param err - The error to check\n * @returns `true` if the error is a `NotFoundError`, `false` otherwise\n * @internal\n */\nexport function isNotFoundError(err: unknown): err is NotFoundError {\n return (\n isRecord(err) &&\n 'name' in err &&\n err.name === 'NotFoundError' &&\n 'code' in err &&\n err.code === 'ENOENT' &&\n 'message' in err &&\n typeof err.message === 'string'\n )\n}\n"],"names":["isRecord","NotFoundError","Error","code","path","message","name","isNotFoundError","err"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,sBAAqB;AAE5C;;;;;;CAMC,GACD,OAAO,MAAMC,sBAAsBC;IACjCC,OAAO,SAAQ;IACfC,KAAa;IAEb,YAAYC,OAAe,EAAED,IAAa,CAAE;QAC1C,KAAK,CAACC;QACN,IAAI,CAACD,IAAI,GAAGA;QACZ,IAAI,CAACE,IAAI,GAAG;IACd;AACF;AAEA;;;;;;CAMC,GACD,OAAO,SAASC,gBAAgBC,GAAY;IAC1C,OACER,SAASQ,QACT,UAAUA,OACVA,IAAIF,IAAI,KAAK,mBACb,UAAUE,OACVA,IAAIL,IAAI,KAAK,YACb,aAAaK,OACb,OAAOA,IAAIH,OAAO,KAAK;AAE3B"}
@@ -0,0 +1,35 @@
1
+ import { CLIError } from '@oclif/core/errors';
2
+ import { isRecord } from '../util/isRecord.js';
3
+ /**
4
+ * Error thrown when a project root directory cannot be found.
5
+ *
6
+ * This occurs when the CLI is run outside a Sanity project directory
7
+ * (one containing `sanity.config.(ts|js)` or `sanity.cli.(ts|js)`).
8
+ *
9
+ * Extends `CLIError` to suppress stack traces in user-facing output.
10
+ *
11
+ * @internal
12
+ */ export class ProjectRootNotFoundError extends CLIError {
13
+ constructor(message, options){
14
+ super(message, {
15
+ code: 'PROJECT_ROOT_NOT_FOUND',
16
+ exit: 1,
17
+ suggestions: options?.suggestions
18
+ });
19
+ this.name = 'ProjectRootNotFoundError';
20
+ if (options?.cause) {
21
+ this.cause = options.cause;
22
+ }
23
+ }
24
+ }
25
+ /**
26
+ * Returns whether or not the given error is a `ProjectRootNotFoundError`
27
+ *
28
+ * @param err - The error to check
29
+ * @returns `true` if the error is a `ProjectRootNotFoundError`, `false` otherwise
30
+ * @internal
31
+ */ export function isProjectRootNotFoundError(err) {
32
+ return isRecord(err) && 'name' in err && err.name === 'ProjectRootNotFoundError' && 'code' in err && err.code === 'PROJECT_ROOT_NOT_FOUND' && 'message' in err && typeof err.message === 'string';
33
+ }
34
+
35
+ //# sourceMappingURL=ProjectRootNotFoundError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/errors/ProjectRootNotFoundError.ts"],"sourcesContent":["import {CLIError} from '@oclif/core/errors'\n\nimport {isRecord} from '../util/isRecord.js'\n\n/**\n * Error thrown when a project root directory cannot be found.\n *\n * This occurs when the CLI is run outside a Sanity project directory\n * (one containing `sanity.config.(ts|js)` or `sanity.cli.(ts|js)`).\n *\n * Extends `CLIError` to suppress stack traces in user-facing output.\n *\n * @internal\n */\nexport class ProjectRootNotFoundError extends CLIError {\n constructor(message: string, options?: {cause?: Error; suggestions?: string[]}) {\n super(message, {code: 'PROJECT_ROOT_NOT_FOUND', exit: 1, suggestions: options?.suggestions})\n this.name = 'ProjectRootNotFoundError'\n if (options?.cause) {\n this.cause = options.cause\n }\n }\n}\n\n/**\n * Returns whether or not the given error is a `ProjectRootNotFoundError`\n *\n * @param err - The error to check\n * @returns `true` if the error is a `ProjectRootNotFoundError`, `false` otherwise\n * @internal\n */\nexport function isProjectRootNotFoundError(err: unknown): err is ProjectRootNotFoundError {\n return (\n isRecord(err) &&\n 'name' in err &&\n err.name === 'ProjectRootNotFoundError' &&\n 'code' in err &&\n err.code === 'PROJECT_ROOT_NOT_FOUND' &&\n 'message' in err &&\n typeof err.message === 'string'\n )\n}\n"],"names":["CLIError","isRecord","ProjectRootNotFoundError","message","options","code","exit","suggestions","name","cause","isProjectRootNotFoundError","err"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,qBAAoB;AAE3C,SAAQC,QAAQ,QAAO,sBAAqB;AAE5C;;;;;;;;;CASC,GACD,OAAO,MAAMC,iCAAiCF;IAC5C,YAAYG,OAAe,EAAEC,OAAiD,CAAE;QAC9E,KAAK,CAACD,SAAS;YAACE,MAAM;YAA0BC,MAAM;YAAGC,aAAaH,SAASG;QAAW;QAC1F,IAAI,CAACC,IAAI,GAAG;QACZ,IAAIJ,SAASK,OAAO;YAClB,IAAI,CAACA,KAAK,GAAGL,QAAQK,KAAK;QAC5B;IACF;AACF;AAEA;;;;;;CAMC,GACD,OAAO,SAASC,2BAA2BC,GAAY;IACrD,OACEV,SAASU,QACT,UAAUA,OACVA,IAAIH,IAAI,KAAK,8BACb,UAAUG,OACVA,IAAIN,IAAI,KAAK,4BACb,aAAaM,OACb,OAAOA,IAAIR,OAAO,KAAK;AAE3B"}