@sanity/cli-core 0.1.0-alpha.9 → 1.0.1

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 (108) hide show
  1. package/dist/SanityCommand.js +81 -5
  2. package/dist/SanityCommand.js.map +1 -1
  3. package/dist/_exports/package-manager.d.ts +33 -0
  4. package/dist/_exports/package-manager.js +3 -0
  5. package/dist/_exports/package-manager.js.map +1 -0
  6. package/dist/_exports/request.d.ts +79 -0
  7. package/dist/_exports/request.js +7 -0
  8. package/dist/_exports/request.js.map +1 -0
  9. package/dist/_exports/ux.d.ts +61 -26
  10. package/dist/_exports/ux.js +1 -0
  11. package/dist/_exports/ux.js.map +1 -1
  12. package/dist/config/cli/getCliConfig.js +33 -33
  13. package/dist/config/cli/getCliConfig.js.map +1 -1
  14. package/dist/config/cli/getCliConfigSync.js +1 -1
  15. package/dist/config/cli/getCliConfigSync.js.map +1 -1
  16. package/dist/config/cli/schemas.js +7 -0
  17. package/dist/config/cli/schemas.js.map +1 -1
  18. package/dist/config/cli/types/cliConfig.js.map +1 -1
  19. package/dist/config/findProjectRoot.js +6 -2
  20. package/dist/config/findProjectRoot.js.map +1 -1
  21. package/dist/config/findProjectRootSync.js +7 -3
  22. package/dist/config/findProjectRootSync.js.map +1 -1
  23. package/dist/config/studio/getStudioWorkspaces.js +14 -1
  24. package/dist/config/studio/getStudioWorkspaces.js.map +1 -1
  25. package/dist/config/studio/readStudioConfig.worker.js +6 -5
  26. package/dist/config/studio/readStudioConfig.worker.js.map +1 -1
  27. package/dist/errors/NonInteractiveError.js +18 -0
  28. package/dist/errors/NonInteractiveError.js.map +1 -0
  29. package/dist/{util → errors}/NotFoundError.js +1 -1
  30. package/dist/errors/NotFoundError.js.map +1 -0
  31. package/dist/errors/ProjectRootNotFoundError.js +35 -0
  32. package/dist/errors/ProjectRootNotFoundError.js.map +1 -0
  33. package/dist/index.d.ts +939 -5689
  34. package/dist/index.js +8 -14
  35. package/dist/index.js.map +1 -1
  36. package/dist/loaders/studio/studioWorkerLoader.worker.js +102 -23
  37. package/dist/loaders/studio/studioWorkerLoader.worker.js.map +1 -1
  38. package/dist/loaders/studio/studioWorkerTask.js +18 -27
  39. package/dist/loaders/studio/studioWorkerTask.js.map +1 -1
  40. package/dist/loaders/tsx/tsxWorkerLoader.worker.js +3 -4
  41. package/dist/loaders/tsx/tsxWorkerLoader.worker.js.map +1 -1
  42. package/dist/loaders/tsx/tsxWorkerTask.js +4 -34
  43. package/dist/loaders/tsx/tsxWorkerTask.js.map +1 -1
  44. package/dist/request/createRequester.js +83 -0
  45. package/dist/request/createRequester.js.map +1 -0
  46. package/dist/services/apiClient.js +7 -3
  47. package/dist/services/apiClient.js.map +1 -1
  48. package/dist/services/cliUserConfig.js +5 -5
  49. package/dist/services/cliUserConfig.js.map +1 -1
  50. package/dist/services/getCliToken.js +2 -2
  51. package/dist/services/getCliToken.js.map +1 -1
  52. package/dist/util/doImport.js +2 -1
  53. package/dist/util/doImport.js.map +1 -1
  54. package/dist/util/environment/mockBrowserEnvironment.js +1 -0
  55. package/dist/util/environment/mockBrowserEnvironment.js.map +1 -1
  56. package/dist/util/getCliTelemetry.js +6 -8
  57. package/dist/util/getCliTelemetry.js.map +1 -1
  58. package/dist/util/getSanityUrl.js +4 -3
  59. package/dist/util/getSanityUrl.js.map +1 -1
  60. package/dist/util/importModule.js +32 -0
  61. package/dist/util/importModule.js.map +1 -0
  62. package/dist/util/isInteractive.js +1 -1
  63. package/dist/util/isInteractive.js.map +1 -1
  64. package/dist/util/packageManager.js +55 -0
  65. package/dist/util/packageManager.js.map +1 -0
  66. package/dist/util/promisifyWorker.js +72 -0
  67. package/dist/util/promisifyWorker.js.map +1 -0
  68. package/dist/util/readPackageJson.js +74 -0
  69. package/dist/util/readPackageJson.js.map +1 -0
  70. package/dist/ux/prompts.js +49 -1
  71. package/dist/ux/prompts.js.map +1 -1
  72. package/package.json +44 -40
  73. package/dist/_exports/tree.d.ts +0 -47
  74. package/dist/_exports/tree.js +0 -3
  75. package/dist/_exports/tree.js.map +0 -1
  76. package/dist/config/cli/getCliConfig.worker.js +0 -15
  77. package/dist/config/cli/getCliConfig.worker.js.map +0 -1
  78. package/dist/telemetry/cleanupOldTelemetryFiles.js +0 -30
  79. package/dist/telemetry/cleanupOldTelemetryFiles.js.map +0 -1
  80. package/dist/telemetry/createTelemetryStore.js +0 -95
  81. package/dist/telemetry/createTelemetryStore.js.map +0 -1
  82. package/dist/telemetry/createTraceId.js +0 -10
  83. package/dist/telemetry/createTraceId.js.map +0 -1
  84. package/dist/telemetry/findTelemetryFiles.js +0 -36
  85. package/dist/telemetry/findTelemetryFiles.js.map +0 -1
  86. package/dist/telemetry/flushTelemetryFiles.js +0 -107
  87. package/dist/telemetry/flushTelemetryFiles.js.map +0 -1
  88. package/dist/telemetry/generateTelemetryFilePath.js +0 -30
  89. package/dist/telemetry/generateTelemetryFilePath.js.map +0 -1
  90. package/dist/telemetry/logger.js +0 -54
  91. package/dist/telemetry/logger.js.map +0 -1
  92. package/dist/telemetry/telemetryStoreDebug.js +0 -7
  93. package/dist/telemetry/telemetryStoreDebug.js.map +0 -1
  94. package/dist/telemetry/trace.js +0 -150
  95. package/dist/telemetry/trace.js.map +0 -1
  96. package/dist/util/NotFoundError.js.map +0 -1
  97. package/dist/util/createExpiringConfig.js +0 -60
  98. package/dist/util/createExpiringConfig.js.map +0 -1
  99. package/dist/util/parseStringFlag.js +0 -19
  100. package/dist/util/parseStringFlag.js.map +0 -1
  101. package/dist/util/tree.js +0 -108
  102. package/dist/util/tree.js.map +0 -1
  103. package/dist/util/waitForAsync.js +0 -5
  104. package/dist/util/waitForAsync.js.map +0 -1
  105. package/dist/ux/formatObject.js +0 -9
  106. package/dist/ux/formatObject.js.map +0 -1
  107. package/dist/ux/printKeyValue.js +0 -16
  108. package/dist/ux/printKeyValue.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/config/cli/types/cliConfig.ts"],"sourcesContent":["import {type TypeGenConfig} from '@sanity/codegen'\nimport {type PluginOptions as ReactCompilerConfig} from 'babel-plugin-react-compiler'\n\nimport {type UserViteConfig} from './userViteConfig'\n\n/**\n * @public\n */\nexport interface CliConfig {\n /** The project ID and dataset the Sanity CLI should use to run its commands */\n api?: {\n dataset?: string\n projectId?: string\n }\n\n /** Configuration for custom Sanity apps built with the App SDK */\n app?: {\n /** The entrypoint for your custom app. By default, `src/App.tsx` */\n entry?: string\n /** String encoding of an icon (typically an SVG) */\n icon?: string\n /** @deprecated Use deployment.appId */\n id?: string\n /** The ID for the Sanity organization that manages this application */\n organizationId?: string\n /** The title of the custom app. Used in Dashboard and in the browser tab */\n title?: string\n }\n\n /** @deprecated Use deployment.autoUpdates */\n autoUpdates?: boolean\n\n /** Options for custom app and Studio deployments */\n deployment?: {\n /**\n * The ID for your custom app or Studio. Generated when deploying your app or Studio for the first time.\n * Get your app ID by either:\n * 1. Checking the output of `sanity deploy`, or\n * 2. Checking your project’s Studio tab at https://sanity.io/manage\n *\n * @remarks This is required for all custom app deployments, and for Studios opting in to fine grained version control.\n * {@link https://www.sanity.io/docs/studio/latest-version-of-sanity#k0896ed4574b7}\n */\n appId?: string\n /**\n * Enable automatic updates for your Studio or custom app’s Sanity dependencies.\n * {@link https://www.sanity.io/docs/studio/latest-version-of-sanity}\n */\n autoUpdates?: boolean\n }\n\n /** Define the GraphQL APIs that the CLI can deploy and interact with */\n graphql?: Array<{\n filterSuffix?: string\n generation?: 'gen1' | 'gen2' | 'gen3'\n id?: string\n nonNullDocumentFields?: boolean\n playground?: boolean\n source?: string\n tag?: string\n workspace?: string\n }>\n\n /** Configuration for the Media Library */\n mediaLibrary?: {\n /** The path to the Media Library aspects directory. When using the CLI to manage aspects, this is the directory they will be read from and written to. */\n aspectsPath?: string\n }\n\n /** Contains the property `basePath` which lets you change the top-level slug for the Studio. You typically need to set this if you embed the Studio in another application where it is one of many routes. Defaults to an empty string. */\n project?: {\n basePath?: string\n }\n\n /** Configuration options for React Compiler */\n reactCompiler?: ReactCompilerConfig\n\n /** Wraps the Studio in \\<React.StrictMode\\> root to aid in flagging potential problems related to concurrent features (startTransition, useTransition, useDeferredValue, Suspense). Can also be enabled by setting SANITY_STUDIO_REACT_STRICT_MODE=\"true\"|\"false\". It only applies to sanity dev in development mode and is ignored in sanity build and in production. Defaults to false. */\n reactStrictMode?: boolean\n\n /** Defines the hostname and port that the development server should run on. hostname defaults to localhost, and port to 3333. */\n server?: {\n hostname?: string\n port?: number\n }\n\n /** @deprecated Use deployment.appId */\n studioHost?: string\n\n /**\n * Configuration for Sanity typegen\n */\n typegen?: Partial<TypeGenConfig>\n\n /** Exposes the default Vite configuration for custom apps and the Studio so it can be changed and extended. */\n vite?: UserViteConfig\n}\n"],"names":[],"mappings":"AAKA;;CAEC,GACD,WAwFC"}
