Skip to content

Commit f424529

Browse files
alan-agius4clydin
authored andcommitted
feat(@schematics/angular): add migration to remove deprecated options from 'angular.json'
1 parent 4773e13 commit f424529

File tree

3 files changed

+142
-0
lines changed

3 files changed

+142
-0
lines changed

packages/schematics/angular/migrations/migration-collection.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@
124124
"version": "11.0.0",
125125
"factory": "./update-11/update-dependencies",
126126
"description": "Update workspace dependencies to match a new v11 project."
127+
},
128+
"update-angular-config-v12": {
129+
"version": "12.0.0-next.0",
130+
"factory": "./update-12/update-angular-config",
131+
"description": "Remove deprecated options from 'angular.json' that are no longer present in v12."
127132
}
128133
}
129134
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import { Rule } from '@angular-devkit/schematics';
10+
import { updateWorkspace } from '../../utility/workspace';
11+
12+
export default function (): Rule {
13+
return updateWorkspace(workspace => {
14+
const optionsToRemove: Record<string, undefined> = {
15+
experimentalRollupPass: undefined,
16+
};
17+
18+
for (const [, project] of workspace.projects) {
19+
for (const [, target] of project.targets) {
20+
// Only interested in Angular Devkit builders
21+
if (!target?.builder.startsWith('@angular-devkit/build-angular')) {
22+
continue;
23+
}
24+
25+
// Check options
26+
if (target.options) {
27+
target.options = {
28+
...optionsToRemove,
29+
};
30+
}
31+
32+
// Go through each configuration entry
33+
if (!target.configurations) {
34+
continue;
35+
}
36+
37+
for (const configurationName of Object.keys(target.configurations)) {
38+
target.configurations[configurationName] = {
39+
...optionsToRemove,
40+
};
41+
}
42+
}
43+
}
44+
});
45+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
import { JsonObject } from '@angular-devkit/core';
9+
import { EmptyTree } from '@angular-devkit/schematics';
10+
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
11+
import { BuilderTarget, Builders, ProjectType, WorkspaceSchema } from '../../utility/workspace-models';
12+
13+
function getBuildTarget(tree: UnitTestTree): BuilderTarget<Builders.Browser, JsonObject> {
14+
return JSON.parse(tree.readContent('/angular.json')).projects.app.architect.build;
15+
}
16+
17+
function createWorkSpaceConfig(tree: UnitTestTree) {
18+
const angularConfig: WorkspaceSchema = {
19+
version: 1,
20+
projects: {
21+
app: {
22+
root: '',
23+
sourceRoot: 'src',
24+
projectType: ProjectType.Application,
25+
prefix: 'app',
26+
architect: {
27+
build: {
28+
builder: Builders.Browser,
29+
options: {
30+
scripts: [
31+
{ lazy: true, name: 'bundle-1.js' },
32+
],
33+
experimentalRollupPass: false,
34+
sourceMaps: true,
35+
buildOptimizer: false,
36+
// tslint:disable-next-line:no-any
37+
} as any,
38+
configurations: {
39+
one: {
40+
aot: true,
41+
scripts: [
42+
{ lazy: true, name: 'bundle-1.js' },
43+
{ lazy: false, name: 'bundle-2.js' },
44+
{ inject: true, name: 'bundle-3.js' },
45+
'bundle-4.js',
46+
],
47+
styles: [
48+
{ lazy: true, name: 'bundle-1.css' },
49+
{ lazy: false, name: 'bundle-2.css' },
50+
{ inject: true, name: 'bundle-3.css' },
51+
'bundle-3.css',
52+
],
53+
},
54+
two: {
55+
experimentalRollupPass: true,
56+
aot: true,
57+
},
58+
// tslint:disable-next-line:no-any
59+
} as any,
60+
},
61+
},
62+
},
63+
},
64+
};
65+
66+
tree.create('/angular.json', JSON.stringify(angularConfig, undefined, 2));
67+
}
68+
69+
const schematicName = 'update-angular-config-v12';
70+
71+
describe(`Migration to update 'angular.json'. ${schematicName}`, () => {
72+
const schematicRunner = new SchematicTestRunner(
73+
'migrations',
74+
require.resolve('../migration-collection.json'),
75+
);
76+
77+
let tree: UnitTestTree;
78+
beforeEach(() => {
79+
tree = new UnitTestTree(new EmptyTree());
80+
createWorkSpaceConfig(tree);
81+
});
82+
83+
it(`should remove 'experimentalRollupPass'`, async () => {
84+
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
85+
const { options, configurations } = getBuildTarget(newTree);
86+
87+
expect(options.experimentalRollupPass).toBeUndefined();
88+
expect(configurations).toBeDefined();
89+
expect(configurations?.one.experimentalRollupPass).toBeUndefined();
90+
expect(configurations?.two.experimentalRollupPass).toBeUndefined();
91+
});
92+
});

0 commit comments

Comments
 (0)