@sanity/cli 6.1.6 → 6.1.7

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,7 +1,7 @@
1
- import path, { resolve } from 'node:path';
1
+ import path from 'node:path';
2
2
  import semver from 'semver';
3
3
  import { build } from 'vite';
4
- import { getLocalPackageVersion } from '../../util/getLocalPackageVersion.js';
4
+ import { getLocalPackageDir, getLocalPackageVersion } from '../../util/getLocalPackageVersion.js';
5
5
  import { createExternalFromImportMap } from './createExternalFromImportMap.js';
6
6
  // Directory where vendor packages will be stored
7
7
  const VENDOR_DIR = 'vendor';
@@ -75,11 +75,14 @@ const STYLED_COMPONENTS_IMPORTS = {
75
75
  throw new Error(`Version '${version}' of package '${packageName}' is not supported yet.`);
76
76
  }
77
77
  const subpaths = ranges[matchedRange];
78
+ // Resolve the actual package directory using Node module resolution,
79
+ // so that hoisted packages in monorepos/workspaces are found correctly
80
+ const packageDir = getLocalPackageDir(packageName, cwd);
78
81
  // Iterate over each subpath and its corresponding entry point
79
82
  for (const [subpath, relativeEntryPoint] of Object.entries(subpaths)){
80
83
  const specifier = path.posix.join(packageName, subpath);
81
84
  const chunkName = path.posix.join(packageName, path.relative(packageName, specifier) || 'index');
82
- entry[chunkName] = resolve(`node_modules/${packageName}/${relativeEntryPoint}`);
85
+ entry[chunkName] = path.join(packageDir, relativeEntryPoint);
83
86
  imports[specifier] = path.posix.join('/', basePath, VENDOR_DIR, `${chunkName}.mjs`);
84
87
  }