1
+ {"version":3,"sources":["../../../../src/config/cli/types/cliConfig.ts"],"sourcesContent":["import {type PluginOptions as ReactCompilerConfig} from 'babel-plugin-react-compiler'\n\nimport {type UserViteConfig} from './userViteConfig'\n\nexport interface TypeGenConfig {\n formatGeneratedCode: boolean\n generates: string\n overloadClientMethods: boolean\n path: string | string[]\n schema: string\n}\n\n/**\n * @public\n */\nexport interface CliConfig {\n /** The project ID and dataset the Sanity CLI should use to run its commands */\n api?: {\n dataset?: string\n projectId?: string\n }\n\n /** Configuration for custom Sanity apps built with the App SDK */\n app?: {\n /** The entrypoint for your custom app. By default, `src/App.tsx` */\n entry?: string\n /**\n * Path to an icon file relative to project root.\n * The file must be an SVG.\n */\n icon?: string\n /** @deprecated Use deployment.appId */\n id?: string\n /** The ID for the Sanity organization that manages this application */\n organizationId?: string\n /** The title of the custom app, as it is seen in Dashboard UI */\n title?: string\n }\n\n /** @deprecated Use deployment.autoUpdates */\n autoUpdates?: boolean\n\n /** Options for custom app and Studio deployments */\n deployment?: {\n /**\n * The ID for your custom app or Studio. Generated when deploying your app or Studio for the first time.\n * Get your app ID by either:\n * 1. Checking the output of `sanity deploy`, or\n * 2. Checking your project’s Studio tab at https://sanity.io/manage\n *\n * @remarks This is required for all custom app deployments, and for Studios opting in to fine grained version control.\n * {@link https://www.sanity.io/docs/studio/latest-version-of-sanity#k0896ed4574b7}\n */\n appId?: string\n /**\n * Enable automatic updates for your Studio or custom app’s Sanity dependencies.\n * {@link https://www.sanity.io/docs/studio/latest-version-of-sanity}\n */\n autoUpdates?: boolean\n }\n\n /** Define the GraphQL APIs that the CLI can deploy and interact with */\n graphql?: Array<{\n filterSuffix?: string\n generation?: 'gen1' | 'gen2' | 'gen3'\n id?: string\n nonNullDocumentFields?: boolean\n playground?: boolean\n source?: string\n tag?: string\n workspace?: string\n }>\n\n /** Configuration for the Media Library */\n mediaLibrary?: {\n /** The path to the Media Library aspects directory. When using the CLI to manage aspects, this is the directory they will be read from and written to. */\n aspectsPath?: string\n }\n\n /** Contains the property `basePath` which lets you change the top-level slug for the Studio. You typically need to set this if you embed the Studio in another application where it is one of many routes. Defaults to an empty string. */\n project?: {\n basePath?: string\n }\n\n /** Configuration options for React Compiler */\n reactCompiler?: ReactCompilerConfig\n\n /** Wraps the Studio in \\<React.StrictMode\\> root to aid in flagging potential problems related to concurrent features (startTransition, useTransition, useDeferredValue, Suspense). Can also be enabled by setting SANITY_STUDIO_REACT_STRICT_MODE=\"true\"|\"false\". It only applies to sanity dev in development mode and is ignored in sanity build and in production. Defaults to false. */\n reactStrictMode?: boolean\n\n /**\n * Configuration for schema extraction (`sanity schema extract`)\n */\n schemaExtraction?: {\n /**\n * Enable schema extraction as part of sanity dev and sanity build\n */\n enabled?: boolean\n\n /**\n * When true, schema fields marked as required will be non-optional in the output.\n * Defaults to `false`\n */\n enforceRequiredFields?: boolean\n\n /**\n * Output path for the extracted schema file.\n * Defaults to `schema.json` in the working directory.\n */\n path?: string\n\n /**\n * Additional glob patterns to watch for schema changes in watch mode.\n * These extend the default patterns:\n * - `sanity.config.{js,jsx,ts,tsx,mjs}`\n * - `schema*\\/**\\/*.{js,jsx,ts,tsx,mjs}`\n */\n watchPatterns?: string[]\n\n /**\n * The name of the workspace to generate a schema for. Required if your Sanity project has more than one\n * workspace.\n */\n workspace?: string\n }\n\n /** Defines the hostname and port that the development server should run on. hostname defaults to localhost, and port to 3333. */\n server?: {\n hostname?: string\n port?: number\n }\n\n /** @deprecated Use deployment.appId */\n studioHost?: string\n\n /**\n * Configuration for Sanity typegen\n */\n typegen?: Partial<TypeGenConfig> & {\n /**\n * Enable typegen as part of sanity dev and sanity build.\n * When enabled, types are generated on startup and when files change.\n * Defaults to `false`\n */\n enabled?: boolean\n }\n\n /** Exposes the default Vite configuration for custom apps and the Studio so it can be changed and extended. */\n vite?: UserViteConfig\n}\n"],"names":[],"mappings":"AAYA;;CAEC,GACD,WAsIC"}
@@ -1,3 +1,4 @@
1
+ import { ProjectRootNotFoundError } from '../errors/ProjectRootNotFoundError.js';
1
2
  import { findAppConfigPath } from './util/findAppConfigPath.js';
