Files
polygraph-snapshot-app[bot] 9371aa571d fix(angular): bump zoneJsVersion to ~0.16.0 to align with Angular v21 (#35799)
## Current Behavior

`@nx/angular`'s `zoneJsVersion` is pinned to `~0.15.0`, while
`catalogs.angular` in `pnpm-workspace.yaml` and the v21 migration entry
in `packages/angular/migrations.json` both pin `zone.js` at `~0.16.0`.
Generators and dependency-installation paths in `@nx/angular` therefore
emit `zone.js@~0.15.0` even when the project is on Angular 21, drifting
from what the migration and workspace catalog declare.

## Expected Behavior

`zoneJsVersion` matches the v21 pin (`~0.16.0`), keeping generator
output aligned with the workspace catalog and the v21 migration. The
bump is safe within Angular 21: `@angular/core@21.x` accepts `~0.15.0 ||
~0.16.0` (see `catalogs.angular-supported-versions` in
`pnpm-workspace.yaml`).

## Implementation Details

Bumps `zoneJsVersion` in `packages/angular/src/utils/versions.ts` from
`~0.15.0` to `~0.16.0`. The v21 entry in
`backward-compatible-versions.ts` inherits from `latestVersions` via
spread, so it picks up the bump automatically. The v20/v19 entries are
unchanged — those Angular majors correctly stay on `~0.15.0`.

Also extends `scripts/angular-support-upgrades/` so this drift doesn't
recur on the next Angular bump:

- `fetch-versions-from-registry.ts`: after the dist-tag fetch, resolves
`zone.js` and `rxjs` against the latest registry-published versions
matching `@angular/core@<resolved>`'s `peerDependencies` ranges. Skips
with a warning if a peer is missing or no satisfying version exists.
- `update-version-utils.ts`: adds regex bumps for `zoneJsVersion` and
`rxjsVersion` in `versions.ts`, guarded so they only run when the
version map carries those keys.

`update-package-jsons.ts` and `build-migrations.ts` need no changes —
their existing iteration over the version map already covers `zone.js`
(and `rxjs` where applicable) once the keys are populated.

`ngrxVersion` and the per-major back-compat blocks in
`backward-compatible-versions.ts` have similar drift risk but are out of
scope here (different mechanics; flagged for follow-up).

<!-- polygraph-session-start -->
---
[View session information
↗](https://snapshot.app.trypolygraph.com/orgs/69cdc268b6aa527e4129c2b4/sessions/fix-zone-js-version-b63af779)
<!-- polygraph-session-end -->

---------

Co-authored-by: Leosvel Pérez Espinosa <leosvel.perez.espinosa@gmail.com>
2026-06-01 14:00:16 -04:00

82 lines
2.7 KiB
TypeScript

import { readFileSync, writeFileSync } from 'fs';
function updateAngularVersionUtils(
packageVersionMap: Map<string, string>,
isPrerelease: boolean
) {
const pathToFile = 'packages/angular/src/utils/versions.ts';
let versionUtilContents = readFileSync(pathToFile, { encoding: 'utf-8' });
const angularVersion = packageVersionMap.get('@angular/core')!;
const angularDevkitVersion = packageVersionMap.get('@angular/cli')!;
const ngPackagrVersion = packageVersionMap.get('ng-packagr')!;
const zoneJsVersion = packageVersionMap.get('zone.js');
const rxjsVersion = packageVersionMap.get('rxjs');
versionUtilContents = versionUtilContents.replace(
/export const angularVersion = '.+';/,
`export const angularVersion = '${
isPrerelease ? angularVersion : `~${angularVersion}`
}';`
);
versionUtilContents = versionUtilContents.replace(
/export const angularDevkitVersion = '.+';/,
`export const angularDevkitVersion = '${
isPrerelease ? angularDevkitVersion : `~${angularDevkitVersion}`
}';`
);
versionUtilContents = versionUtilContents.replace(
/export const ngPackagrVersion = '.+';/,
`export const ngPackagrVersion = '${
isPrerelease ? ngPackagrVersion : `~${ngPackagrVersion}`
}';`
);
if (zoneJsVersion) {
versionUtilContents = versionUtilContents.replace(
/export const zoneJsVersion = '.+';/,
`export const zoneJsVersion = '${
isPrerelease ? zoneJsVersion : `~${zoneJsVersion}`
}';`
);
}
if (rxjsVersion) {
versionUtilContents = versionUtilContents.replace(
/export const rxjsVersion = '.+';/,
`export const rxjsVersion = '${
isPrerelease ? rxjsVersion : `~${rxjsVersion}`
}';`
);
}
writeFileSync(pathToFile, versionUtilContents);
}
function updateWorkspaceAngularVersionUtils(
packageVersionMap: Map<string, string>,
isPrerelease: boolean
) {
const pathToFile = 'packages/workspace/src/utils/versions.ts';
let versionUtilContents = readFileSync(pathToFile, { encoding: 'utf-8' });
const angularDevkitVersion = packageVersionMap.get('@angular/cli')!;
versionUtilContents = versionUtilContents.replace(
/export const angularCliVersion = '.+';/,
`export const angularCliVersion = '${
isPrerelease ? angularDevkitVersion : `~${angularDevkitVersion}`
}';`
);
writeFileSync(pathToFile, versionUtilContents);
}
export function updateVersionUtils(
packageVersionMap: Map<string, string>,
isPrerelease: boolean
) {
console.log('⏳ - Writing Util Files...');
updateAngularVersionUtils(packageVersionMap, isPrerelease);
updateWorkspaceAngularVersionUtils(packageVersionMap, isPrerelease);
console.log('✅ - Wrote Util Files');
}