Skip to content

Commit

Permalink
build: re-enable latest version checks during release
Browse files Browse the repository at this point in the history
This commit restores the latest version checks, which are now fixed by using the stamped versions.
  • Loading branch information
alan-agius4 committed Jan 30, 2025
1 parent c0d20e0 commit 2552093
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
5 changes: 2 additions & 3 deletions scripts/release-checks/dependency-ranges/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ export async function assertValidDependencyRanges(
}

const failures: string[] = [
...(await checkPeerDependencies(newVersion, allPackages)),
// TODO: Re-enable the following once the checks are performed against the stamped `.js` file instead of the source `.json` file.
// ...(await checkSchematicsAngularLatestVersion(newVersion)),
...checkPeerDependencies(newVersion, allPackages),
...checkSchematicsAngularLatestVersion(newVersion),
];

if (failures.length !== 0) {
Expand Down
29 changes: 16 additions & 13 deletions scripts/release-checks/dependency-ranges/latest-versions-check.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,33 @@
* found in the LICENSE file at https://angular.dev/license
*/

import { readFile } from 'node:fs/promises';
import { createRequire } from 'node:module';
import { fileURLToPath } from 'node:url';
import semver from 'semver';

export async function checkSchematicsAngularLatestVersion(
newVersion: semver.SemVer,
): Promise<string[]> {
const { dependencies } = JSON.parse(
await readFile('./packages/schematics/angular/utility/latest-versions/package.json', 'utf-8'),
export function checkSchematicsAngularLatestVersion(newVersion: semver.SemVer): string[] {
// Root of the Angular CLI project.
const root = fileURLToPath(new URL('../../../', import.meta.url));
const rootRequire = createRequire(root);
const { latestVersions } = rootRequire(
'./dist/releases/schematics/angular/utility/latest-versions.js',
);

const keysToCheck = ['ng-packagr', '@angular/core'];
const { major, minor } = newVersion;
const isPrerelease = !!newVersion.prerelease[0];
const keysToCheck = ['Angular', 'NgPackagr'];
const { major, minor, prerelease } = newVersion;
const isPrerelease = !!prerelease[0];
const failures: string[] = [];

let expectedFwDep = `^${major}.${minor}.0`;
let expectedVersionDep = `^${major}.${minor}.0`;
if (isPrerelease) {
expectedFwDep = `^${major}.${minor}.0-next.0`;
expectedVersionDep += '-next.0';
}

for (const key of keysToCheck) {
if (dependencies[key] !== expectedFwDep) {
const latestVersion = latestVersions[key];
if (latestVersion !== expectedVersionDep) {
failures.push(
`latest-versions: Invalid dependency range for "${key}". Expected: ${expectedFwDep}`,
`latest-versions: Invalid dependency range for "${key}". Expected: ${expectedVersionDep} but got: ${latestVersion}`,
);
}
}
Expand Down
10 changes: 5 additions & 5 deletions scripts/release-checks/dependency-ranges/peer-deps-check.mts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ export interface PackageJson {
peerDependencies?: Record<string, string>;
}

export async function checkPeerDependencies(
export function checkPeerDependencies(
newVersion: semver.SemVer,
allPackages: PackageJson[],
): Promise<string[]> {
const { major, minor } = newVersion;
const isPrerelease = !!newVersion.prerelease[0];
): string[] {
const { major, minor, prerelease } = newVersion;
const isPrerelease = !!prerelease[0];
const isMajor = minor === 0;

let expectedFwPeerDep = `^${major}.0.0`;
Expand Down Expand Up @@ -58,7 +58,7 @@ function checkPackage(pkgJson: PackageJson, expectedFwPeerDep: string): string[]

if (range !== expectedFwPeerDep) {
failures.push(
`${pkgJson.name}: Unexpected peer dependency range for "${depName}". Expected: ${expectedFwPeerDep}`,
`${pkgJson.name}: Unexpected peer dependency range for "${depName}". Expected: ${expectedFwPeerDep} but got: ${range}`,
);
}
}
Expand Down

0 comments on commit 2552093

Please sign in to comment.