2
3
  import { tryFindStudioConfigPath } from './util/findStudioConfigPath.js';
3
4
  import { recursivelyResolveProjectRoot } from './util/recursivelyResolveProjectRoot.js';
@@ -24,9 +25,12 @@ import { recursivelyResolveProjectRoot } from './util/recursivelyResolveProjectR
24
25
  if (appProjectRoot) {
25
26
  return appProjectRoot;
26
27
  }
27
- // If nothing is found throw an error
28
- throw new Error('No project root found');
28
+ // If nothing is found throw a specific error
29
+ throw new ProjectRootNotFoundError('No project root found');
29
30
  } catch (err) {
31
+ if (err instanceof ProjectRootNotFoundError) {
32
+ throw err;
33
+ }
30
34
  const message = err instanceof Error ? err.message : `${err}`;
31
35
  throw new Error(`Error occurred trying to resolve project root:\n${message}`);
32
36
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/config/findProjectRoot.ts"],"sourcesContent":["import {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 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, 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":["findAppConfigPath","tryFindStudioConfigPath","recursivelyResolveProjectRoot","findProjectRoot","cwd","studioProjectRoot","resolveProjectRootForStudio","appProjectRoot","resolveProjectRootForApp","Error","err","message","basePath","iterations"],"mappings":"AAAA,SAAQA,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,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,yBAAyB,UAAUY;AACpF;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"}
@@ -1,30 +1,42 @@
1
1
  import { stat } from 'node:fs/promises';
2
2
  import { dirname } from 'node:path';
3
+ import { isMainThread } from 'node:worker_threads';
3
4
  import { firstValueFrom, of } from 'rxjs';
5
+ import { subdebug } from '../../debug.js';
4
6
  import { doImport } from '../../util/doImport.js';
5
7
  import { getEmptyAuth } from '../../util/getEmptyAuth.js';
6
8
  import { resolveLocalPackage } from '../../util/resolveLocalPackage.js';
7
9
  import { findStudioConfigPath } from '../util/findStudioConfigPath.js';
8
10
  import { isStudioConfig } from './isStudioConfig.js';
11
+ const debug = subdebug('worker:getStudioWorkspaces');
9
12
  /**
10
13
  * Resolves the workspaces from the studio config.
11
14
  *
12
- * @param options - The options for the function
15
+ * NOTE: This function should only be called from a worker thread.
16
+ *
17
+ * @param configPath - The path to the studio config
13
18
  * @returns The workspaces
14
19
  * @internal
15
20
  */ export async function getStudioWorkspaces(configPath) {
21
+ if (isMainThread) {
22
+ throw new Error('getStudioWorkspaces should only be called from a worker thread');
23
+ }
16
24
  const isDirectory = (await stat(configPath)).isDirectory();
17
25
  if (isDirectory) {
18
26
  configPath = await findStudioConfigPath(configPath);
19
27
  }
28
+ debug('Finding studio config path %s', configPath);
20
29
  let config = await doImport(configPath);
30
+ debug('Imported config %o', config);
21
31
  if (!isStudioConfig(config)) {
22
32
  if (!('default' in config) || !isStudioConfig(config.default)) {
33
+ debug('Invalid studio config format in "%s"', configPath);
23
34
  throw new TypeError(`Invalid studio config format in "${configPath}"`);
24
35
  }
25
36
  config = config.default;
26
37
  }
27
38
  const workDir = dirname(configPath);
39
+ debug('Work dir %s', workDir);
28
40
  const { resolveConfig } = await resolveLocalPackage('sanity', workDir);
29
41
  if (typeof resolveConfig !== 'function') {
30
42
  throw new TypeError('Expected `resolveConfig` from `sanity` to be a function');
@@ -44,6 +56,7 @@ import { isStudioConfig } from './isStudioConfig.js';
44
56
  state: of(getEmptyAuth())
45
57
  }
46
58
  }));
