@sanity/cli-core 1.1.0 → 1.1.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.
package/dist/index.d.ts CHANGED
@@ -980,6 +980,52 @@ export declare function resolveLocalPackage<T = unknown>(
980
980
  workDir: string,
981
981
  ): Promise<T>;
982
982
 
983
+ /**
984
+ * Resolves and imports a package relative to another resolved module URL.
985
+ * Useful for resolving transitive dependencies that may not be directly
986
+ * accessible from the project root (e.g., in pnpm strict mode).
987
+ *
988
+ * @param packageName - The name of the package to resolve
989
+ * @param parentUrl - The URL of the parent module to resolve from
990
+ * @returns The imported module
991
+ * @throws If the package cannot be resolved or imported
992
+ *
993
+ * @example
994
+ * ```ts
995
+ * const sanityUrl = resolveLocalPackagePath('sanity', workDir)
996
+ * const ui = await resolveLocalPackageFrom<typeof import('@sanity/ui')>('@sanity/ui', sanityUrl)
997
+ * ```
998
+ *
999
+ * @internal
1000
+ */
1001
+ export declare function resolveLocalPackageFrom<T = unknown>(
1002
+ packageName: string,
1003
+ parentUrl: URL,
1004
+ ): Promise<T>;
1005
+
1006
+ /**
1007
+ * Resolves the URL of a package from the local project's node_modules,
1008
+ * relative to the given working directory, without importing it.
1009
+ *
1010
+ * @param packageName - The name of the package to resolve (e.g., 'sanity')
1011
+ * @param workDir - The working directory to resolve the package from
1012
+ * @returns The resolved URL of the package entry point
1013
+ * @throws If the package cannot be resolved
1014
+ *
1015
+ * @example
1016
+ * ```ts
1017
+ * // Resolve a transitive dependency via its parent package:
1018
+ * const sanityUrl = resolveLocalPackagePath('sanity', workDir)
1019
+ * const uiUrl = resolveLocalPackagePathFrom('@sanity/ui', sanityUrl)
1020
+ * ```
1021
+ *
1022
+ * @internal
1023
+ */
1024
+ export declare function resolveLocalPackagePath(
1025
+ packageName: string,
1026
+ workDir: string,
1027
+ ): URL;
1028
+
983
1029
  /**
984
1030
  * `structuredClone()`, but doesn't throw on non-clonable values - instead it drops them.
985
1031
  *
@@ -19,15 +19,59 @@ import { doImport } from './doImport.js';
19
19
  *
20
20
  * @internal
21
21
  */ export async function resolveLocalPackage(packageName, workDir) {
22
- // Create a fake cli config URL - doesn't have to be correct, just need the root path
23
- // This ensures we resolve packages relative to the user's repo, not the CLI package
22
+ const packageUrl = resolveLocalPackagePath(packageName, workDir);
23
+ const module = await doImport(packageUrl.href);
24
+ return module;
25
+ }
26
+ /**
27
+ * Resolves the URL of a package from the local project's node_modules,
28
+ * relative to the given working directory, without importing it.
29
+ *
30
+ * @param packageName - The name of the package to resolve (e.g., 'sanity')
31
+ * @param workDir - The working directory to resolve the package from
32
+ * @returns The resolved URL of the package entry point
33
+ * @throws If the package cannot be resolved
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * // Resolve a transitive dependency via its parent package:
38
+ * const sanityUrl = resolveLocalPackagePath('sanity', workDir)
39
+ * const uiUrl = resolveLocalPackagePathFrom('@sanity/ui', sanityUrl)
40
+ * ```
41
+ *
42
+ * @internal
43
+ */ export function resolveLocalPackagePath(packageName, workDir) {
24
44
  const fakeCliConfigUrl = pathToFileURL(resolve(workDir, 'sanity.cli.mjs'));
25
45
  try {
26
- const packageUrl = moduleResolve(packageName, fakeCliConfigUrl);
46
+ return moduleResolve(packageName, fakeCliConfigUrl);
47
+ } catch (error) {
48
+ throw new Error(`Failed to resolve package "${packageName}" from "${workDir}": ${error instanceof Error ? error.message : String(error)}`);
49
+ }
50
+ }
51
+ /**
52
+ * Resolves and imports a package relative to another resolved module URL.
53
+ * Useful for resolving transitive dependencies that may not be directly
54
+ * accessible from the project root (e.g., in pnpm strict mode).
55
+ *
56
+ * @param packageName - The name of the package to resolve
57
+ * @param parentUrl - The URL of the parent module to resolve from
58
+ * @returns The imported module
59
+ * @throws If the package cannot be resolved or imported
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * const sanityUrl = resolveLocalPackagePath('sanity', workDir)
64
+ * const ui = await resolveLocalPackageFrom<typeof import('@sanity/ui')>('@sanity/ui', sanityUrl)
65
+ * ```
66
+ *
67
+ * @internal
68
+ */ export async function resolveLocalPackageFrom(packageName, parentUrl) {
69
+ try {
70
+ const packageUrl = moduleResolve(packageName, parentUrl);
27
71
  const module = await doImport(packageUrl.href);
28
72
  return module;
29
73
  } catch (error) {
30
- throw new Error(`Failed to resolve package "${packageName}" from "${workDir}": ${error instanceof Error ? error.message : String(error)}`);
74
+ throw new Error(`Failed to resolve package "${packageName}" from "${parentUrl.href}": ${error instanceof Error ? error.message : String(error)}`);
31
75
  }
32
76
  }
