Skip to content

Commit

Permalink
Merge pull request #18297 from abpframework/improve-validate-version-…
Browse files Browse the repository at this point in the history
…message

improve validate version message
  • Loading branch information
masum-ulu authored Nov 29, 2023
2 parents 4ae705b + 1f7eb9c commit 7c7f71a
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions npm/scripts/validate-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async function compare() {
!excludedPackages.includes(pkgJson.name) &&
pkgJson.version !== compareVersion
) {
throwError(pkgJsonPath, pkgJson.name);
throwError(pkgJsonPath, pkgJson.name, pkgJson.version);
}

const { dependencies, peerDependencies } = pkgJson;
Expand All @@ -63,20 +63,27 @@ async function compareDependencies(

for (let i = 0; i < entries.length; i++) {
const entry = entries[i];

const packageName = entry[0];
const version = getCleanVersionName(entry[1]);
const cleanCompareVersion = getCleanVersionName(compareVersion);
if (
!excludedPackages.includes(entry[0]) &&
entry[0].match(/@(abp|volo)/)?.length &&
entry[1] !== `~${compareVersion}`
packageName.match(/@(abp|volo)/)?.length &&
version !== cleanCompareVersion
) {
throwError(filePath, entry[0], `~${compareVersion}`);
throwError(filePath, entry[0], cleanCompareVersion);
}
}
}

function throwError(filePath: string, pkg: string, version?: string) {
const { compareVersion } = program.opts();

log.error(`${filePath}: ${pkg} version is not ${version || compareVersion}`);
log.error(`${filePath}: ${pkg} version is not ${compareVersion}. it is ${version}`);
process.exit(1);
}

function getCleanVersionName(version) {
// Remove caret (^) or tilde (~) from the beginning of the version number
return version.replace(/^[\^~]+/, '');
}

0 comments on commit 7c7f71a

Please sign in to comment.