59
+ debug('Unauthed workspaces %o', unauthedWorkspaces);
47
60
  return firstValueFrom(resolveConfig(unauthedWorkspaces));
48
61
  }
49
62
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/config/studio/getStudioWorkspaces.ts"],"sourcesContent":["import {stat} from 'node:fs/promises'\nimport {dirname} from 'node:path'\n\nimport {firstValueFrom, of} from 'rxjs'\nimport {type Workspace} from 'sanity'\n\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\n/**\n * Resolves the workspaces from the studio config.\n *\n * @param options - The options for the function\n * @returns The workspaces\n * @internal\n */\nexport async function getStudioWorkspaces(configPath: string): Promise<Workspace[]> {\n const isDirectory = (await stat(configPath)).isDirectory()\n if (isDirectory) {\n configPath = await findStudioConfigPath(configPath)\n }\n let config = await doImport(configPath)\n if (!isStudioConfig(config)) {\n if (!('default' in config) || !isStudioConfig(config.default)) {\n throw new TypeError(`Invalid studio config format in \"${configPath}\"`)\n }\n\n config = config.default\n }\n\n const workDir = dirname(configPath)\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 return firstValueFrom(resolveConfig(unauthedWorkspaces))\n}\n"],"names":["stat","dirname","firstValueFrom","of","doImport","getEmptyAuth","resolveLocalPackage","findStudioConfigPath","isStudioConfig","getStudioWorkspaces","configPath","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;AAEjC,SAAQC,cAAc,EAAEC,EAAE,QAAO,OAAM;AAGvC,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;;;;;;CAMC,GACD,OAAO,eAAeC,oBAAoBC,UAAkB;IAC1D,MAAMC,cAAc,AAAC,CAAA,MAAMX,KAAKU,WAAU,EAAGC,WAAW;IACxD,IAAIA,aAAa;QACfD,aAAa,MAAMH,qBAAqBG;IAC1C;IACA,IAAIE,SAAS,MAAMR,SAASM;IAC5B,IAAI,CAACF,eAAeI,SAAS;QAC3B,IAAI,CAAE,CAAA,aAAaA,MAAK,KAAM,CAACJ,eAAeI,OAAOC,OAAO,GAAG;YAC7D,MAAM,IAAIC,UAAU,CAAC,iCAAiC,EAAEJ,WAAW,CAAC,CAAC;QACvE;QAEAE,SAASA,OAAOC,OAAO;IACzB;IAEA,MAAME,UAAUd,QAAQS;IACxB,MAAM,EAACM,aAAa,EAAC,GAAG,MAAMV,oBAA6C,UAAUS;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,OAAOvB,GAAGE;YAAe;QAClC,CAAA;IAEA,OAAOH,eAAec,cAAcM;AACtC"}
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"}
@@ -1,24 +1,25 @@
1
1
  import { isMainThread, parentPort, workerData } from 'node:worker_threads';
