Skip to content

Commit 1d8e392

Browse files
committed
Add test case; fix NodeJS version target circular dependency; Support for rule version constraints
1 parent 07992e3 commit 1d8e392

19 files changed

+107
-21
lines changed

src/lib/schematics/update/index.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,9 @@
77
*/
88

99
import {Rule} from '@angular-devkit/schematics';
10+
import {TargetVersion} from './target-version';
1011
import {createUpdateRule} from './update';
1112

12-
/** Possible versions that can be automatically migrated by `ng update`. */
13-
export enum TargetVersion {
14-
V6,
15-
V7,
16-
}
17-
1813
/** Entry point for the migration schematics with target of Angular Material 6.0.0 */
1914
export function updateToV6(): Rule {
2015
return createUpdateRule(TargetVersion.V6);

src/lib/schematics/update/material/data/attribute-selectors.ts

Lines changed: 1 addition & 1 deletion
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';
910
import {VersionChanges} from '../transform-change-data';
10-
import {TargetVersion} from '../../index';
1111

1212
export interface MaterialAttributeSelectorData {
1313
/** The attribute name to replace. */

src/lib/schematics/update/material/data/class-names.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {TargetVersion} from '../../index';
9+
import {TargetVersion} from '../../target-version';
1010
import {VersionChanges} from '../transform-change-data';
1111

1212
export interface MaterialClassNameData {

src/lib/schematics/update/material/data/constructor-checks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {TargetVersion} from '../../index';
9+
import {TargetVersion} from '../../target-version';
1010
import {VersionChanges} from '../transform-change-data';
1111

1212
/**

src/lib/schematics/update/material/data/css-selectors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {TargetVersion} from '../../index';
9+
import {TargetVersion} from '../../target-version';
1010
import {VersionChanges} from '../transform-change-data';
1111

1212
export interface MaterialCssSelectorData {

src/lib/schematics/update/material/data/element-selectors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {TargetVersion} from '../../index';
9+
import {TargetVersion} from '../../target-version';
1010
import {VersionChanges} from '../transform-change-data';
1111

1212
export interface MaterialElementSelectorData {

src/lib/schematics/update/material/data/input-names.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {TargetVersion} from '../../index';
9+
import {TargetVersion} from '../../target-version';
1010
import {VersionChanges} from '../transform-change-data';
1111

1212
export interface MaterialInputNameData {

src/lib/schematics/update/material/data/method-call-checks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {TargetVersion} from '../../index';
9+
import {TargetVersion} from '../../target-version';
1010
import {VersionChanges} from '../transform-change-data';
1111

1212
export interface MaterialMethodCallData {

src/lib/schematics/update/material/data/output-names.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {TargetVersion} from '../../index';
9+
import {TargetVersion} from '../../target-version';
1010
import {VersionChanges} from '../transform-change-data';
1111

1212
export interface MaterialOutputNameData {

src/lib/schematics/update/material/data/property-names.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {TargetVersion} from '../../index';
9+
import {TargetVersion} from '../../target-version';
1010
import {VersionChanges} from '../transform-change-data';
1111

1212
export interface MaterialPropertyNameData {

src/lib/schematics/update/material/transform-change-data.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import {TargetVersion} from '../index';
8+
9+
import {TargetVersion} from '../target-version';
910

1011
export type VersionChanges<T> = {
1112
[target in TargetVersion]?: ReadableChange<T>[];
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC 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+
/** Possible versions that can be automatically migrated by `ng update`. */
10+
export enum TargetVersion {
11+
V6,
12+
V7,
13+
}

src/lib/schematics/update/test-cases/v7-test-cases.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ describe('v7 upgrade test cases', () => {
1010
* a developers application.
1111
*/
1212
const testCases = [
13-
'v7/property-names'
13+
'v7/property-names',
14+
'v7/ripple-speed-factor',
1415
];
1516

1617
// Iterates through every test case directory and generates a jasmine test block that will
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import {Component} from '@angular/core';
2+
3+
class MatRipple {
4+
speedFactor: number;
5+
}
6+
7+
class A {
8+
self = {me: this.ripple};
9+
10+
constructor(protected ripple: MatRipple) {}
11+
12+
onClick() {
13+
this.ripple.animation = {enterDuration: 900};
14+
this.self.me.animation = {enterDuration: 300};
15+
}
16+
}
17+
18+
const b = new MatRipple();
19+
const myConstant = 1;
20+
21+
b.animation = /** TODO: Cleanup duration calculation. */ {enterDuration: 450 / (0.5 + myConstant)};
22+
23+
@Component({
24+
template: `<div matRipple [matRippleAnimation]="{enterDuration: 900}"></div>`
25+
})
26+
class C {}
27+
28+
@Component({
29+
template: `<div matRipple [matRippleAnimation]="{enterDuration: (450 / (myValue))}"></div>`
30+
})
31+
class D {
32+
myValue = 1.5;
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import {Component} from '@angular/core';
2+
3+
class MatRipple {
4+
speedFactor: number;
5+
}
6+
7+
class A {
8+
self = {me: this.ripple};
9+
10+
constructor(protected ripple: MatRipple) {}
11+
12+
onClick() {
13+
this.ripple.speedFactor = 0.5;
14+
this.self.me.speedFactor = 1.5;
15+
}
16+
}
17+
18+
const b = new MatRipple();
19+
const myConstant = 1;
20+
21+
b.speedFactor = 0.5 + myConstant;
22+
23+
@Component({
24+
template: `<div matRipple [matRippleSpeedFactor]="0.5"></div>`
25+
})
26+
class C {}
27+
28+
@Component({
29+
template: `<div matRipple [matRippleSpeedFactor]="myValue"></div>`
30+
})
31+
class D {
32+
myValue = 1.5;
33+
}

src/lib/schematics/update/tslint-config.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {sync as globSync} from 'glob';
10-
import {TargetVersion} from './index';
10+
import {TargetVersion} from './target-version';
1111

1212
/** List of rules that need to be enabled when running the TSLint fix task. */
1313
const upgradeRules = [
@@ -52,6 +52,10 @@ const upgradeRules = [
5252
// Additional misc rules.
5353
'check-import-misc',
5454
'check-template-misc',
55+
56+
// Ripple misc V7
57+
['ripple-speed-factor-assignment', TargetVersion.V7],
58+
['ripple-speed-factor-template', TargetVersion.V7],
5559
];
5660

5761
/** List of absolute paths that refer to directories that contain the upgrade rules. */
@@ -66,8 +70,14 @@ const rulesDirectory = globSync('rules/**/', {cwd: __dirname, absolute: true});
6670
* walker is not able to detect stylesheets which are not referenced by Angular.
6771
*/
6872
export function createTslintConfig(target: TargetVersion, extraStyleFiles: string[]) {
69-
const rules = upgradeRules.reduce((result, ruleName) => {
70-
result[ruleName] = [true, target, extraStyleFiles];
73+
const rules = upgradeRules.reduce((result, data) => {
74+
const ruleName = data instanceof Array ? data[0] : data;
75+
const versionConstraints = data instanceof Array ? data.slice(1) : null;
76+
77+
if (!versionConstraints || versionConstraints.includes(target)) {
78+
result[ruleName] = [true, target, extraStyleFiles];
79+
}
80+
7181
return result;
7282
}, {});
7383

src/lib/schematics/update/update.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import {Rule, SchematicContext, TaskId, Tree} from '@angular-devkit/schematics';
1010
import {RunSchematicTask, TslintFixTask} from '@angular-devkit/schematics/tasks';
1111
import {sync as globSync} from 'glob';
12-
import {TargetVersion} from './index';
1312
import {getProjectTsConfigPaths} from './project-tsconfig-paths';
13+
import {TargetVersion} from './target-version';
1414
import {createTslintConfig} from './tslint-config';
1515

1616
/** Entry point for `ng update` from Angular CLI. */

0 commit comments

Comments
 (0)