import { checkBinaryUpgrade, isSelfContainedBinary } from './binary-upgrade'
import { checkNpmUpgrade } from './upgrade-check'

export function getNpmPackageOverride(): string | undefined {
  const v = (process.env.DIMCODE_NPM_PACKAGE || '').trim()
  return v || undefined
}

export async function checkUpgrade(): Promise<string | null> {
  const npmPackage = getNpmPackageOverride()
  if (npmPackage)
    return await checkNpmUpgrade(npmPackage)
  if (isSelfContainedBinary())
    return await checkBinaryUpgrade()
  return await checkNpmUpgrade()
}
