Skip to content

Commit

Permalink
fix(@schematics/angular): skip ssr migration when @angular/ssr is n…
Browse files Browse the repository at this point in the history
…ot 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

(cherry picked from commit c716ce1)
  • Loading branch information
alan-agius4 committed Feb 3, 2025
1 parent 4b4eeca commit e9778db
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down

0 comments on commit e9778db

Please sign in to comment.