85
88
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/actions/build/buildVendorDependencies.ts"],"sourcesContent":["import path, {resolve} from 'node:path'\n\nimport semver from 'semver'\nimport {build} from 'vite'\n\nimport {getLocalPackageVersion} from '../../util/getLocalPackageVersion.js'\nimport {createExternalFromImportMap} from './createExternalFromImportMap.js'\n\n// Directory where vendor packages will be stored\nconst VENDOR_DIR = 'vendor'\n\n/**\n * A type representing the imports of vendor packages, defining specific entry\n * points for various versions and subpaths of the packages.\n *\n * The `VendorImports` object is used to build ESM browser-compatible versions\n * of the specified packages. This approach ensures that the appropriate version\n * and entry points are used for each package, enabling compatibility and proper\n * functionality in the browser environment.\n *\n * ## Rationale\n *\n * The rationale for this structure is to handle different versions of the\n * packages carefully, especially major versions. Major version bumps often\n * introduce breaking changes, so the module scheme for the package needs to be\n * checked when there is a major version update. However, minor and patch\n * versions are generally backward compatible, so they are handled more\n * leniently. By assuming that new minor versions are compatible, we avoid\n * unnecessary warnings and streamline the update process.\n *\n * If a new minor version introduces an additional subpath export within the\n * package of this version range, the corresponding package can add a more\n * specific version range that includes the new subpath. This design allows for\n * flexibility and ease of maintenance, ensuring that the latest features and\n * fixes are incorporated without extensive manual intervention.\n *\n * An additional subpath export within the package of this version range that\n * could cause the build to break if that new export is used, can be treated as\n * a bug fix. It might make more sense to our users that this new subpath isn't\n * supported yet until we address it as a bug fix. This approach helps maintain\n * stability and prevents unexpected issues during the build process.\n *\n * ## Structure\n * The `VendorImports` type is a nested object where:\n * - The keys at the first level represent the package names.\n * - The keys at the second level represent the version ranges (e.g., `^19.0.0`).\n * - The keys at the third level represent the subpaths within the package (e.g., `.` for the main entry point).\n * - The values at the third level are the relative paths to the corresponding entry points within the package.\n *\n * This structure allows for precise specification of the entry points for\n * different versions and subpaths, ensuring that the correct files are used\n * during the build process.\n */\ntype VendorImports = {\n [packageName: string]: {\n [versionRange: string]: {\n [subpath: string]: string\n }\n }\n}\n\n// Define the vendor packages and their corresponding versions and entry points\nconst VENDOR_IMPORTS: VendorImports = {\n react: {\n '^19.2.0': {\n '.': './cjs/react.production.js',\n './compiler-runtime': './cjs/react-compiler-runtime.production.js',\n './jsx-dev-runtime': './cjs/react-jsx-dev-runtime.production.js',\n './jsx-runtime': './cjs/react-jsx-runtime.production.js',\n './package.json': './package.json',\n },\n },\n 'react-dom': {\n '^19.2.0': {\n '.': './cjs/react-dom.production.js',\n './client': './cjs/react-dom-client.production.js',\n './package.json': './package.json',\n './server': './cjs/react-dom-server-legacy.browser.production.js',\n './server.browser': './cjs/react-dom-server-legacy.browser.production.js',\n './static': './cjs/react-dom-server.browser.production.js',\n './static.browser': './cjs/react-dom-server.browser.production.js',\n },\n },\n}\n\nconst STYLED_COMPONENTS_IMPORTS = {\n 'styled-components': {\n '^6.1.0': {\n '.': './dist/styled-components.browser.esm.js',\n './package.json': './package.json',\n },\n },\n}\n\ninterface VendorBuildOptions {\n basePath: string\n cwd: string\n isApp: boolean\n outputDir: string\n}\n\n/**\n * Builds the ESM browser compatible versions of the vendor packages\n * specified in VENDOR_IMPORTS. Returns the `imports` object of an import map.\n */\nexport async function buildVendorDependencies({\n basePath,\n cwd,\n isApp,\n outputDir,\n}: VendorBuildOptions): Promise<Record<string, string>> {\n const entry: Record<string, string> = {}\n const imports: Record<string, string> = {}\n\n // If we're building an app, we don't need to build the styled-components package\n const vendorImports = isApp ? VENDOR_IMPORTS : {...VENDOR_IMPORTS, ...STYLED_COMPONENTS_IMPORTS}\n\n // Iterate over each package and its version ranges in VENDOR_IMPORTS\n for (const [packageName, ranges] of Object.entries(vendorImports)) {\n const version = await getLocalPackageVersion(packageName, cwd)\n if (!version) {\n throw new Error(`Could not get version for '${packageName}'`)\n }\n\n // Sort version ranges in descending order\n const sortedRanges = Object.keys(ranges).toSorted((range1, range2) => {\n const min1 = semver.minVersion(range1)\n const min2 = semver.minVersion(range2)\n\n if (!min1) throw new Error(`Could not parse range '${range1}'`)\n if (!min2) throw new Error(`Could not parse range '${range2}'`)\n\n // sort them in reverse so we can rely on array `.find` below\n return semver.rcompare(min1.version, min2.version)\n })\n\n // Find the first version range that satisfies the package version\n const matchedRange = sortedRanges.find((range) => semver.satisfies(version, range))\n\n if (!matchedRange) {\n const min = semver.minVersion(sortedRanges.at(-1)!)\n if (!min) {\n throw new Error(`Could not find a minimum version for package '${packageName}'`)\n }\n\n if (semver.gt(min.version, version)) {\n throw new Error(`Package '${packageName}' requires at least ${min.version}.`)\n }\n\n throw new Error(`Version '${version}' of package '${packageName}' is not supported yet.`)\n }\n\n const subpaths = ranges[matchedRange]\n\n // Iterate over each subpath and its corresponding entry point\n for (const [subpath, relativeEntryPoint] of Object.entries(subpaths)) {\n const specifier = path.posix.join(packageName, subpath)\n const chunkName = path.posix.join(\n packageName,\n path.relative(packageName, specifier) || 'index',\n )\n\n entry[chunkName] = resolve(`node_modules/${packageName}/${relativeEntryPoint}`)\n imports[specifier] = path.posix.join('/', basePath, VENDOR_DIR, `${chunkName}.mjs`)\n }\n }\n\n // removes the `RollupWatcher` type\n type BuildResult = Exclude<Awaited<ReturnType<typeof build>>, {close: unknown}>\n\n // Use Vite to build the packages into the output directory\n let buildResult = (await build({\n appType: 'custom',\n build: {\n commonjsOptions: {strictRequires: 'auto'},\n emptyOutDir: false, // Rely on CLI to do this\n lib: {entry, formats: ['es']},\n minify: true,\n outDir: path.join(outputDir, VENDOR_DIR),\n rollupOptions: {\n external: createExternalFromImportMap({imports}),\n output: {\n chunkFileNames: '[name]-[hash].mjs',\n entryFileNames: '[name]-[hash].mjs',\n exports: 'named',\n format: 'es',\n },\n treeshake: {preset: 'recommended'},\n },\n },\n // Define a custom cache directory so that sanity's vite cache\n // does not conflict with any potential local vite projects\n cacheDir: 'node_modules/.sanity/vite-vendor',\n configFile: false,\n define: {'process.env.NODE_ENV': JSON.stringify('production')},\n logLevel: 'silent',\n mode: 'production',\n root: cwd,\n })) as BuildResult\n\n buildResult = Array.isArray(buildResult) ? buildResult : [buildResult]\n\n // Create a map of the original import specifiers to their hashed filenames\n const hashedImports: Record<string, string> = {}\n const output = buildResult.flatMap((i) => i.output)\n\n for (const chunk of output) {\n if (chunk.type === 'asset') continue\n\n for (const [specifier, originalPath] of Object.entries(imports)) {\n if (originalPath.endsWith(`${chunk.name}.mjs`)) {\n hashedImports[specifier] = path.posix.join('/', basePath, VENDOR_DIR, chunk.fileName)\n }\n }\n }\n\n return hashedImports\n}\n"],"names":["path","resolve","semver","build","getLocalPackageVersion","createExternalFromImportMap","VENDOR_DIR","VENDOR_IMPORTS","react","STYLED_COMPONENTS_IMPORTS","buildVendorDependencies","basePath","cwd","isApp","outputDir","entry","imports","vendorImports","packageName","ranges","Object","entries","version","Error","sortedRanges","keys","toSorted","range1","range2","min1","minVersion","min2","rcompare","matchedRange","find","range","satisfies","min","at","gt","subpaths","subpath","relativeEntryPoint","specifier","posix","join","chunkName","relative","buildResult","appType","commonjsOptions","strictRequires","emptyOutDir","lib","formats","minify","outDir","rollupOptions","external","output","chunkFileNames","entryFileNames","exports","format","treeshake","preset","cacheDir","configFile","define","JSON","stringify","logLevel","mode","root","Array","isArray","hashedImports","flatMap","i","chunk","type","originalPath","endsWith","name","fileName"],"mappings":"AAAA,OAAOA,QAAOC,OAAO,QAAO,YAAW;AAEvC,OAAOC,YAAY,SAAQ;AAC3B,SAAQC,KAAK,QAAO,OAAM;AAE1B,SAAQC,sBAAsB,QAAO,uCAAsC;AAC3E,SAAQC,2BAA2B,QAAO,mCAAkC;AAE5E,iDAAiD;AACjD,MAAMC,aAAa;AAoDnB,+EAA+E;AAC/E,MAAMC,iBAAgC;IACpCC,OAAO;QACL,WAAW;YACT,KAAK;YACL,sBAAsB;YACtB,qBAAqB;YACrB,iBAAiB;YACjB,kBAAkB;QACpB;IACF;IACA,aAAa;QACX,WAAW;YACT,KAAK;YACL,YAAY;YACZ,kBAAkB;YAClB,YAAY;YACZ,oBAAoB;YACpB,YAAY;YACZ,oBAAoB;QACtB;IACF;AACF;AAEA,MAAMC,4BAA4B;IAChC,qBAAqB;QACnB,UAAU;YACR,KAAK;YACL,kBAAkB;QACpB;IACF;AACF;AASA;;;CAGC,GACD,OAAO,eAAeC,wBAAwB,EAC5CC,QAAQ,EACRC,GAAG,EACHC,KAAK,EACLC,SAAS,EACU;IACnB,MAAMC,QAAgC,CAAC;IACvC,MAAMC,UAAkC,CAAC;IAEzC,iFAAiF;IACjF,MAAMC,gBAAgBJ,QAAQN,iBAAiB;QAAC,GAAGA,cAAc;QAAE,GA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X,YAAY6B,OAAO,CAAC,CAACC,IAAMA,EAAEnB,MAAM;IAElD,KAAK,MAAMoB,SAASpB,OAAQ;QAC1B,IAAIoB,MAAMC,IAAI,KAAK,SAAS;QAE5B,KAAK,MAAM,CAACrC,WAAWsC,aAAa,IAAI7D,OAAOC,OAAO,CAACL,SAAU;YAC/D,IAAIiE,aAAaC,QAAQ,CAAC,GAAGH,MAAMI,IAAI,CAAC,IAAI,CAAC,GAAG;gBAC9CP,aAAa,CAACjC,UAAU,GAAG3C,KAAK4C,KAAK,CAACC,IAAI,CAAC,KAAKlC,UAAUL,YAAYyE,MAAMK,QAAQ;YACtF;QACF;IACF;IAEA,OAAOR;AACT"}
1
+ {"version":3,"sources":["../../../src/actions/build/buildVendorDependencies.ts"],"sourcesContent":["import path from 'node:path'\n\nimport semver from 'semver'\nimport {build} from 'vite'\n\nimport {getLocalPackageDir, getLocalPackageVersion} from '../../util/getLocalPackageVersion.js'\nimport {createExternalFromImportMap} from './createExternalFromImportMap.js'\n\n// Directory where vendor packages will be stored\nconst VENDOR_DIR = 'vendor'\n\n/**\n * A type representing the imports of vendor packages, defining specific entry\n * points for various versions and subpaths of the packages.\n *\n * The `VendorImports` object is used to build ESM browser-compatible versions\n * of the specified packages. This approach ensures that the appropriate version\n * and entry points are used for each package, enabling compatibility and proper\n * functionality in the browser environment.\n *\n * ## Rationale\n *\n * The rationale for this structure is to handle different versions of the\n * packages carefully, especially major versions. Major version bumps often\n * introduce breaking changes, so the module scheme for the package needs to be\n * checked when there is a major version update. However, minor and patch\n * versions are generally backward compatible, so they are handled more\n * leniently. By assuming that new minor versions are compatible, we avoid\n * unnecessary warnings and streamline the update process.\n *\n * If a new minor version introduces an additional subpath export within the\n * package of this version range, the corresponding package can add a more\n * specific version range that includes the new subpath. This design allows for\n * flexibility and ease of maintenance, ensuring that the latest features and\n * fixes are incorporated without extensive manual intervention.\n *\n * An additional subpath export within the package of this version range that\n * could cause the build to break if that new export is used, can be treated as\n * a bug fix. It might make more sense to our users that this new subpath isn't\n * supported yet until we address it as a bug fix. This approach helps maintain\n * stability and prevents unexpected issues during the build process.\n *\n * ## Structure\n * The `VendorImports` type is a nested object where:\n * - The keys at the first level represent the package names.\n * - The keys at the second level represent the version ranges (e.g., `^19.0.0`).\n * - The keys at the third level represent the subpaths within the package (e.g., `.` for the main entry point).\n * - The values at the third level are the relative paths to the corresponding entry points within the package.\n *\n * This structure allows for precise specification of the entry points for\n * different versions and subpaths, ensuring that the correct files are used\n * during the build process.\n */\ntype VendorImports = {\n [packageName: string]: {\n [versionRange: string]: {\n [subpath: string]: string\n }\n }\n}\n\n// Define the vendor packages and their corresponding versions and entry points\nconst VENDOR_IMPORTS: VendorImports = {\n react: {\n '^19.2.0': {\n '.': './cjs/react.production.js',\n './compiler-runtime': './cjs/react-compiler-runtime.production.js',\n './jsx-dev-runtime': './cjs/react-jsx-dev-runtime.production.js',\n './jsx-runtime': './cjs/react-jsx-runtime.production.js',\n './package.json': './package.json',\n },\n },\n 'react-dom': {\n '^19.2.0': {\n '.': './cjs/react-dom.production.js',\n './client': './cjs/react-dom-client.production.js',\n './package.json': './package.json',\n './server': './cjs/react-dom-server-legacy.browser.production.js',\n './server.browser': './cjs/react-dom-server-legacy.browser.production.js',\n './static': './cjs/react-dom-server.browser.production.js',\n './static.browser': './cjs/react-dom-server.browser.production.js',\n },\n },\n}\n\nconst STYLED_COMPONENTS_IMPORTS = {\n 'styled-components': {\n '^6.1.0': {\n '.': './dist/styled-components.browser.esm.js',\n './package.json': './package.json',\n },\n },\n}\n\ninterface VendorBuildOptions {\n basePath: string\n cwd: string\n isApp: boolean\n outputDir: string\n}\n\n/**\n * Builds the ESM browser compatible versions of the vendor packages\n * specified in VENDOR_IMPORTS. Returns the `imports` object of an import map.\n */\nexport async function buildVendorDependencies({\n basePath,\n cwd,\n isApp,\n outputDir,\n}: VendorBuildOptions): Promise<Record<string, string>> {\n const entry: Record<string, string> = {}\n const imports: Record<string, string> = {}\n\n // If we're building an app, we don't need to build the styled-components package\n const vendorImports = isApp ? VENDOR_IMPORTS : {...VENDOR_IMPORTS, ...STYLED_COMPONENTS_IMPORTS}\n\n // Iterate over each package and its version ranges in VENDOR_IMPORTS\n for (const [packageName, ranges] of Object.entries(vendorImports)) {\n const version = await getLocalPackageVersion(packageName, cwd)\n if (!version) {\n throw new Error(`Could not get version for '${packageName}'`)\n }\n\n // Sort version ranges in descending order\n const sortedRanges = Object.keys(ranges).toSorted((range1, range2) => {\n const min1 = semver.minVersion(range1)\n const min2 = semver.minVersion(range2)\n\n if (!min1) throw new Error(`Could not parse range '${range1}'`)\n if (!min2) throw new Error(`Could not parse range '${range2}'`)\n\n // sort them in reverse so we can rely on array `.find` below\n return semver.rcompare(min1.version, min2.version)\n })\n\n // Find the first version range that satisfies the package version\n const matchedRange = sortedRanges.find((range) => semver.satisfies(version, range))\n\n if (!matchedRange) {\n const min = semver.minVersion(sortedRanges.at(-1)!)\n if (!min) {\n throw new Error(`Could not find a minimum version for package '${packageName}'`)\n }\n\n if (semver.gt(min.version, version)) {\n throw new Error(`Package '${packageName}' requires at least ${min.version}.`)\n }\n\n throw new Error(`Version '${version}' of package '${packageName}' is not supported yet.`)\n }\n\n const subpaths = ranges[matchedRange]\n\n // Resolve the actual package directory using Node module resolution,\n // so that hoisted packages in monorepos/workspaces are found correctly\n const packageDir = getLocalPackageDir(packageName, cwd)\n\n // Iterate over each subpath and its corresponding entry point\n for (const [subpath, relativeEntryPoint] of Object.entries(subpaths)) {\n const specifier = path.posix.join(packageName, subpath)\n const chunkName = path.posix.join(\n packageName,\n path.relative(packageName, specifier) || 'index',\n )\n\n entry[chunkName] = path.join(packageDir, relativeEntryPoint)\n imports[specifier] = path.posix.join('/', basePath, VENDOR_DIR, `${chunkName}.mjs`)\n }\n }\n\n // removes the `RollupWatcher` type\n type BuildResult = Exclude<Awaited<ReturnType<typeof build>>, {close: unknown}>\n\n // Use Vite to build the packages into the output directory\n let buildResult = (await build({\n appType: 'custom',\n build: {\n commonjsOptions: {strictRequires: 'auto'},\n emptyOutDir: false, // Rely on CLI to do this\n lib: {entry, formats: ['es']},\n minify: true,\n outDir: path.join(outputDir, VENDOR_DIR),\n rollupOptions: {\n external: createExternalFromImportMap({imports}),\n output: {\n chunkFileNames: '[name]-[hash].mjs',\n entryFileNames: '[name]-[hash].mjs',\n exports: 'named',\n format: 'es',\n },\n treeshake: {preset: 'recommended'},\n },\n },\n // Define a custom cache directory so that sanity's vite cache\n // does not conflict with any potential local vite projects\n cacheDir: 'node_modules/.sanity/vite-vendor',\n configFile: false,\n define: {'process.env.NODE_ENV': JSON.stringify('production')},\n logLevel: 'silent',\n mode: 'production',\n root: cwd,\n })) as BuildResult\n\n buildResult = Array.isArray(buildResult) ? buildResult : [buildResult]\n\n // Create a map of the original import specifiers to their hashed filenames\n const hashedImports: Record<string, string> = {}\n const output = buildResult.flatMap((i) => i.output)\n\n for (const chunk of output) {\n if (chunk.type === 'asset') continue\n\n for (const [specifier, originalPath] of Object.entries(imports)) {\n if (originalPath.endsWith(`${chunk.name}.mjs`)) {\n hashedImports[specifier] = path.posix.join('/', basePath, VENDOR_DIR, chunk.fileName)\n }\n }\n }\n\n return hashedImports\n}\n"],"names":["path","semver","build","getLocalPackageDir","getLocalPackageVersion","createExternalFromImportMap","VENDOR_DIR","VENDOR_IMPORTS","react","STYLED_COMPONENTS_IMPORTS","buildVendorDependencies","basePath","cwd","isApp","outputDir","entry","imports","vendorImports","packageName","ranges","Object","entries","version","Error","sortedRanges","keys","toSorted","range1","range2","min1","minVersion","min2","rcompare","matchedRange","find","range","satisfies","min","at","gt","subpaths","packageDir","subpath","relativeEntryPoint","specifier","posix","join","chunkName","relative","buildResult","appType","commonjsOptions","strictRequires","emptyOutDir","lib","formats","minify","outDir","rollupOptions","external","output","chunkFileNames","entryFileNames","exports","format","treeshake","preset","cacheDir","configFile","define","JSON","stringify","logLevel","mode","root","Array","isArray","hashedImports","flatMap","i","chunk","type","originalPath","endsWith","name","fileName"],"mappings":"AA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ACF;IACF;IAEA,OAAOR;AACT"}
@@ -6,11 +6,7 @@ export function getExtractOptions({ flags, projectRoot, schemaExtraction }) {
6
6
  if (pathFlag) {
7
7
  const resolved = resolve(join(projectRoot.directory, pathFlag));
8
8
  const isExistingDirectory = existsSync(resolved) && statSync(resolved).isDirectory();
9
- if (isExistingDirectory || !extname(resolved)) {
10
- outputPath = join(resolved, 'schema.json');
11
- } else {
12
- outputPath = resolved;
13
- }
9
+ outputPath = isExistingDirectory || !extname(resolved) ? join(resolved, 'schema.json') : resolved;
14
10
  } else {
15
11
  outputPath = resolve(join(projectRoot.directory, 'schema.json'));
16
12
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/actions/schema/getExtractOptions.ts"],"sourcesContent":["import {existsSync, statSync} from 'node:fs'\nimport {extname, join, resolve} from 'node:path'\n\nimport {type CliConfig, ProjectRootResult} from '@sanity/cli-core'\n\nimport {type ExtractSchemaCommand} from '../../commands/schema/extract.js'\n\nexport interface ExtractOptions {\n configPath: string\n enforceRequiredFields: boolean\n format: string\n outputPath: string\n watchPatterns: string[]\n workspace: string | undefined\n}\n\ninterface GetExtractionOptions {\n flags: ExtractSchemaCommand['flags']\n projectRoot: ProjectRootResult\n schemaExtraction: CliConfig['schemaExtraction']\n}\n\nexport function getExtractOptions({\n flags,\n projectRoot,\n schemaExtraction,\n}: GetExtractionOptions): ExtractOptions {\n const pathFlag = flags.path ?? schemaExtraction?.path\n let outputPath: string\n if (pathFlag) {\n const resolved = resolve(join(projectRoot.directory, pathFlag))\n const isExistingDirectory = existsSync(resolved) && statSync(resolved).isDirectory()\n\n if (isExistingDirectory || !extname(resolved)) {\n outputPath = join(resolved, 'schema.json')\n } else {\n outputPath = resolved\n }\n } else {\n outputPath = resolve(join(projectRoot.directory, 'schema.json'))\n }\n\n return {\n configPath: projectRoot.path,\n enforceRequiredFields:\n flags['enforce-required-fields'] ?? schemaExtraction?.enforceRequiredFields ?? false,\n format: flags.format ?? 'groq-type-nodes',\n outputPath,\n watchPatterns: flags['watch-patterns'] ?? schemaExtraction?.watchPatterns ?? [],\n workspace: flags.workspace ?? schemaExtraction?.workspace,\n }\n}\n"],"names":["existsSync","statSync","extname","join","resolve","getExtractOptions","flags","projectRoot","schemaExtraction","pathFlag","path","outputPath","resolved","directory","isExistingDirectory","isDirectory","configPath","enforceRequiredFields","format","watchPatterns","workspace"],"mappings":"AAAA,SAAQA,UAAU,EAAEC,QAAQ,QAAO,UAAS;AAC5C,SAAQC,OAAO,EAAEC,IAAI,EAAEC,OAAO,QAAO,YAAW;AAqBhD,OAAO,SAASC,kBAAkB,EAChCC,KAAK,EACLC,WAAW,EACXC,gBAAgB,EACK;IACrB,MAAMC,WAAWH,MAAMI,IAAI,IAAIF,kBAAkBE;IACjD,IAAIC;IACJ,IAAIF,UAAU;QACZ,MAAMG,WAAWR,QAAQD,KAAKI,YAAYM,SAAS,EAAEJ;QACrD,MAAMK,sBAAsBd,WAAWY,aAAaX,SAASW,UAAUG,WAAW;QAElF,IAAID,uBAAuB,CAACZ,QAAQU,WAAW;YAC7CD,aAAaR,KAAKS,UAAU;QAC9B,OAAO;YACLD,aAAaC;QACf;IACF,OAAO;QACLD,aAAaP,QAAQD,KAAKI,YAAYM,SAAS,EAAE;IACnD;IAEA,OAAO;QACLG,YAAYT,YAAYG,IAAI;QAC5BO,uBACEX,KAAK,CAAC,0BAA0B,IAAIE,kBAAkBS,yBAAyB;QACjFC,QAAQZ,MAAMY,MAAM,IAAI;QACxBP;QACAQ,eAAeb,KAAK,CAAC,iBAAiB,IAAIE,kBAAkBW,iBAAiB,EAAE;QAC/EC,WAAWd,MAAMc,SAAS,IAAIZ,kBAAkBY;IAClD;AACF"}
1
+ {"version":3,"sources":["../../../src/actions/schema/getExtractOptions.ts"],"sourcesContent":["import {existsSync, statSync} from 'node:fs'\nimport {extname, join, resolve} from 'node:path'\n\nimport {type CliConfig, ProjectRootResult} from '@sanity/cli-core'\n\nimport {type ExtractSchemaCommand} from '../../commands/schema/extract.js'\n\nexport interface ExtractOptions {\n configPath: string\n enforceRequiredFields: boolean\n format: string\n outputPath: string\n watchPatterns: string[]\n workspace: string | undefined\n}\n\ninterface GetExtractionOptions {\n flags: ExtractSchemaCommand['flags']\n projectRoot: ProjectRootResult\n schemaExtraction: CliConfig['schemaExtraction']\n}\n\nexport function getExtractOptions({\n flags,\n projectRoot,\n schemaExtraction,\n}: GetExtractionOptions): ExtractOptions {\n const pathFlag = flags.path ?? schemaExtraction?.path\n let outputPath: string\n if (pathFlag) {\n const resolved = resolve(join(projectRoot.directory, pathFlag))\n const isExistingDirectory = existsSync(resolved) && statSync(resolved).isDirectory()\n\n outputPath =\n isExistingDirectory || !extname(resolved) ? join(resolved, 'schema.json') : resolved\n } else {\n outputPath = resolve(join(projectRoot.directory, 'schema.json'))\n }\n\n return {\n configPath: projectRoot.path,\n enforceRequiredFields:\n flags['enforce-required-fields'] ?? schemaExtraction?.enforceRequiredFields ?? false,\n format: flags.format ?? 'groq-type-nodes',\n outputPath,\n watchPatterns: flags['watch-patterns'] ?? schemaExtraction?.watchPatterns ?? [],\n workspace: flags.workspace ?? schemaExtraction?.workspace,\n }\n}\n"],"names":["existsSync","statSync","extname","join","resolve","getExtractOptions","flags","projectRoot","schemaExtraction","pathFlag","path","outputPath","resolved","directory","isExistingDirectory","isDirectory","configPath","enforceRequiredFields","format","watchPatterns","workspace"],"mappings":"AAAA,SAAQA,UAAU,EAAEC,QAAQ,QAAO,UAAS;AAC5C,SAAQC,OAAO,EAAEC,IAAI,EAAEC,OAAO,QAAO,YAAW;AAqBhD,OAAO,SAASC,kBAAkB,EAChCC,KAAK,EACLC,WAAW,EACXC,gBAAgB,EACK;IACrB,MAAMC,WAAWH,MAAMI,IAAI,IAAIF,kBAAkBE;IACjD,IAAIC;IACJ,IAAIF,UAAU;QACZ,MAAMG,WAAWR,QAAQD,KAAKI,YAAYM,SAAS,EAAEJ;QACrD,MAAMK,sBAAsBd,WAAWY,aAAaX,SAASW,UAAUG,WAAW;QAElFJ,aACEG,uBAAuB,CAACZ,QAAQU,YAAYT,KAAKS,UAAU,iBAAiBA;IAChF,OAAO;QACLD,aAAaP,QAAQD,KAAKI,YAAYM,SAAS,EAAE;IACnD;IAEA,OAAO;QACLG,YAAYT,YAAYG,IAAI;QAC5BO,uBACEX,KAAK,CAAC,0BAA0B,IAAIE,kBAAkBS,yBAAyB;QACjFC,QAAQZ,MAAMY,MAAM,IAAI;QACxBP;QACAQ,eAAeb,KAAK,CAAC,iBAAiB,IAAIE,kBAAkBW,iBAAiB,EAAE;QAC/EC,WAAWd,MAAMc,SAAS,IAAIZ,kBAAkBY;IAClD;AACF"}
@@ -11,30 +11,43 @@ import { moduleResolve } from 'import-meta-resolve';
11
11
  * @internal
12
12
  */ export async function getLocalPackageVersion(moduleName, workDir) {
13
13
  try {
14
- // Handle import.meta.url being passed instead of a directory path
15
- const dir = workDir.startsWith('file://') ? dirname(fileURLToPath(workDir)) : workDir;
16
- const dirUrl = pathToFileURL(resolve(dir, 'noop.js'));
17
- let packageJsonUrl;
18
- try {
19
- packageJsonUrl = moduleResolve(`${moduleName}/package.json`, dirUrl);
20
- } catch (err) {
21
- if (isErrPackagePathNotExported(err)) {
22
- // Fallback: resolve main entry point and derive package root
23
- const mainUrl = moduleResolve(moduleName, dirUrl);
24
- const mainPath = fileURLToPath(mainUrl);
25
- const normalizedName = normalize(moduleName);
26
- const idx = mainPath.lastIndexOf(normalizedName);
27
- const moduleRoot = mainPath.slice(0, idx + normalizedName.length);
28
- packageJsonUrl = pathToFileURL(join(moduleRoot, 'package.json'));
29
- } else {
30
- throw err;
31
- }
32
- }
33
- return (await readPackageJson(packageJsonUrl)).version;
14
+ const packageDir = getLocalPackageDir(moduleName, workDir);
15
+ return (await readPackageJson(join(packageDir, 'package.json'))).version;
34
16
  } catch {
35
17
  return null;
36
18
  }
37
19
  }
20
+ /**
21
+ * Resolve the filesystem directory of a locally installed package using Node
22
+ * module resolution. Works correctly with hoisted packages in monorepos/workspaces,
23
+ * pnpm symlinks, and other non-standard node_modules layouts.
24
+ *
25
+ * @param moduleName - The name of the package in npm.
26
+ * @param workDir - The working directory to resolve the module from. (aka project root)
27
+ * @returns The absolute path to the package directory.
28
+ * @internal
29
+ */ export function getLocalPackageDir(moduleName, workDir) {
30
+ // Handle import.meta.url being passed instead of a directory path
31
+ const dir = workDir.startsWith('file://') ? dirname(fileURLToPath(workDir)) : workDir;
32
+ const dirUrl = pathToFileURL(resolve(dir, 'noop.js'));
33
+ try {
34
+ const packageJsonUrl = moduleResolve(`${moduleName}/package.json`, dirUrl);
35
+ return dirname(fileURLToPath(packageJsonUrl));
36
+ } catch (err) {
37
+ if (!isErrPackagePathNotExported(err)) {
38
+ throw err;
39
+ }
40
+ }
41
+ // Fallback: resolve main entry point and derive package root
42
+ const mainUrl = moduleResolve(moduleName, dirUrl);
43
+ const mainPath = fileURLToPath(mainUrl);
44
+ const normalizedName = normalize(moduleName);
45
+ const idx = mainPath.lastIndexOf(normalizedName);
46
+ if (idx === -1) {
47
+ throw new Error(`Could not determine package directory for '${moduleName}'`);
48
+ }
49
+ return mainPath.slice(0, idx + normalizedName.length);
50
+ }
38
51
  function isErrPackagePathNotExported(err) {
39
52
  return err instanceof Error && 'code' in err && err.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED';
40
53
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/util/getLocalPackageVersion.ts"],"sourcesContent":["import {dirname, join, normalize, resolve} from 'node:path'\nimport {fileURLToPath, pathToFileURL} from 'node:url'\n\nimport {readPackageJson} from '@sanity/cli-core'\nimport {moduleResolve} from 'import-meta-resolve'\n\n/**\n * Get the version of a package installed locally.\n *\n * @param moduleName - The name of the package in npm.\n * @param workDir - The working directory to resolve the module from. (aka project root)\n * @returns The version of the package installed locally.\n * @internal\n */\nexport async function getLocalPackageVersion(\n moduleName: string,\n workDir: string,\n): Promise<string | null> {\n try {\n // Handle import.meta.url being passed instead of a directory path\n const dir = workDir.startsWith('file://') ? dirname(fileURLToPath(workDir)) : workDir\n const dirUrl = pathToFileURL(resolve(dir, 'noop.js'))\n\n let packageJsonUrl: URL\n try {\n packageJsonUrl = moduleResolve(`${moduleName}/package.json`, dirUrl)\n } catch (err: unknown) {\n if (isErrPackagePathNotExported(err)) {\n // Fallback: resolve main entry point and derive package root\n const mainUrl = moduleResolve(moduleName, dirUrl)\n const mainPath = fileURLToPath(mainUrl)\n const normalizedName = normalize(moduleName)\n const idx = mainPath.lastIndexOf(normalizedName)\n const moduleRoot = mainPath.slice(0, idx + normalizedName.length)\n packageJsonUrl = pathToFileURL(join(moduleRoot, 'package.json'))\n } else {\n throw err\n }\n }\n\n return (await readPackageJson(packageJsonUrl)).version\n } catch {\n return null\n }\n}\n\nfunction isErrPackagePathNotExported(err: unknown): boolean {\n return err instanceof Error && 'code' in err && err.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED'\n}\n"],"names":["dirname","join","normalize","resolve","fileURLToPath","pathToFileURL","readPackageJson","moduleResolve","getLocalPackageVersion","moduleName","workDir","dir","startsWith","dirUrl","packageJsonUrl","err","isErrPackagePathNotExported","mainUrl","mainPath","normalizedName","idx","lastIndexOf","moduleRoot","slice","length","version","Error","code"],"mappings":"AAAA,SAAQA,OAAO,EAAEC,IAAI,EAAEC,SAAS,EAAEC,OAAO,QAAO,YAAW;AAC3D,SAAQC,aAAa,EAAEC,aAAa,QAAO,WAAU;AAErD,SAAQC,eAAe,QAAO,mBAAkB;AAChD,SAAQC,aAAa,QAAO,sBAAqB;AAEjD;;;;;;;CAOC,GACD,OAAO,eAAeC,uBACpBC,UAAkB,EAClBC,OAAe;IAEf,IAAI;QACF,kEAAkE;QAClE,MAAMC,MAAMD,QAAQE,UAAU,CAAC,aAAaZ,QAAQI,cAAcM,YAAYA;QAC9E,MAAMG,SAASR,cAAcF,QAAQQ,KAAK;QAE1C,IAAIG;QACJ,IAAI;YACFA,iBAAiBP,cAAc,GAAGE,WAAW,aAAa,CAAC,EAAEI;QAC/D,EAAE,OAAOE,KAAc;YACrB,IAAIC,4BAA4BD,MAAM;gBACpC,6DAA6D;gBAC7D,MAAME,UAAUV,cAAcE,YAAYI;gBAC1C,MAAMK,WAAWd,cAAca;gBAC/B,MAAME,iBAAiBjB,UAAUO;gBACjC,MAAMW,MAAMF,SAASG,WAAW,CAACF;gBACjC,MAAMG,aAAaJ,SAASK,KAAK,CAAC,GAAGH,MAAMD,eAAeK,MAAM;gBAChEV,iBAAiBT,cAAcJ,KAAKqB,YAAY;YAClD,OAAO;gBACL,MAAMP;YACR;QACF;QAEA,OAAO,AAAC,CAAA,MAAMT,gBAAgBQ,eAAc,EAAGW,OAAO;IACxD,EAAE,OAAM;QACN,OAAO;IACT;AACF;AAEA,SAAST,4BAA4BD,GAAY;IAC/C,OAAOA,eAAeW,SAAS,UAAUX,OAAOA,IAAIY,IAAI,KAAK;AAC/D"}
1
+ {"version":3,"sources":["../../src/util/getLocalPackageVersion.ts"],"sourcesContent":["import {dirname, join, normalize, resolve} from 'node:path'\nimport {fileURLToPath, pathToFileURL} from 'node:url'\n\nimport {readPackageJson} from '@sanity/cli-core'\nimport {moduleResolve} from 'import-meta-resolve'\n\n/**\n * Get the version of a package installed locally.\n *\n * @param moduleName - The name of the package in npm.\n * @param workDir - The working directory to resolve the module from. (aka project root)\n * @returns The version of the package installed locally.\n * @internal\n */\nexport async function getLocalPackageVersion(\n moduleName: string,\n workDir: string,\n): Promise<string | null> {\n try {\n const packageDir = getLocalPackageDir(moduleName, workDir)\n return (await readPackageJson(join(packageDir, 'package.json'))).version\n } catch {\n return null\n }\n}\n\n/**\n * Resolve the filesystem directory of a locally installed package using Node\n * module resolution. Works correctly with hoisted packages in monorepos/workspaces,\n * pnpm symlinks, and other non-standard node_modules layouts.\n *\n * @param moduleName - The name of the package in npm.\n * @param workDir - The working directory to resolve the module from. (aka project root)\n * @returns The absolute path to the package directory.\n * @internal\n */\nexport function getLocalPackageDir(moduleName: string, workDir: string): string {\n // Handle import.meta.url being passed instead of a directory path\n const dir = workDir.startsWith('file://') ? dirname(fileURLToPath(workDir)) : workDir\n const dirUrl = pathToFileURL(resolve(dir, 'noop.js'))\n\n try {\n const packageJsonUrl = moduleResolve(`${moduleName}/package.json`, dirUrl)\n return dirname(fileURLToPath(packageJsonUrl))\n } catch (err: unknown) {\n if (!isErrPackagePathNotExported(err)) {\n throw err\n }\n }\n\n // Fallback: resolve main entry point and derive package root\n const mainUrl = moduleResolve(moduleName, dirUrl)\n const mainPath = fileURLToPath(mainUrl)\n const normalizedName = normalize(moduleName)\n const idx = mainPath.lastIndexOf(normalizedName)\n if (idx === -1) {\n throw new Error(`Could not determine package directory for '${moduleName}'`)\n }\n return mainPath.slice(0, idx + normalizedName.length)\n}\n\nfunction isErrPackagePathNotExported(err: unknown): boolean {\n return err instanceof Error && 'code' in err && err.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED'\n}\n"],"names":["dirname","join","normalize","resolve","fileURLToPath","pathToFileURL","readPackageJson","moduleResolve","getLocalPackageVersion","moduleName","workDir","packageDir","getLocalPackageDir","version","dir","startsWith","dirUrl","packageJsonUrl","err","isErrPackagePathNotExported","mainUrl","mainPath","normalizedName","idx","lastIndexOf","Error","slice","length","code"],"mappings":"AAAA,SAAQA,OAAO,EAAEC,IAAI,EAAEC,SAAS,EAAEC,OAAO,QAAO,YAAW;AAC3D,SAAQC,aAAa,EAAEC,aAAa,QAAO,WAAU;AAErD,SAAQC,eAAe,QAAO,mBAAkB;AAChD,SAAQC,aAAa,QAAO,sBAAqB;AAEjD;;;;;;;CAOC,GACD,OAAO,eAAeC,uBACpBC,UAAkB,EAClBC,OAAe;IAEf,IAAI;QACF,MAAMC,aAAaC,mBAAmBH,YAAYC;QAClD,OAAO,AAAC,CAAA,MAAMJ,gBAAgBL,KAAKU,YAAY,gBAAe,EAAGE,OAAO;IAC1E,EAAE,OAAM;QACN,OAAO;IACT;AACF;AAEA;;;;;;;;;CASC,GACD,OAAO,SAASD,mBAAmBH,UAAkB,EAAEC,OAAe;IACpE,kEAAkE;IAClE,MAAMI,MAAMJ,QAAQK,UAAU,CAAC,aAAaf,QAAQI,cAAcM,YAAYA;IAC9E,MAAMM,SAASX,cAAcF,QAAQW,KAAK;IAE1C,IAAI;QACF,MAAMG,iBAAiBV,cAAc,GAAGE,WAAW,aAAa,CAAC,EAAEO;QACnE,OAAOhB,QAAQI,cAAca;IAC/B,EAAE,OAAOC,KAAc;QACrB,IAAI,CAACC,4BAA4BD,MAAM;YACrC,MAAMA;QACR;IACF;IAEA,6DAA6D;IAC7D,MAAME,UAAUb,cAAcE,YAAYO;IAC1C,MAAMK,WAAWjB,cAAcgB;IAC/B,MAAME,iBAAiBpB,UAAUO;IACjC,MAAMc,MAAMF,SAASG,WAAW,CAACF;IACjC,IAAIC,QAAQ,CAAC,GAAG;QACd,MAAM,IAAIE,MAAM,CAAC,2CAA2C,EAAEhB,WAAW,CAAC,CAAC;IAC7E;IACA,OAAOY,SAASK,KAAK,CAAC,GAAGH,MAAMD,eAAeK,MAAM;AACtD;AAEA,SAASR,4BAA4BD,GAAY;IAC/C,OAAOA,eAAeO,SAAS,UAAUP,OAAOA,IAAIU,IAAI,KAAK;AAC/D"}
@@ -3628,6 +3628,84 @@
3628
3628
  "list.js"
3629
3629
  ]
3630
3630
  },
3631
+ "telemetry:disable": {
3632
+ "aliases": [],
3633
+ "args": {},
3634
+ "description": "Disable telemetry for your logged in user",
3635
+ "examples": [
3636
+ {
3637
+ "command": "<%= config.bin %> telemetry <%= command.id %>",
3638
+ "description": "Disable telemetry for your logged in user"
3639
+ }
3640
+ ],
3641
+ "flags": {},
3642
+ "hasDynamicHelp": false,
3643
+ "hiddenAliases": [],
3644
+ "id": "telemetry:disable",
3645
+ "pluginAlias": "@sanity/cli",
3646
+ "pluginName": "@sanity/cli",
3647
+ "pluginType": "core",
3648
+ "strict": true,
3649
+ "isESM": true,
3650
+ "relativePath": [
3651
+ "dist",
3652
+ "commands",
3653
+ "telemetry",
3654
+ "disable.js"
3655
+ ]
3656
+ },
3657
+ "telemetry:enable": {
3658
+ "aliases": [],
3659
+ "args": {},
3660
+ "description": "Enable telemetry for your logged in user",
3661
+ "examples": [
3662
+ {
3663
+ "command": "<%= config.bin %> telemetry <%= command.id %>",
3664
+ "description": "Enable telemetry for your logged in user"
3665
+ }
3666
+ ],
3667
+ "flags": {},
3668
+ "hasDynamicHelp": false,
3669
+ "hiddenAliases": [],
3670
+ "id": "telemetry:enable",
3671
+ "pluginAlias": "@sanity/cli",
3672
+ "pluginName": "@sanity/cli",
3673
+ "pluginType": "core",
3674
+ "strict": true,
3675
+ "isESM": true,
3676
+ "relativePath": [
3677
+ "dist",
3678
+ "commands",
3679
+ "telemetry",
3680
+ "enable.js"
3681
+ ]
3682
+ },
3683
+ "telemetry:status": {
3684
+ "aliases": [],
3685
+ "args": {},
3686
+ "description": "Check telemetry consent status for your logged in user",
3687
+ "examples": [
3688
+ {
3689
+ "command": "<%= config.bin %> telemetry <%= command.id %>",
3690
+ "description": "Check telemetry consent status for your logged in user"
3691
+ }
3692
+ ],
3693
+ "flags": {},
3694
+ "hasDynamicHelp": false,
3695
+ "hiddenAliases": [],
3696
+ "id": "telemetry:status",
3697
+ "pluginAlias": "@sanity/cli",
3698
+ "pluginName": "@sanity/cli",
3699
+ "pluginType": "core",
3700
+ "strict": true,
3701
+ "isESM": true,
3702
+ "relativePath": [
3703
+ "dist",
3704
+ "commands",
3705
+ "telemetry",
3706
+ "status.js"
3707
+ ]
3708
+ },
3631
3709
  "schema:delete": {
3632
3710
  "aliases": [],
3633
3711
  "args": {},
@@ -4004,84 +4082,6 @@
4004
4082
  "validate.js"
4005
4083
  ]
4006
4084
  },
4007
- "telemetry:disable": {
4008
- "aliases": [],
4009
- "args": {},
4010
- "description": "Disable telemetry for your logged in user",
4011
- "examples": [
4012
- {
4013
- "command": "<%= config.bin %> telemetry <%= command.id %>",
4014
- "description": "Disable telemetry for your logged in user"
4015
- }
4016
- ],
4017
- "flags": {},
4018
- "hasDynamicHelp": false,
4019
- "hiddenAliases": [],
4020
- "id": "telemetry:disable",
4021
- "pluginAlias": "@sanity/cli",
4022
- "pluginName": "@sanity/cli",
4023
- "pluginType": "core",
4024
- "strict": true,
4025
- "isESM": true,
4026
- "relativePath": [
4027
- "dist",
4028
- "commands",
4029
- "telemetry",
4030
- "disable.js"
4031
- ]
4032
- },
4033
- "telemetry:enable": {
4034
- "aliases": [],
4035
- "args": {},
4036
- "description": "Enable telemetry for your logged in user",
4037
- "examples": [
4038
- {
4039
- "command": "<%= config.bin %> telemetry <%= command.id %>",
4040
- "description": "Enable telemetry for your logged in user"
4041
- }
4042
- ],
4043
- "flags": {},
4044
- "hasDynamicHelp": false,
4045
- "hiddenAliases": [],
4046
- "id": "telemetry:enable",
4047
- "pluginAlias": "@sanity/cli",
4048
- "pluginName": "@sanity/cli",
4049
- "pluginType": "core",
4050
- "strict": true,
4051
- "isESM": true,
4052
- "relativePath": [
4053
- "dist",
4054
- "commands",
4055
- "telemetry",
4056
- "enable.js"
4057
- ]
4058
- },
4059
- "telemetry:status": {
4060
- "aliases": [],
4061
- "args": {},
4062
- "description": "Check telemetry consent status for your logged in user",
4063
- "examples": [
4064
- {
4065
- "command": "<%= config.bin %> telemetry <%= command.id %>",
4066
- "description": "Check telemetry consent status for your logged in user"
4067
- }
4068
- ],
4069
- "flags": {},
4070
- "hasDynamicHelp": false,
4071
- "hiddenAliases": [],
4072
- "id": "telemetry:status",
4073
- "pluginAlias": "@sanity/cli",
4074
- "pluginName": "@sanity/cli",
4075
- "pluginType": "core",
4076
- "strict": true,
4077
- "isESM": true,
4078
- "relativePath": [
4079
- "dist",
4080
- "commands",
4081
- "telemetry",
4082
- "status.js"
4083
- ]
4084
- },
4085
4085
  "tokens:add": {
4086
4086
  "aliases": [],
4087
4087
  "args": {
@@ -4943,5 +4943,5 @@
4943
4943
  ]
4944
4944
  }
4945
4945
  },
4946
- "version": "6.1.6"
4946
+ "version": "6.1.7"
4947
4947
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/cli",
3
- "version": "6.1.6",
3
+ "version": "6.1.7",
4
4
  "description": "Sanity CLI tool for managing Sanity projects and organizations",
5
5
  "keywords": [
6
6
  "cli",
@@ -149,10 +149,10 @@
149
149
  "typescript": "^5.9.3",
150
150
  "vite-tsconfig-paths": "^6.1.1",
151
151
  "vitest": "^4.1.0",
152
- "@repo/tsconfig": "3.70.0",
153
152
  "@repo/package.config": "0.0.1",
154
- "@sanity/eslint-config-cli": "1.0.0",
155
- "@sanity/cli-test": "0.2.4"
153
+ "@repo/tsconfig": "3.70.0",
154
+ "@sanity/cli-test": "0.2.4",
155
+ "@sanity/eslint-config-cli": "1.0.0"
156
156
  },
157
157
  "engines": {
158
158
  "node": ">=20.19.1 <22 || >=22.12"