diff --git a/packages/@sanity/cli/src/util/resolveRootDir.ts b/packages/@sanity/cli/src/util/resolveRootDir.ts index 142b78263a5..12ec0dd40cd 100644 --- a/packages/@sanity/cli/src/util/resolveRootDir.ts +++ b/packages/@sanity/cli/src/util/resolveRootDir.ts @@ -17,8 +17,8 @@ export function resolveRootDir(cwd: string): string { function hasStudioConfig(basePath: string): boolean { const buildConfigs = [ - fileExists(path.join(basePath, 'studio.config.js')), - fileExists(path.join(basePath, 'studio.config.ts')), + fileExists(path.join(basePath, 'sanity.config.js')), + fileExists(path.join(basePath, 'sanity.config.ts')), isSanityV2StudioRoot(basePath), ] diff --git a/packages/@sanity/cli/test/basics.test.ts b/packages/@sanity/cli/test/basics.test.ts index 049afb5d977..de9015b8712 100644 --- a/packages/@sanity/cli/test/basics.test.ts +++ b/packages/@sanity/cli/test/basics.test.ts @@ -1,3 +1,5 @@ +import path from 'node:path' + import {describeCliTest, testConcurrent} from './shared/describe' import {getCliUserEmail, runSanityCmdCommand, studioVersions} from './shared/environment' @@ -23,6 +25,15 @@ describeCliTest('CLI: basic commands', () => { expect(result.code).toBe(0) }) + testConcurrent('help (from subdirectory)', async () => { + const result = await runSanityCmdCommand(version, ['help'], { + cwd: (cwd) => path.join(cwd, 'components'), + }) + expect(result.stdout).toContain('Not in project directory') + expect(result.stdout).toMatch(/usage:/i) + expect(result.code).toBe(0) + }) + testConcurrent('projects list', async () => { const result = await runSanityCmdCommand(version, ['projects', 'list']) expect(result.stdout).toContain('.sanity.studio') diff --git a/packages/@sanity/cli/test/shared/environment.ts b/packages/@sanity/cli/test/shared/environment.ts index d9626cdbb89..1ba455afe8c 100644 --- a/packages/@sanity/cli/test/shared/environment.ts +++ b/packages/@sanity/cli/test/shared/environment.ts @@ -125,14 +125,16 @@ export const getTestRunArgs = (version: string) => { export function runSanityCmdCommand( version: string, args: string[], - options: {env?: Record} = {}, + options: {env?: Record; cwd?: (cwd: string) => string} = {}, ): Promise<{ code: number | null stdout: string stderr: string }> { + const cwd = options.cwd ?? ((currentCwd) => currentCwd) + return exec(process.argv[0], [cliBinPath, ...args], { - cwd: path.join(studiosPath, version), + cwd: cwd(path.join(studiosPath, version)), env: {...sanityEnv, ...options.env}, }) }