@sanity/cli-core 0.1.0-alpha.7 → 0.1.0-alpha.8

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.
@@ -1,12 +1,13 @@
1
1
  import { isMainThread, parentPort, workerData } from 'node:worker_threads';
2
2
  import { z } from 'zod';
3
+ import { doImport } from '../../util/doImport.js';
3
4
  if (isMainThread || !parentPort) {
4
5
  throw new Error('Should only be run in a worker!');
5
6
  }
6
7
  const { configPath } = z.object({
7
8
  configPath: z.string()
8
9
  }).parse(workerData);
9
- const { default: loadedConfig } = await import(configPath);
10
+ const { default: loadedConfig } = await doImport(configPath);
10
11
  // This might throw on unserializable properties, but that's actually wanted in this
11
12
  // case, since we _need_ any unserializable props (such as vite config functions)
12
13
  parentPort.postMessage(loadedConfig);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/config/cli/getCliConfig.worker.ts"],"sourcesContent":["import {isMainThread, parentPort, workerData} from 'node:worker_threads'\n\nimport {z} from 'zod'\n\nif (isMainThread || !parentPort) {\n throw new Error('Should only be run in a worker!')\n}\n\nconst {configPath} = z.object({configPath: z.string()}).parse(workerData)\n\nconst {default: loadedConfig} = await import(configPath)\n\n// This might throw on unserializable properties, but that's actually wanted in this\n// case, since we _need_ any unserializable props (such as vite config functions)\nparentPort.postMessage(loadedConfig)\n"],"names":["isMainThread","parentPort","workerData","z","Error","configPath","object","string","parse","default","loadedConfig","postMessage"],"mappings":"AAAA,SAAQA,YAAY,EAAEC,UAAU,EAAEC,UAAU,QAAO,sBAAqB;AAExE,SAAQC,CAAC,QAAO,MAAK;AAErB,IAAIH,gBAAgB,CAACC,YAAY;IAC/B,MAAM,IAAIG,MAAM;AAClB;AAEA,MAAM,EAACC,UAAU,EAAC,GAAGF,EAAEG,MAAM,CAAC;IAACD,YAAYF,EAAEI,MAAM;AAAE,GAAGC,KAAK,CAACN;AAE9D,MAAM,EAACO,SAASC,YAAY,EAAC,GAAG,MAAM,MAAM,CAACL;AAE7C,oFAAoF;AACpF,iFAAiF;AACjFJ,WAAWU,WAAW,CAACD"}
1
+ {"version":3,"sources":["../../../src/config/cli/getCliConfig.worker.ts"],"sourcesContent":["import {isMainThread, parentPort, workerData} from 'node:worker_threads'\n\nimport {z} from 'zod'\n\nimport {doImport} from '../../util/doImport.js'\n\nif (isMainThread || !parentPort) {\n throw new Error('Should only be run in a worker!')\n}\n\nconst {configPath} = z.object({configPath: z.string()}).parse(workerData)\n\nconst {default: loadedConfig} = await doImport(configPath)\n\n// This might throw on unserializable properties, but that's actually wanted in this\n// case, since we _need_ any unserializable props (such as vite config functions)\nparentPort.postMessage(loadedConfig)\n"],"names":["isMainThread","parentPort","workerData","z","doImport","Error","configPath","object","string","parse","default","loadedConfig","postMessage"],"mappings":"AAAA,SAAQA,YAAY,EAAEC,UAAU,EAAEC,UAAU,QAAO,sBAAqB;AAExE,SAAQC,CAAC,QAAO,MAAK;AAErB,SAAQC,QAAQ,QAAO,yBAAwB;AAE/C,IAAIJ,gBAAgB,CAACC,YAAY;IAC/B,MAAM,IAAII,MAAM;AAClB;AAEA,MAAM,EAACC,UAAU,EAAC,GAAGH,EAAEI,MAAM,CAAC;IAACD,YAAYH,EAAEK,MAAM;AAAE,GAAGC,KAAK,CAACP;AAE9D,MAAM,EAACQ,SAASC,YAAY,EAAC,GAAG,MAAMP,SAASE;AAE/C,oFAAoF;AACpF,iFAAiF;AACjFL,WAAWW,WAAW,CAACD"}
@@ -2,6 +2,7 @@ import { pathToFileURL } from 'node:url';
2
2
  import { isMainThread, parentPort, workerData } from 'node:worker_threads';
3
3
  import { moduleResolve } from 'import-meta-resolve';
4
4
  import { z } from 'zod';
5
+ import { doImport } from '../../util/doImport.js';
5
6
  import { getEmptyAuth } from '../../util/getEmptyAuth.js';
6
7
  import { safeStructuredClone } from '../../util/safeStructuredClone.js';
