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

improve validate version message #18297

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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(/^[\^~]+/, '');
}