Skip to content

fix(@schematics/angular): preserve the workspace build version during migration#32875

Open
raashish1601 wants to merge 2 commits intoangular:mainfrom
raashish1601:fix/angular-cli-30696-use-workspace-build-version
Open

fix(@schematics/angular): preserve the workspace build version during migration#32875
raashish1601 wants to merge 2 commits intoangular:mainfrom
raashish1601:fix/angular-cli-30696-use-workspace-build-version

Conversation

@raashish1601
Copy link
Copy Markdown

Summary

  • reuse the workspace version of @angular-devkit/build-angular when the use-application-builder migration adds @angular/build
  • fall back to an existing @angular/build version if it is already present, and only then fall back to the repo default
  • add a regression spec covering an 18.2.x workspace so the migration no longer upgrades the package to an incompatible 20.x release

Testing

  • corepack pnpm exec prettier --check packages/schematics/angular/migrations/use-application-builder/migration.ts packages/schematics/angular/migrations/use-application-builder/migration_spec.ts
  • corepack pnpm exec eslint packages/schematics/angular/migrations/use-application-builder/migration.ts packages/schematics/angular/migrations/use-application-builder/migration_spec.ts
  • git diff --check
  • corepack pnpm -s ng-dev format staged
  • attempted corepack pnpm bazel test //packages/schematics/angular:test --lockfile_mode=update --test_output=errors --verbose_failures under portable Node v24.13.1 with BAZEL_SH pointed at Git Bash; the target analyzed successfully but the Windows host then failed in Bazel's TypeScript toolchain before the schematic suite ran because the expected aspect_rules_js TypeScript entry point was missing from the generated execroot

Fixes #30696

@google-cla
Copy link
Copy Markdown

google-cla bot commented Mar 27, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the use-application-builder migration to reuse the existing version of the builder when migrating to @angular/build. It introduces logic to check for the current version of @angular-devkit/build-angular or @angular/build in the package.json and uses that version for the new @angular/build dependency, falling back to a default version if neither is found. A new test case has been added to verify this version preservation. I have no feedback to provide.

Copy link
Copy Markdown
Collaborator

@alan-agius4 alan-agius4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment

Comment on lines 274 to 281
const buildDependency =
getPackageJsonDependency(tree, '@angular-devkit/build-angular') ??
getPackageJsonDependency(tree, '@angular/build');
rules.push(
addDependency('@angular/build', latestVersions.DevkitBuildAngular, {
addDependency('@angular/build', buildDependency?.version ?? latestVersions.AngularBuild, {
type: DependencyType.Dev,
existing: ExistingBehavior.Replace,
}),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const buildDependency =
getPackageJsonDependency(tree, '@angular-devkit/build-angular') ??
getPackageJsonDependency(tree, '@angular/build');
rules.push(
addDependency('@angular/build', latestVersions.DevkitBuildAngular, {
addDependency('@angular/build', buildDependency?.version ?? latestVersions.AngularBuild, {
type: DependencyType.Dev,
existing: ExistingBehavior.Replace,
}),
const buildAngularVersion =
getDependency(tree, '@angular-devkit/build-angular')?.version ??
latestVersions.DevkitBuildAngular;
rules.push(
addDependency('@angular/build', buildAngularVersion, {
type: DependencyType.Dev,
existing: ExistingBehavior.Skip,
}),

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in 60392dd. I switched to getDependency(...), used latestVersions.DevkitBuildAngular as the fallback, kept ExistingBehavior.Skip, and added coverage for preserving an existing @angular/build version.

@alan-agius4 alan-agius4 added the target: patch This PR is targeted for the next patch release label Mar 27, 2026
Copy link
Copy Markdown
Collaborator

@alan-agius4 alan-agius4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign the CLA and squash the commits. Thanks

// Add direct @angular/build dependencies and remove @angular-devkit/build-angular
const buildAngularVersion =
getDependency(tree, '@angular-devkit/build-angular')?.version ??
latestVersions.DevkitBuildAngular;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT

Suggested change
latestVersions.DevkitBuildAngular;
latestVersions.AngularBuild;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: @schematics/angular target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Running the optional angular build migration installs incompatible version of @angular/build

2 participants