Skip to content

Commit

Permalink
fix(@schematics/angular): make version 12 workspace config migration …
Browse files Browse the repository at this point in the history
…idempotent

With this change we ensure that `update-angular-config-v12` migration is idempotent

Closes #20979

(cherry picked from commit afc9d10)
  • Loading branch information
alan-agius4 authored and filipesilva committed May 31, 2021
1 parent 83fbaca commit 06e0a72
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ function updateOptions(
target: workspaces.TargetDefinition,
optionsToUpdate: typeof ServerBuilderOptions | typeof BrowserBuilderOptions,
): void {
// This is a hacky way to make this migration idempotent.
// `defaultConfiguration` was only introduced in v12 projects and hence v11 projects do not have this property.
// Setting it as an empty string will not cause any side-effect.
if (typeof target.defaultConfiguration === 'string') {
return;
}

target.defaultConfiguration = '';

if (!target.options) {
target.options = {};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,21 @@ describe(`Migration to update 'angular.json'. ${schematicName}`, () => {
expect(options.namedChunks).toBeTrue();
expect(options.buildOptimizer).toBeFalse();
});

it('migration should be idempotent', async () => {
const { options } = getBuildTarget(tree);
expect(options.aot).toBeTrue();

// First run
const newTree1 = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
const { options: options1 } = getBuildTarget(newTree1);
expect(options1.aot).toBeUndefined();

// Second run
const newTree2 = await schematicRunner
.runSchematicAsync(schematicName, {}, newTree1)
.toPromise();
const { options: options2 } = getBuildTarget(newTree2);
expect(options2.aot).toBeUndefined();
});
});

0 comments on commit 06e0a72

Please sign in to comment.