33
77
 
@@ -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\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"}
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 const packageUrl = resolveLocalPackagePath(packageName, workDir)\n const module = await doImport(packageUrl.href)\n return module as T\n}\n\n/**\n * Resolves the URL of a package from the local project's node_modules,\n * relative to the given working directory, without importing it.\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 resolved URL of the package entry point\n * @throws If the package cannot be resolved\n *\n * @example\n * ```ts\n * // Resolve a transitive dependency via its parent package:\n * const sanityUrl = resolveLocalPackagePath('sanity', workDir)\n * const uiUrl = resolveLocalPackagePathFrom('@sanity/ui', sanityUrl)\n * ```\n *\n * @internal\n */\nexport function resolveLocalPackagePath(packageName: string, workDir: string): URL {\n const fakeCliConfigUrl = pathToFileURL(resolve(workDir, 'sanity.cli.mjs'))\n\n try {\n return moduleResolve(packageName, fakeCliConfigUrl)\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\n/**\n * Resolves and imports a package relative to another resolved module URL.\n * Useful for resolving transitive dependencies that may not be directly\n * accessible from the project root (e.g., in pnpm strict mode).\n *\n * @param packageName - The name of the package to resolve\n * @param parentUrl - The URL of the parent module to resolve from\n * @returns The imported module\n * @throws If the package cannot be resolved or imported\n *\n * @example\n * ```ts\n * const sanityUrl = resolveLocalPackagePath('sanity', workDir)\n * const ui = await resolveLocalPackageFrom<typeof import('@sanity/ui')>('@sanity/ui', sanityUrl)\n * ```\n *\n * @internal\n */\nexport async function resolveLocalPackageFrom<T = unknown>(\n packageName: string,\n parentUrl: URL,\n): Promise<T> {\n try {\n const packageUrl = moduleResolve(packageName, parentUrl)\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 \"${parentUrl.href}\": ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n}\n"],"names":["resolve","pathToFileURL","moduleResolve","doImport","resolveLocalPackage","packageName","workDir","packageUrl","resolveLocalPackagePath","module","href","fakeCliConfigUrl","error","Error","message","String","resolveLocalPackageFrom","parentUrl"],"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,MAAMC,aAAaC,wBAAwBH,aAAaC;IACxD,MAAMG,SAAS,MAAMN,SAASI,WAAWG,IAAI;IAC7C,OAAOD;AACT;AAEA;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,SAASD,wBAAwBH,WAAmB,EAAEC,OAAe;IAC1E,MAAMK,mBAAmBV,cAAcD,QAAQM,SAAS;IAExD,IAAI;QACF,OAAOJ,cAAcG,aAAaM;IACpC,EAAE,OAAOC,OAAO;QACd,MAAM,IAAIC,MACR,CAAC,2BAA2B,EAAER,YAAY,QAAQ,EAAEC,QAAQ,GAAG,EAAEM,iBAAiBC,QAAQD,MAAME,OAAO,GAAGC,OAAOH,QAAQ;IAE7H;AACF;AAEA;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,eAAeI,wBACpBX,WAAmB,EACnBY,SAAc;IAEd,IAAI;QACF,MAAMV,aAAaL,cAAcG,aAAaY;QAC9C,MAAMR,SAAS,MAAMN,SAASI,WAAWG,IAAI;QAC7C,OAAOD;IACT,EAAE,OAAOG,OAAO;QACd,MAAM,IAAIC,MACR,CAAC,2BAA2B,EAAER,YAAY,QAAQ,EAAEY,UAAUP,IAAI,CAAC,GAAG,EAAEE,iBAAiBC,QAAQD,MAAME,OAAO,GAAGC,OAAOH,QAAQ;IAEpI;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/cli-core",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Sanity CLI core package",
5
5
  "keywords": [
6
6
  "cli",
@@ -87,8 +87,8 @@
87
87
  "typescript": "^5.9.3",
88
88
  "vitest": "^4.0.18",
89
89
  "@repo/package.config": "0.0.1",
90
- "@sanity/eslint-config-cli": "1.0.0",
91
- "@repo/tsconfig": "3.70.0"
90
+ "@repo/tsconfig": "3.70.0",
91
+ "@sanity/eslint-config-cli": "1.0.0"
92
92
  },
93
93
  "peerDependencies": {
94
94
  "@sanity/telemetry": ">=0.8.1 <0.9.0"