Skip to content

Commit

Permalink
refactor(core): undecorated-classes-with-decorated-fields migration c…
Browse files Browse the repository at this point in the history
…ommits empty updates (angular#32391)

Commit 904a201 introduced a new migration for
undecorated classes with decorated Angular class members. Currently the migration
always calls `tree.beginUpdate` and `tree.commitUpdate` (even if there are no changes).

This causes unnecessary updates to be reported to developers running `ng update`. Once
an update is commited, the CLI will report the update regardless of whether any changes were
made or not.

This behavior can be observed in the `ng_update_migrations` integration test. See:
https://circleci.com/gh/angular/angular/438470#tests/containers/3. Notice how all
source files are denoted as `UPDATED` (even though there are no changes).

PR Close angular#32391
  • Loading branch information
devversion authored and sabeersulaiman committed Sep 6, 2019
1 parent 4443d0c commit 206a78d
Showing 1 changed file with 6 additions and 1 deletion.
Expand Up @@ -65,9 +65,14 @@ function runUndecoratedClassesMigration(tree: Tree, tsconfigPath: string, basePa
file => !file.isDeclarationFile && !program.isSourceFileFromExternalLibrary(file));

sourceFiles.forEach(sourceFile => {
const update = tree.beginUpdate(relative(basePath, sourceFile.fileName));
const classes = getUndecoratedClassesWithDecoratedFields(sourceFile, typeChecker);

if (classes.length === 0) {
return;
}

const update = tree.beginUpdate(relative(basePath, sourceFile.fileName));

classes.forEach((current, index) => {
// If it's the first class that we're processing in this file, add `Directive` to the imports.
if (index === 0 && !hasNamedImport(current.importDeclaration, FALLBACK_DECORATOR)) {
Expand Down

0 comments on commit 206a78d

Please sign in to comment.