Skip to content

Commit ea186d8

Browse files
authored
fix: set cliInitializedAt even if project bootstrap fails (#7558)
1 parent 2e47715 commit ea186d8

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

packages/@sanity/cli/src/actions/init-project/initProject.ts

+25-20
Original file line numberDiff line numberDiff line change
@@ -594,26 +594,31 @@ export default async function initSanity(
594594

595595
trace.log({step: 'importTemplateDataset', selectedOption: shouldImport ? 'yes' : 'no'})
596596

597-
// Bootstrap Sanity, creating required project files, manifests etc
598-
await bootstrapTemplate(templateOptions, context)
599-
600-
// update that files were initialized locally; do not halt flow for request
601-
apiClient({api: {projectId: projectId}})
602-
.request<SanityProject>({uri: `/projects/${projectId}`})
603-
.then((project: SanityProject) => {
604-
if (!project?.metadata?.cliInitializedAt) {
605-
return apiClient({api: {projectId}}).request({
606-
method: 'PATCH',
607-
uri: `/projects/${projectId}`,
608-
body: {metadata: {cliInitializedAt: new Date().toISOString()}},
609-
})
610-
}
611-
return Promise.resolve()
612-
})
613-
.catch(() => {
614-
// Non-critical update
615-
debug('Failed to update cliInitializedAt metadata')
616-
})
597+
const [_, bootstrapPromise] = await Promise.allSettled([
598+
// record template files attempted to be created locally
599+
apiClient({api: {projectId: projectId}})
600+
.request<SanityProject>({uri: `/projects/${projectId}`})
601+
.then((project: SanityProject) => {
602+
if (!project?.metadata?.cliInitializedAt) {
603+
return apiClient({api: {projectId}}).request({
604+
method: 'PATCH',
605+
uri: `/projects/${projectId}`,
606+
body: {metadata: {cliInitializedAt: new Date().toISOString()}},
607+
})
608+
}
609+
return Promise.resolve()
610+
})
611+
.catch(() => {
612+
// Non-critical update
613+
debug('Failed to update cliInitializedAt metadata')
614+
}),
615+
// Bootstrap Sanity, creating required project files, manifests etc
616+
bootstrapTemplate(templateOptions, context),
617+
])
618+
619+
if (bootstrapPromise.status === 'rejected' && bootstrapPromise.reason instanceof Error) {
620+
throw bootstrapPromise.reason
621+
}
617622

618623
let pkgManager: PackageManager
619624

0 commit comments

Comments
 (0)