2
2
  import { z } from 'zod';
3
+ import { subdebug } from '../../debug.js';
3
4
  import { doImport } from '../../util/doImport.js';
4
5
  import { safeStructuredClone } from '../../util/safeStructuredClone.js';
5
6
  import { getStudioWorkspaces } from './getStudioWorkspaces.js';
6
7
  if (isMainThread || !parentPort) {
7
8
  throw new Error('Should only be run in a worker!');
8
9
  }
10
+ const debug = subdebug('readStudioConfig.worker');
9
11
  const { configPath, resolvePlugins } = z.object({
10
12
  configPath: z.string(),
11
13
  resolvePlugins: z.boolean()
12
14
  }).parse(workerData);
15
+ debug('Parsing config path %s', configPath);
13
16
  let { default: config } = await doImport(configPath);
17
+ debug('Imported config %o', config);
14
18
  if (resolvePlugins) {
19
+ debug('Resolving workspaces');
15
20
  config = await getStudioWorkspaces(configPath);
21
+ debug('Resolved workspaces %o', config);
16
22
  }
17
23
  parentPort.postMessage(safeStructuredClone(config));
18
- // Explicitly exit the process to avoid any dangling references from keeping
19
- // the process alive after resolving it's main task
20
- setImmediate(()=>{
21
- process.exit(1);
22
- });
23
24
 
