fix(@schematics/angular): skip ssr migration when @angular/ssr is not a dependency

This commit updates the `update-ssr-imports` migration to not run when the @angular/ssr` package is not listed as a dependency.

Closes #29560
This commit is contained in:
Alan Agius 2025-02-03 22:32:07 +00:00 committed by Alan Agius
parent c48a2da287
commit c716ce1523
2 changed files with 13 additions and 0 deletions

View File

@ -8,6 +8,7 @@
import { DirEntry, Rule, UpdateRecorder } from '@angular-devkit/schematics';
import * as ts from '../../third_party/github.com/Microsoft/TypeScript/lib/typescript';
import { getPackageJsonDependency } from '../../utility/dependencies';
function* visit(directory: DirEntry): IterableIterator<ts.SourceFile> {
for (const path of directory.subfiles) {
@ -46,6 +47,10 @@ function* visit(directory: DirEntry): IterableIterator<ts.SourceFile> {
*/
export default function (): Rule {
return (tree) => {
if (!getPackageJsonDependency(tree, '@angular/ssr')) {
return;
}
for (const sourceFile of visit(tree.root)) {
let recorder: UpdateRecorder | undefined;

View File

@ -19,6 +19,14 @@ describe('CommonEngine migration', () => {
let tree: UnitTestTree;
beforeEach(() => {
tree = new UnitTestTree(new EmptyTree());
tree.create(
'package.json',
JSON.stringify({
dependencies: {
'@angular/ssr': '0.0.0',
},
}),
);
});
function runMigration(): Promise<UnitTestTree> {