Skip to content

Commit afc9d10

Browse files
alan-agius4filipesilva
authored andcommitted
fix(@schematics/angular): make version 12 workspace config migration idempotent
With this change we ensure that `update-angular-config-v12` migration is idempotent Closes #20979
1 parent 92c9be4 commit afc9d10

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

packages/schematics/angular/migrations/update-12/update-angular-config.ts

+9
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ function updateOptions(
5959
target: workspaces.TargetDefinition,
6060
optionsToUpdate: typeof ServerBuilderOptions | typeof BrowserBuilderOptions,
6161
): void {
62+
// This is a hacky way to make this migration idempotent.
63+
// `defaultConfiguration` was only introduced in v12 projects and hence v11 projects do not have this property.
64+
// Setting it as an empty string will not cause any side-effect.
65+
if (typeof target.defaultConfiguration === 'string') {
66+
return;
67+
}
68+
69+
target.defaultConfiguration = '';
70+
6271
if (!target.options) {
6372
target.options = {};
6473
}

packages/schematics/angular/migrations/update-12/update-angular-config_spec.ts

+17
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,21 @@ describe(`Migration to update 'angular.json'. ${schematicName}`, () => {
120120
expect(options.namedChunks).toBeTrue();
121121
expect(options.buildOptimizer).toBeFalse();
122122
});
123+
124+
it('migration should be idempotent', async () => {
125+
const { options } = getBuildTarget(tree);
126+
expect(options.aot).toBeTrue();
127+
128+
// First run
129+
const newTree1 = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
130+
const { options: options1 } = getBuildTarget(newTree1);
131+
expect(options1.aot).toBeUndefined();
132+
133+
// Second run
134+
const newTree2 = await schematicRunner
135+
.runSchematicAsync(schematicName, {}, newTree1)
136+
.toPromise();
137+
const { options: options2 } = getBuildTarget(newTree2);
138+
expect(options2.aot).toBeUndefined();
139+
});
123140
});

0 commit comments

Comments
 (0)