From eb33d25e7d391a4dd96ea5484c3ea316f1528534 Mon Sep 17 00:00:00 2001 From: svirs Date: Tue, 1 Oct 2024 03:11:41 +0200 Subject: [PATCH] wrap in Promise.allSettled --- .../src/actions/init-project/initProject.ts | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/packages/@sanity/cli/src/actions/init-project/initProject.ts b/packages/@sanity/cli/src/actions/init-project/initProject.ts index 78cd4104199..dac97466649 100644 --- a/packages/@sanity/cli/src/actions/init-project/initProject.ts +++ b/packages/@sanity/cli/src/actions/init-project/initProject.ts @@ -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({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({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