Skip to content

Commit

Permalink
wrap in Promise.allSettled
Browse files Browse the repository at this point in the history
  • Loading branch information
svirs committed Oct 1, 2024
1 parent 5a4e770 commit eb33d25
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions packages/@sanity/cli/src/actions/init-project/initProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,26 +594,31 @@ export default async function initSanity(

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

// record that template files attempted to be created locally
await apiClient({api: {projectId: projectId}})
.request<SanityProject>({uri: `/projects/${projectId}`})
.then((project: SanityProject) => {
if (!project?.metadata?.cliInitializedAt) {
return apiClient({api: {projectId}}).request({
method: 'PATCH',
uri: `/projects/${projectId}`,
body: {metadata: {cliInitializedAt: new Date().toISOString()}},
})
}
return Promise.resolve()
})
.catch(() => {
// Non-critical update
debug('Failed to update cliInitializedAt metadata')
})

// Bootstrap Sanity, creating required project files, manifests etc
await bootstrapTemplate(templateOptions, context)
const [_, bootstrapPromise] = await Promise.allSettled([
// record template files attempted to be created locally
apiClient({api: {projectId: projectId}})
.request<SanityProject>({uri: `/projects/${projectId}`})
.then((project: SanityProject) => {
if (!project?.metadata?.cliInitializedAt) {
return apiClient({api: {projectId}}).request({
method: 'PATCH',
uri: `/projects/${projectId}`,
body: {metadata: {cliInitializedAt: new Date().toISOString()}},
})
}
return Promise.resolve()
})
.catch(() => {
// Non-critical update
debug('Failed to update cliInitializedAt metadata')
}),
// Bootstrap Sanity, creating required project files, manifests etc
bootstrapTemplate(templateOptions, context),
])

if (bootstrapPromise.status === 'rejected' && bootstrapPromise.reason instanceof Error) {
throw bootstrapPromise.reason
}

let pkgManager: PackageManager

Expand Down

0 comments on commit eb33d25

Please sign in to comment.