Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(@schematics/angular): keep existing build versions
  • Loading branch information
raashish1601 committed Mar 27, 2026
commit 60392dd84e863bc09754a34efccca53a82d4173c
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import {
externalSchematic,
} from '@angular-devkit/schematics';
import { dirname, join } from 'node:path/posix';
import { getPackageJsonDependency } from '../../utility/dependencies';
import {
DependencyType,
ExistingBehavior,
addDependency,
getDependency,
removeDependency,
} from '../../utility/dependency';
import { JSONFile } from '../../utility/json-file';
Expand Down Expand Up @@ -271,13 +271,13 @@ function updateProjects(tree: Tree, context: SchematicContext) {
}

// Add direct @angular/build dependencies and remove @angular-devkit/build-angular
const buildDependency =
getPackageJsonDependency(tree, '@angular-devkit/build-angular') ??
getPackageJsonDependency(tree, '@angular/build');
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;

rules.push(
addDependency('@angular/build', buildDependency?.version ?? latestVersions.AngularBuild, {
addDependency('@angular/build', buildAngularVersion, {
type: DependencyType.Dev,
existing: ExistingBehavior.Replace,
existing: ExistingBehavior.Skip,
}),
removeDependency('@angular-devkit/build-angular'),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,24 @@ describe(`Migration to use the application builder`, () => {
expect(devDependencies['@angular-devkit/build-angular']).toBeUndefined();
});

it('should preserve an existing "@angular/build" version when migrating', async () => {
tree.overwrite(
'/package.json',
JSON.stringify({
devDependencies: {
'@angular-devkit/build-angular': '~18.2.20',
'@angular/build': '~18.2.10',
},
}),
);

const newTree = await schematicRunner.runSchematic(schematicName, {}, tree);

const { devDependencies } = JSON.parse(newTree.readContent('/package.json'));
expect(devDependencies['@angular/build']).toBe('~18.2.10');
expect(devDependencies['@angular-devkit/build-angular']).toBeUndefined();
});

it('it should not add esModuleInterop and moduleResolution when module is preserve', async () => {
tree.overwrite(
'tsconfig.json',
Expand Down
Loading