24
25
  //# sourceMappingURL=readStudioConfig.worker.js.map
@@ -1 +1 @@
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 {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 {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 config = await getStudioWorkspaces(configPath)\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":["isMainThread","parentPort","workerData","z","doImport","safeStructuredClone","getStudioWorkspaces","Error","configPath","resolvePlugins","object","string","boolean","parse","default","config","postMessage","setImmediate","process","exit"],"mappings":"AAAA,SAAQA,YAAY,EAAEC,UAAU,EAAEC,UAAU,QAAO,sBAAqB;AAExE,SAAQC,CAAC,QAAO,MAAK;AAErB,SAAQC,QAAQ,QAAO,yBAAwB;AAC/C,SAAQC,mBAAmB,QAAO,oCAAmC;AACrE,SAAQC,mBAAmB,QAAO,2BAA0B;AAE5D,IAAIN,gBAAgB,CAACC,YAAY;IAC/B,MAAM,IAAIM,MAAM;AAClB;AAEA,MAAM,EAACC,UAAU,EAAEC,cAAc,EAAC,GAAGN,EAClCO,MAAM,CAAC;IAACF,YAAYL,EAAEQ,MAAM;IAAIF,gBAAgBN,EAAES,OAAO;AAAE,GAC3DC,KAAK,CAACX;AAET,IAAI,EAACY,SAASC,MAAM,EAAC,GAAG,MAAMX,SAASI;AAEvC,IAAIC,gBAAgB;IAClBM,SAAS,MAAMT,oBAAoBE;AACrC;AAEAP,WAAWe,WAAW,CAACX,oBAAoBU;AAE3C,4EAA4E;AAC5E,mDAAmD;AACnDE,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"}
@@ -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"}