Skip to content

Commit 0a4b518

Browse files
devversionjelbourn
authored andcommitted
Rework ng-update to no longer depend on tslint (#16433)
* fix(ng-update): no longer depend on tslint for migration Reworks `ng update` to no longer depend on tslint for the migration. TSlint caused various problems: * No support for HTML templates and stylesheets (workaround was needed) * Reruns all upgrade lint rules after file has been updated (significant performance issue for projects with a lot of files) * Recreates the TypeScript program each time a source file has been updated (significant memory pressure for big TypeScript projects, causing OOM exceptions) * TSLint recursively visits the nodes of all source files for each upgrade lint rule (performance issue) * TSLint is not guaranteed to be installed in CLI projects. See: angular/angular-cli#14555 * TSLint replacements lead to memory leaks due to the retained TypeScript nodes * No way to have a *global analysis* phase since lint rules are only able to visit source files. * No flexibility. i.e. * No way to ensure source files are only analyzed a single time * No way to implement a progress bar * No easy way to add support for HTML templates or stylesheets * chore: reformat update schematics code with clang-format Reformats the `ng update` code within the CDK and Material package with clang-format. This ensures that the update code is consistent. * docs: update schematic architecture document Updates the schematic architecture document to reflect the new state of the `ng update` implementation which no longer uses `tslint` under the hood. * perf(ng-update): do not run migration rules if there is no upgrade data * No longer runs migration rules if there is no upgrade data. Running rules conditionally is now easy to implement with the new `update-tool`. * Adds comments for misc rule migrations to show which PR the given misc migration covers. * perf(ng-update): only migrate projects referenced in CLI workspace config Currently `ng update` tries to resolve projects by common TypeScript tsconfig locations besides looking in the CLI workspace config. This means that projects which are technically not part of a workspace project are still migrated even though they don't need to be. Similarly to `angular/angular`, we only migrate projects explicitly referenced in the `angular.json` workspace configuration. * refactor(ng-update): better messaging for migration failures Previously with tslint, we had no way to determine whether there were any upgrade rules which added rule failures without an automatic migration. With the `update-tool` we can now conditionally print a better a message if there were rule failures which need manual developer attention. i.e. we only print the message that asks the developer to check for any failures in the terminal output if there were actual rule failures.
1 parent ea31bca commit 0a4b518

File tree

98 files changed

+2380
-3098
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+2380
-3098
lines changed

src/cdk/schematics/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ ts_library(
2626
module_name = "@angular/cdk/schematics",
2727
tsconfig = ":tsconfig.json",
2828
deps = [
29+
"//src/cdk/schematics/update-tool",
2930
"@npm//@schematics/angular",
3031
"@npm//@angular-devkit/core",
3132
"@npm//@angular-devkit/schematics",
@@ -34,7 +35,6 @@ ts_library(
3435
"@npm//@types/node",
3536
"@npm//glob",
3637
"@npm//parse5",
37-
"@npm//tslint",
3838
"@npm//typescript",
3939
"@npm//chalk",
4040
],
@@ -73,12 +73,12 @@ ts_library(
7373
deps = [
7474
":schematics",
7575
"//src/cdk/schematics/testing",
76+
"//src/cdk/schematics/update-tool",
7677
"@npm//@angular-devkit/schematics",
7778
"@npm//@schematics/angular",
7879
"@npm//@types/jasmine",
7980
"@npm//@types/node",
8081
"@npm//mock-fs",
81-
"@npm//tslint",
8282
"@npm//typescript",
8383
],
8484
)

src/cdk/schematics/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88

99
export * from './utils';
1010
export * from './ng-update/public-api';
11+
export * from './update-tool/public-api';

src/cdk/schematics/ng-update/data/attribute-selectors.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {TargetVersion} from '../target-version';
10-
import {VersionChanges} from '../upgrade-data';
9+
import {TargetVersion} from '../../update-tool/target-version';
10+
import {VersionChanges} from '../../update-tool/version-changes';
1111

1212
export interface AttributeSelectorUpgradeData {
1313
/** The attribute name to replace. */
@@ -17,19 +17,11 @@ export interface AttributeSelectorUpgradeData {
1717
}
1818

1919
export const attributeSelectors: VersionChanges<AttributeSelectorUpgradeData> = {
20-
[TargetVersion.V6]: [
21-
{
22-
pr: 'https://github.com/angular/components/pull/10257',
23-
changes: [
24-
{
25-
replace: 'cdkPortalHost',
26-
replaceWith: 'cdkPortalOutlet'
27-
},
28-
{
29-
replace: 'portalHost',
30-
replaceWith: 'cdkPortalOutlet'
31-
}
32-
]
33-
}
34-
]
20+
[TargetVersion.V6]: [{
21+
pr: 'https://github.com/angular/components/pull/10257',
22+
changes: [
23+
{replace: 'cdkPortalHost', replaceWith: 'cdkPortalOutlet'},
24+
{replace: 'portalHost', replaceWith: 'cdkPortalOutlet'}
25+
]
26+
}]
3527
};

src/cdk/schematics/ng-update/data/class-names.ts

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {TargetVersion} from '../target-version';
10-
import {VersionChanges} from '../upgrade-data';
9+
import {TargetVersion} from '../../update-tool/target-version';
10+
import {VersionChanges} from '../../update-tool/version-changes';
1111

1212
export interface ClassNameUpgradeData {
1313
/** The Class name to replace. */
@@ -21,35 +21,19 @@ export const classNames: VersionChanges<ClassNameUpgradeData> = {
2121
{
2222
pr: 'https://github.com/angular/components/pull/10161',
2323
changes: [
24-
{
25-
replace: 'ConnectedOverlayDirective',
26-
replaceWith: 'CdkConnectedOverlay'
27-
},
28-
{
29-
replace: 'OverlayOrigin',
30-
replaceWith: 'CdkOverlayOrigin'
31-
}
24+
{replace: 'ConnectedOverlayDirective', replaceWith: 'CdkConnectedOverlay'},
25+
{replace: 'OverlayOrigin', replaceWith: 'CdkOverlayOrigin'}
3226
]
3327
},
3428

3529
{
3630
pr: 'https://github.com/angular/components/pull/10267',
37-
changes: [
38-
{
39-
replace: 'ObserveContent',
40-
replaceWith: 'CdkObserveContent'
41-
}
42-
]
31+
changes: [{replace: 'ObserveContent', replaceWith: 'CdkObserveContent'}]
4332
},
4433

4534
{
4635
pr: 'https://github.com/angular/components/pull/10325',
47-
changes: [
48-
{
49-
replace: 'FocusTrapDirective',
50-
replaceWith: 'CdkTrapFocus'
51-
}
52-
]
36+
changes: [{replace: 'FocusTrapDirective', replaceWith: 'CdkTrapFocus'}]
5337
}
5438
]
5539
};

src/cdk/schematics/ng-update/data/constructor-checks.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {TargetVersion} from '../target-version';
10-
import {VersionChanges} from '../upgrade-data';
9+
import {TargetVersion} from '../../update-tool/target-version';
10+
import {VersionChanges} from '../../update-tool/version-changes';
1111

1212
export type ConstructorChecksUpgradeData = string;
1313

@@ -17,15 +17,13 @@ export type ConstructorChecksUpgradeData = string;
1717
* automatically through type checking.
1818
*/
1919
export const constructorChecks: VersionChanges<ConstructorChecksUpgradeData> = {
20-
[TargetVersion.V8]: [
21-
{
22-
pr: 'https://github.com/angular/components/pull/15647',
23-
changes: [
24-
'CdkDrag', 'CdkDropList', 'ConnectedPositionStrategy', 'FlexibleConnectedPositionStrategy',
25-
'OverlayPositionBuilder', 'CdkTable'
26-
]
27-
}
28-
],
20+
[TargetVersion.V8]: [{
21+
pr: 'https://github.com/angular/components/pull/15647',
22+
changes: [
23+
'CdkDrag', 'CdkDropList', 'ConnectedPositionStrategy', 'FlexibleConnectedPositionStrategy',
24+
'OverlayPositionBuilder', 'CdkTable'
25+
]
26+
}],
2927
[TargetVersion.V7]: [],
3028
[TargetVersion.V6]: []
3129
};

src/cdk/schematics/ng-update/data/css-selectors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {TargetVersion} from '../target-version';
10-
import {VersionChanges} from '../upgrade-data';
9+
import {TargetVersion} from '../../update-tool/target-version';
10+
import {VersionChanges} from '../../update-tool/version-changes';
1111

1212
export interface CssSelectorUpgradeData {
1313
/** The CSS selector to replace. */

src/cdk/schematics/ng-update/data/element-selectors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {TargetVersion} from '../target-version';
10-
import {VersionChanges} from '../upgrade-data';
9+
import {TargetVersion} from '../../update-tool/target-version';
10+
import {VersionChanges} from '../../update-tool/version-changes';
1111

1212
export interface ElementSelectorUpgradeData {
1313
/** The element name to replace. */

src/cdk/schematics/ng-update/data/input-names.ts

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {TargetVersion} from '../target-version';
10-
import {VersionChanges} from '../upgrade-data';
9+
import {TargetVersion} from '../../update-tool/target-version';
10+
import {VersionChanges} from '../../update-tool/version-changes';
1111

1212
export interface InputNameUpgradeData {
1313
/** The @Input() name to replace. */
@@ -31,86 +31,74 @@ export const inputNames: VersionChanges<InputNameUpgradeData> = {
3131
{
3232
replace: 'origin',
3333
replaceWith: 'cdkConnectedOverlayOrigin',
34-
whitelist: {
35-
attributes: ['cdk-connected-overlay', 'connected-overlay', 'cdkConnectedOverlay']
36-
}
34+
whitelist:
35+
{attributes: ['cdk-connected-overlay', 'connected-overlay', 'cdkConnectedOverlay']}
3736
},
3837
{
3938
replace: 'positions',
4039
replaceWith: 'cdkConnectedOverlayPositions',
41-
whitelist: {
42-
attributes: ['cdk-connected-overlay', 'connected-overlay', 'cdkConnectedOverlay']
43-
}
40+
whitelist:
41+
{attributes: ['cdk-connected-overlay', 'connected-overlay', 'cdkConnectedOverlay']}
4442
},
4543
{
4644
replace: 'offsetX',
4745
replaceWith: 'cdkConnectedOverlayOffsetX',
48-
whitelist: {
49-
attributes: ['cdk-connected-overlay', 'connected-overlay', 'cdkConnectedOverlay']
50-
}
46+
whitelist:
47+
{attributes: ['cdk-connected-overlay', 'connected-overlay', 'cdkConnectedOverlay']}
5148
},
5249
{
5350
replace: 'offsetY',
5451
replaceWith: 'cdkConnectedOverlayOffsetY',
55-
whitelist: {
56-
attributes: ['cdk-connected-overlay', 'connected-overlay', 'cdkConnectedOverlay']
57-
}
52+
whitelist:
53+
{attributes: ['cdk-connected-overlay', 'connected-overlay', 'cdkConnectedOverlay']}
5854
},
5955
{
6056
replace: 'width',
6157
replaceWith: 'cdkConnectedOverlayWidth',
62-
whitelist: {
63-
attributes: ['cdk-connected-overlay', 'connected-overlay', 'cdkConnectedOverlay']
64-
}
58+
whitelist:
59+
{attributes: ['cdk-connected-overlay', 'connected-overlay', 'cdkConnectedOverlay']}
6560
},
6661
{
6762
replace: 'height',
6863
replaceWith: 'cdkConnectedOverlayHeight',
69-
whitelist: {
70-
attributes: ['cdk-connected-overlay', 'connected-overlay', 'cdkConnectedOverlay']
71-
}
64+
whitelist:
65+
{attributes: ['cdk-connected-overlay', 'connected-overlay', 'cdkConnectedOverlay']}
7266
},
7367
{
7468
replace: 'minWidth',
7569
replaceWith: 'cdkConnectedOverlayMinWidth',
76-
whitelist: {
77-
attributes: ['cdk-connected-overlay', 'connected-overlay', 'cdkConnectedOverlay']
78-
}
70+
whitelist:
71+
{attributes: ['cdk-connected-overlay', 'connected-overlay', 'cdkConnectedOverlay']}
7972
},
8073
{
8174
replace: 'minHeight',
8275
replaceWith: 'cdkConnectedOverlayMinHeight',
83-
whitelist: {
84-
attributes: ['cdk-connected-overlay', 'connected-overlay', 'cdkConnectedOverlay']
85-
}
76+
whitelist:
77+
{attributes: ['cdk-connected-overlay', 'connected-overlay', 'cdkConnectedOverlay']}
8678
},
8779
{
8880
replace: 'backdropClass',
8981
replaceWith: 'cdkConnectedOverlayBackdropClass',
90-
whitelist: {
91-
attributes: ['cdk-connected-overlay', 'connected-overlay', 'cdkConnectedOverlay']
92-
}
82+
whitelist:
83+
{attributes: ['cdk-connected-overlay', 'connected-overlay', 'cdkConnectedOverlay']}
9384
},
9485
{
9586
replace: 'scrollStrategy',
9687
replaceWith: 'cdkConnectedOverlayScrollStrategy',
97-
whitelist: {
98-
attributes: ['cdk-connected-overlay', 'connected-overlay', 'cdkConnectedOverlay']
99-
}
88+
whitelist:
89+
{attributes: ['cdk-connected-overlay', 'connected-overlay', 'cdkConnectedOverlay']}
10090
},
10191
{
10292
replace: 'open',
10393
replaceWith: 'cdkConnectedOverlayOpen',
104-
whitelist: {
105-
attributes: ['cdk-connected-overlay', 'connected-overlay', 'cdkConnectedOverlay']
106-
}
94+
whitelist:
95+
{attributes: ['cdk-connected-overlay', 'connected-overlay', 'cdkConnectedOverlay']}
10796
},
10897
{
10998
replace: 'hasBackdrop',
11099
replaceWith: 'cdkConnectedOverlayHasBackdrop',
111-
whitelist: {
112-
attributes: ['cdk-connected-overlay', 'connected-overlay', 'cdkConnectedOverlay']
113-
}
100+
whitelist:
101+
{attributes: ['cdk-connected-overlay', 'connected-overlay', 'cdkConnectedOverlay']}
114102
}
115103
]
116104
},

src/cdk/schematics/ng-update/data/method-call-checks.ts

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,22 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {TargetVersion} from '../target-version';
10-
import {VersionChanges} from '../upgrade-data';
9+
import {TargetVersion} from '../../update-tool/target-version';
10+
import {VersionChanges} from '../../update-tool/version-changes';
1111

1212
export interface MethodCallUpgradeData {
1313
className: string;
1414
method: string;
15-
invalidArgCounts: {
16-
count: number,
17-
message: string
18-
}[];
15+
invalidArgCounts: {count: number, message: string}[];
1916
}
2017

2118
export const methodCallChecks: VersionChanges<MethodCallUpgradeData> = {
22-
[TargetVersion.V6]: [
23-
{
24-
pr: 'https://github.com/angular/components/pull/10325',
25-
changes: [
26-
{
27-
className: 'FocusMonitor',
28-
method: 'monitor',
29-
invalidArgCounts: [
30-
{
31-
count: 3,
32-
message: 'The "renderer" argument has been removed'
33-
}
34-
]
35-
}
36-
]
37-
}
38-
]
19+
[TargetVersion.V6]: [{
20+
pr: 'https://github.com/angular/components/pull/10325',
21+
changes: [{
22+
className: 'FocusMonitor',
23+
method: 'monitor',
24+
invalidArgCounts: [{count: 3, message: 'The "renderer" argument has been removed'}]
25+
}]
26+
}]
3927
};

src/cdk/schematics/ng-update/data/output-names.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {TargetVersion} from '../target-version';
10-
import {VersionChanges} from '../upgrade-data';
9+
import {TargetVersion} from '../../update-tool/target-version';
10+
import {VersionChanges} from '../../update-tool/version-changes';
1111

1212
export interface OutputNameUpgradeData {
1313
/** The @Output() name to replace. */

0 commit comments

Comments
 (0)