Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: move cliInitializedAt call higher in init flow #7558

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'})

// Bootstrap Sanity, creating required project files, manifests etc
await bootstrapTemplate(templateOptions, context)

// update that files were initialized locally; do not halt flow for request
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')
})
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
Loading