Skip to content

Commit 981e34c

Browse files
rexxarsclaude
andcommitted
fix(deploy): strip protocol prefix from internal --url, fix return type
Strip https:// prefix from --url for internal deploys so that `--url https://my-studio.sanity.studio` correctly resolves to `my-studio` instead of `https://my-studio`. Also fix the unattended error path in findUserApplicationForStudio to return null instead of undefined for consistency. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent cdccf1c commit 981e34c

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

packages/@sanity/cli/src/actions/deploy/deployStudio.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,6 @@ function resolveAppHost({
224224
return normalized
225225
}
226226

227-
// For internal deploys, strip .sanity.studio suffix if present
228-
return url.replace(/\.sanity\.studio\/?$/i, '')
227+
// For internal deploys, strip protocol prefix and .sanity.studio suffix if present
228+
return url.replace(/^https?:\/\//i, '').replace(/\.sanity\.studio\/?$/i, '')
229229
}

packages/@sanity/cli/src/actions/deploy/findUserApplicationForStudio.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export async function findUserApplicationForStudio(options: FindUserApplicationF
7474
`Multiple studios found for this project. Cannot select in unattended mode. ${flagHint}.`,
7575
{exit: 1},
7676
)
77-
return
77+
return null
7878
}
7979

8080
// If there are user applications, allow the user to select one of the existing host names,

packages/@sanity/cli/src/commands/__tests__/deploy.studio.test.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,62 @@ describe('#deploy studio', () => {
13731373
expect(stdout).toContain('Success! Studio deployed')
13741374
})
13751375

1376+
test('should strip https:// prefix and .sanity.studio suffix from --url flag', async () => {
1377+
const cwd = await testFixture('basic-studio')
1378+
process.cwd = () => cwd
1379+
1380+
const projectId = 'test-project-id'
1381+
const studioHost = 'my-studio'
1382+
const studioAppId = 'studio-app-id'
1383+
const deploymentId = 'deployment-id'
1384+
1385+
// The stripped hostname should be used for lookup
1386+
mockApi({
1387+
apiVersion: USER_APPLICATIONS_API_VERSION,
1388+
query: {
1389+
appHost: studioHost,
1390+
appType: 'studio',
1391+
},
1392+
uri: `/projects/${projectId}/user-applications`,
1393+
}).reply(200, {
1394+
appHost: studioHost,
1395+
createdAt: '2024-01-01T00:00:00Z',
1396+
id: studioAppId,
1397+
projectId,
1398+
title: 'My Studio',
1399+
type: 'studio',
1400+
updatedAt: '2024-01-01T00:00:00Z',
1401+
urlType: 'internal',
1402+
})
1403+
1404+
mockApi({
1405+
apiVersion: USER_APPLICATIONS_API_VERSION,
1406+
method: 'post',
1407+
query: {appType: 'studio'},
1408+
uri: `/projects/${projectId}/user-applications/${studioAppId}/deployments`,
1409+
}).reply(
1410+
201,
1411+
{id: deploymentId, location: `https://${studioHost}.sanity.studio`},
1412+
{location: `https://${studioHost}.sanity.studio`},
1413+
)
1414+
1415+
const {error, stdout} = await testCommand(
1416+
DeployCommand,
1417+
['--url', 'https://my-studio.sanity.studio'],
1418+
{
1419+
config: {root: cwd},
1420+
mocks: {
1421+
cliConfig: {
1422+
api: {projectId},
1423+
},
1424+
},
1425+
},
1426+
)
1427+
1428+
if (error) throw error
1429+
expect(stdout).toContain('Success! Studio deployed')
1430+
})
1431+
13761432
test('should --url flag take precedence over studioHost config', async () => {
13771433
const cwd = await testFixture('basic-studio')
13781434
process.cwd = () => cwd

0 commit comments

Comments
 (0)