Skip to content

Commit d60a6e8

Browse files
committed
fix(@schematics/angular): noop workspace config migration when already executed
Prior to this change there was a missing check that causes the migration to remove valid config when it was executed multiple times or on configs that do not contain the deprecated option. Closes #26063 (cherry picked from commit 53f93b9)
1 parent 6c3d7d1 commit d60a6e8

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

packages/schematics/angular/migrations/update-17/update-workspace-config.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import { Rule, chain } from '@angular-devkit/schematics';
10-
import { removePackageJsonDependency } from '../../utility/dependencies';
9+
import { Rule } from '@angular-devkit/schematics';
1110
import { allTargetOptions, updateWorkspace } from '../../utility/workspace';
1211
import { Builders, ProjectType } from '../../utility/workspace-models';
1312

@@ -22,8 +21,10 @@ export default function (): Rule {
2221
for (const [, target] of project.targets) {
2322
if (target.builder === Builders.ExtractI18n || target.builder === Builders.DevServer) {
2423
for (const [, options] of allTargetOptions(target, false)) {
25-
options['buildTarget'] = options['browserTarget'];
26-
delete options['browserTarget'];
24+
if (options['browserTarget'] !== undefined) {
25+
options['buildTarget'] = options['browserTarget'];
26+
delete options['browserTarget'];
27+
}
2728
}
2829
}
2930
}

packages/schematics/angular/migrations/update-17/update-workspace-config_spec.ts

+23
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,27 @@ describe(`Migration to update 'angular.json'.`, () => {
109109
expect(browserTarget).toBe('app:build');
110110
expect(buildTarget).toBeUndefined();
111111
});
112+
113+
it(`should not remove 'buildTarget' when migration is ran multiple times`, async () => {
114+
const runMigrationAndExpects = async (testTree: UnitTestTree) => {
115+
const newTree = await schematicRunner.runSchematic(schematicName, {}, testTree);
116+
const {
117+
projects: { app },
118+
} = JSON.parse(newTree.readContent('/angular.json'));
119+
120+
const { browserTarget, buildTarget } = app.architect['serve'].options;
121+
expect(browserTarget).toBeUndefined();
122+
expect(buildTarget).toBe('app:build:development');
123+
124+
const { browserTarget: browserTargetProd, buildTarget: buildTargetProd } =
125+
app.architect['serve'].configurations['production'];
126+
expect(browserTargetProd).toBeUndefined();
127+
expect(buildTargetProd).toBe('app:build:production');
128+
129+
return newTree;
130+
};
131+
132+
const newTree = await runMigrationAndExpects(tree);
133+
await runMigrationAndExpects(newTree);
134+
});
112135
});

0 commit comments

Comments
 (0)