Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@schematics/angular): make version 12 workspace config migration idempotent #20980

Merged
merged 1 commit into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
});