From c56c2416a9acb4f017e7e8387a6602a6c81b41fc Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Thu, 29 Aug 2019 12:03:11 +0200 Subject: [PATCH] refactor(core): undecorated-classes-with-decorated-fields migration commits empty updates (#32391) Commit 904a2018e0d3394ad91ffb6472f8271af7845295 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 #32391 --- .../undecorated-classes-with-decorated-fields/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/core/schematics/migrations/undecorated-classes-with-decorated-fields/index.ts b/packages/core/schematics/migrations/undecorated-classes-with-decorated-fields/index.ts index 68f80e5d48..0873860139 100644 --- a/packages/core/schematics/migrations/undecorated-classes-with-decorated-fields/index.ts +++ b/packages/core/schematics/migrations/undecorated-classes-with-decorated-fields/index.ts @@ -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)) {