Skip to content

Commit ffad004

Browse files
macjohnnyjosephperrott
authored andcommitted
feat(common): Add dev-mode sanity check for mismatched versions of cdk and material (#15395)
1 parent 7baac27 commit ffad004

File tree

7 files changed

+26
-1
lines changed

7 files changed

+26
-1
lines changed

src/cdk/tsconfig-tests.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
},
1616
"files": [
1717
"./testing/index.ts",
18+
"./index.ts",
1819
"typings.d.ts"
1920
],
2021
"angularCompilerOptions": {

src/material/core/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ ng_module(
2525
] + glob(["**/*.html"]),
2626
module_name = "@angular/material/core",
2727
deps = [
28+
"//src/cdk",
2829
"//src/cdk/a11y",
2930
"//src/cdk/bidi",
3031
"//src/cdk/coercion",

src/material/core/common-behaviors/common-module.ts

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

9-
import {NgModule, InjectionToken, Optional, Inject, isDevMode} from '@angular/core';
9+
import {NgModule, InjectionToken, Optional, Inject, isDevMode, Version} from '@angular/core';
1010
import {HammerLoader, HAMMER_LOADER} from '@angular/platform-browser';
1111
import {BidiModule} from '@angular/cdk/bidi';
12+
import {VERSION as CDK_VERSION} from '@angular/cdk';
13+
14+
// Private version constant to circumvent test/build issues,
15+
// i.e. avoid core to depend on the @angular/material primary entry-point
16+
// Can be removed once the Material primary entry-point no longer
17+
// re-exports all secondary entry-points
18+
const VERSION = new Version('0.0.0-PLACEHOLDER');
1219

1320

1421
/** Injection token that configures whether the Material sanity checks are enabled. */
@@ -52,6 +59,7 @@ export class MatCommonModule {
5259
if (this._areChecksEnabled() && !this._hasDoneGlobalChecks) {
5360
this._checkDoctypeIsDefined();
5461
this._checkThemeIsPresent();
62+
this._checkCdkVersionMatch();
5563
this._hasDoneGlobalChecks = true;
5664
}
5765
}
@@ -104,6 +112,17 @@ export class MatCommonModule {
104112
this._document.body.removeChild(testElement);
105113
}
106114

115+
/** Checks whether the material version matches the cdk version */
116+
private _checkCdkVersionMatch(): void {
117+
if (VERSION.full !== CDK_VERSION.full) {
118+
console.warn(
119+
'The Angular Material version (' + VERSION.full + ') does not match ' +
120+
'the Angular CDK version (' + CDK_VERSION.full + ').\n' +
121+
'Please ensure the versions of these two packages exactly match.'
122+
);
123+
}
124+
}
125+
107126
/** Checks whether HammerJS is available. */
108127
_checkHammerIsAvailable(): void {
109128
if (this._hasCheckedHammer || !this._window) {

src/material/tsconfig-build.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"../../dist/packages/material"
1414
],
1515
"paths": {
16+
"@angular/cdk": ["../../dist/packages/cdk"],
1617
"@angular/cdk/*": ["../../dist/packages/cdk/*"],
1718
"@angular/material/*": ["../../dist/packages/material/*"]
1819
}

src/material/tsconfig-tests.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"types": ["jasmine"],
1111
"paths": {
1212
"@angular/material/*": ["./*"],
13+
"@angular/cdk": ["../../dist/packages/cdk"],
1314
"@angular/cdk/*": ["../../dist/packages/cdk/*"]
1415
}
1516
},

src/material/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"rootDir": "..",
66
"baseUrl": ".",
77
"paths": {
8+
"@angular/cdk": ["../cdk"],
89
"@angular/cdk/*": ["../cdk/*"],
910
"@angular/material/*": ["./*"]
1011
}

src/universal-app/tsconfig-prerender.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"baseUrl": ".",
2323
"paths": {
2424
"@angular/material": ["./material"],
25+
"@angular/cdk": ["./cdk"],
2526
"@angular/cdk/*": ["./cdk/*"],
2627
"@angular/material/*": ["./material/*"],
2728
"@angular/cdk-experimental": ["./cdk-experimental"],

0 commit comments

Comments
 (0)