From 125a6f84ae9ae5531ee22dec27d3e4b5605bde13 Mon Sep 17 00:00:00 2001 From: Binoy Patel Date: Fri, 17 May 2024 11:01:31 -0400 Subject: [PATCH] feat: show all incompatible versions in the warning prompt --- .../cli/actions/build/buildAction.ts | 10 +++--- .../util/compareStudioDependencyVersions.ts | 31 ++++++++----------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/packages/sanity/src/_internal/cli/actions/build/buildAction.ts b/packages/sanity/src/_internal/cli/actions/build/buildAction.ts index 77ac910da22..3da45594425 100644 --- a/packages/sanity/src/_internal/cli/actions/build/buildAction.ts +++ b/packages/sanity/src/_internal/cli/actions/build/buildAction.ts @@ -67,19 +67,19 @@ export default async function buildSanityStudio( try { const result = await compareStudioDependencyVersions(workDir) - if (result?.error) { - const {pkg, installed, remote} = result.error + if (result?.length) { const shouldContinue = await prompt.single({ type: 'confirm', message: chalk.yellow( - `The version of ${chalk.underline(pkg)} installed (${chalk.underline(installed)}) does not match the version on the remote (${chalk.underline(remote)}).\n` + - `Do you want to continue anyway?`, + `The following versions are different from the versions available with auto updates enabled. \n` + + `This may lead to issues in the studio. \n\n` + + `${result.map((mod) => ` - ${mod.pkg} (installed: ${mod.installed}, want: ${mod.remote})`).join('\n')}`, ), default: false, }) if (!shouldContinue) { - process.exit(0) + return process.exit(0) } } } catch (err) { diff --git a/packages/sanity/src/_internal/cli/util/compareStudioDependencyVersions.ts b/packages/sanity/src/_internal/cli/util/compareStudioDependencyVersions.ts index 39bd6cbb150..4914a7204cd 100644 --- a/packages/sanity/src/_internal/cli/util/compareStudioDependencyVersions.ts +++ b/packages/sanity/src/_internal/cli/util/compareStudioDependencyVersions.ts @@ -47,19 +47,20 @@ async function getRemoteResolvedVersion(url: string) { } } -export async function compareStudioDependencyVersions(workDir: string): Promise< - | { - error?: { - pkg: string - installed: string - remote: string - } - } - | undefined -> { +interface CompareStudioDependencyVersions { + pkg: string + installed: string + remote: string +} + +export async function compareStudioDependencyVersions( + workDir: string, +): Promise> { const manifest = readPackageJson(path.join(workDir, 'package.json')) const dependencies = {...manifest.dependencies, ...manifest.devDependencies} + const failedDependencies: Array = [] + for (const [pkg, value] of Object.entries(AUTO_UPDATE_PACKAGES)) { const resolvedVersion = await getRemoteResolvedVersion(value.url) @@ -79,15 +80,9 @@ export async function compareStudioDependencyVersions(workDir: string): Promise< } if (!semver.eq(resolvedVersion, installed.version)) { - return { - error: { - pkg, - installed: installed.version, - remote: resolvedVersion, - }, - } + failedDependencies.push({pkg, installed: installed.version, remote: resolvedVersion}) } } - return undefined + return failedDependencies }