Skip to content

Commit

Permalink
feat: show all incompatible versions in the warning prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
binoy14 committed May 17, 2024
1 parent 7f5f7c7 commit 50bf5a4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
10 changes: 5 additions & 5 deletions packages/sanity/src/_internal/cli/actions/build/buildAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Array<CompareStudioDependencyVersions>> {
const manifest = readPackageJson(path.join(workDir, 'package.json'))
const dependencies = {...manifest.dependencies, ...manifest.devDependencies}

const failedDependencies: Array<CompareStudioDependencyVersions> = []

for (const [pkg, value] of Object.entries(AUTO_UPDATE_PACKAGES)) {
const resolvedVersion = await getRemoteResolvedVersion(value.url)

Expand All @@ -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
}

0 comments on commit 50bf5a4

Please sign in to comment.