7
8
  if (isMainThread || !parentPort) {
@@ -11,7 +12,7 @@ const { configPath, resolvePlugins } = z.object({
11
12
  configPath: z.string(),
12
13
  resolvePlugins: z.boolean()
13
14
  }).parse(workerData);
14
- let { default: config } = await import(configPath);
15
+ let { default: config } = await doImport(configPath);
15
16
  if (resolvePlugins) {
16
17
  // If we need to resolve plugins, we need to import and use the `resolveConfig`
17
18
  // function from the `sanity` package. This package should be installed in the users'
@@ -19,7 +20,7 @@ if (resolvePlugins) {
19
20
  // Sanity package relative to the studio.
20
21
  const configUrl = pathToFileURL(configPath);
21
22
  const sanityUrl = await moduleResolve('sanity', configUrl);
22
- const { resolveConfig } = await import(sanityUrl.href);
23
+ const { resolveConfig } = await doImport(sanityUrl.href);
23
24
  if (typeof resolveConfig !== 'function') {
24
25
  throw new TypeError('Expected `resolveConfig` from `sanity` to be a function');
25
26
  }
@@ -27,7 +28,7 @@ if (resolvePlugins) {
27
28
  // compatible with what the studio uses internally, thus try to load RxJS from the
28
29
  // sanity module path instead of installing it as a dependency locally.
29
30
  const rxjsPath = (await moduleResolve('rxjs', sanityUrl)).href;
30
- const { firstValueFrom, of } = await import(rxjsPath);
31
+ const { firstValueFrom, of } = await doImport(rxjsPath);
31
32
  // We will also want to stub out some configuration - we don't need to resolve the
32
33
  // users' logged in state, for instance - so let's disable the auth implementation.
33
34
  const workspaces = Array.isArray(config) ? config : [
@@ -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 {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 import(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 import(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 import(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","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,YAAY,QAAO,6BAA4B;AACvD,SAAQC,mBAAmB,QAAO,oCAAmC;AAErE,IAAIN,gBAAgB,CAACC,YAAY;IAC/B,MAAM,IAAIM,MAAM;AAClB;AAEA,MAAM,EAACC,UAAU,EAAEC,cAAc,EAAC,GAAGL,EAClCM,MAAM,CAAC;IAACF,YAAYJ,EAAEO,MAAM;IAAIF,gBAAgBL,EAAEQ,OAAO;AAAE,GAC3DC,KAAK,CAACX;AAET,IAAI,EAACY,SAASC,MAAM,EAAC,GAAG,MAAM,MAAM,CAACP;AAErC,IAAIC,gBAAgB;IAClB,+EAA+E;IAC/E,qFAAqF;IACrF,sFAAsF;IACtF,yCAAyC;IACzC,MAAMO,YAAYjB,cAAcS;IAEhC,MAAMS,YAAY,MAAMd,cAAc,UAAUa;IAChD,MAAM,EAACE,aAAa,EAAC,GAAG,MAAM,MAAM,CAACD,UAAUE,IAAI;IACnD,IAAI,OAAOD,kBAAkB,YAAY;QACvC,MAAM,IAAIE,UAAU;IACtB;IAEA,8EAA8E;IAC9E,kFAAkF;IAClF,uEAAuE;IACvE,MAAMC,WAAW,AAAC,CAAA,MAAMlB,cAAc,QAAQc,UAAS,EAAGE,IAAI;IAC9D,MAAM,EAACG,cAAc,EAAEC,EAAE,EAAC,GAAG,MAAM,MAAM,CAACF;IAE1C,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;AAEAd,WAAW8B,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 {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"}
package/dist/index.d.ts CHANGED
@@ -17,6 +17,7 @@ export * from './services/cliUserConfig.js';
17
17
  export * from './services/getCliToken.js';
18
18
  export { type Output, type SanityOrgUser } from './types.js';
19
19
  export * from './util/createExpiringConfig.js';
20
+ export { doImport } from './util/doImport.js';
20
21
  export * from './util/environment/mockBrowserEnvironment.js';
21
22
  export * from './util/fileExists.js';
22
23
  export * from './util/getEmptyAuth.js';
package/dist/index.js CHANGED
@@ -13,6 +13,7 @@ export * from './services/apiClient.js';
13
13
  export * from './services/cliUserConfig.js';
14
14
  export * from './services/getCliToken.js';
15
15
  export * from './util/createExpiringConfig.js';
16
+ export { doImport } from './util/doImport.js';
16
17
  export * from './util/environment/mockBrowserEnvironment.js';
17
18
  export * from './util/fileExists.js';
18
19
  export * from './util/getEmptyAuth.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './config/cli/getCliConfig.js'\nexport * from './config/cli/getCliConfigSync.js'\nexport {cliConfigSchema} from './config/cli/schemas.js'\nexport {type CliConfig} from './config/cli/types/cliConfig.js'\nexport {type UserViteConfig} from './config/cli/types/userViteConfig.js'\nexport * from './config/findProjectRoot.js'\nexport * from './config/findProjectRootSync.js'\nexport * from './config/studio/getStudioConfig.js'\nexport * from './config/util/findConfigsPaths.js'\nexport * from './config/util/findStudioConfigPath.js'\nexport {type ProjectRootResult} from './config/util/recursivelyResolveProjectRoot.js'\nexport * from './debug.js'\nexport * from './loaders/tsx/tsxWorkerTask.js'\nexport * from './SanityCommand.js'\nexport * from './services/apiClient.js'\nexport * from './services/cliUserConfig.js'\nexport * from './services/getCliToken.js'\nexport {type Output, type SanityOrgUser} from './types.js'\nexport * from './util/createExpiringConfig.js'\nexport * from './util/environment/mockBrowserEnvironment.js'\nexport * from './util/fileExists.js'\nexport * from './util/getEmptyAuth.js'\nexport * from './util/getSanityEnvVar.js'\nexport * from './util/getSanityUrl.js'\nexport * from './util/getUserConfig.js'\nexport * from './util/isCi.js'\nexport * from './util/isInteractive.js'\nexport * from './util/isTrueish.js'\nexport * from './util/parseStringFlag.js'\nexport * from './util/resolveLocalPackage.js'\nexport * from './util/tryGetDefaultExport.js'\nexport * from './ux/colorizeJson.js'\nexport * from './ux/formatObject.js'\nexport * from './ux/printKeyValue.js'\nexport * from './ux/timer.js'\n"],"names":["cliConfigSchema"],"mappings":"AAAA,cAAc,+BAA8B;AAC5C,cAAc,mCAAkC;AAChD,SAAQA,eAAe,QAAO,0BAAyB;AAGvD,cAAc,8BAA6B;AAC3C,cAAc,kCAAiC;AAC/C,cAAc,qCAAoC;AAClD,cAAc,oCAAmC;AACjD,cAAc,wCAAuC;AAErD,cAAc,aAAY;AAC1B,cAAc,iCAAgC;AAC9C,cAAc,qBAAoB;AAClC,cAAc,0BAAyB;AACvC,cAAc,8BAA6B;AAC3C,cAAc,4BAA2B;AAEzC,cAAc,iCAAgC;AAC9C,cAAc,+CAA8C;AAC5D,cAAc,uBAAsB;AACpC,cAAc,yBAAwB;AACtC,cAAc,4BAA2B;AACzC,cAAc,yBAAwB;AACtC,cAAc,0BAAyB;AACvC,cAAc,iBAAgB;AAC9B,cAAc,0BAAyB;AACvC,cAAc,sBAAqB;AACnC,cAAc,4BAA2B;AACzC,cAAc,gCAA+B;AAC7C,cAAc,gCAA+B;AAC7C,cAAc,uBAAsB;AACpC,cAAc,uBAAsB;AACpC,cAAc,wBAAuB;AACrC,cAAc,gBAAe"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './config/cli/getCliConfig.js'\nexport * from './config/cli/getCliConfigSync.js'\nexport {cliConfigSchema} from './config/cli/schemas.js'\nexport {type CliConfig} from './config/cli/types/cliConfig.js'\nexport {type UserViteConfig} from './config/cli/types/userViteConfig.js'\nexport * from './config/findProjectRoot.js'\nexport * from './config/findProjectRootSync.js'\nexport * from './config/studio/getStudioConfig.js'\nexport * from './config/util/findConfigsPaths.js'\nexport * from './config/util/findStudioConfigPath.js'\nexport {type ProjectRootResult} from './config/util/recursivelyResolveProjectRoot.js'\nexport * from './debug.js'\nexport * from './loaders/tsx/tsxWorkerTask.js'\nexport * from './SanityCommand.js'\nexport * from './services/apiClient.js'\nexport * from './services/cliUserConfig.js'\nexport * from './services/getCliToken.js'\nexport {type Output, type SanityOrgUser} from './types.js'\nexport * from './util/createExpiringConfig.js'\nexport {doImport} from './util/doImport.js'\nexport * from './util/environment/mockBrowserEnvironment.js'\nexport * from './util/fileExists.js'\nexport * from './util/getEmptyAuth.js'\nexport * from './util/getSanityEnvVar.js'\nexport * from './util/getSanityUrl.js'\nexport * from './util/getUserConfig.js'\nexport * from './util/isCi.js'\nexport * from './util/isInteractive.js'\nexport * from './util/isTrueish.js'\nexport * from './util/parseStringFlag.js'\nexport * from './util/resolveLocalPackage.js'\nexport * from './util/tryGetDefaultExport.js'\nexport * from './ux/colorizeJson.js'\nexport * from './ux/formatObject.js'\nexport * from './ux/printKeyValue.js'\nexport * from './ux/timer.js'\n"],"names":["cliConfigSchema","doImport"],"mappings":"AAAA,cAAc,+BAA8B;AAC5C,cAAc,mCAAkC;AAChD,SAAQA,eAAe,QAAO,0BAAyB;AAGvD,cAAc,8BAA6B;AAC3C,cAAc,kCAAiC;AAC/C,cAAc,qCAAoC;AAClD,cAAc,oCAAmC;AACjD,cAAc,wCAAuC;AAErD,cAAc,aAAY;AAC1B,cAAc,iCAAgC;AAC9C,cAAc,qBAAoB;AAClC,cAAc,0BAAyB;AACvC,cAAc,8BAA6B;AAC3C,cAAc,4BAA2B;AAEzC,cAAc,iCAAgC;AAC9C,SAAQC,QAAQ,QAAO,qBAAoB;AAC3C,cAAc,+CAA8C;AAC5D,cAAc,uBAAsB;AACpC,cAAc,yBAAwB;AACtC,cAAc,4BAA2B;AACzC,cAAc,yBAAwB;AACtC,cAAc,0BAAyB;AACvC,cAAc,iBAAgB;AAC9B,cAAc,0BAAyB;AACvC,cAAc,sBAAqB;AACnC,cAAc,4BAA2B;AACzC,cAAc,gCAA+B;AAC7C,cAAc,gCAA+B;AAC7C,cAAc,uBAAsB;AACpC,cAAc,uBAAsB;AACpC,cAAc,wBAAuB;AACrC,cAAc,gBAAe"}
@@ -16,12 +16,11 @@ const CLI_REQUEST_TAG_PREFIX = 'sanity.cli';
16
16
  requester.use(authErrors());
17
17
  const sanityEnv = process.env.SANITY_INTERNAL_ENV || 'production';
18
18
  const apiHost = apiHosts[sanityEnv];
19
- let token = providedToken;
19
+ // Use the provided token if it is set, otherwise get the token from the config file
20
+ const token = providedToken || await getCliToken();
21
+ // If the token is not set and requireUser is true, throw an error
20
22
  if (!token && requireUser) {
21
- token = await getCliToken();
22
- if (!token) {
23
- throw new Error('You must login first - run "sanity login"');
24
- }
23
+ throw new Error('You must login first - run "sanity login"');
25
24
  }
26
25
  return createClient({
27
26
  ...apiHost ? {
@@ -45,12 +44,11 @@ const CLI_REQUEST_TAG_PREFIX = 'sanity.cli';
45
44
  requester.use(authErrors());
46
45
  const sanityEnv = process.env.SANITY_INTERNAL_ENV || 'production';
47
46
  const apiHost = apiHosts[sanityEnv];
48
- let token = providedToken;
47
+ // Use the provided token if it is set, otherwise get the token from the config file
48
+ const token = providedToken || await getCliToken();
49
+ // If the token is not set and requireUser is true, throw an error
49
50
  if (!token && requireUser) {
50
- token = await getCliToken();
51
- if (!token) {
52
- throw new Error('You must login first - run "sanity login"');
53
- }
51
+ throw new Error('You must login first - run "sanity login"');
54
52
  }
55
53
  return createClient({
56
54
  ...apiHost ? {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/services/apiClient.ts"],"sourcesContent":["import {ux} from '@oclif/core'\nimport {\n type ClientConfig,\n type ClientError,\n createClient,\n requester as defaultRequester,\n isHttpError,\n type SanityClient,\n type ServerError,\n} from '@sanity/client'\n\nimport {generateHelpUrl} from '../util/generateHelpUrl.js'\nimport {getCliToken} from './getCliToken.js'\n\nconst apiHosts: Record<string, string | undefined> = {\n staging: 'https://api.sanity.work',\n}\n\nconst CLI_REQUEST_TAG_PREFIX = 'sanity.cli'\n\n/**\n * @internal\n */\nexport interface GlobalCliClientOptions extends ClientConfig {\n /**\n * The API version to use for this client.\n */\n apiVersion: string\n\n /**\n * Whether to require a user to be authenticated to use this client.\n * Default: `false`.\n * Throws an error if `true` and user is not authenticated.\n */\n requireUser?: boolean\n}\n\n/**\n * Create a \"global\" (unscoped) Sanity API client.\n *\n * @param options - The options to use for the client.\n * @returns Promise that resolves to a configured Sanity API client.\n */\nexport async function getGlobalCliClient({\n requireUser,\n token: providedToken,\n ...config\n}: GlobalCliClientOptions): Promise<SanityClient> {\n const requester = defaultRequester.clone()\n requester.use(authErrors())\n\n const sanityEnv = process.env.SANITY_INTERNAL_ENV || 'production'\n\n const apiHost = apiHosts[sanityEnv]\n\n let token: string | undefined = providedToken\n if (!token && requireUser) {\n token = await getCliToken()\n if (!token) {\n throw new Error('You must login first - run \"sanity login\"')\n }\n }\n\n return createClient({\n ...(apiHost ? {apiHost} : {}),\n requester,\n requestTagPrefix: CLI_REQUEST_TAG_PREFIX,\n token,\n useCdn: false,\n useProjectHostname: false,\n ...config,\n })\n}\n\n/**\n * @internal\n */\nexport interface ProjectCliClientOptions extends ClientConfig {\n /**\n * The API version to use for this client.\n */\n apiVersion: string\n\n /**\n * The project ID to use for this client.\n */\n projectId: string\n\n /**\n * The dataset to use for this client.\n */\n dataset?: string\n\n /**\n * Whether to require a user to be authenticated to use this client.\n * Default: `false`.\n * Throws an error if `true` and user is not authenticated.\n */\n requireUser?: boolean\n}\n\n/**\n * Create a \"global\" (unscoped) Sanity API client.\n *\n * @param options - The options to use for the client.\n * @returns Promise that resolves to a configured Sanity API client.\n */\nexport async function getProjectCliClient({\n requireUser,\n token: providedToken,\n ...config\n}: ProjectCliClientOptions): Promise<SanityClient> {\n const requester = defaultRequester.clone()\n requester.use(authErrors())\n\n const sanityEnv = process.env.SANITY_INTERNAL_ENV || 'production'\n\n const apiHost = apiHosts[sanityEnv]\n\n let token: string | undefined = providedToken\n if (!token && requireUser) {\n token = await getCliToken()\n if (!token) {\n throw new Error('You must login first - run \"sanity login\"')\n }\n }\n\n return createClient({\n ...(apiHost ? {apiHost} : {}),\n requester,\n requestTagPrefix: CLI_REQUEST_TAG_PREFIX,\n token,\n useCdn: false,\n useProjectHostname: true,\n ...config,\n })\n}\n\n/**\n * `get-it` middleware that checks for 401 authentication errors and extends the error with more\n * helpful guidance on what to do next.\n *\n * @returns get-it middleware with `onError` handler\n * @internal\n */\nfunction authErrors() {\n return {\n onError: (err: Error | null) => {\n if (!err || !isReqResError(err)) {\n return err\n }\n\n const statusCode = isHttpError(err) && err.response.body.statusCode\n if (statusCode === 401) {\n err.message = `${err.message}. You may need to login again with ${ux.colorize('cyan', 'sanity login')}.\\nFor more information, see ${generateHelpUrl('cli-errors')}.`\n }\n\n return err\n },\n }\n}\n\nfunction isReqResError(err: Error): err is ClientError | ServerError {\n return Object.prototype.hasOwnProperty.call(err, 'response')\n}\n"],"names":["ux","createClient","requester","defaultRequester","isHttpError","generateHelpUrl","getCliToken","apiHosts","staging","CLI_REQUEST_TAG_PREFIX","getGlobalCliClient","requireUser","token","providedToken","config","clone","use","authErrors","sanityEnv","process","env","SANITY_INTERNAL_ENV","apiHost","Error","requestTagPrefix","useCdn","useProjectHostname","getProjectCliClient","onError","err","isReqResError","statusCode","response","body","message","colorize","Object","prototype","hasOwnProperty","call"],"mappings":"AAAA,SAAQA,EAAE,QAAO,cAAa;AAC9B,SAGEC,YAAY,EACZC,aAAaC,gBAAgB,EAC7BC,WAAW,QAGN,iBAAgB;AAEvB,SAAQC,eAAe,QAAO,6BAA4B;AAC1D,SAAQC,WAAW,QAAO,mBAAkB;AAE5C,MAAMC,WAA+C;IACnDC,SAAS;AACX;AAEA,MAAMC,yBAAyB;AAmB/B;;;;;CAKC,GACD,OAAO,eAAeC,mBAAmB,EACvCC,WAAW,EACXC,OAAOC,aAAa,EACpB,GAAGC,QACoB;IACvB,MAAMZ,YAAYC,iBAAiBY,KAAK;IACxCb,UAAUc,GAAG,CAACC;IAEd,MAAMC,YAAYC,QAAQC,GAAG,CAACC,mBAAmB,IAAI;IAErD,MAAMC,UAAUf,QAAQ,CAACW,UAAU;IAEnC,IAAIN,QAA4BC;IAChC,IAAI,CAACD,SAASD,aAAa;QACzBC,QAAQ,MAAMN;QACd,IAAI,CAACM,OAAO;YACV,MAAM,IAAIW,MAAM;QAClB;IACF;IAEA,OAAOtB,aAAa;QAClB,GAAIqB,UAAU;YAACA;QAAO,IAAI,CAAC,CAAC;QAC5BpB;QACAsB,kBAAkBf;QAClBG;QACAa,QAAQ;QACRC,oBAAoB;QACpB,GAAGZ,MAAM;IACX;AACF;AA6BA;;;;;CAKC,GACD,OAAO,eAAea,oBAAoB,EACxChB,WAAW,EACXC,OAAOC,aAAa,EACpB,GAAGC,QACqB;IACxB,MAAMZ,YAAYC,iBAAiBY,KAAK;IACxCb,UAAUc,GAAG,CAACC;IAEd,MAAMC,YAAYC,QAAQC,GAAG,CAACC,mBAAmB,IAAI;IAErD,MAAMC,UAAUf,QAAQ,CAACW,UAAU;IAEnC,IAAIN,QAA4BC;IAChC,IAAI,CAACD,SAASD,aAAa;QACzBC,QAAQ,MAAMN;QACd,IAAI,CAACM,OAAO;YACV,MAAM,IAAIW,MAAM;QAClB;IACF;IAEA,OAAOtB,aAAa;QAClB,GAAIqB,UAAU;YAACA;QAAO,IAAI,CAAC,CAAC;QAC5BpB;QACAsB,kBAAkBf;QAClBG;QACAa,QAAQ;QACRC,oBAAoB;QACpB,GAAGZ,MAAM;IACX;AACF;AAEA;;;;;;CAMC,GACD,SAASG;IACP,OAAO;QACLW,SAAS,CAACC;YACR,IAAI,CAACA,OAAO,CAACC,cAAcD,MAAM;gBAC/B,OAAOA;YACT;YAEA,MAAME,aAAa3B,YAAYyB,QAAQA,IAAIG,QAAQ,CAACC,IAAI,CAACF,UAAU;YACnE,IAAIA,eAAe,KAAK;gBACtBF,IAAIK,OAAO,GAAG,GAAGL,IAAIK,OAAO,CAAC,mCAAmC,EAAElC,GAAGmC,QAAQ,CAAC,QAAQ,gBAAgB,6BAA6B,EAAE9B,gBAAgB,cAAc,CAAC,CAAC;YACvK;YAEA,OAAOwB;QACT;IACF;AACF;AAEA,SAASC,cAAcD,GAAU;IAC/B,OAAOO,OAAOC,SAAS,CAACC,cAAc,CAACC,IAAI,CAACV,KAAK;AACnD"}
1
+ {"version":3,"sources":["../../src/services/apiClient.ts"],"sourcesContent":["import {ux} from '@oclif/core'\nimport {\n type ClientConfig,\n type ClientError,\n createClient,\n requester as defaultRequester,\n isHttpError,\n type SanityClient,\n type ServerError,\n} from '@sanity/client'\n\nimport {generateHelpUrl} from '../util/generateHelpUrl.js'\nimport {getCliToken} from './getCliToken.js'\n\nconst apiHosts: Record<string, string | undefined> = {\n staging: 'https://api.sanity.work',\n}\n\nconst CLI_REQUEST_TAG_PREFIX = 'sanity.cli'\n\n/**\n * @internal\n */\nexport interface GlobalCliClientOptions extends ClientConfig {\n /**\n * The API version to use for this client.\n */\n apiVersion: string\n\n /**\n * Whether to require a user to be authenticated to use this client.\n * Default: `false`.\n * Throws an error if `true` and user is not authenticated.\n */\n requireUser?: boolean\n}\n\n/**\n * Create a \"global\" (unscoped) Sanity API client.\n *\n * @param options - The options to use for the client.\n * @returns Promise that resolves to a configured Sanity API client.\n */\nexport async function getGlobalCliClient({\n requireUser,\n token: providedToken,\n ...config\n}: GlobalCliClientOptions): Promise<SanityClient> {\n const requester = defaultRequester.clone()\n requester.use(authErrors())\n\n const sanityEnv = process.env.SANITY_INTERNAL_ENV || 'production'\n\n const apiHost = apiHosts[sanityEnv]\n\n // Use the provided token if it is set, otherwise get the token from the config file\n const token = providedToken || (await getCliToken())\n\n // If the token is not set and requireUser is true, throw an error\n if (!token && requireUser) {\n throw new Error('You must login first - run \"sanity login\"')\n }\n\n return createClient({\n ...(apiHost ? {apiHost} : {}),\n requester,\n requestTagPrefix: CLI_REQUEST_TAG_PREFIX,\n token,\n useCdn: false,\n useProjectHostname: false,\n ...config,\n })\n}\n\n/**\n * @internal\n */\nexport interface ProjectCliClientOptions extends ClientConfig {\n /**\n * The API version to use for this client.\n */\n apiVersion: string\n\n /**\n * The project ID to use for this client.\n */\n projectId: string\n\n /**\n * The dataset to use for this client.\n */\n dataset?: string\n\n /**\n * Whether to require a user to be authenticated to use this client.\n * Default: `false`.\n * Throws an error if `true` and user is not authenticated.\n */\n requireUser?: boolean\n}\n\n/**\n * Create a \"global\" (unscoped) Sanity API client.\n *\n * @param options - The options to use for the client.\n * @returns Promise that resolves to a configured Sanity API client.\n */\nexport async function getProjectCliClient({\n requireUser,\n token: providedToken,\n ...config\n}: ProjectCliClientOptions): Promise<SanityClient> {\n const requester = defaultRequester.clone()\n requester.use(authErrors())\n\n const sanityEnv = process.env.SANITY_INTERNAL_ENV || 'production'\n\n const apiHost = apiHosts[sanityEnv]\n\n // Use the provided token if it is set, otherwise get the token from the config file\n const token = providedToken || (await getCliToken())\n\n // If the token is not set and requireUser is true, throw an error\n if (!token && requireUser) {\n throw new Error('You must login first - run \"sanity login\"')\n }\n\n return createClient({\n ...(apiHost ? {apiHost} : {}),\n requester,\n requestTagPrefix: CLI_REQUEST_TAG_PREFIX,\n token,\n useCdn: false,\n useProjectHostname: true,\n ...config,\n })\n}\n\n/**\n * `get-it` middleware that checks for 401 authentication errors and extends the error with more\n * helpful guidance on what to do next.\n *\n * @returns get-it middleware with `onError` handler\n * @internal\n */\nfunction authErrors() {\n return {\n onError: (err: Error | null) => {\n if (!err || !isReqResError(err)) {\n return err\n }\n\n const statusCode = isHttpError(err) && err.response.body.statusCode\n if (statusCode === 401) {\n err.message = `${err.message}. You may need to login again with ${ux.colorize('cyan', 'sanity login')}.\\nFor more information, see ${generateHelpUrl('cli-errors')}.`\n }\n\n return err\n },\n }\n}\n\nfunction isReqResError(err: Error): err is ClientError | ServerError {\n return Object.prototype.hasOwnProperty.call(err, 'response')\n}\n"],"names":["ux","createClient","requester","defaultRequester","isHttpError","generateHelpUrl","getCliToken","apiHosts","staging","CLI_REQUEST_TAG_PREFIX","getGlobalCliClient","requireUser","token","providedToken","config","clone","use","authErrors","sanityEnv","process","env","SANITY_INTERNAL_ENV","apiHost","Error","requestTagPrefix","useCdn","useProjectHostname","getProjectCliClient","onError","err","isReqResError","statusCode","response","body","message","colorize","Object","prototype","hasOwnProperty","call"],"mappings":"AAAA,SAAQA,EAAE,QAAO,cAAa;AAC9B,SAGEC,YAAY,EACZC,aAAaC,gBAAgB,EAC7BC,WAAW,QAGN,iBAAgB;AAEvB,SAAQC,eAAe,QAAO,6BAA4B;AAC1D,SAAQC,WAAW,QAAO,mBAAkB;AAE5C,MAAMC,WAA+C;IACnDC,SAAS;AACX;AAEA,MAAMC,yBAAyB;AAmB/B;;;;;CAKC,GACD,OAAO,eAAeC,mBAAmB,EACvCC,WAAW,EACXC,OAAOC,aAAa,EACpB,GAAGC,QACoB;IACvB,MAAMZ,YAAYC,iBAAiBY,KAAK;IACxCb,UAAUc,GAAG,CAACC;IAEd,MAAMC,YAAYC,QAAQC,GAAG,CAACC,mBAAmB,IAAI;IAErD,MAAMC,UAAUf,QAAQ,CAACW,UAAU;IAEnC,oFAAoF;IACpF,MAAMN,QAAQC,iBAAkB,MAAMP;IAEtC,kEAAkE;IAClE,IAAI,CAACM,SAASD,aAAa;QACzB,MAAM,IAAIY,MAAM;IAClB;IAEA,OAAOtB,aAAa;QAClB,GAAIqB,UAAU;YAACA;QAAO,IAAI,CAAC,CAAC;QAC5BpB;QACAsB,kBAAkBf;QAClBG;QACAa,QAAQ;QACRC,oBAAoB;QACpB,GAAGZ,MAAM;IACX;AACF;AA6BA;;;;;CAKC,GACD,OAAO,eAAea,oBAAoB,EACxChB,WAAW,EACXC,OAAOC,aAAa,EACpB,GAAGC,QACqB;IACxB,MAAMZ,YAAYC,iBAAiBY,KAAK;IACxCb,UAAUc,GAAG,CAACC;IAEd,MAAMC,YAAYC,QAAQC,GAAG,CAACC,mBAAmB,IAAI;IAErD,MAAMC,UAAUf,QAAQ,CAACW,UAAU;IAEnC,oFAAoF;IACpF,MAAMN,QAAQC,iBAAkB,MAAMP;IAEtC,kEAAkE;IAClE,IAAI,CAACM,SAASD,aAAa;QACzB,MAAM,IAAIY,MAAM;IAClB;IAEA,OAAOtB,aAAa;QAClB,GAAIqB,UAAU;YAACA;QAAO,IAAI,CAAC,CAAC;QAC5BpB;QACAsB,kBAAkBf;QAClBG;QACAa,QAAQ;QACRC,oBAAoB;QACpB,GAAGZ,MAAM;IACX;AACF;AAEA;;;;;;CAMC,GACD,SAASG;IACP,OAAO;QACLW,SAAS,CAACC;YACR,IAAI,CAACA,OAAO,CAACC,cAAcD,MAAM;gBAC/B,OAAOA;YACT;YAEA,MAAME,aAAa3B,YAAYyB,QAAQA,IAAIG,QAAQ,CAACC,IAAI,CAACF,UAAU;YACnE,IAAIA,eAAe,KAAK;gBACtBF,IAAIK,OAAO,GAAG,GAAGL,IAAIK,OAAO,CAAC,mCAAmC,EAAElC,GAAGmC,QAAQ,CAAC,QAAQ,gBAAgB,6BAA6B,EAAE9B,gBAAgB,cAAc,CAAC,CAAC;YACvK;YAEA,OAAOwB;QACT;IACF;AACF;AAEA,SAASC,cAAcD,GAAU;IAC/B,OAAOO,OAAOC,SAAS,CAACC,cAAc,CAACC,IAAI,CAACV,KAAK;AACnD"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * This function is a replacement for built in dynamic import
3
+ * This handles the case for windows file paths especially for absolute paths.
4
+ *
5
+ * @param source - File path
6
+ */
7
+ export declare function doImport(source: string): Promise<any>;
@@ -0,0 +1,16 @@
1
+ // Only file that should be using dynamic import
2
+ import { pathToFileURL } from 'node:url';
3
+ /**
4
+ * This function is a replacement for built in dynamic import
5
+ * This handles the case for windows file paths especially for absolute paths.
6
+ *
7
+ * @param source - File path
8
+ */ export function doImport(source) {
9
+ // Absolute paths in windows are not valid URLs and are not supported by import().
10
+ // We need to convert the path to a file URL.
11
+ // See: https://github.com/nodejs/node/issues/31710
12
+ // eslint-disable-next-line no-restricted-syntax
13
+ return import(/^file:\/\//.test(source) ? source : pathToFileURL(source).href);
14
+ }
15
+
16
+ //# sourceMappingURL=doImport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/util/doImport.ts"],"sourcesContent":["// Only file that should be using dynamic import\nimport {pathToFileURL} from 'node:url'\n\n/**\n * This function is a replacement for built in dynamic import\n * This handles the case for windows file paths especially for absolute paths.\n *\n * @param source - File path\n */\nexport function doImport(source: string) {\n // Absolute paths in windows are not valid URLs and are not supported by import().\n // We need to convert the path to a file URL.\n // See: https://github.com/nodejs/node/issues/31710\n // eslint-disable-next-line no-restricted-syntax\n return import(/^file:\\/\\//.test(source) ? source : pathToFileURL(source).href)\n}\n"],"names":["pathToFileURL","doImport","source","test","href"],"mappings":"AAAA,gDAAgD;AAChD,SAAQA,aAAa,QAAO,WAAU;AAEtC;;;;;CAKC,GACD,OAAO,SAASC,SAASC,MAAc;IACrC,kFAAkF;IAClF,6CAA6C;IAC7C,mDAAmD;IACnD,gDAAgD;IAChD,OAAO,MAAM,CAAC,aAAaC,IAAI,CAACD,UAAUA,SAASF,cAAcE,QAAQE,IAAI;AAC/E"}
@@ -1,6 +1,7 @@
1
1
  import { resolve } from 'node:path';
2
2
  import { pathToFileURL } from 'node:url';
3
3
  import { moduleResolve } from 'import-meta-resolve';
4
+ import { doImport } from '../doImport.js';
4
5
  /**
5
6
  * Loads the `getStudioEnvironmentVariables` function from the studio's
6
7
  * installed `sanity` package and returns the environment variables.
@@ -19,7 +20,7 @@ import { moduleResolve } from 'import-meta-resolve';
19
20
  // running, in order to ensure we're using the same version as the studio would.
20
21
  const sanityCliUrl = moduleResolve('sanity/cli', fakeConfigUrl);
21
22
  try {
22
- const { getStudioEnvironmentVariables: getEnvVars } = await import(sanityCliUrl.href);
23
+ const { getStudioEnvironmentVariables: getEnvVars } = await doImport(sanityCliUrl.href);
23
24
  if (typeof getEnvVars !== 'function') {
24
25
  throw new TypeError('Expected `getStudioEnvironmentVariables` from `sanity/cli` to be a function');
25
26
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/util/environment/getStudioEnvironmentVariables.ts"],"sourcesContent":["import {resolve} from 'node:path'\nimport {pathToFileURL} from 'node:url'\n\nimport {moduleResolve} from 'import-meta-resolve'\n\n/**\n * Loads the `getStudioEnvironmentVariables` function from the studio's\n * installed `sanity` package and returns the environment variables.\n *\n * This is used to ensure we're using the same version of environment variable\n * logic as the studio itself.\n *\n * @param rootPath - The root path of the Sanity Studio project\n * @returns Object containing studio environment variables\n * @internal\n */\nexport async function getStudioEnvironmentVariables(\n rootPath: string,\n): Promise<Record<string, string>> {\n // Create a fake config URL - doesn't have to be correct, just need the root path\n const fakeConfigUrl = pathToFileURL(resolve(rootPath, 'sanity.config.mjs'))\n\n // Load `getStudioEnvironmentVariables` from the `sanity/cli` module installed\n // relative to where the studio is located, instead of resolving from where this CLI is\n // running, in order to ensure we're using the same version as the studio would.\n const sanityCliUrl = moduleResolve('sanity/cli', fakeConfigUrl)\n try {\n const {getStudioEnvironmentVariables: getEnvVars} = await import(sanityCliUrl.href)\n if (typeof getEnvVars !== 'function') {\n throw new TypeError(\n 'Expected `getStudioEnvironmentVariables` from `sanity/cli` to be a function',\n )\n }\n return getEnvVars(rootPath)\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err)\n throw new Error(\n `Failed to import getStudioEnvironmentVariables from sanity/cli module: ${message}`,\n )\n }\n}\n"],"names":["resolve","pathToFileURL","moduleResolve","getStudioEnvironmentVariables","rootPath","fakeConfigUrl","sanityCliUrl","getEnvVars","href","TypeError","err","message","Error","String"],"mappings":"AAAA,SAAQA,OAAO,QAAO,YAAW;AACjC,SAAQC,aAAa,QAAO,WAAU;AAEtC,SAAQC,aAAa,QAAO,sBAAqB;AAEjD;;;;;;;;;;CAUC,GACD,OAAO,eAAeC,8BACpBC,QAAgB;IAEhB,iFAAiF;IACjF,MAAMC,gBAAgBJ,cAAcD,QAAQI,UAAU;IAEtD,8EAA8E;IAC9E,uFAAuF;IACvF,gFAAgF;IAChF,MAAME,eAAeJ,cAAc,cAAcG;IACjD,IAAI;QACF,MAAM,EAACF,+BAA+BI,UAAU,EAAC,GAAG,MAAM,MAAM,CAACD,aAAaE,IAAI;QAClF,IAAI,OAAOD,eAAe,YAAY;YACpC,MAAM,IAAIE,UACR;QAEJ;QACA,OAAOF,WAAWH;IACpB,EAAE,OAAOM,KAAK;QACZ,MAAMC,UAAUD,eAAeE,QAAQF,IAAIC,OAAO,GAAGE,OAAOH;QAC5D,MAAM,IAAIE,MACR,CAAC,uEAAuE,EAAED,SAAS;IAEvF;AACF"}
1
+ {"version":3,"sources":["../../../src/util/environment/getStudioEnvironmentVariables.ts"],"sourcesContent":["import {resolve} from 'node:path'\nimport {pathToFileURL} from 'node:url'\n\nimport {moduleResolve} from 'import-meta-resolve'\n\nimport {doImport} from '../doImport.js'\n\n/**\n * Loads the `getStudioEnvironmentVariables` function from the studio's\n * installed `sanity` package and returns the environment variables.\n *\n * This is used to ensure we're using the same version of environment variable\n * logic as the studio itself.\n *\n * @param rootPath - The root path of the Sanity Studio project\n * @returns Object containing studio environment variables\n * @internal\n */\nexport async function getStudioEnvironmentVariables(\n rootPath: string,\n): Promise<Record<string, string>> {\n // Create a fake config URL - doesn't have to be correct, just need the root path\n const fakeConfigUrl = pathToFileURL(resolve(rootPath, 'sanity.config.mjs'))\n\n // Load `getStudioEnvironmentVariables` from the `sanity/cli` module installed\n // relative to where the studio is located, instead of resolving from where this CLI is\n // running, in order to ensure we're using the same version as the studio would.\n const sanityCliUrl = moduleResolve('sanity/cli', fakeConfigUrl)\n try {\n const {getStudioEnvironmentVariables: getEnvVars} = await doImport(sanityCliUrl.href)\n if (typeof getEnvVars !== 'function') {\n throw new TypeError(\n 'Expected `getStudioEnvironmentVariables` from `sanity/cli` to be a function',\n )\n }\n return getEnvVars(rootPath)\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err)\n throw new Error(\n `Failed to import getStudioEnvironmentVariables from sanity/cli module: ${message}`,\n )\n }\n}\n"],"names":["resolve","pathToFileURL","moduleResolve","doImport","getStudioEnvironmentVariables","rootPath","fakeConfigUrl","sanityCliUrl","getEnvVars","href","TypeError","err","message","Error","String"],"mappings":"AAAA,SAAQA,OAAO,QAAO,YAAW;AACjC,SAAQC,aAAa,QAAO,WAAU;AAEtC,SAAQC,aAAa,QAAO,sBAAqB;AAEjD,SAAQC,QAAQ,QAAO,iBAAgB;AAEvC;;;;;;;;;;CAUC,GACD,OAAO,eAAeC,8BACpBC,QAAgB;IAEhB,iFAAiF;IACjF,MAAMC,gBAAgBL,cAAcD,QAAQK,UAAU;IAEtD,8EAA8E;IAC9E,uFAAuF;IACvF,gFAAgF;IAChF,MAAME,eAAeL,cAAc,cAAcI;IACjD,IAAI;QACF,MAAM,EAACF,+BAA+BI,UAAU,EAAC,GAAG,MAAML,SAASI,aAAaE,IAAI;QACpF,IAAI,OAAOD,eAAe,YAAY;YACpC,MAAM,IAAIE,UACR;QAEJ;QACA,OAAOF,WAAWH;IACpB,EAAE,OAAOM,KAAK;QACZ,MAAMC,UAAUD,eAAeE,QAAQF,IAAIC,OAAO,GAAGE,OAAOH;QAC5D,MAAM,IAAIE,MACR,CAAC,uEAAuE,EAAED,SAAS;IAEvF;AACF"}
@@ -1,6 +1,7 @@
1
1
  import { resolve } from 'node:path';
2
2
  import { pathToFileURL } from 'node:url';
3
3
  import { moduleResolve } from 'import-meta-resolve';
4
+ import { doImport } from './doImport.js';
4
5
  /**
5
6
  * Resolves and imports a package from the local project's node_modules,
6
7
  * relative to the given working directory. This avoids circular dependencies
@@ -23,7 +24,7 @@ import { moduleResolve } from 'import-meta-resolve';
23
24
  const fakeCliConfigUrl = pathToFileURL(resolve(workDir, 'sanity.cli.mjs'));
24
25
  try {
25
26
  const packageUrl = moduleResolve(packageName, fakeCliConfigUrl);
26
- const module = await import(packageUrl.href);
27
+ const module = await doImport(packageUrl.href);
27
28
  return module;
28
29
  } catch (error) {
29
30
  throw new Error(`Failed to resolve package "${packageName}" from "${workDir}": ${error instanceof Error ? error.message : String(error)}`);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/util/resolveLocalPackage.ts"],"sourcesContent":["import {resolve} from 'node:path'\nimport {pathToFileURL} from 'node:url'\n\nimport {moduleResolve} from 'import-meta-resolve'\n\n/**\n * Resolves and imports a package from the local project's node_modules,\n * relative to the given working directory. This avoids circular dependencies\n * and ensures the correct version of the package is used.\n *\n * @param packageName - The name of the package to resolve (e.g., 'sanity')\n * @param workDir - The working directory to resolve the package from\n * @returns The imported module\n * @throws If the package cannot be resolved or imported\n *\n * @example\n * ```ts\n * const {createSchema} = await resolveLocalPackage('sanity', workDir)\n * ```\n *\n * @internal\n */\nexport async function resolveLocalPackage<T = unknown>(\n packageName: string,\n workDir: string,\n): Promise<T> {\n // Create a fake cli config URL - doesn't have to be correct, just need the root path\n // This ensures we resolve packages relative to the user's repo, not the CLI package\n const fakeCliConfigUrl = pathToFileURL(resolve(workDir, 'sanity.cli.mjs'))\n\n try {\n const packageUrl = moduleResolve(packageName, fakeCliConfigUrl)\n const module = await import(packageUrl.href)\n return module as T\n } catch (error) {\n throw new Error(\n `Failed to resolve package \"${packageName}\" from \"${workDir}\": ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n}\n"],"names":["resolve","pathToFileURL","moduleResolve","resolveLocalPackage","packageName","workDir","fakeCliConfigUrl","packageUrl","module","href","error","Error","message","String"],"mappings":"AAAA,SAAQA,OAAO,QAAO,YAAW;AACjC,SAAQC,aAAa,QAAO,WAAU;AAEtC,SAAQC,aAAa,QAAO,sBAAqB;AAEjD;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,eAAeC,oBACpBC,WAAmB,EACnBC,OAAe;IAEf,qFAAqF;IACrF,oFAAoF;IACpF,MAAMC,mBAAmBL,cAAcD,QAAQK,SAAS;IAExD,IAAI;QACF,MAAME,aAAaL,cAAcE,aAAaE;QAC9C,MAAME,SAAS,MAAM,MAAM,CAACD,WAAWE,IAAI;QAC3C,OAAOD;IACT,EAAE,OAAOE,OAAO;QACd,MAAM,IAAIC,MACR,CAAC,2BAA2B,EAAEP,YAAY,QAAQ,EAAEC,QAAQ,GAAG,EAAEK,iBAAiBC,QAAQD,MAAME,OAAO,GAAGC,OAAOH,QAAQ;IAE7H;AACF"}
1
+ {"version":3,"sources":["../../src/util/resolveLocalPackage.ts"],"sourcesContent":["import {resolve} from 'node:path'\nimport {pathToFileURL} from 'node:url'\n\nimport {moduleResolve} from 'import-meta-resolve'\n\nimport {doImport} from './doImport.js'\n\n/**\n * Resolves and imports a package from the local project's node_modules,\n * relative to the given working directory. This avoids circular dependencies\n * and ensures the correct version of the package is used.\n *\n * @param packageName - The name of the package to resolve (e.g., 'sanity')\n * @param workDir - The working directory to resolve the package from\n * @returns The imported module\n * @throws If the package cannot be resolved or imported\n *\n * @example\n * ```ts\n * const {createSchema} = await resolveLocalPackage('sanity', workDir)\n * ```\n *\n * @internal\n */\nexport async function resolveLocalPackage<T = unknown>(\n packageName: string,\n workDir: string,\n): Promise<T> {\n // Create a fake cli config URL - doesn't have to be correct, just need the root path\n // This ensures we resolve packages relative to the user's repo, not the CLI package\n const fakeCliConfigUrl = pathToFileURL(resolve(workDir, 'sanity.cli.mjs'))\n\n try {\n const packageUrl = moduleResolve(packageName, fakeCliConfigUrl)\n const module = await doImport(packageUrl.href)\n return module as T\n } catch (error) {\n throw new Error(\n `Failed to resolve package \"${packageName}\" from \"${workDir}\": ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n}\n"],"names":["resolve","pathToFileURL","moduleResolve","doImport","resolveLocalPackage","packageName","workDir","fakeCliConfigUrl","packageUrl","module","href","error","Error","message","String"],"mappings":"AAAA,SAAQA,OAAO,QAAO,YAAW;AACjC,SAAQC,aAAa,QAAO,WAAU;AAEtC,SAAQC,aAAa,QAAO,sBAAqB;AAEjD,SAAQC,QAAQ,QAAO,gBAAe;AAEtC;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,eAAeC,oBACpBC,WAAmB,EACnBC,OAAe;IAEf,qFAAqF;IACrF,oFAAoF;IACpF,MAAMC,mBAAmBN,cAAcD,QAAQM,SAAS;IAExD,IAAI;QACF,MAAME,aAAaN,cAAcG,aAAaE;QAC9C,MAAME,SAAS,MAAMN,SAASK,WAAWE,IAAI;QAC7C,OAAOD;IACT,EAAE,OAAOE,OAAO;QACd,MAAM,IAAIC,MACR,CAAC,2BAA2B,EAAEP,YAAY,QAAQ,EAAEC,QAAQ,GAAG,EAAEK,iBAAiBC,QAAQD,MAAME,OAAO,GAAGC,OAAOH,QAAQ;IAE7H;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/cli-core",
3
- "version": "0.1.0-alpha.7",
3
+ "version": "0.1.0-alpha.8",
4
4
  "description": "Sanity CLI core package",
5
5
  "keywords": [
6
6
  "sanity",
@@ -49,7 +49,7 @@
49
49
  "@inquirer/prompts": "^8.1.0",
50
50
  "@oclif/core": "^4.8.0",
51
51
  "@sanity/client": "^7.14.0",
52
- "@sanity/types": "^5.5.0",
52
+ "@sanity/types": "^5.6.0",
53
53
  "babel-plugin-react-compiler": "^1.0.0",
54
54
  "chalk": "^5.6.2",
55
55
  "configstore": "^7.0.0",
@@ -66,9 +66,9 @@
66
66
  },
67
67
  "devDependencies": {
68
68
  "@eslint/compat": "^2.0.1",
69
- "@sanity/codegen": "^5.5.0",
70
- "@swc/cli": "^0.7.9",
71
- "@swc/core": "^1.15.8",
69
+ "@sanity/codegen": "^5.6.0",
70
+ "@swc/cli": "^0.7.10",
71
+ "@swc/core": "^1.15.10",
72
72
  "@types/debug": "^4.1.12",
73
73
  "@types/jsdom": "^27.0.0",
74
74
  "@types/node": "^20.19.30",